| 1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
| 2 | // test_set.cpp |
| 3 | |
| 4 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . |
| 5 | // (C) Copyright 2014 Jim Bell |
| 6 | // Use, modification and distribution is subject to the Boost Software |
| 7 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 8 | // http://www.boost.org/LICENSE_1_0.txt) |
| 9 | |
| 10 | // should pass compilation and execution |
| 11 | |
| 12 | #include <cstddef> // NULLsize_t |
| 13 | #include <cstdio> // remove |
| 14 | #include <fstream> |
| 15 | |
| 16 | #include <algorithm> // std::copy |
| 17 | #include <vector> |
| 18 | |
| 19 | #include <boost/config.hpp> |
| 20 | #if defined(BOOST_NO_STDC_NAMESPACE) |
| 21 | namespace std{ |
| 22 | using ::size_t; |
| 23 | } |
| 24 | #endif |
| 25 | |
| 26 | #include <boost/detail/workaround.hpp> |
| 27 | #if defined(BOOST_NO_STDC_NAMESPACE) |
| 28 | namespace std{ |
| 29 | using ::remove; |
| 30 | } |
| 31 | #endif |
| 32 | |
| 33 | #include <boost/archive/archive_exception.hpp> |
| 34 | |
| 35 | #include "test_tools.hpp" |
| 36 | |
| 37 | #include <boost/serialization/nvp.hpp> |
| 38 | #include <boost/serialization/set.hpp> |
| 39 | |
| 40 | #include "A.hpp" |
| 41 | #include "A.ipp" |
| 42 | |
| 43 | void |
| 44 | test_set(){ |
| 45 | const char * testfile = boost::archive::tmpnam(NULL); |
| 46 | BOOST_REQUIRE(NULL != testfile); |
| 47 | |
| 48 | // test array of objects |
| 49 | std::set<A> aset; |
| 50 | aset.insert(x: A()); |
| 51 | aset.insert(x: A()); |
| 52 | const A * a_ptr = & * aset.begin(); |
| 53 | { |
| 54 | test_ostream os(testfile, TEST_STREAM_FLAGS); |
| 55 | test_oarchive oa(os, TEST_ARCHIVE_FLAGS); |
| 56 | oa << boost::serialization::make_nvp(n: "aset" , v&: aset); |
| 57 | // serialize a pointer into the set |
| 58 | oa << boost::serialization::make_nvp(n: "a_ptr" , v&: a_ptr); |
| 59 | } |
| 60 | std::set<A> aset1; |
| 61 | A * a_ptr1; |
| 62 | { |
| 63 | test_istream is(testfile, TEST_STREAM_FLAGS); |
| 64 | test_iarchive ia(is, TEST_ARCHIVE_FLAGS); |
| 65 | ia >> boost::serialization::make_nvp(n: "aset" , v&: aset1); |
| 66 | // deserialize a pointer into the set |
| 67 | ia >> boost::serialization::make_nvp(n: "a_ptr1" , v&: a_ptr1); |
| 68 | } |
| 69 | BOOST_CHECK_EQUAL(aset, aset1); |
| 70 | BOOST_CHECK_EQUAL(*a_ptr1, * aset1.begin()); |
| 71 | BOOST_CHECK_EQUAL(a_ptr1, & * aset1.begin()); |
| 72 | std::remove(filename: testfile); |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | test_multiset(){ |
| 77 | const char * testfile = boost::archive::tmpnam(NULL); |
| 78 | BOOST_REQUIRE(NULL != testfile); |
| 79 | |
| 80 | std::multiset<A> amultiset; |
| 81 | amultiset.insert(x: A()); |
| 82 | amultiset.insert(x: A()); |
| 83 | const A * a_ptr = & * amultiset.begin(); |
| 84 | { |
| 85 | test_ostream os(testfile, TEST_STREAM_FLAGS); |
| 86 | test_oarchive oa(os, TEST_ARCHIVE_FLAGS); |
| 87 | oa << boost::serialization::make_nvp(n: "amultiset" , v&: amultiset); |
| 88 | // serialize a pointer into the set |
| 89 | oa << boost::serialization::make_nvp(n: "a_ptr" , v&: a_ptr); |
| 90 | } |
| 91 | std::multiset<A> amultiset1; |
| 92 | A * a_ptr1; |
| 93 | { |
| 94 | test_istream is(testfile, TEST_STREAM_FLAGS); |
| 95 | test_iarchive ia(is, TEST_ARCHIVE_FLAGS); |
| 96 | ia >> boost::serialization::make_nvp(n: "amultiset" , v&: amultiset1); |
| 97 | // deserialize a pointer into the set |
| 98 | ia >> boost::serialization::make_nvp(n: "a_ptr1" , v&: a_ptr1); |
| 99 | } |
| 100 | BOOST_CHECK(amultiset == amultiset1); |
| 101 | BOOST_CHECK_EQUAL(*a_ptr1, * amultiset1.begin()); |
| 102 | BOOST_CHECK_EQUAL(a_ptr1, & * amultiset1.begin()); |
| 103 | std::remove(filename: testfile); |
| 104 | } |
| 105 | |
| 106 | int test_main( int /* argc */, char* /* argv */[] ){ |
| 107 | test_set(); |
| 108 | test_multiset(); |
| 109 | |
| 110 | return EXIT_SUCCESS; |
| 111 | } |
| 112 | |