1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
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)
10 // should pass compilation and execution
12 #include <cstddef> // NULLsize_t
13 #include <cstdio> // remove
16 #include <algorithm> // std::copy
19 #include <boost/config.hpp>
20 #if defined(BOOST_NO_STDC_NAMESPACE)
26 #include <boost/detail/workaround.hpp>
27 #if defined(BOOST_NO_STDC_NAMESPACE)
33 #include <boost/archive/archive_exception.hpp>
35 #include "test_tools.hpp"
37 #include <boost/serialization/nvp.hpp>
38 #include <boost/serialization/set.hpp>
45 const char * testfile
= boost::archive::tmpnam(NULL
);
46 BOOST_REQUIRE(NULL
!= testfile
);
48 // test array of objects
53 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
54 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
55 oa
<< boost::serialization::make_nvp("aset", aset
);
59 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
60 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
61 ia
>> boost::serialization::make_nvp("aset", aset1
);
63 BOOST_CHECK(aset
== aset1
);
64 std::remove(testfile
);
69 const char * testfile
= boost::archive::tmpnam(NULL
);
70 BOOST_REQUIRE(NULL
!= testfile
);
72 std::multiset
<A
> amultiset
;
73 amultiset
.insert(A());
74 amultiset
.insert(A());
76 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
77 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
78 oa
<< boost::serialization::make_nvp("amultiset", amultiset
);
80 std::multiset
<A
> amultiset1
;
82 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
83 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
84 ia
>> boost::serialization::make_nvp("amultiset", amultiset1
);
86 BOOST_CHECK(amultiset
== amultiset1
);
87 std::remove(testfile
);
92 #include <boost/serialization/hash_set.hpp>
94 namespace BOOST_STD_EXTENSION_NAMESPACE
{
97 std::size_t operator()(const A
& a
) const {
98 return static_cast<std::size_t>(a
);
105 const char * testfile
= boost::archive::tmpnam(NULL
);
106 BOOST_REQUIRE(NULL
!= testfile
);
108 // test array of objects
109 BOOST_STD_EXTENSION_NAMESPACE::hash_set
<A
> ahash_set
;
112 ahash_set
.insert(a1
);
114 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
115 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
116 oa
<< boost::serialization::make_nvp("ahash_set", ahash_set
);
118 BOOST_STD_EXTENSION_NAMESPACE::hash_set
<A
> ahash_set1
;
120 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
121 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
122 ia
>> boost::serialization::make_nvp("ahash_set", ahash_set1
);
124 std::vector
<A
> tvec
, tvec1
;
127 std::copy(ahash_set
.begin(), ahash_set
.end(), std::back_inserter(tvec
));
128 std::sort(tvec
.begin(), tvec
.end());
129 std::copy(ahash_set1
.begin(), ahash_set1
.end(), std::back_inserter(tvec1
));
130 std::sort(tvec1
.begin(), tvec1
.end());
131 BOOST_CHECK(tvec
== tvec1
);
132 std::remove(testfile
);
136 test_hash_multiset(){
137 const char * testfile
= boost::archive::tmpnam(NULL
);
138 BOOST_REQUIRE(NULL
!= testfile
);
140 BOOST_STD_EXTENSION_NAMESPACE::hash_multiset
<A
> ahash_multiset
;
141 ahash_multiset
.insert(A());
142 ahash_multiset
.insert(A());
144 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
145 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
146 oa
<< boost::serialization::make_nvp("ahash_multiset", ahash_multiset
);
148 BOOST_STD_EXTENSION_NAMESPACE::hash_multiset
<A
> ahash_multiset1
;
150 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
151 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
152 ia
>> boost::serialization::make_nvp("ahash_multiset", ahash_multiset1
);
155 std::vector
<A
> tvec
, tvec1
;
158 std::copy(ahash_multiset
.begin(), ahash_multiset
.end(), std::back_inserter(tvec
));
159 std::sort(tvec
.begin(), tvec
.end());
160 std::copy(ahash_multiset1
.begin(), ahash_multiset1
.end(), std::back_inserter(tvec1
));
161 std::sort(tvec1
.begin(), tvec1
.end());
162 BOOST_CHECK(tvec
== tvec1
);
164 std::remove(testfile
);
168 #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET
170 #include <boost/serialization/unordered_set.hpp>
171 #include <functional> // requires changeset [69520]; Ticket #5254
176 std::size_t operator()(const A
& a
) const {
177 return static_cast<std::size_t>(a
);
183 test_unordered_set(){
184 const char * testfile
= boost::archive::tmpnam(NULL
);
185 BOOST_REQUIRE(NULL
!= testfile
);
187 // test array of objects
188 std::unordered_set
<A
> anunordered_set
;
190 anunordered_set
.insert(a
);
191 anunordered_set
.insert(a1
);
193 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
194 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
195 oa
<< boost::serialization::make_nvp("anunordered_set", anunordered_set
);
197 std::unordered_set
<A
> anunordered_set1
;
199 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
200 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
201 ia
>> boost::serialization::make_nvp("anunordered_set", anunordered_set1
);
203 std::vector
<A
> tvec
, tvec1
;
206 std::copy(anunordered_set
.begin(), anunordered_set
.end(), std::back_inserter(tvec
));
207 std::sort(tvec
.begin(), tvec
.end());
208 std::copy(anunordered_set1
.begin(), anunordered_set1
.end(), std::back_inserter(tvec1
));
209 std::sort(tvec1
.begin(), tvec1
.end());
210 BOOST_CHECK(tvec
== tvec1
);
211 std::remove(testfile
);
215 test_unordered_multiset(){
216 const char * testfile
= boost::archive::tmpnam(NULL
);
217 BOOST_REQUIRE(NULL
!= testfile
);
219 std::unordered_multiset
<A
> anunordered_multiset
;
220 anunordered_multiset
.insert(A());
221 anunordered_multiset
.insert(A());
223 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
224 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
225 oa
<< boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset
);
227 std::unordered_multiset
<A
> anunordered_multiset1
;
229 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
230 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
231 ia
>> boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset1
);
234 std::vector
<A
> tvec
, tvec1
;
237 std::copy(anunordered_multiset
.begin(), anunordered_multiset
.end(), std::back_inserter(tvec
));
238 std::sort(tvec
.begin(), tvec
.end());
239 std::copy(anunordered_multiset1
.begin(), anunordered_multiset1
.end(), std::back_inserter(tvec1
));
240 std::sort(tvec1
.begin(), tvec1
.end());
241 BOOST_CHECK(tvec
== tvec1
);
243 std::remove(testfile
);
247 int test_main( int /* argc */, char* /* argv */[] ){
251 #ifdef BOOST_HAS_HASH
253 test_hash_multiset();
256 #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET
257 test_unordered_set();
258 test_unordered_multiset();