tesseract/unittest/params_model_test.cc
Stefan Weil 2b7df59187 Add more unittests from Google
They were provided by Jeff Breidenbach <jbreiden@google.com>.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
2018-08-25 18:16:46 +02:00

40 lines
1.3 KiB
C++

#include <vector>
#include "tesseract/wordrec/params_model.h"
namespace {
// Test some basic I/O of params model files (automated learning of language
// model weights).
class ParamsModelTest : public testing::Test {
protected:
string TestDataNameToPath(const string& name) const {
return file::JoinPath(FLAGS_test_srcdir,
"testdata/" + name);
}
string OutputNameToPath(const string& name) const {
return file::JoinPath(FLAGS_test_tmpdir, name);
}
// Test that we are able to load a params model, save it, reload it,
// and verify that the re-serialized version is the same as the original.
void TestParamsModelRoundTrip(const string &params_model_filename) const {
tesseract::ParamsModel orig_model;
tesseract::ParamsModel duplicate_model;
string orig_file = TestDataNameToPath(params_model_filename);
string out_file = OutputNameToPath(params_model_filename);
EXPECT_TRUE(orig_model.LoadFromFile("eng", orig_file.c_str()));
EXPECT_TRUE(orig_model.SaveToFile(out_file.c_str()));
EXPECT_TRUE(duplicate_model.LoadFromFile("eng", out_file.c_str()));
EXPECT_TRUE(orig_model.Equivalent(duplicate_model));
}
};
TEST_F(ParamsModelTest, TestEngParamsModelIO) {
TestParamsModelRoundTrip("eng.params_model");
}
} // namespace