1
- #include " tesseract/ccstruct/imagedata.h"
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
+
2
12
#include < string>
3
13
#include < vector>
4
14
15
+ #include " absl/strings/str_cat.h"
16
+ #include " absl/strings/str_format.h"
17
+
18
+ #include " imagedata.h"
19
+ #include " include_gunit.h"
20
+ #include " log.h"
21
+
5
22
using tesseract::DocumentCache;
6
23
using tesseract::DocumentData;
7
24
using tesseract::ImageData;
@@ -15,8 +32,8 @@ class ImagedataTest : public ::testing::Test {
15
32
ImagedataTest () {}
16
33
17
34
// Creates a fake DocumentData, writes it to a file, and returns the filename.
18
- string MakeFakeDoc (int num_pages, int doc_id,
19
- std::vector<string>* page_texts) {
35
+ std:: string MakeFakeDoc (int num_pages, int doc_id,
36
+ std::vector<std:: string>* page_texts) {
20
37
// The size of the fake images that we will use.
21
38
const int kImageSize = 1048576 ;
22
39
// Not using a real image here - just an array of zeros! We are just testing
@@ -26,7 +43,7 @@ class ImagedataTest : public ::testing::Test {
26
43
for (int p = 0 ; p < num_pages; ++p) {
27
44
// Make some fake text that is different for each page and save it.
28
45
page_texts->push_back (
29
- StringPrintf (" Page %d of %d in doc %d" , p, num_pages, doc_id));
46
+ absl::StrFormat (" Page %d of %d in doc %d" , p, num_pages, doc_id));
30
47
// Make an imagedata and put it in the document.
31
48
ImageData* imagedata =
32
49
ImageData::Build (" noname" , p, " eng" , fake_image.data (),
@@ -35,7 +52,7 @@ class ImagedataTest : public ::testing::Test {
35
52
write_doc.AddPageToDocument (imagedata);
36
53
}
37
54
// Write it to a file.
38
- string filename = file::JoinPath (
55
+ std:: string filename = file::JoinPath (
39
56
FLAGS_test_tmpdir, absl::StrCat (" documentdata" , doc_id, " .lstmf" ));
40
57
EXPECT_TRUE (write_doc.SaveDocument (filename.c_str (), nullptr ));
41
58
return filename;
@@ -52,8 +69,8 @@ TEST_F(ImagedataTest, CachesProperly) {
52
69
// Order in which to read the pages, with some sequential and some seeks.
53
70
const int kPageReadOrder [] = {0 , 1 , 2 , 3 , 8 , 4 , 5 , 6 , 7 , 11 , 10 , 9 , -1 };
54
71
55
- std::vector<string> page_texts;
56
- string filename = MakeFakeDoc (kNumPages , 0 , &page_texts);
72
+ std::vector<std:: string> page_texts;
73
+ std:: string filename = MakeFakeDoc (kNumPages , 0 , &page_texts);
57
74
// Now try getting it back with different memory allowances and check that
58
75
// the pages can still be read.
59
76
for (int m = 0 ; kMemoryAllowances [m] > 0 ; ++m) {
@@ -65,7 +82,8 @@ TEST_F(ImagedataTest, CachesProperly) {
65
82
for (int p = 0 ; kPageReadOrder [p] >= 0 ; ++p) {
66
83
int page = kPageReadOrder [p];
67
84
const ImageData* imagedata = read_doc.GetPage (page);
68
- EXPECT_NE (reinterpret_cast <const ImageData*>(nullptr ), imagedata);
85
+ EXPECT_NE (nullptr , imagedata);
86
+ // EXPECT_NE(reinterpret_cast<ImageData*>(nullptr), imagedata);
69
87
// Check that this is the right page.
70
88
EXPECT_STREQ (page_texts[page].c_str (),
71
89
imagedata->transcription ().string ());
@@ -78,11 +96,11 @@ TEST_F(ImagedataTest, CachesMultiDocs) {
78
96
// and the two caching strategies read images in the right order.
79
97
// Number of pages in each document.
80
98
const std::vector<int > kNumPages = {6 , 5 , 7 };
81
- std::vector<std::vector<string>> page_texts;
99
+ std::vector<std::vector<std:: string>> page_texts;
82
100
GenericVector<STRING> filenames;
83
101
for (int d = 0 ; d < kNumPages .size (); ++d) {
84
- page_texts.emplace_back (std::vector<string>());
85
- string filename = MakeFakeDoc (kNumPages [d], d, &page_texts.back ());
102
+ page_texts.emplace_back (std::vector<std:: string>());
103
+ std:: string filename = MakeFakeDoc (kNumPages [d], d, &page_texts.back ());
86
104
filenames.push_back (STRING (filename.c_str ()));
87
105
}
88
106
// Now try getting them back with different cache strategies and check that
0 commit comments