From d7448b574684207f62326f8ebe3adc526bf20566 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Sun, 23 Mar 2008 14:51:40 +0000 Subject: [PATCH] Added a little more test code for new enable_shared_from_this behavior. [SVN r43804] --- test/esft_constructor_test.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/esft_constructor_test.cpp b/test/esft_constructor_test.cpp index 88fbe68..068f236 100644 --- a/test/esft_constructor_test.cpp +++ b/test/esft_constructor_test.cpp @@ -75,6 +75,9 @@ bool are_shared_owners(const boost::shared_ptr &a, const boost::shared_ptr return a && !(a < b) && !(b < a); } +struct Y: public boost::enable_shared_from_this +{}; + int main() { BOOST_TEST( X::instances == 0 ); @@ -121,6 +124,14 @@ int main() early_px.reset(); 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 &err) + {} } BOOST_TEST( X::instances == 0 ); @@ -140,5 +151,19 @@ int main() BOOST_TEST( X::instances == 0 ); + { + boost::shared_ptr px(new Y()); + Y y(*px); + px.reset(); + try + { + y.shared_from_this(); + } + catch( const boost::bad_weak_ptr &err) + { + BOOST_ERROR("y threw bad_weak_ptr"); + } + } + return boost::report_errors(); }