1 // Copyright (c) 2007 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 #include "atf-c++/check.hpp"
31 #include "atf-c/build.h"
32 #include "atf-c/error.h"
35 #include "atf-c++/detail/exceptions.hpp"
36 #include "atf-c++/detail/process.hpp"
37 #include "atf-c++/detail/sanity.hpp"
39 namespace impl = atf::check;
40 #define IMPL_NAME "atf::check"
42 // ------------------------------------------------------------------------
43 // The "check_result" class.
44 // ------------------------------------------------------------------------
46 impl::check_result::check_result(const atf_check_result_t* result)
48 std::memcpy(&m_result, result, sizeof(m_result));
51 impl::check_result::~check_result(void)
53 atf_check_result_fini(&m_result);
57 impl::check_result::exited(void)
60 return atf_check_result_exited(&m_result);
64 impl::check_result::exitcode(void)
68 return atf_check_result_exitcode(&m_result);
72 impl::check_result::signaled(void)
75 return atf_check_result_signaled(&m_result);
79 impl::check_result::termsig(void)
83 return atf_check_result_termsig(&m_result);
87 impl::check_result::stdout_path(void) const
89 return atf_check_result_stdout(&m_result);
93 impl::check_result::stderr_path(void) const
95 return atf_check_result_stderr(&m_result);
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
103 impl::build_c_o(const std::string& sfile, const std::string& ofile,
104 const atf::process::argv_array& optargs)
108 atf_error_t err = atf_check_build_c_o(sfile.c_str(), ofile.c_str(),
109 optargs.exec_argv(), &success);
110 if (atf_is_error(err))
111 throw_atf_error(err);
117 impl::build_cpp(const std::string& sfile, const std::string& ofile,
118 const atf::process::argv_array& optargs)
122 atf_error_t err = atf_check_build_cpp(sfile.c_str(), ofile.c_str(),
123 optargs.exec_argv(), &success);
124 if (atf_is_error(err))
125 throw_atf_error(err);
131 impl::build_cxx_o(const std::string& sfile, const std::string& ofile,
132 const atf::process::argv_array& optargs)
136 atf_error_t err = atf_check_build_cxx_o(sfile.c_str(), ofile.c_str(),
137 optargs.exec_argv(), &success);
138 if (atf_is_error(err))
139 throw_atf_error(err);
144 std::auto_ptr< impl::check_result >
145 impl::exec(const atf::process::argv_array& argva)
147 atf_check_result_t result;
149 atf_error_t err = atf_check_exec_array(argva.exec_argv(), &result);
150 if (atf_is_error(err))
151 throw_atf_error(err);
153 return std::auto_ptr< impl::check_result >(new impl::check_result(&result));