• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __TEST_H__
2 #define __TEST_H__
3 
4 static int test_passed = 0;
5 static int test_failed = 0;
6 
7 /* Terminate current test with error */
8 #define fail() return __LINE__
9 
10 /* Successful end of the test case */
11 #define done() return 0
12 
13 /* Check single condition */
14 #define check(cond)                                                            \
15   do {                                                                         \
16     if (!(cond))                                                               \
17       fail();                                                                  \
18   } while (0)
19 
20 /* Test runner */
test(int (* func)(void),const char * name)21 static void test(int (*func)(void), const char *name) {
22   int r = func();
23   if (r == 0) {
24     test_passed++;
25   } else {
26     test_failed++;
27     printf("FAILED: %s (at line %d)\n", name, r);
28   }
29 }
30 
31 #endif /* __TEST_H__ */
32