1 // Copyright (c) 2007 The NetBSD Foundation, Inc. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions 6 // are met: 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. 12 // 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. 25 26 #if !defined(ATF_CXX_CHECK_HPP) 27 #define ATF_CXX_CHECK_HPP 28 29 extern "C" { 30 #include <atf-c/check.h> 31 } 32 33 #include <cstddef> 34 #include <memory> 35 #include <string> 36 #include <vector> 37 38 namespace atf { 39 40 namespace process { 41 class argv_array; 42 } // namespace process 43 44 namespace check { 45 46 // ------------------------------------------------------------------------ 47 // The "check_result" class. 48 // ------------------------------------------------------------------------ 49 50 //! 51 //! \brief A class that contains results of executed command. 52 //! 53 //! The check_result class holds information about results 54 //! of executing arbitrary command and manages files containing 55 //! its output. 56 //! 57 class check_result { 58 // Non-copyable. 59 check_result(const check_result&); 60 check_result& operator=(const check_result&); 61 62 //! 63 //! \brief Internal representation of a result. 64 //! 65 atf_check_result_t m_result; 66 67 //! 68 //! \brief Constructs a results object and grabs ownership of the 69 //! parameter passed in. 70 //! 71 check_result(const atf_check_result_t* result); 72 73 friend check_result test_constructor(const char* const*); 74 friend std::unique_ptr< check_result > 75 exec(const atf::process::argv_array&); 76 77 public: 78 //! 79 //! \brief Destroys object and removes all managed files. 80 //! 81 ~check_result(void); 82 83 //! 84 //! \brief Returns whether the command exited correctly or not. 85 //! 86 bool exited(void) const; 87 88 //! 89 //! \brief Returns command's exit status. 90 //! 91 int exitcode(void) const; 92 93 //! 94 //! \brief Returns whether the command received a signal or not. 95 //! 96 bool signaled(void) const; 97 98 //! 99 //! \brief Returns the signal that terminated the command. 100 //! 101 int termsig(void) const; 102 103 //! 104 //! \brief Returns the path to file contaning command's stdout. 105 //! 106 const std::string stdout_path(void) const; 107 108 //! 109 //! \brief Returns the path to file contaning command's stderr. 110 //! 111 const std::string stderr_path(void) const; 112 }; 113 114 // ------------------------------------------------------------------------ 115 // Free functions. 116 // ------------------------------------------------------------------------ 117 118 bool build_c_o(const std::string&, const std::string&, 119 const atf::process::argv_array&); 120 bool build_cpp(const std::string&, const std::string&, 121 const atf::process::argv_array&); 122 bool build_cxx_o(const std::string&, const std::string&, 123 const atf::process::argv_array&); 124 std::unique_ptr< check_result > exec(const atf::process::argv_array&); 125 126 // Useful for testing only. 127 check_result test_constructor(void); 128 129 } // namespace check 130 } // namespace atf 131 132 #endif // !defined(ATF_CXX_CHECK_HPP) 133