unittest: Remove some dependencies on abseil

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2021-08-04 10:21:01 +02:00
parent d50baec7a7
commit 6b8b1f0007
5 changed files with 30 additions and 38 deletions

View File

@ -1521,7 +1521,7 @@ qrsequence_test_LDADD = $(ABSEIL_LIBS) $(TESS_LIBS)
recodebeam_test_SOURCES = unittest/recodebeam_test.cc recodebeam_test_SOURCES = unittest/recodebeam_test.cc
recodebeam_test_CPPFLAGS = $(unittest_CPPFLAGS) recodebeam_test_CPPFLAGS = $(unittest_CPPFLAGS)
recodebeam_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) recodebeam_test_LDADD = $(TRAINING_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS)
rect_test_SOURCES = unittest/rect_test.cc rect_test_SOURCES = unittest/rect_test.cc
rect_test_CPPFLAGS = $(unittest_CPPFLAGS) rect_test_CPPFLAGS = $(unittest_CPPFLAGS)
@ -1529,7 +1529,7 @@ rect_test_LDADD = $(TESS_LIBS)
resultiterator_test_SOURCES = unittest/resultiterator_test.cc resultiterator_test_SOURCES = unittest/resultiterator_test.cc
resultiterator_test_CPPFLAGS = $(unittest_CPPFLAGS) resultiterator_test_CPPFLAGS = $(unittest_CPPFLAGS)
resultiterator_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) resultiterator_test_LDADD = $(TRAINING_LIBS)
resultiterator_test_LDADD += $(LEPTONICA_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS) resultiterator_test_LDADD += $(LEPTONICA_LIBS) $(ICU_I18N_LIBS) $(ICU_UC_LIBS)
scanutils_test_SOURCES = unittest/scanutils_test.cc scanutils_test_SOURCES = unittest/scanutils_test.cc
@ -1580,7 +1580,7 @@ tatweel_test_LDADD = $(TRAINING_LIBS)
textlineprojection_test_SOURCES = unittest/textlineprojection_test.cc textlineprojection_test_SOURCES = unittest/textlineprojection_test.cc
textlineprojection_test_CPPFLAGS = $(unittest_CPPFLAGS) textlineprojection_test_CPPFLAGS = $(unittest_CPPFLAGS)
textlineprojection_test_LDADD = $(ABSEIL_LIBS) $(TRAINING_LIBS) $(LEPTONICA_LIBS) textlineprojection_test_LDADD = $(TRAINING_LIBS) $(LEPTONICA_LIBS)
tfile_test_SOURCES = unittest/tfile_test.cc tfile_test_SOURCES = unittest/tfile_test.cc
tfile_test_CPPFLAGS = $(unittest_CPPFLAGS) tfile_test_CPPFLAGS = $(unittest_CPPFLAGS)

View File

@ -32,7 +32,6 @@
#include "trainingsample.h" #include "trainingsample.h"
#include "unicharset.h" #include "unicharset.h"
#include "absl/strings/numbers.h" // for safe_strto32
#include "absl/strings/str_split.h" // for absl::StrSplit #include "absl/strings/str_split.h" // for absl::StrSplit
#include <string> #include <string>

View File

@ -22,8 +22,6 @@
#include "helpers.h" #include "helpers.h"
#include "absl/strings/str_format.h" // for absl::StrFormat
namespace tesseract { namespace tesseract {
// Number of characters to test beam search with. // Number of characters to test beam search with.
@ -160,9 +158,9 @@ protected:
if (u_decoded.size() < truth_utf8.size()) { if (u_decoded.size() < truth_utf8.size()) {
const char *str = ccutil_.unicharset.id_to_unichar(unichar_ids[u]); const char *str = ccutil_.unicharset.id_to_unichar(unichar_ids[u]);
total_rating += ratings[u]; total_rating += ratings[u];
LOG(INFO) << absl::StrFormat("%d:u_id=%d=%s, c=%g, r=%g, r_sum=%g @%d", u, unichar_ids[u], LOG(INFO) << u << ":u_id=" << unichar_ids[u] << "=" << str << ", c="
str, certainties[u], ratings[u], total_rating, xcoords[u]) << certainties[u] << ", r=" << ratings[u] << "r_sum="
<< "\n"; << total_rating << " @" << xcoords[u] << "\n";
if (str[0] == ' ') { if (str[0] == ' ') {
total_rating = 0.0f; total_rating = 0.0f;
} }
@ -184,11 +182,9 @@ protected:
} }
w_decoded += word->best_choice->unichar_string().c_str(); w_decoded += word->best_choice->unichar_string().c_str();
} }
LOG(INFO) << absl::StrFormat("Word:%d = %s, c=%g, r=%g, perm=%d", w, LOG(INFO) << "Word:" << w << " = " << word->best_choice->unichar_string()
word->best_choice->unichar_string().c_str(), << ", c=" << word->best_choice->certainty() << ", r=" << word->best_choice->rating()
word->best_choice->certainty(), word->best_choice->rating(), << ", perm=" << word->best_choice->permuter() << "\n";
word->best_choice->permuter())
<< "\n";
} }
std::string w_trunc(w_decoded.data(), truth_utf8.size()); std::string w_trunc(w_decoded.data(), truth_utf8.size());
if (truth_utf8 != w_trunc) { if (truth_utf8 != w_trunc) {

View File

@ -5,7 +5,6 @@
#include <string> #include <string>
#include "scrollview.h" #include "scrollview.h"
#include "absl/strings/str_format.h" // for absl::StrFormat
#include "include_gunit.h" #include "include_gunit.h"
#include "log.h" // for LOG #include "log.h" // for LOG
@ -99,7 +98,7 @@ protected:
pixWrite(outfile.c_str(), pix, IFF_PNG); pixWrite(outfile.c_str(), pix, IFF_PNG);
} }
pix.destroy(); pix.destroy();
LOG(INFO) << absl::StrFormat("At level %d: pix diff = %d\n", level, pixcount); LOG(INFO) << "At level " << level << ": pix diff = " << pixcount << "\n";
EXPECT_LE(pixcount, max_diff); EXPECT_LE(pixcount, max_diff);
// if (base::GetFlag(FLAGS_v) > 1) CHECK_LE(pixcount, max_diff); // if (base::GetFlag(FLAGS_v) > 1) CHECK_LE(pixcount, max_diff);
} }
@ -293,7 +292,8 @@ TEST_F(ResultIteratorTest, EasyTest) {
// Test baseline of the first line. // Test baseline of the first line.
int x1, y1, x2, y2; int x1, y1, x2, y2;
r_it->Baseline(tesseract::RIL_TEXTLINE, &x1, &y1, &x2, &y2); r_it->Baseline(tesseract::RIL_TEXTLINE, &x1, &y1, &x2, &y2);
LOG(INFO) << absl::StrFormat("Baseline (%d,%d)->(%d,%d)", x1, y1, x2, y2) << "\n"; LOG(INFO) << "Baseline ("
<< x1 << ',' << y1 << ")->(" << x2 << ',' << y2 << ")\n";
// Make sure we have a decent vector. // Make sure we have a decent vector.
EXPECT_GE(x2, x1 + 400); EXPECT_GE(x2, x1 + 400);
// The point 200,116 should be very close to the baseline. // The point 200,116 should be very close to the baseline.
@ -315,9 +315,9 @@ TEST_F(ResultIteratorTest, EasyTest) {
float confidence = r_it->Confidence(tesseract::RIL_WORD); float confidence = r_it->Confidence(tesseract::RIL_WORD);
EXPECT_GE(confidence, 80.0f); EXPECT_GE(confidence, 80.0f);
char *word_str = r_it->GetUTF8Text(tesseract::RIL_WORD); char *word_str = r_it->GetUTF8Text(tesseract::RIL_WORD);
LOG(INFO) << absl::StrFormat("Word %s in font %s, id %d, size %d, conf %g", word_str, font, LOG(INFO) << "Word " << word_str << " in font " << font
font_id, pointsize, confidence) << ", id " << font_id << ", size " << pointsize
<< "\n"; << ", conf " << confidence << "\n";
delete[] word_str; delete[] word_str;
EXPECT_FALSE(bold); EXPECT_FALSE(bold);
EXPECT_FALSE(italic); EXPECT_FALSE(italic);
@ -372,8 +372,8 @@ TEST_F(ResultIteratorTest, SmallCapDropCapTest) {
&pointsize, &font_id); &pointsize, &font_id);
char *word_str = r_it->GetUTF8Text(tesseract::RIL_WORD); char *word_str = r_it->GetUTF8Text(tesseract::RIL_WORD);
if (word_str != nullptr) { if (word_str != nullptr) {
LOG(INFO) << absl::StrFormat("Word %s is %s", word_str, smallcaps ? "SMALLCAPS" : "Normal") LOG(INFO) << "Word " << word_str
<< "\n"; << " is " << (smallcaps ? "SMALLCAPS" : "Normal") << "\n";
if (r_it->SymbolIsDropcap()) { if (r_it->SymbolIsDropcap()) {
++found_dropcaps; ++found_dropcaps;
} }
@ -392,7 +392,7 @@ TEST_F(ResultIteratorTest, SmallCapDropCapTest) {
while (s_it.Next(tesseract::RIL_SYMBOL) && !s_it.IsAtBeginningOf(tesseract::RIL_WORD)) { while (s_it.Next(tesseract::RIL_SYMBOL) && !s_it.IsAtBeginningOf(tesseract::RIL_WORD)) {
if (s_it.SymbolIsDropcap()) { if (s_it.SymbolIsDropcap()) {
char *sym_str = s_it.GetUTF8Text(tesseract::RIL_SYMBOL); char *sym_str = s_it.GetUTF8Text(tesseract::RIL_SYMBOL);
LOG(ERROR) << absl::StrFormat("Symbol %s of word %s is dropcap", sym_str, word_str); LOG(ERROR) << "Symbol " << sym_str << " of word " << word_str << " is dropcap";
delete[] sym_str; delete[] sym_str;
} }
EXPECT_FALSE(s_it.SymbolIsDropcap()); EXPECT_FALSE(s_it.SymbolIsDropcap());
@ -433,8 +433,7 @@ TEST_F(ResultIteratorTest, SubSuperTest) {
result = r_it->GetUTF8Text(tesseract::RIL_SYMBOL); result = r_it->GetUTF8Text(tesseract::RIL_SYMBOL);
if (strchr(kAllowedSupers, result[0]) == nullptr) { if (strchr(kAllowedSupers, result[0]) == nullptr) {
char* word = r_it->GetUTF8Text(tesseract::RIL_WORD); char* word = r_it->GetUTF8Text(tesseract::RIL_WORD);
LOG(ERROR) << absl::StrFormat("Char %s in word %s is unexpected super!", LOG(ERROR) << "Char " << result << " in word " << word << " is unexpected super!";
result, word);
delete [] word; delete [] word;
EXPECT_TRUE(strchr(kAllowedSupers, result[0]) != nullptr); EXPECT_TRUE(strchr(kAllowedSupers, result[0]) != nullptr);
} }
@ -445,8 +444,8 @@ TEST_F(ResultIteratorTest, SubSuperTest) {
} }
} while (r_it->Next(tesseract::RIL_SYMBOL)); } while (r_it->Next(tesseract::RIL_SYMBOL));
delete r_it; delete r_it;
LOG(INFO) << absl::StrFormat("Subs = %d, supers= %d, normal = %d", LOG(INFO) << "Subs = " << found_subs << ", supers= " << found_supers
found_subs, found_supers, found_normal) << "\n"; << ", normal = " << found_normal << "\n";
EXPECT_GE(found_subs, 25); EXPECT_GE(found_subs, 25);
EXPECT_GE(found_supers, 25); EXPECT_GE(found_supers, 25);
EXPECT_GE(found_normal, 1350); EXPECT_GE(found_normal, 1350);
@ -528,7 +527,7 @@ TEST_F(ResultIteratorTest, DISABLED_NonNullChoicesTest) {
do { do {
char *word_str = r_it->GetUTF8Text(tesseract::RIL_WORD); char *word_str = r_it->GetUTF8Text(tesseract::RIL_WORD);
if (word_str != nullptr) { if (word_str != nullptr) {
LOG(INFO) << absl::StrFormat("Word %s:", word_str) << "\n"; LOG(INFO) << "Word " << word_str << ":\n";
ResultIterator s_it = *r_it; ResultIterator s_it = *r_it;
do { do {
tesseract::ChoiceIterator c_it(s_it); tesseract::ChoiceIterator c_it(s_it);
@ -571,7 +570,7 @@ TEST_F(ResultIteratorTest, NonNullConfidencesTest) {
const char *char_str = s_it.GetUTF8Text(tesseract::RIL_SYMBOL); const char *char_str = s_it.GetUTF8Text(tesseract::RIL_SYMBOL);
CHECK(char_str != nullptr); CHECK(char_str != nullptr);
float confidence = s_it.Confidence(tesseract::RIL_SYMBOL); float confidence = s_it.Confidence(tesseract::RIL_SYMBOL);
LOG(INFO) << absl::StrFormat("Char %s has confidence %g\n", char_str, confidence); LOG(INFO) << "Char " << char_str << " has confidence " << confidence << "\n";
delete[] char_str; delete[] char_str;
} while (!s_it.IsAtFinalElement(tesseract::RIL_WORD, tesseract::RIL_SYMBOL) && } while (!s_it.IsAtFinalElement(tesseract::RIL_WORD, tesseract::RIL_SYMBOL) &&
s_it.Next(tesseract::RIL_SYMBOL)); s_it.Next(tesseract::RIL_SYMBOL));

View File

@ -12,7 +12,6 @@
#include <allheaders.h> #include <allheaders.h>
#include <string> // for std::string #include <string> // for std::string
#include "absl/strings/str_format.h" // for absl::StrFormat
#include "include_gunit.h" #include "include_gunit.h"
#include <tesseract/baseapi.h> #include <tesseract/baseapi.h>
@ -114,13 +113,12 @@ protected:
const char *message) { const char *message) {
int value = projection_->EvaluateBox(box, denorm_, false); int value = projection_->EvaluateBox(box, denorm_, false);
if (greater_or_equal != (value > target_value)) { if (greater_or_equal != (value > target_value)) {
LOG(INFO) << absl::StrFormat( LOG(INFO) << "EvaluateBox too " << (greater_or_equal ? "low" : "high")
"EvaluateBox too %s:%d vs %d for %s word '%s' at:", greater_or_equal ? "low" : "high", << ":" << value << " vs " << target_value << " for " << message << " word '" << text << "' at:";
value, target_value, message, text);
box.print(); box.print();
value = projection_->EvaluateBox(box, denorm_, true); value = projection_->EvaluateBox(box, denorm_, true);
} else { } else {
LOG(INFO) << absl::StrFormat("EvaluateBox OK(%d) for %s word '%s'", value, message, text); LOG(INFO) << "EvaluateBox OK(" << value << ") for " << message << " word '" << text << "'";
} }
if (greater_or_equal) { if (greater_or_equal) {
EXPECT_GE(value, target_value); EXPECT_GE(value, target_value);
@ -136,14 +134,14 @@ protected:
int true_dist = projection_->DistanceOfBoxFromBox(box, true_box, true, denorm_, false); int true_dist = projection_->DistanceOfBoxFromBox(box, true_box, true, denorm_, false);
int false_dist = projection_->DistanceOfBoxFromBox(box, false_box, true, denorm_, false); int false_dist = projection_->DistanceOfBoxFromBox(box, false_box, true, denorm_, false);
if (false_dist <= true_dist) { if (false_dist <= true_dist) {
LOG(INFO) << absl::StrFormat("Distance wrong:%d vs %d for %s word '%s' at:", false_dist, LOG(INFO) << "Distance wrong:" << false_dist << " vs " << true_dist
true_dist, message, text); << " for " << message << " word '" << text << "' at:";
true_box.print(); true_box.print();
projection_->DistanceOfBoxFromBox(box, true_box, true, denorm_, true); projection_->DistanceOfBoxFromBox(box, true_box, true, denorm_, true);
projection_->DistanceOfBoxFromBox(box, false_box, true, denorm_, true); projection_->DistanceOfBoxFromBox(box, false_box, true, denorm_, true);
} else { } else {
LOG(INFO) << absl::StrFormat("Distance OK(%d vs %d) for %s word '%s'", false_dist, true_dist, LOG(INFO) << "Distance OK(" << false_dist << " vs " << true_dist
message, text); << ") for " << message << " word '" << text << "'";
} }
} }