sl@0: // (C) Copyright Gennadiy Rozental 2005. sl@0: // Distributed under the Boost Software License, Version 1.0. sl@0: // (See accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // See http://www.boost.org/libs/test for the library home page. sl@0: // sl@0: // File : $RCSfile: exception_safety.hpp,v $ sl@0: // sl@0: // Version : $Revision: 1.4 $ sl@0: // sl@0: // Description : Facilities to perform exception safety tests sl@0: // *************************************************************************** sl@0: sl@0: #ifndef BOOST_TEST_EXCEPTION_SAFETY_HPP_111705GER sl@0: #define BOOST_TEST_EXCEPTION_SAFETY_HPP_111705GER sl@0: sl@0: // Boost.Test sl@0: #include sl@0: sl@0: #include sl@0: sl@0: // STL sl@0: #include sl@0: sl@0: #include sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: // ************************************************************************** // sl@0: // ************** BOOST_TEST_EXCEPTION_SAFETY ************** // sl@0: // ************************************************************************** // sl@0: sl@0: #define BOOST_TEST_EXCEPTION_SAFETY( test_name ) \ sl@0: struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \ sl@0: { void test_method(); }; \ sl@0: \ sl@0: static void BOOST_AUTO_TC_INVOKER( test_name )() \ sl@0: { \ sl@0: test_name t; \ sl@0: ::boost::itest::exception_safety( \ sl@0: boost::bind( &test_name::test_method, t ), \ sl@0: BOOST_STRINGIZE(test_name) ); \ sl@0: } \ sl@0: \ sl@0: struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \ sl@0: \ sl@0: BOOST_AUTO_TC_REGISTRAR( test_name )( \ sl@0: boost::unit_test::make_test_case( \ sl@0: &BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \ sl@0: boost::unit_test::ut_detail::auto_tc_exp_fail< \ sl@0: BOOST_AUTO_TC_UNIQUE_ID( test_name )>::value ); \ sl@0: \ sl@0: void test_name::test_method() \ sl@0: /**/ sl@0: sl@0: namespace boost { sl@0: sl@0: namespace itest { sl@0: sl@0: // ************************************************************************** // sl@0: // ************** exception safety test ************** // sl@0: // ************************************************************************** // sl@0: sl@0: void BOOST_TEST_DECL exception_safety( unit_test::callback0<> const& F, sl@0: unit_test::const_string test_name = "" ); sl@0: sl@0: } // namespace itest sl@0: sl@0: } // namespace boost sl@0: sl@0: // ************************************************************************** // sl@0: // ************** global operator new/delete overloads ************** // sl@0: // ************************************************************************** // sl@0: sl@0: #ifndef BOOST_ITEST_NO_NEW_OVERLOADS sl@0: sl@0: #include sl@0: sl@0: # ifdef BOOST_NO_STDC_NAMESPACE sl@0: namespace std { using ::isprint; using ::malloc; using ::free; } sl@0: # endif sl@0: sl@0: inline void* sl@0: operator new( std::size_t s ) throw(std::bad_alloc) sl@0: { sl@0: void* res = std::malloc(s ? s : 1); sl@0: sl@0: if( res ) sl@0: ::boost::itest::manager::instance().allocated( 0, 0, res, s ); sl@0: else sl@0: throw std::bad_alloc(); sl@0: sl@0: return res; sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: inline void* sl@0: operator new( std::size_t s, std::nothrow_t const& ) throw() sl@0: { sl@0: void* res = std::malloc(s ? s : 1); sl@0: sl@0: if( res ) sl@0: ::boost::itest::manager::instance().allocated( 0, 0, res, s ); sl@0: sl@0: return res; sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: inline void* sl@0: operator new[]( std::size_t s ) throw(std::bad_alloc) sl@0: { sl@0: void* res = std::malloc(s ? s : 1); sl@0: sl@0: if( res ) sl@0: ::boost::itest::manager::instance().allocated( 0, 0, res, s ); sl@0: else sl@0: throw std::bad_alloc(); sl@0: sl@0: return res; sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: inline void* sl@0: operator new[]( std::size_t s, std::nothrow_t const& ) throw() sl@0: { sl@0: void* res = std::malloc(s ? s : 1); sl@0: sl@0: if( res ) sl@0: ::boost::itest::manager::instance().allocated( 0, 0, res, s ); sl@0: sl@0: return res; sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: inline void sl@0: operator delete( void* p ) throw() sl@0: { sl@0: ::boost::itest::manager::instance().freed( p ); sl@0: sl@0: std::free( p ); sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: inline void sl@0: operator delete( void* p, std::nothrow_t const& ) throw() sl@0: { sl@0: ::boost::itest::manager::instance().freed( p ); sl@0: sl@0: std::free( p ); sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: inline void sl@0: operator delete[]( void* p ) throw() sl@0: { sl@0: ::boost::itest::manager::instance().freed( p ); sl@0: sl@0: std::free( p ); sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: inline void sl@0: operator delete[]( void* p, std::nothrow_t const& ) throw() sl@0: { sl@0: ::boost::itest::manager::instance().freed( p ); sl@0: sl@0: std::free( p ); sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #endif // BOOST_ITEST_NO_NEW_OVERLOADS sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #include sl@0: sl@0: // *************************************************************************** sl@0: // Revision History : sl@0: // sl@0: // $Log: exception_safety.hpp,v $ sl@0: // Revision 1.4 2006/01/28 08:52:35 rogeeff sl@0: // operator new overloads made inline to: sl@0: // 1. prevent issues with export them from DLL sl@0: // 2. release link issue fixed sl@0: // sl@0: // Revision 1.3 2006/01/15 11:14:38 rogeeff sl@0: // simpl_mock -> mock_object<>::prototype() sl@0: // operator new need to be rethinked sl@0: // sl@0: // Revision 1.2 2005/12/20 23:50:13 rogeeff sl@0: // unit_test.hpp removed sl@0: // sl@0: // Revision 1.1 2005/12/14 05:03:46 rogeeff sl@0: // exception safety automatic testing facilties sl@0: // sl@0: // *************************************************************************** sl@0: sl@0: #endif // BOOST_TEST_EXCEPTION_SAFETY_HPP_111705GER