1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
24 /* The fail macros mark the current test step as failed, and continue */
25 #define fail_if(expr, msg) \
27 fprintf(stderr, "%s:%d Assertion '%s' met: %s\n" , \
28 __FILE__, __LINE__, #expr, msg); \
32 #define fail_unless(expr, msg) \
34 fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
35 __FILE__, __LINE__, #expr, msg); \
39 #define verify_memory(dynamic, check, len) \
40 if(dynamic && memcmp(dynamic, check, len)) { \
41 fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
42 __FILE__, __LINE__, len, hexdump((unsigned char *)check, len)); \
43 fprintf(stderr, "%s:%d the same as '%s'\n", \
44 __FILE__, __LINE__, hexdump((unsigned char *)dynamic, len)); \
48 /* fail() is for when the test case figured out by itself that a check
50 #define fail(msg) do { \
51 fprintf(stderr, "%s:%d test failed: '%s'\n", \
52 __FILE__, __LINE__, msg); \
57 /* The abort macros mark the current test step as failed, and exit the test */
58 #define abort_if(expr, msg) \
60 fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n" , \
61 __FILE__, __LINE__, #expr, msg); \
63 goto unit_test_abort; \
66 #define abort_unless(expr, msg) \
68 fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
69 __FILE__, __LINE__, #expr, msg); \
71 goto unit_test_abort; \
74 #define abort_test(msg) do { \
75 fprintf(stderr, "%s:%d test aborted: '%s'\n", \
76 __FILE__, __LINE__, msg); \
78 goto unit_test_abort; \
85 #define UNITTEST_START \
90 fail("unit_setup() failure"); \
93 #define UNITTEST_STOP \
94 goto unit_test_abort; /* avoid warning */ \