1 // Copyright (c) 2009 The NetBSD Foundation, Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions
7 // 1. Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
13 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #if defined(ATF_CXX_DETAIL_TEST_HELPERS_H)
27 # error "Cannot include test_helpers.hpp more than once."
29 # define ATF_CXX_DETAIL_TEST_HELPERS_H
37 #include <atf-c++.hpp>
39 #include <atf-c++/detail/process.hpp>
41 #define HEADER_TC(name, hdrname) \
42 ATF_TEST_CASE(name); \
43 ATF_TEST_CASE_HEAD(name) \
45 set_md_var("descr", "Tests that the " hdrname " file can be " \
46 "included on its own, without any prerequisites"); \
48 ATF_TEST_CASE_BODY(name) \
50 header_check(hdrname); \
53 #define BUILD_TC(name, sfile, descr, failmsg) \
54 ATF_TEST_CASE(name); \
55 ATF_TEST_CASE_HEAD(name) \
57 set_md_var("descr", descr); \
59 ATF_TEST_CASE_BODY(name) \
61 if (!build_check_cxx_o_srcdir(*this, sfile)) \
71 void header_check(const char*);
72 bool build_check_cxx_o(const char*);
73 bool build_check_cxx_o_srcdir(const atf::tests::tc&, const char*);
74 atf::fs::path get_process_helpers_path(const atf::tests::tc&, bool);
76 struct run_h_tc_data {
77 const atf::tests::vars_map& m_config;
79 run_h_tc_data(const atf::tests::vars_map& config) :
83 template< class TestCase >
85 run_h_tc_child(void* v)
87 run_h_tc_data* data = static_cast< run_h_tc_data* >(v);
90 tc.init(data->m_config);
92 std::exit(EXIT_SUCCESS);
95 template< class TestCase >
97 run_h_tc(atf::tests::vars_map config = atf::tests::vars_map())
99 run_h_tc_data data(config);
100 atf::process::child c = atf::process::fork(
101 run_h_tc_child< TestCase >,
102 atf::process::stream_redirect_path(atf::fs::path("stdout")),
103 atf::process::stream_redirect_path(atf::fs::path("stderr")),
105 const atf::process::status s = c.wait();
106 ATF_REQUIRE(s.exited());