diff --git a/include/tesseract/baseapi.h b/include/tesseract/baseapi.h index 712a5b9cc..ac800bbaf 100644 --- a/include/tesseract/baseapi.h +++ b/include/tesseract/baseapi.h @@ -498,11 +498,6 @@ class TESS_API TessBaseAPI { * Recognize() or TesseractRect(). (Recognize is called implicitly if needed.) */ -#ifndef DISABLED_LEGACY_ENGINE - /** Variant on Recognize used for testing chopper. */ - int RecognizeForChopTest(ETEXT_DESC* monitor); -#endif - /** * Turns images into symbolic text. * diff --git a/include/tesseract/capi.h b/include/tesseract/capi.h index d7920a98e..f8db2f0cd 100644 --- a/include/tesseract/capi.h +++ b/include/tesseract/capi.h @@ -326,11 +326,6 @@ TESS_API TessPageIterator* TessBaseAPIAnalyseLayout(TessBaseAPI* handle); TESS_API int TessBaseAPIRecognize(TessBaseAPI* handle, ETEXT_DESC* monitor); -#ifndef DISABLED_LEGACY_ENGINE -TESS_API int TessBaseAPIRecognizeForChopTest(TessBaseAPI* handle, - ETEXT_DESC* monitor); -#endif - TESS_API BOOL TessBaseAPIProcessPages(TessBaseAPI* handle, const char* filename, const char* retry_config, int timeout_millisec, diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index 38269cd96..4cfe84029 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -893,40 +893,6 @@ int TessBaseAPI::Recognize(ETEXT_DESC* monitor) { return result; } -#ifndef DISABLED_LEGACY_ENGINE -/** Tests the chopper by exhaustively running chop_one_blob. */ -int TessBaseAPI::RecognizeForChopTest(ETEXT_DESC* monitor) { - if (tesseract_ == nullptr) - return -1; - if (thresholder_ == nullptr || thresholder_->IsEmpty()) { - tprintf("Please call SetImage before attempting recognition.\n"); - return -1; - } - if (page_res_ != nullptr) - ClearResults(); - if (FindLines() != 0) - return -1; - // Additional conditions under which chopper test cannot be run - if (tesseract_->interactive_display_mode) return -1; - - recognition_done_ = true; - - page_res_ = new PAGE_RES(false, block_list_, - &(tesseract_->prev_word_best_choice_)); - - PAGE_RES_IT page_res_it(page_res_); - - while (page_res_it.word() != nullptr) { - WERD_RES *word_res = page_res_it.word(); - std::vector boxes; - tesseract_->MaximallyChopWord(boxes, page_res_it.block()->block, - page_res_it.row()->row, word_res); - page_res_it.forward(); - } - return 0; -} -#endif // ndef DISABLED_LEGACY_ENGINE - // Takes ownership of the input pix. void TessBaseAPI::SetInputImage(Pix* pix) { tesseract_->set_pix_original(pix); } diff --git a/src/api/capi.cpp b/src/api/capi.cpp index cb3e99156..352b14168 100644 --- a/src/api/capi.cpp +++ b/src/api/capi.cpp @@ -458,13 +458,6 @@ int TessBaseAPIRecognize(TessBaseAPI* handle, return handle->Recognize(monitor); } -#ifndef DISABLED_LEGACY_ENGINE -int TessBaseAPIRecognizeForChopTest(TessBaseAPI* handle, - ETEXT_DESC* monitor) { - return handle->RecognizeForChopTest(monitor); -} -#endif - BOOL TessBaseAPIProcessPages(TessBaseAPI* handle, const char* filename, const char* retry_config, diff --git a/src/ccutil/clst.h b/src/ccutil/clst.h index b362a5778..f04f4ba92 100644 --- a/src/ccutil/clst.h +++ b/src/ccutil/clst.h @@ -877,22 +877,28 @@ CLISTIZEH_C. \ CLASSNAME##_C_IT(CLASSNAME##_CLIST *list) : CLIST_ITERATOR(list) {} \ \ - CLASSNAME *data() { return (CLASSNAME *)CLIST_ITERATOR::data(); } \ - \ - CLASSNAME *data_relative(int8_t offset) { \ - return (CLASSNAME *)CLIST_ITERATOR::data_relative(offset); \ + CLASSNAME* data() { \ + return static_cast(CLIST_ITERATOR::data()); \ } \ \ - CLASSNAME *forward() { return (CLASSNAME *)CLIST_ITERATOR::forward(); } \ - \ - CLASSNAME *extract() { return (CLASSNAME *)CLIST_ITERATOR::extract(); } \ - \ - CLASSNAME *move_to_first() { \ - return (CLASSNAME *)CLIST_ITERATOR::move_to_first(); \ + CLASSNAME* data_relative(int8_t offset) { \ + return static_cast(CLIST_ITERATOR::data_relative(offset)); \ } \ \ - CLASSNAME *move_to_last() { \ - return (CLASSNAME *)CLIST_ITERATOR::move_to_last(); \ + CLASSNAME* forward() { \ + return static_cast(CLIST_ITERATOR::forward()); \ + } \ + \ + CLASSNAME* extract() { \ + return static_cast(CLIST_ITERATOR::extract()); \ + } \ + \ + CLASSNAME* move_to_first() { \ + return static_cast(CLIST_ITERATOR::move_to_first()); \ + } \ + \ + CLASSNAME* move_to_last() { \ + return static_cast(CLIST_ITERATOR::move_to_last()); \ } \ }; @@ -923,7 +929,7 @@ CLISTIZEH_C. DLLSYM void CLASSNAME##_c1_zapper( /*delete a link*/ \ void *link) /*link to delete*/ \ { \ - delete (CLASSNAME *)link; \ + delete static_cast(link); \ } } // namespace tesseract diff --git a/src/ccutil/elst.h b/src/ccutil/elst.h index 0bfd21573..509617e6b 100644 --- a/src/ccutil/elst.h +++ b/src/ccutil/elst.h @@ -913,7 +913,7 @@ class DLLSYM CLASSNAME##_IT : public ELIST_ITERATOR { \ return reinterpret_cast(ELIST_ITERATOR::data()); \ } \ \ - CLASSNAME* data_relative(int8_t offset) { \ + CLASSNAME* data_relative(int8_t offset) { \ return reinterpret_cast(ELIST_ITERATOR::data_relative(offset));\ } \ \ diff --git a/src/ccutil/elst2.h b/src/ccutil/elst2.h index 0dd45ab78..f2ea16d08 100644 --- a/src/ccutil/elst2.h +++ b/src/ccutil/elst2.h @@ -922,24 +922,32 @@ ELIST2IZEH_C. public: \ CLASSNAME##_IT(CLASSNAME##_LIST *list) : ELIST2_ITERATOR(list) {} \ \ - CLASSNAME *data() { return (CLASSNAME *)ELIST2_ITERATOR::data(); } \ - \ - CLASSNAME *data_relative(int8_t offset) { \ - return (CLASSNAME *)ELIST2_ITERATOR::data_relative(offset); \ + CLASSNAME* data() { \ + return reinterpret_cast(ELIST2_ITERATOR::data()); \ } \ \ - CLASSNAME *forward() { return (CLASSNAME *)ELIST2_ITERATOR::forward(); } \ - \ - CLASSNAME *backward() { return (CLASSNAME *)ELIST2_ITERATOR::backward(); } \ - \ - CLASSNAME *extract() { return (CLASSNAME *)ELIST2_ITERATOR::extract(); } \ - \ - CLASSNAME *move_to_first() { \ - return (CLASSNAME *)ELIST2_ITERATOR::move_to_first(); \ + CLASSNAME* data_relative(int8_t offset) { \ + return reinterpret_cast(ELIST2_ITERATOR::data_relative(offset)); \ } \ \ - CLASSNAME *move_to_last() { \ - return (CLASSNAME *)ELIST2_ITERATOR::move_to_last(); \ + CLASSNAME* forward() { \ + return reinterpret_cast(ELIST2_ITERATOR::forward()); \ + } \ + \ + CLASSNAME* backward() { \ + return reinterpret_cast(ELIST2_ITERATOR::backward()); \ + } \ + \ + CLASSNAME* extract() { \ + return reinterpret_cast(ELIST2_ITERATOR::extract()); \ + } \ + \ + CLASSNAME* move_to_first() { \ + return reinterpret_cast(ELIST2_ITERATOR::move_to_first()); \ + } \ + \ + CLASSNAME* move_to_last() { \ + return reinterpret_cast(ELIST2_ITERATOR::move_to_last()); \ } \ private: \ CLASSNAME##_IT(); \ @@ -971,7 +979,7 @@ ELIST2IZEH_C. DLLSYM void CLASSNAME##_zapper( /*delete a link*/ \ ELIST2_LINK *link) /*link to delete*/ \ { \ - delete (CLASSNAME *)link; \ + delete reinterpret_cast(link); \ } \ \ /* Become a deep copy of src_list*/ \ diff --git a/unittest/bitvector_test.cc b/unittest/bitvector_test.cc index 6eb9b1ef7..9be718a07 100644 --- a/unittest/bitvector_test.cc +++ b/unittest/bitvector_test.cc @@ -25,6 +25,7 @@ class BitVectorTest : public testing::Test { protected: void SetUp() override { std::locale::global(std::locale("")); + file::MakeTmpdir(); } public: @@ -117,11 +118,6 @@ TEST_F(BitVectorTest, Primes) { map3 = map; TestPrimes(map3); // Test file i/o too. -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif std::string filename = OutputNameToPath("primesbitvector"); FILE* fp = fopen(filename.c_str(), "wb"); ASSERT_TRUE(fp != nullptr); diff --git a/unittest/dawg_test.cc b/unittest/dawg_test.cc index b90602c91..4a40b0509 100644 --- a/unittest/dawg_test.cc +++ b/unittest/dawg_test.cc @@ -35,6 +35,7 @@ class DawgTest : public testing::Test { protected: void SetUp() { std::locale::global(std::locale("")); + file::MakeTmpdir(); } void LoadWordlist(const std::string& filename, std::set* words) const { @@ -74,11 +75,6 @@ class DawgTest : public testing::Test { std::string orig_wordlist = file::JoinPath(TESTING_DIR, wordlist_filename); std::string output_dawg = OutputNameToPath(wordlist_filename + ".dawg"); std::string output_wordlist = OutputNameToPath(wordlist_filename); -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif LoadWordlist(orig_wordlist, &orig_words); EXPECT_EQ( RunCommand(wordlist2dawg_prog, orig_wordlist, output_dawg, unicharset), 0); diff --git a/unittest/imagedata_test.cc b/unittest/imagedata_test.cc index d51c9ad63..31bd2f24b 100644 --- a/unittest/imagedata_test.cc +++ b/unittest/imagedata_test.cc @@ -27,6 +27,7 @@ class ImagedataTest : public ::testing::Test { protected: void SetUp() { std::locale::global(std::locale("")); + file::MakeTmpdir(); } ImagedataTest() {} @@ -51,11 +52,6 @@ class ImagedataTest : public ::testing::Test { EXPECT_EQ(kImageSize, imagedata->MemoryUsed()); write_doc.AddPageToDocument(imagedata); } -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif // Write it to a file. std::string filename = file::JoinPath( FLAGS_test_tmpdir, absl::StrCat("documentdata", doc_id, ".lstmf")); diff --git a/unittest/include_gunit.h b/unittest/include_gunit.h index cbdf3fd21..8d27ab48a 100644 --- a/unittest/include_gunit.h +++ b/unittest/include_gunit.h @@ -23,6 +23,14 @@ const char* FLAGS_test_tmpdir = "./tmp"; class file : public tesseract::File { public: + static void MakeTmpdir() { +#if defined(_WIN32) + _mkdir(FLAGS_test_tmpdir); +#else + mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); +#endif + } + // Create a file and write a string to it. static bool WriteStringToFile(const std::string& contents, const std::string& filename) { File::WriteStringToFileOrDie(contents, filename); diff --git a/unittest/indexmapbidi_test.cc b/unittest/indexmapbidi_test.cc index aa6df4815..bdd3c8955 100644 --- a/unittest/indexmapbidi_test.cc +++ b/unittest/indexmapbidi_test.cc @@ -25,6 +25,7 @@ class IndexMapBiDiTest : public testing::Test { protected: void SetUp() { std::locale::global(std::locale("")); + file::MakeTmpdir(); } public: @@ -78,11 +79,6 @@ TEST_F(IndexMapBiDiTest, Primes) { IndexMap base_map; base_map.CopyFrom(map); TestPrimes(base_map); -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif // Test file i/o too. std::string filename = OutputNameToPath("primesmap"); FILE* fp = fopen(filename.c_str(), "wb"); diff --git a/unittest/lang_model_test.cc b/unittest/lang_model_test.cc index 16eb9219a..538d5e059 100644 --- a/unittest/lang_model_test.cc +++ b/unittest/lang_model_test.cc @@ -41,11 +41,7 @@ TEST(LangModelTest, AddACharacter) { UNICHARSET unicharset; EXPECT_TRUE(unicharset.load_from_file(unicharset_path.c_str())); std::string version_str = "TestVersion"; -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif + file::MakeTmpdir(); std::string output_dir = FLAGS_test_tmpdir; LOG(INFO) << "Output dir=" << output_dir << "\n"; std::string lang1 = "eng"; @@ -137,11 +133,7 @@ TEST(LangModelTest, AddACharacterHindi) { UNICHARSET unicharset; EXPECT_TRUE(unicharset.load_from_file(unicharset_path.c_str())); std::string version_str = "TestVersion"; -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif + file::MakeTmpdir(); std::string output_dir = FLAGS_test_tmpdir; LOG(INFO) << "Output dir=" << output_dir << "\n"; std::string lang1 = "hin"; diff --git a/unittest/ligature_table_test.cc b/unittest/ligature_table_test.cc index 2ef4d090a..b4d1598c7 100644 --- a/unittest/ligature_table_test.cc +++ b/unittest/ligature_table_test.cc @@ -35,12 +35,7 @@ class LigatureTableTest : public ::testing::Test { void SetUp() override { static std::locale system_locale(""); std::locale::global(system_locale); - -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif + file::MakeTmpdir(); lig_table_ = LigatureTable::Get(); if (!font_map) { diff --git a/unittest/lstm_test.h b/unittest/lstm_test.h index 2fc84e28f..6da8238a5 100644 --- a/unittest/lstm_test.h +++ b/unittest/lstm_test.h @@ -47,12 +47,7 @@ class LSTMTrainerTest : public testing::Test { protected: void SetUp() { std::locale::global(std::locale("")); - -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif + file::MakeTmpdir(); } LSTMTrainerTest() {} diff --git a/unittest/lstmtrainer_test.cc b/unittest/lstmtrainer_test.cc index 77e224ac6..3e0fdb5c0 100644 --- a/unittest/lstmtrainer_test.cc +++ b/unittest/lstmtrainer_test.cc @@ -77,6 +77,7 @@ TEST_F(LSTMTrainerTest, ConvertModel) { file::JoinPath(TESSDATA_BEST_DIR, "fra.traineddata"); CHECK(mgr.Init(fra_data.c_str())); LOG(INFO) << "Load " << fra_data << "\n"; + file::MakeTmpdir(); std::string model_path = file::JoinPath(FLAGS_test_tmpdir, "fra.lstm"); CHECK(mgr.ExtractToFile(model_path.c_str())); LOG(INFO) << "Extract " << model_path << "\n"; diff --git a/unittest/mastertrainer_test.cc b/unittest/mastertrainer_test.cc index 4c73f93f9..a3a03cdab 100644 --- a/unittest/mastertrainer_test.cc +++ b/unittest/mastertrainer_test.cc @@ -150,6 +150,7 @@ class MasterTrainerTest : public testing::Test { protected: void SetUp() { std::locale::global(std::locale("")); + file::MakeTmpdir(); } std::string TestDataNameToPath(const std::string& name) { diff --git a/unittest/pango_font_info_test.cc b/unittest/pango_font_info_test.cc index 9ef09dce9..aa8d6da70 100644 --- a/unittest/pango_font_info_test.cc +++ b/unittest/pango_font_info_test.cc @@ -64,12 +64,7 @@ class PangoFontInfoTest : public ::testing::Test { void SetUp() override { static std::locale system_locale(""); std::locale::global(system_locale); - -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif + file::MakeTmpdir(); if (!font_map) { font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT); @@ -192,11 +187,7 @@ TEST_F(PangoFontInfoTest, CanDropUncoveredChars) { class FontUtilsTest : public ::testing::Test { protected: void SetUp() override { -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif + file::MakeTmpdir(); } // Creates a fake fonts.conf file that points to the testdata fonts for // fontconfig to initialize with. diff --git a/unittest/params_model_test.cc b/unittest/params_model_test.cc index 1f0c893a9..8627ab8e5 100644 --- a/unittest/params_model_test.cc +++ b/unittest/params_model_test.cc @@ -50,11 +50,7 @@ class ParamsModelTest : public testing::Test { void TestParamsModelRoundTrip(const std::string& params_model_filename) const { tesseract::ParamsModel orig_model; tesseract::ParamsModel duplicate_model; -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif + file::MakeTmpdir(); std::string orig_file = TestDataNameToPath(params_model_filename); std::string out_file = OutputNameToPath(params_model_filename); diff --git a/unittest/recodebeam_test.cc b/unittest/recodebeam_test.cc index 3cc68b092..7d7191bfa 100644 --- a/unittest/recodebeam_test.cc +++ b/unittest/recodebeam_test.cc @@ -65,6 +65,7 @@ class RecodeBeamTest : public ::testing::Test { protected: void SetUp() { std::locale::global(std::locale("")); + file::MakeTmpdir(); } RecodeBeamTest() : lstm_dict_(&ccutil_) {} diff --git a/unittest/resultiterator_test.cc b/unittest/resultiterator_test.cc index 226672154..b6fe725e3 100644 --- a/unittest/resultiterator_test.cc +++ b/unittest/resultiterator_test.cc @@ -44,6 +44,7 @@ class ResultIteratorTest : public testing::Test { return file::JoinPath(TESSDATA_DIR, ""); } std::string OutputNameToPath(const std::string& name) { + file::MakeTmpdir(); return file::JoinPath(FLAGS_test_tmpdir, name); } diff --git a/unittest/shapetable_test.cc b/unittest/shapetable_test.cc index 0688ee17a..285ed8332 100644 --- a/unittest/shapetable_test.cc +++ b/unittest/shapetable_test.cc @@ -56,6 +56,7 @@ class ShapeTest : public testing::Test { protected: void SetUp() { std::locale::global(std::locale("")); + file::MakeTmpdir(); } }; @@ -70,11 +71,6 @@ TEST_F(ShapeTest, BasicTest) { Setup352(101, &shape1); Expect352(101, shape1); // It should still work after file I/O. -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif std::string filename = TmpNameToPath("shapefile"); FILE* fp = fopen(filename.c_str(), "wb"); ASSERT_TRUE(fp != nullptr); diff --git a/unittest/stringrenderer_test.cc b/unittest/stringrenderer_test.cc index 39563a149..1c5b107ff 100644 --- a/unittest/stringrenderer_test.cc +++ b/unittest/stringrenderer_test.cc @@ -51,12 +51,7 @@ class StringRendererTest : public ::testing::Test { void SetUp() override { static std::locale system_locale(""); std::locale::global(system_locale); - -#if defined(_WIN32) - _mkdir(FLAGS_test_tmpdir); -#else - mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG); -#endif + file::MakeTmpdir(); if (!font_map) { font_map = pango_cairo_font_map_new_for_font_type(CAIRO_FONT_TYPE_FT); diff --git a/unittest/textlineprojection_test.cc b/unittest/textlineprojection_test.cc index 8f6d4d1cc..f84236152 100644 --- a/unittest/textlineprojection_test.cc +++ b/unittest/textlineprojection_test.cc @@ -34,6 +34,7 @@ const int kMinStrongTextValue = 6; class TextlineProjectionTest : public testing::Test { protected: std::string OutputNameToPath(const std::string& name) { + file::MakeTmpdir(); return file::JoinPath(FLAGS_test_tmpdir, name); } diff --git a/unittest/unicharcompress_test.cc b/unittest/unicharcompress_test.cc index ce06d641a..1777930e5 100644 --- a/unittest/unicharcompress_test.cc +++ b/unittest/unicharcompress_test.cc @@ -28,6 +28,7 @@ class UnicharcompressTest : public ::testing::Test { protected: void SetUp() { std::locale::global(std::locale("")); + file::MakeTmpdir(); } // Loads and compresses the given unicharset.