Skip to content

Commit

Permalink
Showing 20 changed files with 162 additions and 162 deletions.
6 changes: 3 additions & 3 deletions unittest/applybox_test.cc
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ class ApplyBoxTest : public testing::Test {
return file::JoinPath(FLAGS_test_tmpdir, name);
}

ApplyBoxTest() { src_pix_ = NULL; }
ApplyBoxTest() { src_pix_ = nullptr; }
~ApplyBoxTest() { pixDestroy(&src_pix_); }

void SetImage(const char* filename) {
@@ -61,15 +61,15 @@ class ApplyBoxTest : public testing::Test {
api_.SetVariable("tessedit_resegment_from_line_boxes", "1");
else
api_.SetVariable("tessedit_resegment_from_boxes", "1");
api_.Recognize(NULL);
api_.Recognize(nullptr);
char* ocr_text = api_.GetUTF8Text();
EXPECT_STREQ(truth_str, ocr_text);
delete[] ocr_text;
// Test the boxes by reading the target box file in parallel with the
// bounding boxes in the ocr output.
std::string box_filename = TestDataNameToPath(target_box_file);
FILE* box_file = OpenBoxFile(STRING(box_filename.c_str()));
ASSERT_TRUE(box_file != NULL);
ASSERT_TRUE(box_file != nullptr);
int height = pixGetHeight(src_pix_);
ResultIterator* it = api_.GetIterator();
do {
42 changes: 21 additions & 21 deletions unittest/baseapi_test.cc
Original file line number Diff line number Diff line change
@@ -11,13 +11,13 @@ namespace {
using ::testing::ContainsRegex;
using ::testing::HasSubstr;

const char* langs[] = {"eng", "vie", "hin", "ara", NULL};
const char* langs[] = {"eng", "vie", "hin", "ara", nullptr};
const char* image_files[] = {"HelloGoogle.tif", "viet.tif", "raaj.tif",
"arabic.tif", NULL};
"arabic.tif", nullptr};
const char* gt_text[] = {"Hello Google", "\x74\x69\xe1\xba\xbf\x6e\x67",
"\xe0\xa4\xb0\xe0\xa4\xbe\xe0\xa4\x9c",
"\xd8\xa7\xd9\x84\xd8\xb9\xd8\xb1\xd8\xa8\xd9\x8a",
NULL};
nullptr};

class FriendlyTessBaseAPI : public tesseract::TessBaseAPI {
FRIEND_TEST(TesseractTest, LSTMGeometryTest);
@@ -78,11 +78,11 @@ TEST_F(TesseractTest, IteratesParagraphsEvenIfNotDetected) {
CHECK(src_pix);
api.SetImage(src_pix);
Boxa* para_boxes =
api.GetComponentImages(tesseract::RIL_PARA, true, NULL, NULL);
EXPECT_TRUE(para_boxes != NULL);
api.GetComponentImages(tesseract::RIL_PARA, true, nullptr, nullptr);
EXPECT_TRUE(para_boxes != nullptr);
Boxa* block_boxes =
api.GetComponentImages(tesseract::RIL_BLOCK, true, NULL, NULL);
EXPECT_TRUE(block_boxes != NULL);
api.GetComponentImages(tesseract::RIL_BLOCK, true, nullptr, nullptr);
EXPECT_TRUE(block_boxes != nullptr);
// TODO(eger): Get paragraphs out of this page pre-text.
EXPECT_GE(boxaGetCount(para_boxes), boxaGetCount(block_boxes));
boxaDestroy(&block_boxes);
@@ -99,7 +99,7 @@ TEST_F(TesseractTest, HOCRWorksWithoutSetInputName) {
CHECK(src_pix);
api.SetImage(src_pix);
char* result = api.GetHOCRText(0);
EXPECT_TRUE(result != NULL);
EXPECT_TRUE(result != nullptr);
EXPECT_THAT(result, HasSubstr("Hello"));
EXPECT_THAT(result, HasSubstr("<div class='ocr_page'"));
delete[] result;
@@ -115,7 +115,7 @@ TEST_F(TesseractTest, HOCRContainsBaseline) {
api.SetInputName("HelloGoogle.tif");
api.SetImage(src_pix);
char* result = api.GetHOCRText(0);
EXPECT_TRUE(result != NULL);
EXPECT_TRUE(result != nullptr);
EXPECT_THAT(result, HasSubstr("Hello"));
EXPECT_THAT(result, ContainsRegex("<span class='ocr_line'[^>]* "
"baseline [-.0-9]+ [-.0-9]+"));
@@ -134,7 +134,7 @@ TEST_F(TesseractTest, RickSnyderNotFuckSnyder) {
CHECK(src_pix);
api.SetImage(src_pix);
char* result = api.GetHOCRText(0);
EXPECT_TRUE(result != NULL);
EXPECT_TRUE(result != nullptr);
EXPECT_THAT(result, Not(HasSubstr("FUCK")));
delete[] result;
pixDestroy(&src_pix);
@@ -145,20 +145,20 @@ TEST_F(TesseractTest, AdaptToWordStrTest) {
static const char* kTrainingPages[] = {
"136.tif", "256.tif", "410.tif", "432.tif", "540.tif",
"692.tif", "779.tif", "793.tif", "808.tif", "815.tif",
"12.tif", "12.tif", NULL};
"12.tif", "12.tif", nullptr};
static const char* kTrainingText[] = {
"1 3 6", "2 5 6", "4 1 0", "4 3 2", "5 4 0", "6 9 2", "7 7 9",
"7 9 3", "8 0 8", "8 1 5", "1 2", "1 2", NULL};
static const char* kTestPages[] = {"324.tif", "433.tif", "12.tif", NULL};
static const char* kTestText[] = {"324", "433", "12", NULL};
"7 9 3", "8 0 8", "8 1 5", "1 2", "1 2", nullptr};
static const char* kTestPages[] = {"324.tif", "433.tif", "12.tif", nullptr};
static const char* kTestText[] = {"324", "433", "12", nullptr};
tesseract::TessBaseAPI api;
string truth_text;
string ocr_text;
api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY);
api.SetVariable("matcher_sufficient_examples_for_prototyping", "1");
api.SetVariable("classify_class_pruner_threshold", "220");
// Train on the training text.
for (int i = 0; kTrainingPages[i] != NULL; ++i) {
for (int i = 0; kTrainingPages[i] != nullptr; ++i) {
string image_file = TestDataNameToPath(kTrainingPages[i]);
Pix* src_pix = pixRead(image_file.c_str());
CHECK(src_pix);
@@ -172,7 +172,7 @@ TEST_F(TesseractTest, AdaptToWordStrTest) {
// Test the test text.
api.SetVariable("tess_bn_matching", "1");
api.SetPageSegMode(tesseract::PSM_SINGLE_WORD);
for (int i = 0; kTestPages[i] != NULL; ++i) {
for (int i = 0; kTestPages[i] != nullptr; ++i) {
Pix* src_pix = pixRead(TestDataNameToPath(kTestPages[i]).c_str());
CHECK(src_pix);
ocr_text = GetCleanedTextResult(&api, src_pix);
@@ -209,7 +209,7 @@ TEST_F(TesseractTest, LSTMGeometryTest) {
FriendlyTessBaseAPI api;
api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_LSTM_ONLY);
api.SetImage(src_pix);
ASSERT_EQ(api.Recognize(NULL), 0);
ASSERT_EQ(api.Recognize(nullptr), 0);

const PAGE_RES* page_res = api.GetPageRes();
PAGE_RES_IT page_res_it(const_cast<PAGE_RES*>(page_res));
@@ -218,7 +218,7 @@ TEST_F(TesseractTest, LSTMGeometryTest) {
CHECK(block);

// extract word and character boxes for each word
for (page_res_it.restart_page(); page_res_it.word() != NULL;
for (page_res_it.restart_page(); page_res_it.word() != nullptr;
page_res_it.forward()) {
WERD_RES* word = page_res_it.word();
CHECK(word);
@@ -268,7 +268,7 @@ TEST_F(TesseractTest, InitConfigOnlyTest) {
api.reset(new tesseract::TessBaseAPI);
timer.Restart();
EXPECT_EQ(0, api->Init(TessdataPath().c_str(), langs[i],
tesseract::OEM_TESSERACT_ONLY, NULL, 0, &vars_vec,
tesseract::OEM_TESSERACT_ONLY, nullptr, 0, &vars_vec,
&vars_values, false));
timer.Stop();
LOG(INFO) << "Lang " << langs[i] << " took " << timer.GetInMs()
@@ -284,7 +284,7 @@ TEST_F(TesseractTest, InitConfigOnlyTest) {
// OEM_DEFAULT mode.
TEST(TesseractInstanceTest, TestMultipleTessInstances) {
int num_langs = 0;
while (langs[num_langs] != NULL) ++num_langs;
while (langs[num_langs] != nullptr) ++num_langs;

const string kTessdataPath = file::JoinPath(FLAGS_test_srcdir, "tessdata");

@@ -294,7 +294,7 @@ TEST(TesseractInstanceTest, TestMultipleTessInstances) {
SCOPED_TRACE(absl::StrCat("Single instance test with lang = ", langs[i]));
string path = FLAGS_test_srcdir + "/testdata/" + image_files[i];
pix[i] = pixRead(path.c_str());
QCHECK(pix[i] != NULL) << "Could not read " << path;
QCHECK(pix[i] != nullptr) << "Could not read " << path;

tesseract::TessBaseAPI tess;
EXPECT_EQ(0, tess.Init(kTessdataPath.c_str(), langs[i]));
20 changes: 10 additions & 10 deletions unittest/baseapi_thread_test.cc
Original file line number Diff line number Diff line change
@@ -37,16 +37,16 @@ using tesseract::TessBaseAPI;

namespace {

const char* kTessLangs[] = {"eng", "vie", NULL};
const char* kTessImages[] = {"HelloGoogle.tif", "viet.tif", NULL};
const char* kTessLangs[] = {"eng", "vie", nullptr};
const char* kTessImages[] = {"HelloGoogle.tif", "viet.tif", nullptr};
const char* kTessTruthText[] = {"Hello Google", "\x74\x69\xe1\xba\xbf\x6e\x67",
NULL};
nullptr};

const char* kCubeLangs[] = {"hin", "ara", NULL};
const char* kCubeImages[] = {"raaj.tif", "arabic.tif", NULL};
const char* kCubeLangs[] = {"hin", "ara", nullptr};
const char* kCubeImages[] = {"raaj.tif", "arabic.tif", nullptr};
const char* kCubeTruthText[] = {
"\xe0\xa4\xb0\xe0\xa4\xbe\xe0\xa4\x9c",
"\xd8\xa7\xd9\x84\xd8\xb9\xd8\xb1\xd8\xa8\xd9\x8a", NULL};
"\xd8\xa7\xd9\x84\xd8\xb9\xd8\xb1\xd8\xa8\xd9\x8a", nullptr};

class BaseapiThreadTest : public ::testing::Test {
protected:
@@ -86,7 +86,7 @@ class BaseapiThreadTest : public ::testing::Test {
string path =
FLAGS_test_srcdir + "/testdata/" + image_files[i % num_langs_];
Pix* new_pix = pixRead(path.c_str());
QCHECK(new_pix != NULL) << "Could not read " << path;
QCHECK(new_pix != nullptr) << "Could not read " << path;
pix_.push_back(new_pix);
}

@@ -106,7 +106,7 @@ class BaseapiThreadTest : public ::testing::Test {
pool_->StartWorkers();
}

void WaitForPoolWorkers() { pool_.reset(NULL); }
void WaitForPoolWorkers() { pool_.reset(nullptr); }

std::unique_ptr<ThreadPool> pool_;
static int pool_size_;
@@ -139,7 +139,7 @@ void GetCleanedText(TessBaseAPI* tess, Pix* pix, string* ocr_text) {

void VerifyTextResult(TessBaseAPI* tess, Pix* pix, const string& lang,
const string& expected_text) {
TessBaseAPI* tess_local = NULL;
TessBaseAPI* tess_local = nullptr;
if (tess) {
tess_local = tess;
} else {
@@ -197,7 +197,7 @@ TEST_F(BaseapiThreadTest, TestAll) {
const int n = num_langs_ * FLAGS_reps;
ResetPool();
for (int i = 0; i < n; ++i) {
pool_->Add(NewCallback(VerifyTextResult, NULL, pix_[i],
pool_->Add(NewCallback(VerifyTextResult, nullptr, pix_[i],
langs_[i % num_langs_], gt_text_[i % num_langs_]));
}
WaitForPoolWorkers();
12 changes: 6 additions & 6 deletions unittest/denorm_test.cc
Original file line number Diff line number Diff line change
@@ -28,15 +28,15 @@ class DENORMTest : public testing::Test {
if (local)
denorm.LocalNormTransform(src, &normed);
else
denorm.NormTransform(NULL, src, &normed);
denorm.NormTransform(nullptr, src, &normed);
EXPECT_EQ(result.x, normed.x);
EXPECT_EQ(result.y, normed.y);
// Now undo
TPOINT denormed;
if (local)
denorm.LocalDenormTransform(normed, &denormed);
else
denorm.DenormTransform(NULL, normed, &denormed);
denorm.DenormTransform(nullptr, normed, &denormed);
EXPECT_EQ(src.x, denormed.x);
EXPECT_EQ(src.y, denormed.y);
}
@@ -45,7 +45,7 @@ class DENORMTest : public testing::Test {
// Tests a simple baseline-style normalization.
TEST_F(DENORMTest, NoRotations) {
DENORM denorm;
denorm.SetupNormalization(NULL, NULL, NULL, 1000.0f, 2000.0f, 2.0f, 3.0f,
denorm.SetupNormalization(nullptr, nullptr, nullptr, 1000.0f, 2000.0f, 2.0f, 3.0f,
0.0f, static_cast<float>(kBlnBaselineOffset));
TPOINT pt1(1100, 2000);
TPOINT result1(200, kBlnBaselineOffset);
@@ -61,7 +61,7 @@ TEST_F(DENORMTest, NoRotations) {
TEST_F(DENORMTest, WithRotations) {
DENORM denorm;
FCOORD rotation90(0.0f, 1.0f);
denorm.SetupNormalization(NULL, &rotation90, NULL, 1000.0f, 2000.0f, 2.0f,
denorm.SetupNormalization(nullptr, &rotation90, nullptr, 1000.0f, 2000.0f, 2.0f,
3.0f, 0.0f, static_cast<float>(kBlnBaselineOffset));

TPOINT pt1(1100, 2000);
@@ -77,12 +77,12 @@ TEST_F(DENORMTest, WithRotations) {
// Tests a simple baseline-style normalization with a second rotation & scale.
TEST_F(DENORMTest, Multiple) {
DENORM denorm;
denorm.SetupNormalization(NULL, NULL, NULL, 1000.0f, 2000.0f, 2.0f, 3.0f,
denorm.SetupNormalization(nullptr, nullptr, nullptr, 1000.0f, 2000.0f, 2.0f, 3.0f,
0.0f, static_cast<float>(kBlnBaselineOffset));

DENORM denorm2;
FCOORD rotation90(0.0f, 1.0f);
denorm2.SetupNormalization(NULL, &rotation90, &denorm, 128.0f, 128.0f, 0.5f,
denorm2.SetupNormalization(nullptr, &rotation90, &denorm, 128.0f, 128.0f, 0.5f,
0.25f, 0.0f, 0.0f);
TPOINT pt1(1050, 2000);
TPOINT result1(100, kBlnBaselineOffset);
8 changes: 4 additions & 4 deletions unittest/equationdetect_test.cc
Original file line number Diff line number Diff line change
@@ -117,8 +117,8 @@ class EquationFinderTest : public testing::Test {
}

void TearDown() {
tesseract_.reset(NULL);
equation_det_.reset(NULL);
tesseract_.reset(nullptr);
equation_det_.reset(nullptr);
}

// Add a BLOCK covering the whole page.
@@ -169,7 +169,7 @@ TEST_F(EquationFinderTest, IdentifySpecialText) {
// Load Image.
string imagefile = file::JoinPath(testdata_dir_, "equ_gt1.tif");
Pix* pix_binary = pixRead(imagefile.c_str());
CHECK(pix_binary != NULL && pixGetDepth(pix_binary) == 1);
CHECK(pix_binary != nullptr && pixGetDepth(pix_binary) == 1);

// Get components.
BLOCK_LIST blocks;
@@ -364,7 +364,7 @@ TEST_F(EquationFinderTest, ComputeForegroundDensity) {
// Create the pix with top half foreground, bottom half background.
int width = 1024, height = 768;
Pix* pix = pixCreate(width, height, 1);
pixRasterop(pix, 0, 0, width, height / 2, PIX_SET, NULL, 0, 0);
pixRasterop(pix, 0, 0, width, height / 2, PIX_SET, nullptr, 0, 0);
TBOX box1(100, 0, 140, 140), box2(100, height / 2 - 20, 140, height / 2 + 20),
box3(100, height - 40, 140, height);
equation_det_->SetPixBinary(pix);
14 changes: 7 additions & 7 deletions unittest/heap_test.cc
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ class HeapTest : public testing::Test {
// Indices don't necessarily match for equal keys, so don't test them.
if (i + 1 < v->size() && (*v)[i + 1].key == (*v)[i].key) {
while (i + 1 < v->size() && (*v)[i + 1].key == (*v)[i].key) {
heap->Pop(NULL);
heap->Pop(nullptr);
++i;
EXPECT_FALSE(heap->empty());
EXPECT_EQ((*v)[i].key, heap->PeekTop().key);
@@ -61,7 +61,7 @@ class HeapTest : public testing::Test {
EXPECT_EQ((*v)[i].data, heap->PeekTop().data);
}
EXPECT_FALSE(heap->empty());
EXPECT_TRUE(heap->Pop(NULL));
EXPECT_TRUE(heap->Pop(nullptr));
}
EXPECT_TRUE(heap->empty());
}
@@ -95,7 +95,7 @@ TEST_F(HeapTest, MixedTest) {
// Sort the vector and remove the first 5 values from both heap and v.
v.sort();
for (int i = 0; i < 5; ++i) {
heap.Pop(NULL);
heap.Pop(nullptr);
v.remove(0);
}
// Push the test data onto both the heap and the KDVector.
@@ -162,7 +162,7 @@ TEST_F(HeapTest, RevalueTest) {
for (int i = 0; i < v.size(); ++i) {
EXPECT_EQ(v[i].key, heap.PeekTop().key);
EXPECT_FALSE(heap.empty());
heap.Pop(NULL);
heap.Pop(nullptr);
}
EXPECT_TRUE(heap.empty());
}
@@ -174,7 +174,7 @@ TEST_F(HeapTest, RevalueTest) {
static void ConstRefTest(const DoublePtr& ptr1) {
DoublePtr ptr2(ptr1); // Compiler error here.
EXPECT_EQ(&ptr2, ptr2.OtherEnd()->OtherEnd());
EXPECT_TRUE(ptr1.OtherEnd() == NULL);
EXPECT_TRUE(ptr1.OtherEnd() == nullptr);
}
#endif

@@ -186,11 +186,11 @@ TEST_F(HeapTest, DoublePtrTest) {
// Check that the correct copy constructor is used.
DoublePtr ptr3(ptr1);
EXPECT_EQ(&ptr3, ptr3.OtherEnd()->OtherEnd());
EXPECT_TRUE(ptr1.OtherEnd() == NULL);
EXPECT_TRUE(ptr1.OtherEnd() == nullptr);
// Check that the correct operator= is used.
ptr1 = ptr3;
EXPECT_EQ(&ptr1, ptr1.OtherEnd()->OtherEnd());
EXPECT_TRUE(ptr3.OtherEnd() == NULL);
EXPECT_TRUE(ptr3.OtherEnd() == nullptr);
}

} // namespace tesseract
8 changes: 4 additions & 4 deletions unittest/imagedata_test.cc
Original file line number Diff line number Diff line change
@@ -30,14 +30,14 @@ class ImagedataTest : public ::testing::Test {
// Make an imagedata and put it in the document.
ImageData* imagedata =
ImageData::Build("noname", p, "eng", fake_image.data(),
fake_image.size(), (*page_texts)[p].c_str(), NULL);
fake_image.size(), (*page_texts)[p].c_str(), nullptr);
EXPECT_EQ(kImageSize, imagedata->MemoryUsed());
write_doc.AddPageToDocument(imagedata);
}
// Write it to a file.
string filename = file::JoinPath(
FLAGS_test_tmpdir, absl::StrCat("documentdata", doc_id, ".lstmf"));
EXPECT_TRUE(write_doc.SaveDocument(filename.c_str(), NULL));
EXPECT_TRUE(write_doc.SaveDocument(filename.c_str(), nullptr));
return filename;
}
};
@@ -59,13 +59,13 @@ TEST_F(ImagedataTest, CachesProperly) {
for (int m = 0; kMemoryAllowances[m] > 0; ++m) {
DocumentData read_doc("My document");
EXPECT_TRUE(
read_doc.LoadDocument(filename.c_str(), 0, kMemoryAllowances[m], NULL));
read_doc.LoadDocument(filename.c_str(), 0, kMemoryAllowances[m], nullptr));
LOG(ERROR) << "Allowance = " << kMemoryAllowances[m];
// Read the pages in a specific order.
for (int p = 0; kPageReadOrder[p] >= 0; ++p) {
int page = kPageReadOrder[p];
const ImageData* imagedata = read_doc.GetPage(page);
EXPECT_NE(reinterpret_cast<const ImageData*>(NULL), imagedata);
EXPECT_NE(reinterpret_cast<const ImageData*>(nullptr), imagedata);
// Check that this is the right page.
EXPECT_STREQ(page_texts[page].c_str(),
imagedata->transcription().string());
Loading

0 comments on commit 4ec9c86

Please sign in to comment.