2 // Automated Testing Framework (atf)
4 // Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
5 // All rights reserved.
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_CXX_MACROS_HPP_)
31 #define _ATF_CXX_MACROS_HPP_
37 #include <atf-c++/tests.hpp>
39 #define ATF_TEST_CASE(name) \
40 class atfu_tc_ ## name : public atf::tests::tc { \
42 void body(void) const; \
44 atfu_tc_ ## name(void) : atf::tests::tc(#name) {} \
47 #define ATF_TEST_CASE_WITH_CLEANUP(name) \
48 class atfu_tc_ ## name : public atf::tests::tc { \
50 void body(void) const; \
51 void cleanup(void) const; \
53 atfu_tc_ ## name(void) : atf::tests::tc(#name) {} \
56 #define ATF_TEST_CASE_NAME(name) atfu_tc_ ## name
58 #define ATF_TEST_CASE_HEAD(name) \
60 atfu_tc_ ## name::head(void)
62 #define ATF_TEST_CASE_BODY(name) \
64 atfu_tc_ ## name::body(void) \
67 #define ATF_TEST_CASE_CLEANUP(name) \
69 atfu_tc_ ## name::cleanup(void) \
72 #define ATF_FAIL(reason) atf::tests::tc::fail(reason)
74 #define ATF_SKIP(reason) atf::tests::tc::skip(reason)
76 #define ATF_PASS() atf::tests::tc::pass()
78 #define ATF_CHECK(x) \
81 std::ostringstream atfu_ss; \
82 atfu_ss << "Line " << __LINE__ << ": " << #x << " not met"; \
83 atf::tests::tc::fail(atfu_ss.str()); \
87 #define ATF_CHECK_EQUAL(x, y) \
90 std::ostringstream atfu_ss; \
91 atfu_ss << "Line " << __LINE__ << ": " << #x << " != " << #y \
92 << " (" << (x) << " != " << (y) << ")"; \
93 atf::tests::tc::fail(atfu_ss.str()); \
97 #define ATF_CHECK_THROW(x, e) \
101 std::ostringstream atfu_ss; \
102 atfu_ss << "Line " << __LINE__ << ": " #x " did not throw " \
104 atf::tests::tc::fail(atfu_ss.str()); \
105 } catch (const e& atfu_eo) { \
106 } catch (const std::exception& atfu_e) { \
107 std::ostringstream atfu_ss; \
108 atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \
109 "unexpected error (not " #e "): " << atfu_e.what(); \
110 atf::tests::tc::fail(atfu_ss.str()); \
112 std::ostringstream atfu_ss; \
113 atfu_ss << "Line " << __LINE__ << ": " #x " threw an " \
114 "unexpected error (not " #e ")"; \
115 atf::tests::tc::fail(atfu_ss.str()); \
119 #define ATF_INIT_TEST_CASES(tcs) \
122 int run_tp(int, char* const*, \
123 void (*)(std::vector< atf::tests::tc * >&)); \
127 static void atfu_init_tcs(std::vector< atf::tests::tc * >&); \
130 main(int argc, char* const* argv) \
132 return atf::tests::run_tp(argc, argv, atfu_init_tcs); \
137 atfu_init_tcs(std::vector< atf::tests::tc * >& tcs)
139 #define ATF_ADD_TEST_CASE(tcs, tcname) \
141 atf::tests::tc* tcptr = new atfu_tc_ ## tcname(); \
142 (tcs).push_back(tcptr); \
145 #endif // !defined(_ATF_CXX_MACROS_HPP_)