111be35a1SLionel Sambuc //
211be35a1SLionel Sambuc // Automated Testing Framework (atf)
311be35a1SLionel Sambuc //
411be35a1SLionel Sambuc // Copyright (c) 2009 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc // All rights reserved.
611be35a1SLionel Sambuc //
711be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
811be35a1SLionel Sambuc // modification, are permitted provided that the following conditions
911be35a1SLionel Sambuc // are met:
1011be35a1SLionel Sambuc // 1. Redistributions of source code must retain the above copyright
1111be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer.
1211be35a1SLionel Sambuc // 2. Redistributions in binary form must reproduce the above copyright
1311be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer in the
1411be35a1SLionel Sambuc // documentation and/or other materials provided with the distribution.
1511be35a1SLionel Sambuc //
1611be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1711be35a1SLionel Sambuc // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1811be35a1SLionel Sambuc // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1911be35a1SLionel Sambuc // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2011be35a1SLionel Sambuc // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2111be35a1SLionel Sambuc // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2211be35a1SLionel Sambuc // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2311be35a1SLionel Sambuc // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2411be35a1SLionel Sambuc // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2511be35a1SLionel Sambuc // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2611be35a1SLionel Sambuc // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2711be35a1SLionel Sambuc // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2811be35a1SLionel Sambuc //
2911be35a1SLionel Sambuc
3011be35a1SLionel Sambuc #if defined(TESTS_ATF_ATF_CXX_TEST_HELPERS_H)
3111be35a1SLionel Sambuc # error "Cannot include test_helpers.hpp more than once."
3211be35a1SLionel Sambuc #else
3311be35a1SLionel Sambuc # define TESTS_ATF_ATF_CXX_TEST_HELPERS_H
3411be35a1SLionel Sambuc #endif
3511be35a1SLionel Sambuc
3611be35a1SLionel Sambuc #include <cstdlib>
3711be35a1SLionel Sambuc #include <iostream>
3811be35a1SLionel Sambuc #include <sstream>
3911be35a1SLionel Sambuc #include <utility>
4011be35a1SLionel Sambuc
4111be35a1SLionel Sambuc #include "../macros.hpp"
4211be35a1SLionel Sambuc #include "../tests.hpp"
4311be35a1SLionel Sambuc #include "process.hpp"
4411be35a1SLionel Sambuc
4511be35a1SLionel Sambuc #define HEADER_TC(name, hdrname) \
4611be35a1SLionel Sambuc ATF_TEST_CASE(name); \
4711be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(name) \
4811be35a1SLionel Sambuc { \
4911be35a1SLionel Sambuc set_md_var("descr", "Tests that the " hdrname " file can be " \
5011be35a1SLionel Sambuc "included on its own, without any prerequisites"); \
5111be35a1SLionel Sambuc } \
5211be35a1SLionel Sambuc ATF_TEST_CASE_BODY(name) \
5311be35a1SLionel Sambuc { \
5411be35a1SLionel Sambuc header_check(hdrname); \
5511be35a1SLionel Sambuc }
5611be35a1SLionel Sambuc
5711be35a1SLionel Sambuc #define BUILD_TC(name, sfile, descr, failmsg) \
5811be35a1SLionel Sambuc ATF_TEST_CASE(name); \
5911be35a1SLionel Sambuc ATF_TEST_CASE_HEAD(name) \
6011be35a1SLionel Sambuc { \
6111be35a1SLionel Sambuc set_md_var("descr", descr); \
6211be35a1SLionel Sambuc } \
6311be35a1SLionel Sambuc ATF_TEST_CASE_BODY(name) \
6411be35a1SLionel Sambuc { \
65*0a6a1f1dSLionel Sambuc if (!build_check_cxx_o_srcdir(*this, sfile)) \
66*0a6a1f1dSLionel Sambuc ATF_FAIL(failmsg); \
6711be35a1SLionel Sambuc }
6811be35a1SLionel Sambuc
6911be35a1SLionel Sambuc namespace atf {
7011be35a1SLionel Sambuc namespace tests {
7111be35a1SLionel Sambuc class tc;
7211be35a1SLionel Sambuc }
7311be35a1SLionel Sambuc }
7411be35a1SLionel Sambuc
7511be35a1SLionel Sambuc void header_check(const char*);
76*0a6a1f1dSLionel Sambuc bool build_check_cxx_o(const char*);
77*0a6a1f1dSLionel Sambuc bool build_check_cxx_o_srcdir(const atf::tests::tc&, const char*);
78*0a6a1f1dSLionel Sambuc atf::fs::path get_process_helpers_path(const atf::tests::tc&, bool);
7911be35a1SLionel Sambuc
8011be35a1SLionel Sambuc struct run_h_tc_data {
8111be35a1SLionel Sambuc const atf::tests::vars_map& m_config;
8211be35a1SLionel Sambuc
run_h_tc_datarun_h_tc_data8311be35a1SLionel Sambuc run_h_tc_data(const atf::tests::vars_map& config) :
8411be35a1SLionel Sambuc m_config(config) {}
8511be35a1SLionel Sambuc };
8611be35a1SLionel Sambuc
8711be35a1SLionel Sambuc template< class TestCase >
8811be35a1SLionel Sambuc void
run_h_tc_child(void * v)8911be35a1SLionel Sambuc run_h_tc_child(void* v)
9011be35a1SLionel Sambuc {
9111be35a1SLionel Sambuc run_h_tc_data* data = static_cast< run_h_tc_data* >(v);
9211be35a1SLionel Sambuc
9311be35a1SLionel Sambuc TestCase tc;
9411be35a1SLionel Sambuc tc.init(data->m_config);
9511be35a1SLionel Sambuc tc.run("result");
9611be35a1SLionel Sambuc std::exit(EXIT_SUCCESS);
9711be35a1SLionel Sambuc }
9811be35a1SLionel Sambuc
9911be35a1SLionel Sambuc template< class TestCase >
10011be35a1SLionel Sambuc void
run_h_tc(atf::tests::vars_map config=atf::tests::vars_map ())10111be35a1SLionel Sambuc run_h_tc(atf::tests::vars_map config = atf::tests::vars_map())
10211be35a1SLionel Sambuc {
10311be35a1SLionel Sambuc run_h_tc_data data(config);
10411be35a1SLionel Sambuc atf::process::child c = atf::process::fork(
10511be35a1SLionel Sambuc run_h_tc_child< TestCase >,
10611be35a1SLionel Sambuc atf::process::stream_redirect_path(atf::fs::path("stdout")),
10711be35a1SLionel Sambuc atf::process::stream_redirect_path(atf::fs::path("stderr")),
10811be35a1SLionel Sambuc &data);
10911be35a1SLionel Sambuc const atf::process::status s = c.wait();
11011be35a1SLionel Sambuc ATF_REQUIRE(s.exited());
11111be35a1SLionel Sambuc }
112