unittest: Remove dependency on absl::StrJoin()

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2021-08-06 17:08:14 +02:00
parent 61b8e301dd
commit f407345cbe
3 changed files with 25 additions and 11 deletions

View File

@ -1467,7 +1467,7 @@ normstrngs_test_SOURCES += unittest/third_party/utf/rune.c
normstrngs_test_SOURCES += unittest/util/utf8/unilib.cc normstrngs_test_SOURCES += unittest/util/utf8/unilib.cc
endif # TENSORFLOW endif # TENSORFLOW
normstrngs_test_CPPFLAGS = $(unittest_CPPFLAGS) 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_SOURCES = unittest/nthitem_test.cc
nthitem_test_CPPFLAGS = $(unittest_CPPFLAGS) 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_SOURCES = unittest/validate_grapheme_test.cc
validate_grapheme_test_CPPFLAGS = $(unittest_CPPFLAGS) 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_SOURCES = unittest/validate_indic_test.cc
validate_indic_test_CPPFLAGS = $(unittest_CPPFLAGS) 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_SOURCES = unittest/validate_khmer_test.cc
validate_khmer_test_CPPFLAGS = $(unittest_CPPFLAGS) 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_SOURCES = unittest/validate_myanmar_test.cc
validate_myanmar_test_CPPFLAGS = $(unittest_CPPFLAGS) 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_SOURCES = unittest/validator_test.cc
validator_test_CPPFLAGS = $(unittest_CPPFLAGS) validator_test_CPPFLAGS = $(unittest_CPPFLAGS)

View File

@ -16,7 +16,6 @@
#include <sstream> // for std::stringstream #include <sstream> // for std::stringstream
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/strings/str_join.h"
namespace tesseract { namespace tesseract {
@ -50,18 +49,30 @@ inline void ExpectGraphemeModeResults(const std::string &str, UnicodeNormMode u_
int unicode_count, int glyph_count, int grapheme_count, int unicode_count, int glyph_count, int grapheme_count,
const std::string &target_str) { const std::string &target_str) {
std::vector<std::string> glyphs; std::vector<std::string> glyphs;
std::string s;
EXPECT_TRUE(NormalizeCleanAndSegmentUTF8( EXPECT_TRUE(NormalizeCleanAndSegmentUTF8(
u_mode, OCRNorm::kNone, GraphemeNormMode::kIndividualUnicodes, true, str.c_str(), &glyphs)); u_mode, OCRNorm::kNone, GraphemeNormMode::kIndividualUnicodes, true, str.c_str(), &glyphs));
EXPECT_EQ(glyphs.size(), unicode_count) << PrintStringVectorWithUnicodes(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, EXPECT_TRUE(NormalizeCleanAndSegmentUTF8(u_mode, OCRNorm::kNone, GraphemeNormMode::kGlyphSplit,
true, str.c_str(), &glyphs)); true, str.c_str(), &glyphs));
EXPECT_EQ(glyphs.size(), glyph_count) << PrintStringVectorWithUnicodes(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, EXPECT_TRUE(NormalizeCleanAndSegmentUTF8(u_mode, OCRNorm::kNone, GraphemeNormMode::kCombined,
true, str.c_str(), &glyphs)); true, str.c_str(), &glyphs));
EXPECT_EQ(glyphs.size(), grapheme_count) << PrintStringVectorWithUnicodes(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, EXPECT_TRUE(NormalizeCleanAndSegmentUTF8(u_mode, OCRNorm::kNone, GraphemeNormMode::kSingleString,
true, str.c_str(), &glyphs)); true, str.c_str(), &glyphs));
EXPECT_EQ(glyphs.size(), 1) << PrintStringVectorWithUnicodes(glyphs); EXPECT_EQ(glyphs.size(), 1) << PrintStringVectorWithUnicodes(glyphs);

View File

@ -11,7 +11,6 @@
#include <string> // for std::string #include <string> // for std::string
#include "absl/strings/str_join.h" // for absl::StrJoin
#include "absl/strings/str_split.h" // for absl::StrSplit #include "absl/strings/str_split.h" // for absl::StrSplit
#include "include_gunit.h" // for TEST #include "include_gunit.h" // for TEST
@ -183,7 +182,11 @@ void EvaluateParagraphDetection(const TextAndModel *correct, int n,
std::string s = correct[i].ascii + annotation; std::string s = correct[i].ascii + annotation;
dbg_lines.push_back(s); 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;
} }
} }