| Index: third_party/cld/encodings/compact_enc_det/compact_enc_det_fuzz_test.cc
|
| diff --git a/third_party/cld/encodings/compact_enc_det/compact_enc_det_fuzz_test.cc b/third_party/cld/encodings/compact_enc_det/compact_enc_det_fuzz_test.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b214f9818c069807e4838dc77fbb83e32684be26
|
| --- /dev/null
|
| +++ b/third_party/cld/encodings/compact_enc_det/compact_enc_det_fuzz_test.cc
|
| @@ -0,0 +1,36 @@
|
| +#include <stddef.h>
|
| +#include <stdlib.h>
|
| +#include <memory>
|
| +
|
| +#include "i18n/encodings/compact_enc_det/compact_enc_det.h"
|
| +#include "i18n/encodings/public/encodings.h"
|
| +#include "i18n/languages/public/languages.h"
|
| +#include "testing/base/public/gunit.h"
|
| +
|
| +namespace {
|
| +
|
| +class CompactEncDetFuzzTest : public testing::Test {};
|
| +
|
| +TEST_F(CompactEncDetFuzzTest, TestRandom) {
|
| + for (size_t i = 0; i < 16384; ++i) {
|
| + unsigned int seed = i;
|
| + size_t length = static_cast<size_t>(rand_r(&seed)) % 1024;
|
| + std::unique_ptr<char[]> text(new char[length]);
|
| +
|
| + for (size_t j = 0; j < length; ++j) text[j] = rand_r(&seed);
|
| +
|
| + int bytes_consumed;
|
| + bool is_reliable;
|
| +
|
| + CompactEncDet::DetectEncoding(text.get(), length, nullptr, // URL hint
|
| + nullptr, // HTTP hint
|
| + nullptr, // Meta hint
|
| + UNKNOWN_ENCODING,
|
| + i18n::languages::UNKNOWN_LANGUAGE,
|
| + CompactEncDet::WEB_CORPUS,
|
| + false, // Include 7-bit encodings?
|
| + &bytes_consumed, &is_reliable);
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
|
|