Ticket #5265: test_unordered.patch
File test_unordered.patch, 7.0 KB (added by , 12 years ago) |
---|
-
libs/serialization/test/test_map.cpp
147 147 template<> 148 148 struct hash<random_key>{ 149 149 std::size_t operator()(const random_key& r) const { 150 return (std::size_t)r;150 return static_cast<std::size_t>(r); 151 151 } 152 152 }; 153 153 } // namespace BOOST_STD_EXTENSION_NAMESPACE … … 216 216 } 217 217 #endif 218 218 219 #include <boost/serialization/unordered_map.hpp> 220 #include <boost/tr1/functional.hpp> // requires changeset [69520]; Ticket #5254 221 222 namespace std { 223 namespace tr1 { 224 225 template<> 226 struct hash<random_key>{ 227 std::size_t operator()(const random_key& r) const { 228 return static_cast<std::size_t>(r); 229 } 230 }; 231 } // namespace tr1 232 } // namespace std 233 234 void 235 test_unordered_map(){ 236 const char * testfile = boost::archive::tmpnam(NULL); 237 BOOST_REQUIRE(NULL != testfile); 238 239 BOOST_CHECKPOINT("unordered_map"); 240 // test unordered_map of objects 241 std::tr1::unordered_map<random_key, A> anunordered_map; 242 anunordered_map.insert(std::make_pair(random_key(), A())); 243 anunordered_map.insert(std::make_pair(random_key(), A())); 244 { 245 test_ostream os(testfile, TEST_STREAM_FLAGS); 246 test_oarchive oa(os, TEST_ARCHIVE_FLAGS); 247 oa << boost::serialization::make_nvp("anunorderedmap",anunordered_map); 248 } 249 std::tr1::unordered_map<random_key, A> anunordered_map1; 250 { 251 test_istream is(testfile, TEST_STREAM_FLAGS); 252 test_iarchive ia(is, TEST_ARCHIVE_FLAGS); 253 ia >> boost::serialization::make_nvp("anunorderedmap",anunordered_map1); 254 } 255 256 std::vector< std::pair<random_key, A> > tvec, tvec1; 257 std::copy(anunordered_map.begin(), anunordered_map.end(), std::back_inserter(tvec)); 258 std::sort(tvec.begin(), tvec.end()); 259 std::copy(anunordered_map1.begin(), anunordered_map1.end(), std::back_inserter(tvec1)); 260 std::sort(tvec1.begin(), tvec1.end()); 261 BOOST_CHECK(tvec == tvec1); 262 263 std::remove(testfile); 264 } 265 266 void 267 test_unordered_multimap(){ 268 const char * testfile = boost::archive::tmpnam(NULL); 269 BOOST_REQUIRE(NULL != testfile); 270 271 BOOST_CHECKPOINT("unordered_multimap"); 272 std::tr1::unordered_multimap<random_key, A> anunordered_multimap; 273 anunordered_multimap.insert(std::make_pair(random_key(), A())); 274 anunordered_multimap.insert(std::make_pair(random_key(), A())); 275 { 276 test_ostream os(testfile, TEST_STREAM_FLAGS); 277 test_oarchive oa(os, TEST_ARCHIVE_FLAGS); 278 oa << boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap); 279 } 280 std::tr1::unordered_multimap<random_key, A> anunordered_multimap1; 281 { 282 test_istream is(testfile, TEST_STREAM_FLAGS); 283 test_iarchive ia(is, TEST_ARCHIVE_FLAGS); 284 ia >> boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap1); 285 } 286 std::vector< std::pair<random_key, A> > tvec, tvec1; 287 tvec.clear(); 288 tvec1.clear(); 289 std::copy(anunordered_multimap.begin(), anunordered_multimap.end(), std::back_inserter(tvec)); 290 std::sort(tvec.begin(), tvec.end()); 291 std::copy(anunordered_multimap1.begin(), anunordered_multimap1.end(), std::back_inserter(tvec1)); 292 std::sort(tvec1.begin(), tvec1.end()); 293 BOOST_CHECK(tvec == tvec1); 294 std::remove(testfile); 295 } 296 297 219 298 int test_main( int /* argc */, char* /* argv */[] ) 220 299 { 221 300 test_map(); … … 225 304 test_hash_map(); 226 305 test_hash_multimap(); 227 306 #endif 307 test_unordered_map(); 308 test_unordered_multimap(); 228 309 return EXIT_SUCCESS; 229 310 } -
libs/serialization/test/test_set.cpp
94 94 template<> 95 95 struct hash<A> { 96 96 std::size_t operator()(const A& a) const { 97 return (std::size_t)a;97 return static_cast<std::size_t>(a); 98 98 } 99 99 }; 100 100 } … … 164 164 } 165 165 #endif 166 166 167 #include <boost/serialization/unordered_set.hpp> 168 #include <boost/tr1/functional.hpp> // requires changeset [69520]; Ticket #5254 169 170 171 namespace std { 172 namespace tr1 { 173 template<> 174 struct hash<A> { 175 std::size_t operator()(const A& a) const { 176 return static_cast<std::size_t>(a); 177 } 178 }; 179 } // namespace tr1 180 } // namespace std 181 182 void 183 test_unordered_set(){ 184 const char * testfile = boost::archive::tmpnam(NULL); 185 BOOST_REQUIRE(NULL != testfile); 186 187 // test array of objects 188 std::tr1::unordered_set<A> anunordered_set; 189 A a, a1; 190 anunordered_set.insert(a); 191 anunordered_set.insert(a1); 192 { 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); 196 } 197 std::tr1::unordered_set<A> anunordered_set1; 198 { 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); 202 } 203 std::vector<A> tvec, tvec1; 204 tvec.clear(); 205 tvec1.clear(); 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); 212 } 213 214 void 215 test_unordered_multiset(){ 216 const char * testfile = boost::archive::tmpnam(NULL); 217 BOOST_REQUIRE(NULL != testfile); 218 219 std::tr1::unordered_multiset<A> anunordered_multiset; 220 anunordered_multiset.insert(A()); 221 anunordered_multiset.insert(A()); 222 { 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); 226 } 227 std::tr1::unordered_multiset<A> anunordered_multiset1; 228 { 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); 232 } 233 234 std::vector<A> tvec, tvec1; 235 tvec.clear(); 236 tvec1.clear(); 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); 242 243 std::remove(testfile); 244 } 245 246 167 247 int test_main( int /* argc */, char* /* argv */[] ) 168 248 { 169 249 test_set(); … … 172 252 test_hash_set(); 173 253 test_hash_multiset(); 174 254 #endif 255 test_unordered_set(); 256 test_unordered_multiset(); 175 257 return EXIT_SUCCESS; 176 258 }