17 #include "allheaders.h"
35 static const char* kPolyBlockNames[] = {
54 const char* kStrings8087_054[] = {
55 "dat",
"Dalmatian",
"",
"DAMAGED DURING",
"margarine,",
nullptr};
61 class LayoutTest :
public testing::Test {
70 LayoutTest() { src_pix_ =
nullptr; }
71 ~LayoutTest() { pixDestroy(&src_pix_); }
73 void SetImage(
const char* filename,
const char* lang) {
74 pixDestroy(&src_pix_);
75 src_pix_ = pixRead(TestDataNameToPath(filename).c_str());
78 api_.SetImage(src_pix_);
86 void VerifyBlockTextOrder(
const char* strings[],
const PolyBlockType* blocks,
93 if (block_text !=
nullptr && it->BlockType() == blocks[string_index] &&
94 strstr(block_text, strings[string_index]) !=
nullptr) {
95 LOG(
INFO) <<
"Found string " << strings[string_index]
96 <<
" in block " << block_index
97 <<
" of type " << kPolyBlockNames[blocks[string_index]] <<
"\n";
100 }
else if (it->BlockType() == blocks[string_index] &&
101 block_text ==
nullptr && strings[string_index][0] ==
'\0') {
102 LOG(
INFO) <<
"Found block of type " << kPolyBlockNames[blocks[string_index]]
103 <<
" at block " << block_index <<
"\n";
107 LOG(
INFO) <<
"No match found in block with text:\n" << block_text;
111 if (strings[string_index] ==
nullptr)
break;
113 EXPECT_TRUE(strings[string_index] ==
nullptr);
121 void VerifyRoughBlockOrder(
bool right_to_left, ResultIterator* it) {
127 int left, top, right, bottom;
130 bottom - top > 200) {
131 if (prev_right > prev_left) {
132 if (std::min(right, prev_right) > std::max(left, prev_left)) {
133 EXPECT_GE(top, prev_bottom) <<
"Overlapping block should be below";
134 }
else if (top < prev_bottom) {
136 EXPECT_GE(prev_left, right) <<
"Block should be to the left";
138 EXPECT_GE(left, prev_right) <<
"Block should be to the right";
144 prev_bottom = bottom;
152 void VerifyTotalContainment(
int winding_target, MutableIterator* it) {
155 int left, top, right, bottom;
158 bottom - top > 200) {
161 CHECK(pb !=
nullptr);
163 EXPECT_GT(skew.
x(), 0.0f);
164 EXPECT_GT(skew.
y(), 0.0f);
166 MutableIterator word_it = *it;
171 for (b_it.mark_cycle_pt(); !b_it.cycled_list(); b_it.forward()) {
172 C_BLOB* blob = b_it.data();
174 C_OUTLINE_IT ol_it(blob->
out_list());
175 for (ol_it.mark_cycle_pt(); !ol_it.cycled_list(); ol_it.forward()) {
195 TEST_F(LayoutTest, ArraySizeTest) {
197 for (size = 0; kPolyBlockNames[size][0] !=
'\0'; ++size)
204 TEST_F(LayoutTest, UNLV8087_054) {
205 SetImage(
"8087_054.3B.tif",
"eng");
207 EXPECT_EQ(api_.Recognize(
nullptr), 0);
210 VerifyBlockTextOrder(kStrings8087_054, kBlocks8087_054, it);
217 TEST_F(LayoutTest, HebrewOrderingAndSkew) {
218 SetImage(
"hebrew.png",
"eng");
220 EXPECT_EQ(api_.Recognize(
nullptr), 0);
223 VerifyRoughBlockOrder(
false, it);
224 VerifyTotalContainment(1, it);
227 SetImage(
"hebrew.png",
"heb");
229 EXPECT_EQ(api_.Recognize(
nullptr), 0);
230 it = api_.GetMutableIterator();
232 VerifyRoughBlockOrder(
true, it);
234 VerifyTotalContainment(-1, it);