From 540929976309b5662c73534079ffcad951f98bd1 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 29 Jun 2019 11:43:12 +0200 Subject: [PATCH] unittest: Fix tests which need Tensorflow headers Signed-off-by: Stefan Weil --- unittest/Makefile.am | 9 +++++++++ unittest/normstrngs_test.cc | 12 +++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/unittest/Makefile.am b/unittest/Makefile.am index 04d0d34e72..36d7361da7 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -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 @@ -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 @@ -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 @@ -282,6 +289,7 @@ 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 @@ -289,6 +297,7 @@ pango_font_info_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TRAINING_LIBS) $(LEP 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) diff --git a/unittest/normstrngs_test.cc b/unittest/normstrngs_test.cc index 716981569e..f833db86f3 100644 --- a/unittest/normstrngs_test.cc +++ b/unittest/normstrngs_test.cc @@ -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" @@ -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) { @@ -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;