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 <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2019-05-16 18:07:32 +02:00
parent 780986ebfb
commit 59e31e958b
6 changed files with 80 additions and 3 deletions

View File

@ -234,6 +234,10 @@ TEST_F(TesseractTest, BasicLSTMTest) {
// errors due to float/int conversions (e.g., see OUTLINE::move() in
// ccstruct/poutline.h) Instead, we do a loose check.
TEST_F(TesseractTest, LSTMGeometryTest) {
#ifdef DISABLED_LEGACY_ENGINE
// Skip test because TessBaseAPI::GetPageRes is missing.
GTEST_SKIP();
#else
Pix* src_pix = pixRead(TestDataNameToPath("deslant.tif").c_str());
FriendlyTessBaseAPI api;
api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_LSTM_ONLY);
@ -272,6 +276,7 @@ TEST_F(TesseractTest, LSTMGeometryTest) {
}
}
pixDestroy(&src_pix);
#endif
}
TEST_F(TesseractTest, InitConfigOnlyTest) {

View File

@ -26,6 +26,11 @@ const int kThetaBuckets = 13;
namespace {
class IntFeatureMapTest : public testing::Test {
protected:
void SetUp() {
std::locale::global(std::locale(""));
}
public:
// Expects that the given vector has contiguous integer values in the
// range [start, end).
@ -38,6 +43,10 @@ class IntFeatureMapTest : public testing::Test {
// Tests the IntFeatureMap and implicitly the IntFeatureSpace underneath.
TEST_F(IntFeatureMapTest, Exhaustive) {
#ifdef DISABLED_LEGACY_ENGINE
// Skip test because IntFeatureSpace is missing.
GTEST_SKIP();
#else
IntFeatureSpace space;
space.Init(kXBuckets, kYBuckets, kThetaBuckets);
IntFeatureMap map;
@ -117,6 +126,7 @@ TEST_F(IntFeatureMapTest, Exhaustive) {
ExpectContiguous(map_features, 0, total_buckets - 2);
EXPECT_EQ(total_buckets - 2, map.compact_size());
EXPECT_EQ(total_buckets, map.sparse_size());
#endif
}
} // namespace.

View File

@ -61,12 +61,14 @@ static const int kNumAnswers = kNumNonReject + 2 * (kNumTop2Errs - kNumTopNErrs)
(kNumTop1Errs - kNumTop2Errs) +
(kNumTopTopErrs - kNumTop1Errs);
#ifndef DISABLED_LEGACY_ENGINE
static bool safe_strto32(const std::string& str, int* pResult)
{
long n = strtol(str.c_str(), nullptr, 0);
*pResult = n;
return true;
}
#endif
namespace tesseract {
@ -160,7 +162,12 @@ const double kMin1lDistance = 0.25;
// The fixture for testing Tesseract.
class MasterTrainerTest : public testing::Test {
#ifndef DISABLED_LEGACY_ENGINE
protected:
void SetUp() {
std::locale::global(std::locale(""));
}
std::string TestDataNameToPath(const std::string& name) {
return file::JoinPath(TESTING_DIR, name);
}
@ -252,19 +259,29 @@ class MasterTrainerTest : public testing::Test {
// Objects declared here can be used by all tests in the test case for Foo.
ShapeTable* shape_table_;
MasterTrainer* master_trainer_;
#endif
};
// Tests that the MasterTrainer correctly loads its data and reaches the correct
// conclusion over the distance between Arial I l and 1.
TEST_F(MasterTrainerTest, Il1Test) {
#ifdef DISABLED_LEGACY_ENGINE
// Skip test because LoadTrainingData is missing.
GTEST_SKIP();
#else
// Initialize the master_trainer_ and load the Arial tr file.
LoadMasterTrainer();
VerifyIl1();
#endif
}
// Tests the ErrorCounter using a MockClassifier to check that it counts
// error categories correctly.
TEST_F(MasterTrainerTest, ErrorCounterTest) {
#ifdef DISABLED_LEGACY_ENGINE
// Skip test because LoadTrainingData is missing.
GTEST_SKIP();
#else
// Initialize the master_trainer_ from the saved tmp file.
LoadMasterTrainer();
// Add the space character to the shape_table_ if not already present to
@ -303,6 +320,7 @@ TEST_F(MasterTrainerTest, ErrorCounterTest) {
EXPECT_EQ(kNumAnswers, result_values[tesseract::CT_NUM_RESULTS]);
delete shape_classifier;
#endif
}
} // namespace.

View File

@ -32,7 +32,8 @@ class TestClass : public testing::Test {
protected:
};
void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
#ifndef DISABLED_LEGACY_ENGINE
static void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
// log.info() << tessdatadir << " for image: " << imgname << std::endl;
std::unique_ptr<tesseract::TessBaseAPI> api(new tesseract::TessBaseAPI());
ASSERT_FALSE(api->Init(tessdatadir, "osd"))
@ -55,14 +56,20 @@ void OSDTester(int expected_deg, const char* imgname, const char* tessdatadir) {
api->End();
pixDestroy(&image);
}
#endif
class OSDTest : public TestClass,
public ::testing::WithParamInterface<
std::tuple<int, const char*, const char*>> {};
TEST_P(OSDTest, MatchOrientationDegrees) {
#ifdef DISABLED_LEGACY_ENGINE
// Skip test because TessBaseAPI::DetectOrientationScript is missing.
GTEST_SKIP();
#else
OSDTester(std::get<0>(GetParam()), std::get<1>(GetParam()),
std::get<2>(GetParam()));
#endif
}
INSTANTIATE_TEST_CASE_P(

View File

@ -21,6 +21,7 @@ namespace {
// Test some basic I/O of params model files (automated learning of language
// model weights).
#ifndef DISABLED_LEGACY_ENGINE
static bool LoadFromFile(tesseract::ParamsModel& model, const char* lang, const char* full_path) {
tesseract::TFile fp;
if (!fp.Open(full_path, nullptr)) {
@ -29,9 +30,15 @@ static bool LoadFromFile(tesseract::ParamsModel& model, const char* lang, const
}
return model.LoadFromFp(lang, &fp);
}
#endif
class ParamsModelTest : public testing::Test {
#ifndef DISABLED_LEGACY_ENGINE
protected:
void SetUp() override {
std::locale::global(std::locale(""));
}
std::string TestDataNameToPath(const std::string& name) const {
return file::JoinPath(TESTDATA_DIR, name);
}
@ -52,10 +59,16 @@ class ParamsModelTest : public testing::Test {
EXPECT_TRUE(LoadFromFile(duplicate_model, "eng", out_file.c_str()));
EXPECT_TRUE(orig_model.Equivalent(duplicate_model));
}
#endif
};
TEST_F(ParamsModelTest, TestEngParamsModelIO) {
#ifdef DISABLED_LEGACY_ENGINE
// Skip test because ParamsModel::LoadFromFp is missing.
GTEST_SKIP();
#else
TestParamsModelRoundTrip("eng.params_model");
#endif
}
} // namespace

View File

@ -22,7 +22,9 @@
namespace {
using tesseract::Shape;
#ifndef DISABLED_LEGACY_ENGINE
using tesseract::Shape;
using tesseract::ShapeTable;
using tesseract::TFile;
using tesseract::UnicharAndFonts;
@ -52,11 +54,22 @@ static void Expect352(int font_id, const Shape& shape) {
EXPECT_TRUE(shape.IsSubsetOf(shape));
}
#endif
// The fixture for testing Shape.
class ShapeTest : public testing::Test {};
class ShapeTest : public testing::Test {
protected:
void SetUp() {
std::locale::global(std::locale(""));
}
};
// Tests that a Shape works as expected for all the basic functions.
TEST_F(ShapeTest, BasicTest) {
#ifdef DISABLED_LEGACY_ENGINE
// Skip test because Shape is missing.
GTEST_SKIP();
#else
Shape shape1;
EXPECT_EQ(0, shape1.size());
Setup352(101, &shape1);
@ -80,10 +93,15 @@ TEST_F(ShapeTest, BasicTest) {
// and still pass afterwards.
Expect352(101, shape1);
Expect352(101, shape2);
#endif
}
// Tests AddShape separately, as it takes quite a bit of work.
TEST_F(ShapeTest, AddShapeTest) {
#ifdef DISABLED_LEGACY_ENGINE
// Skip test because Shape is missing.
GTEST_SKIP();
#else
Shape shape1;
Setup352(101, &shape1);
Expect352(101, shape1);
@ -107,6 +125,7 @@ TEST_F(ShapeTest, AddShapeTest) {
EXPECT_FALSE(shape1.ContainsUnicharAndFont(3, 110));
EXPECT_FALSE(shape1.ContainsUnicharAndFont(7, 110));
EXPECT_FALSE(shape1.IsEqualUnichars(&shape2));
#endif
}
// The fixture for testing Shape.
@ -114,6 +133,10 @@ class ShapeTableTest : public testing::Test {};
// Tests that a Shape works as expected for all the basic functions.
TEST_F(ShapeTableTest, FullTest) {
#ifdef DISABLED_LEGACY_ENGINE
// Skip test because Shape is missing.
GTEST_SKIP();
#else
Shape shape1;
Setup352(101, &shape1);
// Build a shape table with the same data, but in separate shapes.
@ -157,6 +180,7 @@ TEST_F(ShapeTableTest, FullTest) {
EXPECT_EQ(1, st2.NumShapes());
EXPECT_TRUE(st2.MutableShape(0)->IsEqualUnichars(&shape1));
EXPECT_TRUE(st2.AnyMultipleUnichars());
#endif
}
} // namespace