6 #define TEST(suite, test) \ 7 void _TEST_##suite##_##test(); \ 8 ACCUMULATE int TEST_RunAll_accumulated(int f) { \ 9 if (!TEST_Run(#suite "_" #test)) ++f; \ 12 void _TEST_##suite##_##test() 15 #define SUCCEED() (TEST_ok = true) 18 #define ADD_FAILURE(msg) MACRO_BEGIN \ 24 #define FAIL(msg) _TEST_ASSERT(ADD_FAILURE(msg)) 26 #define HasFatalFailure() (TEST_fatal > 0) 32 #define EXPECT_EQ(expected_, actual_) MACRO_BEGIN \ 33 int expected = expected_; \ 34 int actual = actual_; \ 35 if ((expected) != (actual)) { \ 36 ADD_FAILURE(sprintf( \ 37 "Value of: " #actual_ "\n" \ 44 #define ASSERT_EQ(expected, actual) _TEST_ASSERT(EXPECT_EQ(expected, actual)) 46 #define EXPECT_TRUE(condition) EXPECT_EQ(true, condition) 47 #define ASSERT_TRUE(condition) ASSERT_EQ(true, condition) 49 #define EXPECT_FALSE(condition) EXPECT_EQ(false, condition) 50 #define ASSERT_FALSE(condition) ASSERT_EQ(false, condition) 52 #define EXPECT_NE(val1, val2) EXPECT_TRUE((val1) != (val2)) 53 #define ASSERT_NE(val1, val2) _TEST_ASSERT(EXPECT_NE(val1, val2)) 55 #define EXPECT_LT(val1, val2) EXPECT_TRUE((val1) < (val2)) 56 #define ASSERT_LT(val1, val2) _TEST_ASSERT(EXPECT_LT(val1, val2)) 58 #define EXPECT_LE(val1, val2) EXPECT_TRUE((val1) <= (val2)) 59 #define ASSERT_LE(val1, val2) _TEST_ASSERT(EXPECT_LE(val1, val2)) 61 #define EXPECT_GT(val1, val2) EXPECT_TRUE((val1) > (val2)) 62 #define ASSERT_GT(val1, val2) _TEST_ASSERT(EXPECT_GT(val1, val2)) 64 #define EXPECT_GE(val1, val2) EXPECT_TRUE((val1) >= (val2)) 65 #define ASSERT_GE(val1, val2) _TEST_ASSERT(EXPECT_GE(val1, val2)) 67 #define EXPECT_NO_FATAL_FAILURE(statement) EXPECT_NO_FATAL_FAILURE_(statement, { }) 68 #define ASSERT_NO_FATAL_FAILURE(statement) EXPECT_NO_FATAL_FAILURE_(statement, { ++TEST_fatal; return; }) 77 #define _TEST_ASSERT(statement) \ 80 ++TEST_fatal; return; \ 83 #define EXPECT_NO_FATAL_FAILURE__(statement, then) \ 85 int TEST_prevfatal = TEST_fatal; \ 87 if (TEST_fatal != TEST_prevfatal) \ 91 #define EXPECT_NO_FATAL_FAILURE_(statement, then) \ 92 EXPECT_NO_FATAL_FAILURE__(statement, { \ 94 " Actual: %d fatal failures\n" \ 95 "Expected: no fatal failures\n", \ 96 TEST_fatal - TEST_prevfatal \ bool TEST_Run(string test)