1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #ifndef __INTEL_COMPILER
26 #pragma GCC diagnostic ignored "-Wold-style-cast"
30 A structure describing the test case.
35 test_callback_fn
*test_fn
;
38 #define test_assert_errno(A) \
42 fprintf(stderr, "\n%s:%d: Assertion failed for %s: ", __FILE__, __LINE__, __func__);\
44 fprintf(stderr, "\n"); \
45 libtest::create_core(); \
50 #define test_assert(A, B) \
54 fprintf(stderr, "\n%s:%d: Assertion failed %s, with message %s, in %s", __FILE__, __LINE__, (B), #A, __func__ );\
55 fprintf(stderr, "\n"); \
56 libtest::create_core(); \
61 #define test_truth(A) \
65 fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
66 libtest::create_core(); \
67 return TEST_FAILURE; \
71 #define test_true(A) \
75 fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
76 libtest::create_core(); \
77 return TEST_FAILURE; \
81 #define test_true_got(__expected, __hint) \
84 if (not libtest::_compare_truth_hint(__FILE__, __LINE__, __func__, ((__expected)), #__expected, ((__hint)))) \
86 libtest::create_core(); \
87 return TEST_FAILURE; \
90 #define test_true_hint test_true_got
92 #define test_skip(__expected, __actual) \
95 if (libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), false) == false) \
97 return TEST_SKIPPED; \
101 #define test_skip_valgrind() \
104 if (libtest::_in_valgrind(__FILE__, __LINE__, __func__)) \
106 return TEST_SKIPPED; \
110 #define test_fail(A) \
114 fprintf(stderr, "\n%s:%d: Failed with %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
115 libtest::create_core(); \
116 return TEST_FAILURE; \
121 #define test_false(A) \
125 fprintf(stderr, "\n%s:%d: Assertion failed %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
126 libtest::create_core(); \
127 return TEST_FAILURE; \
131 #define test_false_with(A,B) \
135 fprintf(stderr, "\n%s:%d: Assertion failed %s with %s\n", __FILE__, __LINE__, #A, (B));\
136 libtest::create_core(); \
137 return TEST_FAILURE; \
141 #define test_ne_compare(__expected, __actual) \
144 if (libtest::_ne_compare_hint(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \
146 libtest::create_core(); \
147 return TEST_FAILURE; \
151 #define test_compare(__expected, __actual) \
154 if (libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)), true) == false) \
156 libtest::create_core(); \
157 return TEST_FAILURE; \
161 #define test_zero(__actual) \
164 if (not libtest::_compare_zero(__FILE__, __LINE__, __func__, ((__actual)))) \
166 libtest::create_core(); \
167 return TEST_FAILURE; \
171 #define test_null test_zero
173 #define test_compare_got(__expected, __actual, __hint) \
176 if (not libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint))) \
178 libtest::create_core(); \
179 return TEST_FAILURE; \
183 #define test_compare_hint test_compare_got
185 #define test_compare_warn(__expected, __actual) \
188 void(libtest::_compare(__FILE__, __LINE__, __func__, (__expected), (__actual)), true); \
191 #define test_compare_warn_hint(__expected, __actual, __hint) \
194 libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint)); \
197 #define test_warn(__truth) \
200 void(libtest::_truth(__FILE__, __LINE__, __func__, (__truth))); \
203 #define test_warn_hint(__truth, __hint) \
206 void(libtest::_compare_truth_hint(__FILE__, __LINE__, __func__, (__truth), #__truth, (__hint))); \
210 #define test_strcmp(A,B) \
213 if ((A) == NULL or (B) == NULL or strcmp((A), (B))) \
215 if ((B) == NULL) fprintf(stderr, "\n%s:%d: Expected %s, got <null>\n", __FILE__, __LINE__, (A)); \
216 else fprintf(stderr, "\n%s:%d: Expected %s, got \"%s\"\n", __FILE__, __LINE__, (A), (B)); \
217 libtest::create_core(); \
218 return TEST_FAILURE; \
222 #define test_memcmp(A,B,C) \
225 if ((A) == NULL or (B) == NULL or memcmp((A), (B), (C))) \
227 fprintf(stderr, "\n%s:%d: %.*s -> %.*s\n", __FILE__, __LINE__, (int)(C), (char *)(A), (int)(C), (char *)(B)); \
228 libtest::create_core(); \
229 return TEST_FAILURE; \
233 #define test_memcmp_hint(A,B,C,__hint) \
236 if ((A) == NULL or (B) == NULL or memcmp((A), (B), (C))) \
238 fprintf(stderr, "\n%s:%d: (hint:%s) %.*s -> %.*s\n", __FILE__, __LINE__, __hint, (int)(C), (char *)(A), (int)(C), (char *)(B)); \
239 libtest::create_core(); \
240 return TEST_FAILURE; \
244 #define test_return_if(__test_return_t) \
247 if ((__test_return_t) != TEST_SUCCESS) \
249 return __test_return_t; \