Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81338 - branches/release/libs/smart_ptr/test
From: pdimov_at_[hidden]
Date: 2012-11-14 08:36:44


Author: pdimov
Date: 2012-11-14 08:36:44 EST (Wed, 14 Nov 2012)
New Revision: 81338
URL: http://svn.boost.org/trac/boost/changeset/81338

Log:
Merge from 57197, 57206, 57423, 57518 did not apply to 'libs' for some reason; update.
Added:
   branches/release/libs/smart_ptr/test/enable_shared_from_raw_test.cpp (contents, props changed)
Text files modified:
   branches/release/libs/smart_ptr/test/Jamfile.v2 | 1 +
   branches/release/libs/smart_ptr/test/esft_constructor_test.cpp | 30 ++++++++++++++----------------
   2 files changed, 15 insertions(+), 16 deletions(-)

Modified: branches/release/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- branches/release/libs/smart_ptr/test/Jamfile.v2 (original)
+++ branches/release/libs/smart_ptr/test/Jamfile.v2 2012-11-14 08:36:44 EST (Wed, 14 Nov 2012)
@@ -60,6 +60,7 @@
           [ run sp_recursive_assign_rv_test.cpp ]
           [ run sp_recursive_assign2_rv_test.cpp ]
           [ run esft_constructor_test.cpp ]
+ [ run enable_shared_from_raw_test.cpp ]
           [ compile-fail auto_ptr_lv_fail.cpp ]
           [ run atomic_count_test2.cpp ]
           [ run sp_typeinfo_test.cpp ]

Added: branches/release/libs/smart_ptr/test/enable_shared_from_raw_test.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/smart_ptr/test/enable_shared_from_raw_test.cpp 2012-11-14 08:36:44 EST (Wed, 14 Nov 2012)
@@ -0,0 +1,39 @@
+#include <boost/config.hpp>
+
+//
+// weak_from_raw_test.cpp
+//
+// Copyright (c) 2009 Frank Mori Hess
+//
+// 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/detail/lightweight_test.hpp>
+
+
+struct X: public boost::enable_shared_from_raw
+{};
+
+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::shared_ptr<X> shared(p);
+ weak = boost::weak_from_raw(p);
+ BOOST_TEST(weak.expired() == false);
+ boost::shared_ptr<X> shared2(weak);
+ BOOST_TEST((shared < shared2 || shared2 < shared) == false);
+ BOOST_TEST(shared.get() == p);
+}
+
+int main()
+{
+ basic_weak_from_raw_test();
+ return boost::report_errors();
+}

Modified: branches/release/libs/smart_ptr/test/esft_constructor_test.cpp
==============================================================================
--- branches/release/libs/smart_ptr/test/esft_constructor_test.cpp (original)
+++ branches/release/libs/smart_ptr/test/esft_constructor_test.cpp 2012-11-14 08:36:44 EST (Wed, 14 Nov 2012)
@@ -13,14 +13,13 @@
 // 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_this2.hpp>
+#include <boost/smart_ptr/enable_shared_from_raw.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/weak_ptr.hpp>
 #include <boost/detail/lightweight_test.hpp>
 #include <memory>
 
-class X: public boost::enable_shared_from_this2< X >
+class X: public boost::enable_shared_from_raw
 {
 private:
 
@@ -42,7 +41,7 @@
     explicit X( int expected, boost::shared_ptr<X> *early_px = 0 ): destroyed_( 0 ), deleted_( 0 ), expected_( expected )
     {
         ++instances;
- if( early_px ) *early_px = shared_from_this();
+ if( early_px ) *early_px = shared_from_raw(this);
     }
 
     ~X()
@@ -75,7 +74,7 @@
     return !(a < b) && !(b < a);
 }
 
-struct Y: public boost::enable_shared_from_this2<Y>
+struct Y: public boost::enable_shared_from_raw
 {};
 
 int main()
@@ -87,14 +86,15 @@
         X* x = new X( 1, &early_px );
         BOOST_TEST( early_px.use_count() > 0 );
         BOOST_TEST( boost::get_deleter<X::deleter_type>(early_px) == 0 );
+ BOOST_TEST( early_px.get() == x );
         boost::shared_ptr<X> px( x, &X::deleter2 );
         BOOST_TEST( early_px.use_count() == 2 && px.use_count() == 2 );
         BOOST_TEST(are_shared_owners(early_px, px));
         px.reset();
         BOOST_TEST( early_px.use_count() == 1 );
         BOOST_TEST( X::instances == 1 );
- // X::deleter_type *pd = boost::get_deleter<X::deleter_type>(early_px);
- // BOOST_TEST(pd && *pd == &X::deleter2 );
+ X::deleter_type *pd = boost::get_deleter<X::deleter_type>(early_px);
+ BOOST_TEST(pd && *pd == &X::deleter2 );
     }
 
     BOOST_TEST( X::instances == 0 );
@@ -117,7 +117,7 @@
 
     {
         boost::shared_ptr<X> early_px;
- X x( 1, &early_px );
+ X x( 2, &early_px );
         BOOST_TEST( early_px.use_count() > 0 );
         boost::shared_ptr<X> px( &x, &X::deleter );
         BOOST_TEST( early_px.use_count() == 2 && px.use_count() == 2 );
@@ -125,13 +125,11 @@
         BOOST_TEST( px.use_count() == 1 );
         BOOST_TEST( X::instances == 1 );
         px.reset();
- try
- {
- x.shared_from_this();
- BOOST_ERROR("x did not throw bad_weak_ptr");
- }
- catch( const boost::bad_weak_ptr & )
- {}
+ // test reinitialization after all shared_ptr have expired
+ early_px = shared_from_raw(&x);
+ px.reset( &x, &X::deleter );
+ BOOST_TEST(are_shared_owners(early_px, px));
+ early_px.reset();
     }
 
     BOOST_TEST( X::instances == 0 );
@@ -157,7 +155,7 @@
         px.reset();
         try
         {
- y.shared_from_this();
+ shared_from_raw(&y);
         }
         catch( const boost::bad_weak_ptr & )
         {


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk