From 8486f59493c395268c9b972412d5717c7634e240 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 5 Aug 2021 10:33:35 +0200 Subject: [PATCH] unittest: Remove dependency on absl::StrFormat() Signed-off-by: Stefan Weil --- Makefile.am | 2 +- unittest/imagedata_test.cc | 5 +++-- unittest/normstrngs_test.cc | 17 ++++++++++++----- unittest/shapetable_test.cc | 7 +++---- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Makefile.am b/Makefile.am index 23391b88..80f15926 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1535,7 +1535,7 @@ scanutils_test_LDADD = $(TRAINING_LIBS) if !DISABLED_LEGACY_ENGINE shapetable_test_SOURCES = unittest/shapetable_test.cc shapetable_test_CPPFLAGS = $(unittest_CPPFLAGS) -shapetable_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) +shapetable_test_LDADD = $(TRAINING_LIBS) endif # !DISABLED_LEGACY_ENGINE stats_test_SOURCES = unittest/stats_test.cc diff --git a/unittest/imagedata_test.cc b/unittest/imagedata_test.cc index 77c0c5ba..3c93ce18 100644 --- a/unittest/imagedata_test.cc +++ b/unittest/imagedata_test.cc @@ -13,7 +13,6 @@ #include #include "absl/strings/str_cat.h" -#include "absl/strings/str_format.h" #include "imagedata.h" #include "include_gunit.h" @@ -42,7 +41,9 @@ protected: DocumentData write_doc("My document"); for (int p = 0; p < num_pages; ++p) { // Make some fake text that is different for each page and save it. - page_texts->push_back(absl::StrFormat("Page %d of %d in doc %u", p, num_pages, doc_id)); + char text[80]; + snprintf(text, sizeof(text), "Page %d of %d in doc %u", p, num_pages, doc_id); + page_texts->push_back(text); // Make an imagedata and put it in the document. ImageData *imagedata = ImageData::Build("noname", p, "eng", fake_image.data(), fake_image.size(), (*page_texts)[p].c_str(), nullptr); diff --git a/unittest/normstrngs_test.cc b/unittest/normstrngs_test.cc index bb2ca5aa..26b050f6 100644 --- a/unittest/normstrngs_test.cc +++ b/unittest/normstrngs_test.cc @@ -11,7 +11,6 @@ #include "normstrngs.h" #include -#include "absl/strings/str_format.h" // for absl::StrFormat #include "include_gunit.h" #include "normstrngs_test.h" #ifdef INCLUDE_TENSORFLOW @@ -315,7 +314,9 @@ TEST(NormstrngsTest, IsWhitespace) { EXPECT_TRUE(IsWhitespace('\n')); // U+2000 through U+200A for (char32 ch = 0x2000; ch <= 0x200A; ++ch) { - SCOPED_TRACE(absl::StrFormat("Failed at U+%x", ch)); + char text[80]; + snprintf(text, sizeof(text), "Failed at U+%x", ch); + SCOPED_TRACE(text); EXPECT_TRUE(IsWhitespace(ch)); } // U+3000 is whitespace @@ -354,7 +355,9 @@ TEST(NormstrngsTest, IsInterchangeValid) { 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)); + char text[80]; + snprintf(text, sizeof(text), "Failed at U+%x", ch); + SCOPED_TRACE(text); EXPECT_EQ(UniLib::IsInterchangeValid(ch), IsInterchangeValid(ch)); } #else @@ -369,7 +372,9 @@ TEST(NormstrngsTest, IsInterchangeValid7BitAscii) { 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)); + char text[80]; + snprintf(text, sizeof(text), "Failed at U+%x", ch); + SCOPED_TRACE(text); std::string str = EncodeAsUTF8(ch); EXPECT_EQ(UniLib::IsInterchangeValid7BitAscii(str), IsInterchangeValid7BitAscii(ch)); } @@ -396,7 +401,9 @@ TEST(NormstrngsTest, FullwidthToHalfwidth) { for (int32_t ch = kMinUnicodeValue; ch <= kMaxUnicodeValue; ++ch) { if (!IsValidCodepoint(ch)) continue; - SCOPED_TRACE(absl::StrFormat("Failed at U+%x", ch)); + char text[80]; + snprintf(text, sizeof(text), "Failed at U+%x", ch); + SCOPED_TRACE(text); std::string str = EncodeAsUTF8(ch); const std::string expected_half_str = UniLib::FullwidthToHalfwidth(str.c_str(), str.length(), true); diff --git a/unittest/shapetable_test.cc b/unittest/shapetable_test.cc index 094d4367..842f5505 100644 --- a/unittest/shapetable_test.cc +++ b/unittest/shapetable_test.cc @@ -12,8 +12,6 @@ #include #include -#include "absl/strings/str_format.h" // for absl::StrFormat - #include "include_gunit.h" #include "serialis.h" @@ -139,8 +137,9 @@ TEST_F(ShapeTableTest, FullTest) { UNICHARSET unicharset; unicharset.unichar_insert(" "); for (int i = 1; i <= 10; ++i) { - std::string class_str = absl::StrFormat("class%d", i); - unicharset.unichar_insert(class_str.c_str()); + char class_str[20]; + snprintf(class_str, sizeof(class_str), "class%d", i); + unicharset.unichar_insert(class_str); } ShapeTable st(unicharset); EXPECT_EQ(0, st.AddShape(3, 101));