Skip to content

Commit

Permalink
Fix and enable shapetable_test
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jan 24, 2019
1 parent bbd23bb commit 6b7f7db
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
10 changes: 7 additions & 3 deletions unittest/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ check_PROGRAMS = \
progress_test \
qrsequence_test \
rect_test \
stringrenderer_test \
shapetable_test \
stats_test \
stringrenderer_test \
tablefind_test \
tablerecog_test \
tabvector_test \
Expand Down Expand Up @@ -255,12 +256,15 @@ qrsequence_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TESS_LIBS)
rect_test_SOURCES = rect_test.cc
rect_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS)

stringrenderer_test_SOURCES = stringrenderer_test.cc
stringrenderer_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TRAINING_LIBS) $(TESS_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) -lfontconfig -lpangocairo-1.0 -lpangoft2-1.0 $(cairo_LIBS) $(pango_LIBS)
shapetable_test_SOURCES = shapetable_test.cc
shapetable_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TESS_LIBS)

stats_test_SOURCES = stats_test.cc
stats_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS)

stringrenderer_test_SOURCES = stringrenderer_test.cc
stringrenderer_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TRAINING_LIBS) $(TESS_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) -lfontconfig -lpangocairo-1.0 -lpangoft2-1.0 $(cairo_LIBS) $(pango_LIBS)

tablefind_test_SOURCES = tablefind_test.cc
tablefind_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS)

Expand Down
26 changes: 20 additions & 6 deletions unittest/shapetable_test.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
// (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 <string>
#include <utility>

#include "tesseract/ccutil/serialis.h"
#include "tesseract/ccutil/unicharset.h"
#include "tesseract/classify/shapetable.h"
#include "absl/strings/str_format.h" // for absl::StrFormat

#include "include_gunit.h"

#include "serialis.h"
#include "shapetable.h"
#include "unicharset.h"

namespace {

Expand All @@ -13,7 +27,7 @@ using tesseract::ShapeTable;
using tesseract::TFile;
using tesseract::UnicharAndFonts;

static string TmpNameToPath(const string& name) {
static std::string TmpNameToPath(const std::string& name) {
return file::JoinPath(FLAGS_test_tmpdir, name);
}

Expand Down Expand Up @@ -48,7 +62,7 @@ TEST_F(ShapeTest, BasicTest) {
Setup352(101, &shape1);
Expect352(101, shape1);
// It should still work after file I/O.
string filename = TmpNameToPath("shapefile");
std::string filename = TmpNameToPath("shapefile");
FILE* fp = fopen(filename.c_str(), "wb");
EXPECT_TRUE(fp != nullptr);
EXPECT_TRUE(shape1.Serialize(fp));
Expand Down Expand Up @@ -106,7 +120,7 @@ TEST_F(ShapeTableTest, FullTest) {
UNICHARSET unicharset;
unicharset.unichar_insert(" ");
for (int i = 1; i <= 10; ++i) {
string class_str = StringPrintf("class%d", i);
std::string class_str = absl::StrFormat("class%d", i);
unicharset.unichar_insert(class_str.c_str());
}
ShapeTable st(unicharset);
Expand Down

0 comments on commit 6b7f7db

Please sign in to comment.