]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_exported.cpp
5e59cef16a83ab5ad8b09f991aeb6e069c4c1815
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
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)
9 // should pass compilation and execution
14 #include <boost/config.hpp>
15 #include <cstdio> // remove
16 #if defined(BOOST_NO_STDC_NAMESPACE)
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>
27 #include <boost/serialization/force_include.hpp>
29 #include <boost/archive/archive_exception.hpp>
30 #include "test_tools.hpp"
32 #include "polymorphic_base.hpp"
34 class polymorphic_derived1
:
35 public polymorphic_base
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
);
42 virtual const char * get_key() const {
43 return "polymorphic_derived1";
46 ~polymorphic_derived1(){}
49 BOOST_CLASS_EXPORT(polymorphic_derived1
)
51 // MWerks users can do this to make their code work
52 BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base
, polymorphic_derived1
)
54 #include "polymorphic_derived2.hpp"
56 // MWerks users can do this to make their code work
57 BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base
, polymorphic_derived2
)
59 BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_derived2
)
61 template void polymorphic_derived2::serialize(
63 const unsigned int version
65 template void polymorphic_derived2::serialize(
67 const unsigned int version
70 // save exported polymorphic class
71 void save_exported(const char *testfile
)
73 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
74 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
76 polymorphic_base
*rb1
= new polymorphic_derived1
;
77 polymorphic_base
*rb2
= new polymorphic_derived2
;
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
);
88 // save exported polymorphic class
89 void load_exported(const char *testfile
)
91 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
92 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
94 polymorphic_base
*rb1
= NULL
;
95 polymorphic_base
*rb2
= NULL
;
97 // export will permit correct serialization
98 // through a pointer to a base class
99 ia
>> BOOST_SERIALIZATION_NVP(rb1
);
101 boost::serialization::type_info_implementation
<polymorphic_derived1
>
102 ::type::get_const_instance()
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"
109 ia
>> BOOST_SERIALIZATION_NVP(rb2
);
111 boost::serialization::type_info_implementation
<polymorphic_derived2
>
112 ::type::get_const_instance()
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"
124 test_main( int /* argc */, char* /* argv */[] )
126 const char * testfile
= boost::archive::tmpnam(NULL
);
127 BOOST_REQUIRE(NULL
!= testfile
);
129 save_exported(testfile
);
130 load_exported(testfile
);
131 std::remove(testfile
);