From 2833db7c67da8d247006ea7110f4278b16d5baec Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 30 Jun 2019 12:36:20 +0200 Subject: [PATCH] unittest: Fix and enable equationdetect_test It requires Tensorflow. Skip one test because equ_gt1.tif is missing. Signed-off-by: Stefan Weil --- unittest/Makefile.am | 9 ++++++- unittest/equationdetect_test.cc | 46 ++++++++++++++++++++++----------- unittest/include_gunit.h | 9 ++++--- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/unittest/Makefile.am b/unittest/Makefile.am index 36d7361d..bc16dfab 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -117,7 +117,9 @@ check_PROGRAMS += cleanapi_test check_PROGRAMS += colpartition_test check_PROGRAMS += dawg_test check_PROGRAMS += denorm_test -# check_PROGRAMS += equationdetect_test +if TENSORFLOW +check_PROGRAMS += equationdetect_test +endif check_PROGRAMS += fileio_test check_PROGRAMS += heap_test check_PROGRAMS += imagedata_test @@ -216,6 +218,11 @@ dawg_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS) denorm_test_SOURCES = denorm_test.cc denorm_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS) +if TENSORFLOW +equationdetect_test_SOURCES = equationdetect_test.cc +equationdetect_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS) +endif + fileio_test_SOURCES = fileio_test.cc fileio_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TESS_LIBS) diff --git a/unittest/equationdetect_test.cc b/unittest/equationdetect_test.cc index 69cf85ea..55c87e2b 100644 --- a/unittest/equationdetect_test.cc +++ b/unittest/equationdetect_test.cc @@ -1,13 +1,26 @@ +// (C) Copyright 2017, Google Inc. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. -#include "tesseract/ccmain/equationdetect.h" #include #include #include -#include "leptonica/include/allheaders.h" -#include "tesseract/ccmain/tesseractclass.h" -#include "tesseract/textord/colpartitiongrid.h" -#include "util/gtl/map_util.h" -#include "util/gtl/stl_util.h" +#include "allheaders.h" +#include "colpartitiongrid.h" +#include "equationdetect.h" +#include "tesseractclass.h" +#include "include_gunit.h" + +using string = std::string; +#include +#include namespace tesseract { @@ -102,19 +115,18 @@ class EquationFinderTest : public testing::Test { std::unique_ptr tesseract_; // The directory for testdata; - string testdata_dir_; + std::string testdata_dir_; void SetUp() { std::locale::global(std::locale("")); - string tessdata_dir = file::JoinPath(FLAGS_test_srcdir, "tessdata"); tesseract_.reset(new Tesseract()); - tesseract_->init_tesseract(tessdata_dir.c_str(), "eng", OEM_TESSERACT_ONLY); + tesseract_->init_tesseract(TESSDATA_DIR, "eng", OEM_TESSERACT_ONLY); tesseract_->set_source_resolution(300); equation_det_.reset( - new TestableEquationDetect(tessdata_dir.c_str(), tesseract_.get())); + new TestableEquationDetect(TESSDATA_DIR, tesseract_.get())); equation_det_->SetResolution(300); - testdata_dir_ = file::JoinPath(FLAGS_test_srcdir, "testdata"); + testdata_dir_ = TESTDATA_DIR; } void TearDown() { @@ -151,7 +163,7 @@ class EquationFinderTest : public testing::Test { } void ClearParts(std::vector* all_parts) { - for (int i = 0; i < all_parts->size(); ++i) { + for (size_t i = 0; i < all_parts->size(); ++i) { (*all_parts)[i]->DeleteBoxes(); delete ((*all_parts)[i]); } @@ -167,8 +179,11 @@ class EquationFinderTest : public testing::Test { }; TEST_F(EquationFinderTest, IdentifySpecialText) { +#if 1 + GTEST_SKIP(); +#else // TODO: missing equ_gt1.tif // Load Image. - string imagefile = file::JoinPath(testdata_dir_, "equ_gt1.tif"); + std::string imagefile = file::JoinPath(testdata_dir_, "equ_gt1.tif"); Pix* pix_binary = pixRead(imagefile.c_str()); CHECK(pix_binary != nullptr && pixGetDepth(pix_binary) == 1); @@ -181,7 +196,7 @@ TEST_F(EquationFinderTest, IdentifySpecialText) { // Identify special texts from to_blocks. TO_BLOCK_IT to_block_it(&to_blocks); - __gnu_cxx::hash_map stt_count; + std::map stt_count; for (to_block_it.mark_cycle_pt(); !to_block_it.cycled_list(); to_block_it.forward()) { TO_BLOCK* to_block = to_block_it.data(); @@ -190,7 +205,7 @@ TEST_F(EquationFinderTest, IdentifySpecialText) { BLOBNBOX* blob = blob_it.data(); // blob->set_special_text_type(BSTT_NONE); equation_det_->RunIdentifySpecialText(blob, 0); - InsertIfNotPresent(&stt_count, blob->special_text_type(), 0); + tensorflow::gtl::InsertIfNotPresent(&stt_count, blob->special_text_type(), 0); stt_count[blob->special_text_type()]++; } } @@ -212,6 +227,7 @@ TEST_F(EquationFinderTest, IdentifySpecialText) { // Release memory. pixDestroy(&pix_binary); +#endif } TEST_F(EquationFinderTest, EstimateTypeForUnichar) { diff --git a/unittest/include_gunit.h b/unittest/include_gunit.h index ac85eeeb..c26e9856 100644 --- a/unittest/include_gunit.h +++ b/unittest/include_gunit.h @@ -52,9 +52,10 @@ public: #define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0])) #define CHECK(test) ASSERT_HOST(test) -#define CHECK_GT(test, value) ASSERT_HOST((test) > (value)) -#define CHECK_LT(test, value) ASSERT_HOST((test) < (value)) -#define CHECK_LE(test, value) ASSERT_HOST((test) <= (value)) -#define CHECK_OK(test) ASSERT_HOST(test) +#define CHECK_EQ(test, value) CHECK((test) == (value)) +#define CHECK_GT(test, value) CHECK((test) > (value)) +#define CHECK_LT(test, value) CHECK((test) < (value)) +#define CHECK_LE(test, value) CHECK((test) <= (value)) +#define CHECK_OK(test) CHECK(test) #endif // TESSERACT_UNITTEST_INCLUDE_GUNIT_H_