Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test.h
Go to the documentation of this file.
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) do { if (!(cond)) fail(); } while (0)
15 
16 /* Test runner */
17 static void test(int (*func)(void), const char *name) {
18  int r = func();
19  if (r == 0) {
20  test_passed++;
21  } else {
22  test_failed++;
23  printf("FAILED: %s (at line %d)\n", name, r);
24  }
25 }
26 
27 #endif /* __TEST_H__ */