2 * Automated Testing Framework (atf)
4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #if !defined(ATF_C_MACROS_H)
31 #define ATF_C_MACROS_H
36 #define ATF_TC_NAME(tc) \
39 #define ATF_TC_PACK_NAME(tc) \
40 (atfu_ ## tc ## _tc_pack)
43 static void atfu_ ## tc ## _head(atf_tc_t *); \
44 static void atfu_ ## tc ## _body(const atf_tc_t *); \
45 static atf_tc_t atfu_ ## tc ## _tc; \
46 static atf_tc_pack_t atfu_ ## tc ## _tc_pack = { \
48 .m_head = atfu_ ## tc ## _head, \
49 .m_body = atfu_ ## tc ## _body, \
53 #define ATF_TC_WITH_CLEANUP(tc) \
54 static void atfu_ ## tc ## _head(atf_tc_t *); \
55 static void atfu_ ## tc ## _body(const atf_tc_t *); \
56 static void atfu_ ## tc ## _cleanup(const atf_tc_t *); \
57 static atf_tc_t atfu_ ## tc ## _tc; \
58 static atf_tc_pack_t atfu_ ## tc ## _tc_pack = { \
60 .m_head = atfu_ ## tc ## _head, \
61 .m_body = atfu_ ## tc ## _body, \
62 .m_cleanup = atfu_ ## tc ## _cleanup, \
65 #define ATF_TC_HEAD(tc, tcptr) \
68 atfu_ ## tc ## _head(atf_tc_t *tcptr)
70 #define ATF_TC_HEAD_NAME(tc) \
71 (atfu_ ## tc ## _head)
73 #define ATF_TC_BODY(tc, tcptr) \
76 atfu_ ## tc ## _body(const atf_tc_t *tcptr)
78 #define ATF_TC_BODY_NAME(tc) \
79 (atfu_ ## tc ## _body)
81 #define ATF_TC_CLEANUP(tc, tcptr) \
84 atfu_ ## tc ## _cleanup(const atf_tc_t *tcptr)
86 #define ATF_TC_CLEANUP_NAME(tc) \
87 (atfu_ ## tc ## _cleanup)
89 #define ATF_TP_ADD_TCS(tps) \
90 static atf_error_t atfu_tp_add_tcs(atf_tp_t *); \
91 int atf_tp_main(int, char **, atf_error_t (*)(atf_tp_t *)); \
94 main(int argc, char **argv) \
96 return atf_tp_main(argc, argv, atfu_tp_add_tcs); \
100 atfu_tp_add_tcs(atf_tp_t *tps)
102 #define ATF_TP_ADD_TC(tp, tc) \
104 atf_error_t atfu_err; \
105 atfu_err = atf_tc_init_pack(&atfu_ ## tc ## _tc, \
106 &atfu_ ## tc ## _tc_pack, \
107 atf_tp_get_config(tp)); \
108 if (atf_is_error(atfu_err)) \
110 atfu_err = atf_tp_add_tc(tp, &atfu_ ## tc ## _tc); \
111 if (atf_is_error(atfu_err)) \
115 #define ATF_REQUIRE_MSG(x, fmt, ...) \
118 atf_tc_fail_requirement(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \
121 #define ATF_CHECK_MSG(x, fmt, ...) \
124 atf_tc_fail_check(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \
127 #define ATF_REQUIRE(x) \
128 ATF_REQUIRE_MSG(x, #x " not met")
130 #define ATF_CHECK(x) \
131 ATF_CHECK_MSG(x, #x " not met")
133 #define ATF_REQUIRE_EQ(x, y) \
134 ATF_REQUIRE_MSG((x) == (y), "%s != %s", #x, #y)
136 #define ATF_CHECK_EQ(x, y) \
137 ATF_CHECK_MSG((x) == (y), "%s != %s", #x, #y)
139 #define ATF_REQUIRE_EQ_MSG(x, y, fmt, ...) \
140 ATF_REQUIRE_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__)
142 #define ATF_CHECK_EQ_MSG(x, y, fmt, ...) \
143 ATF_CHECK_MSG((x) == (y), "%s != %s: " fmt, #x, #y, ##__VA_ARGS__)
145 #define ATF_REQUIRE_STREQ(x, y) \
146 ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y)
148 #define ATF_CHECK_STREQ(x, y) \
149 ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s)", #x, #y, x, y)
151 #define ATF_REQUIRE_STREQ_MSG(x, y, fmt, ...) \
152 ATF_REQUIRE_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s): " fmt, \
153 #x, #y, x, y, ##__VA_ARGS__)
155 #define ATF_CHECK_STREQ_MSG(x, y, fmt, ...) \
156 ATF_CHECK_MSG(strcmp(x, y) == 0, "%s != %s (%s != %s): " fmt, \
157 #x, #y, x, y, ##__VA_ARGS__)
159 #endif /* !defined(ATF_C_MACROS_H) */