1 // (C) Copyright Gennadiy Rozental 2005-2008. 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 // See http://www.boost.org/libs/test for the library home page. 7 // 8 // File : $RCSfile$ 9 // 10 // Version : $Revision: 54633 $ 11 // 12 // Description : defines framework interface 13 // *************************************************************************** 14 15 #ifndef BOOST_TEST_FRAMEWORK_HPP_020805GER 16 #define BOOST_TEST_FRAMEWORK_HPP_020805GER 17 18 // Boost.Test 19 #include <boost/test/detail/global_typedef.hpp> 20 #include <boost/test/detail/fwd_decl.hpp> 21 #include <boost/test/utils/trivial_singleton.hpp> 22 23 #include <boost/test/detail/suppress_warnings.hpp> 24 25 // STL 26 #include <stdexcept> 27 28 //____________________________________________________________________________// 29 30 namespace boost { 31 32 namespace unit_test { 33 34 // ************************************************************************** // 35 // ************** init_unit_test_func ************** // 36 // ************************************************************************** // 37 38 #ifdef BOOST_TEST_ALTERNATIVE_INIT_API 39 typedef bool (*init_unit_test_func)(); 40 #else 41 typedef test_suite* (*init_unit_test_func)( int, char* [] ); 42 #endif 43 44 // ************************************************************************** // 45 // ************** framework ************** // 46 // ************************************************************************** // 47 48 namespace framework { 49 50 // initialization 51 BOOST_TEST_DECL void init( init_unit_test_func init_func, int argc, char* argv[] ); 52 BOOST_TEST_DECL bool is_initialized(); 53 54 // mutation access methods 55 BOOST_TEST_DECL void register_test_unit( test_case* tc ); 56 BOOST_TEST_DECL void register_test_unit( test_suite* ts ); 57 BOOST_TEST_DECL void deregister_test_unit( test_unit* tu ); 58 BOOST_TEST_DECL void clear(); 59 60 BOOST_TEST_DECL void register_observer( test_observer& ); 61 BOOST_TEST_DECL void deregister_observer( test_observer& ); 62 BOOST_TEST_DECL void reset_observers(); 63 64 BOOST_TEST_DECL master_test_suite_t& master_test_suite(); 65 66 // constant access methods 67 BOOST_TEST_DECL test_case const& current_test_case(); 68 69 BOOST_TEST_DECL test_unit& get( test_unit_id, test_unit_type ); 70 template<typename UnitType> 71 UnitType& get( test_unit_id id ) 72 { 73 return static_cast<UnitType&>( get( id, static_cast<test_unit_type>(UnitType::type) ) ); 74 } 75 76 // test initiation 77 BOOST_TEST_DECL void run( test_unit_id = INV_TEST_UNIT_ID, bool continue_test = true ); 78 BOOST_TEST_DECL void run( test_unit const*, bool continue_test = true ); 79 80 // public test events dispatchers 81 BOOST_TEST_DECL void assertion_result( bool passed ); 82 BOOST_TEST_DECL void exception_caught( execution_exception const& ); 83 BOOST_TEST_DECL void test_unit_aborted( test_unit const& ); 84 85 // ************************************************************************** // 86 // ************** framework errors ************** // 87 // ************************************************************************** // 88 89 struct internal_error : std::runtime_error { 90 internal_error( const_string m ) : std::runtime_error( std::string( m.begin(), m.size() ) ) {} 91 }; 92 93 struct setup_error : std::runtime_error { 94 setup_error( const_string m ) : std::runtime_error( std::string( m.begin(), m.size() ) ) {} 95 }; 96 97 #define BOOST_TEST_SETUP_ASSERT( cond, msg ) if( cond ) {} else throw unit_test::framework::setup_error( msg ) 98 99 struct nothing_to_test {}; // not really an error 100 101 } // namespace framework 102 103 } // unit_test 104 105 } // namespace boost 106 107 //____________________________________________________________________________// 108 109 #include <boost/test/detail/enable_warnings.hpp> 110 111 #endif // BOOST_TEST_FRAMEWORK_HPP_020805GER 112 113