Replace remaining STRING by std::string in unittest

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2021-03-14 22:52:52 +01:00
parent 0edd69eb10
commit 576c09bf31
14 changed files with 20 additions and 24 deletions

View File

@ -36,7 +36,6 @@
# include "host.h" // windows.h for HANDLE, ...
#endif
#include "params.h"
#include "strngs.h"
#include "unicharset.h"
namespace tesseract {

View File

@ -19,9 +19,11 @@
#ifndef PARAMS_H
#define PARAMS_H
#include "strngs.h"
#include <tesseract/export.h> // for TESS_API
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
namespace tesseract {
@ -30,6 +32,7 @@ class IntParam;
class BoolParam;
class StringParam;
class DoubleParam;
class TFile;
// Enum for constraints on what kind of params should be set by SetParam().
enum SetParamConstraint {

View File

@ -24,7 +24,6 @@
#include <unordered_map>
#include "genericvector.h" // GenericVector
#include "serialis.h"
#include "strngs.h"
#include "unicharset.h"
namespace tesseract {

View File

@ -18,7 +18,6 @@
#include "commontraining.h"
#include "genericvector.h"
#include "lstmtester.h"
#include "strngs.h"
#include "tprintf.h"
using namespace tesseract;

View File

@ -24,7 +24,6 @@
#include "lstmtester.h"
#include "lstmtrainer.h"
#include "params.h"
#include "strngs.h"
#include "tprintf.h"
#include "unicharset_training_utils.h"

View File

@ -23,7 +23,6 @@
#include "commontraining.h"
#include "mastertrainer.h"
#include "params.h"
#include "strngs.h"
using namespace tesseract;

View File

@ -26,7 +26,6 @@
#include "commontraining.h" // CheckSharedLibraryVersion
#include "lang_model_helpers.h"
#include "normstrngs.h"
#include "strngs.h"
#include "unicharset.h"
#include "unicharset_training_utils.h"

View File

@ -64,7 +64,7 @@ TEST(LangModelTest, AddACharacter) {
trainer1.InitCharSet(traineddata1);
std::vector<int> labels1;
EXPECT_TRUE(trainer1.EncodeString(kTestString, &labels1));
STRING test1_decoded = trainer1.DecodeLabels(labels1);
std::string test1_decoded = trainer1.DecodeLabels(labels1);
std::string test1_str(&test1_decoded[0], test1_decoded.length());
LOG(INFO) << "Labels1=" << test1_str << "\n";
@ -84,13 +84,13 @@ TEST(LangModelTest, AddACharacter) {
trainer2.InitCharSet(traineddata2);
std::vector<int> labels2;
EXPECT_TRUE(trainer2.EncodeString(kTestString, &labels2));
STRING test2_decoded = trainer2.DecodeLabels(labels2);
std::string test2_decoded = trainer2.DecodeLabels(labels2);
std::string test2_str(&test2_decoded[0], test2_decoded.length());
LOG(INFO) << "Labels2=" << test2_str << "\n";
// encode kTestStringRupees.
std::vector<int> labels3;
EXPECT_TRUE(trainer2.EncodeString(kTestStringRupees, &labels3));
STRING test3_decoded = trainer2.DecodeLabels(labels3);
std::string test3_decoded = trainer2.DecodeLabels(labels3);
std::string test3_str(&test3_decoded[0], test3_decoded.length());
LOG(INFO) << "labels3=" << test3_str << "\n";
// Copy labels1 to a std::vector, renumbering the null char to match trainer2.
@ -148,7 +148,7 @@ TEST(LangModelTest, AddACharacterHindi) {
trainer1.InitCharSet(traineddata1);
std::vector<int> labels1;
EXPECT_TRUE(trainer1.EncodeString(kTestString, &labels1));
STRING test1_decoded = trainer1.DecodeLabels(labels1);
std::string test1_decoded = trainer1.DecodeLabels(labels1);
std::string test1_str(&test1_decoded[0], test1_decoded.length());
LOG(INFO) << "Labels1=" << test1_str << "\n";
@ -168,13 +168,13 @@ TEST(LangModelTest, AddACharacterHindi) {
trainer2.InitCharSet(traineddata2);
std::vector<int> labels2;
EXPECT_TRUE(trainer2.EncodeString(kTestString, &labels2));
STRING test2_decoded = trainer2.DecodeLabels(labels2);
std::string test2_decoded = trainer2.DecodeLabels(labels2);
std::string test2_str(&test2_decoded[0], test2_decoded.length());
LOG(INFO) << "Labels2=" << test2_str << "\n";
// encode kTestStringRupees.
std::vector<int> labels3;
EXPECT_TRUE(trainer2.EncodeString(kTestStringRupees, &labels3));
STRING test3_decoded = trainer2.DecodeLabels(labels3);
std::string test3_decoded = trainer2.DecodeLabels(labels3);
std::string test3_str(&test3_decoded[0], test3_decoded.length());
LOG(INFO) << "labels3=" << test3_str << "\n";
// Copy labels1 to a std::vector, renumbering the null char to match trainer2.

View File

@ -92,7 +92,7 @@ protected:
EXPECT_TRUE(
trainer_->InitNetwork(network_spec.c_str(), -1, net_mode, 0.1, learning_rate, 0.9, 0.999));
std::vector<std::string> filenames;
filenames.push_back(STRING(TestDataNameToPath(lstmf_file).c_str()));
filenames.push_back(std::string(TestDataNameToPath(lstmf_file).c_str()));
EXPECT_TRUE(trainer_->LoadAllTrainingData(filenames, CS_SEQUENTIAL, false));
LOG(INFO) << "Setup network:" << model_name << "\n";
}
@ -165,7 +165,7 @@ protected:
5e-4f, true, lang);
std::vector<int> labels;
EXPECT_TRUE(trainer_->EncodeString(str.c_str(), &labels));
STRING decoded = trainer_->DecodeLabels(labels);
std::string decoded = trainer_->DecodeLabels(labels);
std::string decoded_str(&decoded[0], decoded.length());
EXPECT_EQ(str, decoded_str);
}

View File

@ -37,7 +37,7 @@ TEST_F(LSTMTrainerTest, MapCoder) {
std::vector<int> deu_labels;
EXPECT_TRUE(deu_trainer.EncodeString(kTestStr.c_str(), &deu_labels));
// The french trainer cannot decode them correctly.
STRING badly_decoded = fra_trainer.DecodeLabels(deu_labels);
std::string badly_decoded = fra_trainer.DecodeLabels(deu_labels);
std::string bad_str(&badly_decoded[0], badly_decoded.length());
LOG(INFO) << "bad_str fra=" << bad_str << "\n";
EXPECT_NE(kTestStr, bad_str);
@ -56,7 +56,7 @@ TEST_F(LSTMTrainerTest, MapCoder) {
<< ", but mapped to " << mapped_fra_labels[i];
}
// The german trainer can now decode them correctly.
STRING decoded = deu_trainer.DecodeLabels(mapped_fra_labels);
std::string decoded = deu_trainer.DecodeLabels(mapped_fra_labels);
std::string ok_str(&decoded[0], decoded.length());
LOG(INFO) << "ok_str deu=" << ok_str << "\n";
EXPECT_EQ(kTestStr, ok_str);

View File

@ -261,7 +261,7 @@ TEST_F(MasterTrainerTest, ErrorCounterTest) {
// Make a mock classifier.
auto shape_classifier = std::make_unique<MockClassifier>(shape_table_);
// Get the accuracy report.
STRING accuracy_report;
std::string accuracy_report;
master_trainer_->TestClassifierOnSamples(tesseract::CT_UNICHAR_TOP1_ERR, 0, false,
shape_classifier.get(), &accuracy_report);
LOG(INFO) << accuracy_report.c_str();

View File

@ -79,7 +79,7 @@ protected:
CHECK(ccutil_.unicharset.load_from_file(unicharset_file.c_str()));
unichar_null_char_ =
ccutil_.unicharset.has_special_codes() ? UNICHAR_BROKEN : ccutil_.unicharset.size();
STRING radical_str(radical_data.c_str());
std::string radical_str(radical_data.c_str());
EXPECT_TRUE(recoder_.ComputeEncoding(ccutil_.unicharset, unichar_null_char_, &radical_str));
RecodedCharID code;
recoder_.EncodeUnichar(unichar_null_char_, &code);
@ -88,7 +88,7 @@ protected:
recoder_.EncodeUnichar(UNICHAR_SPACE, &code);
EXPECT_EQ(UNICHAR_SPACE, code(0));
std::string output_name = file::JoinPath(FLAGS_test_tmpdir, "testenc.txt");
STRING encoding = recoder_.GetEncodingAsString(ccutil_.unicharset);
std::string encoding = recoder_.GetEncodingAsString(ccutil_.unicharset);
std::string encoding_str(&encoding[0], encoding.size());
CHECK_OK(file::SetContents(output_name, encoding_str, file::Defaults()));
LOG(INFO) << "Wrote encoding to:" << output_name << "\n";

View File

@ -15,7 +15,6 @@
#include "boxread.h"
#include "commandlineflags.h"
#include "stringrenderer.h"
#include "strngs.h"
#include <allheaders.h>
#include "absl/strings/str_split.h" // for absl::StrSplit

View File

@ -38,7 +38,7 @@ protected:
std::string radical_data;
CHECK_OK(file::GetContents(radical_stroke_file, &radical_data, file::Defaults()));
CHECK(unicharset_.load_from_file(unicharset_file.c_str()));
STRING radical_str(radical_data.c_str());
std::string radical_str(radical_data.c_str());
null_char_ = unicharset_.has_special_codes() ? UNICHAR_BROKEN : unicharset_.size();
compressed_.ComputeEncoding(unicharset_, null_char_, &radical_str);
// Get the encoding of the null char.
@ -47,7 +47,7 @@ protected:
encoded_null_char_ = code(0);
std::string output_name =
file::JoinPath(FLAGS_test_tmpdir, absl::StrCat(unicharset_name, ".encoding.txt"));
STRING encoding = compressed_.GetEncodingAsString(unicharset_);
std::string encoding = compressed_.GetEncodingAsString(unicharset_);
std::string encoding_str(&encoding[0], encoding.size());
CHECK_OK(file::SetContents(output_name, encoding_str, file::Defaults()));
LOG(INFO) << "Wrote encoding to:" << output_name;
@ -231,7 +231,7 @@ TEST_F(UnicharcompressTest, DoesLigaturesWithDoubles) {
TEST_F(UnicharcompressTest, GetEncodingAsString) {
LoadUnicharset("trivial.unicharset");
ExpectCorrect("trivial");
STRING encoding = compressed_.GetEncodingAsString(unicharset_);
std::string encoding = compressed_.GetEncodingAsString(unicharset_);
std::string encoding_str(&encoding[0], encoding.length());
std::vector<std::string> lines = absl::StrSplit(encoding_str, "\n", absl::SkipEmpty());
EXPECT_EQ(5, lines.size());