]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_dll_exported.cpp
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // test_dll_exported.cpp
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
11 // This is an overly complex test. The purpose of this test is to
12 // demostrate and test the ability to serialize a hiarchy of class
13 // through a base class pointer even though those class might be
14 // implemente in different dlls and use different extended type info
17 // polymorphic_ base is locally declared and defined. It use the
18 // "no_rtti" extended type info system.
20 // polymorphic_derived1 is locally declared and defined. It uses
21 // the default "type_id" extended type info system
23 // polymorphic_derived2 is declared in polymorphic_derived.hpp
24 // and defined in dll_polymorphic_derived2. It uses the typeid
27 #include <cstddef> // NULL
30 #include <cstdio> // remove
31 #include <boost/config.hpp>
32 #if defined(BOOST_NO_STDC_NAMESPACE)
38 // for now, only test with simple text archive
39 #define BOOST_ARCHIVE_TEST text_archive.hpp
40 #include "test_tools.hpp"
42 #include <boost/archive/archive_exception.hpp>
44 #include <boost/serialization/base_object.hpp>
45 #include <boost/serialization/export.hpp>
46 #include <boost/serialization/access.hpp>
48 #include "polymorphic_base.hpp"
50 class polymorphic_derived1
: public polymorphic_base
52 friend class boost::serialization::access
;
53 template<class Archive
>
54 void serialize(Archive
&ar
, const unsigned int /* file_version */){
55 ar
& BOOST_SERIALIZATION_BASE_OBJECT_NVP(polymorphic_base
);
57 virtual const char * get_key() const {
58 return "polymorphic_derived1";
61 virtual ~polymorphic_derived1(){}
64 BOOST_CLASS_EXPORT_KEY(polymorphic_derived1
)
65 BOOST_CLASS_EXPORT_IMPLEMENT(polymorphic_derived1
)
67 // MWerks users can do this to make their code work
68 BOOST_SERIALIZATION_MWERKS_BASE_AND_DERIVED(polymorphic_base
, polymorphic_derived1
)
70 #define POLYMORPHIC_DERIVED2_IMPORT
71 #include "polymorphic_derived2.hpp"
73 // save exported polymorphic class
74 void save_exported(const char *testfile
)
76 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
77 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
79 polymorphic_base
*rb1
= new polymorphic_derived1
;
80 polymorphic_base
*rb2
= new polymorphic_derived2
;
81 polymorphic_derived2
*rd21
= new polymorphic_derived2
;
83 // export will permit correct serialization
84 // through a pointer to a base class
85 oa
<< BOOST_SERIALIZATION_NVP(rb1
);
86 oa
<< BOOST_SERIALIZATION_NVP(rb2
);
87 oa
<< BOOST_SERIALIZATION_NVP(rd21
);
94 // save exported polymorphic class
95 void load_exported(const char *testfile
)
97 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
98 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
100 polymorphic_base
*rb1
= NULL
;
101 polymorphic_base
*rb2
= NULL
;
102 polymorphic_derived2
*rd21
= NULL
;
104 // export will permit correct serialization
105 // through a pointer to a base class
106 ia
>> BOOST_SERIALIZATION_NVP(rb1
);
108 boost::serialization::type_info_implementation
<polymorphic_derived1
>
109 ::type::get_const_instance()
111 * boost::serialization::type_info_implementation
<polymorphic_base
>
112 ::type::get_const_instance().get_derived_extended_type_info(*rb1
),
113 "restored pointer b1 not of correct type"
115 ia
>> BOOST_SERIALIZATION_NVP(rb2
);
117 boost::serialization::type_info_implementation
<polymorphic_derived2
>
118 ::type::get_const_instance()
120 * boost::serialization::type_info_implementation
<polymorphic_base
>
121 ::type::get_const_instance().get_derived_extended_type_info(*rb2
),
122 "restored pointer b2 not of correct type"
124 ia
>> BOOST_SERIALIZATION_NVP(rd21
);
126 boost::serialization::type_info_implementation
<polymorphic_derived2
>
127 ::type::get_const_instance()
129 * boost::serialization::type_info_implementation
<polymorphic_derived2
>
130 ::type::get_const_instance().get_derived_extended_type_info(*rd21
),
131 "restored pointer d2 not of correct type"
139 test_main( int /* argc */, char* /* argv */[] )
141 const char * testfile
= boost::archive::tmpnam(NULL
);
142 BOOST_REQUIRE(NULL
!= testfile
);
144 save_exported(testfile
);
145 load_exported(testfile
);
146 std::remove(testfile
);