]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_private_base.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / serialization / test / test_private_base.cpp
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // test_private_base.cpp
3
4 // (C) Copyright 2009 Eric Moyer - http://www.rrsd.com .
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 // should pass compilation and execution
10
11 // invoke header for a custom archive test.
12
13 #include <fstream>
14 #include <boost/config.hpp>
15 #if defined(BOOST_NO_STDC_NAMESPACE)
16 namespace std{
17 using ::remove;
18 }
19 #endif
20
21 #include <boost/serialization/access.hpp>
22 #include <boost/serialization/base_object.hpp>
23 #include <boost/serialization/export.hpp>
24
25 #include "test_tools.hpp"
26
27 class Base {
28 friend class boost::serialization::access;
29 int m_i;
30 template<class Archive>
31 void serialize(Archive & ar, const unsigned int version){
32 ar & BOOST_SERIALIZATION_NVP(m_i);
33 }
34 protected:
35 bool equals(const Base &rhs) const {
36 return m_i == rhs.m_i;
37 }
38 Base(int i = 0) :
39 m_i(i)
40 {}
41 public:
42 };
43
44 class Derived : private Base {
45 friend class boost::serialization::access;
46 private:
47 Base & base_cast(){
48 return static_cast<Base &>(*this);
49 }
50 template<class Archive>
51 void serialize(Archive & ar, const unsigned int version){
52 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
53 }
54 public:
55 bool operator==(const Derived &rhs) const {
56 return Base::equals(static_cast<const Base &>(rhs));
57 }
58 Derived(int i = 0) :
59 Base(i)
60 {}
61 };
62
63 int
64 test_main( int /* argc */, char* /* argv */[] )
65 {
66 const char * testfile = boost::archive::tmpnam(NULL);
67 BOOST_REQUIRE(NULL != testfile);
68
69 Derived a(1), a1(2);
70 {
71 test_ostream os(testfile, TEST_STREAM_FLAGS);
72 test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
73 oa << boost::serialization::make_nvp("a", a);
74 }
75 {
76 test_istream is(testfile, TEST_STREAM_FLAGS);
77 test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
78 ia >> boost::serialization::make_nvp("a", a1);
79 }
80 BOOST_CHECK_EQUAL(a, a1);
81 std::remove(testfile);
82
83 return 0;
84 }