xref: /freebsd/contrib/atf/atf-c++/check.hpp (revision f3c5273d315a64826d2149ac453ff8c4583ddbe8)
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::auto_ptr< check_result > exec(const atf::process::argv_array&);
75 
76 public:
77     //!
78     //! \brief Destroys object and removes all managed files.
79     //!
80     ~check_result(void);
81 
82     //!
83     //! \brief Returns whether the command exited correctly or not.
84     //!
85     bool exited(void) const;
86 
87     //!
88     //! \brief Returns command's exit status.
89     //!
90     int exitcode(void) const;
91 
92     //!
93     //! \brief Returns whether the command received a signal or not.
94     //!
95     bool signaled(void) const;
96 
97     //!
98     //! \brief Returns the signal that terminated the command.
99     //!
100     int termsig(void) const;
101 
102     //!
103     //! \brief Returns the path to file contaning command's stdout.
104     //!
105     const std::string stdout_path(void) const;
106 
107     //!
108     //! \brief Returns the path to file contaning command's stderr.
109     //!
110     const std::string stderr_path(void) const;
111 };
112 
113 // ------------------------------------------------------------------------
114 // Free functions.
115 // ------------------------------------------------------------------------
116 
117 bool build_c_o(const std::string&, const std::string&,
118                const atf::process::argv_array&);
119 bool build_cpp(const std::string&, const std::string&,
120                const atf::process::argv_array&);
121 bool build_cxx_o(const std::string&, const std::string&,
122                  const atf::process::argv_array&);
123 std::auto_ptr< check_result > exec(const atf::process::argv_array&);
124 
125 // Useful for testing only.
126 check_result test_constructor(void);
127 
128 } // namespace check
129 } // namespace atf
130 
131 #endif // !defined(ATF_CXX_CHECK_HPP)
132