raw: Add skeleton test suite for swift raw.
[swifty.git] / src / raw / test / test.h
1 /*
2  * generic test suite
3  *
4  * test macros and headers
5  */
6
7 #ifndef TEST_H_
8 #define TEST_H_         1
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 #include <stdio.h>
15 #include <string.h>
16
17 /*
18  * uncommend EXIT_IF_FAIL macro in order to stop test execution
19  * at first failed test
20  */
21
22 /*#define EXIT_IF_FAIL  1*/
23
24 #if defined (EXIT_IF_FAIL)
25 #define test_do_fail()                  \
26         do {                            \
27                 printf("failed\n");     \
28                 exit(EXIT_FAILURE);     \
29         } while (0)
30 #else
31 #define test_do_fail()                  \
32         printf("failed\n")
33 #endif
34
35 #define test_do_pass()                  \
36         printf("passed\n")
37
38 #define test(test)                                              \
39         do {                                                    \
40                 size_t i;                                       \
41                 int t = (test);                                 \
42                                                                 \
43                 printf("%s", __FUNCTION__);                     \
44                 fflush(stdout);                                 \
45                                                                 \
46                 for (i = 0; i < 60 - strlen(__FUNCTION__); i++) \
47                         putchar('.');                           \
48                                                                 \
49                 if (!t)                                         \
50                         test_do_fail();                         \
51                 else                                            \
52                         test_do_pass();                         \
53                                                                 \
54                 fflush(stdout);                                 \
55         } while (0)
56
57 #ifdef __cplusplus
58 }
59 #endif
60
61 #endif