xref: /minix3/external/bsd/atf/dist/atf-c++/tests.hpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
111be35a1SLionel Sambuc //
211be35a1SLionel Sambuc // Automated Testing Framework (atf)
311be35a1SLionel Sambuc //
411be35a1SLionel Sambuc // Copyright (c) 2007 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc // All rights reserved.
611be35a1SLionel Sambuc //
711be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
811be35a1SLionel Sambuc // modification, are permitted provided that the following conditions
911be35a1SLionel Sambuc // are met:
1011be35a1SLionel Sambuc // 1. Redistributions of source code must retain the above copyright
1111be35a1SLionel Sambuc //    notice, this list of conditions and the following disclaimer.
1211be35a1SLionel Sambuc // 2. Redistributions in binary form must reproduce the above copyright
1311be35a1SLionel Sambuc //    notice, this list of conditions and the following disclaimer in the
1411be35a1SLionel Sambuc //    documentation and/or other materials provided with the distribution.
1511be35a1SLionel Sambuc //
1611be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1711be35a1SLionel Sambuc // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1811be35a1SLionel Sambuc // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1911be35a1SLionel Sambuc // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2011be35a1SLionel Sambuc // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2111be35a1SLionel Sambuc // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2211be35a1SLionel Sambuc // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2311be35a1SLionel Sambuc // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2411be35a1SLionel Sambuc // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2511be35a1SLionel Sambuc // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2611be35a1SLionel Sambuc // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2711be35a1SLionel Sambuc // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2811be35a1SLionel Sambuc //
2911be35a1SLionel Sambuc 
3011be35a1SLionel Sambuc #if !defined(_ATF_CXX_TESTS_HPP_)
3111be35a1SLionel Sambuc #define _ATF_CXX_TESTS_HPP_
3211be35a1SLionel Sambuc 
3311be35a1SLionel Sambuc #include <map>
3411be35a1SLionel Sambuc #include <memory>
3511be35a1SLionel Sambuc #include <string>
3611be35a1SLionel Sambuc 
3711be35a1SLionel Sambuc extern "C" {
3811be35a1SLionel Sambuc #include <atf-c/defs.h>
3911be35a1SLionel Sambuc }
4011be35a1SLionel Sambuc 
4111be35a1SLionel Sambuc namespace atf {
4211be35a1SLionel Sambuc namespace tests {
4311be35a1SLionel Sambuc 
4411be35a1SLionel Sambuc namespace detail {
4511be35a1SLionel Sambuc 
4611be35a1SLionel Sambuc class atf_tp_writer {
4711be35a1SLionel Sambuc     std::ostream& m_os;
4811be35a1SLionel Sambuc 
4911be35a1SLionel Sambuc     bool m_is_first;
5011be35a1SLionel Sambuc 
5111be35a1SLionel Sambuc public:
5211be35a1SLionel Sambuc     atf_tp_writer(std::ostream&);
5311be35a1SLionel Sambuc 
5411be35a1SLionel Sambuc     void start_tc(const std::string&);
5511be35a1SLionel Sambuc     void end_tc(void);
5611be35a1SLionel Sambuc     void tc_meta_data(const std::string&, const std::string&);
5711be35a1SLionel Sambuc };
5811be35a1SLionel Sambuc 
5911be35a1SLionel Sambuc bool match(const std::string&, const std::string&);
6011be35a1SLionel Sambuc 
6111be35a1SLionel Sambuc } // namespace
6211be35a1SLionel Sambuc 
6311be35a1SLionel Sambuc // ------------------------------------------------------------------------
6411be35a1SLionel Sambuc // The "vars_map" class.
6511be35a1SLionel Sambuc // ------------------------------------------------------------------------
6611be35a1SLionel Sambuc 
6711be35a1SLionel Sambuc typedef std::map< std::string, std::string > vars_map;
6811be35a1SLionel Sambuc 
6911be35a1SLionel Sambuc // ------------------------------------------------------------------------
7011be35a1SLionel Sambuc // The "tc" class.
7111be35a1SLionel Sambuc // ------------------------------------------------------------------------
7211be35a1SLionel Sambuc 
7311be35a1SLionel Sambuc struct tc_impl;
7411be35a1SLionel Sambuc 
75*0a6a1f1dSLionel Sambuc class tc {
76*0a6a1f1dSLionel Sambuc     // Non-copyable.
77*0a6a1f1dSLionel Sambuc     tc(const tc&);
78*0a6a1f1dSLionel Sambuc     tc& operator=(const tc&);
79*0a6a1f1dSLionel Sambuc 
8011be35a1SLionel Sambuc     std::auto_ptr< tc_impl > pimpl;
8111be35a1SLionel Sambuc 
8211be35a1SLionel Sambuc protected:
8311be35a1SLionel Sambuc     virtual void head(void);
8411be35a1SLionel Sambuc     virtual void body(void) const = 0;
8511be35a1SLionel Sambuc     virtual void cleanup(void) const;
8611be35a1SLionel Sambuc 
8711be35a1SLionel Sambuc     void require_prog(const std::string&) const;
8811be35a1SLionel Sambuc 
8911be35a1SLionel Sambuc     friend struct tc_impl;
9011be35a1SLionel Sambuc 
9111be35a1SLionel Sambuc public:
9211be35a1SLionel Sambuc     tc(const std::string&, const bool);
9311be35a1SLionel Sambuc     virtual ~tc(void);
9411be35a1SLionel Sambuc 
9511be35a1SLionel Sambuc     void init(const vars_map&);
9611be35a1SLionel Sambuc 
9711be35a1SLionel Sambuc     const std::string get_config_var(const std::string&) const;
9811be35a1SLionel Sambuc     const std::string get_config_var(const std::string&, const std::string&)
9911be35a1SLionel Sambuc         const;
10011be35a1SLionel Sambuc     const std::string get_md_var(const std::string&) const;
10111be35a1SLionel Sambuc     const vars_map get_md_vars(void) const;
10211be35a1SLionel Sambuc     bool has_config_var(const std::string&) const;
10311be35a1SLionel Sambuc     bool has_md_var(const std::string&) const;
10411be35a1SLionel Sambuc     void set_md_var(const std::string&, const std::string&);
10511be35a1SLionel Sambuc 
10611be35a1SLionel Sambuc     void run(const std::string&) const;
10711be35a1SLionel Sambuc     void run_cleanup(void) const;
10811be35a1SLionel Sambuc 
10911be35a1SLionel Sambuc     // To be called from the child process only.
11011be35a1SLionel Sambuc     static void pass(void) ATF_DEFS_ATTRIBUTE_NORETURN;
11111be35a1SLionel Sambuc     static void fail(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
11211be35a1SLionel Sambuc     static void fail_nonfatal(const std::string&);
11311be35a1SLionel Sambuc     static void skip(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN;
11411be35a1SLionel Sambuc     static void check_errno(const char*, const int, const int, const char*,
11511be35a1SLionel Sambuc                             const bool);
11611be35a1SLionel Sambuc     static void require_errno(const char*, const int, const int, const char*,
11711be35a1SLionel Sambuc                               const bool);
11811be35a1SLionel Sambuc     static void expect_pass(void);
11911be35a1SLionel Sambuc     static void expect_fail(const std::string&);
12011be35a1SLionel Sambuc     static void expect_exit(const int, const std::string&);
12111be35a1SLionel Sambuc     static void expect_signal(const int, const std::string&);
12211be35a1SLionel Sambuc     static void expect_death(const std::string&);
12311be35a1SLionel Sambuc     static void expect_timeout(const std::string&);
12411be35a1SLionel Sambuc };
12511be35a1SLionel Sambuc 
12611be35a1SLionel Sambuc } // namespace tests
12711be35a1SLionel Sambuc } // namespace atf
12811be35a1SLionel Sambuc 
12911be35a1SLionel Sambuc #endif // !defined(_ATF_CXX_TESTS_HPP_)
130