// // sp_array_cast_test.cpp // // Copyright (c) 2012 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 #include struct X { }; void static_cast_test() { { boost::shared_ptr pv; boost::shared_ptr pi = boost::static_pointer_cast( pv ); BOOST_TEST( pi.get() == 0 ); boost::shared_ptr pi2 = boost::static_pointer_cast( pv ); BOOST_TEST( pi2.get() == 0 ); boost::shared_ptr px = boost::static_pointer_cast( pv ); BOOST_TEST( px.get() == 0 ); boost::shared_ptr px2 = boost::static_pointer_cast( pv ); BOOST_TEST( px2.get() == 0 ); } { boost::shared_ptr pi( new int[2] ); boost::shared_ptr pv( pi ); boost::shared_ptr pi2 = boost::static_pointer_cast( pv ); BOOST_TEST(pi.get() == pi2.get()); BOOST_TEST(!(pi < pi2 || pi2 < pi)); boost::shared_ptr pi3 = boost::static_pointer_cast( pv ); BOOST_TEST(pi.get() == pi3.get()); BOOST_TEST(!(pi < pi3 || pi3 < pi)); boost::shared_ptr pv2( pi3 ); boost::shared_ptr pi4 = boost::static_pointer_cast( pv2 ); BOOST_TEST(pi.get() == pi4.get()); BOOST_TEST(!(pi < pi4 || pi4 < pi)); } { boost::shared_ptr px( new X[4] ); boost::shared_ptr pv( px ); boost::shared_ptr px2 = boost::static_pointer_cast( pv ); BOOST_TEST(px.get() == px2.get()); BOOST_TEST(!(px < px2 || px2 < px)); boost::shared_ptr px3 = boost::static_pointer_cast( pv ); BOOST_TEST(px.get() == px3.get()); BOOST_TEST(!(px < px3 || px3 < px)); boost::shared_ptr pv2( px3 ); boost::shared_ptr px4 = boost::static_pointer_cast( pv2 ); BOOST_TEST(px.get() == px4.get()); BOOST_TEST(!(px < px4 || px4 < px)); } } void const_cast_test() { { boost::shared_ptr px; boost::shared_ptr px2 = boost::const_pointer_cast(px); BOOST_TEST( px2.get() == 0 ); } { boost::shared_ptr px; boost::shared_ptr px2 = boost::const_pointer_cast(px); BOOST_TEST( px2.get() == 0 ); } { boost::shared_ptr px; boost::shared_ptr px2 = boost::const_pointer_cast(px); BOOST_TEST( px2.get() == 0 ); } { boost::shared_ptr px; boost::shared_ptr px2 = boost::const_pointer_cast(px); BOOST_TEST( px2.get() == 0 ); } { boost::shared_ptr px( new int[3] ); boost::shared_ptr px2 = boost::const_pointer_cast(px); BOOST_TEST(px.get() == px2.get()); BOOST_TEST(!(px < px2 || px2 < px)); } { boost::shared_ptr px( new int[3] ); boost::shared_ptr px2 = boost::const_pointer_cast(px); BOOST_TEST(px.get() == px2.get()); BOOST_TEST(!(px < px2 || px2 < px)); } { boost::shared_ptr px( new X[4] ); boost::shared_ptr px2 = boost::const_pointer_cast(px); BOOST_TEST(px.get() == px2.get()); BOOST_TEST(!(px < px2 || px2 < px)); } { boost::shared_ptr px( new X[4] ); boost::shared_ptr px2 = boost::const_pointer_cast(px); BOOST_TEST(px.get() == px2.get()); BOOST_TEST(!(px < px2 || px2 < px)); } } void reinterpret_cast_test() { { boost::shared_ptr pi; BOOST_TEST( pi.get() == 0 ); boost::shared_ptr pi2 = boost::reinterpret_pointer_cast( pi ); BOOST_TEST( pi2.get() == 0 ); boost::shared_ptr pi3 = boost::reinterpret_pointer_cast( pi2 ); BOOST_TEST( pi3.get() == 0 ); } { boost::shared_ptr px; BOOST_TEST( px.get() == 0 ); boost::shared_ptr px2 = boost::reinterpret_pointer_cast( px ); BOOST_TEST( px2.get() == 0 ); boost::shared_ptr px3 = boost::reinterpret_pointer_cast( px2 ); BOOST_TEST( px3.get() == 0 ); } { boost::shared_ptr pi( new int[2] ); boost::shared_ptr pi2 = boost::reinterpret_pointer_cast( pi ); BOOST_TEST(pi.get() == pi2.get()); BOOST_TEST(!(pi < pi2 || pi2 < pi)); boost::shared_ptr pi3 = boost::reinterpret_pointer_cast( pi2 ); BOOST_TEST(pi.get() == pi3.get()); BOOST_TEST(!(pi < pi3 || pi3 < pi)); boost::shared_ptr pi4 = boost::reinterpret_pointer_cast( pi3 ); BOOST_TEST(pi.get() == pi4.get()); BOOST_TEST(!(pi < pi4 || pi4 < pi)); } { boost::shared_ptr px( new X[4] ); boost::shared_ptr px2 = boost::reinterpret_pointer_cast( px ); BOOST_TEST(px.get() == px2.get()); BOOST_TEST(!(px < px2 || px2 < px)); boost::shared_ptr px3 = boost::reinterpret_pointer_cast( px2 ); BOOST_TEST(px.get() == px3.get()); BOOST_TEST(!(px < px3 || px3 < px)); boost::shared_ptr px4 = boost::reinterpret_pointer_cast( px3 ); BOOST_TEST(px.get() == px4.get()); BOOST_TEST(!(px < px4 || px4 < px)); } } int main() { static_cast_test(); const_cast_test(); reinterpret_cast_test(); return boost::report_errors(); }