2011-03-10 18:48:02 +08:00
|
|
|
/***************************************************************************
|
2011-01-02 00:33:42 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2016-04-03 22:21:10 +08:00
|
|
|
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-03-10 18:48:02 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-03 07:19:02 +08:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2011-03-10 18:48:02 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2011-01-02 00:33:42 +08:00
|
|
|
#include "test.h"
|
|
|
|
|
2011-03-05 05:53:15 +08:00
|
|
|
/* The fail macros mark the current test step as failed, and continue */
|
2011-01-04 06:47:34 +08:00
|
|
|
#define fail_if(expr, msg) \
|
|
|
|
if(expr) { \
|
2016-04-04 04:51:47 +08:00
|
|
|
fprintf(stderr, "%s:%d Assertion '%s' met: %s\n", \
|
2011-01-04 06:47:34 +08:00
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
}
|
|
|
|
|
2011-01-04 23:14:23 +08:00
|
|
|
#define fail_unless(expr, msg) \
|
|
|
|
if(!(expr)) { \
|
|
|
|
fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
|
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
2011-01-02 00:33:42 +08:00
|
|
|
}
|
|
|
|
|
2015-02-04 03:59:54 +08:00
|
|
|
#define verify_memory(dynamic, check, len) \
|
|
|
|
if(dynamic && memcmp(dynamic, check, len)) { \
|
2016-04-03 22:21:10 +08:00
|
|
|
fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
|
2017-05-06 03:29:50 +08:00
|
|
|
__FILE__, __LINE__, len, \
|
|
|
|
hexdump((const unsigned char *)check, len)); \
|
|
|
|
fprintf(stderr, "%s:%d the same as '%s'\n", __FILE__, __LINE__, \
|
|
|
|
hexdump((const unsigned char *)dynamic, len)); \
|
2015-02-04 03:59:54 +08:00
|
|
|
unitfail++; \
|
2011-01-04 23:31:54 +08:00
|
|
|
}
|
|
|
|
|
2011-01-05 06:09:19 +08: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++; \
|
2011-09-03 22:06:10 +08:00
|
|
|
} WHILE_FALSE
|
2011-01-05 06:09:19 +08:00
|
|
|
|
|
|
|
|
2011-03-05 05:53:15 +08:00
|
|
|
/* The abort macros mark the current test step as failed, and exit the test */
|
|
|
|
#define abort_if(expr, msg) \
|
|
|
|
if(expr) { \
|
2016-04-04 04:51:47 +08:00
|
|
|
fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n", \
|
2011-03-05 05:53:15 +08:00
|
|
|
__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; \
|
2011-09-03 22:06:10 +08:00
|
|
|
} WHILE_FALSE
|
2011-03-05 05:53:15 +08:00
|
|
|
|
|
|
|
|
2011-01-05 06:09:19 +08:00
|
|
|
|
2011-01-02 00:33:42 +08:00
|
|
|
extern int unitfail;
|
|
|
|
|
|
|
|
#define UNITTEST_START \
|
2011-03-05 07:11:21 +08:00
|
|
|
int test(char *arg) \
|
2011-01-02 00:33:42 +08:00
|
|
|
{ \
|
2016-04-03 22:21:10 +08:00
|
|
|
(void)arg; \
|
|
|
|
if(unit_setup()) { \
|
|
|
|
fail("unit_setup() failure"); \
|
|
|
|
} \
|
|
|
|
else {
|
2011-01-02 00:33:42 +08:00
|
|
|
|
|
|
|
#define UNITTEST_STOP \
|
2011-03-05 05:53:15 +08:00
|
|
|
goto unit_test_abort; /* avoid warning */ \
|
|
|
|
unit_test_abort: \
|
2011-01-06 15:53:24 +08:00
|
|
|
unit_stop(); \
|
2011-01-04 06:47:34 +08:00
|
|
|
} \
|
2011-01-02 00:33:42 +08:00
|
|
|
return unitfail; \
|
|
|
|
}
|