tesseract  5.0.0-alpha-619-ge9db
include_gunit.h
Go to the documentation of this file.
1 // (C) Copyright 2017, Google Inc.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 // http://www.apache.org/licenses/LICENSE-2.0
6 // Unless required by applicable law or agreed to in writing, software
7 // distributed under the License is distributed on an "AS IS" BASIS,
8 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9 // See the License for the specific language governing permissions and
10 // limitations under the License.
11 // Portability include to match the Google test environment.
12 
13 #ifndef TESSERACT_UNITTEST_INCLUDE_GUNIT_H_
14 #define TESSERACT_UNITTEST_INCLUDE_GUNIT_H_
15 
16 #include "errcode.h" // for ASSERT_HOST
17 #include "fileio.h" // for tesseract::File
18 #include "gtest/gtest.h"
19 
20 const char* FLAGS_test_tmpdir = "./tmp";
21 
22 class file : public tesseract::File {
23 public:
24 
25 // Create a file and write a string to it.
26  static bool WriteStringToFile(const std::string& contents, const std::string& filename) {
27  File::WriteStringToFileOrDie(contents, filename);
28  return true;
29  }
30 
31  static bool GetContents(const std::string& filename, std::string* out, int) {
32  return File::ReadFileToString(filename, out);
33  }
34 
35  static bool SetContents(const std::string& name, const std::string& contents, bool /*is_default*/) {
36  return WriteStringToFile(contents, name);
37  }
38 
39  static int Defaults() {
40  return 0;
41  }
42 
43  static std::string JoinPath(const std::string& s1, const std::string& s2) {
44  return tesseract::File::JoinPath(s1, s2);
45  }
46 
47  static std::string JoinPath(const std::string& s1, const std::string& s2,
48  const std::string& s3) {
49  return JoinPath(JoinPath(s1, s2), s3);
50  }
51 };
52 
53 #define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
54 
55 // /usr/include/tensorflow/core/platform/default/logging.h defines the CHECK* macros.
56 #if !defined(CHECK)
57 #define CHECK(test) ASSERT_HOST(test)
58 #define CHECK_EQ(test, value) CHECK((test) == (value))
59 #define CHECK_GT(test, value) CHECK((test) > (value))
60 #define CHECK_LT(test, value) CHECK((test) < (value))
61 #define CHECK_LE(test, value) CHECK((test) <= (value))
62 #define CHECK_OK(test) CHECK(test)
63 #endif
64 
65 #endif // TESSERACT_UNITTEST_INCLUDE_GUNIT_H_
file::JoinPath
static std::string JoinPath(const std::string &s1, const std::string &s2)
Definition: include_gunit.h:43
string
std::string string
Definition: equationdetect_test.cc:21
file::JoinPath
static std::string JoinPath(const std::string &s1, const std::string &s2, const std::string &s3)
Definition: include_gunit.h:47
file::Defaults
static int Defaults()
Definition: include_gunit.h:39
file::GetContents
static bool GetContents(const std::string &filename, std::string *out, int)
Definition: include_gunit.h:31
tesseract::File::JoinPath
static std::string JoinPath(const std::string &prefix, const std::string &suffix)
Definition: fileio.cpp:98
fileio.h
file::SetContents
static bool SetContents(const std::string &name, const std::string &contents, bool)
Definition: include_gunit.h:35
FLAGS_test_tmpdir
const char * FLAGS_test_tmpdir
Definition: include_gunit.h:20
file
Definition: include_gunit.h:22
errcode.h
tesseract::File
Definition: fileio.h:55
file::WriteStringToFile
static bool WriteStringToFile(const std::string &contents, const std::string &filename)
Definition: include_gunit.h:26