Skip to content

Commit

Permalink
unittest: Fix tests which need Tensorflow headers
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Jun 29, 2019
1 parent 89de2bf commit 5409299
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 9 additions & 0 deletions unittest/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ endif
AM_CPPFLAGS += -I$(top_srcdir)/src/viewer
AM_CPPFLAGS += -I$(top_srcdir)/src/wordrec
AM_CPPFLAGS += -I$(top_srcdir)/abseil
if TENSORFLOW
AM_CPPFLAGS += -DINCLUDE_TENSORFLOW
endif

# Build googletest:
check_LTLIBRARIES = libgtest.la libgtest_main.la libgmock.la libgmock_main.la
Expand Down Expand Up @@ -158,7 +161,9 @@ check_PROGRAMS += lstm_squashed_test
check_PROGRAMS += lstm_test
check_PROGRAMS += lstmtrainer_test
check_PROGRAMS += normstrngs_test
if TENSORFLOW
check_PROGRAMS += pango_font_info_test
endif
check_PROGRAMS += unichar_test
check_PROGRAMS += unicharcompress_test
check_PROGRAMS += unicharset_test
Expand Down Expand Up @@ -273,7 +278,9 @@ matrix_test_SOURCES = matrix_test.cc
matrix_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS)

normstrngs_test_SOURCES = normstrngs_test.cc
if TENSORFLOW
normstrngs_test_SOURCES += third_party/utf/rune.c util/utf8/unilib.cc
endif
normstrngs_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS)

nthitem_test_SOURCES = nthitem_test.cc
Expand All @@ -282,13 +289,15 @@ nthitem_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS)
osd_test_SOURCES = osd_test.cc
osd_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS) $(LEPTONICA_LIBS)

if TENSORFLOW
pango_font_info_test_SOURCES = pango_font_info_test.cc
pango_font_info_test_SOURCES += third_party/utf/rune.c
pango_font_info_test_SOURCES += util/utf8/unicodetext.cc util/utf8/unilib.cc
pango_font_info_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TRAINING_LIBS) $(LEPTONICA_LIBS)
pango_font_info_test_LDADD += $(ICU_I18N_LIBS) -lfontconfig
pango_font_info_test_LDADD += -lpangocairo-1.0 -lpangoft2-1.0
pango_font_info_test_LDADD += $(cairo_LIBS) $(pango_LIBS)
endif

paragraphs_test_SOURCES = paragraphs_test.cc
paragraphs_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TESS_LIBS)
Expand Down
12 changes: 9 additions & 3 deletions unittest/normstrngs_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "normstrngs_test.h"
#include "strngs.h"
#include "unichar.h"
#include "util/utf8/unilib.h"
#ifdef INCLUDE_TENSORFLOW
#include "util/utf8/unilib.h" // for UniLib
#endif

#include "include_gunit.h"

Expand Down Expand Up @@ -364,18 +366,22 @@ TEST(NormstrngsTest, SpanUTF8NotWhitespace) {
// Test that the method clones the util/utf8/public/unilib definition of
// interchange validity.
TEST(NormstrngsTest, IsInterchangeValid) {
#ifdef INCLUDE_TENSORFLOW
const int32_t kMinUnicodeValue = 33;
const int32_t kMaxUnicodeValue = 0x10FFFF;
for (int32_t ch = kMinUnicodeValue; ch <= kMaxUnicodeValue; ++ch) {
SCOPED_TRACE(absl::StrFormat("Failed at U+%x", ch));
EXPECT_EQ(UniLib::IsInterchangeValid(ch), IsInterchangeValid(ch));
}
#else
GTEST_SKIP();
#endif
}

// Test that the method clones the util/utf8/public/unilib definition of
// 7-bit ASCII interchange validity.
TEST(NormstrngsTest, IsInterchangeValid7BitAscii) {
#if defined(MISSING_CODE)
#if defined(MISSING_CODE) && defined(INCLUDE_TENSORFLOW)
const int32_t kMinUnicodeValue = 33;
const int32_t kMaxUnicodeValue = 0x10FFFF;
for (int32_t ch = kMinUnicodeValue; ch <= kMaxUnicodeValue; ++ch) {
Expand All @@ -400,7 +406,7 @@ TEST(NormstrngsTest, FullwidthToHalfwidth) {
// U+FFE6 -> U+20A9 (won sign)
EXPECT_EQ(0x20A9, FullwidthToHalfwidth(0xFFE6));

#if defined(MISSING_CODE)
#if defined(MISSING_CODE) && defined(INCLUDE_TENSORFLOW)
// Skipped because of missing UniLib::FullwidthToHalfwidth.
const int32_t kMinUnicodeValue = 33;
const int32_t kMaxUnicodeValue = 0x10FFFF;
Expand Down

0 comments on commit 5409299

Please sign in to comment.