diff --git a/test b/test index be9f714313..74f84c3dba 160000 --- a/test +++ b/test @@ -1 +1 @@ -Subproject commit be9f714313a376c1a6b140bee56ed0029fceb05a +Subproject commit 74f84c3dbafa5d9d4e995c7c390ec55e7a57d21f diff --git a/unittest/Makefile.am b/unittest/Makefile.am index c0f9b19825..0ae2c2a83d 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -140,7 +140,7 @@ check_PROGRAMS += qrsequence_test check_PROGRAMS += recodebeam_test check_PROGRAMS += rect_test check_PROGRAMS += resultiterator_test -# check_PROGRAMS += scanutils_test +check_PROGRAMS += scanutils_test check_PROGRAMS += shapetable_test # check_PROGRAMS += stridemap_test check_PROGRAMS += stats_test @@ -302,6 +302,9 @@ rect_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS) resultiterator_test_SOURCES = resultiterator_test.cc resultiterator_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TRAINING_LIBS) $(TESS_LIBS) $(LEPTONICA_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) +scanutils_test_SOURCES = scanutils_test.cc +scanutils_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS) + shapetable_test_SOURCES = shapetable_test.cc shapetable_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TESS_LIBS) diff --git a/unittest/scanutils_test.cc b/unittest/scanutils_test.cc index f54f87dfc0..9e5867c941 100644 --- a/unittest/scanutils_test.cc +++ b/unittest/scanutils_test.cc @@ -1,17 +1,24 @@ -#include +// (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/ccutil/scanutils.h" +#include // for cout + +#include "include_gunit.h" +#include "scanutils.h" namespace { class ScanutilsTest : public ::testing::Test { protected: - void SetUp() { - std::locale::global(std::locale("")); - } - - string TestDataNameToPath(const string& name) { - return file::JoinPath(FLAGS_test_srcdir, "testdata/" + name); + void SetUp() override { } }; @@ -19,9 +26,20 @@ TEST_F(ScanutilsTest, DoesScanf) { // This test verifies that tfscanf does Scanf the same as stdio fscanf. // There are probably a gazillion more test cases that could be added, but // these brought the tesseract and unittest test results in line. - string filename = TestDataNameToPath("scanftest.txt"); + std::string filename = file::JoinPath(TESTDATA_DIR, "scanftest.txt"); FILE* fp1 = fopen(filename.c_str(), "r"); + if (fp1 == nullptr) { + std::cout << "Failed to open file " << filename << '\n'; + GTEST_SKIP(); + return; + } FILE* fp2 = fopen(filename.c_str(), "r"); + if (fp2 == nullptr) { + std::cout << "Failed to open file " << filename << '\n'; + GTEST_SKIP(); + fclose(fp1); + return; + } // The file contains this: // 42.5 17 0.001000 -0.001000 // 0 1 123 -123 0x100 @@ -34,14 +52,24 @@ TEST_F(ScanutilsTest, DoesScanf) { float f1[kNumFloats], f2[kNumFloats]; int r1 = fscanf(fp1, "%f %f %f %f", &f1[0], &f1[1], &f1[2], &f1[3]); int r2 = tfscanf(fp2, "%f %f %f %f", &f2[0], &f2[1], &f2[2], &f2[3]); - EXPECT_EQ(r1, r2); - for (int i = 0; i < kNumFloats; ++i) EXPECT_FLOAT_EQ(f1[i], f2[i]); + EXPECT_EQ(r1, kNumFloats); + EXPECT_EQ(r2, kNumFloats); + if (r1 == r2) { + for (int i = 0; i < r1; ++i) { + EXPECT_FLOAT_EQ(f1[i], f2[i]); + } + } const int kNumInts = 5; int i1[kNumInts], i2[kNumInts]; r1 = fscanf(fp1, "%d %d %d %d %i", &i1[0], &i1[1], &i1[2], &i1[3], &i1[4]); r2 = tfscanf(fp2, "%d %d %d %d %i", &i2[0], &i2[1], &i2[2], &i2[3], &i2[4]); - EXPECT_EQ(r1, r2); - for (int i = 0; i < kNumInts; ++i) EXPECT_EQ(i1[i], i2[i]); + EXPECT_EQ(r1, kNumInts); + EXPECT_EQ(r2, kNumInts); + if (r1 == r2) { + for (int i = 0; i < kNumInts; ++i) { + EXPECT_EQ(i1[i], i2[i]); + } + } const int kStrLen = 1024; char s1[kStrLen]; char s2[kStrLen]; @@ -81,6 +109,8 @@ TEST_F(ScanutilsTest, DoesScanf) { EXPECT_EQ(r1, r2); EXPECT_EQ(1, r2); EXPECT_EQ(i1[0], i2[0]); + fclose(fp2); + fclose(fp1); } } // namespace