Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/serialization/test/test_polymorphic.cpp @ 20

Last change on this file since 20 was 12, checked in by landauf, 18 years ago

added boost

File size: 2.1 KB
Line 
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)
16namespace std{ 
17    using ::remove;
18}
19#endif
20
21#if !defined(BOOST_ARCHIVE_TEST)
22#define BOOST_ARCHIVE_TEST polymorphic_text_archive.hpp
23#endif
24
25#include "test_tools.hpp"
26#include <boost/preprocessor/stringize.hpp>
27#include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
28
29#include <boost/archive/polymorphic_oarchive.hpp>
30#include <boost/archive/polymorphic_iarchive.hpp>
31
32#include <boost/serialization/nvp.hpp>
33#include "test_polymorphic_A.hpp"
34
35int test_main(int /* argc */, char * /* argv */ [])
36{
37    const char * testfile = boost::archive::tmpnam(NULL);
38    BOOST_REQUIRE(NULL != testfile);
39    const data d;
40    data d1;
41    // test using using polymorphic interface
42    {
43        test_ostream os(testfile, TEST_STREAM_FLAGS);
44        test_oarchive oa_implementation(os);
45        boost::archive::polymorphic_oarchive & oa_interface = oa_implementation;
46        oa_interface << BOOST_SERIALIZATION_NVP(d);
47    }
48    {
49        test_istream is(testfile, TEST_STREAM_FLAGS);
50        test_iarchive  ia_implementation(is);
51        boost::archive::polymorphic_iarchive & ia_interface = ia_implementation;
52        ia_interface >> BOOST_SERIALIZATION_NVP(d1);
53    }
54    BOOST_CHECK(d == d1);
55    std::remove(testfile);
56
57    // test using using polymorphic implementation.
58    {
59        test_ostream os(testfile, TEST_STREAM_FLAGS);
60        test_oarchive oa_implementation(os);
61        oa_implementation << BOOST_SERIALIZATION_NVP(d);
62    }
63    {
64        test_istream is(testfile, TEST_STREAM_FLAGS);
65        test_iarchive  ia_implementation(is);
66        ia_implementation >> BOOST_SERIALIZATION_NVP(d1);
67    }
68    BOOST_CHECK(d == d1);
69    std::remove(testfile);
70
71    return EXIT_SUCCESS;
72}
Note: See TracBrowser for help on using the repository browser.