Print more informative assert message
[projects/chimara/chimara.git] / tests / unit / glkunit.h
1 #ifndef GLKUNIT_H
2 #define GLKUNIT_H
3
4 #include <stdio.h>
5
6 #define _BEGIN do {
7 #define _END } while(0);
8
9 /* msg must be a string literal */
10 #define _ASSERT(expr, msg, ...) _BEGIN \
11     if( !(expr) ) { \
12         fprintf(stderr, "Assertion failed: " msg "\n", __VA_ARGS__); \
13         return 0; \
14     } _END
15
16 #define SUCCEED _BEGIN return 1; _END
17 #define ASSERT(expr) _ASSERT(expr, "%s", #expr)
18 /* This macro is meant for int-like things that can print with %d */
19 #define ASSERT_EQUAL(expected, actual) _ASSERT((expected) == (actual), \
20     "%s == %s (expected %d, was %d)", \
21     #actual, #expected, expected, actual);
22
23 struct TestDescription {
24     char *name;
25     int (*testfunc)(void);
26 };
27
28 #endif /* GLKUNIT_H */