framework.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision: 54633 $
  10. //
  11. // Description : defines framework interface
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_FRAMEWORK_HPP_020805GER
  14. #define BOOST_TEST_FRAMEWORK_HPP_020805GER
  15. // Boost.Test
  16. #include <boost/test/detail/global_typedef.hpp>
  17. #include <boost/test/detail/fwd_decl.hpp>
  18. #include <boost/test/utils/trivial_singleton.hpp>
  19. #include <boost/test/detail/suppress_warnings.hpp>
  20. // STL
  21. #include <stdexcept>
  22. //____________________________________________________________________________//
  23. namespace boost {
  24. namespace unit_test {
  25. // ************************************************************************** //
  26. // ************** init_unit_test_func ************** //
  27. // ************************************************************************** //
  28. #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
  29. typedef bool (*init_unit_test_func)();
  30. #else
  31. typedef test_suite* (*init_unit_test_func)( int, char* [] );
  32. #endif
  33. // ************************************************************************** //
  34. // ************** framework ************** //
  35. // ************************************************************************** //
  36. namespace framework {
  37. // initialization
  38. BOOST_TEST_DECL void init( init_unit_test_func init_func, int argc, char* argv[] );
  39. BOOST_TEST_DECL bool is_initialized();
  40. // mutation access methods
  41. BOOST_TEST_DECL void register_test_unit( test_case* tc );
  42. BOOST_TEST_DECL void register_test_unit( test_suite* ts );
  43. BOOST_TEST_DECL void deregister_test_unit( test_unit* tu );
  44. BOOST_TEST_DECL void clear();
  45. BOOST_TEST_DECL void register_observer( test_observer& );
  46. BOOST_TEST_DECL void deregister_observer( test_observer& );
  47. BOOST_TEST_DECL void reset_observers();
  48. BOOST_TEST_DECL master_test_suite_t& master_test_suite();
  49. // constant access methods
  50. BOOST_TEST_DECL test_case const& current_test_case();
  51. BOOST_TEST_DECL test_unit& get( test_unit_id, test_unit_type );
  52. template<typename UnitType>
  53. UnitType& get( test_unit_id id )
  54. {
  55. return static_cast<UnitType&>( get( id, static_cast<test_unit_type>(UnitType::type) ) );
  56. }
  57. // test initiation
  58. BOOST_TEST_DECL void run( test_unit_id = INV_TEST_UNIT_ID, bool continue_test = true );
  59. BOOST_TEST_DECL void run( test_unit const*, bool continue_test = true );
  60. // public test events dispatchers
  61. BOOST_TEST_DECL void assertion_result( bool passed );
  62. BOOST_TEST_DECL void exception_caught( execution_exception const& );
  63. BOOST_TEST_DECL void test_unit_aborted( test_unit const& );
  64. // ************************************************************************** //
  65. // ************** framework errors ************** //
  66. // ************************************************************************** //
  67. struct internal_error : std::runtime_error {
  68. internal_error( const_string m ) : std::runtime_error( std::string( m.begin(), m.size() ) ) {}
  69. };
  70. struct setup_error : std::runtime_error {
  71. setup_error( const_string m ) : std::runtime_error( std::string( m.begin(), m.size() ) ) {}
  72. };
  73. #define BOOST_TEST_SETUP_ASSERT( cond, msg ) if( cond ) {} else throw unit_test::framework::setup_error( msg )
  74. struct nothing_to_test {}; // not really an error
  75. } // namespace framework
  76. } // unit_test
  77. } // namespace boost
  78. //____________________________________________________________________________//
  79. #include <boost/test/detail/enable_warnings.hpp>
  80. #endif // BOOST_TEST_FRAMEWORK_HPP_020805GER