Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52834 - sandbox/boost0x/libs/smart_ptr/test
From: whatwasthataddress_at_[hidden]
Date: 2009-05-07 11:02:55


Author: tzlaine
Date: 2009-05-07 11:02:53 EDT (Thu, 07 May 2009)
New Revision: 52834
URL: http://svn.boost.org/trac/boost/changeset/52834

Log:
Moved the #if defined( BOOST_HAS_RVALUE_REFS ) check enabling the shared_ptr
move tests to after the inclusion of shared_ptr.hpp, so that it has a chance of
actually being defined.

Text files modified:
   sandbox/boost0x/libs/smart_ptr/test/Jamfile.v2 | 1
   sandbox/boost0x/libs/smart_ptr/test/intrusive_ptr_move_test.cpp | 199 ++++++++++++++++++++++++++-------------
   2 files changed, 132 insertions(+), 68 deletions(-)

Modified: sandbox/boost0x/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- sandbox/boost0x/libs/smart_ptr/test/Jamfile.v2 (original)
+++ sandbox/boost0x/libs/smart_ptr/test/Jamfile.v2 2009-05-07 11:02:53 EDT (Thu, 07 May 2009)
@@ -20,6 +20,7 @@
           [ run shared_from_this_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-non-virtual-dtor ]
           [ run get_deleter_test.cpp ]
           [ run intrusive_ptr_test.cpp ]
+ [ run intrusive_ptr_move_test.cpp ]
           [ run atomic_count_test.cpp ]
           [ run lw_mutex_test.cpp ]
           [ compile-fail shared_ptr_assign_fail.cpp ]

Modified: sandbox/boost0x/libs/smart_ptr/test/intrusive_ptr_move_test.cpp
==============================================================================
--- sandbox/boost0x/libs/smart_ptr/test/intrusive_ptr_move_test.cpp (original)
+++ sandbox/boost0x/libs/smart_ptr/test/intrusive_ptr_move_test.cpp 2009-05-07 11:02:53 EDT (Thu, 07 May 2009)
@@ -1,111 +1,174 @@
+//#include <boost/config.hpp>
+
+#if defined(BOOST_MSVC)
+
+#pragma warning(disable: 4786) // identifier truncated in debug info
+#pragma warning(disable: 4710) // function not inlined
+#pragma warning(disable: 4711) // function selected for automatic inline expansion
+#pragma warning(disable: 4514) // unreferenced inline removed
+#pragma warning(disable: 4355) // 'this' : used in base member initializer list
+#pragma warning(disable: 4511) // copy constructor could not be generated
+#pragma warning(disable: 4512) // assignment operator could not be generated
+
+#if (BOOST_MSVC >= 1310)
+#pragma warning(disable: 4675) // resolved overload found with Koenig lookup
+#endif
+
+#endif
+
 //
-// shared_ptr_move_test.cpp
+// intrusive_ptr_test.cpp
 //
-// Copyright (c) 2007 Peter Dimov
+// Copyright (c) 2002-2005 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
+// 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>
+#include <boost/intrusive_ptr.hpp>
+#include <boost/detail/atomic_count.hpp>
+#include <boost/config.hpp>
+#include <algorithm>
+#include <functional>
 
 #if defined( BOOST_HAS_RVALUE_REFS )
 
-struct X
+namespace N
 {
- static long instances;
 
- X()
+class base
+{
+private:
+
+ boost::detail::atomic_count use_count_;
+
+ base(base const &);
+ base & operator=(base const &);
+
+protected:
+
+ base(): use_count_(0)
     {
         ++instances;
     }
 
- ~X()
+ virtual ~base()
     {
         --instances;
     }
 
-private:
+public:
+
+ static long instances;
+
+ long use_count() const
+ {
+ return use_count_;
+ }
+
+#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
+
+ inline friend void intrusive_ptr_add_ref(base * p)
+ {
+ ++p->use_count_;
+ }
+
+ inline friend void intrusive_ptr_release(base * p)
+ {
+ if(--p->use_count_ == 0) delete p;
+ }
+
+#else
+
+ void add_ref()
+ {
+ ++use_count_;
+ }
+
+ void release()
+ {
+ if(--use_count_ == 0) delete this;
+ }
 
- X( X const & );
- X & operator=( X const & );
+#endif
 };
 
-long X::instances = 0;
+long base::instances = 0;
+
+} // namespace N
+
+#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
+
+namespace boost
+{
+
+inline void intrusive_ptr_add_ref(N::base * p)
+{
+ p->add_ref();
+}
+
+inline void intrusive_ptr_release(N::base * p)
+{
+ p->release();
+}
+
+} // namespace boost
+
+#endif
+
+//
+
+struct X: public virtual N::base
+{
+};
+
+struct Y: public X
+{
+};
 
 int main()
 {
- BOOST_TEST( X::instances == 0 );
+ BOOST_TEST( N::base::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> p( new X );
+ BOOST_TEST( N::base::instances == 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() );
+ BOOST_TEST( N::base::instances == 1 );
+ BOOST_TEST( p.get() == 0 );
 
- p_.reset();
- BOOST_TEST( X::instances == 0 );
- BOOST_TEST( p3.expired() );
+ p2.reset();
+ BOOST_TEST( N::base::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> p( new X );
+ BOOST_TEST( N::base::instances == 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_TEST( N::base::instances == 1 );
+ BOOST_TEST( p.get() == 0 );
+
+ p2.reset();
+ BOOST_TEST( N::base::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::shared_ptr<X> p_2( new X );
- boost::intrusive_ptr<X> p2( p_2 );
- BOOST_TEST( X::instances == 2 );
+ boost::intrusive_ptr<X> p( new X );
+ BOOST_TEST( N::base::instances == 1 );
+
+ boost::intrusive_ptr<X> p2( new X );
+ BOOST_TEST( N::base::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 );
+ BOOST_TEST( N::base::instances == 1 );
+ BOOST_TEST( p.get() == 0 );
+
+ p2.reset();
+ BOOST_TEST( N::base::instances == 0 );
     }
 
     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