Skip to content

Commit 9e66fb9

Browse files
committed
unittest: Format code
It was formatted with clang-format-7 -i unittest/*.{c*,h}. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 0f3206d commit 9e66fb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1484
-1619
lines changed

unittest/apiexample_test.cc

+66-67
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// File: apiexample_test.cc
33
// Description: Api Test for Tesseract using text fixtures and parameters.
44
// Tests for Devanagari, Latin and Arabic scripts are disabled by default.
5-
// Disabled tests can be run when required by using the --gtest_also_run_disabled_tests argument.
5+
// Disabled tests can be run when required by using the
6+
// --gtest_also_run_disabled_tests argument.
67
// ./unittest/apiexample_test --gtest_also_run_disabled_tests
78
//
89
// Author: ShreeDevi Kumar
@@ -21,91 +22,89 @@
2122
// expects clone of tessdata_fast repo in ../../tessdata_fast
2223

2324
//#include "log.h"
24-
#include "include_gunit.h"
25-
#include "baseapi.h"
26-
#include "leptonica/allheaders.h"
27-
#include <iostream>
28-
#include <string>
29-
#include <fstream>
30-
#include <locale>
3125
#include <limits.h>
3226
#include <time.h>
27+
#include <fstream>
28+
#include <iostream>
29+
#include <locale>
30+
#include <string>
31+
#include "baseapi.h"
32+
#include "include_gunit.h"
33+
#include "leptonica/allheaders.h"
3334

3435
namespace {
3536

3637
class QuickTest : public testing::Test {
3738
protected:
38-
virtual void SetUp() {
39-
start_time_ = time(nullptr);
40-
}
39+
virtual void SetUp() { start_time_ = time(nullptr); }
4140
virtual void TearDown() {
4241
const time_t end_time = time(nullptr);
43-
EXPECT_TRUE(end_time - start_time_ <=55) << "The test took too long - " << ::testing::PrintToString(end_time - start_time_);
42+
EXPECT_TRUE(end_time - start_time_ <= 55)
43+
<< "The test took too long - "
44+
<< ::testing::PrintToString(end_time - start_time_);
4445
}
4546
time_t start_time_;
46-
};
47+
};
4748

48-
void OCRTester(const char* imgname, const char* groundtruth, const char* tessdatadir, const char* lang) {
49-
//log.info() << tessdatadir << " for language: " << lang << std::endl;
50-
char *outText;
51-
std::locale loc("C"); // You can also use "" for the default system locale
52-
std::ifstream file(groundtruth);
53-
file.imbue(loc); // Use it for file input
54-
std::string gtText((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
55-
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
56-
ASSERT_FALSE(api->Init(tessdatadir, lang)) << "Could not initialize tesseract.";
57-
Pix *image = pixRead(imgname);
58-
ASSERT_TRUE(image != nullptr) << "Failed to read test image.";
59-
api->SetImage(image);
60-
outText = api->GetUTF8Text();
61-
EXPECT_EQ(gtText,outText) << "Phototest.tif OCR does not match ground truth for " << ::testing::PrintToString(lang);
62-
api->End();
63-
delete [] outText;
64-
pixDestroy(&image);
65-
}
49+
void OCRTester(const char* imgname, const char* groundtruth,
50+
const char* tessdatadir, const char* lang) {
51+
// log.info() << tessdatadir << " for language: " << lang << std::endl;
52+
char* outText;
53+
std::locale loc("C"); // You can also use "" for the default system locale
54+
std::ifstream file(groundtruth);
55+
file.imbue(loc); // Use it for file input
56+
std::string gtText((std::istreambuf_iterator<char>(file)),
57+
std::istreambuf_iterator<char>());
58+
tesseract::TessBaseAPI* api = new tesseract::TessBaseAPI();
59+
ASSERT_FALSE(api->Init(tessdatadir, lang))
60+
<< "Could not initialize tesseract.";
61+
Pix* image = pixRead(imgname);
62+
ASSERT_TRUE(image != nullptr) << "Failed to read test image.";
63+
api->SetImage(image);
64+
outText = api->GetUTF8Text();
65+
EXPECT_EQ(gtText, outText)
66+
<< "Phototest.tif OCR does not match ground truth for "
67+
<< ::testing::PrintToString(lang);
68+
api->End();
69+
delete[] outText;
70+
pixDestroy(&image);
71+
}
6672

67-
class MatchGroundTruth : public QuickTest ,
68-
public ::testing::WithParamInterface<const char*> {
69-
};
73+
class MatchGroundTruth : public QuickTest,
74+
public ::testing::WithParamInterface<const char*> {};
7075

71-
TEST_P(MatchGroundTruth, FastPhototestOCR) {
72-
OCRTester(TESTING_DIR "/phototest.tif",
73-
TESTING_DIR "/phototest.txt",
74-
TESSDATA_DIR "_fast", GetParam());
75-
}
76+
TEST_P(MatchGroundTruth, FastPhototestOCR) {
77+
OCRTester(TESTING_DIR "/phototest.tif", TESTING_DIR "/phototest.txt",
78+
TESSDATA_DIR "_fast", GetParam());
79+
}
7680

77-
TEST_P(MatchGroundTruth, BestPhototestOCR) {
78-
OCRTester(TESTING_DIR "/phototest.tif",
79-
TESTING_DIR "/phototest.txt",
80-
TESSDATA_DIR "_best", GetParam());
81-
}
81+
TEST_P(MatchGroundTruth, BestPhototestOCR) {
82+
OCRTester(TESTING_DIR "/phototest.tif", TESTING_DIR "/phototest.txt",
83+
TESSDATA_DIR "_best", GetParam());
84+
}
8285

83-
TEST_P(MatchGroundTruth, TessPhototestOCR) {
84-
OCRTester(TESTING_DIR "/phototest.tif",
85-
TESTING_DIR "/phototest.txt",
86-
TESSDATA_DIR , GetParam());
87-
}
86+
TEST_P(MatchGroundTruth, TessPhototestOCR) {
87+
OCRTester(TESTING_DIR "/phototest.tif", TESTING_DIR "/phototest.txt",
88+
TESSDATA_DIR, GetParam());
89+
}
8890

89-
INSTANTIATE_TEST_CASE_P( Eng, MatchGroundTruth,
90-
::testing::Values("eng") );
91-
INSTANTIATE_TEST_CASE_P( DISABLED_Latin, MatchGroundTruth,
92-
::testing::Values("script/Latin") );
93-
INSTANTIATE_TEST_CASE_P( DISABLED_Deva, MatchGroundTruth,
94-
::testing::Values("script/Devanagari") );
95-
INSTANTIATE_TEST_CASE_P( DISABLED_Arabic, MatchGroundTruth,
96-
::testing::Values("script/Arabic") );
91+
INSTANTIATE_TEST_CASE_P(Eng, MatchGroundTruth, ::testing::Values("eng"));
92+
INSTANTIATE_TEST_CASE_P(DISABLED_Latin, MatchGroundTruth,
93+
::testing::Values("script/Latin"));
94+
INSTANTIATE_TEST_CASE_P(DISABLED_Deva, MatchGroundTruth,
95+
::testing::Values("script/Devanagari"));
96+
INSTANTIATE_TEST_CASE_P(DISABLED_Arabic, MatchGroundTruth,
97+
::testing::Values("script/Arabic"));
9798

98-
class EuroText : public QuickTest {
99-
};
99+
class EuroText : public QuickTest {};
100100

101-
TEST_F(EuroText, FastLatinOCR) {
102-
OCRTester(TESTING_DIR "/eurotext.tif",
103-
TESTING_DIR "/eurotext.txt",
104-
TESSDATA_DIR "_fast", "script/Latin");
105-
}
101+
TEST_F(EuroText, FastLatinOCR) {
102+
OCRTester(TESTING_DIR "/eurotext.tif", TESTING_DIR "/eurotext.txt",
103+
TESSDATA_DIR "_fast", "script/Latin");
104+
}
106105

107-
// script/Latin for eurotext.tif does not match groundtruth
108-
// for tessdata & tessdata_best.
109-
// so do not test these here.
106+
// script/Latin for eurotext.tif does not match groundtruth
107+
// for tessdata & tessdata_best.
108+
// so do not test these here.
110109

111110
} // namespace

unittest/applybox_test.cc

+16-23
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,13 @@ class ApplyBoxTest : public testing::Test {
3131
std::string TestDataNameToPath(const std::string& name) {
3232
return file::JoinPath(TESTING_DIR, name);
3333
}
34-
std::string TessdataPath() {
35-
return TESSDATA_DIR;
36-
}
34+
std::string TessdataPath() { return TESSDATA_DIR; }
3735
std::string OutputNameToPath(const std::string& name) {
3836
return file::JoinPath(FLAGS_test_tmpdir, name);
3937
}
4038

41-
ApplyBoxTest() {
42-
src_pix_ = NULL;
43-
}
44-
~ApplyBoxTest() {
45-
pixDestroy(&src_pix_);
46-
}
39+
ApplyBoxTest() { src_pix_ = NULL; }
40+
~ApplyBoxTest() { pixDestroy(&src_pix_); }
4741

4842
void SetImage(const char* filename) {
4943
pixDestroy(&src_pix_);
@@ -70,7 +64,7 @@ class ApplyBoxTest : public testing::Test {
7064
api_.Recognize(NULL);
7165
char* ocr_text = api_.GetUTF8Text();
7266
EXPECT_STREQ(truth_str, ocr_text);
73-
delete [] ocr_text;
67+
delete[] ocr_text;
7468
// Test the boxes by reading the target box file in parallel with the
7569
// bounding boxes in the ocr output.
7670
std::string box_filename = TestDataNameToPath(target_box_file);
@@ -80,22 +74,21 @@ class ApplyBoxTest : public testing::Test {
8074
ResultIterator* it = api_.GetIterator();
8175
do {
8276
int left, top, right, bottom;
83-
EXPECT_TRUE(it->BoundingBox(tesseract::RIL_SYMBOL,
84-
&left, &top, &right, &bottom));
85-
TBOX ocr_box(ICOORD(left, height - bottom),
86-
ICOORD(right, height - top));
77+
EXPECT_TRUE(
78+
it->BoundingBox(tesseract::RIL_SYMBOL, &left, &top, &right, &bottom));
79+
TBOX ocr_box(ICOORD(left, height - bottom), ICOORD(right, height - top));
8780
int line_number;
8881
TBOX truth_box;
8982
STRING box_text;
90-
EXPECT_TRUE(ReadNextBox(0, &line_number, box_file, &box_text,
91-
&truth_box));
83+
EXPECT_TRUE(
84+
ReadNextBox(0, &line_number, box_file, &box_text, &truth_box));
9285
// Testing for major overlap is a bit weak, but if they all
9386
// major overlap successfully, then it has to be fairly close.
9487
EXPECT_TRUE(ocr_box.major_overlap(truth_box));
9588
// Also check that the symbol text matches the box text.
9689
char* symbol_text = it->GetUTF8Text(tesseract::RIL_SYMBOL);
9790
EXPECT_STREQ(box_text.string(), symbol_text);
98-
delete [] symbol_text;
91+
delete[] symbol_text;
9992
} while (it->Next(tesseract::RIL_SYMBOL));
10093
delete it;
10194
}
@@ -107,14 +100,14 @@ class ApplyBoxTest : public testing::Test {
107100

108101
// Tests character-level applyboxes on normal Times New Roman.
109102
TEST_F(ApplyBoxTest, TimesCharLevel) {
110-
VerifyBoxesAndText("trainingtimes.tif", kTruthTextWords,
111-
"trainingtimes.box", false);
103+
VerifyBoxesAndText("trainingtimes.tif", kTruthTextWords, "trainingtimes.box",
104+
false);
112105
}
113106

114107
// Tests character-level applyboxes on italic Times New Roman.
115108
TEST_F(ApplyBoxTest, ItalicCharLevel) {
116-
VerifyBoxesAndText("trainingital.tif", kTruthTextWords,
117-
"trainingital.box", false);
109+
VerifyBoxesAndText("trainingital.tif", kTruthTextWords, "trainingital.box",
110+
false);
118111
}
119112

120113
// Tests line-level applyboxes on normal Times New Roman.
@@ -125,8 +118,8 @@ TEST_F(ApplyBoxTest, TimesLineLevel) {
125118

126119
// Tests line-level applyboxes on italic Times New Roman.
127120
TEST_F(ApplyBoxTest, ItalLineLevel) {
128-
VerifyBoxesAndText("trainingitalline.tif", kTruthTextLine,
129-
"trainingital.box", true);
121+
VerifyBoxesAndText("trainingitalline.tif", kTruthTextLine, "trainingital.box",
122+
true);
130123
}
131124

132125
} // namespace

0 commit comments

Comments
 (0)