• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 Peter Dimov
2 // Distributed under the Boost Software License, Version 1.0.
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #include <boost/shared_ptr.hpp>
6 #include <boost/weak_ptr.hpp>
7 #include <boost/core/lightweight_test.hpp>
8 
main()9 int main()
10 {
11     {
12         boost::shared_ptr<int> p1( new int );
13         boost::shared_ptr<int> p2( p1 );
14 
15         BOOST_TEST( p1.owner_equals( p2 ) );
16         BOOST_TEST( p2.owner_equals( p1 ) );
17 
18         boost::shared_ptr<int> p3( new int );
19 
20         BOOST_TEST( !p1.owner_equals( p3 ) );
21         BOOST_TEST( !p3.owner_equals( p1 ) );
22 
23         boost::shared_ptr<int> p4;
24         boost::shared_ptr<int> p5;
25 
26         BOOST_TEST( p4.owner_equals( p5 ) );
27         BOOST_TEST( p5.owner_equals( p4 ) );
28 
29         BOOST_TEST( !p4.owner_equals( p3 ) );
30         BOOST_TEST( !p3.owner_equals( p4 ) );
31 
32         boost::shared_ptr<int> p6( static_cast<int*>(0) );
33 
34         BOOST_TEST( !p4.owner_equals( p6 ) );
35         BOOST_TEST( !p6.owner_equals( p4 ) );
36 
37         boost::shared_ptr<void> p7( p1 );
38 
39         BOOST_TEST( p1.owner_equals( p7 ) );
40         BOOST_TEST( p7.owner_equals( p1 ) );
41 
42         boost::shared_ptr<void> p8;
43 
44         BOOST_TEST( !p1.owner_equals( p8 ) );
45         BOOST_TEST( !p8.owner_equals( p1 ) );
46 
47         BOOST_TEST( p4.owner_equals( p8 ) );
48         BOOST_TEST( p8.owner_equals( p4 ) );
49 
50         boost::weak_ptr<int> q1( p1 );
51 
52         BOOST_TEST( p1.owner_equals( q1 ) );
53         BOOST_TEST( q1.owner_equals( p1 ) );
54 
55         boost::weak_ptr<int> q2( p1 );
56 
57         BOOST_TEST( q1.owner_equals( q2 ) );
58         BOOST_TEST( q2.owner_equals( q1 ) );
59 
60         boost::weak_ptr<int> q3( p3 );
61 
62         BOOST_TEST( !p1.owner_equals( q3 ) );
63         BOOST_TEST( !q3.owner_equals( p1 ) );
64 
65         BOOST_TEST( !q1.owner_equals( q3 ) );
66         BOOST_TEST( !q3.owner_equals( q1 ) );
67 
68         boost::weak_ptr<int> q4;
69 
70         BOOST_TEST( p4.owner_equals( q4 ) );
71         BOOST_TEST( q4.owner_equals( p4 ) );
72 
73         BOOST_TEST( !q1.owner_equals( q4 ) );
74         BOOST_TEST( !q4.owner_equals( q1 ) );
75 
76         boost::weak_ptr<void> q5;
77 
78         BOOST_TEST( q4.owner_equals( q5 ) );
79         BOOST_TEST( q5.owner_equals( q4 ) );
80 
81         boost::weak_ptr<void> q7( p7 );
82 
83         BOOST_TEST( p1.owner_equals( q7 ) );
84         BOOST_TEST( q7.owner_equals( p1 ) );
85 
86         BOOST_TEST( q1.owner_equals( q7 ) );
87         BOOST_TEST( q7.owner_equals( q1 ) );
88 
89         p1.reset();
90         p2.reset();
91         p3.reset();
92         p7.reset();
93 
94         BOOST_TEST( q1.expired() );
95         BOOST_TEST( q2.expired() );
96         BOOST_TEST( q3.expired() );
97         BOOST_TEST( q7.expired() );
98 
99         BOOST_TEST( q1.owner_equals( q2 ) );
100         BOOST_TEST( q2.owner_equals( q1 ) );
101 
102         BOOST_TEST( q1.owner_equals( q7 ) );
103         BOOST_TEST( q7.owner_equals( q1 ) );
104 
105         BOOST_TEST( !q1.owner_equals( q3 ) );
106         BOOST_TEST( !q3.owner_equals( q1 ) );
107 
108         BOOST_TEST( !q1.owner_equals( q4 ) );
109         BOOST_TEST( !q4.owner_equals( q1 ) );
110     }
111 
112     return boost::report_errors();
113 }
114