4 #include <test_config.h>
26 # define ONCE __pragma(warning(push)) \
27 __pragma(warning(disable:4127)) \
29 __pragma(warning(pop))
31 # define ONCE while (0)
40 #define UTEST_MAIN() int main(int argc, char *argv[]) { \
41 return testlib_main(argc, argv); \
47 #define UFATAL(condition) \
49 if (testlib_fatal(condition, #condition, __FILE__, __LINE__)) { \
63 #define UVERIFY(condition) \
65 if (testlib_verify(condition, #condition, __FILE__, __LINE__)) { \
78 #define UVERIFY2(condition, info) \
80 if (testlib_verify2(condition, #condition, info, __FILE__, __LINE__)) { \
97 #define UCOMPARE(actual, expected) \
99 if (testlib_compare(actual, expected, #actual, #expected, __FILE__, __LINE__)) { \
105 #define UCOMPARE64(actual, expected) \
107 if (testlib_compare64(actual, expected, #actual, #expected, __FILE__, __LINE__)) { \
125 #define UCOMPAREF(actual, expected) \
127 if (testlib_comparef(actual, expected, #actual, #expected, __FILE__, __LINE__)) { \
151 #define UFUZZY_COMPAREF(actual, expected) \
153 if (testlib_fuzzy_comparef(actual, expected, #actual, #expected, \
154 __FILE__, __LINE__)) { \
164 #define UCOMPARESTR(actual, expected) \
166 if (testlib_comparestr(actual, expected, #actual, #expected, __FILE__, __LINE__)) { \
176 #define UCOMPAREMEM(actual, actuallen, expected, expectedlen) \
178 if (testlib_comparemem(actual, actuallen, expected, expectedlen, __FILE__, __LINE__)) { \
183 #define UREGISTER_NAME(name) \
185 testlib_register_name(name); \
197 #define UREGISTER_INIT(func) \
199 testlib_register_init(func); \
212 #define UREGISTER_CLEANUP(func) \
214 testlib_register_cleanup(func); \
222 #define UREGISTER_TEST(test) \
224 testlib_register_test(test, #test, 0, 0); \
232 #define UREGISTER_DATADRIVEN_TEST(test, testdata) \
234 testlib_register_datadriven_test(test, #test, testdata, #testdata, 0, 0); \
244 #define UREGISTER_TEST2(test, init, cleanup) \
246 testlib_register_test(test, #test, init, cleanup); \
260 #define UREGISTER_DATADRIVEN_TEST2(test, testdata, init, cleanup) \
262 testlib_register_datadriven_test(test, #test, testdata, #testdata, init, cleanup); \
288 #define UEXPECT_FAIL(dataIndex, comment, mode) \
290 testlib_expect_fail(dataIndex, comment, mode); \
303 #ifdef ENABLE_BENCHMARK
339 # define UBENCHMARK for (test_benchmark_start(); test_benchmark_done(); test_benchmark_next())
340 void test_benchmark_start();
341 bool test_benchmark_done();
342 void test_benchmark_next();
344 # define UBENCHMARK while (0)
347 int testlib_fatal(
int condition,
const char *scondition,
const char *file,
int line);
348 int testlib_verify(
int condition,
const char *scondition,
const char *file,
int line);
349 int testlib_verify2(
int condition,
const char *scondition,
const char *info,
const char *file,
int line);
350 int testlib_compare(
int actual,
int expected,
const char *sactual,
const char *sexpected,
const char *file,
int line);
351 int testlib_compare64(int64_t actual, int64_t expected,
const char *sactual,
const char *sexpected,
const char *file,
int line);
352 int testlib_comparef(
double actual,
double expected,
const char *sactual,
const char *sexpected,
const char *file,
int line);
353 int testlib_fuzzy_comparef(
double actual,
double expected,
const char *sactual,
const char *sexpected,
const char *file,
int line);
354 int testlib_comparestr(
const char *actual,
const char *expected,
const char *sactual,
const char *sexpected,
const char *file,
int line);
355 int testlib_comparemem(
const unsigned char *actual,
size_t actuallen,
const unsigned char *expected,
size_t expectedlen,
const char *file,
int line);
356 void testlib_expect_fail(
const char *dataIndex,
const char *comment,
enum testlib_fail_mode mode);
365 typedef void (*testfunction)();
367 void testlib_register_name(
const char *name);
368 void testlib_register_init(testfunction func);
369 void testlib_register_cleanup(testfunction func);
370 void testlib_register_test(testfunction test,
const char *stest, testfunction init, testfunction cleanup);
371 void testlib_register_datadriven_test(testfunction test,
const char *stest, testfunction testdata,
const char *stestdata, testfunction init, testfunction cleanup);
376 void testlib_info(
const char *msg);
378 struct testlib_stat {
388 #define UINFO(msg) testlib_info(msg)
unsigned int testlib_fetch_uint(const char *name)
This function behaves exactly like testlib_fetch() but returns an unsigned int value previously store...
Definition: testlib.c:465
void testlib_run_tests(const char *testname, const char *testset)
Executes registered test functions.
Definition: testlib.c:924
int testlib_main(int argc, char *argv[])
Test main implementation used by UTEST_MAIN.
Definition: testlib.c:1221
Continues execution of the test after the expected failure.
Definition: testlib.h:300
struct testlib_stat * testlib_result()
Returns the test result statistic.
Definition: testlib.c:1044
void testlib_add_row(const char *name,...)
Adds a new data row for data-driven tests.
Definition: testlib.c:348
int testlib_silent()
Decrease verbosity level to get less output.
Definition: testlib.c:198
double testlib_fetch_double(const char *name)
This function behaves exactly like testlib_fetch() but returns a double value previously stored in a ...
Definition: testlib.c:483
int testlib_verbose()
Increase verbosity level to get more output.
Definition: testlib.c:192
Aborts the execution of the test.
Definition: testlib.h:297
void testlib_add_column(const char *name, const char *fmt)
Adds a new data column for data-driven tests.
Definition: testlib.c:332
void * testlib_fetch(const char *name)
Returns the data for the given column name of the current test dataset.
Definition: testlib.c:429
testlib_fail_mode
This enum describes the modes for handling an expected failure of the UVERIFY() or UCOMPARE() macros...
Definition: testlib.h:296
int testlib_fetch_int(const char *name)
This function behaves exactly like testlib_fetch() but returns an int value previously stored in a %i...
Definition: testlib.c:447
void testlib_list_tests()
Lists all registered test functions.
Definition: testlib.c:1033