summaryrefslogtreecommitdiff
path: root/libs/smart_ptr/test
diff options
context:
space:
mode:
Diffstat (limited to 'libs/smart_ptr/test')
-rw-r--r--libs/smart_ptr/test/Jamfile.v28
-rw-r--r--libs/smart_ptr/test/array_fail_array_access.cpp6
-rw-r--r--libs/smart_ptr/test/sp_explicit_inst_test.cpp23
-rw-r--r--libs/smart_ptr/test/weak_from_raw_test.cpp3
-rw-r--r--libs/smart_ptr/test/weak_from_raw_test3.cpp46
-rw-r--r--libs/smart_ptr/test/weak_from_raw_test4.cpp67
-rw-r--r--libs/smart_ptr/test/weak_from_raw_test5.cpp45
-rw-r--r--libs/smart_ptr/test/weak_from_this_test.cpp52
-rw-r--r--libs/smart_ptr/test/weak_from_this_test2.cpp60
9 files changed, 307 insertions, 3 deletions
diff --git a/libs/smart_ptr/test/Jamfile.v2 b/libs/smart_ptr/test/Jamfile.v2
index 027367ced..b17e55f19 100644
--- a/libs/smart_ptr/test/Jamfile.v2
+++ b/libs/smart_ptr/test/Jamfile.v2
@@ -171,5 +171,13 @@ import testing ;
[ run weak_from_raw_test.cpp ]
[ run weak_from_raw_test2.cpp ]
+ [ run weak_from_raw_test3.cpp ]
+ [ run weak_from_raw_test4.cpp ]
+ [ run weak_from_raw_test5.cpp ]
+
+ [ compile sp_explicit_inst_test.cpp ]
+
+ [ run weak_from_this_test.cpp ]
+ [ run weak_from_this_test2.cpp ]
;
}
diff --git a/libs/smart_ptr/test/array_fail_array_access.cpp b/libs/smart_ptr/test/array_fail_array_access.cpp
index abfacbe38..4f4e3f8cb 100644
--- a/libs/smart_ptr/test/array_fail_array_access.cpp
+++ b/libs/smart_ptr/test/array_fail_array_access.cpp
@@ -12,8 +12,12 @@ struct X
{
};
+template<class T> void f( T & /*t*/ )
+{
+}
+
int main()
{
boost::shared_ptr<X> px( new X );
- px[ 0 ];
+ f( px[ 0 ] );
}
diff --git a/libs/smart_ptr/test/sp_explicit_inst_test.cpp b/libs/smart_ptr/test/sp_explicit_inst_test.cpp
new file mode 100644
index 000000000..d8de782ee
--- /dev/null
+++ b/libs/smart_ptr/test/sp_explicit_inst_test.cpp
@@ -0,0 +1,23 @@
+//
+// Explicit instantiations are reported to exist in user code
+//
+// Copyright (c) 2014 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+
+#include <boost/shared_ptr.hpp>
+
+template class boost::shared_ptr< int >;
+
+struct X
+{
+};
+
+template class boost::shared_ptr< X >;
+
+int main()
+{
+}
diff --git a/libs/smart_ptr/test/weak_from_raw_test.cpp b/libs/smart_ptr/test/weak_from_raw_test.cpp
index ba95ecc0f..34d21eb26 100644
--- a/libs/smart_ptr/test/weak_from_raw_test.cpp
+++ b/libs/smart_ptr/test/weak_from_raw_test.cpp
@@ -12,7 +12,6 @@
#include <boost/smart_ptr/enable_shared_from_raw.hpp>
-
#include <boost/detail/lightweight_test.hpp>
@@ -23,7 +22,7 @@ void basic_weak_from_raw_test()
{
X *p(new X);
boost::weak_ptr<X> weak = boost::weak_from_raw(p);
- BOOST_TEST(weak.expired());
+ BOOST_TEST(!weak.expired());
boost::shared_ptr<X> shared(p);
weak = boost::weak_from_raw(p);
BOOST_TEST(weak.expired() == false);
diff --git a/libs/smart_ptr/test/weak_from_raw_test3.cpp b/libs/smart_ptr/test/weak_from_raw_test3.cpp
new file mode 100644
index 000000000..ee73b4c88
--- /dev/null
+++ b/libs/smart_ptr/test/weak_from_raw_test3.cpp
@@ -0,0 +1,46 @@
+//
+// weak_from_raw_test3.cpp
+//
+// Test that weak_from_raw and shared_from_raw
+// return consistent values from a constructor
+//
+// Copyright (c) 2015 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+//
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+
+#include <boost/smart_ptr/enable_shared_from_raw.hpp>
+#include <boost/weak_ptr.hpp>
+#include <boost/core/lightweight_test.hpp>
+
+class X: public boost::enable_shared_from_raw
+{
+public:
+
+ X()
+ {
+ boost::weak_ptr<X> p1 = boost::weak_from_raw( this );
+ BOOST_TEST( !p1.expired() );
+
+ boost::weak_ptr<X> p2 = boost::weak_from_raw( this );
+ BOOST_TEST( !p2.expired() );
+ BOOST_TEST( !( p1 < p2 ) && !( p2 < p1 ) );
+
+ boost::weak_ptr<X> p3 = boost::shared_from_raw( this );
+ BOOST_TEST( !( p1 < p3 ) && !( p3 < p1 ) );
+
+ boost::weak_ptr<X> p4 = boost::weak_from_raw( this );
+ BOOST_TEST( !p4.expired() );
+ BOOST_TEST( !( p3 < p4 ) && !( p4 < p3 ) );
+ BOOST_TEST( !( p1 < p4 ) && !( p4 < p1 ) );
+ }
+};
+
+int main()
+{
+ boost::shared_ptr< X > px( new X );
+ return boost::report_errors();
+}
diff --git a/libs/smart_ptr/test/weak_from_raw_test4.cpp b/libs/smart_ptr/test/weak_from_raw_test4.cpp
new file mode 100644
index 000000000..2408f0092
--- /dev/null
+++ b/libs/smart_ptr/test/weak_from_raw_test4.cpp
@@ -0,0 +1,67 @@
+//
+// weak_from_raw_test4.cpp
+//
+// As weak_from_raw_test2.cpp, but uses weak_from_raw
+// in the constructor
+//
+// Copyright (c) 2014, 2015 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+//
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+
+#include <boost/smart_ptr/enable_shared_from_raw.hpp>
+#include <boost/weak_ptr.hpp>
+#include <boost/core/lightweight_test.hpp>
+
+class X;
+
+static boost::weak_ptr< X > r_;
+
+void register_( boost::weak_ptr< X > const & r )
+{
+ r_ = r;
+}
+
+void check_( boost::weak_ptr< X > const & r )
+{
+ BOOST_TEST( !( r < r_ ) && !( r_ < r ) );
+}
+
+void unregister_( boost::weak_ptr< X > const & r )
+{
+ BOOST_TEST( !( r < r_ ) && !( r_ < r ) );
+ r_.reset();
+}
+
+class X: public boost::enable_shared_from_raw
+{
+public:
+
+ X()
+ {
+ register_( boost::weak_from_raw( this ) );
+ }
+
+ ~X()
+ {
+ unregister_( boost::weak_from_raw( this ) );
+ }
+
+ void check()
+ {
+ check_( boost::weak_from_raw( this ) );
+ }
+};
+
+int main()
+{
+ {
+ boost::shared_ptr< X > px( new X );
+ px->check();
+ }
+
+ return boost::report_errors();
+}
diff --git a/libs/smart_ptr/test/weak_from_raw_test5.cpp b/libs/smart_ptr/test/weak_from_raw_test5.cpp
new file mode 100644
index 000000000..5425c27a4
--- /dev/null
+++ b/libs/smart_ptr/test/weak_from_raw_test5.cpp
@@ -0,0 +1,45 @@
+//
+// weak_from_raw_test5.cpp
+//
+// Tests whether pointers returned from weak_from_raw
+// expire properly
+//
+// Copyright 2015 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+//
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+
+#include <boost/smart_ptr/enable_shared_from_raw.hpp>
+#include <boost/weak_ptr.hpp>
+#include <boost/core/lightweight_test.hpp>
+
+class X: public boost::enable_shared_from_raw
+{
+public:
+
+ explicit X( boost::weak_ptr< X > & r )
+ {
+ r = boost::weak_from_raw( this );
+ }
+};
+
+int main()
+{
+ boost::weak_ptr<X> p1, p2;
+
+ {
+ boost::shared_ptr< X > px( new X( p1 ) );
+ p2 = boost::weak_from_raw( px.get() );
+
+ BOOST_TEST( !p1.expired() );
+ BOOST_TEST( !p2.expired() );
+ }
+
+ BOOST_TEST( p1.expired() );
+ BOOST_TEST( p2.expired() );
+
+ return boost::report_errors();
+}
diff --git a/libs/smart_ptr/test/weak_from_this_test.cpp b/libs/smart_ptr/test/weak_from_this_test.cpp
new file mode 100644
index 000000000..1a874e16f
--- /dev/null
+++ b/libs/smart_ptr/test/weak_from_this_test.cpp
@@ -0,0 +1,52 @@
+#include <boost/config.hpp>
+
+//
+// weak_from_this_test.cpp
+//
+// Copyright (c) 2002, 2003, 2015 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+//
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+
+
+#include <boost/enable_shared_from_this.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+class V: public boost::enable_shared_from_this<V>
+{
+};
+
+void test()
+{
+ boost::shared_ptr<V> p( new V );
+
+ boost::weak_ptr<V> q = p;
+ BOOST_TEST( !q.expired() );
+
+ boost::weak_ptr<V> q2 = p->weak_from_this();
+ BOOST_TEST( !q2.expired() );
+ BOOST_TEST( !(q < q2) && !(q2 < q) );
+
+ V v2( *p );
+
+ boost::weak_ptr<V> q3 = v2.weak_from_this();
+ BOOST_TEST( q3.expired() );
+
+ *p = V();
+
+ boost::weak_ptr<V> q4 = p->shared_from_this();
+ BOOST_TEST( !q4.expired() );
+ BOOST_TEST( !(q < q4) && !(q4 < q) );
+ BOOST_TEST( !(q2 < q4) && !(q4 < q2) );
+}
+
+int main()
+{
+ test();
+ return boost::report_errors();
+}
diff --git a/libs/smart_ptr/test/weak_from_this_test2.cpp b/libs/smart_ptr/test/weak_from_this_test2.cpp
new file mode 100644
index 000000000..05f3df2e6
--- /dev/null
+++ b/libs/smart_ptr/test/weak_from_this_test2.cpp
@@ -0,0 +1,60 @@
+//
+// weak_from_this_test2.cpp
+//
+// Tests weak_from_this in a destructor
+//
+// Copyright (c) 2014, 2015 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+//
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+
+#include <boost/smart_ptr/enable_shared_from_this.hpp>
+#include <boost/weak_ptr.hpp>
+#include <boost/core/lightweight_test.hpp>
+
+class X: public boost::enable_shared_from_this< X >
+{
+private:
+
+ boost::weak_ptr<X> px_;
+
+public:
+
+ X()
+ {
+ boost::weak_ptr<X> p1 = weak_from_this();
+ BOOST_TEST( p1._empty() );
+ BOOST_TEST( p1.expired() );
+ }
+
+ void check()
+ {
+ boost::weak_ptr<X> p2 = weak_from_this();
+ BOOST_TEST( !p2.expired() );
+
+ BOOST_TEST( p2.lock().get() == this );
+
+ px_ = p2;
+ }
+
+ ~X()
+ {
+ boost::weak_ptr<X> p3 = weak_from_this();
+ BOOST_TEST( p3.expired() );
+
+ BOOST_TEST( !(px_ < p3) && !(p3 < px_) );
+ }
+};
+
+int main()
+{
+ {
+ boost::shared_ptr< X > px( new X );
+ px->check();
+ }
+
+ return boost::report_errors();
+}