mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-23 18:49:08 +08:00
Replace access/_access by std::filesystem::exists (#4307)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
ee80dfe509
commit
fc50324986
@ -10,10 +10,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <io.h> // for _access
|
||||
#endif
|
||||
|
||||
#include "ccutil.h"
|
||||
#include "tprintf.h" // for tprintf
|
||||
|
||||
@ -63,7 +59,7 @@ void CCUtil::main_setup(const std::string &argv0, const std::string &basename) {
|
||||
/* Use tessdata prefix from the environment. */
|
||||
datadir = tessdata_prefix;
|
||||
#if defined(_WIN32)
|
||||
} else if (datadir.empty() || _access(datadir.c_str(), 0) != 0) {
|
||||
} else if (datadir.empty() || !std::filesystem::exists(datadir)) {
|
||||
/* Look for tessdata in directory of executable. */
|
||||
char path[_MAX_PATH];
|
||||
DWORD length = GetModuleFileName(nullptr, path, sizeof(path));
|
||||
@ -73,7 +69,7 @@ void CCUtil::main_setup(const std::string &argv0, const std::string &basename) {
|
||||
*separator = '\0';
|
||||
std::string subdir = path;
|
||||
subdir += "/tessdata";
|
||||
if (_access(subdir.c_str(), 0) == 0) {
|
||||
if (std::filesystem::exists(subdir)) {
|
||||
datadir = subdir;
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <io.h> // for _access
|
||||
#else
|
||||
# include <unistd.h> // for access
|
||||
#endif
|
||||
#include <allheaders.h>
|
||||
#include <tesseract/baseapi.h>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include "helpers.h"
|
||||
#include "include_gunit.h"
|
||||
@ -24,15 +20,6 @@
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Replacement for std::filesystem::exists (C++-17)
|
||||
static bool file_exists(const char *filename) {
|
||||
#if defined(_WIN32)
|
||||
return _access(filename, 0) == 0;
|
||||
#else
|
||||
return access(filename, 0) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// The fixture for testing Tesseract.
|
||||
class PageSegModeTest : public testing::Test {
|
||||
protected:
|
||||
@ -86,7 +73,7 @@ protected:
|
||||
// and differently to line and block mode.
|
||||
TEST_F(PageSegModeTest, WordTest) {
|
||||
std::string filename = file::JoinPath(TESTING_DIR, "segmodeimg.tif");
|
||||
if (!file_exists(filename.c_str())) {
|
||||
if (!std::filesystem::exists(filename)) {
|
||||
LOG(INFO) << "Skip test because of missing " << filename << '\n';
|
||||
GTEST_SKIP();
|
||||
} else {
|
||||
|
@ -9,12 +9,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#if defined(_WIN32)
|
||||
# include <io.h> // for _access
|
||||
#else
|
||||
# include <unistd.h> // for access
|
||||
#endif
|
||||
|
||||
#include <filesystem>
|
||||
#include "dawg.h"
|
||||
#include "include_gunit.h"
|
||||
#include "trie.h"
|
||||
@ -23,15 +18,6 @@
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Replacement for std::filesystem::exists (C++-17)
|
||||
static bool file_exists(const char *filename) {
|
||||
#if defined(_WIN32)
|
||||
return _access(filename, 0) == 0;
|
||||
#else
|
||||
return access(filename, 0) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
class TatweelTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
@ -41,7 +27,7 @@ protected:
|
||||
|
||||
TatweelTest() {
|
||||
std::string filename = TestDataNameToPath("ara.wordlist");
|
||||
if (file_exists(filename.c_str())) {
|
||||
if (std::filesystem::exists(filename)) {
|
||||
std::string wordlist("\u0640");
|
||||
CHECK_OK(file::GetContents(filename, &wordlist, file::Defaults()));
|
||||
// Put all the unicodes in the unicharset_.
|
||||
@ -77,7 +63,7 @@ TEST_F(TatweelTest, DictIgnoresTatweel) {
|
||||
// This test verifies that the dictionary ignores the Tatweel character.
|
||||
tesseract::Trie trie(tesseract::DAWG_TYPE_WORD, "ara", SYSTEM_DAWG_PERM, unicharset_.size(), 0);
|
||||
std::string filename = TestDataNameToPath("ara.wordlist");
|
||||
if (!file_exists(filename.c_str())) {
|
||||
if (!std::filesystem::exists(filename)) {
|
||||
LOG(INFO) << "Skip test because of missing " << filename;
|
||||
GTEST_SKIP();
|
||||
} else {
|
||||
@ -91,7 +77,7 @@ TEST_F(TatweelTest, UnicharsetLoadKeepsTatweel) {
|
||||
// This test verifies that a load of an existing unicharset keeps any
|
||||
// existing tatweel for backwards compatibility.
|
||||
std::string filename = TestDataNameToPath("ara.unicharset");
|
||||
if (!file_exists(filename.c_str())) {
|
||||
if (!std::filesystem::exists(filename)) {
|
||||
LOG(INFO) << "Skip test because of missing " << filename;
|
||||
GTEST_SKIP();
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user