1 // make_shared_esft_test.cpp
3 // Copyright 2007-2009 Peter Dimov
5 // Distributed under the Boost Software License, Version 1.0.
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/make_shared.hpp>
11 #include <boost/shared_ptr.hpp>
12 #include <boost/enable_shared_from_this.hpp>
14 class X: public boost::enable_shared_from_this<X>
19 X & operator=( X const & );
25 explicit X( int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0 )
40 BOOST_TEST( X::instances == 0 );
43 boost::shared_ptr< X > px = boost::make_shared< X >();
44 BOOST_TEST( X::instances == 1 );
48 boost::shared_ptr< X > qx = px->shared_from_this();
50 BOOST_TEST( px == qx );
51 BOOST_TEST( !( px < qx ) && !( qx < px ) );
54 BOOST_TEST( X::instances == 1 );
56 catch( boost::bad_weak_ptr const& )
58 BOOST_ERROR( "px->shared_from_this() failed" );
62 BOOST_TEST( X::instances == 0 );
65 boost::shared_ptr< X > px = boost::make_shared< X >( 1 );
66 BOOST_TEST( X::instances == 1 );
70 boost::shared_ptr< X > qx = px->shared_from_this();
72 BOOST_TEST( px == qx );
73 BOOST_TEST( !( px < qx ) && !( qx < px ) );
76 BOOST_TEST( X::instances == 1 );
78 catch( boost::bad_weak_ptr const& )
80 BOOST_ERROR( "px->shared_from_this() failed" );
84 BOOST_TEST( X::instances == 0 );
87 boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2 );
88 BOOST_TEST( X::instances == 1 );
92 boost::shared_ptr< X > qx = px->shared_from_this();
94 BOOST_TEST( px == qx );
95 BOOST_TEST( !( px < qx ) && !( qx < px ) );
98 BOOST_TEST( X::instances == 1 );
100 catch( boost::bad_weak_ptr const& )
102 BOOST_ERROR( "px->shared_from_this() failed" );
106 BOOST_TEST( X::instances == 0 );
109 boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3 );
110 BOOST_TEST( X::instances == 1 );
114 boost::shared_ptr< X > qx = px->shared_from_this();
116 BOOST_TEST( px == qx );
117 BOOST_TEST( !( px < qx ) && !( qx < px ) );
120 BOOST_TEST( X::instances == 1 );
122 catch( boost::bad_weak_ptr const& )
124 BOOST_ERROR( "px->shared_from_this() failed" );
128 BOOST_TEST( X::instances == 0 );
131 boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4 );
132 BOOST_TEST( X::instances == 1 );
136 boost::shared_ptr< X > qx = px->shared_from_this();
138 BOOST_TEST( px == qx );
139 BOOST_TEST( !( px < qx ) && !( qx < px ) );
142 BOOST_TEST( X::instances == 1 );
144 catch( boost::bad_weak_ptr const& )
146 BOOST_ERROR( "px->shared_from_this() failed" );
150 BOOST_TEST( X::instances == 0 );
153 boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5 );
154 BOOST_TEST( X::instances == 1 );
158 boost::shared_ptr< X > qx = px->shared_from_this();
160 BOOST_TEST( px == qx );
161 BOOST_TEST( !( px < qx ) && !( qx < px ) );
164 BOOST_TEST( X::instances == 1 );
166 catch( boost::bad_weak_ptr const& )
168 BOOST_ERROR( "px->shared_from_this() failed" );
172 BOOST_TEST( X::instances == 0 );
175 boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5, 6 );
176 BOOST_TEST( X::instances == 1 );
180 boost::shared_ptr< X > qx = px->shared_from_this();
182 BOOST_TEST( px == qx );
183 BOOST_TEST( !( px < qx ) && !( qx < px ) );
186 BOOST_TEST( X::instances == 1 );
188 catch( boost::bad_weak_ptr const& )
190 BOOST_ERROR( "px->shared_from_this() failed" );
194 BOOST_TEST( X::instances == 0 );
197 boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7 );
198 BOOST_TEST( X::instances == 1 );
202 boost::shared_ptr< X > qx = px->shared_from_this();
204 BOOST_TEST( px == qx );
205 BOOST_TEST( !( px < qx ) && !( qx < px ) );
208 BOOST_TEST( X::instances == 1 );
210 catch( boost::bad_weak_ptr const& )
212 BOOST_ERROR( "px->shared_from_this() failed" );
216 BOOST_TEST( X::instances == 0 );
219 boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8 );
220 BOOST_TEST( X::instances == 1 );
224 boost::shared_ptr< X > qx = px->shared_from_this();
226 BOOST_TEST( px == qx );
227 BOOST_TEST( !( px < qx ) && !( qx < px ) );
230 BOOST_TEST( X::instances == 1 );
232 catch( boost::bad_weak_ptr const& )
234 BOOST_ERROR( "px->shared_from_this() failed" );
238 BOOST_TEST( X::instances == 0 );
241 boost::shared_ptr< X > px = boost::make_shared< X >( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
242 BOOST_TEST( X::instances == 1 );
246 boost::shared_ptr< X > qx = px->shared_from_this();
248 BOOST_TEST( px == qx );
249 BOOST_TEST( !( px < qx ) && !( qx < px ) );
252 BOOST_TEST( X::instances == 1 );
254 catch( boost::bad_weak_ptr const& )
256 BOOST_ERROR( "px->shared_from_this() failed" );
260 BOOST_TEST( X::instances == 0 );
262 return boost::report_errors();