]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/performance/performance_polymorphic.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / serialization / performance / performance_polymorphic.cpp
1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // test_polymorphic.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 <fstream>
12
13 #include <cstdio> // remove
14 #include <boost/config.hpp>
15 #if defined(BOOST_NO_STDC_NAMESPACE)
16 namespace std{
17 using ::remove;
18 }
19 #endif
20
21 #include "../test/test_tools.hpp"
22
23 #if !defined(BOOST_ARCHIVE_TEST)
24 #define BOOST_ARCHIVE_TEST polymorphic_text_archive.hpp
25 #endif
26
27 // the following is to ensure that when one of the libraries changes
28 // BJAM rebuilds and relinks the test.
29 /*
30 #include "polymorphic_text_archive.hpp"
31 #include "polymorphic_text_warchive.hpp"
32 #include "polymorphic_binary_archive.hpp"
33 #include "polymorphic_xml_archive.hpp"
34 #include "polymorphic_xml_warchive.hpp"
35 */
36
37 #include <boost/preprocessor/stringize.hpp>
38 // #include <boost/preprocessor/cat.hpp>
39 // the following fails with (only!) gcc 3.4
40 // #include BOOST_PP_STRINGIZE(BOOST_PP_CAT(../test/,BOOST_ARCHIVE_TEST))
41 // just copy over the files from the test directory
42 #include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
43
44 #include <boost/archive/polymorphic_oarchive.hpp>
45 #include <boost/archive/polymorphic_iarchive.hpp>
46
47 #include <boost/serialization/nvp.hpp>
48 #include "../test/test_polymorphic_A.hpp"
49
50 int test_main(int /* argc */, char * /* argv */ [])
51 {
52 const char * testfile = boost::archive::tmpnam(NULL);
53 BOOST_REQUIRE(NULL != testfile);
54 const data d;
55 data d1;
56 // test using using polymorphic interface
57 {
58 test_ostream os(testfile, TEST_STREAM_FLAGS);
59 test_oarchive oa_implementation(os);
60 boost::archive::polymorphic_oarchive & oa_interface = oa_implementation;
61 oa_interface << BOOST_SERIALIZATION_NVP(d);
62 }
63 {
64 test_istream is(testfile, TEST_STREAM_FLAGS);
65 test_iarchive ia_implementation(is);
66 boost::archive::polymorphic_iarchive & ia_interface = ia_implementation;
67 ia_interface >> BOOST_SERIALIZATION_NVP(d1);
68 }
69 BOOST_CHECK(d == d1);
70 std::remove(testfile);
71
72 // test using using polymorphic implementation.
73 {
74 test_ostream os(testfile, TEST_STREAM_FLAGS);
75 test_oarchive oa_implementation(os);
76 oa_implementation << BOOST_SERIALIZATION_NVP(d);
77 }
78 {
79 test_istream is(testfile, TEST_STREAM_FLAGS);
80 test_iarchive ia_implementation(is);
81 ia_implementation >> BOOST_SERIALIZATION_NVP(d1);
82 }
83 BOOST_CHECK(d == d1);
84 std::remove(testfile);
85
86 // test using using polymorphic implementation.
87 {
88 test_ostream os(testfile, TEST_STREAM_FLAGS);
89 boost::archive::polymorphic_oarchive * oa_implementation
90 = new test_oarchive(os);
91 *oa_implementation << BOOST_SERIALIZATION_NVP(d);
92 delete oa_implementation;
93 }
94 {
95 test_istream is(testfile, TEST_STREAM_FLAGS);
96 boost::archive::polymorphic_iarchive * ia_implementation
97 = new test_iarchive(is);
98 *ia_implementation >> BOOST_SERIALIZATION_NVP(d1);
99 delete ia_implementation;
100 }
101 BOOST_CHECK(d == d1);
102 std::remove(testfile);
103 return EXIT_SUCCESS;
104 }