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