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 <cstddef> // NULL
12#include <cstdio> // remove
13#include <fstream>
14
15#include <boost/config.hpp>
16#if defined(BOOST_NO_STDC_NAMESPACE)
17namespace std{
18 using ::remove;
19}
20#endif
21
22// the following is to ensure that when one of the libraries changes
23// BJAM rebuilds and relinks the test.
24/*
25#include "polymorphic_text_archive.hpp"
26#include "polymorphic_text_warchive.hpp"
27#include "polymorphic_binary_archive.hpp"
28#include "polymorphic_xml_archive.hpp"
29#include "polymorphic_xml_warchive.hpp"
30*/
31
32#include "test_tools.hpp"
33
34#include <boost/archive/polymorphic_oarchive.hpp>
35#include <boost/archive/polymorphic_iarchive.hpp>
36
37#include <boost/serialization/nvp.hpp>
38#include "test_polymorphic_A.hpp"
39
40int test_main(int /* argc */, char * /* argv */ [])
41{
42 const char * testfile = boost::archive::tmpnam(NULL);
43 BOOST_REQUIRE(NULL != testfile);
44 const data d;
45 data d1;
46 // test using using polymorphic interface
47 {
48 test_ostream os(testfile, TEST_STREAM_FLAGS);
49 test_oarchive oa_implementation(os, TEST_ARCHIVE_FLAGS);
50 boost::archive::polymorphic_oarchive & oa_interface = oa_implementation;
51 oa_interface << BOOST_SERIALIZATION_NVP(d);
52 }
53 {
54 test_istream is(testfile, TEST_STREAM_FLAGS);
55 test_iarchive ia_implementation(is, TEST_ARCHIVE_FLAGS);
56 boost::archive::polymorphic_iarchive & ia_interface = ia_implementation;
57 ia_interface >> BOOST_SERIALIZATION_NVP(d1);
58 }
59 BOOST_CHECK(d == d1);
60 std::remove(filename: testfile);
61
62 // test using using polymorphic implementation.
63 {
64 test_ostream os(testfile, TEST_STREAM_FLAGS);
65 test_oarchive oa_implementation(os, TEST_ARCHIVE_FLAGS);
66 oa_implementation << BOOST_SERIALIZATION_NVP(d);
67 }
68 {
69 test_istream is(testfile, TEST_STREAM_FLAGS);
70 test_iarchive ia_implementation(is, TEST_ARCHIVE_FLAGS);
71 ia_implementation >> BOOST_SERIALIZATION_NVP(d1);
72 }
73 BOOST_CHECK(d == d1);
74 std::remove(filename: testfile);
75
76 // test using using polymorphic interface.
77 {
78 test_ostream os(testfile, TEST_STREAM_FLAGS);
79 boost::archive::polymorphic_oarchive * oa_implementation
80 = new test_oarchive(os, TEST_ARCHIVE_FLAGS);
81 *oa_implementation << BOOST_SERIALIZATION_NVP(d);
82 delete oa_implementation;
83 }
84 {
85 test_istream is(testfile, TEST_STREAM_FLAGS);
86 boost::archive::polymorphic_iarchive * ia_implementation
87 = new test_iarchive(is, TEST_ARCHIVE_FLAGS);
88 *ia_implementation >> BOOST_SERIALIZATION_NVP(d1);
89 delete ia_implementation;
90 }
91 BOOST_CHECK(d == d1);
92 std::remove(filename: testfile);
93 return EXIT_SUCCESS;
94}
95

source code of boost/libs/serialization/test/test_polymorphic.cpp