34 #ifndef GFLAGS_UTIL_H_ 35 #define GFLAGS_UTIL_H_ 41 #ifdef HAVE_INTTYPES_H 50 #ifdef HAVE_SYS_STAT_H 51 # include <sys/stat.h> 62 #if defined(strtoll) || defined(HAVE_STRTOLL) 63 # define strto64 strtoll 64 # define strtou64 strtoull 65 #elif defined(HAVE_STRTOQ) 66 # define strto64 strtoq 67 # define strtou64 strtouq 70 # define strto64 strtol 71 # define strtou64 strtoul 93 #define COMPILE_ASSERT(expr, msg) \ 94 enum { assert_##msg = sizeof(CompileAssert<bool(expr)>) } 97 #define arraysize(arr) (sizeof(arr)/sizeof(*(arr))) 104 #define LOG(level) std::cerr 105 #define VLOG(level) if (true) {} else std::cerr 106 #define DVLOG(level) if (true) {} else std::cerr 113 #define EXPECT_TRUE(condition) \ 115 if (!(condition)) { \ 116 fprintf(stderr, "Check failed: %s\n", #condition); \ 119 } else std::cerr << "" 121 #define EXPECT_OP(op, val1, val2) \ 123 if (!((val1) op (val2))) { \ 124 fprintf(stderr, "Check failed: %s %s %s\n", #val1, #op, #val2); \ 127 } else std::cerr << "" 129 #define EXPECT_EQ(val1, val2) EXPECT_OP(==, val1, val2) 130 #define EXPECT_NE(val1, val2) EXPECT_OP(!=, val1, val2) 131 #define EXPECT_LE(val1, val2) EXPECT_OP(<=, val1, val2) 132 #define EXPECT_LT(val1, val2) EXPECT_OP(< , val1, val2) 133 #define EXPECT_GE(val1, val2) EXPECT_OP(>=, val1, val2) 134 #define EXPECT_GT(val1, val2) EXPECT_OP(> , val1, val2) 135 #define EXPECT_FALSE(cond) EXPECT_TRUE(!(cond)) 141 #ifdef isnan // Some compilers, like sun's for Solaris 10, don't define this 142 #define EXPECT_NAN(arg) \ 145 fprintf(stderr, "Check failed: isnan(%s)\n", #arg); \ 150 #define EXPECT_NAN(arg) 153 #ifdef isinf // Some compilers, like sun's for Solaris 10, don't define this 154 #define EXPECT_INF(arg) \ 157 fprintf(stderr, "Check failed: isinf(%s)\n", #arg); \ 162 #define EXPECT_INF(arg) 165 #define EXPECT_DOUBLE_EQ(val1, val2) \ 167 if (((val1) < (val2) - 0.001 || (val1) > (val2) + 0.001)) { \ 168 fprintf(stderr, "Check failed: %s == %s\n", #val1, #val2); \ 173 #define EXPECT_STREQ(val1, val2) \ 175 if (strcmp((val1), (val2)) != 0) { \ 176 fprintf(stderr, "Check failed: streq(%s, %s)\n", #val1, #val2); \ 183 static std::vector<void (*)()> g_testlist; \ 184 static int RUN_ALL_TESTS() { \ 185 std::vector<void (*)()>::const_iterator it; \ 186 for (it = g_testlist.begin(); it != g_testlist.end(); ++it) { \ 189 fprintf(stderr, "\nPassed %d tests\n\nPASS\n", \ 190 static_cast<int>(g_testlist.size())); \ 196 struct Test_##a##_##b { \ 197 Test_##a##_##b() { g_testlist.push_back(&Run); } \ 198 static void Run() { \ 200 fprintf(stderr, "Running test %s/%s\n", #a, #b); \ 203 static void RunTest(); \ 205 static Test_##a##_##b g_test_##a##_##b; \ 206 void Test_##a##_##b::RunTest() 214 #define EXPECT_DEATH_INIT \ 215 static bool g_called_exit; \ 216 static void CalledExit(int) { g_called_exit = true; } 218 #define EXPECT_DEATH(fn, msg) \ 220 g_called_exit = false; \ 221 gflags_exitfunc = &CalledExit; \ 223 gflags_exitfunc = &exit; \ 224 if (!g_called_exit) { \ 225 fprintf(stderr, "Function didn't die (%s): %s\n", msg, #fn); \ 230 #define GTEST_HAS_DEATH_TEST 1 236 #if defined(__MINGW32__) 239 if (!path->empty()) {
240 path->append(
"/gflags_unittest_testdir");
241 int err = mkdir(path->c_str());
242 if (err == 0 || errno == EEXIST)
return;
245 *path =
"./gflags_unittest";
246 mkdir(path->c_str());
248 #elif defined(_MSC_VER) 251 if (!path->empty()) {
252 int err = _mkdir(path->c_str());
253 if (err == 0 || errno == EEXIST)
return;
255 char tmppath_buffer[1024];
256 int tmppath_len = GetTempPathA(
sizeof(tmppath_buffer), tmppath_buffer);
257 assert(tmppath_len > 0 && tmppath_len <
sizeof(tmppath_buffer));
258 assert(tmppath_buffer[tmppath_len - 1] ==
'\\');
259 *path =
std::string(tmppath_buffer) +
"gflags_unittest";
260 _mkdir(path->c_str());
264 if (!path->empty()) {
265 int err = mkdir(path->c_str(), 0755);
266 if (err == 0 || errno == EEXIST)
return;
268 mkdir(
"/tmp/gflags_unittest", 0755);
283 int bytes_written =
vsnprintf(space,
sizeof(space), format, backup_ap);
286 if ((bytes_written >= 0) && (static_cast<size_t>(bytes_written) <
sizeof(space))) {
287 output->append(space, bytes_written);
294 if (bytes_written < 0) {
299 length = bytes_written+1;
305 bytes_written =
vsnprintf(buf, length, format, backup_ap);
308 if ((bytes_written >= 0) && (bytes_written < length)) {
309 output->append(buf, bytes_written);
320 va_start(ap, format);
328 va_start(ap, format);
335 va_start(ap, format);
344 #if defined(_MSC_VER) && _MSC_VER >= 1400 347 if (_dupenv_s(&val, &sz, varname) != 0 || !val)
return false;
351 const char *
const val = getenv(varname);
352 if (!val)
return false;
360 #if defined(_MSC_VER) && _MSC_VER >= 1400 361 return fopen_s(fp, fname, mode);
364 *fp = fopen(fname, mode);
366 return ((*fp ==
NULL) ? errno : 0);
374 #endif // GFLAGS_UTIL_H_ std::string StringPrintf(const char *format,...)
Definition: util.h:333
Definition: testutils.h:40
void GFLAGS_DLL_DECL(* gflags_exitfunc)(int)
Definition: gflags.cc:138
GLint GLint GLint GLsizei GLsizei GLenum format
Definition: gl2.h:403
signed char int8
Definition: util.h:86
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: gl2ext.h:134
path
Definition: generate.py:74
GLenum mode
Definition: gl2.h:461
const UChar space
Definition: CharacterNames.h:87
#define va_copy(dst, src)
Definition: windows_port.h:72
void
Definition: AVFoundationCFSoftLinking.h:81
int
Definition: runtests.py:53
void MakeTmpdir(std::string *path)
Definition: util.h:263
#define true
Definition: float-mm.c:6
#define GFLAGS_DLL_DECL
Definition: gflags_declare.h:53
int SafeFOpen(FILE **fp, const char *fname, const char *mode)
Definition: util.h:358
GLsizei const GLchar *const * string
Definition: gl2.h:479
#define vsnprintf(str, size, format, ap)
Definition: windows_port.h:71
#define NULL
Definition: common_types.h:41
unsigned char uint8
Definition: util.h:87
bool SafeGetEnv(const char *varname, std::string &valstr)
Definition: util.h:342
void SStringPrintf(std::string *output, const char *format,...)
Definition: util.h:318
#define free
Definition: mbmalloc.h:50
GLuint GLsizei GLsizei GLfloat * val
Definition: gl2ext.h:3301
void InternalStringPrintf(std::string *output, const char *format, va_list ap)
Definition: util.h:274
GLuint GLsizei GLsizei * length
Definition: gl2.h:435
void StringAppendF(std::string *output, const char *format,...)
Definition: util.h:326