1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Data Differential YATL (i.e. libtest) library
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #ifndef __INTEL_COMPILER
40 #pragma GCC diagnostic ignored "-Wold-style-cast"
44 A structure describing the test case.
49 test_callback_fn
*test_fn
;
52 #define test_assert_errno(A) \
56 fprintf(stderr, "\n%s:%d: Assertion failed for %s: ", __FILE__, __LINE__, __func__);\
58 fprintf(stderr, "\n"); \
59 libtest::create_core(); \
64 #define test_assert(A, B) \
68 fprintf(stderr, "\n%s:%d: Assertion failed %s, with message %s, in %s", __FILE__, __LINE__, (B), #A, __func__ );\
69 fprintf(stderr, "\n"); \
70 libtest::create_core(); \
75 #define test_truth(A) \
79 fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
80 libtest::create_core(); \
81 return TEST_FAILURE; \
85 #define test_true(A) \
89 fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
90 libtest::create_core(); \
91 return TEST_FAILURE; \
95 #define test_true_got(__expected, __hint) \
98 if (not libtest::_compare_truth_hint(__FILE__, __LINE__, __func__, ((__expected)), #__expected, ((__hint)))) \
100 libtest::create_core(); \
101 return TEST_FAILURE; \
104 #define test_true_hint test_true_got
106 #define test_skip(__expected, __actual) \
109 if (libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), false) == false) \
111 return TEST_SKIPPED; \
115 #define test_skip_hint(__expected, __actual, __hint) \
118 if (libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint)) == false) \
120 return TEST_SKIPPED; \
124 #define test_skip_valgrind() \
127 if (libtest::_in_valgrind(__FILE__, __LINE__, __func__)) \
129 return TEST_SKIPPED; \
133 #define test_fail(A) \
137 fprintf(stderr, "\n%s:%d: Failed with %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
138 libtest::create_core(); \
139 return TEST_FAILURE; \
144 #define test_false(A) \
148 fprintf(stderr, "\n%s:%d: Assertion failed %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
149 libtest::create_core(); \
150 return TEST_FAILURE; \
154 #define test_false_with(A,B) \
158 fprintf(stderr, "\n%s:%d: Assertion failed %s with %s\n", __FILE__, __LINE__, #A, (B));\
159 libtest::create_core(); \
160 return TEST_FAILURE; \
164 #define test_ne_compare(__expected, __actual) \
167 if (libtest::_ne_compare_hint(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \
169 libtest::create_core(); \
170 return TEST_FAILURE; \
174 #define test_compare(__expected, __actual) \
177 if (libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \
179 libtest::create_core(); \
180 return TEST_FAILURE; \
184 #define test_zero(__actual) \
187 if (not libtest::_compare_zero(__FILE__, __LINE__, __func__, ((__actual)))) \
189 libtest::create_core(); \
190 return TEST_FAILURE; \
194 #define test_null test_zero
196 #define test_compare_got(__expected, __actual, __hint) \
199 if (not libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint))) \
201 libtest::create_core(); \
202 return TEST_FAILURE; \
206 #define test_compare_hint test_compare_got
208 #define test_compare_warn(__expected, __actual) \
211 void(libtest::_compare(__FILE__, __LINE__, __func__, (__expected), (__actual)), true); \
214 #define test_compare_warn_hint(__expected, __actual, __hint) \
217 libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint)); \
220 #define test_warn(__truth) \
223 void(libtest::_truth(__FILE__, __LINE__, __func__, (__truth))); \
226 #define test_warn_hint(__truth, __hint) \
229 void(libtest::_compare_truth_hint(__FILE__, __LINE__, __func__, (__truth), #__truth, (__hint))); \
233 #define test_strcmp(A,B) \
236 if ((A) == NULL or (B) == NULL or strcmp((A), (B))) \
238 if ((B) == NULL) fprintf(stderr, "\n%s:%d: Expected %s, got <null>\n", __FILE__, __LINE__, (A)); \
239 else fprintf(stderr, "\n%s:%d: Expected %s, got \"%s\"\n", __FILE__, __LINE__, (A), (B)); \
240 libtest::create_core(); \
241 return TEST_FAILURE; \
245 #define test_memcmp(A,B,C) \
248 if ((A) == NULL or (B) == NULL or memcmp((A), (B), (C))) \
250 fprintf(stderr, "\n%s:%d: %.*s -> %.*s\n", __FILE__, __LINE__, (int)(C), (char *)(A), (int)(C), (char *)(B)); \
251 libtest::create_core(); \
252 return TEST_FAILURE; \
256 #define test_memcmp_hint(A,B,C,__hint) \
259 if ((A) == NULL or (B) == NULL or memcmp((A), (B), (C))) \
261 fprintf(stderr, "\n%s:%d: (hint:%s) %.*s -> %.*s\n", __FILE__, __LINE__, __hint, (int)(C), (char *)(A), (int)(C), (char *)(B)); \
262 libtest::create_core(); \
263 return TEST_FAILURE; \
267 #define test_return_if(__test_return_t) \
270 if ((__test_return_t) != TEST_SUCCESS) \
272 return __test_return_t; \