Skip to content

Commit 4ec9c86

Browse files
committed
unittest: Replace NULL by nullptr
Signed-off-by: Stefan Weil <[email protected]>
1 parent 9e66fb9 commit 4ec9c86

20 files changed

+162
-162
lines changed

unittest/applybox_test.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ApplyBoxTest : public testing::Test {
3636
return file::JoinPath(FLAGS_test_tmpdir, name);
3737
}
3838

39-
ApplyBoxTest() { src_pix_ = NULL; }
39+
ApplyBoxTest() { src_pix_ = nullptr; }
4040
~ApplyBoxTest() { pixDestroy(&src_pix_); }
4141

4242
void SetImage(const char* filename) {
@@ -61,15 +61,15 @@ class ApplyBoxTest : public testing::Test {
6161
api_.SetVariable("tessedit_resegment_from_line_boxes", "1");
6262
else
6363
api_.SetVariable("tessedit_resegment_from_boxes", "1");
64-
api_.Recognize(NULL);
64+
api_.Recognize(nullptr);
6565
char* ocr_text = api_.GetUTF8Text();
6666
EXPECT_STREQ(truth_str, ocr_text);
6767
delete[] ocr_text;
6868
// Test the boxes by reading the target box file in parallel with the
6969
// bounding boxes in the ocr output.
7070
std::string box_filename = TestDataNameToPath(target_box_file);
7171
FILE* box_file = OpenBoxFile(STRING(box_filename.c_str()));
72-
ASSERT_TRUE(box_file != NULL);
72+
ASSERT_TRUE(box_file != nullptr);
7373
int height = pixGetHeight(src_pix_);
7474
ResultIterator* it = api_.GetIterator();
7575
do {

unittest/baseapi_test.cc

+21-21
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace {
1111
using ::testing::ContainsRegex;
1212
using ::testing::HasSubstr;
1313

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

2222
class FriendlyTessBaseAPI : public tesseract::TessBaseAPI {
2323
FRIEND_TEST(TesseractTest, LSTMGeometryTest);
@@ -78,11 +78,11 @@ TEST_F(TesseractTest, IteratesParagraphsEvenIfNotDetected) {
7878
CHECK(src_pix);
7979
api.SetImage(src_pix);
8080
Boxa* para_boxes =
81-
api.GetComponentImages(tesseract::RIL_PARA, true, NULL, NULL);
82-
EXPECT_TRUE(para_boxes != NULL);
81+
api.GetComponentImages(tesseract::RIL_PARA, true, nullptr, nullptr);
82+
EXPECT_TRUE(para_boxes != nullptr);
8383
Boxa* block_boxes =
84-
api.GetComponentImages(tesseract::RIL_BLOCK, true, NULL, NULL);
85-
EXPECT_TRUE(block_boxes != NULL);
84+
api.GetComponentImages(tesseract::RIL_BLOCK, true, nullptr, nullptr);
85+
EXPECT_TRUE(block_boxes != nullptr);
8686
// TODO(eger): Get paragraphs out of this page pre-text.
8787
EXPECT_GE(boxaGetCount(para_boxes), boxaGetCount(block_boxes));
8888
boxaDestroy(&block_boxes);
@@ -99,7 +99,7 @@ TEST_F(TesseractTest, HOCRWorksWithoutSetInputName) {
9999
CHECK(src_pix);
100100
api.SetImage(src_pix);
101101
char* result = api.GetHOCRText(0);
102-
EXPECT_TRUE(result != NULL);
102+
EXPECT_TRUE(result != nullptr);
103103
EXPECT_THAT(result, HasSubstr("Hello"));
104104
EXPECT_THAT(result, HasSubstr("<div class='ocr_page'"));
105105
delete[] result;
@@ -115,7 +115,7 @@ TEST_F(TesseractTest, HOCRContainsBaseline) {
115115
api.SetInputName("HelloGoogle.tif");
116116
api.SetImage(src_pix);
117117
char* result = api.GetHOCRText(0);
118-
EXPECT_TRUE(result != NULL);
118+
EXPECT_TRUE(result != nullptr);
119119
EXPECT_THAT(result, HasSubstr("Hello"));
120120
EXPECT_THAT(result, ContainsRegex("<span class='ocr_line'[^>]* "
121121
"baseline [-.0-9]+ [-.0-9]+"));
@@ -134,7 +134,7 @@ TEST_F(TesseractTest, RickSnyderNotFuckSnyder) {
134134
CHECK(src_pix);
135135
api.SetImage(src_pix);
136136
char* result = api.GetHOCRText(0);
137-
EXPECT_TRUE(result != NULL);
137+
EXPECT_TRUE(result != nullptr);
138138
EXPECT_THAT(result, Not(HasSubstr("FUCK")));
139139
delete[] result;
140140
pixDestroy(&src_pix);
@@ -145,20 +145,20 @@ TEST_F(TesseractTest, AdaptToWordStrTest) {
145145
static const char* kTrainingPages[] = {
146146
"136.tif", "256.tif", "410.tif", "432.tif", "540.tif",
147147
"692.tif", "779.tif", "793.tif", "808.tif", "815.tif",
148-
"12.tif", "12.tif", NULL};
148+
"12.tif", "12.tif", nullptr};
149149
static const char* kTrainingText[] = {
150150
"1 3 6", "2 5 6", "4 1 0", "4 3 2", "5 4 0", "6 9 2", "7 7 9",
151-
"7 9 3", "8 0 8", "8 1 5", "1 2", "1 2", NULL};
152-
static const char* kTestPages[] = {"324.tif", "433.tif", "12.tif", NULL};
153-
static const char* kTestText[] = {"324", "433", "12", NULL};
151+
"7 9 3", "8 0 8", "8 1 5", "1 2", "1 2", nullptr};
152+
static const char* kTestPages[] = {"324.tif", "433.tif", "12.tif", nullptr};
153+
static const char* kTestText[] = {"324", "433", "12", nullptr};
154154
tesseract::TessBaseAPI api;
155155
string truth_text;
156156
string ocr_text;
157157
api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_TESSERACT_ONLY);
158158
api.SetVariable("matcher_sufficient_examples_for_prototyping", "1");
159159
api.SetVariable("classify_class_pruner_threshold", "220");
160160
// Train on the training text.
161-
for (int i = 0; kTrainingPages[i] != NULL; ++i) {
161+
for (int i = 0; kTrainingPages[i] != nullptr; ++i) {
162162
string image_file = TestDataNameToPath(kTrainingPages[i]);
163163
Pix* src_pix = pixRead(image_file.c_str());
164164
CHECK(src_pix);
@@ -172,7 +172,7 @@ TEST_F(TesseractTest, AdaptToWordStrTest) {
172172
// Test the test text.
173173
api.SetVariable("tess_bn_matching", "1");
174174
api.SetPageSegMode(tesseract::PSM_SINGLE_WORD);
175-
for (int i = 0; kTestPages[i] != NULL; ++i) {
175+
for (int i = 0; kTestPages[i] != nullptr; ++i) {
176176
Pix* src_pix = pixRead(TestDataNameToPath(kTestPages[i]).c_str());
177177
CHECK(src_pix);
178178
ocr_text = GetCleanedTextResult(&api, src_pix);
@@ -209,7 +209,7 @@ TEST_F(TesseractTest, LSTMGeometryTest) {
209209
FriendlyTessBaseAPI api;
210210
api.Init(TessdataPath().c_str(), "eng", tesseract::OEM_LSTM_ONLY);
211211
api.SetImage(src_pix);
212-
ASSERT_EQ(api.Recognize(NULL), 0);
212+
ASSERT_EQ(api.Recognize(nullptr), 0);
213213

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

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

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

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

299299
tesseract::TessBaseAPI tess;
300300
EXPECT_EQ(0, tess.Init(kTessdataPath.c_str(), langs[i]));

unittest/baseapi_thread_test.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ using tesseract::TessBaseAPI;
3737

3838
namespace {
3939

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

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

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

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

109-
void WaitForPoolWorkers() { pool_.reset(NULL); }
109+
void WaitForPoolWorkers() { pool_.reset(nullptr); }
110110

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

140140
void VerifyTextResult(TessBaseAPI* tess, Pix* pix, const string& lang,
141141
const string& expected_text) {
142-
TessBaseAPI* tess_local = NULL;
142+
TessBaseAPI* tess_local = nullptr;
143143
if (tess) {
144144
tess_local = tess;
145145
} else {
@@ -197,7 +197,7 @@ TEST_F(BaseapiThreadTest, TestAll) {
197197
const int n = num_langs_ * FLAGS_reps;
198198
ResetPool();
199199
for (int i = 0; i < n; ++i) {
200-
pool_->Add(NewCallback(VerifyTextResult, NULL, pix_[i],
200+
pool_->Add(NewCallback(VerifyTextResult, nullptr, pix_[i],
201201
langs_[i % num_langs_], gt_text_[i % num_langs_]));
202202
}
203203
WaitForPoolWorkers();

unittest/denorm_test.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ class DENORMTest : public testing::Test {
2828
if (local)
2929
denorm.LocalNormTransform(src, &normed);
3030
else
31-
denorm.NormTransform(NULL, src, &normed);
31+
denorm.NormTransform(nullptr, src, &normed);
3232
EXPECT_EQ(result.x, normed.x);
3333
EXPECT_EQ(result.y, normed.y);
3434
// Now undo
3535
TPOINT denormed;
3636
if (local)
3737
denorm.LocalDenormTransform(normed, &denormed);
3838
else
39-
denorm.DenormTransform(NULL, normed, &denormed);
39+
denorm.DenormTransform(nullptr, normed, &denormed);
4040
EXPECT_EQ(src.x, denormed.x);
4141
EXPECT_EQ(src.y, denormed.y);
4242
}
@@ -45,7 +45,7 @@ class DENORMTest : public testing::Test {
4545
// Tests a simple baseline-style normalization.
4646
TEST_F(DENORMTest, NoRotations) {
4747
DENORM denorm;
48-
denorm.SetupNormalization(NULL, NULL, NULL, 1000.0f, 2000.0f, 2.0f, 3.0f,
48+
denorm.SetupNormalization(nullptr, nullptr, nullptr, 1000.0f, 2000.0f, 2.0f, 3.0f,
4949
0.0f, static_cast<float>(kBlnBaselineOffset));
5050
TPOINT pt1(1100, 2000);
5151
TPOINT result1(200, kBlnBaselineOffset);
@@ -61,7 +61,7 @@ TEST_F(DENORMTest, NoRotations) {
6161
TEST_F(DENORMTest, WithRotations) {
6262
DENORM denorm;
6363
FCOORD rotation90(0.0f, 1.0f);
64-
denorm.SetupNormalization(NULL, &rotation90, NULL, 1000.0f, 2000.0f, 2.0f,
64+
denorm.SetupNormalization(nullptr, &rotation90, nullptr, 1000.0f, 2000.0f, 2.0f,
6565
3.0f, 0.0f, static_cast<float>(kBlnBaselineOffset));
6666

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

8383
DENORM denorm2;
8484
FCOORD rotation90(0.0f, 1.0f);
85-
denorm2.SetupNormalization(NULL, &rotation90, &denorm, 128.0f, 128.0f, 0.5f,
85+
denorm2.SetupNormalization(nullptr, &rotation90, &denorm, 128.0f, 128.0f, 0.5f,
8686
0.25f, 0.0f, 0.0f);
8787
TPOINT pt1(1050, 2000);
8888
TPOINT result1(100, kBlnBaselineOffset);

unittest/equationdetect_test.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class EquationFinderTest : public testing::Test {
117117
}
118118

119119
void TearDown() {
120-
tesseract_.reset(NULL);
121-
equation_det_.reset(NULL);
120+
tesseract_.reset(nullptr);
121+
equation_det_.reset(nullptr);
122122
}
123123

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

174174
// Get components.
175175
BLOCK_LIST blocks;
@@ -364,7 +364,7 @@ TEST_F(EquationFinderTest, ComputeForegroundDensity) {
364364
// Create the pix with top half foreground, bottom half background.
365365
int width = 1024, height = 768;
366366
Pix* pix = pixCreate(width, height, 1);
367-
pixRasterop(pix, 0, 0, width, height / 2, PIX_SET, NULL, 0, 0);
367+
pixRasterop(pix, 0, 0, width, height / 2, PIX_SET, nullptr, 0, 0);
368368
TBOX box1(100, 0, 140, 140), box2(100, height / 2 - 20, 140, height / 2 + 20),
369369
box3(100, height - 40, 140, height);
370370
equation_det_->SetPixBinary(pix);

unittest/heap_test.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class HeapTest : public testing::Test {
5151
// Indices don't necessarily match for equal keys, so don't test them.
5252
if (i + 1 < v->size() && (*v)[i + 1].key == (*v)[i].key) {
5353
while (i + 1 < v->size() && (*v)[i + 1].key == (*v)[i].key) {
54-
heap->Pop(NULL);
54+
heap->Pop(nullptr);
5555
++i;
5656
EXPECT_FALSE(heap->empty());
5757
EXPECT_EQ((*v)[i].key, heap->PeekTop().key);
@@ -61,7 +61,7 @@ class HeapTest : public testing::Test {
6161
EXPECT_EQ((*v)[i].data, heap->PeekTop().data);
6262
}
6363
EXPECT_FALSE(heap->empty());
64-
EXPECT_TRUE(heap->Pop(NULL));
64+
EXPECT_TRUE(heap->Pop(nullptr));
6565
}
6666
EXPECT_TRUE(heap->empty());
6767
}
@@ -95,7 +95,7 @@ TEST_F(HeapTest, MixedTest) {
9595
// Sort the vector and remove the first 5 values from both heap and v.
9696
v.sort();
9797
for (int i = 0; i < 5; ++i) {
98-
heap.Pop(NULL);
98+
heap.Pop(nullptr);
9999
v.remove(0);
100100
}
101101
// Push the test data onto both the heap and the KDVector.
@@ -162,7 +162,7 @@ TEST_F(HeapTest, RevalueTest) {
162162
for (int i = 0; i < v.size(); ++i) {
163163
EXPECT_EQ(v[i].key, heap.PeekTop().key);
164164
EXPECT_FALSE(heap.empty());
165-
heap.Pop(NULL);
165+
heap.Pop(nullptr);
166166
}
167167
EXPECT_TRUE(heap.empty());
168168
}
@@ -174,7 +174,7 @@ TEST_F(HeapTest, RevalueTest) {
174174
static void ConstRefTest(const DoublePtr& ptr1) {
175175
DoublePtr ptr2(ptr1); // Compiler error here.
176176
EXPECT_EQ(&ptr2, ptr2.OtherEnd()->OtherEnd());
177-
EXPECT_TRUE(ptr1.OtherEnd() == NULL);
177+
EXPECT_TRUE(ptr1.OtherEnd() == nullptr);
178178
}
179179
#endif
180180

@@ -186,11 +186,11 @@ TEST_F(HeapTest, DoublePtrTest) {
186186
// Check that the correct copy constructor is used.
187187
DoublePtr ptr3(ptr1);
188188
EXPECT_EQ(&ptr3, ptr3.OtherEnd()->OtherEnd());
189-
EXPECT_TRUE(ptr1.OtherEnd() == NULL);
189+
EXPECT_TRUE(ptr1.OtherEnd() == nullptr);
190190
// Check that the correct operator= is used.
191191
ptr1 = ptr3;
192192
EXPECT_EQ(&ptr1, ptr1.OtherEnd()->OtherEnd());
193-
EXPECT_TRUE(ptr3.OtherEnd() == NULL);
193+
EXPECT_TRUE(ptr3.OtherEnd() == nullptr);
194194
}
195195

196196
} // namespace tesseract

unittest/imagedata_test.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class ImagedataTest : public ::testing::Test {
3030
// Make an imagedata and put it in the document.
3131
ImageData* imagedata =
3232
ImageData::Build("noname", p, "eng", fake_image.data(),
33-
fake_image.size(), (*page_texts)[p].c_str(), NULL);
33+
fake_image.size(), (*page_texts)[p].c_str(), nullptr);
3434
EXPECT_EQ(kImageSize, imagedata->MemoryUsed());
3535
write_doc.AddPageToDocument(imagedata);
3636
}
3737
// Write it to a file.
3838
string filename = file::JoinPath(
3939
FLAGS_test_tmpdir, absl::StrCat("documentdata", doc_id, ".lstmf"));
40-
EXPECT_TRUE(write_doc.SaveDocument(filename.c_str(), NULL));
40+
EXPECT_TRUE(write_doc.SaveDocument(filename.c_str(), nullptr));
4141
return filename;
4242
}
4343
};
@@ -59,13 +59,13 @@ TEST_F(ImagedataTest, CachesProperly) {
5959
for (int m = 0; kMemoryAllowances[m] > 0; ++m) {
6060
DocumentData read_doc("My document");
6161
EXPECT_TRUE(
62-
read_doc.LoadDocument(filename.c_str(), 0, kMemoryAllowances[m], NULL));
62+
read_doc.LoadDocument(filename.c_str(), 0, kMemoryAllowances[m], nullptr));
6363
LOG(ERROR) << "Allowance = " << kMemoryAllowances[m];
6464
// Read the pages in a specific order.
6565
for (int p = 0; kPageReadOrder[p] >= 0; ++p) {
6666
int page = kPageReadOrder[p];
6767
const ImageData* imagedata = read_doc.GetPage(page);
68-
EXPECT_NE(reinterpret_cast<const ImageData*>(NULL), imagedata);
68+
EXPECT_NE(reinterpret_cast<const ImageData*>(nullptr), imagedata);
6969
// Check that this is the right page.
7070
EXPECT_STREQ(page_texts[page].c_str(),
7171
imagedata->transcription().string());

0 commit comments

Comments
 (0)