comparison DEPENDENCIES/generic/include/boost/test/exception_safety.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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: 49312 $
11 //
12 // Description : Facilities to perform exception safety tests
13 // ***************************************************************************
14
15 #ifndef BOOST_TEST_EXCEPTION_SAFETY_HPP_111705GER
16 #define BOOST_TEST_EXCEPTION_SAFETY_HPP_111705GER
17
18 // Boost.Test
19 #include <boost/test/detail/config.hpp>
20
21 #include <boost/test/utils/callback.hpp>
22 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
23
24 // STL
25 #include <memory>
26
27 #include <boost/test/detail/suppress_warnings.hpp>
28
29 //____________________________________________________________________________//
30
31 // ************************************************************************** //
32 // ************** BOOST_TEST_EXCEPTION_SAFETY ************** //
33 // ************************************************************************** //
34
35 #define BOOST_TEST_EXCEPTION_SAFETY( test_name ) \
36 struct test_name : public BOOST_AUTO_TEST_CASE_FIXTURE \
37 { void test_method(); }; \
38 \
39 static void BOOST_AUTO_TC_INVOKER( test_name )() \
40 { \
41 test_name t; \
42 ::boost::itest::exception_safety( \
43 boost::bind( &test_name::test_method, t ), \
44 BOOST_STRINGIZE(test_name) ); \
45 } \
46 \
47 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
48 \
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() ); \
54 \
55 void test_name::test_method() \
56 /**/
57
58 namespace boost {
59
60 namespace itest {
61
62 // ************************************************************************** //
63 // ************** exception safety test ************** //
64 // ************************************************************************** //
65
66 void BOOST_TEST_DECL exception_safety( unit_test::callback0<> const& F,
67 unit_test::const_string test_name = "" );
68
69 } // namespace itest
70
71 } // namespace boost
72
73 // ************************************************************************** //
74 // ************** global operator new/delete overloads ************** //
75 // ************************************************************************** //
76
77 #ifndef BOOST_ITEST_NO_NEW_OVERLOADS
78
79 #include <boost/test/interaction_based.hpp>
80
81 # ifdef BOOST_NO_STDC_NAMESPACE
82 namespace std { using ::isprint; using ::malloc; using ::free; }
83 # endif
84
85 inline void*
86 operator new( std::size_t s ) throw(std::bad_alloc)
87 {
88 void* res = std::malloc(s ? s : 1);
89
90 if( res )
91 ::boost::itest::manager::instance().allocated( 0, 0, res, s );
92 else
93 throw std::bad_alloc();
94
95 return res;
96 }
97
98 //____________________________________________________________________________//
99
100 inline void*
101 operator new( std::size_t s, std::nothrow_t const& ) throw()
102 {
103 void* res = std::malloc(s ? s : 1);
104
105 if( res )
106 ::boost::itest::manager::instance().allocated( 0, 0, res, s );
107
108 return res;
109 }
110
111 //____________________________________________________________________________//
112
113 inline void*
114 operator new[]( std::size_t s ) throw(std::bad_alloc)
115 {
116 void* res = std::malloc(s ? s : 1);
117
118 if( res )
119 ::boost::itest::manager::instance().allocated( 0, 0, res, s );
120 else
121 throw std::bad_alloc();
122
123 return res;
124 }
125
126 //____________________________________________________________________________//
127
128 inline void*
129 operator new[]( std::size_t s, std::nothrow_t const& ) throw()
130 {
131 void* res = std::malloc(s ? s : 1);
132
133 if( res )
134 ::boost::itest::manager::instance().allocated( 0, 0, res, s );
135
136 return res;
137 }
138
139 //____________________________________________________________________________//
140
141 inline void
142 operator delete( void* p ) throw()
143 {
144 ::boost::itest::manager::instance().freed( p );
145
146 std::free( p );
147 }
148
149 //____________________________________________________________________________//
150
151 inline void
152 operator delete( void* p, std::nothrow_t const& ) throw()
153 {
154 ::boost::itest::manager::instance().freed( p );
155
156 std::free( p );
157 }
158
159 //____________________________________________________________________________//
160
161 inline void
162 operator delete[]( void* p ) throw()
163 {
164 ::boost::itest::manager::instance().freed( p );
165
166 std::free( p );
167 }
168
169 //____________________________________________________________________________//
170
171 inline void
172 operator delete[]( void* p, std::nothrow_t const& ) throw()
173 {
174 ::boost::itest::manager::instance().freed( p );
175
176 std::free( p );
177 }
178
179 //____________________________________________________________________________//
180
181 #endif // BOOST_ITEST_NO_NEW_OVERLOADS
182
183 //____________________________________________________________________________//
184
185 #include <boost/test/detail/enable_warnings.hpp>
186
187 #endif // BOOST_TEST_EXCEPTION_SAFETY_HPP_111705GER