Skip to content

Commit 59e31e9

Browse files
committed
Fix more build error for compilation without legacy engine
Skip the tests which need the legacy code. Add also code to those tests to use the user's locale to test that, too. Signed-off-by: Stefan Weil <[email protected]>
1 parent 780986e commit 59e31e9

File tree

6 files changed

+80
-3
lines changed

6 files changed

+80
-3
lines changed

unittest/baseapi_test.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ TEST_F(TesseractTest, BasicLSTMTest) {
234234
// errors due to float/int conversions (e.g., see OUTLINE::move() in
235235
// ccstruct/poutline.h) Instead, we do a loose check.
236236
TEST_F(TesseractTest, LSTMGeometryTest) {
237+
#ifdef DISABLED_LEGACY_ENGINE
238+
// Skip test because TessBaseAPI::GetPageRes is missing.
239+
GTEST_SKIP();
240+
#else
237241
Pix* src_pix = pixRead(TestDataNameToPath("deslant.tif").c_str());
238242
FriendlyTessBaseAPI api;
239243
api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_LSTM_ONLY);
@@ -272,6 +276,7 @@ TEST_F(TesseractTest, LSTMGeometryTest) {
272276
}
273277
}
274278
pixDestroy(&src_pix);
279+
#endif
275280
}
276281

277282
TEST_F(TesseractTest, InitConfigOnlyTest) {

unittest/intfeaturemap_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ const int kThetaBuckets = 13;
2626
namespace {
2727

2828
class IntFeatureMapTest : public testing::Test {
29+
protected:
30+
void SetUp() {
31+
std::locale::global(std::locale(""));
32+
}
33+
2934
public:
3035
// Expects that the given vector has contiguous integer values in the
3136
// range [start, end).
@@ -38,6 +43,10 @@ class IntFeatureMapTest : public testing::Test {
3843

3944
// Tests the IntFeatureMap and implicitly the IntFeatureSpace underneath.
4045
TEST_F(IntFeatureMapTest, Exhaustive) {
46+
#ifdef DISABLED_LEGACY_ENGINE
47+
// Skip test because IntFeatureSpace is missing.
48+
GTEST_SKIP();
49+
#else
4150
IntFeatureSpace space;
4251
space.Init(kXBuckets, kYBuckets, kThetaBuckets);
4352
IntFeatureMap map;
@@ -117,6 +126,7 @@ TEST_F(IntFeatureMapTest, Exhaustive) {
117126
ExpectContiguous(map_features, 0, total_buckets - 2);
118127
EXPECT_EQ(total_buckets - 2, map.compact_size());
119128
EXPECT_EQ(total_buckets, map.sparse_size());
129+
#endif
120130
}
121131

122132
} // namespace.

unittest/mastertrainer_test.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ static const int kNumAnswers = kNumNonReject + 2 * (kNumTop2Errs - kNumTopNErrs)
6161
(kNumTop1Errs - kNumTop2Errs) +
6262
(kNumTopTopErrs - kNumTop1Errs);
6363

64+
#ifndef DISABLED_LEGACY_ENGINE
6465
static bool safe_strto32(const std::string& str, int* pResult)
6566
{
6667
long n = strtol(str.c_str(), nullptr, 0);
6768
*pResult = n;
6869
return true;
6970
}
71+
#endif
7072

7173
namespace tesseract {
7274

@@ -160,7 +162,12 @@ const double kMin1lDistance = 0.25;
160162

161163
// The fixture for testing Tesseract.
162164
class MasterTrainerTest : public testing::Test {
165+
#ifndef DISABLED_LEGACY_ENGINE
163166
protected:
167+
void SetUp() {
168+
std::locale::global(std::locale(""));
169+
}
170+
164171
std::string TestDataNameToPath(const std::string& name) {
165172
return file::JoinPath(TESTING_DIR, name);
166173
}
@@ -252,19 +259,29 @@ class MasterTrainerTest : public testing::Test {
252259
// Objects declared here can be used by all tests in the test case for Foo.
253260
ShapeTable* shape_table_;
254261
MasterTrainer* master_trainer_;
262+
#endif
255263
};
256264

257265
// Tests that the MasterTrainer correctly loads its data and reaches the correct
258266
// conclusion over the distance between Arial I l and 1.
259267
TEST_F(MasterTrainerTest, Il1Test) {
268+
#ifdef DISABLED_LEGACY_ENGINE
269+
// Skip test because LoadTrainingData is missing.
270+
GTEST_SKIP();
271+
#else
260272
// Initialize the master_trainer_ and load the Arial tr file.
261273
LoadMasterTrainer();
262274
VerifyIl1();
275+
#endif
263276
}
264277

265278
// Tests the ErrorCounter using a MockClassifier to check that it counts
266279
// error categories correctly.
267280
TEST_F(MasterTrainerTest, ErrorCounterTest) {
281+
#ifdef DISABLED_LEGACY_ENGINE
282+
// Skip test because LoadTrainingData is missing.
283+
GTEST_SKIP();
284+
#else
268285
// Initialize the master_trainer_ from the saved tmp file.
269286
LoadMasterTrainer();
270287
// Add the space character to the shape_table_ if not already present to
@@ -303,6 +320,7 @@ TEST_F(MasterTrainerTest, ErrorCounterTest) {
303320
EXPECT_EQ(kNumAnswers, result_values[tesseract::CT_NUM_RESULTS]);
304321

305322
delete shape_classifier;
323+
#endif
306324
}
307325

308326
} // namespace.

unittest/osd_test.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class TestClass : public testing::Test {
3232
protected:
3333
};
3434

35-
void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
35+
#ifndef DISABLED_LEGACY_ENGINE
36+
static void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
3637
// log.info() << tessdatadir << " for image: " << imgname << std::endl;
3738
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
3839
ASSERT_FALSE(api->Init(tessdatadir, "osd"))
@@ -55,14 +56,20 @@ void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
5556
api->End();
5657
pixDestroy(&image);
5758
}
59+
#endif
5860

5961
class OSDTest : public TestClass,
6062
public ::testing::WithParamInterface<
6163
std::tuple<int, const char*, const char*>> {};
6264

6365
TEST_P(OSDTest, MatchOrientationDegrees) {
66+
#ifdef DISABLED_LEGACY_ENGINE
67+
// Skip test because TessBaseAPI::DetectOrientationScript is missing.
68+
GTEST_SKIP();
69+
#else
6470
OSDTester(std::get<0>(GetParam()), std::get<1>(GetParam()),
6571
std::get<2>(GetParam()));
72+
#endif
6673
}
6774

6875
INSTANTIATE_TEST_CASE_P(

unittest/params_model_test.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace {
2121

2222
// Test some basic I/O of params model files (automated learning of language
2323
// model weights).
24+
#ifndef DISABLED_LEGACY_ENGINE
2425
static bool LoadFromFile(tesseract::ParamsModel& model, const char* lang, const char* full_path) {
2526
tesseract::TFile fp;
2627
if (!fp.Open(full_path, nullptr)) {
@@ -29,9 +30,15 @@ static bool LoadFromFile(tesseract::ParamsModel& model, const char* lang, const
2930
}
3031
return model.LoadFromFp(lang, &fp);
3132
}
33+
#endif
3234

3335
class ParamsModelTest : public testing::Test {
36+
#ifndef DISABLED_LEGACY_ENGINE
3437
protected:
38+
void SetUp() override {
39+
std::locale::global(std::locale(""));
40+
}
41+
3542
std::string TestDataNameToPath(const std::string& name) const {
3643
return file::JoinPath(TESTDATA_DIR, name);
3744
}
@@ -52,10 +59,16 @@ class ParamsModelTest : public testing::Test {
5259
EXPECT_TRUE(LoadFromFile(duplicate_model, "eng", out_file.c_str()));
5360
EXPECT_TRUE(orig_model.Equivalent(duplicate_model));
5461
}
62+
#endif
5563
};
5664

5765
TEST_F(ParamsModelTest, TestEngParamsModelIO) {
66+
#ifdef DISABLED_LEGACY_ENGINE
67+
// Skip test because ParamsModel::LoadFromFp is missing.
68+
GTEST_SKIP();
69+
#else
5870
TestParamsModelRoundTrip("eng.params_model");
71+
#endif
5972
}
6073

6174
} // namespace

unittest/shapetable_test.cc

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
namespace {
2424

25-
using tesseract::Shape;
25+
#ifndef DISABLED_LEGACY_ENGINE
26+
27+
using tesseract::Shape;
2628
using tesseract::ShapeTable;
2729
using tesseract::TFile;
2830
using tesseract::UnicharAndFonts;
@@ -52,11 +54,22 @@ static void Expect352(int font_id, const Shape& shape) {
5254
EXPECT_TRUE(shape.IsSubsetOf(shape));
5355
}
5456

57+
#endif
58+
5559
// The fixture for testing Shape.
56-
class ShapeTest : public testing::Test {};
60+
class ShapeTest : public testing::Test {
61+
protected:
62+
void SetUp() {
63+
std::locale::global(std::locale(""));
64+
}
65+
};
5766

5867
// Tests that a Shape works as expected for all the basic functions.
5968
TEST_F(ShapeTest, BasicTest) {
69+
#ifdef DISABLED_LEGACY_ENGINE
70+
// Skip test because Shape is missing.
71+
GTEST_SKIP();
72+
#else
6073
Shape shape1;
6174
EXPECT_EQ(0, shape1.size());
6275
Setup352(101, &shape1);
@@ -80,10 +93,15 @@ TEST_F(ShapeTest, BasicTest) {
8093
// and still pass afterwards.
8194
Expect352(101, shape1);
8295
Expect352(101, shape2);
96+
#endif
8397
}
8498

8599
// Tests AddShape separately, as it takes quite a bit of work.
86100
TEST_F(ShapeTest, AddShapeTest) {
101+
#ifdef DISABLED_LEGACY_ENGINE
102+
// Skip test because Shape is missing.
103+
GTEST_SKIP();
104+
#else
87105
Shape shape1;
88106
Setup352(101, &shape1);
89107
Expect352(101, shape1);
@@ -107,13 +125,18 @@ TEST_F(ShapeTest, AddShapeTest) {
107125
EXPECT_FALSE(shape1.ContainsUnicharAndFont(3, 110));
108126
EXPECT_FALSE(shape1.ContainsUnicharAndFont(7, 110));
109127
EXPECT_FALSE(shape1.IsEqualUnichars(&shape2));
128+
#endif
110129
}
111130

112131
// The fixture for testing Shape.
113132
class ShapeTableTest : public testing::Test {};
114133

115134
// Tests that a Shape works as expected for all the basic functions.
116135
TEST_F(ShapeTableTest, FullTest) {
136+
#ifdef DISABLED_LEGACY_ENGINE
137+
// Skip test because Shape is missing.
138+
GTEST_SKIP();
139+
#else
117140
Shape shape1;
118141
Setup352(101, &shape1);
119142
// Build a shape table with the same data, but in separate shapes.
@@ -157,6 +180,7 @@ TEST_F(ShapeTableTest, FullTest) {
157180
EXPECT_EQ(1, st2.NumShapes());
158181
EXPECT_TRUE(st2.MutableShape(0)->IsEqualUnichars(&shape1));
159182
EXPECT_TRUE(st2.AnyMultipleUnichars());
183+
#endif
160184
}
161185

162186
} // namespace

0 commit comments

Comments
 (0)