#ifndef TESTING_H #define TESTING_H #include #include #define TESTING_BEGIN() fail_count = 0 #define TESTING_END() return 0 == fail_count ? EXIT_SUCCESS : EXIT_FAILURE #define RUN_TEST(test) test() #define ASSERT_FAIL() \ do { \ ++fail_count; \ testing_fail_msg(__func__, __FILE__, __LINE__); \ return; \ } while (0) #define ASSERT_TRUE(p) \ do { \ if (!(p)) \ ASSERT_FAIL(); \ } while (0) #define ASSERT_FALSE(p) ASSERT_TRUE(!(p)) #define ASSERT_EQUAL(x, y) ASSERT_TRUE((x) == (y)) #define ASSERT_NOT_EQUAL(x, y) ASSERT_TRUE((x) != (y)) #define ASSERT_NULL(p) ASSERT_TRUE(NULL == (p)) #define ASSERT_NOT_NULL(p) ASSERT_TRUE(NULL != (p)) #define ASSERT_GT(x, y) ASSERT_TRUE((y) > (x)) #define ASSERT_GE(x, y) ASSERT_TRUE((y) >= (x)) #define ASSERT_LT(x, y) ASSERT_TRUE((y) < (x)) #define ASSERT_LE(x, y) ASSERT_TRUE((y) <= (x)) #define ASSERT_MEM_EQUAL(p, q, n) ASSERT_TRUE(memcmp(p, q, n) == 0) extern int fail_count; void testing_fail_msg(const char *func, const char *file, int line); #endif