1240116Smarcel// Copyright (c) 2007 The NetBSD Foundation, Inc.
2240116Smarcel// All rights reserved.
3240116Smarcel//
4240116Smarcel// Redistribution and use in source and binary forms, with or without
5240116Smarcel// modification, are permitted provided that the following conditions
6240116Smarcel// are met:
7240116Smarcel// 1. Redistributions of source code must retain the above copyright
8240116Smarcel//    notice, this list of conditions and the following disclaimer.
9240116Smarcel// 2. Redistributions in binary form must reproduce the above copyright
10240116Smarcel//    notice, this list of conditions and the following disclaimer in the
11240116Smarcel//    documentation and/or other materials provided with the distribution.
12240116Smarcel//
13240116Smarcel// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14240116Smarcel// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15240116Smarcel// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16240116Smarcel// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17240116Smarcel// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18240116Smarcel// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19240116Smarcel// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20240116Smarcel// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21240116Smarcel// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22240116Smarcel// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23240116Smarcel// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24240116Smarcel// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25240116Smarcel
26273929Sjmmv#if !defined(ATF_CXX_CHECK_HPP)
27273929Sjmmv#define ATF_CXX_CHECK_HPP
28240116Smarcel
29240116Smarcelextern "C" {
30240116Smarcel#include <atf-c/check.h>
31240116Smarcel}
32240116Smarcel
33240116Smarcel#include <cstddef>
34240116Smarcel#include <memory>
35240116Smarcel#include <string>
36240116Smarcel#include <vector>
37240116Smarcel
38240116Smarcelnamespace atf {
39240116Smarcel
40240116Smarcelnamespace process {
41240116Smarcelclass argv_array;
42240116Smarcel} // namespace process
43240116Smarcel
44240116Smarcelnamespace check {
45240116Smarcel
46240116Smarcel// ------------------------------------------------------------------------
47240116Smarcel// The "check_result" class.
48240116Smarcel// ------------------------------------------------------------------------
49240116Smarcel
50240116Smarcel//!
51240116Smarcel//! \brief A class that contains results of executed command.
52240116Smarcel//!
53240116Smarcel//! The check_result class holds information about results
54240116Smarcel//! of executing arbitrary command and manages files containing
55240116Smarcel//! its output.
56240116Smarcel//!
57261897Sjmmvclass check_result {
58261897Sjmmv    // Non-copyable.
59261897Sjmmv    check_result(const check_result&);
60261897Sjmmv    check_result& operator=(const check_result&);
61261897Sjmmv
62240116Smarcel    //!
63240116Smarcel    //! \brief Internal representation of a result.
64240116Smarcel    //!
65240116Smarcel    atf_check_result_t m_result;
66240116Smarcel
67240116Smarcel    //!
68240116Smarcel    //! \brief Constructs a results object and grabs ownership of the
69240116Smarcel    //! parameter passed in.
70240116Smarcel    //!
71240116Smarcel    check_result(const atf_check_result_t* result);
72240116Smarcel
73240116Smarcel    friend check_result test_constructor(const char* const*);
74240116Smarcel    friend std::auto_ptr< check_result > exec(const atf::process::argv_array&);
75240116Smarcel
76240116Smarcelpublic:
77240116Smarcel    //!
78240116Smarcel    //! \brief Destroys object and removes all managed files.
79240116Smarcel    //!
80240116Smarcel    ~check_result(void);
81240116Smarcel
82240116Smarcel    //!
83240116Smarcel    //! \brief Returns whether the command exited correctly or not.
84240116Smarcel    //!
85240116Smarcel    bool exited(void) const;
86240116Smarcel
87240116Smarcel    //!
88240116Smarcel    //! \brief Returns command's exit status.
89240116Smarcel    //!
90240116Smarcel    int exitcode(void) const;
91240116Smarcel
92240116Smarcel    //!
93240116Smarcel    //! \brief Returns whether the command received a signal or not.
94240116Smarcel    //!
95240116Smarcel    bool signaled(void) const;
96240116Smarcel
97240116Smarcel    //!
98240116Smarcel    //! \brief Returns the signal that terminated the command.
99240116Smarcel    //!
100240116Smarcel    int termsig(void) const;
101240116Smarcel
102240116Smarcel    //!
103240116Smarcel    //! \brief Returns the path to file contaning command's stdout.
104240116Smarcel    //!
105240116Smarcel    const std::string stdout_path(void) const;
106240116Smarcel
107240116Smarcel    //!
108240116Smarcel    //! \brief Returns the path to file contaning command's stderr.
109240116Smarcel    //!
110240116Smarcel    const std::string stderr_path(void) const;
111240116Smarcel};
112240116Smarcel
113240116Smarcel// ------------------------------------------------------------------------
114240116Smarcel// Free functions.
115240116Smarcel// ------------------------------------------------------------------------
116240116Smarcel
117240116Smarcelbool build_c_o(const std::string&, const std::string&,
118240116Smarcel               const atf::process::argv_array&);
119240116Smarcelbool build_cpp(const std::string&, const std::string&,
120240116Smarcel               const atf::process::argv_array&);
121240116Smarcelbool build_cxx_o(const std::string&, const std::string&,
122240116Smarcel                 const atf::process::argv_array&);
123240116Smarcelstd::auto_ptr< check_result > exec(const atf::process::argv_array&);
124240116Smarcel
125240116Smarcel// Useful for testing only.
126240116Smarcelcheck_result test_constructor(void);
127240116Smarcel
128240116Smarcel} // namespace check
129240116Smarcel} // namespace atf
130240116Smarcel
131273929Sjmmv#endif // !defined(ATF_CXX_CHECK_HPP)
132