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(A, B) test_true(A);
96 #define test_true_hint(A, B) test_true(A);
98 #define test_compare_hint(A, B, C) test_compare(A, B);
99 #define test_compare_got(A, B, C) test_compare(A, B);
101 #define test_skip(__expected, __actual) \
104 if (libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), false) == false) \
106 return TEST_SKIPPED; \
110 #define test_skip_valgrind() \
113 if (libtest::_in_valgrind(__FILE__, __LINE__, __func__)) \
115 return TEST_SKIPPED; \
119 #define test_fail(A) \
123 fprintf(stderr, "\n%s:%d: Failed with %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
124 libtest::create_core(); \
125 return TEST_FAILURE; \
130 #define test_false(A) \
134 fprintf(stderr, "\n%s:%d: Assertion failed %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
135 libtest::create_core(); \
136 return TEST_FAILURE; \
140 #define test_false_with(A,B) \
144 fprintf(stderr, "\n%s:%d: Assertion failed %s with %s\n", __FILE__, __LINE__, #A, (B));\
145 libtest::create_core(); \
146 return TEST_FAILURE; \
150 #define test_ne_compare(__expected, __actual) \
153 if (libtest::_ne_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \
155 libtest::create_core(); \
156 return TEST_FAILURE; \
160 #define test_compare(__expected, __actual) \
163 if (libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \
165 libtest::create_core(); \
166 return TEST_FAILURE; \
170 #define test_zero(__actual) \
173 if (libtest::_compare_zero(__FILE__, __LINE__, __func__, ((__actual))) == false) \
175 libtest::create_core(); \
176 return TEST_FAILURE; \
180 #define test_null test_zero
182 #define test_compare_warn(__expected, __actual) \
185 void(libtest::_compare(__FILE__, __LINE__, __func__, (__expected), (__actual)), true); \
188 #define test_warn(__truth, __explain) \
191 void(libtest::_assert_truth(__FILE__, __LINE__, __func__, bool((__truth)), #__truth, __explain)); \
194 #define test_strcmp(__expected, __actual) \
197 void(libtest::_compare_strcmp(__FILE__, __LINE__, __func__, (__expected), (__actual))); \
200 #define test_memcmp(A,B,C) \
203 if ((A) == NULL or (B) == NULL or memcmp((A), (B), (C))) \
205 fprintf(stderr, "\n%s:%d: %.*s -> %.*s\n", __FILE__, __LINE__, (int)(C), (char *)(A), (int)(C), (char *)(B)); \
206 libtest::create_core(); \
207 return TEST_FAILURE; \
211 #define test_return_if(__test_return_t) \
214 if ((__test_return_t) != TEST_SUCCESS) \
216 return __test_return_t; \