tizen 2.3.1 release
[external/curl.git] / tests / unit / curlcheck.h
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
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.
13  *
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.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "test.h"
23
24 /* The fail macros mark the current test step as failed, and continue */
25 #define fail_if(expr, msg)                              \
26   if(expr) {                                            \
27     fprintf(stderr, "%s:%d Assertion '%s' met: %s\n" ,  \
28             __FILE__, __LINE__, #expr, msg);            \
29     unitfail++;                                         \
30   }
31
32 #define fail_unless(expr, msg)                           \
33   if(!(expr)) {                                          \
34     fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
35             __FILE__, __LINE__, #expr, msg);             \
36     unitfail++;                                          \
37   }
38
39 #define verify_memory(dynamic, check, len)                              \
40   if(dynamic && memcmp(dynamic, check, len)) {                          \
41     fprintf(stderr, "%s:%d The dynamic string didn't match '%s'\n",     \
42             __FILE__, __LINE__, check);                                 \
43     unitfail++;                                                         \
44   }
45
46 /* fail() is for when the test case figured out by itself that a check
47    proved a failure */
48 #define fail(msg) do {                                                 \
49     fprintf(stderr, "%s:%d test failed: '%s'\n",                       \
50             __FILE__, __LINE__, msg);                                  \
51     unitfail++;                                                        \
52   } WHILE_FALSE
53
54
55 /* The abort macros mark the current test step as failed, and exit the test */
56 #define abort_if(expr, msg)                                   \
57   if(expr) {                                                  \
58     fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n" ,  \
59             __FILE__, __LINE__, #expr, msg);                  \
60     unitfail++;                                               \
61     goto unit_test_abort;                                     \
62   }
63
64 #define abort_unless(expr, msg)                                \
65   if(!(expr)) {                                                \
66     fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
67             __FILE__, __LINE__, #expr, msg);                   \
68     unitfail++;                                                \
69     goto unit_test_abort;                                      \
70   }
71
72 #define abort_test(msg) do {                                  \
73     fprintf(stderr, "%s:%d test aborted: '%s'\n",             \
74             __FILE__, __LINE__, msg);                         \
75     unitfail++;                                               \
76     goto unit_test_abort;                                     \
77   } WHILE_FALSE
78
79
80
81 extern int unitfail;
82
83 #define UNITTEST_START                          \
84   int test(char *arg)                           \
85   {                                             \
86   (void)arg;                                    \
87   if (unit_setup()) {                           \
88     fail("unit_setup() failure");               \
89   } else {
90
91 #define UNITTEST_STOP                           \
92     goto unit_test_abort; /* avoid warning */   \
93 unit_test_abort:                                \
94     unit_stop();                                \
95   }                                             \
96   return unitfail;                              \
97   }
98