2011-03-10 18:48:02 +08:00
|
|
|
/***************************************************************************
|
2011-01-02 00:33:42 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) 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
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.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.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2011-03-10 18:48:02 +08:00
|
|
|
***************************************************************************/
|
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 */
|
2020-12-30 00:21:24 +08:00
|
|
|
#define fail_if(expr, msg) \
|
|
|
|
do { \
|
|
|
|
if(expr) { \
|
|
|
|
fprintf(stderr, "%s:%d Assertion '%s' met: %s\n", \
|
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2011-01-04 06:47:34 +08:00
|
|
|
|
2020-12-30 00:21:24 +08:00
|
|
|
#define fail_unless(expr, msg) \
|
|
|
|
do { \
|
|
|
|
if(!(expr)) { \
|
|
|
|
fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
|
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2011-01-02 00:33:42 +08:00
|
|
|
|
2020-12-30 00:21:24 +08:00
|
|
|
#define verify_memory(dynamic, check, len) \
|
|
|
|
do { \
|
|
|
|
if(dynamic && memcmp(dynamic, check, len)) { \
|
|
|
|
fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
|
|
|
|
__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)); \
|
|
|
|
unitfail++; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
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++; \
|
2019-11-30 16:29:36 +08:00
|
|
|
} while(0)
|
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 */
|
2020-12-30 00:21:24 +08:00
|
|
|
#define abort_if(expr, msg) \
|
|
|
|
do { \
|
|
|
|
if(expr) { \
|
|
|
|
fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n", \
|
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
goto unit_test_abort; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2011-03-05 05:53:15 +08:00
|
|
|
|
2020-12-30 00:21:24 +08:00
|
|
|
#define abort_unless(expr, msg) \
|
|
|
|
do { \
|
|
|
|
if(!(expr)) { \
|
|
|
|
fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
|
|
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
goto unit_test_abort; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2011-03-05 05:53:15 +08:00
|
|
|
|
2020-12-30 00:21:24 +08:00
|
|
|
#define abort_test(msg) \
|
|
|
|
do { \
|
2011-03-05 05:53:15 +08:00
|
|
|
fprintf(stderr, "%s:%d test aborted: '%s'\n", \
|
|
|
|
__FILE__, __LINE__, msg); \
|
|
|
|
unitfail++; \
|
|
|
|
goto unit_test_abort; \
|
2019-11-30 16:29:36 +08:00
|
|
|
} while(0)
|
2011-03-05 05:53:15 +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; \
|
|
|
|
}
|