2017-09-08 22:06:19 +08:00
|
|
|
// (C) Copyright 2017, Google Inc.
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
// Portability include to match the Google test environment.
|
2018-08-25 16:29:29 +08:00
|
|
|
|
2017-09-08 22:06:19 +08:00
|
|
|
#ifndef TESSERACT_UNITTEST_INCLUDE_GUNIT_H_
|
|
|
|
#define TESSERACT_UNITTEST_INCLUDE_GUNIT_H_
|
|
|
|
|
2018-09-29 15:19:13 +08:00
|
|
|
#include "errcode.h" // for ASSERT_HOST
|
|
|
|
#include "fileio.h" // for tesseract::File
|
2020-12-28 07:32:27 +08:00
|
|
|
|
2017-09-08 22:06:19 +08:00
|
|
|
#include "gtest/gtest.h"
|
2018-08-25 16:29:29 +08:00
|
|
|
|
2019-01-24 15:01:19 +08:00
|
|
|
const char* FLAGS_test_tmpdir = "./tmp";
|
2018-08-25 16:29:29 +08:00
|
|
|
|
2018-10-12 04:12:28 +08:00
|
|
|
class file : public tesseract::File {
|
|
|
|
public:
|
2019-01-19 13:13:03 +08:00
|
|
|
|
2020-12-31 01:17:58 +08:00
|
|
|
static void MakeTmpdir() {
|
|
|
|
#if defined(_WIN32)
|
|
|
|
_mkdir(FLAGS_test_tmpdir);
|
|
|
|
#else
|
|
|
|
mkdir(FLAGS_test_tmpdir, S_IRWXU | S_IRWXG);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-01-19 13:13:03 +08:00
|
|
|
// Create a file and write a string to it.
|
2019-01-19 15:34:00 +08:00
|
|
|
static bool WriteStringToFile(const std::string& contents, const std::string& filename) {
|
|
|
|
File::WriteStringToFileOrDie(contents, filename);
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-19 13:13:03 +08:00
|
|
|
|
2018-10-12 04:12:28 +08:00
|
|
|
static bool GetContents(const std::string& filename, std::string* out, int) {
|
|
|
|
return File::ReadFileToString(filename, out);
|
|
|
|
}
|
2018-08-25 16:29:29 +08:00
|
|
|
|
2019-01-19 13:13:03 +08:00
|
|
|
static bool SetContents(const std::string& name, const std::string& contents, bool /*is_default*/) {
|
|
|
|
return WriteStringToFile(contents, name);
|
|
|
|
}
|
|
|
|
|
2018-10-12 04:12:28 +08:00
|
|
|
static int Defaults() {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-10-12 17:29:45 +08:00
|
|
|
|
|
|
|
static std::string JoinPath(const std::string& s1, const std::string& s2) {
|
|
|
|
return tesseract::File::JoinPath(s1, s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string JoinPath(const std::string& s1, const std::string& s2,
|
|
|
|
const std::string& s3) {
|
|
|
|
return JoinPath(JoinPath(s1, s2), s3);
|
|
|
|
}
|
2018-10-12 04:12:28 +08:00
|
|
|
};
|
|
|
|
|
2018-08-26 00:36:43 +08:00
|
|
|
#define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
2019-06-30 21:26:28 +08:00
|
|
|
|
|
|
|
// /usr/include/tensorflow/core/platform/default/logging.h defines the CHECK* macros.
|
|
|
|
#if !defined(CHECK)
|
2018-08-25 16:29:29 +08:00
|
|
|
#define CHECK(test) ASSERT_HOST(test)
|
2019-06-30 18:36:20 +08:00
|
|
|
#define CHECK_EQ(test, value) CHECK((test) == (value))
|
|
|
|
#define CHECK_GT(test, value) CHECK((test) > (value))
|
|
|
|
#define CHECK_LT(test, value) CHECK((test) < (value))
|
|
|
|
#define CHECK_LE(test, value) CHECK((test) <= (value))
|
|
|
|
#define CHECK_OK(test) CHECK(test)
|
2019-06-30 21:26:28 +08:00
|
|
|
#endif
|
2017-09-08 22:06:19 +08:00
|
|
|
|
|
|
|
#endif // TESSERACT_UNITTEST_INCLUDE_GUNIT_H_
|