1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
2 | // test_contained_class.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> |
12 | #include <fstream> |
13 | |
14 | #include <cstdio> // remove |
15 | #include <boost/config.hpp> |
16 | #if defined(BOOST_NO_STDC_NAMESPACE) |
17 | namespace std{ |
18 | using ::remove; |
19 | } |
20 | #endif |
21 | |
22 | #include "test_tools.hpp" |
23 | #include <boost/serialization/nvp.hpp> |
24 | |
25 | #include "B.hpp" |
26 | #include "A.ipp" |
27 | |
28 | /////////////////////////////////////////////////////// |
29 | // Contained class |
30 | class C |
31 | { |
32 | private: |
33 | friend class boost::serialization::access; |
34 | template<class Archive> |
35 | void serialize(Archive & ar, const unsigned int /* file_version */){ |
36 | ar & BOOST_SERIALIZATION_NVP(b); |
37 | } |
38 | B b; |
39 | public: |
40 | bool operator==(const C &rhs) const |
41 | { |
42 | return b == rhs.b; |
43 | } |
44 | C(){} |
45 | }; |
46 | |
47 | int test_main( int /* argc */, char* /* argv */[] ) |
48 | { |
49 | const char * testfile = boost::archive::tmpnam(NULL); |
50 | BOOST_REQUIRE(NULL != testfile); |
51 | |
52 | const C c; |
53 | C c1; |
54 | { |
55 | test_ostream os(testfile, TEST_STREAM_FLAGS); |
56 | test_oarchive oa(os, TEST_ARCHIVE_FLAGS); |
57 | oa << boost::serialization::make_nvp(n: "c" , v: c); |
58 | } |
59 | { |
60 | test_istream is(testfile, TEST_STREAM_FLAGS); |
61 | test_iarchive ia(is, TEST_ARCHIVE_FLAGS); |
62 | ia >> boost::serialization::make_nvp(n: "c" , v&: c1); |
63 | } |
64 | BOOST_CHECK(c == c1); |
65 | std::remove(filename: testfile); |
66 | return EXIT_SUCCESS; |
67 | } |
68 | |
69 | // EOF |
70 | |