1 | // |
---|---|
2 | // esft_second_ptr_test.cpp |
3 | // |
4 | // This test has been extracted from a real |
5 | // scenario that occurs in Boost.Python |
6 | // |
7 | // Copyright 2009 Peter Dimov |
8 | // |
9 | // Distributed under the Boost Software License, Version 1.0. |
10 | // See accompanying file LICENSE_1_0.txt or copy at |
11 | // http://www.boost.org/LICENSE_1_0.txt |
12 | // |
13 | |
14 | |
15 | #include <boost/enable_shared_from_this.hpp> |
16 | #include <boost/shared_ptr.hpp> |
17 | #include <boost/core/lightweight_test.hpp> |
18 | |
19 | // |
20 | |
21 | class X: public boost::enable_shared_from_this<X> |
22 | { |
23 | }; |
24 | |
25 | void null_deleter( void const* ) |
26 | { |
27 | } |
28 | |
29 | int main() |
30 | { |
31 | boost::shared_ptr<X> px( new X ); |
32 | |
33 | { |
34 | boost::shared_ptr<X> px2( px.get(), null_deleter ); |
35 | BOOST_TEST( px == px2 ); |
36 | } |
37 | |
38 | try |
39 | { |
40 | boost::shared_ptr< X > qx = px->shared_from_this(); |
41 | |
42 | BOOST_TEST( px == qx ); |
43 | BOOST_TEST( !( px < qx ) && !( qx < px ) ); |
44 | } |
45 | catch( boost::bad_weak_ptr const& ) |
46 | { |
47 | BOOST_ERROR( "px->shared_from_this() failed"); |
48 | } |
49 | |
50 | return boost::report_errors(); |
51 | } |
52 |