Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52819 - sandbox/boost0x/libs/smart_ptr/test
From: whatwasthataddress_at_[hidden]
Date: 2009-05-07 01:07:38


Author: tzlaine
Date: 2009-05-07 01:07:37 EDT (Thu, 07 May 2009)
New Revision: 52819
URL: http://svn.boost.org/trac/boost/changeset/52819

Log:
Added tests for recently-added intrusive_ptr move ctor and move assignment
operator.

Added:
   sandbox/boost0x/libs/smart_ptr/test/intrusive_ptr_move_test.cpp (contents, props changed)

Added: sandbox/boost0x/libs/smart_ptr/test/intrusive_ptr_move_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/boost0x/libs/smart_ptr/test/intrusive_ptr_move_test.cpp 2009-05-07 01:07:37 EDT (Thu, 07 May 2009)
@@ -0,0 +1,121 @@
+//
+// shared_ptr_move_test.cpp
+//
+// Copyright (c) 2007 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/intrusive_ptr.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#if defined( BOOST_HAS_RVALUE_REFS )
+
+struct X
+{
+ static long instances;
+
+ X()
+ {
+ ++instances;
+ }
+
+ ~X()
+ {
+ --instances;
+ }
+
+private:
+
+ X( X const & );
+ X & operator=( X const & );
+};
+
+long X::instances = 0;
+
+int main()
+{
+ BOOST_TEST( X::instances == 0 );
+
+ {
+ boost::shared_ptr<X> p_( new X );
+ boost::intrusive_ptr<X> p( p_ );
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( p.use_count() == 1 );
+
+ boost::intrusive_ptr<X> p2( static_cast< boost::intrusive_ptr<X> && >( p ) );
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( p2.use_count() == 1 );
+ BOOST_TEST( p.expired() );
+
+ boost::intrusive_ptr<void> p3( static_cast< boost::intrusive_ptr<X> && >( p2 ) );
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( p3.use_count() == 1 );
+ BOOST_TEST( p2.expired() );
+
+ p_.reset();
+ BOOST_TEST( X::instances == 0 );
+ BOOST_TEST( p3.expired() );
+ }
+
+ {
+ boost::shared_ptr<X> p_( new X );
+ boost::intrusive_ptr<X> p( p_ );
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( p.use_count() == 1 );
+
+ boost::intrusive_ptr<X> p2;
+ p2 = static_cast< boost::intrusive_ptr<X> && >( p );
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( p2.use_count() == 1 );
+ BOOST_TEST( p.expired() );
+
+ boost::intrusive_ptr<void> p3;
+ p3 = static_cast< boost::intrusive_ptr<X> && >( p2 );
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( p3.use_count() == 1 );
+ BOOST_TEST( p2.expired() );
+
+ p_.reset();
+ BOOST_TEST( X::instances == 0 );
+ BOOST_TEST( p3.expired() );
+ }
+
+ {
+ boost::shared_ptr<X> p_( new X );
+ boost::intrusive_ptr<X> p( p_ );
+ BOOST_TEST( X::instances == 1 );
+ BOOST_TEST( p.use_count() == 1 );
+
+ boost::shared_ptr<X> p_2( new X );
+ boost::intrusive_ptr<X> p2( p_2 );
+ BOOST_TEST( X::instances == 2 );
+ p2 = static_cast< boost::intrusive_ptr<X> && >( p );
+ BOOST_TEST( X::instances == 2 );
+ BOOST_TEST( p2.use_count() == 1 );
+ BOOST_TEST( p.expired() );
+ BOOST_TEST( p2.lock() != p_2 );
+
+ boost::shared_ptr<void> p_3( new X );
+ boost::intrusive_ptr<void> p3( p_3 );
+ BOOST_TEST( X::instances == 3 );
+ p3 = static_cast< boost::intrusive_ptr<X> && >( p2 );
+ BOOST_TEST( X::instances == 3 );
+ BOOST_TEST( p3.use_count() == 1 );
+ BOOST_TEST( p2.expired() );
+ BOOST_TEST( p3.lock() != p_3 );
+ }
+
+ return boost::report_errors();
+}
+
+#else // !defined( BOOST_HAS_RVALUE_REFS )
+
+int main()
+{
+ return 0;
+}
+
+#endif


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