2011-03-10 05:48:02 -05:00
|
|
|
/***************************************************************************
|
2011-01-01 11:33:42 -05:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2015-02-03 14:59:54 -05:00
|
|
|
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-03-10 05:48:02 -05: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-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2011-03-10 05:48:02 -05: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-01 11:33:42 -05:00
|
|
|
#include "test.h"
|
|
|
|
|
2011-03-04 16:53:15 -05:00
|
|
|
/* The fail macros mark the current test step as failed, and continue */
|
2011-01-03 17:47:34 -05:00
|
|
|
#define fail_if(expr, msg) \
|
|
|
|
if(expr) { \
|
2011-01-04 10:14:23 -05:00
|
|
|
fprintf(stderr, "%s:%d Assertion '%s' met: %s\n" , \
|
2011-01-03 17:47:34 -05:00
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
}
|
|
|
|
|
2011-01-04 10:14:23 -05: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 11:33:42 -05:00
|
|
|
}
|
|
|
|
|
2015-02-03 14:59:54 -05:00
|
|
|
#define verify_memory(dynamic, check, len) \
|
|
|
|
if(dynamic && memcmp(dynamic, check, len)) { \
|
|
|
|
fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
|
|
|
|
__FILE__, __LINE__, len, hexdump((unsigned char *)check, len)); \
|
|
|
|
fprintf(stderr, "%s:%d the same as '%s'\n", \
|
|
|
|
__FILE__, __LINE__, hexdump((unsigned char *)dynamic, len)); \
|
|
|
|
unitfail++; \
|
2011-01-04 10:31:54 -05:00
|
|
|
}
|
|
|
|
|
2011-01-04 17:09:19 -05: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 10:06:10 -04:00
|
|
|
} WHILE_FALSE
|
2011-01-04 17:09:19 -05:00
|
|
|
|
|
|
|
|
2011-03-04 16:53:15 -05: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; \
|
2011-09-03 10:06:10 -04:00
|
|
|
} WHILE_FALSE
|
2011-03-04 16:53:15 -05:00
|
|
|
|
|
|
|
|
2011-01-04 17:09:19 -05:00
|
|
|
|
2011-01-01 11:33:42 -05:00
|
|
|
extern int unitfail;
|
|
|
|
|
|
|
|
#define UNITTEST_START \
|
2011-03-04 18:11:21 -05:00
|
|
|
int test(char *arg) \
|
2011-01-01 11:33:42 -05:00
|
|
|
{ \
|
2011-03-04 18:11:21 -05:00
|
|
|
(void)arg; \
|
2011-01-06 02:53:24 -05:00
|
|
|
if (unit_setup()) { \
|
|
|
|
fail("unit_setup() failure"); \
|
|
|
|
} else {
|
2011-01-01 11:33:42 -05:00
|
|
|
|
|
|
|
#define UNITTEST_STOP \
|
2011-03-04 16:53:15 -05:00
|
|
|
goto unit_test_abort; /* avoid warning */ \
|
|
|
|
unit_test_abort: \
|
2011-01-06 02:53:24 -05:00
|
|
|
unit_stop(); \
|
2011-01-03 17:47:34 -05:00
|
|
|
} \
|
2011-01-01 11:33:42 -05:00
|
|
|
return unitfail; \
|
|
|
|
}
|
|
|
|
|