tesseract  5.0.0
tesseract::DawgTest Class Reference
Inheritance diagram for tesseract::DawgTest:

Protected Member Functions

void SetUp () override
 
void LoadWordlist (const std::string &filename, std::set< std::string > *words) const
 
std::string TessBinaryPath (const std::string &name) const
 
std::string OutputNameToPath (const std::string &name) const
 
int RunCommand (const std::string &program, const std::string &arg1, const std::string &arg2, const std::string &arg3) const
 
void TestDawgRoundTrip (const std::string &unicharset_filename, const std::string &wordlist_filename) const
 

Detailed Description

Definition at line 34 of file dawg_test.cc.

Member Function Documentation

◆ LoadWordlist()

void tesseract::DawgTest::LoadWordlist ( const std::string &  filename,
std::set< std::string > *  words 
) const
inlineprotected

Definition at line 41 of file dawg_test.cc.

41  {
42  std::ifstream file(filename);
43  if (file.is_open()) {
44  std::string line;
45  while (getline(file, line)) {
46  // Remove trailing line terminators from line.
47  while (!line.empty() && (line.back() == '\n' || line.back() == '\r')) {
48  line.resize(line.size() - 1);
49  }
50  // Add line to set.
51  words->insert(line.c_str());
52  }
53  file.close();
54  }
55  }

◆ OutputNameToPath()

std::string tesseract::DawgTest::OutputNameToPath ( const std::string &  name) const
inlineprotected

Definition at line 59 of file dawg_test.cc.

59  {
60  return file::JoinPath(FLAGS_test_tmpdir, name);
61  }
static std::string JoinPath(const std::string &s1, const std::string &s2)
Definition: include_gunit.h:65

◆ RunCommand()

int tesseract::DawgTest::RunCommand ( const std::string &  program,
const std::string &  arg1,
const std::string &  arg2,
const std::string &  arg3 
) const
inlineprotected

Definition at line 62 of file dawg_test.cc.

63  {
64  std::string cmdline = TessBinaryPath(program) + " " + arg1 + " " + arg2 + " " + arg3;
65  return system(cmdline.c_str());
66  }
std::string TessBinaryPath(const std::string &name) const
Definition: dawg_test.cc:56

◆ SetUp()

void tesseract::DawgTest::SetUp ( )
inlineoverrideprotected

Definition at line 36 of file dawg_test.cc.

36  {
37  std::locale::global(std::locale(""));
39  }
static void MakeTmpdir()
Definition: include_gunit.h:38

◆ TessBinaryPath()

std::string tesseract::DawgTest::TessBinaryPath ( const std::string &  name) const
inlineprotected

Definition at line 56 of file dawg_test.cc.

56  {
57  return file::JoinPath(TESSBIN_DIR, name);
58  }

◆ TestDawgRoundTrip()

void tesseract::DawgTest::TestDawgRoundTrip ( const std::string &  unicharset_filename,
const std::string &  wordlist_filename 
) const
inlineprotected

Definition at line 70 of file dawg_test.cc.

71  {
72  std::set<std::string> orig_words, roundtrip_words;
73  std::string unicharset = file::JoinPath(TESTING_DIR, unicharset_filename);
74  std::string orig_wordlist = file::JoinPath(TESTING_DIR, wordlist_filename);
75  std::string output_dawg = OutputNameToPath(wordlist_filename + ".dawg");
76  std::string output_wordlist = OutputNameToPath(wordlist_filename);
77  LoadWordlist(orig_wordlist, &orig_words);
78  EXPECT_EQ(RunCommand(wordlist2dawg_prog, orig_wordlist, output_dawg, unicharset), 0);
79  EXPECT_EQ(RunCommand(dawg2wordlist_prog, unicharset, output_dawg, output_wordlist), 0);
80  LoadWordlist(output_wordlist, &roundtrip_words);
81  EXPECT_EQ(orig_words, roundtrip_words);
82  }
#define dawg2wordlist_prog
Definition: dawg_test.cc:27
#define wordlist2dawg_prog
Definition: dawg_test.cc:26
int RunCommand(const std::string &program, const std::string &arg1, const std::string &arg2, const std::string &arg3) const
Definition: dawg_test.cc:62
void LoadWordlist(const std::string &filename, std::set< std::string > *words) const
Definition: dawg_test.cc:41
std::string OutputNameToPath(const std::string &name) const
Definition: dawg_test.cc:59

The documentation for this class was generated from the following file: