specify the mode of the array as C
[liba.git] / test / test.h
blob28b9e58e53d5d3d5a71461a30c776a7775cfb366
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 <assert.h>
11 #include <inttypes.h>
12 #if defined(_MSC_VER)
13 #pragma warning(disable : 4127)
14 #pragma warning(disable : 4820)
15 #endif /* _MSC_VER */
16 #if defined(__cplusplus) && (__cplusplus > 201100L)
17 #include <type_traits>
18 #endif /* __cplusplus */
19 #if A_PREREQ_GNUC(2, 95) || __has_warning("-Winline")
20 #pragma GCC diagnostic ignored "-Winline"
21 #endif /* -Winline */
22 #if A_PREREQ_GNUC(2, 95) || __has_warning("-Wpadded")
23 #pragma GCC diagnostic ignored "-Wpadded"
24 #endif /* -Wpadded */
25 #if A_PREREQ_GNUC(4, 6) || __has_warning("-Wdouble-promotion")
26 #if defined(A_FLOAT_TYPE) && (A_FLOAT_TYPE + 0 == A_FLOAT_SINGLE)
27 #pragma GCC diagnostic ignored "-Wdouble-promotion"
28 #endif /* A_FLOAT_TYPE + 0 == 0x04 */
29 #endif /* -Wdouble-promotion */
30 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
31 defined(__cplusplus) && (__cplusplus > 201100L) || A_PREREQ_MSVC(19, 0)
32 #define PRIj "j"
33 #define SCNj "j"
34 #define PRIz "z"
35 #define SCNz "z"
36 #define PRIt "t"
37 #define SCNt "t"
38 #elif defined(_MSC_VER)
39 #define PRIj "I64"
40 #define SCNj "I64"
41 #define PRIz "I"
42 #define SCNz "I"
43 #define PRIt "I"
44 #define SCNt "I"
45 #else /* C < 199900 and C++ < 201100 */
46 #if LONG_MAX < INT64_MAX
47 #define PRIj "ll"
48 #define SCNj "ll"
49 #else
50 #define PRIj "l"
51 #define SCNj "l"
52 #endif
53 #define PRIz "l"
54 #define SCNz "l"
55 #define PRIt "l"
56 #define SCNt "l"
57 #endif /* C > 199900 or C++ > 201100 */
59 #if A_FLOAT_TYPE + 0 == A_FLOAT_SINGLE
60 #define strtonum(string, endptr) strtof(string, endptr)
61 #elif A_FLOAT_TYPE + 0 == A_FLOAT_DOUBLE
62 #define strtonum(string, endptr) strtod(string, endptr)
63 #elif A_FLOAT_TYPE + 0 == A_FLOAT_EXTEND
64 #define strtonum(string, endptr) strtold(string, endptr)
65 #endif /* A_FLOAT_TYPE */
67 #define TEST_IS1(expression, message) \
68 do { \
69 if (!(expression)) \
70 { \
71 (void)fprintf(stderr, "%s:%i:%s\n", __FILE__, __LINE__, message); \
72 } \
73 } while (0)
75 #define TEST_IS0(expression, message) \
76 do { \
77 if (expression) \
78 { \
79 (void)fprintf(stderr, "%s:%i:%s\n", __FILE__, __LINE__, message); \
80 } \
81 } while (0)
83 #define TEST_BUG(expression) TEST_IS1(expression, #expression)
85 #if defined(MAIN)
86 #if defined(__cplusplus)
87 extern "C" {
88 #endif /* __cplusplus */
89 int MAIN(_c)(int argc, char *argv[]);
90 int MAIN(_x)(int argc, char *argv[]);
91 int main_init(int argc, char *argv[], int arg1);
92 int debug(char const *fmt, ...) A_FORMAT(printf, 1, 2);
93 #if defined(__cplusplus)
94 } /* extern "C" */
95 #endif /* __cplusplus */
96 #if !defined __cplusplus
97 static void main_exit(void);
98 int main_init(int argc, char *argv[], int arg1)
100 static FILE *out = A_NULL;
101 if (!out && argc > arg1)
103 out = freopen(argv[arg1], "wb", stdout);
104 if (out) { arg1 = atexit(main_exit); }
106 return arg1;
108 int main(int argc, char *argv[])
110 int status = 0;
111 #if defined(HAS_CXX)
112 status += MAIN(_x)(argc, argv);
113 #endif /* HAS_CXX */
114 status += MAIN(_c)(argc, argv);
115 return status;
117 int debug(char const *fmt, ...)
119 return (void)fmt, 0;
121 static void main_exit(void)
123 if (fclose(stdout)) {}
125 #define main MAIN(_c)
126 #else /* !__cplusplus */
127 #define main MAIN(_x)
128 #endif /* __cplusplus */
129 #if defined(HAS_CXX) == \
130 defined(__cplusplus)
131 #define debug printf
132 #endif /* __cplusplus */
133 #endif /* MAIN */
135 #endif /* test/test.h */