13 #ifndef __STOUT_GTEST_HPP__ 14 #define __STOUT_GTEST_HPP__ 18 #include <gtest/gtest.h> 25 #include <sys/types.h> 39 return ::testing::AssertionFailure()
40 << expr <<
" is NONE";
43 return ::testing::AssertionSuccess();
47 template <
typename T,
typename E>
53 return ::testing::AssertionFailure()
54 << expr <<
": " << actual.
error();
57 return ::testing::AssertionSuccess();
67 return ::testing::AssertionFailure()
68 << expr <<
" is NONE";
70 return ::testing::AssertionFailure()
71 << expr <<
": " << actual.
error();
74 return ::testing::AssertionSuccess();
78 template <
typename T1,
typename T2>
80 const char* expectedExpr,
81 const char* actualExpr,
85 const ::testing::AssertionResult result =
AssertSome(actualExpr, actual);
88 if (expected == actual.get()) {
89 return ::testing::AssertionSuccess();
91 return ::testing::AssertionFailure()
92 <<
"Value of: (" << actualExpr <<
").get()\n" 93 <<
" Actual: " << ::testing::PrintToString(actual.get()) <<
"\n" 94 <<
"Expected: " << expectedExpr <<
"\n" 95 <<
"Which is: " << ::testing::PrintToString(expected);
103 template <
typename T1,
typename T2>
105 const char* notExpectedExpr,
106 const char* actualExpr,
107 const T1& notExpected,
110 const ::testing::AssertionResult result =
AssertSome(actualExpr, actual);
113 if (notExpected == actual.get()) {
114 return ::testing::AssertionFailure()
115 <<
" Value of: (" << actualExpr <<
").get()\n" 116 <<
" Actual: " << ::testing::PrintToString(actual.get()) <<
"\n" 117 <<
"Not expected: " << notExpectedExpr <<
"\n" 118 <<
" Which is: " << ::testing::PrintToString(notExpected);
120 return ::testing::AssertionSuccess();
128 #define ASSERT_SOME(actual) \ 129 ASSERT_PRED_FORMAT1(AssertSome, actual) 132 #define EXPECT_SOME(actual) \ 133 EXPECT_PRED_FORMAT1(AssertSome, actual) 136 #define ASSERT_SOME_EQ(expected, actual) \ 137 ASSERT_PRED_FORMAT2(AssertSomeEq, expected, actual) 140 #define EXPECT_SOME_EQ(expected, actual) \ 141 EXPECT_PRED_FORMAT2(AssertSomeEq, expected, actual) 144 #define ASSERT_SOME_NE(notExpected, actual) \ 145 ASSERT_PRED_FORMAT2(AssertSomeNe, notExpected, actual) 148 #define EXPECT_SOME_NE(notExpected, actual) \ 149 EXPECT_PRED_FORMAT2(AssertSomeNe, notExpected, actual) 152 #define ASSERT_SOME_TRUE(actual) \ 153 ASSERT_PRED_FORMAT2(AssertSomeEq, true, actual) 156 #define EXPECT_SOME_TRUE(actual) \ 157 EXPECT_PRED_FORMAT2(AssertSomeEq, true, actual) 160 #define ASSERT_SOME_FALSE(actual) \ 161 ASSERT_PRED_FORMAT2(AssertSomeEq, false, actual) 164 #define EXPECT_SOME_FALSE(actual) \ 165 EXPECT_PRED_FORMAT2(AssertSomeEq, false, actual) 168 #define ASSERT_ERROR(actual) \ 169 ASSERT_TRUE(actual.isError()) 172 #define EXPECT_ERROR(actual) \ 173 EXPECT_TRUE(actual.isError()) 176 #define ASSERT_NONE(actual) \ 177 ASSERT_TRUE(actual.isNone()) 180 #define EXPECT_NONE(actual) \ 181 EXPECT_TRUE(actual.isNone()) 188 #define TEST_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \ 189 TEST(test_case_name, test_name) 191 #define TEST_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \ 192 TEST(test_case_name, DISABLED_##test_name) 193 #endif // __WINDOWS__ 200 #define TEST_F_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \ 201 TEST_F(test_case_name, test_name) 203 #define TEST_F_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \ 204 TEST_F(test_case_name, DISABLED_##test_name) 205 #endif // __WINDOWS__ 212 #define TEST_P_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \ 213 TEST_P(test_case_name, test_name) 215 #define TEST_P_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \ 216 TEST_P(test_case_name, DISABLED_##test_name) 217 #endif // __WINDOWS__ 224 #define TYPED_TEST_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \ 225 TYPED_TEST(test_case_name, test_name) 227 #define TYPED_TEST_TEMP_DISABLED_ON_WINDOWS(test_case_name, test_name) \ 228 TYPED_TEST(test_case_name, DISABLED_##test_name) 229 #endif // __WINDOWS__ 243 #define SLEEP_COMMAND(x) "sleep " #x 245 #define SLEEP_COMMAND(x) \ 246 ((x) > 0 ? "ping 127.0.0.1 -n " #x " > NUL" : "cmd /C exit 0") 247 #endif // __WINDOWS__ 251 const char* actualExpr,
255 return ::testing::AssertionSuccess();
258 return ::testing::AssertionFailure()
259 <<
"Expecting WIFEXITED(" << actualExpr <<
") but " 260 <<
" WIFSIGNALED(" << actualExpr <<
") is true and " 261 <<
"WTERMSIG(" << actualExpr <<
") is " <<
strsignal(WTERMSIG(actual));
262 }
else if (WIFSTOPPED(actual)) {
263 return ::testing::AssertionFailure()
264 <<
"Expecting WIFEXITED(" << actualExpr <<
") but" 265 <<
" WIFSTOPPED(" << actualExpr <<
") is true and " 266 <<
"WSTOPSIG(" << actualExpr <<
") is " <<
strsignal(WSTOPSIG(actual));
267 #endif // __WINDOWS__ 270 return ::testing::AssertionFailure()
271 <<
"Expecting WIFEXITED(" << actualExpr <<
") but got" 272 <<
" unknown value: " << ::testing::PrintToString(actual);
276 #define ASSERT_EXITED(expected, actual) \ 277 ASSERT_PRED_FORMAT2(AssertExited, expected, actual) 280 #define EXPECT_EXITED(expected, actual) \ 281 EXPECT_PRED_FORMAT2(AssertExited, expected, actual) 285 const char* expectedExpr,
286 const char* actualExpr,
290 const ::testing::AssertionResult result =
AssertExited(actualExpr, actual);
294 return ::testing::AssertionSuccess();
296 return ::testing::AssertionFailure()
297 <<
"Value of: WEXITSTATUS(" << actualExpr <<
")\n" 298 <<
" Actual: " << ::testing::PrintToString(
WEXITSTATUS(actual)) <<
"\n" 299 <<
"Expected: " << expectedExpr <<
"\n" 300 <<
"Which is: " << ::testing::PrintToString(expected);
308 #define ASSERT_WEXITSTATUS_EQ(expected, actual) \ 309 ASSERT_PRED_FORMAT2(AssertExitStatusEq, expected, actual) 312 #define EXPECT_WEXITSTATUS_EQ(expected, actual) \ 313 EXPECT_PRED_FORMAT2(AssertExitStatusEq, expected, actual) 318 const char* expectedExpr,
319 const char* actualExpr,
323 const ::testing::AssertionResult result =
AssertExited(actualExpr, actual);
327 return ::testing::AssertionSuccess();
329 return ::testing::AssertionFailure()
330 <<
"Value of: WEXITSTATUS(" << actualExpr <<
")\n" 331 <<
" Actual: " << ::testing::PrintToString(
WEXITSTATUS(actual)) <<
"\n" 332 <<
"Expected: " << expectedExpr <<
"\n" 333 <<
"Which is: " << ::testing::PrintToString(expected);
341 #define ASSERT_WEXITSTATUS_NE(expected, actual) \ 342 ASSERT_PRED_FORMAT2(AssertExitStatusNe, expected, actual) 345 #define EXPECT_WEXITSTATUS_NE(expected, actual) \ 346 EXPECT_PRED_FORMAT2(AssertExitStatusNe, expected, actual) 352 const char* actualExpr,
356 return ::testing::AssertionFailure()
357 <<
"Expecting WIFSIGNALED(" << actualExpr <<
") but " 358 <<
" WIFEXITED(" << actualExpr <<
") is true and " 359 <<
"WEXITSTATUS(" << actualExpr <<
") is " <<
WEXITSTATUS(actual);
361 return ::testing::AssertionSuccess();
362 }
else if (WIFSTOPPED(actual)) {
363 return ::testing::AssertionFailure()
364 <<
"Expecting WIFSIGNALED(" << actualExpr <<
") but" 365 <<
" WIFSTOPPED(" << actualExpr <<
") is true and " 366 <<
"WSTOPSIG(" << actualExpr <<
") is " <<
strsignal(WSTOPSIG(actual));
369 return ::testing::AssertionFailure()
370 <<
"Expecting WIFSIGNALED(" << actualExpr <<
") but got" 371 <<
" unknown value: " << ::testing::PrintToString(actual);
375 #define ASSERT_SIGNALED(expected, actual) \ 376 ASSERT_PRED_FORMAT2(AssertSignaled, expected, actual) 379 #define EXPECT_SIGNALED(expected, actual) \ 380 EXPECT_PRED_FORMAT2(AssertSignaled, expected, actual) 384 const char* expectedExpr,
385 const char* actualExpr,
389 const ::testing::AssertionResult result =
AssertSignaled(actualExpr, actual);
392 if (WTERMSIG(actual) == expected) {
393 return ::testing::AssertionSuccess();
395 return ::testing::AssertionFailure()
396 <<
"Value of: WTERMSIG(" << actualExpr <<
")\n" 397 <<
" Actual: " <<
strsignal(WTERMSIG(actual)) <<
"\n" 398 <<
"Expected: " << expectedExpr <<
"\n" 407 #define ASSERT_WTERMSIG_EQ(expected, actual) \ 408 ASSERT_PRED_FORMAT2(AssertTermSigEq, expected, actual) 411 #define EXPECT_WTERMSIG_EQ(expected, actual) \ 412 EXPECT_PRED_FORMAT2(AssertTermSigEq, expected, actual) 416 const char* expectedExpr,
417 const char* actualExpr,
421 const ::testing::AssertionResult result =
AssertSignaled(actualExpr, actual);
424 if (WTERMSIG(actual) != expected) {
425 return ::testing::AssertionSuccess();
427 return ::testing::AssertionFailure()
428 <<
"Value of: WTERMSIG(" << actualExpr <<
")\n" 429 <<
" Actual: " <<
strsignal(WTERMSIG(actual)) <<
"\n" 430 <<
"Expected: " << expectedExpr <<
"\n" 439 #define ASSERT_WTERMSIG_NE(expected, actual) \ 440 ASSERT_PRED_FORMAT2(AssertTermSigNe, expected, actual) 443 #define EXPECT_WTERMSIG_NE(expected, actual) \ 444 EXPECT_PRED_FORMAT2(AssertTermSigNe, expected, actual) 445 #endif // __WINDOWS__ 447 #endif // __STOUT_GTEST_HPP__ inline::testing::AssertionResult AssertExitStatusNe(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:317
bool isNone() const
Definition: result.hpp:113
Definition: option.hpp:29
::testing::AssertionResult AssertSomeEq(const char *expectedExpr, const char *actualExpr, const T1 &expected, const T2 &actual)
Definition: gtest.hpp:79
static Result< T > error(const std::string &message)
Definition: result.hpp:54
const char * strsignal(int signum)
Definition: windows.hpp:347
::testing::AssertionResult AssertSome(const char *expr, const Option< T > &actual)
Definition: gtest.hpp:34
inline::testing::AssertionResult AssertExitStatusEq(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:284
#define WIFSIGNALED(x)
Definition: windows.hpp:376
#define WEXITSTATUS(x)
Definition: windows.hpp:368
inline::testing::AssertionResult AssertTermSigNe(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:415
static Try error(const E &e)
Definition: try.hpp:43
#define WIFEXITED(x)
Definition: windows.hpp:362
bool isError() const
Definition: try.hpp:78
inline::testing::AssertionResult AssertTermSigEq(const char *expectedExpr, const char *actualExpr, const int expected, const int actual)
Definition: gtest.hpp:383
inline::testing::AssertionResult AssertSignaled(const char *actualExpr, const int actual)
Definition: gtest.hpp:351
bool isNone() const
Definition: option.hpp:117
bool isError() const
Definition: result.hpp:114
inline::testing::AssertionResult AssertExited(const char *actualExpr, const int actual)
Definition: gtest.hpp:250
::testing::AssertionResult AssertSomeNe(const char *notExpectedExpr, const char *actualExpr, const T1 ¬Expected, const T2 &actual)
Definition: gtest.hpp:104