Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / atf-c++ / tests.hpp @ 14

History | View | Annotate | Download (4.12 KB)

1 13 up20180614
//
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
37
extern "C" {
38
#include <atf-c/defs.h>
39
}
40
41
namespace atf {
42
namespace tests {
43
44
namespace detail {
45
46
class atf_tp_writer {
47
    std::ostream& m_os;
48
49
    bool m_is_first;
50
51
public:
52
    atf_tp_writer(std::ostream&);
53
54
    void start_tc(const std::string&);
55
    void end_tc(void);
56
    void tc_meta_data(const std::string&, const std::string&);
57
};
58
59
bool match(const std::string&, const std::string&);
60
61
} // namespace
62
63
// ------------------------------------------------------------------------
64
// The "vars_map" class.
65
// ------------------------------------------------------------------------
66
67
typedef std::map< std::string, std::string > vars_map;
68
69
// ------------------------------------------------------------------------
70
// The "tc" class.
71
// ------------------------------------------------------------------------
72
73
struct tc_impl;
74
75
class tc {
76
    // Non-copyable.
77
    tc(const tc&);
78
    tc& operator=(const tc&);
79
80
    std::auto_ptr< tc_impl > pimpl;
81
82
protected:
83
    virtual void head(void);
84
    virtual void body(void) const = 0;
85
    virtual void cleanup(void) const;
86
87
    void require_prog(const std::string&) const;
88
89
    friend struct tc_impl;
90
91
public:
92
    tc(const std::string&, const bool);
93
    virtual ~tc(void);
94
95
    void init(const vars_map&);
96
97
    const std::string get_config_var(const std::string&) const;
98
    const std::string get_config_var(const std::string&, const std::string&)
99
        const;
100
    const std::string get_md_var(const std::string&) const;
101
    const vars_map get_md_vars(void) const;
102
    bool has_config_var(const std::string&) const;
103
    bool has_md_var(const std::string&) const;
104
    void set_md_var(const std::string&, const std::string&);
105
106
    void run(const std::string&) const;
107
    void run_cleanup(void) const;
108
109
    // To be called from the child process only.
110
    static void pass(void) ATF_DEFS_ATTRIBUTE_NORETURN;
111
    static void fail(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
112
    static void fail_nonfatal(const std::string&);
113
    static void skip(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
114
    static void check_errno(const char*, const int, const int, const char*,
115
                            const bool);
116
    static void require_errno(const char*, const int, const int, const char*,
117
                              const bool);
118
    static void expect_pass(void);
119
    static void expect_fail(const std::string&);
120
    static void expect_exit(const int, const std::string&);
121
    static void expect_signal(const int, const std::string&);
122
    static void expect_death(const std::string&);
123
    static void expect_timeout(const std::string&);
124
};
125
126
} // namespace tests
127
} // namespace atf
128
129
#endif // !defined(_ATF_CXX_TESTS_HPP_)