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"
29 #include <libtest/stream.h>
30 #include <libtest/comparison.hpp>
33 A structure describing the test case.
38 test_callback_fn
*test_fn
;
41 #define test_assert_errno(A) \
45 fprintf(stderr, "\n%s:%d: Assertion failed for %s: ", __FILE__, __LINE__, __func__);\
47 fprintf(stderr, "\n"); \
53 #define test_assert(A, B) \
57 fprintf(stderr, "\n%s:%d: Assertion failed %s, with message %s, in %s", __FILE__, __LINE__, (B), #A, __func__ );\
58 fprintf(stderr, "\n"); \
64 #define test_truth(A) \
68 fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
70 return TEST_FAILURE; \
74 #define test_true(A) \
78 fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, in %s\n", __FILE__, __LINE__, #A, __func__);\
80 return TEST_FAILURE; \
84 #define test_true_got(__expected, __hint) \
87 if (not libtest::_compare_true_hint(__FILE__, __LINE__, __func__, ((__expected)), #__expected, ((__hint)))) \
90 return TEST_FAILURE; \
94 #define test_skip(A,B) \
99 return TEST_SKIPPED; \
103 #define test_fail(A) \
107 fprintf(stderr, "\n%s:%d: Failed with %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
109 return TEST_FAILURE; \
114 #define test_false(A) \
118 fprintf(stderr, "\n%s:%d: Assertion failed %s, in %s\n", __FILE__, __LINE__, #A, __func__);\
120 return TEST_FAILURE; \
124 #define test_false_with(A,B) \
128 fprintf(stderr, "\n%s:%d: Assertion failed %s with %s\n", __FILE__, __LINE__, #A, (B));\
130 return TEST_FAILURE; \
134 #define test_compare(__expected, __actual) \
137 if (not libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)))) \
140 return TEST_FAILURE; \
144 #define test_zero(__actual) \
147 if (not libtest::_compare_zero(__FILE__, __LINE__, __func__, ((__actual)))) \
150 return TEST_FAILURE; \
154 #define test_compare_got(__expected, __actual, __hint) \
157 if (not libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint))) \
160 return TEST_FAILURE; \
165 #define test_strcmp(A,B) \
168 if (strcmp((A), (B))) \
170 fprintf(stderr, "\n%s:%d: Expected %s, got %s\n", __FILE__, __LINE__, (A), (B)); \
172 return TEST_FAILURE; \
176 #define test_memcmp(A,B,C) \
179 if (memcmp((A), (B), (C))) \
181 fprintf(stderr, "\n%s:%d: %.*s -> %.*s\n", __FILE__, __LINE__, (int)(C), (char *)(A), (int)(C), (char *)(B)); \
183 return TEST_FAILURE; \
187 #define test_return_if(__test_return_t) \
190 if ((__test_return_t) != TEST_SUCCESS) \
192 return __test_return_t; \