00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "test.h"
00023
00024
00025 #define fail_if(expr, msg) \
00026 if(expr) { \
00027 fprintf(stderr, "%s:%d Assertion '%s' met: %s\n", \
00028 __FILE__, __LINE__, #expr, msg); \
00029 unitfail++; \
00030 }
00031
00032 #define fail_unless(expr, msg) \
00033 if(!(expr)) { \
00034 fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
00035 __FILE__, __LINE__, #expr, msg); \
00036 unitfail++; \
00037 }
00038
00039 #define verify_memory(dynamic, check, len) \
00040 if(dynamic && memcmp(dynamic, check, len)) { \
00041 fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
00042 __FILE__, __LINE__, len, hexdump((unsigned char *)check, len)); \
00043 fprintf(stderr, "%s:%d the same as '%s'\n", \
00044 __FILE__, __LINE__, hexdump((unsigned char *)dynamic, len)); \
00045 unitfail++; \
00046 }
00047
00048
00049
00050 #define fail(msg) do { \
00051 fprintf(stderr, "%s:%d test failed: '%s'\n", \
00052 __FILE__, __LINE__, msg); \
00053 unitfail++; \
00054 } WHILE_FALSE
00055
00056
00057
00058 #define abort_if(expr, msg) \
00059 if(expr) { \
00060 fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n", \
00061 __FILE__, __LINE__, #expr, msg); \
00062 unitfail++; \
00063 goto unit_test_abort; \
00064 }
00065
00066 #define abort_unless(expr, msg) \
00067 if(!(expr)) { \
00068 fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
00069 __FILE__, __LINE__, #expr, msg); \
00070 unitfail++; \
00071 goto unit_test_abort; \
00072 }
00073
00074 #define abort_test(msg) do { \
00075 fprintf(stderr, "%s:%d test aborted: '%s'\n", \
00076 __FILE__, __LINE__, msg); \
00077 unitfail++; \
00078 goto unit_test_abort; \
00079 } WHILE_FALSE
00080
00081
00082
00083 extern int unitfail;
00084
00085 #define UNITTEST_START \
00086 int test(char *arg) \
00087 { \
00088 (void)arg; \
00089 if(unit_setup()) { \
00090 fail("unit_setup() failure"); \
00091 } \
00092 else {
00093
00094 #define UNITTEST_STOP \
00095 goto unit_test_abort; \
00096 unit_test_abort: \
00097 unit_stop(); \
00098 } \
00099 return unitfail; \
00100 }
00101