2 // Automated Testing Framework (atf)
4 // Copyright (c) 2009 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(TESTS_ATF_ATF_CXX_TEST_HELPERS_H)
31 # error "Cannot include test_helpers.hpp more than once."
33 # define TESTS_ATF_ATF_CXX_TEST_HELPERS_H
41 #include "../macros.hpp"
42 #include "../tests.hpp"
43 #include "process.hpp"
45 #define HEADER_TC(name, hdrname) \
46 ATF_TEST_CASE(name); \
47 ATF_TEST_CASE_HEAD(name) \
49 set_md_var("descr", "Tests that the " hdrname " file can be " \
50 "included on its own, without any prerequisites"); \
52 ATF_TEST_CASE_BODY(name) \
54 header_check(hdrname); \
57 #define BUILD_TC(name, sfile, descr, failmsg) \
58 ATF_TEST_CASE(name); \
59 ATF_TEST_CASE_HEAD(name) \
61 set_md_var("descr", descr); \
63 ATF_TEST_CASE_BODY(name) \
65 if (!build_check_cxx_o_srcdir(*this, sfile)) \
75 void header_check(const char*);
76 bool build_check_cxx_o(const char*);
77 bool build_check_cxx_o_srcdir(const atf::tests::tc
&, const char*);
78 atf::fs::path
get_process_helpers_path(const atf::tests::tc
&, bool);
80 struct run_h_tc_data
{
81 const atf::tests::vars_map
& m_config
;
83 run_h_tc_data(const atf::tests::vars_map
& config
) :
87 template< class TestCase
>
89 run_h_tc_child(void* v
)
91 run_h_tc_data
* data
= static_cast< run_h_tc_data
* >(v
);
94 tc
.init(data
->m_config
);
96 std::exit(EXIT_SUCCESS
);
99 template< class TestCase
>
101 run_h_tc(atf::tests::vars_map config
= atf::tests::vars_map())
103 run_h_tc_data
data(config
);
104 atf::process::child c
= atf::process::fork(
105 run_h_tc_child
< TestCase
>,
106 atf::process::stream_redirect_path(atf::fs::path("stdout")),
107 atf::process::stream_redirect_path(atf::fs::path("stderr")),
109 const atf::process::status s
= c
.wait();
110 ATF_REQUIRE(s
.exited());