aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--simple-test.h34
1 files changed, 23 insertions, 11 deletions
diff --git a/simple-test.h b/simple-test.h
index b5e4678..e7220ca 100644
--- a/simple-test.h
+++ b/simple-test.h
@@ -56,11 +56,11 @@ _test_cleanup_current=_TEST_PASTE(_test_cleanup_, unique_count);
/* pretty printing for the current state within
* a test */
#define STATE(...) \
- do { \
- printf("\e[1m :: \e[m\e[34m"); \
- printf(...); \
- printf("...\e[m\n"); \
- } while(0)
+do { \
+ printf("\e[1m :: \e[m\e[34m"); \
+ printf(__VA_ARGS__); \
+ printf("...\e[m\n"); \
+} while(0)
/* one of these goes at the end of every test
* with CLEANUP (unless you want memory leaks).
@@ -83,6 +83,18 @@ do { \
* TESTS *
***********/
+#define EXPECT_NULL(summary, arg) \
+do { \
+ if((arg) != NULL) \
+ _TEST_FAIL_VAL(summary, "%s", "%p", "NULL", (void*)(arg)); \
+} while(0);
+
+#define EXPECT_NON_NULL(summary, arg) \
+do { \
+ if((arg) == NULL) \
+ _TEST_FAIL_VAL(summary, "%s", "%p", "non NULL", (void*)(arg)); \
+} while(0);
+
#define EXPECT_ZERO(summary, arg) \
do { \
if(arg) \
@@ -91,31 +103,31 @@ do { \
#define EXPECT_ONE(summary, arg) \
do { \
- if(arg != 1) \
+ if((arg) != 1) \
_TEST_FAIL_VAL(summary, "%i", "%i", 1, arg); \
} while(0);
#define EXPECT_GREATER_THAN_ZERO(summary, arg) \
do { \
- if(arg <= 0) \
+ if((arg) <= 0) \
_TEST_FAIL_VAL(summary, "%s", "%i", ">0", arg); \
} while(0);
#define EXPECT_INT(summary, arg1, arg2) \
do { \
- if(arg1 != arg2) \
+ if((arg1) != (arg2)) \
_TEST_FAIL_VAL(summary, "%i", "%i", arg1, arg2); \
} while(0);
#define EXPECT_EQUAL_INT(summary, arg1, arg2) \
do { \
- if(arg1 != arg2) \
+ if((arg1) != (arg2)) \
_TEST_FAIL_EQUAL(summary, "%i", "%i", arg1, arg2); \
} while(0);
#define EXPECT_UNEQUAL_INT(summary, arg1, arg2) \
do { \
- if(arg1 == arg2) \
+ if((arg1) == (arg2)) \
_TEST_FAIL_EQUAL(summary, "%i", "%i", arg1, arg2); \
} while(0);
@@ -141,7 +153,7 @@ do { \
do { \
printf("\e[1m :: \e[m\e[31mFAIL: " summary "\e[m\n"); \
printf("\e[1m :: \e[m\e[1;32m expected:\e[m " format1 "\n", expected);\
- printf("\e[1m :: \e[m\e[1;31m actual:\e[m " format1 "\n", actual); \
+ printf("\e[1m :: \e[m\e[1;31m actual:\e[m " format2 "\n", actual); \
_TEST_RETURN(true); \
} while(0)