release 0.1.13
[liba.git] / test / test.h
blobce3cbce31e26fd65e0f3c3907d4d24a23ce65945
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 <stdlib.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 defined(__cplusplus) && (__cplusplus > 201100L)
16 #include <type_traits>
17 #endif /* __cplusplus */
18 #if A_PREREQ_GNUC(2, 95) || __has_warning("-Winline")
19 #pragma GCC diagnostic ignored "-Winline"
20 #endif /* -Winline */
21 #if A_PREREQ_GNUC(2, 95) || __has_warning("-Wpadded")
22 #pragma GCC diagnostic ignored "-Wpadded"
23 #endif /* -Wpadded */
24 #if A_PREREQ_GNUC(4, 6) || __has_warning("-Wdouble-promotion")
25 #if defined(A_FLOAT_TYPE) && (A_FLOAT_TYPE + 0 == A_FLOAT_SINGLE)
26 #pragma GCC diagnostic ignored "-Wdouble-promotion"
27 #endif /* A_FLOAT_TYPE + 0 == 0x04 */
28 #endif /* -Wdouble-promotion */
29 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
30 defined(__cplusplus) && (__cplusplus > 201100L) || A_PREREQ_MSVC(19, 0)
31 #define PRIj "j"
32 #define SCNj "j"
33 #define PRIz "z"
34 #define SCNz "z"
35 #define PRIt "t"
36 #define SCNt "t"
37 #elif defined(_MSC_VER)
38 #define PRIj "I64"
39 #define SCNj "I64"
40 #define PRIz "I"
41 #define SCNz "I"
42 #define PRIt "I"
43 #define SCNt "I"
44 #else /* C < 199900 and C++ < 201100 */
45 #if LONG_MAX == INT32_MAX
46 #define PRIj "ll"
47 #define SCNj "ll"
48 #else
49 #define PRIj "l"
50 #define SCNj "l"
51 #endif
52 #define PRIz "l"
53 #define SCNz "l"
54 #define PRIt "l"
55 #define SCNt "l"
56 #endif /* C > 199900 or C++ > 201100 */
58 #if A_FLOAT_TYPE + 0 == A_FLOAT_SINGLE
59 #define strtonum(string, endptr) strtof(string, endptr)
60 #elif A_FLOAT_TYPE + 0 == A_FLOAT_DOUBLE
61 #define strtonum(string, endptr) strtod(string, endptr)
62 #elif A_FLOAT_TYPE + 0 == A_FLOAT_EXTEND
63 #define strtonum(string, endptr) strtold(string, endptr)
64 #endif /* A_FLOAT_TYPE */
66 #define TEST_IS1(expression, message) \
67 do { \
68 if (!(expression)) \
69 { \
70 (void)fprintf(stderr, "%s:%i:%s\n", __FILE__, __LINE__, message); \
71 } \
72 } while (0)
74 #define TEST_IS0(expression, message) \
75 do { \
76 if (expression) \
77 { \
78 (void)fprintf(stderr, "%s:%i:%s\n", __FILE__, __LINE__, message); \
79 } \
80 } while (0)
82 #define TEST_BUG(expression) TEST_IS1(expression, #expression)
84 #if defined(MAIN)
85 #if defined(__cplusplus)
86 extern "C" {
87 #endif /* __cplusplus */
88 int MAIN(_c)(int argc, char *argv[]);
89 int MAIN(_x)(int argc, char *argv[]);
90 int main_init(int argc, char *argv[], int arg1);
91 int debug(char const *fmt, ...) A_FORMAT(printf, 1, 2);
92 #if defined(__cplusplus)
93 } /* extern "C" */
94 #endif /* __cplusplus */
95 #if !defined __cplusplus
96 static void main_exit(void);
97 int main_init(int argc, char *argv[], int arg1)
99 static FILE *out = A_NULL;
100 if (!out && argc > arg1)
102 out = freopen(argv[arg1], "wb", stdout);
103 if (out) { arg1 = atexit(main_exit); }
105 return arg1;
107 int main(int argc, char *argv[])
109 int status = 0;
110 #if defined(HAS_CXX)
111 status += MAIN(_x)(argc, argv);
112 #endif /* HAS_CXX */
113 status += MAIN(_c)(argc, argv);
114 return status;
116 int debug(char const *fmt, ...)
118 return (void)fmt, 0;
120 static void main_exit(void)
122 if (fclose(stdout)) {}
124 #define main MAIN(_c)
125 #else /* !__cplusplus */
126 #define main MAIN(_x)
127 #endif /* __cplusplus */
128 #if defined(HAS_CXX) == \
129 defined(__cplusplus)
130 #define debug printf
131 #endif /* __cplusplus */
132 #endif /* MAIN */
134 #endif /* test/test.h */