From 86b0f3625e699120fd4e9f1f7a2cf5433c940948 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 24 Jan 2019 16:10:52 +0100 Subject: [PATCH] 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 --- googletest | 2 +- unittest/applybox_test.cc | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/googletest b/googletest index 2fe3bd994b..bf07131c1d 160000 --- a/googletest +++ b/googletest @@ -1 +1 @@ -Subproject commit 2fe3bd994b3189899d93f1d5a881e725e046fdc2 +Subproject commit bf07131c1d0a4e001daeee8936089f8b438b7f30 diff --git a/unittest/applybox_test.cc b/unittest/applybox_test.cc index 8ad8515c5b..34ef0a7312 100644 --- a/unittest/applybox_test.cc +++ b/unittest/applybox_test.cc @@ -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) @@ -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