tesseract v5.3.3.20231005
validator_test.cc
Go to the documentation of this file.
1// (C) Copyright 2017, Google Inc.
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5// http://www.apache.org/licenses/LICENSE-2.0
6// Unless required by applicable law or agreed to in writing, software
7// distributed under the License is distributed on an "AS IS" BASIS,
8// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9// See the License for the specific language governing permissions and
10// limitations under the License.
11
12#include "validator.h"
13
14#include "gmock/gmock.h" // for testing::ElementsAreArray
15#include "include_gunit.h"
16
17namespace tesseract {
18
20public:
21 static ViramaScript TestableMostFrequentViramaScript(const std::vector<char32> &utf32) {
22 return MostFrequentViramaScript(utf32);
23 }
24};
25
26// The majority of Validator is tested by the script-specific tests of its
27// subclasses, but the MostFrequentViramaScript function is worth a unittest.
28TEST(ValidatorTest, MostFrequentViramaScript) {
29 // The most frequent virama script should come out correct, despite
30 // distractions from other scripts.
32 // It is still Telugu surrounded by Latin.
35 // But not still Telugu surrounded by Devanagari.
37 TestableValidator::TestableMostFrequentViramaScript({0x905, 0xc05, 0x906, 0x907}));
39 TestableValidator::TestableMostFrequentViramaScript({0xc85, 0xc05, 0xc86, 0xc87}));
41 TestableValidator::TestableMostFrequentViramaScript({0x985, 0xc05, 0x986, 0x987}));
42 // Danda and double Danda don't count as Devanagari, as they are common.
44 TestableValidator::TestableMostFrequentViramaScript({0x964, 0xc05, 0x965, 0x965}));
45}
46
47// ValidateCleanAndSegment doesn't modify the input by much, but its
48// transformation should be idempotent. (Doesn't change again if re-applied.)
49TEST(ValidatorTest, Idempotency) {
50 std::vector<char32> str1({0xd24, 0xd23, 0xd32, 0xd4d, '\'', 0x200d, 0x200c, 0x200d, 0x200c});
51 std::vector<char32> str2({0xd24, 0xd23, 0xd32, 0xd4d, 0x200c, 0x200d, 0x200c, 0x200d, '\''});
52 std::vector<std::vector<char32>> result1, result2, result3, result4;
56 &result2));
57 EXPECT_EQ(result1.size(), result2.size());
58 EXPECT_THAT(result2[0], testing::ElementsAreArray(result1[0]));
62 &result4));
63 EXPECT_EQ(result3.size(), result4.size());
64 EXPECT_THAT(result4[0], testing::ElementsAreArray(result3[0]));
65}
66
67} // namespace tesseract
#define EXPECT_THAT(value, matcher)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:2043
#define EXPECT_TRUE(condition)
Definition: gtest.h:1982
TEST(TesseractInstanceTest, TestMultipleTessInstances)
static ViramaScript MostFrequentViramaScript(const std::vector< char32 > &utf32)
Definition: validator.cpp:135
static bool ValidateCleanAndSegment(GraphemeNormMode g_mode, bool report_errors, const std::vector< char32 > &src, std::vector< std::vector< char32 > > *dest)
Definition: validator.cpp:40
static ViramaScript TestableMostFrequentViramaScript(const std::vector< char32 > &utf32)