Skip to content

Commit 86b0f36

Browse files
committed
unittest: Skip test is traineddata is missing in applybox_test
Many tests have preconditions like a correct version of the test submodule or installed traineddata files at the right location. They fail or even crash if those preconditions are not met. The latest version of Googletest supports skipping single tests with GTEST_SKIP which is used here to skip tests in applybox_test when tessdata/eng.traineddata is missing. Signed-off-by: Stefan Weil <[email protected]>
1 parent 87a4fba commit 86b0f36

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

googletest

Submodule googletest updated 190 files

unittest/applybox_test.cc

+15-7
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ class ApplyBoxTest : public testing::Test {
3939
ApplyBoxTest() { src_pix_ = nullptr; }
4040
~ApplyBoxTest() { pixDestroy(&src_pix_); }
4141

42-
void SetImage(const char* filename) {
42+
bool SetImage(const char* filename) {
43+
bool found = false;
4344
pixDestroy(&src_pix_);
4445
src_pix_ = pixRead(TestDataNameToPath(filename).c_str());
45-
api_.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY);
46-
api_.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);
47-
api_.SetImage(src_pix_);
48-
api_.SetVariable("tessedit_make_boxes_from_boxes", "1");
49-
api_.SetInputName(TestDataNameToPath(filename).c_str());
46+
if (api_.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY) != -1) {
47+
api_.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);
48+
api_.SetImage(src_pix_);
49+
api_.SetVariable("tessedit_make_boxes_from_boxes", "1");
50+
api_.SetInputName(TestDataNameToPath(filename).c_str());
51+
found = true;
52+
}
53+
return found;
5054
}
5155

5256
// Runs ApplyBoxes (via setting the appropriate variables and Recognize)
@@ -56,7 +60,11 @@ class ApplyBoxTest : public testing::Test {
5660
// otherwise the input box file is assumed to have character-level boxes.
5761
void VerifyBoxesAndText(const char* imagefile, const char* truth_str,
5862
const char* target_box_file, bool line_mode) {
59-
SetImage(imagefile);
63+
if (!SetImage(imagefile)) {
64+
// eng.traineddata not found or other problem during Init.
65+
GTEST_SKIP();
66+
return;
67+
}
6068
if (line_mode)
6169
api_.SetVariable("tessedit_resegment_from_line_boxes", "1");
6270
else

0 commit comments

Comments
 (0)