tests.hpp revision 240116
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 41240116Smarcel#include <atf-c++/utils.hpp> 42240116Smarcel 43240116Smarcelnamespace atf { 44240116Smarcelnamespace tests { 45240116Smarcel 46240116Smarcelnamespace detail { 47240116Smarcel 48240116Smarcelclass atf_tp_writer { 49240116Smarcel std::ostream& m_os; 50240116Smarcel 51240116Smarcel bool m_is_first; 52240116Smarcel 53240116Smarcelpublic: 54240116Smarcel atf_tp_writer(std::ostream&); 55240116Smarcel 56240116Smarcel void start_tc(const std::string&); 57240116Smarcel void end_tc(void); 58240116Smarcel void tc_meta_data(const std::string&, const std::string&); 59240116Smarcel}; 60240116Smarcel 61240116Smarcelbool match(const std::string&, const std::string&); 62240116Smarcel 63240116Smarcel} // namespace 64240116Smarcel 65240116Smarcel// ------------------------------------------------------------------------ 66240116Smarcel// The "vars_map" class. 67240116Smarcel// ------------------------------------------------------------------------ 68240116Smarcel 69240116Smarceltypedef std::map< std::string, std::string > vars_map; 70240116Smarcel 71240116Smarcel// ------------------------------------------------------------------------ 72240116Smarcel// The "tc" class. 73240116Smarcel// ------------------------------------------------------------------------ 74240116Smarcel 75240116Smarcelstruct tc_impl; 76240116Smarcel 77240116Smarcelclass tc : utils::noncopyable { 78240116Smarcel std::auto_ptr< tc_impl > pimpl; 79240116Smarcel 80240116Smarcelprotected: 81240116Smarcel virtual void head(void); 82240116Smarcel virtual void body(void) const = 0; 83240116Smarcel virtual void cleanup(void) const; 84240116Smarcel 85240116Smarcel void require_prog(const std::string&) const; 86240116Smarcel 87240116Smarcel friend struct tc_impl; 88240116Smarcel 89240116Smarcelpublic: 90240116Smarcel tc(const std::string&, const bool); 91240116Smarcel virtual ~tc(void); 92240116Smarcel 93240116Smarcel void init(const vars_map&); 94240116Smarcel 95240116Smarcel const std::string get_config_var(const std::string&) const; 96240116Smarcel const std::string get_config_var(const std::string&, const std::string&) 97240116Smarcel const; 98240116Smarcel const std::string get_md_var(const std::string&) const; 99240116Smarcel const vars_map get_md_vars(void) const; 100240116Smarcel bool has_config_var(const std::string&) const; 101240116Smarcel bool has_md_var(const std::string&) const; 102240116Smarcel void set_md_var(const std::string&, const std::string&); 103240116Smarcel 104240116Smarcel void run(const std::string&) const; 105240116Smarcel void run_cleanup(void) const; 106240116Smarcel 107240116Smarcel // To be called from the child process only. 108240116Smarcel static void pass(void) ATF_DEFS_ATTRIBUTE_NORETURN; 109240116Smarcel static void fail(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN; 110240116Smarcel static void fail_nonfatal(const std::string&); 111240116Smarcel static void skip(const std::string&) ATF_DEFS_ATTRIBUTE_NORETURN; 112240116Smarcel static void check_errno(const char*, const int, const int, const char*, 113240116Smarcel const bool); 114240116Smarcel static void require_errno(const char*, const int, const int, const char*, 115240116Smarcel const bool); 116240116Smarcel static void expect_pass(void); 117240116Smarcel static void expect_fail(const std::string&); 118240116Smarcel static void expect_exit(const int, const std::string&); 119240116Smarcel static void expect_signal(const int, const std::string&); 120240116Smarcel static void expect_death(const std::string&); 121240116Smarcel static void expect_timeout(const std::string&); 122240116Smarcel}; 123240116Smarcel 124240116Smarcel} // namespace tests 125240116Smarcel} // namespace atf 126240116Smarcel 127240116Smarcel#endif // !defined(_ATF_CXX_TESTS_HPP_) 128