Skip to content

Commit 53f0e76

Browse files
committed
unittest: Add imagedata_test
Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 30081c5 commit 53f0e76

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

unittest/Makefile.am

+14
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,17 @@ libabseil_la_SOURCES += ../abseil/absl/base/internal/throw_delegate.cc
4747
libabseil_la_SOURCES += ../abseil/absl/base/internal/unscaledcycleclock.cc
4848
libabseil_la_SOURCES += ../abseil/absl/numeric/int128.cc
4949
libabseil_la_SOURCES += ../abseil/absl/strings/ascii.cc
50+
libabseil_la_SOURCES += ../abseil/absl/strings/charconv.cc
51+
libabseil_la_SOURCES += ../abseil/absl/strings/internal/charconv_bigint.cc
52+
libabseil_la_SOURCES += ../abseil/absl/strings/internal/charconv_parse.cc
5053
libabseil_la_SOURCES += ../abseil/absl/strings/internal/memutil.cc
54+
libabseil_la_SOURCES += ../abseil/absl/strings/internal/str_format/arg.cc
55+
libabseil_la_SOURCES += ../abseil/absl/strings/internal/str_format/bind.cc
56+
libabseil_la_SOURCES += ../abseil/absl/strings/internal/str_format/extension.cc
57+
libabseil_la_SOURCES += ../abseil/absl/strings/internal/str_format/float_conversion.cc
58+
libabseil_la_SOURCES += ../abseil/absl/strings/internal/str_format/output.cc
59+
libabseil_la_SOURCES += ../abseil/absl/strings/internal/str_format/parser.cc
60+
libabseil_la_SOURCES += ../abseil/absl/strings/numbers.cc
5161
libabseil_la_SOURCES += ../abseil/absl/strings/str_cat.cc
5262
libabseil_la_SOURCES += ../abseil/absl/strings/str_split.cc
5363
libabseil_la_SOURCES += ../abseil/absl/strings/string_view.cc
@@ -87,6 +97,7 @@ check_PROGRAMS = \
8797
denorm_test \
8898
fileio_test \
8999
heap_test \
100+
imagedata_test \
90101
indexmapbidi_test \
91102
intfeaturemap_test \
92103
intsimdmatrix_test \
@@ -148,6 +159,9 @@ fileio_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TESS_LIBS)
148159
heap_test_SOURCES = heap_test.cc
149160
heap_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS)
150161

162+
imagedata_test_SOURCES = imagedata_test.cc
163+
imagedata_test_LDADD = $(ABSEIL_LIBS) $(GTEST_LIBS) $(TESS_LIBS)
164+
151165
indexmapbidi_test_SOURCES = indexmapbidi_test.cc
152166
indexmapbidi_test_LDADD = $(GTEST_LIBS) $(TESS_LIBS)
153167

unittest/imagedata_test.cc

+29-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
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+
212
#include <string>
313
#include <vector>
414

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+
522
using tesseract::DocumentCache;
623
using tesseract::DocumentData;
724
using tesseract::ImageData;
@@ -15,8 +32,8 @@ class ImagedataTest : public ::testing::Test {
1532
ImagedataTest() {}
1633

1734
// 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) {
2037
// The size of the fake images that we will use.
2138
const int kImageSize = 1048576;
2239
// Not using a real image here - just an array of zeros! We are just testing
@@ -26,7 +43,7 @@ class ImagedataTest : public ::testing::Test {
2643
for (int p = 0; p < num_pages; ++p) {
2744
// Make some fake text that is different for each page and save it.
2845
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));
3047
// Make an imagedata and put it in the document.
3148
ImageData* imagedata =
3249
ImageData::Build("noname", p, "eng", fake_image.data(),
@@ -35,7 +52,7 @@ class ImagedataTest : public ::testing::Test {
3552
write_doc.AddPageToDocument(imagedata);
3653
}
3754
// Write it to a file.
38-
string filename = file::JoinPath(
55+
std::string filename = file::JoinPath(
3956
FLAGS_test_tmpdir, absl::StrCat("documentdata", doc_id, ".lstmf"));
4057
EXPECT_TRUE(write_doc.SaveDocument(filename.c_str(), nullptr));
4158
return filename;
@@ -52,8 +69,8 @@ TEST_F(ImagedataTest, CachesProperly) {
5269
// Order in which to read the pages, with some sequential and some seeks.
5370
const int kPageReadOrder[] = {0, 1, 2, 3, 8, 4, 5, 6, 7, 11, 10, 9, -1};
5471

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);
5774
// Now try getting it back with different memory allowances and check that
5875
// the pages can still be read.
5976
for (int m = 0; kMemoryAllowances[m] > 0; ++m) {
@@ -65,7 +82,8 @@ TEST_F(ImagedataTest, CachesProperly) {
6582
for (int p = 0; kPageReadOrder[p] >= 0; ++p) {
6683
int page = kPageReadOrder[p];
6784
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);
6987
// Check that this is the right page.
7088
EXPECT_STREQ(page_texts[page].c_str(),
7189
imagedata->transcription().string());
@@ -78,11 +96,11 @@ TEST_F(ImagedataTest, CachesMultiDocs) {
7896
// and the two caching strategies read images in the right order.
7997
// Number of pages in each document.
8098
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;
82100
GenericVector<STRING> filenames;
83101
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());
86104
filenames.push_back(STRING(filename.c_str()));
87105
}
88106
// Now try getting them back with different cache strategies and check that

0 commit comments

Comments
 (0)