]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/smart_ptr/test/allocate_shared_test.cpp
6ea5182903cadb5c7790942e0f982a70008365b1
1 // allocate_shared_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/core/lightweight_test.hpp>
10 #include <boost/make_shared.hpp>
11 #include <boost/shared_ptr.hpp>
12 #include <boost/weak_ptr.hpp>
20 X
& operator=( X
const & );
22 void * operator new( std::size_t n
)
24 // lack of this definition causes link errors on Comeau C++
25 BOOST_ERROR( "private X::new called" );
26 return ::operator new( n
);
29 void operator delete( void * p
)
31 // lack of this definition causes link errors on MSVC
32 BOOST_ERROR( "private X::delete called" );
33 ::operator delete( p
);
42 explicit X( int a1
= 0, int a2
= 0, int a3
= 0, int a4
= 0, int a5
= 0, int a6
= 0, int a7
= 0, int a8
= 0, int a9
= 0 ): v( a1
+a2
+a3
+a4
+a5
+a6
+a7
+a8
+a9
)
58 boost::shared_ptr
< int > pi
= boost::allocate_shared
< int >( std::allocator
<int>() );
60 BOOST_TEST( pi
.get() != 0 );
61 BOOST_TEST( *pi
== 0 );
65 boost::shared_ptr
< int > pi
= boost::allocate_shared_noinit
< int >( std::allocator
<int>() );
67 BOOST_TEST( pi
.get() != 0 );
71 boost::shared_ptr
< int > pi
= boost::allocate_shared
< int >( std::allocator
<int>(), 5 );
73 BOOST_TEST( pi
.get() != 0 );
74 BOOST_TEST( *pi
== 5 );
77 BOOST_TEST( X::instances
== 0 );
80 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>() );
81 boost::weak_ptr
<X
> wp( pi
);
83 BOOST_TEST( X::instances
== 1 );
84 BOOST_TEST( pi
.get() != 0 );
85 BOOST_TEST( pi
->v
== 0 );
89 BOOST_TEST( X::instances
== 0 );
93 boost::shared_ptr
< X
> pi
= boost::allocate_shared_noinit
< X
>( std::allocator
<void>() );
94 boost::weak_ptr
<X
> wp( pi
);
96 BOOST_TEST( X::instances
== 1 );
97 BOOST_TEST( pi
.get() != 0 );
98 BOOST_TEST( pi
->v
== 0 );
102 BOOST_TEST( X::instances
== 0 );
106 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>(), 1 );
107 boost::weak_ptr
<X
> wp( pi
);
109 BOOST_TEST( X::instances
== 1 );
110 BOOST_TEST( pi
.get() != 0 );
111 BOOST_TEST( pi
->v
== 1 );
115 BOOST_TEST( X::instances
== 0 );
119 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>(), 1, 2 );
120 boost::weak_ptr
<X
> wp( pi
);
122 BOOST_TEST( X::instances
== 1 );
123 BOOST_TEST( pi
.get() != 0 );
124 BOOST_TEST( pi
->v
== 1+2 );
128 BOOST_TEST( X::instances
== 0 );
132 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>(), 1, 2, 3 );
133 boost::weak_ptr
<X
> wp( pi
);
135 BOOST_TEST( X::instances
== 1 );
136 BOOST_TEST( pi
.get() != 0 );
137 BOOST_TEST( pi
->v
== 1+2+3 );
141 BOOST_TEST( X::instances
== 0 );
145 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>(), 1, 2, 3, 4 );
146 boost::weak_ptr
<X
> wp( pi
);
148 BOOST_TEST( X::instances
== 1 );
149 BOOST_TEST( pi
.get() != 0 );
150 BOOST_TEST( pi
->v
== 1+2+3+4 );
154 BOOST_TEST( X::instances
== 0 );
158 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>(), 1, 2, 3, 4, 5 );
159 boost::weak_ptr
<X
> wp( pi
);
161 BOOST_TEST( X::instances
== 1 );
162 BOOST_TEST( pi
.get() != 0 );
163 BOOST_TEST( pi
->v
== 1+2+3+4+5 );
167 BOOST_TEST( X::instances
== 0 );
171 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>(), 1, 2, 3, 4, 5, 6 );
172 boost::weak_ptr
<X
> wp( pi
);
174 BOOST_TEST( X::instances
== 1 );
175 BOOST_TEST( pi
.get() != 0 );
176 BOOST_TEST( pi
->v
== 1+2+3+4+5+6 );
180 BOOST_TEST( X::instances
== 0 );
184 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>(), 1, 2, 3, 4, 5, 6, 7 );
185 boost::weak_ptr
<X
> wp( pi
);
187 BOOST_TEST( X::instances
== 1 );
188 BOOST_TEST( pi
.get() != 0 );
189 BOOST_TEST( pi
->v
== 1+2+3+4+5+6+7 );
193 BOOST_TEST( X::instances
== 0 );
197 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>(), 1, 2, 3, 4, 5, 6, 7, 8 );
198 boost::weak_ptr
<X
> wp( pi
);
200 BOOST_TEST( X::instances
== 1 );
201 BOOST_TEST( pi
.get() != 0 );
202 BOOST_TEST( pi
->v
== 1+2+3+4+5+6+7+8 );
206 BOOST_TEST( X::instances
== 0 );
210 boost::shared_ptr
< X
> pi
= boost::allocate_shared
< X
>( std::allocator
<void>(), 1, 2, 3, 4, 5, 6, 7, 8, 9 );
211 boost::weak_ptr
<X
> wp( pi
);
213 BOOST_TEST( X::instances
== 1 );
214 BOOST_TEST( pi
.get() != 0 );
215 BOOST_TEST( pi
->v
== 1+2+3+4+5+6+7+8+9 );
219 BOOST_TEST( X::instances
== 0 );
222 return boost::report_errors();