From f407345cbebd0eed5232db76d25ac70faaadfcd2 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 6 Aug 2021 17:08:14 +0200 Subject: [PATCH] unittest: Remove dependency on absl::StrJoin() Signed-off-by: Stefan Weil --- Makefile.am | 10 +++++----- unittest/normstrngs_test.h | 19 +++++++++++++++---- unittest/paragraphs_test.cc | 7 +++++-- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6473b56f..dd8ad360 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1467,7 +1467,7 @@ normstrngs_test_SOURCES += unittest/third_party/utf/rune.c normstrngs_test_SOURCES += unittest/util/utf8/unilib.cc endif # TENSORFLOW normstrngs_test_CPPFLAGS = $(unittest_CPPFLAGS) -normstrngs_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) +normstrngs_test_LDADD = $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) nthitem_test_SOURCES = unittest/nthitem_test.cc nthitem_test_CPPFLAGS = $(unittest_CPPFLAGS) @@ -1595,19 +1595,19 @@ unicharset_test_LDADD = $(TRAINING_LIBS) $(ICU_UC_LIBS) validate_grapheme_test_SOURCES = unittest/validate_grapheme_test.cc validate_grapheme_test_CPPFLAGS = $(unittest_CPPFLAGS) -validate_grapheme_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) +validate_grapheme_test_LDADD = $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) validate_indic_test_SOURCES = unittest/validate_indic_test.cc validate_indic_test_CPPFLAGS = $(unittest_CPPFLAGS) -validate_indic_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) +validate_indic_test_LDADD = $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) validate_khmer_test_SOURCES = unittest/validate_khmer_test.cc validate_khmer_test_CPPFLAGS = $(unittest_CPPFLAGS) -validate_khmer_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) +validate_khmer_test_LDADD = $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) validate_myanmar_test_SOURCES = unittest/validate_myanmar_test.cc validate_myanmar_test_CPPFLAGS = $(unittest_CPPFLAGS) -validate_myanmar_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) +validate_myanmar_test_LDADD = $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) validator_test_SOURCES = unittest/validator_test.cc validator_test_CPPFLAGS = $(unittest_CPPFLAGS) diff --git a/unittest/normstrngs_test.h b/unittest/normstrngs_test.h index fbc8ea64..df12fc0c 100644 --- a/unittest/normstrngs_test.h +++ b/unittest/normstrngs_test.h @@ -16,7 +16,6 @@ #include // for std::stringstream #include #include -#include "absl/strings/str_join.h" namespace tesseract { @@ -50,18 +49,30 @@ inline void ExpectGraphemeModeResults(const std::string &str, UnicodeNormMode u_ int unicode_count, int glyph_count, int grapheme_count, const std::string &target_str) { std::vector glyphs; + std::string s; EXPECT_TRUE(NormalizeCleanAndSegmentUTF8( u_mode, OCRNorm::kNone, GraphemeNormMode::kIndividualUnicodes, true, str.c_str(), &glyphs)); EXPECT_EQ(glyphs.size(), unicode_count) << PrintStringVectorWithUnicodes(glyphs); - EXPECT_EQ(target_str, absl::StrJoin(glyphs.begin(), glyphs.end(), "")); + for (auto &glyph : glyphs) { + s += glyph; + } + EXPECT_EQ(target_str, s); EXPECT_TRUE(NormalizeCleanAndSegmentUTF8(u_mode, OCRNorm::kNone, GraphemeNormMode::kGlyphSplit, true, str.c_str(), &glyphs)); EXPECT_EQ(glyphs.size(), glyph_count) << PrintStringVectorWithUnicodes(glyphs); - EXPECT_EQ(target_str, absl::StrJoin(glyphs.begin(), glyphs.end(), "")); + s.clear(); + for (auto &glyph : glyphs) { + s += glyph; + } + EXPECT_EQ(target_str, s); EXPECT_TRUE(NormalizeCleanAndSegmentUTF8(u_mode, OCRNorm::kNone, GraphemeNormMode::kCombined, true, str.c_str(), &glyphs)); EXPECT_EQ(glyphs.size(), grapheme_count) << PrintStringVectorWithUnicodes(glyphs); - EXPECT_EQ(target_str, absl::StrJoin(glyphs.begin(), glyphs.end(), "")); + s.clear(); + for (auto &glyph : glyphs) { + s += glyph; + } + EXPECT_EQ(target_str, s); EXPECT_TRUE(NormalizeCleanAndSegmentUTF8(u_mode, OCRNorm::kNone, GraphemeNormMode::kSingleString, true, str.c_str(), &glyphs)); EXPECT_EQ(glyphs.size(), 1) << PrintStringVectorWithUnicodes(glyphs); diff --git a/unittest/paragraphs_test.cc b/unittest/paragraphs_test.cc index 2a4cc966..c595d74e 100644 --- a/unittest/paragraphs_test.cc +++ b/unittest/paragraphs_test.cc @@ -11,7 +11,6 @@ #include // for std::string -#include "absl/strings/str_join.h" // for absl::StrJoin #include "absl/strings/str_split.h" // for absl::StrSplit #include "include_gunit.h" // for TEST @@ -183,7 +182,11 @@ void EvaluateParagraphDetection(const TextAndModel *correct, int n, std::string s = correct[i].ascii + annotation; dbg_lines.push_back(s); } - LOG(INFO) << "Discrepancy!\n" << absl::StrJoin(dbg_lines, "\n"); + std::string s; + for (auto &dbg_line : dbg_lines) { + s += dbg_line + "\n"; + } + LOG(INFO) << "Discrepancy!\n" << s; } }