From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../libs/serialization/test/test_void_cast.cpp | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 src/boost/libs/serialization/test/test_void_cast.cpp (limited to 'src/boost/libs/serialization/test/test_void_cast.cpp') diff --git a/src/boost/libs/serialization/test/test_void_cast.cpp b/src/boost/libs/serialization/test/test_void_cast.cpp new file mode 100644 index 000000000..1538ab2b0 --- /dev/null +++ b/src/boost/libs/serialization/test/test_void_cast.cpp @@ -0,0 +1,165 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_void_cast.cpp: test implementation of run-time casting of void pointers + +// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . +// Use, modification and distribution is subject to 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 // NULL +#include "test_tools.hpp" +#include +#include +#include + +class Base1 +{ + char a; +}; + +class Base2 +{ + int b; +}; + +class Derived : public Base1, public Base2 +{ + long c; +}; + +class MostDerived : public Derived +{ + char d[32]; +}; + +template +const boost::serialization::extended_type_info & eti(){ + return boost::serialization::singleton< + boost::serialization::extended_type_info_typeid< T > + >::get_const_instance(); +} + +int +test_main( int /* argc */, char* /* argv */[] ) +{ + MostDerived md; + MostDerived* pmd =& md; + Derived* pd = static_cast(pmd); + + Base2* pb2 = static_cast(pmd); + Base1* pb1 = static_cast(pd); + + void* vpmd = static_cast(pmd); + void* vpb1 = static_cast(pb1); + void* vpb2 = static_cast(pb2); + void* vpd = static_cast(pd); + + // simple casts only requiring table lookup + BOOST_CHECK(vpd == boost::serialization::void_downcast( + eti(), + eti(), + vpb1 + )); + BOOST_CHECK(vpb1 == boost::serialization::void_upcast( + eti(), + eti(), + vpd + )); + BOOST_CHECK(vpd == boost::serialization::void_downcast( + eti(), + eti(), + vpb2 + )); + BOOST_CHECK(vpb2 == boost::serialization::void_upcast( + eti(), + eti(), + vpd + )); + BOOST_CHECK(vpmd == boost::serialization::void_downcast( + eti(), + eti(), + vpd + )); + BOOST_CHECK(vpd == boost::serialization::void_upcast( + eti(), + eti(), + vpmd + )); + // note relationship between MostDerived and Base1 is automatically derived + BOOST_CHECK(vpmd == boost::serialization::void_downcast( + eti(), + eti(), + vpb1 + )); + BOOST_CHECK(vpb1 == boost::serialization::void_upcast( + eti(), + eti(), + vpmd + )); + + // note relationship between MostDerived and Base2 is automatically derived + BOOST_CHECK(vpmd == boost::serialization::void_downcast( + eti(), + eti(), + vpb2 + )); + BOOST_CHECK(vpb2 == boost::serialization::void_upcast( + eti(), + eti(), + vpmd + )); + + // note: currently derivations are not optimised. See void_cast.cpp + // for and explanation. These should still work though. + + // need to double check to validate speed up optimization of derivations + BOOST_CHECK(vpmd == boost::serialization::void_downcast( + eti(), + eti(), + vpb1 + )); + BOOST_CHECK(vpb1 == boost::serialization::void_upcast( + eti(), + eti(), + vpmd + )); + BOOST_CHECK(vpmd == boost::serialization::void_downcast( + eti(), + eti(), + vpb2 + )); + BOOST_CHECK(vpb2 == boost::serialization::void_upcast( + eti(), + eti(), + vpmd + )); + + // check things that should fail + BOOST_CHECK(NULL == boost::serialization::void_downcast( + eti(), + eti(), + vpb1 + )); + + // note that a fundamental feature is that derived/base pairs are created + // at compiler time so that all are registered before the main program starts + // so leave the registration here at the end to verify this. Note bogus arguments + // to workaround msvc 6 bug + boost::serialization::void_cast_register( + static_cast(NULL), + static_cast(NULL) + ); + boost::serialization::void_cast_register( + static_cast(NULL), + static_cast(NULL) + ); + boost::serialization::void_cast_register( + static_cast(NULL), + static_cast(NULL) + ); + + return EXIT_SUCCESS; +} + +// EOF -- cgit v1.2.3