1 // Copyright 2016 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ////////////////////////////////////////////////////////////////////////////////
16
17 #include <stddef.h>
18 #include <stdlib.h>
19 #include <memory>
20
21 #include "compact_enc_det/compact_enc_det.h"
22 #include "util/encodings/encodings.h"
23 #include "util/languages/languages.h"
24 #include "util/port.h"
25 #include "gtest/gtest.h"
26
27 namespace {
28
29 class CompactEncDetFuzzTest : public testing::Test {};
30
TEST_F(CompactEncDetFuzzTest,TestRandom)31 TEST_F(CompactEncDetFuzzTest, TestRandom) {
32 for (size_t i = 0; i < 16384; ++i) {
33 unsigned int seed = i;
34 srand(seed);
35 size_t length = static_cast<size_t>(rand()) % 1024;
36 std::unique_ptr<char[]> text(new char[length]);
37
38 for (size_t j = 0; j < length; ++j) text[j] = rand();
39
40 int bytes_consumed;
41 bool is_reliable;
42
43 CompactEncDet::DetectEncoding(text.get(), length, nullptr, // URL hint
44 nullptr, // HTTP hint
45 nullptr, // Meta hint
46 UNKNOWN_ENCODING,
47 UNKNOWN_LANGUAGE,
48 CompactEncDet::WEB_CORPUS,
49 false, // Include 7-bit encodings?
50 &bytes_consumed, &is_reliable);
51 }
52 }
53
54 } // namespace
55