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 --- .../test/test_multiple_inheritance.cpp | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/boost/libs/serialization/test/test_multiple_inheritance.cpp (limited to 'src/boost/libs/serialization/test/test_multiple_inheritance.cpp') diff --git a/src/boost/libs/serialization/test/test_multiple_inheritance.cpp b/src/boost/libs/serialization/test/test_multiple_inheritance.cpp new file mode 100644 index 000000000..08c304f83 --- /dev/null +++ b/src/boost/libs/serialization/test/test_multiple_inheritance.cpp @@ -0,0 +1,125 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_multiple_inheritance.cpp + +// (C) Copyright 2009 Robert Ramey. +// 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) + +// test of serialization library for multiple inheritence situations + +#include +#include + +#include +#include // remove +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include "test_tools.hpp" + +#include +#include +#include +#include + +struct Base1 { + int m_x; + Base1(){} + Base1(int x) : m_x(1 + x) {} + virtual ~Base1() {} + bool operator==(Base1 & rhs) const { + return m_x == rhs.m_x; + } + // serialize + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int /* file_version */) { + ar & BOOST_SERIALIZATION_NVP(m_x); + } +}; + +//BOOST_CLASS_EXPORT(Base1) + +struct Base2 { + int m_x; + Base2(){} + Base2(int x) : m_x(2 + x) {} + virtual ~Base2() {} + bool operator==(Base2 & rhs) const { + return m_x == rhs.m_x; + } + // serialize + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int /* file_version */) { + ar & BOOST_SERIALIZATION_NVP(m_x); + } +}; + +//BOOST_CLASS_EXPORT(Base2) + +struct Sub : + public Base1, + public Base2 +{ + int m_x; + Sub(){} + Sub(int x) : + Base1(x), + Base2(x), + m_x(x) + {} + bool operator==(Sub & rhs) const { + if(! Base2::operator==(rhs)) + return false; + if(! Base1::operator==(rhs)) + return false; + return m_x == rhs.m_x; + } + virtual ~Sub() {} + + // serialize + friend class boost::serialization::access; + template + void serialize(Archive &ar, const unsigned int /* file_version */) + { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base1); + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base2); + ar & BOOST_SERIALIZATION_NVP(m_x); + } +}; + +BOOST_CLASS_EXPORT(Sub) + +int +test_main( int /* argc */, char* /* argv */[] ) +{ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + Base2 * pb2; + { + // serialize + pb2 = new Sub(2); + + test_ostream ofs(testfile); + test_oarchive oa(ofs); + oa << boost::serialization::make_nvp("Base2", pb2); + } + Base2 * pb2_1; + { + // de-serialize + test_istream ifs(testfile); + test_iarchive ia(ifs); + ia >> boost::serialization::make_nvp("Base2", pb2_1); + } + Sub *s1 = dynamic_cast(pb2); + BOOST_CHECK(0 != s1); + Sub *s2 = dynamic_cast(pb2_1); + BOOST_CHECK(0 != s2); + BOOST_CHECK(*s1 == *s2); + return EXIT_SUCCESS; +} -- cgit v1.2.3