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_private_base2.cpp | 104 +++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/boost/libs/serialization/test/test_private_base2.cpp (limited to 'src/boost/libs/serialization/test/test_private_base2.cpp') diff --git a/src/boost/libs/serialization/test/test_private_base2.cpp b/src/boost/libs/serialization/test/test_private_base2.cpp new file mode 100644 index 000000000..67d714c4c --- /dev/null +++ b/src/boost/libs/serialization/test/test_private_base2.cpp @@ -0,0 +1,104 @@ +/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 +// test_private_base.cpp + +// (C) Copyright 2009 Eric Moyer - 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) + +// should pass compilation and execution + +// invoke header for a custom archive test. + +#include +#include +#if defined(BOOST_NO_STDC_NAMESPACE) +namespace std{ + using ::remove; +} +#endif + +#include +#include +#include + +#include "test_tools.hpp" + +class Base { + friend class boost::serialization::access; + int m_i; + template + void serialize(Archive & ar, const unsigned int version){ + ar & BOOST_SERIALIZATION_NVP(m_i); + } +protected: + bool equals(const Base &rhs) const { + return m_i == rhs.m_i; + } + Base(int i = 0) : + m_i(i) + {} + virtual ~Base(){}; +public: + virtual bool operator==(const Base &rhs) const { + return false; + }// = 0; +}; + +class Derived : private Base { + friend class boost::serialization::access; +public: + virtual bool operator==(const Derived &rhs) const { + return Base::equals(static_cast(rhs)); + } + Derived(int i = 0) : + Base(i) + {} +}; + +//BOOST_CLASS_EXPORT(Derived) + +int +test_main( int /* argc */, char* /* argv */[] ) +{ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + Derived a(1), a1(2); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("a", a); + } + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("a", a1); + } + BOOST_CHECK_EQUAL(a, a1); + std::remove(testfile); + + //Base *ta = static_cast(&a); + //Base *ta1 = NULL; + + Derived *ta = &a; + Derived *ta1 = NULL; + + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("ta", ta); + } + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("ta", ta1); + } + BOOST_CHECK(ta != ta1); + BOOST_CHECK(*ta == *ta1); + //BOOST_CHECK(*static_cast(ta) == *static_cast(ta1)); + + std::remove(testfile); + + return 0; +} -- cgit v1.2.3