tests.hpp revision 260029
1//
2// Automated Testing Framework (atf)
3//
4// Copyright (c) 2007 The NetBSD Foundation, Inc.
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10// 1. Redistributions of source code must retain the above copyright
11//    notice, this list of conditions and the following disclaimer.
12// 2. Redistributions in binary form must reproduce the above copyright
13//    notice, this list of conditions and the following disclaimer in the
14//    documentation and/or other materials provided with the distribution.
15//
16// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
30#if !defined(_ATF_CXX_TESTS_HPP_)
31#define _ATF_CXX_TESTS_HPP_
32
33#include <map>
34#include <memory>
35#include <string>
36
37extern "C" {
38#include <atf-c/defs.h>
39}
40
41#include <atf-c++/noncopyable.hpp>
42
43namespace atf {
44namespace tests {
45
46namespace detail {
47
48class atf_tp_writer {
49    std::ostream& m_os;
50
51    bool m_is_first;
52
53public:
54    atf_tp_writer(std::ostream&);
55
56    void start_tc(const std::string&);
57    void end_tc(void);
58    void tc_meta_data(const std::string&, const std::string&);
59};
60
61bool match(const std::string&, const std::string&);
62
63} // namespace
64
65// ------------------------------------------------------------------------
66// The "vars_map" class.
67// ------------------------------------------------------------------------
68
69typedef std::map< std::string, std::string > vars_map;
70
71// ------------------------------------------------------------------------
72// The "tc" class.
73// ------------------------------------------------------------------------
74
75struct tc_impl;
76
77class tc : noncopyable {
78    std::auto_ptr< tc_impl > pimpl;
79
80protected:
81    virtual void head(void);
82    virtual void body(void) const = 0;
83    virtual void cleanup(void) const;
84
85    void require_prog(const std::string&) const;
86
87    friend struct tc_impl;
88
89public:
90    tc(const std::string&, const bool);
91    virtual ~tc(void);
92
93    void init(const vars_map&);
94
95    const std::string get_config_var(const std::string&) const;
96    const std::string get_config_var(const std::string&, const std::string&)
97        const;
98    const std::string get_md_var(const std::string&) const;
99    const vars_map get_md_vars(void) const;
100    bool has_config_var(const std::string&) const;
101    bool has_md_var(const std::string&) const;
102    void set_md_var(const std::string&, const std::string&);
103
104    void run(const std::string&) const;
105    void run_cleanup(void) const;
106
107    // To be called from the child process only.
108    static void pass(void) ATF_DEFS_ATTRIBUTE_NORETURN;
109    static void fail(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
110    static void fail_nonfatal(const std::string&);
111    static void skip(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
112    static void check_errno(const char*, const int, const int, const char*,
113                            const bool);
114    static void require_errno(const char*, const int, const int, const char*,
115                              const bool);
116    static void expect_pass(void);
117    static void expect_fail(const std::string&);
118    static void expect_exit(const int, const std::string&);
119    static void expect_signal(const int, const std::string&);
120    static void expect_death(const std::string&);
121    static void expect_timeout(const std::string&);
122};
123
124} // namespace tests
125} // namespace atf
126
127#endif // !defined(_ATF_CXX_TESTS_HPP_)
128