2 * uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/
4 * Use and distribution licensed under the BSD license. See
5 * the COPYING file in the parent directory for full text.
10 #ifndef __INTEL_COMPILER
11 #pragma GCC diagnostic ignored "-Wold-style-cast"
14 #include <libtest/stream.h>
17 const char* default_socket();
20 void set_default_socket(const char *socket
);
24 A structure describing the test case.
29 test_callback_fn
*test_fn
;
33 bool test_is_local(void);
35 #define test_assert_errno(A) \
39 fprintf(stderr, "\n%s:%d: Assertion failed for %s: ", __FILE__, __LINE__, __func__);\
41 fprintf(stderr, "\n"); \
47 #define test_assert(A, B) \
51 fprintf(stderr, "\n%s:%d: Assertion failed %s, with message %s, in %s", __FILE__, __LINE__, (B), #A, __func__ );\
52 fprintf(stderr, "\n"); \
58 #define test_truth(A) \
62 fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
64 return TEST_FAILURE; \
68 #define test_true(A) \
72 fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
74 return TEST_FAILURE; \
78 template <class T_comparable
, class T_hint
>
79 bool _true_hint(const char *file
, int line
, const char *func
, T_comparable __expected
, const char *assertation_label
, T_hint __hint
)
81 if (__expected
== false)
83 libtest::stream::make_cerr(file
, line
, func
) << "Assertation \"" << assertation_label
<< "\" failed, hint: " << __hint
;
90 #define test_true_got(__expected, __hint) \
93 if (not _true_hint(__FILE__, __LINE__, __func__, ((__expected)), #__expected, ((__hint)))) \
96 return TEST_FAILURE; \
100 #define test_skip(A,B) \
105 return TEST_SKIPPED; \
109 #define test_fail(A) \
113 fprintf(stderr, "\n%s:%d: Failed with %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
115 return TEST_FAILURE; \
120 #define test_false(A) \
124 fprintf(stderr, "\n%s:%d: Assertion failed %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
126 return TEST_FAILURE; \
130 #define test_false_with(A,B) \
134 fprintf(stderr, "\n%s:%d: Assertion failed %s with %s\n", __FILE__, __LINE__, #A, (B));\
136 return TEST_FAILURE; \
140 template <class T_comparable
>
141 bool _compare(const char *file
, int line
, const char *func
, T_comparable __expected
, T_comparable __actual
)
143 if (__expected
!= __actual
)
145 libtest::stream::make_cerr(file
, line
, func
) << "Expected \"" << __expected
<< "\" got \"" << __actual
<< "\"";
152 template <class T_comparable
>
153 bool _compare_zero(const char *file
, int line
, const char *func
, T_comparable __actual
)
155 if (T_comparable(0) != __actual
)
157 libtest::stream::make_cerr(file
, line
, func
) << "Expected 0 got \"" << __actual
<< "\"";
164 template <class T_comparable
, class T_hint
>
165 bool _compare_hint(const char *file
, int line
, const char *func
, T_comparable __expected
, T_comparable __actual
, T_hint __hint
)
167 if (__expected
!= __actual
)
169 libtest::stream::make_cerr(file
, line
, func
) << "Expected \"" << __expected
<< "\" got \"" << __actual
<< "\" Additionally: \"" << __hint
<< "\"";
177 #define test_compare(__expected, __actual) \
180 if (not _compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)))) \
183 return TEST_FAILURE; \
187 #define test_zero(__actual) \
190 if (not _compare_zero(__FILE__, __LINE__, __func__, ((__actual)))) \
193 return TEST_FAILURE; \
197 #define test_compare_got(__expected, __actual, __hint) \
200 if (not _compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint))) \
203 return TEST_FAILURE; \
208 #define test_strcmp(A,B) \
211 if (strcmp((A), (B))) \
213 fprintf(stderr, "\n%s:%d: Expected %s, got %s\n", __FILE__, __LINE__, (A), (B)); \
215 return TEST_FAILURE; \
219 #define test_memcmp(A,B,C) \
222 if (memcmp((A), (B), (C))) \
224 fprintf(stderr, "\n%s:%d: %.*s -> %.*s\n", __FILE__, __LINE__, (int)(C), (char *)(A), (int)(C), (char *)(B)); \
226 return TEST_FAILURE; \
230 #define test_return_if(__test_return_t) \
233 if ((__test_return_t) != TEST_SUCCESS) \
235 return __test_return_t; \