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()9int main() 10 { 11 { 12 boost::shared_ptr<int> p1( new int ); 13 boost::shared_ptr<int> p2( p1 ); 14 15 BOOST_TEST( !p1.owner_before( p2 ) ); 16 BOOST_TEST( !p2.owner_before( p1 ) ); 17 18 boost::shared_ptr<int> p3( new int ); 19 20 BOOST_TEST( p1.owner_before( p3 ) || p3.owner_before( p1 ) ); 21 22 boost::shared_ptr<int> p4; 23 boost::shared_ptr<int> p5; 24 25 BOOST_TEST( !p4.owner_before( p5 ) ); 26 BOOST_TEST( !p5.owner_before( p4 ) ); 27 28 BOOST_TEST( p4.owner_before( p3 ) || p3.owner_before( p4 ) ); 29 30 boost::shared_ptr<int> p6( static_cast<int*>(0) ); 31 32 BOOST_TEST( p4.owner_before( p6 ) || p6.owner_before( p4 ) ); 33 34 boost::shared_ptr<void> p7( p1 ); 35 36 BOOST_TEST( !p1.owner_before( p7 ) ); 37 BOOST_TEST( !p7.owner_before( p1 ) ); 38 39 boost::shared_ptr<void> p8; 40 41 BOOST_TEST( p1.owner_before( p8 ) || p8.owner_before( p1 ) ); 42 43 BOOST_TEST( !p4.owner_before( p8 ) ); 44 BOOST_TEST( !p8.owner_before( p4 ) ); 45 46 boost::weak_ptr<int> q1( p1 ); 47 48 BOOST_TEST( !p1.owner_before( q1 ) ); 49 BOOST_TEST( !q1.owner_before( p1 ) ); 50 51 boost::weak_ptr<int> q2( p1 ); 52 53 BOOST_TEST( !q1.owner_before( q2 ) ); 54 BOOST_TEST( !q2.owner_before( q1 ) ); 55 56 boost::weak_ptr<int> q3( p3 ); 57 58 BOOST_TEST( p1.owner_before( q3 ) || q3.owner_before( p1 ) ); 59 BOOST_TEST( q1.owner_before( q3 ) || q3.owner_before( q1 ) ); 60 61 boost::weak_ptr<int> q4; 62 63 BOOST_TEST( !p4.owner_before( q4 ) ); 64 BOOST_TEST( !q4.owner_before( p4 ) ); 65 66 BOOST_TEST( q1.owner_before( q4 ) || q4.owner_before( q1 ) ); 67 68 boost::weak_ptr<void> q5; 69 70 BOOST_TEST( !q4.owner_before( q5 ) ); 71 BOOST_TEST( !q5.owner_before( q4 ) ); 72 73 boost::weak_ptr<void> q7( p7 ); 74 75 BOOST_TEST( !p1.owner_before( q7 ) ); 76 BOOST_TEST( !q7.owner_before( p1 ) ); 77 78 BOOST_TEST( !q1.owner_before( q7 ) ); 79 BOOST_TEST( !q7.owner_before( q1 ) ); 80 81 p1.reset(); 82 p2.reset(); 83 p3.reset(); 84 p7.reset(); 85 86 BOOST_TEST( q1.expired() ); 87 BOOST_TEST( q2.expired() ); 88 BOOST_TEST( q3.expired() ); 89 BOOST_TEST( q7.expired() ); 90 91 BOOST_TEST( !q1.owner_before( q2 ) ); 92 BOOST_TEST( !q2.owner_before( q1 ) ); 93 94 BOOST_TEST( !q1.owner_before( q7 ) ); 95 BOOST_TEST( !q7.owner_before( q1 ) ); 96 97 BOOST_TEST( q1.owner_before( q3 ) || q3.owner_before( q1 ) ); 98 99 BOOST_TEST( q1.owner_before( q4 ) || q4.owner_before( q1 ) ); 100 } 101 102 return boost::report_errors(); 103 } 104