Skip to content

Commit

Permalink
unittest: Skip test is traineddata is missing in applybox_test
Browse files Browse the repository at this point in the history
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 <sw@weilnetz.de>
  • Loading branch information
stweil committed Jan 24, 2019
1 parent 87a4fba commit 86b0f36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion googletest
Submodule googletest updated 190 files
22 changes: 15 additions & 7 deletions unittest/applybox_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ class ApplyBoxTest : public testing::Test {
ApplyBoxTest() { src_pix_ = nullptr; }
~ApplyBoxTest() { pixDestroy(&src_pix_); }

void SetImage(const char* filename) {
bool SetImage(const char* filename) {
bool found = false;
pixDestroy(&src_pix_);
src_pix_ = pixRead(TestDataNameToPath(filename).c_str());
api_.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY);
api_.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);
api_.SetImage(src_pix_);
api_.SetVariable("tessedit_make_boxes_from_boxes", "1");
api_.SetInputName(TestDataNameToPath(filename).c_str());
if (api_.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY) != -1) {
api_.SetPageSegMode(tesseract::PSM_SINGLE_BLOCK);
api_.SetImage(src_pix_);
api_.SetVariable("tessedit_make_boxes_from_boxes", "1");
api_.SetInputName(TestDataNameToPath(filename).c_str());
found = true;
}
return found;
}

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

0 comments on commit 86b0f36

Please sign in to comment.