]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_exported.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / serialization / test / test_exported.cpp
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // test_exported.cpp
3
4 // (C) Copyright 2002 Robert Ramey - 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 #include <cstddef>
12 #include <fstream>
13
14 #include <boost/config.hpp>
15 #include <cstdio> // remove
16 #if defined(BOOST_NO_STDC_NAMESPACE)
17 namespace std{
18 using ::remove;
19 }
20 #endif
21
22 #include <boost/serialization/export.hpp>
23 #include <boost/serialization/base_object.hpp>
24 #include <boost/serialization/type_info_implementation.hpp>
25 #include <boost/serialization/extended_type_info_typeid.hpp>
26
27 #include <boost/serialization/force_include.hpp>
28
29 #include <boost/archive/archive_exception.hpp>
30 #include "test_tools.hpp"
31
32 #include "polymorphic_base.hpp"
33
34 class polymorphic_derived1 :
35 public polymorphic_base
36 {
37 friend class boost::serialization::access;
38 template<class Archive>
39 void serialize(Archive & ar, const unsigned int /* file_version */){
40 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base);
41 }
42 virtual const char * get_key() const {
43 return "polymorphic_derived1";
44 }
45 public:
46 ~polymorphic_derived1(){}
47 };
48
49 BOOST_CLASS_EXPORT(polymorphic_derived1)
50
51 // MWerks users can do this to make their code work
52 BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived1)
53
54 #include "polymorphic_derived2.hpp"
55
56 // MWerks users can do this to make their code work
57 BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base, polymorphic_derived2)
58
59 BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_derived2)
60
61 template void polymorphic_derived2::serialize(
62 test_oarchive & ar,
63 const unsigned int version
64 );
65 template void polymorphic_derived2::serialize(
66 test_iarchive & ar,
67 const unsigned int version
68 );
69
70 // save exported polymorphic class
71 void save_exported(const char *testfile)
72 {
73 test_ostream os(testfile, TEST_STREAM_FLAGS);
74 test_oarchive oa(os, TEST_ARCHIVE_FLAGS);
75
76 polymorphic_base *rb1 = new polymorphic_derived1;
77 polymorphic_base *rb2 = new polymorphic_derived2;
78
79 // export will permit correct serialization
80 // through a pointer to a base class
81 oa << BOOST_SERIALIZATION_NVP(rb1);
82 oa << BOOST_SERIALIZATION_NVP(rb2);
83
84 delete rb1;
85 delete rb2;
86 }
87
88 // save exported polymorphic class
89 void load_exported(const char *testfile)
90 {
91 test_istream is(testfile, TEST_STREAM_FLAGS);
92 test_iarchive ia(is, TEST_ARCHIVE_FLAGS);
93
94 polymorphic_base *rb1 = NULL;
95 polymorphic_base *rb2 = NULL;
96
97 // export will permit correct serialization
98 // through a pointer to a base class
99 ia >> BOOST_SERIALIZATION_NVP(rb1);
100 BOOST_CHECK_MESSAGE(
101 boost::serialization::type_info_implementation<polymorphic_derived1>
102 ::type::get_const_instance()
103 ==
104 * boost::serialization::type_info_implementation<polymorphic_base>
105 ::type::get_const_instance().get_derived_extended_type_info(*rb1),
106 "restored pointer b1 not of correct type"
107 );
108
109 ia >> BOOST_SERIALIZATION_NVP(rb2);
110 BOOST_CHECK_MESSAGE(
111 boost::serialization::type_info_implementation<polymorphic_derived2>
112 ::type::get_const_instance()
113 ==
114 * boost::serialization::type_info_implementation<polymorphic_base>
115 ::type::get_const_instance().get_derived_extended_type_info(*rb2),
116 "restored pointer b2 not of correct type"
117 );
118
119 delete rb1;
120 delete rb2;
121 }
122
123 int
124 test_main( int /* argc */, char* /* argv */[] )
125 {
126 const char * testfile = boost::archive::tmpnam(NULL);
127 BOOST_REQUIRE(NULL != testfile);
128
129 save_exported(testfile);
130 load_exported(testfile);
131 std::remove(testfile);
132 return EXIT_SUCCESS;
133 }
134
135 // EOF