Create userdata without user values in Lua 5.4
[liba.git] / test / test.h
blob7cfb0778ac9121017193c6d800ebc721bcf3deea
1 #ifndef TEST_TEST_H
2 #define TEST_TEST_H
4 #if defined(_MSC_VER)
5 #define _CRT_SECURE_NO_WARNINGS
6 #endif /* _MSC_VER */
7 #include "a/a.h"
8 #include <stdio.h>
9 #include <assert.h>
10 #include <inttypes.h>
11 #if defined(_MSC_VER)
12 #pragma warning(disable : 4127)
13 #pragma warning(disable : 4820)
14 #endif /* _MSC_VER */
15 #if A_PREREQ_GNUC(2, 95) || __has_warning("-Winline")
16 #pragma GCC diagnostic ignored "-Winline"
17 #endif /* -Winline */
18 #if A_PREREQ_GNUC(2, 95) || __has_warning("-Wpadded")
19 #pragma GCC diagnostic ignored "-Wpadded"
20 #endif /* -Wpadded */
21 #if A_PREREQ_GNUC(4, 6) || __has_warning("-Wdouble-promotion")
22 #if defined(A_FLOAT_TYPE) && (A_FLOAT_TYPE + 0 == A_FLOAT_SINGLE)
23 #pragma GCC diagnostic ignored "-Wdouble-promotion"
24 #endif /* A_FLOAT_TYPE + 0 == 0x04 */
25 #endif /* -Wdouble-promotion */
26 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
27 defined(__cplusplus) && (__cplusplus > 201100L) || defined(_MSC_VER)
29 #define PRIjd "jd"
30 #define PRIji "ji"
31 #define PRIjo "jo"
32 #define PRIju "ju"
33 #define PRIjx "jx"
34 #define PRIjX "jX"
36 #define SCNjd "jd"
37 #define SCNji "ji"
38 #define SCNjo "jo"
39 #define SCNju "ju"
40 #define SCNjx "jx"
41 #define SCNjX "jX"
43 #define PRIzd "zd"
44 #define PRIzi "zi"
45 #define PRIzo "zo"
46 #define PRIzu "zu"
47 #define PRIzx "zx"
48 #define PRIzX "zX"
50 #define SCNzd "zd"
51 #define SCNzi "zi"
52 #define SCNzo "zo"
53 #define SCNzu "zu"
54 #define SCNzx "zx"
55 #define SCNzX "zX"
57 #define PRItd "td"
58 #define PRIti "ti"
59 #define PRIto "to"
60 #define PRItu "tu"
61 #define PRItx "tx"
62 #define PRItX "tX"
64 #define SCNtd "td"
65 #define SCNti "ti"
66 #define SCNto "to"
67 #define SCNtu "tu"
68 #define SCNtx "tx"
69 #define SCNtX "tX"
71 #else /* C < 199900 and C++ < 201100 */
73 #define PRIjd PRIdMAX
74 #define PRIji PRIiMAX
75 #define PRIjo PRIoMAX
76 #define PRIju PRIuMAX
77 #define PRIjx PRIxMAX
78 #define PRIjX PRIXMAX
80 #define SCNjd PRIdMAX
81 #define SCNji PRIiMAX
82 #define SCNjo PRIoMAX
83 #define SCNju PRIuMAX
84 #define SCNjx PRIxMAX
85 #define SCNjX PRIXMAX
87 #define PRIzd PRIdPTR
88 #define PRIzi PRIiPTR
89 #define PRIzo PRIoPTR
90 #define PRIzu PRIuPTR
91 #define PRIzx PRIxPTR
92 #define PRIzX PRIXPTR
94 #define SCNzd PRIdPTR
95 #define SCNzi PRIiPTR
96 #define SCNzo PRIoPTR
97 #define SCNzu PRIuPTR
98 #define SCNzx PRIxPTR
99 #define SCNzX PRIXPTR
101 #define PRItd PRIdPTR
102 #define PRIti PRIiPTR
103 #define PRIto PRIoPTR
104 #define PRItu PRIuPTR
105 #define PRItx PRIxPTR
106 #define PRItX PRIXPTR
108 #define SCNtd PRIdPTR
109 #define SCNti PRIiPTR
110 #define SCNto PRIoPTR
111 #define SCNtu PRIuPTR
112 #define SCNtx PRIxPTR
113 #define SCNtX PRIXPTR
115 #endif /* C > 199900 or C++ > 201100 */
117 #define TEST_IS_TRUE(expression, message) \
118 do { \
119 if (!(expression)) \
121 (void)fprintf(stderr, "%s: file %s, line %i\n", \
122 message, __FILE__, __LINE__); \
124 } while (0)
126 #define TEST_IS_FASLE(expression, message) \
127 do { \
128 if (expression) \
130 (void)fprintf(stderr, "%s: file %s, line %i\n", \
131 message, __FILE__, __LINE__); \
133 } while (0)
135 #define TEST_BUG(expression) TEST_IS_TRUE(expression, "bug")
137 #if defined(MAIN_)
138 #if defined(__cplusplus)
139 extern "C" {
140 #endif /* __cplusplus */
141 int MAIN_(c)(int argc, char *argv[]);
142 int MAIN_(cpp)(int argc, char *argv[]);
143 int test_init(int argc, char *argv[], int out);
144 int debug(char const *fmt, ...) A_FORMAT(printf, 1, 2);
145 #if defined(__cplusplus)
146 } /* extern "C" */
147 #define MAIN(argc, argv) MAIN_(cpp)(argc, argv)
148 #else /* !__cplusplus */
149 #define MAIN(argc, argv) MAIN_(c)(argc, argv)
150 #endif /* __cplusplus */
151 #if !defined __cplusplus
152 static void test_exit(void);
153 int debug(char const *fmt, ...)
155 return (void)fmt, 0;
157 int test_init(int argc, char *argv[], int out)
159 static FILE *log = A_NULL;
160 if (!log && argc > out)
162 log = freopen(argv[out], "wb", stdout);
163 if (log) { out = atexit(test_exit); }
165 return out;
167 int main(int argc, char *argv[])
169 #if defined(HAS_CXX)
170 return MAIN_(cpp)(argc, argv) + MAIN_(c)(argc, argv);
171 #else /* !HAS_CXX */
172 return MAIN_(c)(argc, argv);
173 #endif /* HAS_CXX */
175 static void test_exit(void)
177 if (fclose(stdout)) {}
179 #endif /* __cplusplus */
180 #if defined(__cplusplus) == defined(HAS_CXX)
181 #define debug printf
182 #endif /* __cplusplus */
183 #endif /* MAIN_ */
185 #endif /* test/test.h */