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