forked from boostorg/smart_ptr
Fix smart_ptr tests to not require RTTI.
[SVN r58123]
This commit is contained in:
@ -9,6 +9,8 @@
|
|||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
#include <boost/pointer_cast.hpp>
|
#include <boost/pointer_cast.hpp>
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
@ -58,6 +60,8 @@ class derived_derived
|
|||||||
|
|
||||||
// And now some simple check functions
|
// And now some simple check functions
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
|
|
||||||
template <class BasePtr>
|
template <class BasePtr>
|
||||||
bool check_dynamic_pointer_cast(const BasePtr &ptr)
|
bool check_dynamic_pointer_cast(const BasePtr &ptr)
|
||||||
{
|
{
|
||||||
@ -74,6 +78,8 @@ bool check_dynamic_pointer_cast(const BasePtr &ptr)
|
|||||||
dynamic_cast<derived_derived*>(boost::get_pointer(ptr));
|
dynamic_cast<derived_derived*>(boost::get_pointer(ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
template <class BasePtr>
|
template <class BasePtr>
|
||||||
bool check_static_pointer_cast(const BasePtr &ptr)
|
bool check_static_pointer_cast(const BasePtr &ptr)
|
||||||
{
|
{
|
||||||
@ -107,7 +113,9 @@ int main()
|
|||||||
|
|
||||||
boost::shared_ptr<base> ptr(new derived);
|
boost::shared_ptr<base> ptr(new derived);
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
BOOST_TEST( check_dynamic_pointer_cast( ptr ) );
|
BOOST_TEST( check_dynamic_pointer_cast( ptr ) );
|
||||||
|
#endif
|
||||||
BOOST_TEST( check_static_pointer_cast( ptr ) );
|
BOOST_TEST( check_static_pointer_cast( ptr ) );
|
||||||
BOOST_TEST( check_const_pointer_cast( ptr ) );
|
BOOST_TEST( check_const_pointer_cast( ptr ) );
|
||||||
}
|
}
|
||||||
@ -117,7 +125,9 @@ int main()
|
|||||||
|
|
||||||
boost::scoped_ptr<base> ptr(new derived);
|
boost::scoped_ptr<base> ptr(new derived);
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
BOOST_TEST( check_dynamic_pointer_cast( ptr.get() ) );
|
BOOST_TEST( check_dynamic_pointer_cast( ptr.get() ) );
|
||||||
|
#endif
|
||||||
BOOST_TEST( check_static_pointer_cast( ptr.get() ) );
|
BOOST_TEST( check_static_pointer_cast( ptr.get() ) );
|
||||||
BOOST_TEST( check_const_pointer_cast( ptr.get() ) );
|
BOOST_TEST( check_const_pointer_cast( ptr.get() ) );
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,12 @@ void test()
|
|||||||
|
|
||||||
px->f();
|
px->f();
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px);
|
boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px);
|
||||||
BOOST_TEST(py.get() == py2.get());
|
BOOST_TEST(py.get() == py2.get());
|
||||||
BOOST_TEST(!(py < py2 || py2 < py));
|
BOOST_TEST(!(py < py2 || py2 < py));
|
||||||
BOOST_TEST(py.use_count() == 3);
|
BOOST_TEST(py.use_count() == 3);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
catch( boost::bad_weak_ptr const& )
|
catch( boost::bad_weak_ptr const& )
|
||||||
{
|
{
|
||||||
|
@ -188,6 +188,7 @@ int main()
|
|||||||
test_eq(p, q);
|
test_eq(p, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
shared_ptr<Y> p3 = dynamic_pointer_cast<Y>(p);
|
shared_ptr<Y> p3 = dynamic_pointer_cast<Y>(p);
|
||||||
shared_ptr<Y> p4 = dynamic_pointer_cast<Y>(p2);
|
shared_ptr<Y> p4 = dynamic_pointer_cast<Y>(p2);
|
||||||
|
|
||||||
@ -201,6 +202,7 @@ int main()
|
|||||||
test_is_Y(p3);
|
test_is_Y(p3);
|
||||||
test_eq2(p, p3);
|
test_eq2(p, p3);
|
||||||
test_ne2(p2, p4);
|
test_ne2(p2, p4);
|
||||||
|
#endif
|
||||||
|
|
||||||
shared_ptr<void> p5(p);
|
shared_ptr<void> p5(p);
|
||||||
|
|
||||||
@ -214,13 +216,17 @@ int main()
|
|||||||
|
|
||||||
p.reset();
|
p.reset();
|
||||||
p2.reset();
|
p2.reset();
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
p3.reset();
|
p3.reset();
|
||||||
p4.reset();
|
p4.reset();
|
||||||
|
#endif
|
||||||
|
|
||||||
test_is_zero(p);
|
test_is_zero(p);
|
||||||
test_is_zero(p2);
|
test_is_zero(p2);
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
test_is_zero(p3);
|
test_is_zero(p3);
|
||||||
test_is_zero(p4);
|
test_is_zero(p4);
|
||||||
|
#endif
|
||||||
|
|
||||||
BOOST_TEST(p5.use_count() == 1);
|
BOOST_TEST(p5.use_count() == 1);
|
||||||
|
|
||||||
@ -250,6 +256,7 @@ int main()
|
|||||||
test_is_nonzero(wp2.lock());
|
test_is_nonzero(wp2.lock());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
weak_ptr<Y> wp3 = dynamic_pointer_cast<Y>(wp2.lock());
|
weak_ptr<Y> wp3 = dynamic_pointer_cast<Y>(wp2.lock());
|
||||||
|
|
||||||
BOOST_TEST(wp3.use_count() == 1);
|
BOOST_TEST(wp3.use_count() == 1);
|
||||||
@ -259,12 +266,15 @@ int main()
|
|||||||
|
|
||||||
BOOST_TEST(wp4.use_count() == 1);
|
BOOST_TEST(wp4.use_count() == 1);
|
||||||
test_shared(wp2, wp4);
|
test_shared(wp2, wp4);
|
||||||
|
#endif
|
||||||
|
|
||||||
wp1 = p2;
|
wp1 = p2;
|
||||||
test_is_zero(wp1.lock());
|
test_is_zero(wp1.lock());
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
wp1 = p4;
|
wp1 = p4;
|
||||||
wp1 = wp3;
|
wp1 = wp3;
|
||||||
|
#endif
|
||||||
wp1 = wp2;
|
wp1 = wp2;
|
||||||
|
|
||||||
BOOST_TEST(wp1.use_count() == 1);
|
BOOST_TEST(wp1.use_count() == 1);
|
||||||
@ -279,7 +289,9 @@ int main()
|
|||||||
|
|
||||||
BOOST_TEST(wp1.use_count() == 0);
|
BOOST_TEST(wp1.use_count() == 0);
|
||||||
BOOST_TEST(wp2.use_count() == 0);
|
BOOST_TEST(wp2.use_count() == 0);
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
BOOST_TEST(wp3.use_count() == 0);
|
BOOST_TEST(wp3.use_count() == 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Test operator< stability for std::set< weak_ptr<> >
|
// Test operator< stability for std::set< weak_ptr<> >
|
||||||
// Thanks to Joe Gottman for pointing this out
|
// Thanks to Joe Gottman for pointing this out
|
||||||
|
@ -2462,6 +2462,8 @@ void test()
|
|||||||
|
|
||||||
} // namespace n_const_cast
|
} // namespace n_const_cast
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
|
|
||||||
namespace n_dynamic_cast
|
namespace n_dynamic_cast
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -2527,6 +2529,8 @@ void test()
|
|||||||
|
|
||||||
} // namespace n_dynamic_cast
|
} // namespace n_dynamic_cast
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace n_map
|
namespace n_map
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -3200,10 +3204,12 @@ void test()
|
|||||||
BOOST_TEST(px.get() != 0);
|
BOOST_TEST(px.get() != 0);
|
||||||
BOOST_TEST(py.use_count() == 2);
|
BOOST_TEST(py.use_count() == 2);
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px);
|
boost::shared_ptr<Y> py2 = boost::dynamic_pointer_cast<Y>(px);
|
||||||
BOOST_TEST(py.get() == py2.get());
|
BOOST_TEST(py.get() == py2.get());
|
||||||
BOOST_TEST(!(py < py2 || py2 < py));
|
BOOST_TEST(!(py < py2 || py2 < py));
|
||||||
BOOST_TEST(py.use_count() == 3);
|
BOOST_TEST(py.use_count() == 3);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace n_spt_shared_from_this
|
} // namespace n_spt_shared_from_this
|
||||||
@ -3229,7 +3235,9 @@ int main()
|
|||||||
n_comparison::test();
|
n_comparison::test();
|
||||||
n_static_cast::test();
|
n_static_cast::test();
|
||||||
n_const_cast::test();
|
n_const_cast::test();
|
||||||
|
#if !defined( BOOST_NO_RTTI )
|
||||||
n_dynamic_cast::test();
|
n_dynamic_cast::test();
|
||||||
|
#endif
|
||||||
|
|
||||||
n_map::test();
|
n_map::test();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user