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)
6
// See http://www.boost.org/libs/test for the library home page.
10
// Version : $Revision: 49312 $
12
// Description : Facilities to perform exception safety tests
13
// ***************************************************************************
15
#ifndef BOOST_TEST_EXCEPTION_SAFETY_HPP_111705GER
16
#define BOOST_TEST_EXCEPTION_SAFETY_HPP_111705GER
19
#include <boost/test/detail/config.hpp>
21
#include <boost/test/utils/callback.hpp>
22
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
27
#include <boost/test/detail/suppress_warnings.hpp>
29
//____________________________________________________________________________//
31
// ************************************************************************** //
32
// ************** BOOST_TEST_EXCEPTION_SAFETY ************** //
33
// ************************************************************************** //
35
#define BOOST_TEST_EXCEPTION_SAFETY( test_name ) \
36
struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \
37
{ void test_method(); }; \
39
static void BOOST_AUTO_TC_INVOKER( test_name )() \
42
::boost::itest::exception_safety( \
43
boost::bind( &test_name::test_method, t ), \
44
BOOST_STRINGIZE(test_name) ); \
47
struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
49
BOOST_AUTO_TU_REGISTRAR( test_name )( \
50
boost::unit_test::make_test_case( \
51
&BOOST_AUTO_TC_INVOKER( test_name ), #test_name ), \
52
boost::unit_test::ut_detail::auto_tc_exp_fail< \
53
BOOST_AUTO_TC_UNIQUE_ID( test_name )>::instance()->value() ); \
55
void test_name::test_method() \
62
// ************************************************************************** //
63
// ************** exception safety test ************** //
64
// ************************************************************************** //
66
void BOOST_TEST_DECL exception_safety( unit_test::callback0<> const& F,
67
unit_test::const_string test_name = "" );
73
// ************************************************************************** //
74
// ************** global operator new/delete overloads ************** //
75
// ************************************************************************** //
77
#ifndef BOOST_ITEST_NO_NEW_OVERLOADS
79
#include <boost/test/interaction_based.hpp>
81
# ifdef BOOST_NO_STDC_NAMESPACE
82
namespace std { using ::isprint; using ::malloc; using ::free; }
86
operator new( std::size_t s ) throw(std::bad_alloc)
88
void* res = std::malloc(s ? s : 1);
91
::boost::itest::manager::instance().allocated( 0, 0, res, s );
93
throw std::bad_alloc();
98
//____________________________________________________________________________//
101
operator new( std::size_t s, std::nothrow_t const& ) throw()
103
void* res = std::malloc(s ? s : 1);
106
::boost::itest::manager::instance().allocated( 0, 0, res, s );
111
//____________________________________________________________________________//
114
operator new[]( std::size_t s ) throw(std::bad_alloc)
116
void* res = std::malloc(s ? s : 1);
119
::boost::itest::manager::instance().allocated( 0, 0, res, s );
121
throw std::bad_alloc();
126
//____________________________________________________________________________//
129
operator new[]( std::size_t s, std::nothrow_t const& ) throw()
131
void* res = std::malloc(s ? s : 1);
134
::boost::itest::manager::instance().allocated( 0, 0, res, s );
139
//____________________________________________________________________________//
142
operator delete( void* p ) throw()
144
::boost::itest::manager::instance().freed( p );
149
//____________________________________________________________________________//
152
operator delete( void* p, std::nothrow_t const& ) throw()
154
::boost::itest::manager::instance().freed( p );
159
//____________________________________________________________________________//
162
operator delete[]( void* p ) throw()
164
::boost::itest::manager::instance().freed( p );
169
//____________________________________________________________________________//
172
operator delete[]( void* p, std::nothrow_t const& ) throw()
174
::boost::itest::manager::instance().freed( p );
179
//____________________________________________________________________________//
181
#endif // BOOST_ITEST_NO_NEW_OVERLOADS
183
//____________________________________________________________________________//
185
#include <boost/test/detail/enable_warnings.hpp>
187
#endif // BOOST_TEST_EXCEPTION_SAFETY_HPP_111705GER