]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/make_local_shared_esft_test.cpp
1 // make_local_shared_esft_test.cpp
3 // Copyright 2007-2009, 2017 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/config.hpp>
11 #if defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) || defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES )
19 #include <boost/core/lightweight_test.hpp>
20 #include <boost/smart_ptr/make_local_shared.hpp>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/enable_shared_from_this.hpp>
24 class X
: public boost::enable_shared_from_this
<X
>
29 X
& operator=( X
const & );
35 explicit X( int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0, int = 0 )
50 BOOST_TEST( X::instances
== 0 );
53 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>();
54 BOOST_TEST( px
.use_count() == 1 );
55 BOOST_TEST( X::instances
== 1 );
59 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
61 BOOST_TEST( px
== qx
);
62 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
65 BOOST_TEST( X::instances
== 1 );
67 catch( boost::bad_weak_ptr
const& )
69 BOOST_ERROR( "px->shared_from_this() failed" );
73 BOOST_TEST( X::instances
== 0 );
76 boost::shared_ptr
< X
> px
= boost::make_local_shared_noinit
< X
>();
77 BOOST_TEST( px
.use_count() == 1 );
78 BOOST_TEST( X::instances
== 1 );
82 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
84 BOOST_TEST( px
== qx
);
85 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
88 BOOST_TEST( X::instances
== 1 );
90 catch( boost::bad_weak_ptr
const& )
92 BOOST_ERROR( "px->shared_from_this() failed" );
96 BOOST_TEST( X::instances
== 0 );
99 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>( 1 );
100 BOOST_TEST( px
.use_count() == 1 );
101 BOOST_TEST( X::instances
== 1 );
105 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
107 BOOST_TEST( px
== qx
);
108 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
111 BOOST_TEST( X::instances
== 1 );
113 catch( boost::bad_weak_ptr
const& )
115 BOOST_ERROR( "px->shared_from_this() failed" );
119 BOOST_TEST( X::instances
== 0 );
122 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>( 1, 2 );
123 BOOST_TEST( px
.use_count() == 1 );
124 BOOST_TEST( X::instances
== 1 );
128 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
130 BOOST_TEST( px
== qx
);
131 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
134 BOOST_TEST( X::instances
== 1 );
136 catch( boost::bad_weak_ptr
const& )
138 BOOST_ERROR( "px->shared_from_this() failed" );
142 BOOST_TEST( X::instances
== 0 );
145 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>( 1, 2, 3 );
146 BOOST_TEST( px
.use_count() == 1 );
147 BOOST_TEST( X::instances
== 1 );
151 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
153 BOOST_TEST( px
== qx
);
154 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
157 BOOST_TEST( X::instances
== 1 );
159 catch( boost::bad_weak_ptr
const& )
161 BOOST_ERROR( "px->shared_from_this() failed" );
165 BOOST_TEST( X::instances
== 0 );
168 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>( 1, 2, 3, 4 );
169 BOOST_TEST( px
.use_count() == 1 );
170 BOOST_TEST( X::instances
== 1 );
174 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
176 BOOST_TEST( px
== qx
);
177 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
180 BOOST_TEST( X::instances
== 1 );
182 catch( boost::bad_weak_ptr
const& )
184 BOOST_ERROR( "px->shared_from_this() failed" );
188 BOOST_TEST( X::instances
== 0 );
191 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>( 1, 2, 3, 4, 5 );
192 BOOST_TEST( px
.use_count() == 1 );
193 BOOST_TEST( X::instances
== 1 );
197 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
199 BOOST_TEST( px
== qx
);
200 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
203 BOOST_TEST( X::instances
== 1 );
205 catch( boost::bad_weak_ptr
const& )
207 BOOST_ERROR( "px->shared_from_this() failed" );
211 BOOST_TEST( X::instances
== 0 );
214 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>( 1, 2, 3, 4, 5, 6 );
215 BOOST_TEST( px
.use_count() == 1 );
216 BOOST_TEST( X::instances
== 1 );
220 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
222 BOOST_TEST( px
== qx
);
223 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
226 BOOST_TEST( X::instances
== 1 );
228 catch( boost::bad_weak_ptr
const& )
230 BOOST_ERROR( "px->shared_from_this() failed" );
234 BOOST_TEST( X::instances
== 0 );
237 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>( 1, 2, 3, 4, 5, 6, 7 );
238 BOOST_TEST( px
.use_count() == 1 );
239 BOOST_TEST( X::instances
== 1 );
243 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
245 BOOST_TEST( px
== qx
);
246 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
249 BOOST_TEST( X::instances
== 1 );
251 catch( boost::bad_weak_ptr
const& )
253 BOOST_ERROR( "px->shared_from_this() failed" );
257 BOOST_TEST( X::instances
== 0 );
260 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>( 1, 2, 3, 4, 5, 6, 7, 8 );
261 BOOST_TEST( px
.use_count() == 1 );
262 BOOST_TEST( X::instances
== 1 );
266 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
268 BOOST_TEST( px
== qx
);
269 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
272 BOOST_TEST( X::instances
== 1 );
274 catch( boost::bad_weak_ptr
const& )
276 BOOST_ERROR( "px->shared_from_this() failed" );
280 BOOST_TEST( X::instances
== 0 );
283 boost::shared_ptr
< X
> px
= boost::make_local_shared
< X
>( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
284 BOOST_TEST( px
.use_count() == 1 );
285 BOOST_TEST( X::instances
== 1 );
289 boost::shared_ptr
< X
> qx
= px
->shared_from_this();
291 BOOST_TEST( px
== qx
);
292 BOOST_TEST( !( px
< qx
) && !( qx
< px
) );
295 BOOST_TEST( X::instances
== 1 );
297 catch( boost::bad_weak_ptr
const& )
299 BOOST_ERROR( "px->shared_from_this() failed" );
303 BOOST_TEST( X::instances
== 0 );
305 return boost::report_errors();