change a_float to a_real
[liba.git] / test / test.h
blob3ca49ebb77b0cf191c4d231ff79001721a908d27
1 #ifndef TEST_TEST_H
2 #define TEST_TEST_H
4 #if !defined _CRT_SECURE_NO_WARNINGS && defined(_MSC_VER)
5 #define _CRT_SECURE_NO_WARNINGS /* NOLINT */
6 #endif /* _CRT_SECURE_NO_WARNINGS */
7 #include "a/a.h"
8 #include <stdio.h>
9 #include <stdlib.h>
10 #if defined(_MSC_VER)
11 #pragma warning(disable : 4127)
12 #pragma warning(disable : 4820)
13 #endif /* _MSC_VER */
14 #if defined(__cplusplus) && (__cplusplus > 201100L)
15 #include <type_traits>
16 #endif /* __cplusplus */
17 #if A_PREREQ_GNUC(2, 95) || __has_warning("-Winline")
18 #pragma GCC diagnostic ignored "-Winline"
19 #endif /* -Winline */
20 #if A_PREREQ_GNUC(2, 95) || __has_warning("-Wpadded")
21 #pragma GCC diagnostic ignored "-Wpadded"
22 #endif /* -Wpadded */
23 #if A_PREREQ_GNUC(4, 6) || __has_warning("-Wdouble-promotion")
24 #if defined(A_REAL_TYPE) && (A_REAL_TYPE + 0 == A_REAL_SINGLE)
25 #pragma GCC diagnostic ignored "-Wdouble-promotion"
26 #endif /* A_REAL_TYPE + 0 == 0x04 */
27 #endif /* -Wdouble-promotion */
29 #if A_REAL_TYPE + 0 == A_REAL_SINGLE
30 #define strtonum(string, endptr) strtof(string, endptr)
31 #elif A_REAL_TYPE + 0 == A_REAL_DOUBLE
32 #define strtonum(string, endptr) strtod(string, endptr)
33 #elif A_REAL_TYPE + 0 == A_REAL_EXTEND
34 #define strtonum(string, endptr) strtold(string, endptr)
35 #endif /* A_REAL_TYPE */
37 #define TEST_IS1(expression, message) \
38 do { \
39 if (!(expression)) \
40 { \
41 (void)fprintf(stderr, "%s:%i:%s\n", __FILE__, __LINE__, message); \
42 } \
43 } while (0)
45 #define TEST_IS0(expression, message) \
46 do { \
47 if (expression) \
48 { \
49 (void)fprintf(stderr, "%s:%i:%s\n", __FILE__, __LINE__, message); \
50 } \
51 } while (0)
53 #define TEST_BUG(expression) TEST_IS1(expression, #expression)
55 #if defined(MAIN)
56 #if defined(__cplusplus)
57 extern "C" {
58 #endif /* __cplusplus */
59 int MAIN(_c)(int argc, char *argv[]);
60 int MAIN(_x)(int argc, char *argv[]);
61 int main_init(int argc, char *argv[], int arg1);
62 int debug(char const *fmt, ...) A_FORMAT(printf, 1, 2);
63 #if defined(__cplusplus)
64 } /* extern "C" */
65 #endif /* __cplusplus */
66 #if !defined __cplusplus
67 static void main_exit(void);
68 int main_init(int argc, char *argv[], int arg1)
70 static FILE *out = A_NULL;
71 if (!out && argc > arg1)
73 out = freopen(argv[arg1], "wb", stdout);
74 if (out) { arg1 = atexit(main_exit); }
76 return arg1;
78 int main(int argc, char *argv[])
80 int status = 0;
81 #if defined(HAS_CXX)
82 status += MAIN(_x)(argc, argv);
83 #endif /* HAS_CXX */
84 status += MAIN(_c)(argc, argv);
85 return status;
87 int debug(char const *fmt, ...)
89 return (void)fmt, 0;
91 static void main_exit(void)
93 if (fclose(stdout)) {}
95 #define main MAIN(_c)
96 #else /* !__cplusplus */
97 #define main MAIN(_x)
98 #endif /* __cplusplus */
99 #if defined(HAS_CXX) == \
100 defined(__cplusplus)
101 #define debug printf
102 #endif /* __cplusplus */
103 #endif /* MAIN */
105 #endif /* test/test.h */