]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_exported.cpp
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/type_info_implementation.hpp>
23 #include <boost/serialization/export.hpp>
24 #include <boost/serialization/base_object.hpp>
26 #include "test_tools.hpp"
28 #include <boost/archive/polymorphic_oarchive.hpp>
29 #include <boost/archive/polymorphic_iarchive.hpp>
31 #include "polymorphic_derived1.hpp"
32 #include "polymorphic_derived2.hpp"
34 // save exported polymorphic class
35 void save_exported(const char *testfile
)
37 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
38 test_oarchive
oa_implementation(os
, TEST_ARCHIVE_FLAGS
);
39 boost::archive::polymorphic_oarchive
& oa_interface
= oa_implementation
;
41 const polymorphic_base
*rb1
= new polymorphic_derived1
;
42 const polymorphic_base
*rb2
= new polymorphic_derived2
;
44 // export will permit correct serialization
45 // through a pointer to a base class
46 std::cout
<< "saving polymorphic_derived1 (no_rtti)\n";
47 oa_interface
<< BOOST_SERIALIZATION_NVP(rb1
);
49 std::cout
<< "saving polymorphic_derived2\n";
50 oa_interface
<< BOOST_SERIALIZATION_NVP(rb2
);
56 // save exported polymorphic class
57 void load_exported(const char *testfile
)
59 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
60 test_iarchive
ia_implementation(is
, TEST_ARCHIVE_FLAGS
);
61 boost::archive::polymorphic_iarchive
& ia_interface
= ia_implementation
;
63 polymorphic_base
*rb1
= NULL
;
64 polymorphic_base
*rb2
= NULL
;
66 // export will permit correct serialization
67 // through a pointer to a base class
68 ia_interface
>> BOOST_SERIALIZATION_NVP(rb1
);
70 boost::serialization::type_info_implementation
<polymorphic_derived1
>
71 ::type::get_const_instance()
73 * boost::serialization::type_info_implementation
<polymorphic_base
>
74 ::type::get_const_instance().get_derived_extended_type_info(*rb1
),
75 "restored pointer b1 not of correct type"
78 ia_interface
>> BOOST_SERIALIZATION_NVP(rb2
);
80 boost::serialization::type_info_implementation
<polymorphic_derived2
>
81 ::type::get_const_instance()
83 * boost::serialization::type_info_implementation
<polymorphic_base
>
84 ::type::get_const_instance().get_derived_extended_type_info(*rb2
),
85 "restored pointer b2 not of correct type"
93 test_main( int /* argc */, char* /* argv */[] )
95 const char * testfile
= boost::archive::tmpnam(NULL
);
96 BOOST_REQUIRE(NULL
!= testfile
);
98 save_exported(testfile
);
99 load_exported(testfile
);
100 std::remove(testfile
);