1240116Smarcel//
2240116Smarcel// Automated Testing Framework (atf)
3240116Smarcel//
4240116Smarcel// Copyright (c) 2007 The NetBSD Foundation, Inc.
5240116Smarcel// All rights reserved.
6240116Smarcel//
7240116Smarcel// Redistribution and use in source and binary forms, with or without
8240116Smarcel// modification, are permitted provided that the following conditions
9240116Smarcel// are met:
10240116Smarcel// 1. Redistributions of source code must retain the above copyright
11240116Smarcel//    notice, this list of conditions and the following disclaimer.
12240116Smarcel// 2. Redistributions in binary form must reproduce the above copyright
13240116Smarcel//    notice, this list of conditions and the following disclaimer in the
14240116Smarcel//    documentation and/or other materials provided with the distribution.
15240116Smarcel//
16240116Smarcel// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17240116Smarcel// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18240116Smarcel// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19240116Smarcel// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20240116Smarcel// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21240116Smarcel// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22240116Smarcel// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23240116Smarcel// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24240116Smarcel// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25240116Smarcel// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26240116Smarcel// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27240116Smarcel// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28240116Smarcel//
29240116Smarcel
30240116Smarcel#if !defined(_ATF_CXX_TESTS_HPP_)
31240116Smarcel#define _ATF_CXX_TESTS_HPP_
32240116Smarcel
33240116Smarcel#include <map>
34240116Smarcel#include <memory>
35240116Smarcel#include <string>
36240116Smarcel
37240116Smarcelextern "C" {
38240116Smarcel#include <atf-c/defs.h>
39240116Smarcel}
40240116Smarcel
41240116Smarcelnamespace atf {
42240116Smarcelnamespace tests {
43240116Smarcel
44240116Smarcelnamespace detail {
45240116Smarcel
46240116Smarcelclass atf_tp_writer {
47240116Smarcel    std::ostream& m_os;
48240116Smarcel
49240116Smarcel    bool m_is_first;
50240116Smarcel
51240116Smarcelpublic:
52240116Smarcel    atf_tp_writer(std::ostream&);
53240116Smarcel
54240116Smarcel    void start_tc(const std::string&);
55240116Smarcel    void end_tc(void);
56240116Smarcel    void tc_meta_data(const std::string&, const std::string&);
57240116Smarcel};
58240116Smarcel
59240116Smarcelbool match(const std::string&, const std::string&);
60240116Smarcel
61240116Smarcel} // namespace
62240116Smarcel
63240116Smarcel// ------------------------------------------------------------------------
64240116Smarcel// The "vars_map" class.
65240116Smarcel// ------------------------------------------------------------------------
66240116Smarcel
67240116Smarceltypedef std::map< std::string, std::string > vars_map;
68240116Smarcel
69240116Smarcel// ------------------------------------------------------------------------
70240116Smarcel// The "tc" class.
71240116Smarcel// ------------------------------------------------------------------------
72240116Smarcel
73240116Smarcelstruct tc_impl;
74240116Smarcel
75262855Sjmmvclass tc {
76262855Sjmmv    // Non-copyable.
77262855Sjmmv    tc(const tc&);
78262855Sjmmv    tc& operator=(const tc&);
79262855Sjmmv
80240116Smarcel    std::auto_ptr< tc_impl > pimpl;
81240116Smarcel
82240116Smarcelprotected:
83240116Smarcel    virtual void head(void);
84240116Smarcel    virtual void body(void) const = 0;
85240116Smarcel    virtual void cleanup(void) const;
86240116Smarcel
87240116Smarcel    void require_prog(const std::string&) const;
88240116Smarcel
89240116Smarcel    friend struct tc_impl;
90240116Smarcel
91240116Smarcelpublic:
92240116Smarcel    tc(const std::string&, const bool);
93240116Smarcel    virtual ~tc(void);
94240116Smarcel
95240116Smarcel    void init(const vars_map&);
96240116Smarcel
97240116Smarcel    const std::string get_config_var(const std::string&) const;
98240116Smarcel    const std::string get_config_var(const std::string&, const std::string&)
99240116Smarcel        const;
100240116Smarcel    const std::string get_md_var(const std::string&) const;
101240116Smarcel    const vars_map get_md_vars(void) const;
102240116Smarcel    bool has_config_var(const std::string&) const;
103240116Smarcel    bool has_md_var(const std::string&) const;
104240116Smarcel    void set_md_var(const std::string&, const std::string&);
105240116Smarcel
106240116Smarcel    void run(const std::string&) const;
107240116Smarcel    void run_cleanup(void) const;
108240116Smarcel
109240116Smarcel    // To be called from the child process only.
110240116Smarcel    static void pass(void) ATF_DEFS_ATTRIBUTE_NORETURN;
111240116Smarcel    static void fail(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
112240116Smarcel    static void fail_nonfatal(const std::string&);
113240116Smarcel    static void skip(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
114240116Smarcel    static void check_errno(const char*, const int, const int, const char*,
115240116Smarcel                            const bool);
116240116Smarcel    static void require_errno(const char*, const int, const int, const char*,
117240116Smarcel                              const bool);
118240116Smarcel    static void expect_pass(void);
119240116Smarcel    static void expect_fail(const std::string&);
120240116Smarcel    static void expect_exit(const int, const std::string&);
121240116Smarcel    static void expect_signal(const int, const std::string&);
122240116Smarcel    static void expect_death(const std::string&);
123240116Smarcel    static void expect_timeout(const std::string&);
124240116Smarcel};
125240116Smarcel
126240116Smarcel} // namespace tests
127240116Smarcel} // namespace atf
128240116Smarcel
129240116Smarcel#endif // !defined(_ATF_CXX_TESTS_HPP_)
130