34 #include "leptonica/allheaders.h"
38 class QuickTest :
public testing::Test {
40 virtual void SetUp() { start_time_ = time(
nullptr); }
41 virtual void TearDown() {
45 const time_t MAX_SECONDS_FOR_TEST = 240;
49 const time_t MAX_SECONDS_FOR_TEST = 55;
51 const time_t end_time = time(
nullptr);
52 EXPECT_TRUE(end_time - start_time_ <= MAX_SECONDS_FOR_TEST)
53 <<
"The test took too long - "
54 << ::testing::PrintToString(end_time - start_time_);
59 void OCRTester(
const char* imgname,
const char* groundtruth,
60 const char* tessdatadir,
const char* lang) {
64 std::ifstream
file(groundtruth);
67 std::istreambuf_iterator<char>());
69 ASSERT_FALSE(api->Init(tessdatadir, lang))
70 <<
"Could not initialize tesseract.";
71 Pix* image = pixRead(imgname);
72 ASSERT_TRUE(image !=
nullptr) <<
"Failed to read test image.";
74 outText = api->GetUTF8Text();
75 EXPECT_EQ(gtText, outText)
76 <<
"Phototest.tif OCR does not match ground truth for "
77 << ::testing::PrintToString(lang);
83 class MatchGroundTruth :
public QuickTest,
84 public ::testing::WithParamInterface<const char*> {};
86 TEST_P(MatchGroundTruth, FastPhototestOCR) {
87 OCRTester(TESTING_DIR
"/phototest.tif", TESTING_DIR
"/phototest.txt",
88 TESSDATA_DIR
"_fast", GetParam());
91 TEST_P(MatchGroundTruth, BestPhototestOCR) {
92 OCRTester(TESTING_DIR
"/phototest.tif", TESTING_DIR
"/phototest.txt",
93 TESSDATA_DIR
"_best", GetParam());
96 TEST_P(MatchGroundTruth, TessPhototestOCR) {
97 OCRTester(TESTING_DIR
"/phototest.tif", TESTING_DIR
"/phototest.txt",
98 TESSDATA_DIR, GetParam());
101 INSTANTIATE_TEST_CASE_P(Eng, MatchGroundTruth, ::testing::Values(
"eng"));
102 INSTANTIATE_TEST_CASE_P(DISABLED_Latin, MatchGroundTruth,
103 ::testing::Values(
"script/Latin"));
104 INSTANTIATE_TEST_CASE_P(DISABLED_Deva, MatchGroundTruth,
105 ::testing::Values(
"script/Devanagari"));
106 INSTANTIATE_TEST_CASE_P(DISABLED_Arabic, MatchGroundTruth,
107 ::testing::Values(
"script/Arabic"));
109 class EuroText :
public QuickTest {};
111 TEST_F(EuroText, FastLatinOCR) {
112 OCRTester(TESTING_DIR
"/eurotext.tif", TESTING_DIR
"/eurotext.txt",
113 TESSDATA_DIR
"_fast",
"script/Latin");