Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 15 | #ifndef NDNBOOST_TEST_FRAMEWORK_HPP_020805GER |
| 16 | #define NDNBOOST_TEST_FRAMEWORK_HPP_020805GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 17 | |
| 18 | // Boost.Test |
| 19 | #include <ndnboost/test/detail/global_typedef.hpp> |
| 20 | #include <ndnboost/test/detail/fwd_decl.hpp> |
| 21 | #include <ndnboost/test/utils/trivial_singleton.hpp> |
| 22 | |
| 23 | #include <ndnboost/test/detail/suppress_warnings.hpp> |
| 24 | |
| 25 | // STL |
| 26 | #include <stdexcept> |
| 27 | |
| 28 | //____________________________________________________________________________// |
| 29 | |
| 30 | namespace ndnboost { |
| 31 | |
| 32 | namespace unit_test { |
| 33 | |
| 34 | // ************************************************************************** // |
| 35 | // ************** init_unit_test_func ************** // |
| 36 | // ************************************************************************** // |
| 37 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 38 | #ifdef NDNBOOST_TEST_ALTERNATIVE_INIT_API |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 51 | NDNBOOST_TEST_DECL void init( init_unit_test_func init_func, int argc, char* argv[] ); |
| 52 | NDNBOOST_TEST_DECL bool is_initialized(); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 53 | |
| 54 | // mutation access methods |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 55 | NDNBOOST_TEST_DECL void register_test_unit( test_case* tc ); |
| 56 | NDNBOOST_TEST_DECL void register_test_unit( test_suite* ts ); |
| 57 | NDNBOOST_TEST_DECL void deregister_test_unit( test_unit* tu ); |
| 58 | NDNBOOST_TEST_DECL void clear(); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 59 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 60 | NDNBOOST_TEST_DECL void register_observer( test_observer& ); |
| 61 | NDNBOOST_TEST_DECL void deregister_observer( test_observer& ); |
| 62 | NDNBOOST_TEST_DECL void reset_observers(); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 63 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 64 | NDNBOOST_TEST_DECL master_test_suite_t& master_test_suite(); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 65 | |
| 66 | // constant access methods |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 67 | NDNBOOST_TEST_DECL test_case const& current_test_case(); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 68 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 69 | NDNBOOST_TEST_DECL test_unit& get( test_unit_id, test_unit_type ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 77 | NDNBOOST_TEST_DECL void run( test_unit_id = INV_TEST_UNIT_ID, bool continue_test = true ); |
| 78 | NDNBOOST_TEST_DECL void run( test_unit const*, bool continue_test = true ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 79 | |
| 80 | // public test events dispatchers |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 81 | NDNBOOST_TEST_DECL void assertion_result( bool passed ); |
| 82 | NDNBOOST_TEST_DECL void exception_caught( execution_exception const& ); |
| 83 | NDNBOOST_TEST_DECL void test_unit_aborted( test_unit const& ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 97 | #define NDNBOOST_TEST_SETUP_ASSERT( cond, msg ) if( cond ) {} else throw unit_test::framework::setup_error( msg ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 98 | |
| 99 | struct nothing_to_test {}; // not really an error |
| 100 | |
| 101 | } // namespace framework |
| 102 | |
| 103 | } // unit_test |
| 104 | |
| 105 | } // namespace ndnboost |
| 106 | |
| 107 | //____________________________________________________________________________// |
| 108 | |
| 109 | #include <ndnboost/test/detail/enable_warnings.hpp> |
| 110 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 111 | #endif // NDNBOOST_TEST_FRAMEWORK_HPP_020805GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 112 | |