Changeset View
Changeset View
Standalone View
Standalone View
src/test/fuzz/span.cpp
Show All 12 Lines | |||||
#include <cstdint> | #include <cstdint> | ||||
#include <string> | #include <string> | ||||
#include <vector> | #include <vector> | ||||
void test_one_input(const std::vector<uint8_t> &buffer) { | void test_one_input(const std::vector<uint8_t> &buffer) { | ||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); | FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); | ||||
std::string str = fuzzed_data_provider.ConsumeBytesAsString(32); | std::string str = fuzzed_data_provider.ConsumeBytesAsString(32); | ||||
const Span<const char> span = MakeSpan(str); | const Span<const char> span{str}; | ||||
(void)span.data(); | (void)span.data(); | ||||
(void)span.begin(); | (void)span.begin(); | ||||
(void)span.end(); | (void)span.end(); | ||||
if (span.size() > 0) { | if (span.size() > 0) { | ||||
const std::ptrdiff_t idx = | const std::ptrdiff_t idx = | ||||
fuzzed_data_provider.ConsumeIntegralInRange<std::ptrdiff_t>( | fuzzed_data_provider.ConsumeIntegralInRange<std::ptrdiff_t>( | ||||
0U, span.size() - 1U); | 0U, span.size() - 1U); | ||||
(void)span.first(idx); | (void)span.first(idx); | ||||
(void)span.last(idx); | (void)span.last(idx); | ||||
(void)span.subspan(idx); | (void)span.subspan(idx); | ||||
(void)span.subspan(idx, span.size() - idx); | (void)span.subspan(idx, span.size() - idx); | ||||
(void)span[idx]; | (void)span[idx]; | ||||
} | } | ||||
std::string another_str = fuzzed_data_provider.ConsumeBytesAsString(32); | std::string another_str = fuzzed_data_provider.ConsumeBytesAsString(32); | ||||
const Span<const char> another_span = MakeSpan(another_str); | const Span<const char> another_span{another_str}; | ||||
assert((span <= another_span) != (span > another_span)); | assert((span <= another_span) != (span > another_span)); | ||||
assert((span == another_span) != (span != another_span)); | assert((span == another_span) != (span != another_span)); | ||||
assert((span >= another_span) != (span < another_span)); | assert((span >= another_span) != (span < another_span)); | ||||
} | } |