Skip to content

Commit 8e7b111

Browse files
committed
Run more unittests with the user's locale
Hopefully this improves the test coverage. Signed-off-by: Stefan Weil <[email protected]>
1 parent 59e31e9 commit 8e7b111

31 files changed

+122
-9
lines changed

unittest/bitvector_test.cc

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const int kPrimeLimit = 1000;
2424
namespace {
2525

2626
class BitVectorTest : public testing::Test {
27+
protected:
28+
void SetUp() override {
29+
std::locale::global(std::locale(""));
30+
}
31+
2732
public:
2833
std::string OutputNameToPath(const std::string& name) {
2934
return file::JoinPath(FLAGS_test_tmpdir, name);

unittest/colpartition_test.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class TestableColPartition : public ColPartition {
2727

2828
class ColPartitionTest : public testing::Test {
2929
protected:
30-
void SetUp() {}
30+
void SetUp() {
31+
std::locale::global(std::locale(""));
32+
}
3133

3234
void TearDown() {}
3335
};

unittest/commandlineflags_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ namespace {
3131

3232
class CommandlineflagsTest : public ::testing::Test {
3333
protected:
34+
void SetUp() {
35+
std::locale::global(std::locale(""));
36+
}
37+
3438
void TestParser(int argc, const char** const_argv) {
3539
TestParser("", argc, const_argv);
3640
}

unittest/dawg_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ namespace {
2727
// aka Directed Acyclic Word Graphs).
2828
class DawgTest : public testing::Test {
2929
protected:
30+
void SetUp() {
31+
std::locale::global(std::locale(""));
32+
}
33+
3034
void LoadWordlist(const std::string& filename, std::set<std::string>* words) const {
3135
std::ifstream file(filename);
3236
if (file.is_open()) {

unittest/denorm_test.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717
namespace {
1818

1919
class DENORMTest : public testing::Test {
20-
public:
21-
void SetUp() {}
20+
protected:
21+
void SetUp() {
22+
std::locale::global(std::locale(""));
23+
}
2224

25+
public:
2326
void TearDown() {}
2427

2528
void ExpectCorrectTransform(const DENORM& denorm, const TPOINT& src,

unittest/equationdetect_test.cc

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class EquationFinderTest : public testing::Test {
105105
string testdata_dir_;
106106

107107
void SetUp() {
108+
std::locale::global(std::locale(""));
108109
string tessdata_dir = file::JoinPath(FLAGS_test_srcdir, "tessdata");
109110
tesseract_.reset(new Tesseract());
110111
tesseract_->init_tesseract(tessdata_dir.c_str(), "eng", OEM_TESSERACT_ONLY);

unittest/heap_test.cc

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ int test_data[] = {8, 1, 2, -4, 7, 9, 65536, 4, 9, 0};
2525

2626
// The fixture for testing GenericHeap and DoublePtr.
2727
class HeapTest : public testing::Test {
28+
protected:
29+
void SetUp() {
30+
std::locale::global(std::locale(""));
31+
}
32+
2833
public:
2934
virtual ~HeapTest();
3035
// Pushes the test data onto both the heap and the KDVector.

unittest/imagedata_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ namespace {
2929

3030
class ImagedataTest : public ::testing::Test {
3131
protected:
32+
void SetUp() {
33+
std::locale::global(std::locale(""));
34+
}
35+
3236
ImagedataTest() {}
3337

3438
// Creates a fake DocumentData, writes it to a file, and returns the filename.

unittest/indexmapbidi_test.cc

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ const int kPrimeLimit = 1000;
2525
namespace {
2626

2727
class IndexMapBiDiTest : public testing::Test {
28+
protected:
29+
void SetUp() {
30+
std::locale::global(std::locale(""));
31+
}
32+
2833
public:
2934
std::string OutputNameToPath(const std::string& name) {
3035
return file::JoinPath(FLAGS_test_tmpdir, name);

unittest/intsimdmatrix_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ namespace {
2727

2828
class IntSimdMatrixTest : public ::testing::Test {
2929
protected:
30+
void SetUp() {
31+
std::locale::global(std::locale(""));
32+
}
33+
3034
// Makes a random weights matrix of the given size.
3135
GENERIC_2D_ARRAY<int8_t> InitRandom(int no, int ni) {
3236
GENERIC_2D_ARRAY<int8_t> a(no, ni, 0);

unittest/ligature_table_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const char kRenderableEngLigatureText[] = "fidelity effigy ſteep";
2424

2525
class LigatureTableTest : public ::testing::Test {
2626
protected:
27+
void SetUp() {
28+
std::locale::global(std::locale(""));
29+
}
30+
2731
static void SetUpTestCase() {
2832
FLAGS_fonts_dir = File::JoinPath(FLAGS_test_srcdir, "testdata");
2933
FLAGS_fontconfig_tmpdir = FLAGS_test_tmpdir;

unittest/linlsq_test.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
namespace {
1717

1818
class LLSQTest : public testing::Test {
19-
public:
20-
void SetUp() {}
19+
protected:
20+
void SetUp() {
21+
std::locale::global(std::locale(""));
22+
}
2123

24+
public:
2225
void TearDown() {}
2326

2427
void ExpectCorrectLine(const LLSQ& llsq, double m, double c, double rms,

unittest/lstm_test.h

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const int kBatchIterations = 1;
4545
// The fixture for testing LSTMTrainer.
4646
class LSTMTrainerTest : public testing::Test {
4747
protected:
48+
void SetUp() {
49+
std::locale::global(std::locale(""));
50+
}
51+
4852
LSTMTrainerTest() {}
4953
std::string TestDataNameToPath(const std::string& name) {
5054
return file::JoinPath(TESTDATA_DIR,

unittest/matrix_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ namespace {
2222

2323
class MatrixTest : public ::testing::Test {
2424
protected:
25+
void SetUp() override {
26+
std::locale::global(std::locale(""));
27+
}
28+
2529
// Fills src_ with data so it can pretend to be a tensor thus:
2630
// dims_=[5, 4, 3, 2]
2731
// array_=[0, 1, 2, ....119]

unittest/networkio_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace {
1212

1313
class NetworkioTest : public ::testing::Test {
1414
protected:
15+
void SetUp() override {
16+
std::locale::global(std::locale(""));
17+
}
18+
1519
// Sets up an Array2d object of the given size, initialized to increasing
1620
// values starting with start.
1721
std::unique_ptr<Array2D<int>> SetupArray(int ysize, int xsize, int start) {

unittest/nthitem_test.cc

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ int test_data[] = {8, 1, 2, -4, 7, 9, 65536, 4, 9, 0, -32767, 6, 7};
2020

2121
// The fixture for testing GenericHeap and DoublePtr.
2222
class NthItemTest : public testing::Test {
23+
protected:
24+
void SetUp() override {
25+
std::locale::global(std::locale(""));
26+
}
27+
2328
public:
2429
virtual ~NthItemTest();
2530
// Pushes the test data onto the KDVector.

unittest/pango_font_info_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ const char* kBadlyFormedHinWords[] = {
4848

4949
class PangoFontInfoTest : public ::testing::Test {
5050
protected:
51+
void SetUp() override {
52+
std::locale::global(std::locale(""));
53+
}
54+
5155
// Creates a fake fonts.conf file that points to the testdata fonts for
5256
// fontconfig to initialize with.
5357
static void SetUpTestCase() {

unittest/qrsequence_test.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ TEST(QRSequenceGenerator, GetBinaryReversedInteger) {
3737
}
3838

3939
// Trivial test fixture for a parameterized test.
40-
class QRSequenceGeneratorTest : public ::testing::TestWithParam<int> {};
40+
class QRSequenceGeneratorTest : public ::testing::TestWithParam<int> {
41+
protected:
42+
void SetUp() {
43+
std::locale::global(std::locale(""));
44+
}
45+
};
4146

4247
TEST_P(QRSequenceGeneratorTest, GeneratesValidSequence) {
4348
const int kRangeSize = GetParam();

unittest/recodebeam_test.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ const float kVi2ndScores[] = {0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01};
6969

7070
class RecodeBeamTest : public ::testing::Test {
7171
protected:
72+
void SetUp() {
73+
std::locale::global(std::locale(""));
74+
}
75+
7276
RecodeBeamTest() : lstm_dict_(&ccutil_) {}
7377
~RecodeBeamTest() { lstm_dict_.End(); }
7478

@@ -153,7 +157,7 @@ class RecodeBeamTest : public ::testing::Test {
153157
!recoder_.IsValidFirstCode(labels[index])));
154158
EXPECT_NE(INVALID_UNICHAR_ID, uni_id)
155159
<< "index=" << index << "/" << labels.size();
156-
// To the extent of truth_utf8, we expect decoded to match, but if
160+
// To the extent of truth_utf8, we expect decoded to match, but if
157161
// transcription is shorter, that is OK too, as we may just be testing
158162
// that we get a valid sequence when padded with random data.
159163
if (uni_id != unichar_null_char_ && decoded.size() < truth_utf8.size())

unittest/rect_test.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ namespace {
1717

1818
class TBOXTest : public testing::Test {
1919
public:
20-
void SetUp() {}
20+
void SetUp() {
21+
std::locale::global(std::locale(""));
22+
}
2123

2224
void TearDown() {}
2325
};

unittest/scanutils_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ namespace {
66

77
class ScanutilsTest : public ::testing::Test {
88
protected:
9+
void SetUp() {
10+
std::locale::global(std::locale(""));
11+
}
12+
913
string TestDataNameToPath(const string& name) {
1014
return file::JoinPath(FLAGS_test_srcdir, "testdata/" + name);
1115
}

unittest/stats_test.cc

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const int kTestData[] = {2, 0, 12, 1, 1, 2, 10, 1, 0, 0, 0, 2, 0, 4, 1, 1};
2222
class STATSTest : public testing::Test {
2323
public:
2424
void SetUp() {
25+
std::locale::global(std::locale(""));
2526
stats_.set_range(0, 16);
2627
for (size_t i = 0; i < ARRAYSIZE(kTestData); ++i)
2728
stats_.add(i, kTestData[i]);

unittest/stridemap_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ namespace {
1010

1111
class StridemapTest : public ::testing::Test {
1212
protected:
13+
void SetUp() {
14+
std::locale::global(std::locale(""));
15+
}
16+
1317
// Sets up an Array2d object of the given size, initialized to increasing
1418
// values starting with start.
1519
std::unique_ptr<Array2D<int>> SetupArray(int ysize, int xsize, int start) {

unittest/stringrenderer_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ using tesseract::StringRenderer;
5050

5151
class StringRendererTest : public ::testing::Test {
5252
protected:
53+
void SetUp() {
54+
std::locale::global(std::locale(""));
55+
}
56+
5357
static void SetUpTestCase() {
5458
l_chooseDisplayProg(L_DISPLAY_WITH_XZGV);
5559
FLAGS_fonts_dir = TESTING_DIR;

unittest/tablefind_test.cc

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class TestableTableFinder : public tesseract::TableFinder {
6666
class TableFinderTest : public testing::Test {
6767
protected:
6868
void SetUp() {
69+
std::locale::global(std::locale(""));
6970
free_boxes_it_.set_to_list(&free_boxes_);
7071
finder_.reset(new TestableTableFinder());
7172
finder_->Init(1, ICOORD(0, 0), ICOORD(500, 500));

unittest/tablerecog_test.cc

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class TestableStructuredTable : public tesseract::StructuredTable {
7171
class SharedTest : public testing::Test {
7272
protected:
7373
void SetUp() {
74+
std::locale::global(std::locale(""));
7475
ICOORD bleft(0, 0);
7576
ICOORD tright(1000, 1000);
7677
text_grid_.reset(new ColPartitionGrid(5, bleft, tright));

unittest/tabvector_test.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ namespace {
2121

2222
class TabVectorTest : public testing::Test {
2323
protected:
24-
void SetUp() { vector_.reset(); }
24+
void SetUp() {
25+
std::locale::global(std::locale(""));
26+
vector_.reset();
27+
}
2528

2629
void TearDown() {}
2730

unittest/tatweel_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ namespace {
77

88
class TatweelTest : public ::testing::Test {
99
protected:
10+
void SetUp() {
11+
std::locale::global(std::locale(""));
12+
}
13+
1014
TatweelTest() {
1115
string filename = TestDataNameToPath("ara.wordlist");
1216
string wordlist;

unittest/tfile_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ namespace {
2323

2424
class TfileTest : public ::testing::Test {
2525
protected:
26+
void SetUp() {
27+
std::locale::global(std::locale(""));
28+
}
29+
2630
TfileTest() {}
2731

2832
// Some data to serialize.

unittest/unicharcompress_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ namespace {
2727

2828
class UnicharcompressTest : public ::testing::Test {
2929
protected:
30+
void SetUp() {
31+
std::locale::global(std::locale(""));
32+
}
33+
3034
// Loads and compresses the given unicharset.
3135
void LoadUnicharset(const std::string& unicharset_name) {
3236
std::string radical_stroke_file =

unittest/unicharset_test.cc

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ using testing::ElementsAreArray;
1919

2020
namespace {
2121

22+
class UnicharsetTest : public ::testing::Test {
23+
protected:
24+
void SetUp() override {
25+
std::locale::global(std::locale(""));
26+
}
27+
};
28+
2229
TEST(UnicharsetTest, Basics) {
2330
// This test verifies basic insertion, unichar_to_id, and encode.
2431
UNICHARSET u;

0 commit comments

Comments
 (0)