2011-01-01 19:33:42 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
2011-03-05 00:53:15 +03:00
|
|
|
/* The fail macros mark the current test step as failed, and continue */
|
2011-01-04 01:47:34 +03:00
|
|
|
#define fail_if(expr, msg) \
|
|
|
|
if(expr) { \
|
2011-01-04 18:14:23 +03:00
|
|
|
fprintf(stderr, "%s:%d Assertion '%s' met: %s\n" , \
|
2011-01-04 01:47:34 +03:00
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
}
|
|
|
|
|
2011-01-04 18:14:23 +03:00
|
|
|
#define fail_unless(expr, msg) \
|
|
|
|
if(!(expr)) { \
|
|
|
|
fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
|
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
2011-01-01 19:33:42 +03:00
|
|
|
}
|
|
|
|
|
2011-01-04 18:31:54 +03:00
|
|
|
#define verify_memory(dynamic, check, len) \
|
2011-01-04 18:41:42 +03:00
|
|
|
if(dynamic && memcmp(dynamic, check, len)) { \
|
2011-01-04 18:31:54 +03:00
|
|
|
fprintf(stderr, "%s:%d The dynamic string didn't match '%s'\n", \
|
|
|
|
__FILE__, __LINE__, check); \
|
|
|
|
unitfail++; \
|
|
|
|
}
|
|
|
|
|
2011-01-05 01:09:19 +03:00
|
|
|
/* fail() is for when the test case figured out by itself that a check
|
|
|
|
proved a failure */
|
|
|
|
#define fail(msg) do { \
|
|
|
|
fprintf(stderr, "%s:%d test failed: '%s'\n", \
|
|
|
|
__FILE__, __LINE__, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
2011-03-05 00:53:15 +03:00
|
|
|
/* The abort macros mark the current test step as failed, and exit the test */
|
|
|
|
#define abort_if(expr, msg) \
|
|
|
|
if(expr) { \
|
|
|
|
fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n" , \
|
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
goto unit_test_abort; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define abort_unless(expr, msg) \
|
|
|
|
if(!(expr)) { \
|
|
|
|
fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
|
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
goto unit_test_abort; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define abort_test(msg) do { \
|
|
|
|
fprintf(stderr, "%s:%d test aborted: '%s'\n", \
|
|
|
|
__FILE__, __LINE__, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
goto unit_test_abort; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
2011-01-05 01:09:19 +03:00
|
|
|
|
2011-01-01 19:33:42 +03:00
|
|
|
extern int unitfail;
|
|
|
|
|
|
|
|
#define UNITTEST_START \
|
|
|
|
int test(char *unused) \
|
|
|
|
{ \
|
|
|
|
(void)unused; \
|
2011-01-06 10:53:24 +03:00
|
|
|
if (unit_setup()) { \
|
|
|
|
fail("unit_setup() failure"); \
|
|
|
|
} else {
|
2011-01-01 19:33:42 +03:00
|
|
|
|
|
|
|
#define UNITTEST_STOP \
|
2011-03-05 00:53:15 +03:00
|
|
|
goto unit_test_abort; /* avoid warning */ \
|
|
|
|
unit_test_abort: \
|
2011-01-06 10:53:24 +03:00
|
|
|
unit_stop(); \
|
2011-01-04 01:47:34 +03:00
|
|
|
} \
|
2011-01-01 19:33:42 +03:00
|
|
|
return unitfail; \
|
|
|
|
}
|
|
|
|
|