|
Boost-Commit : |
From: pdimov_at_[hidden]
Date: 2008-07-12 06:45:56
Author: pdimov
Date: 2008-07-12 06:45:56 EDT (Sat, 12 Jul 2008)
New Revision: 47342
URL: http://svn.boost.org/trac/boost/changeset/47342
Log:
Update esft_regtest.cpp to trunk HEAD; takes care of 43829, 43856, 44775.
Text files modified:
branches/release/libs/smart_ptr/test/esft_regtest.cpp | 87 +++++++++++++++++++++++++++++++++++++++
1 files changed, 86 insertions(+), 1 deletions(-)
Modified: branches/release/libs/smart_ptr/test/esft_regtest.cpp
==============================================================================
--- branches/release/libs/smart_ptr/test/esft_regtest.cpp (original)
+++ branches/release/libs/smart_ptr/test/esft_regtest.cpp 2008-07-12 06:45:56 EDT (Sat, 12 Jul 2008)
@@ -16,6 +16,7 @@
#include <boost/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <memory>
+#include <string>
class X: public boost::enable_shared_from_this< X >
{
@@ -65,7 +66,7 @@
int X::instances = 0;
-int main()
+void test()
{
BOOST_TEST( X::instances == 0 );
@@ -131,6 +132,90 @@
}
BOOST_TEST( X::instances == 0 );
+}
+
+struct V: public boost::enable_shared_from_this<V>
+{
+ virtual ~V() {}
+ std::string m_;
+};
+
+struct V2
+{
+ virtual ~V2() {}
+ std::string m2_;
+};
+
+struct W: V2, V
+{
+};
+
+void test2()
+{
+ boost::shared_ptr<W> p( new W );
+}
+
+void test3()
+{
+ V * p = new W;
+ boost::shared_ptr<void> pv( p );
+ BOOST_TEST( pv.get() == p );
+ BOOST_TEST( pv.use_count() == 1 );
+}
+
+struct null_deleter
+{
+ void operator()( void const* ) const {}
+};
+
+void test4()
+{
+ boost::shared_ptr<V> pv( new V );
+ boost::shared_ptr<V> pv2( pv.get(), null_deleter() );
+ BOOST_TEST( pv2.get() == pv.get() );
+ BOOST_TEST( pv2.use_count() == 1 );
+}
+
+void test5()
+{
+ V v;
+
+ boost::shared_ptr<V> p1( &v, null_deleter() );
+ BOOST_TEST( p1.get() == &v );
+ BOOST_TEST( p1.use_count() == 1 );
+
+ try
+ {
+ p1->shared_from_this();
+ }
+ catch( ... )
+ {
+ BOOST_ERROR( "p1->shared_from_this() failed" );
+ }
+
+ p1.reset();
+
+ boost::shared_ptr<V> p2( &v, null_deleter() );
+ BOOST_TEST( p2.get() == &v );
+ BOOST_TEST( p2.use_count() == 1 );
+
+ try
+ {
+ p2->shared_from_this();
+ }
+ catch( ... )
+ {
+ BOOST_ERROR( "p2->shared_from_this() failed" );
+ }
+}
+
+int main()
+{
+ test();
+ test2();
+ test3();
+ test4();
+ test5();
return boost::report_errors();
}
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