|
1 |
| - |
| 1 | +// (C) Copyright 2017, Google Inc. |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +// Unless required by applicable law or agreed to in writing, software |
| 7 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +// See the License for the specific language governing permissions and |
| 10 | +// limitations under the License. |
| 11 | + |
| 12 | +#include <string> // std::string |
2 | 13 | #include <vector>
|
3 | 14 |
|
4 |
| -#include "tesseract/wordrec/params_model.h" |
| 15 | +#include "include_gunit.h" |
| 16 | +#include "params_model.h" |
| 17 | +#include "serialis.h" // TFile |
| 18 | +#include "tprintf.h" // tprintf |
5 | 19 |
|
6 | 20 | namespace {
|
7 | 21 |
|
8 | 22 | // Test some basic I/O of params model files (automated learning of language
|
9 | 23 | // model weights).
|
| 24 | +static bool LoadFromFile(tesseract::ParamsModel& model, const char* lang, const char* full_path) { |
| 25 | + tesseract::TFile fp; |
| 26 | + if (!fp.Open(full_path, nullptr)) { |
| 27 | + tprintf("Error opening file %s\n", full_path); |
| 28 | + return false; |
| 29 | + } |
| 30 | + return model.LoadFromFp(lang, &fp); |
| 31 | +} |
| 32 | + |
10 | 33 | class ParamsModelTest : public testing::Test {
|
11 | 34 | protected:
|
12 |
| - string TestDataNameToPath(const string& name) const { |
13 |
| - return file::JoinPath(FLAGS_test_srcdir, "testdata/" + name); |
| 35 | + std::string TestDataNameToPath(const std::string& name) const { |
| 36 | + return file::JoinPath(TESTDATA_DIR, name); |
14 | 37 | }
|
15 |
| - string OutputNameToPath(const string& name) const { |
| 38 | + std::string OutputNameToPath(const std::string& name) const { |
16 | 39 | return file::JoinPath(FLAGS_test_tmpdir, name);
|
17 | 40 | }
|
18 | 41 | // Test that we are able to load a params model, save it, reload it,
|
19 | 42 | // and verify that the re-serialized version is the same as the original.
|
20 |
| - void TestParamsModelRoundTrip(const string& params_model_filename) const { |
| 43 | + void TestParamsModelRoundTrip(const std::string& params_model_filename) const { |
21 | 44 | tesseract::ParamsModel orig_model;
|
22 | 45 | tesseract::ParamsModel duplicate_model;
|
23 |
| - string orig_file = TestDataNameToPath(params_model_filename); |
24 |
| - string out_file = OutputNameToPath(params_model_filename); |
| 46 | + std::string orig_file = TestDataNameToPath(params_model_filename); |
| 47 | + std::string out_file = OutputNameToPath(params_model_filename); |
25 | 48 |
|
26 |
| - EXPECT_TRUE(orig_model.LoadFromFile("eng", orig_file.c_str())); |
| 49 | + EXPECT_TRUE(LoadFromFile(orig_model, "eng", orig_file.c_str())); |
27 | 50 | EXPECT_TRUE(orig_model.SaveToFile(out_file.c_str()));
|
28 | 51 |
|
29 |
| - EXPECT_TRUE(duplicate_model.LoadFromFile("eng", out_file.c_str())); |
| 52 | + EXPECT_TRUE(LoadFromFile(duplicate_model, "eng", out_file.c_str())); |
30 | 53 | EXPECT_TRUE(orig_model.Equivalent(duplicate_model));
|
31 | 54 | }
|
32 | 55 | };
|
|
0 commit comments