forked from boostorg/smart_ptr
Merged 43316, 43317, 43318, 43733, 43782, 43873, 43888, 43916, 43950, 44055, 44056, 44058, 44073, 44074, 44132, 44137, 44138, 44140, 44344 from trunk to release
[SVN r47339]
This commit is contained in:
1 parent
a9cd84f43d
commit
866590ee97
26 files changed
+1256
-31
No files matched your search
@@ -33,5 +33,14 @@ import testing ;
|
||||
[ run shared_ptr_move_test.cpp ]
|
||||
[ compile-fail shared_ptr_pv_fail.cpp ]
|
||||
[ run sp_unary_addr_test.cpp ]
|
||||
[ compile-fail scoped_ptr_eq_fail.cpp ]
|
||||
[ compile-fail scoped_array_eq_fail.cpp ]
|
||||
[ run esft_regtest.cpp ]
|
||||
[ run yield_k_test.cpp ]
|
||||
[ run yield_k_test.cpp : : : <threading>multi : yield_k_test.mt ]
|
||||
[ run spinlock_test.cpp ]
|
||||
[ run spinlock_try_test.cpp ]
|
||||
[ run spinlock_try_test.cpp : : : <threading>multi : spinlock_try_test.mt ]
|
||||
[ run spinlock_pool_test.cpp ]
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
//
|
||||
// esft_regtest.cpp
|
||||
//
|
||||
// A regression test for enable_shared_from_this
|
||||
//
|
||||
// Copyright (c) 2008 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/enable_shared_from_this.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_this< X >
|
||||
{
|
||||
private:
|
||||
|
||||
int destroyed_;
|
||||
int deleted_;
|
||||
int expected_;
|
||||
|
||||
private:
|
||||
|
||||
X( X const& );
|
||||
X& operator=( X const& );
|
||||
|
||||
public:
|
||||
|
||||
static int instances;
|
||||
|
||||
public:
|
||||
|
||||
explicit X( int expected ): destroyed_( 0 ), deleted_( 0 ), expected_( expected )
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~X()
|
||||
{
|
||||
BOOST_TEST( deleted_ == expected_ );
|
||||
BOOST_TEST( destroyed_ == 0 );
|
||||
++destroyed_;
|
||||
--instances;
|
||||
}
|
||||
|
||||
typedef void (*deleter_type)( X* );
|
||||
|
||||
static void deleter( X * px )
|
||||
{
|
||||
++px->deleted_;
|
||||
}
|
||||
|
||||
static void deleter2( X * px )
|
||||
{
|
||||
++px->deleted_;
|
||||
delete px;
|
||||
}
|
||||
};
|
||||
|
||||
int X::instances = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
X x( 0 );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
std::auto_ptr<X> px( new X( 0 ) );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
}
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
boost::shared_ptr<X> px( new X( 0 ) );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
|
||||
boost::weak_ptr<X> wp( px );
|
||||
BOOST_TEST( !wp.expired() );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( wp.expired() );
|
||||
}
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
X x( 1 );
|
||||
boost::shared_ptr<X> px( &x, X::deleter );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
|
||||
X::deleter_type * pd = boost::get_deleter<X::deleter_type>( px );
|
||||
BOOST_TEST( pd != 0 && *pd == X::deleter );
|
||||
|
||||
boost::weak_ptr<X> wp( px );
|
||||
BOOST_TEST( !wp.expired() );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( wp.expired() );
|
||||
}
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
{
|
||||
boost::shared_ptr<X> px( new X( 1 ), X::deleter2 );
|
||||
BOOST_TEST( X::instances == 1 );
|
||||
|
||||
X::deleter_type * pd = boost::get_deleter<X::deleter_type>( px );
|
||||
BOOST_TEST( pd != 0 && *pd == X::deleter2 );
|
||||
|
||||
boost::weak_ptr<X> wp( px );
|
||||
BOOST_TEST( !wp.expired() );
|
||||
|
||||
px.reset();
|
||||
|
||||
BOOST_TEST( wp.expired() );
|
||||
}
|
||||
|
||||
BOOST_TEST( X::instances == 0 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#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
|
||||
#endif
|
||||
|
||||
//
|
||||
// scoped_array_eq_fail.cpp - a negative test for "p == q"
|
||||
//
|
||||
// Copyright (c) 2008 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/scoped_array.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::scoped_array<int> p, q;
|
||||
p == q; // must fail
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#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
|
||||
#endif
|
||||
|
||||
//
|
||||
// scoped_ptr_eq_fail.cpp - a negative test for "p == q"
|
||||
//
|
||||
// Copyright (c) 2008 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/scoped_ptr.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::scoped_ptr<int> p, q;
|
||||
p == q; // must fail
|
||||
return 0;
|
||||
}
|
||||
@@ -133,7 +133,8 @@ void test3()
|
||||
try
|
||||
{
|
||||
boost::shared_ptr<V> r = v2.shared_from_this();
|
||||
BOOST_ERROR("v2.shared_from_this() failed to throw");
|
||||
BOOST_TEST( p < r || r < p );
|
||||
BOOST_TEST( r.get() == &v2 );
|
||||
}
|
||||
catch(boost::bad_weak_ptr const &)
|
||||
{
|
||||
|
||||
@@ -62,6 +62,7 @@ void default_constructor()
|
||||
BOOST_TEST(pi? false: true);
|
||||
BOOST_TEST(!pi);
|
||||
BOOST_TEST(pi.get() == 0);
|
||||
BOOST_TEST(pi.use_count() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -69,6 +70,7 @@ void default_constructor()
|
||||
BOOST_TEST(pv? false: true);
|
||||
BOOST_TEST(!pv);
|
||||
BOOST_TEST(pv.get() == 0);
|
||||
BOOST_TEST(pv.use_count() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -76,6 +78,7 @@ void default_constructor()
|
||||
BOOST_TEST(px? false: true);
|
||||
BOOST_TEST(!px);
|
||||
BOOST_TEST(px.get() == 0);
|
||||
BOOST_TEST(px.use_count() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1565,6 +1568,7 @@ void plain_reset()
|
||||
BOOST_TEST(pi? false: true);
|
||||
BOOST_TEST(!pi);
|
||||
BOOST_TEST(pi.get() == 0);
|
||||
BOOST_TEST(pi.use_count() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1573,6 +1577,7 @@ void plain_reset()
|
||||
BOOST_TEST(pi? false: true);
|
||||
BOOST_TEST(!pi);
|
||||
BOOST_TEST(pi.get() == 0);
|
||||
BOOST_TEST(pi.use_count() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1581,6 +1586,7 @@ void plain_reset()
|
||||
BOOST_TEST(pi? false: true);
|
||||
BOOST_TEST(!pi);
|
||||
BOOST_TEST(pi.get() == 0);
|
||||
BOOST_TEST(pi.use_count() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1589,6 +1595,7 @@ void plain_reset()
|
||||
BOOST_TEST(px? false: true);
|
||||
BOOST_TEST(!px);
|
||||
BOOST_TEST(px.get() == 0);
|
||||
BOOST_TEST(px.use_count() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1597,6 +1604,7 @@ void plain_reset()
|
||||
BOOST_TEST(px? false: true);
|
||||
BOOST_TEST(!px);
|
||||
BOOST_TEST(px.get() == 0);
|
||||
BOOST_TEST(px.use_count() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1605,6 +1613,7 @@ void plain_reset()
|
||||
BOOST_TEST(px? false: true);
|
||||
BOOST_TEST(!px);
|
||||
BOOST_TEST(px.get() == 0);
|
||||
BOOST_TEST(px.use_count() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1615,6 +1624,7 @@ void plain_reset()
|
||||
BOOST_TEST(px? false: true);
|
||||
BOOST_TEST(!px);
|
||||
BOOST_TEST(px.get() == 0);
|
||||
BOOST_TEST(px.use_count() == 0);
|
||||
BOOST_TEST(X::instances == 0);
|
||||
}
|
||||
|
||||
@@ -1624,6 +1634,7 @@ void plain_reset()
|
||||
BOOST_TEST(pv? false: true);
|
||||
BOOST_TEST(!pv);
|
||||
BOOST_TEST(pv.get() == 0);
|
||||
BOOST_TEST(pv.use_count() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1634,6 +1645,7 @@ void plain_reset()
|
||||
BOOST_TEST(pv? false: true);
|
||||
BOOST_TEST(!pv);
|
||||
BOOST_TEST(pv.get() == 0);
|
||||
BOOST_TEST(pv.use_count() == 0);
|
||||
BOOST_TEST(X::instances == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// spinlock_pool_test.cpp
|
||||
//
|
||||
// Copyright 2008 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/detail/spinlock_pool.hpp>
|
||||
|
||||
// Sanity check only
|
||||
|
||||
int main()
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
{
|
||||
boost::detail::spinlock_pool<0>::scoped_lock lock( &x );
|
||||
++x;
|
||||
}
|
||||
|
||||
{
|
||||
boost::detail::spinlock_pool<1>::scoped_lock lock( &x );
|
||||
boost::detail::spinlock_pool<2>::scoped_lock lock2( &x );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// spinlock_test.cpp
|
||||
//
|
||||
// Copyright 2008 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/detail/spinlock.hpp>
|
||||
|
||||
// Sanity check only
|
||||
|
||||
static boost::detail::spinlock sp = BOOST_DETAIL_SPINLOCK_INIT;
|
||||
static boost::detail::spinlock sp2 = BOOST_DETAIL_SPINLOCK_INIT;
|
||||
|
||||
int main()
|
||||
{
|
||||
sp.lock();
|
||||
sp2.lock();
|
||||
sp.unlock();
|
||||
sp2.unlock();
|
||||
|
||||
{
|
||||
boost::detail::spinlock::scoped_lock lock( sp );
|
||||
boost::detail::spinlock::scoped_lock lock2( sp2 );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// spinlock_try_test.cpp
|
||||
//
|
||||
// Copyright 2008 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/detail/spinlock.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
|
||||
// Sanity check only
|
||||
|
||||
static boost::detail::spinlock sp = BOOST_DETAIL_SPINLOCK_INIT;
|
||||
static boost::detail::spinlock sp2 = BOOST_DETAIL_SPINLOCK_INIT;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST( sp.try_lock() );
|
||||
BOOST_TEST( !sp.try_lock() );
|
||||
BOOST_TEST( sp2.try_lock() );
|
||||
BOOST_TEST( !sp.try_lock() );
|
||||
BOOST_TEST( !sp2.try_lock() );
|
||||
sp.unlock();
|
||||
sp2.unlock();
|
||||
|
||||
sp.lock();
|
||||
BOOST_TEST( !sp.try_lock() );
|
||||
sp2.lock();
|
||||
BOOST_TEST( !sp.try_lock() );
|
||||
BOOST_TEST( !sp2.try_lock() );
|
||||
sp.unlock();
|
||||
sp2.unlock();
|
||||
|
||||
{
|
||||
boost::detail::spinlock::scoped_lock lock( sp );
|
||||
BOOST_TEST( !sp.try_lock() );
|
||||
boost::detail::spinlock::scoped_lock lock2( sp2 );
|
||||
BOOST_TEST( !sp.try_lock() );
|
||||
BOOST_TEST( !sp2.try_lock() );
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// yield_k_test.cpp
|
||||
//
|
||||
// Copyright 2008 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/detail/yield_k.hpp>
|
||||
|
||||
// Sanity check only
|
||||
|
||||
int main()
|
||||
{
|
||||
for( unsigned k = 0; k < 256; ++k )
|
||||
{
|
||||
boost::detail::yield( k );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user