diff --git a/test/test_map.cpp b/test/test_map.cpp index aaff4022..6f8dd233 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -83,8 +83,8 @@ namespace BOOST_STD_EXTENSION_NAMESPACE { #endif -int test_main( int /* argc */, char* /* argv */[] ) -{ +void +test_map(){ const char * testfile = boost::archive::tmpnam(NULL); BOOST_REQUIRE(NULL != testfile); @@ -105,6 +105,45 @@ int test_main( int /* argc */, char* /* argv */[] ) ia >> boost::serialization::make_nvp("amap", amap1); } BOOST_CHECK(amap == amap1); + std::remove(testfile); +} + +void +test_map_2(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_CHECKPOINT("map_2"); + std::pair a(11, 22); + std::map b; + b[0] = 0; + b[-1] = -1; + b[1] = 1; + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + std::pair * const pa = &a; + std::map * const pb = &b; + test_oarchive oa(os); + oa << BOOST_SERIALIZATION_NVP(pb); + oa << BOOST_SERIALIZATION_NVP(pa); + } + { + test_istream is(testfile, TEST_STREAM_FLAGS); + std::pair *pa = 0; + std::map *pb = 0; + test_iarchive ia(is); + ia >> BOOST_SERIALIZATION_NVP(pb); + ia >> BOOST_SERIALIZATION_NVP(pa); + delete pa; + delete pb; + } + std::remove(testfile); +} + +void +test_multimap(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); BOOST_CHECKPOINT("multimap"); std::multimap amultimap; @@ -122,8 +161,15 @@ int test_main( int /* argc */, char* /* argv */[] ) ia >> boost::serialization::make_nvp("amultimap", amultimap1); } BOOST_CHECK(amultimap == amultimap1); + std::remove(testfile); +} +void +test_hash_map(){ #ifdef BOOST_HAS_HASH + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + BOOST_CHECKPOINT("hash_map"); // test hash_map of objects BOOST_STD_EXTENSION_NAMESPACE::hash_map ahash_map; @@ -150,7 +196,16 @@ int test_main( int /* argc */, char* /* argv */[] ) std::copy(ahash_map1.begin(), ahash_map1.end(), std::back_inserter(tvec1)); std::sort(tvec1.begin(), tvec1.end()); BOOST_CHECK(tvec == tvec1); - + std::remove(testfile); + #endif +} + +void +test_hash_multimap(){ + #ifdef BOOST_HAS_HASH + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + BOOST_CHECKPOINT("hash_multimap"); BOOST_STD_EXTENSION_NAMESPACE::hash_multimap ahash_multimap; ahash_multimap.insert(std::make_pair(random_key(), A())); @@ -170,6 +225,7 @@ int test_main( int /* argc */, char* /* argv */[] ) // to implement the == operator for hash collections - but goes ahead // does it anyway even though it doesn't seem to work. So sort into // vectors and then compare. + std::vector< std::pair > tvec, tvec1; tvec.clear(); tvec1.clear(); std::copy(ahash_multimap.begin(), ahash_multimap.end(), std::back_inserter(tvec)); @@ -177,8 +233,16 @@ int test_main( int /* argc */, char* /* argv */[] ) std::copy(ahash_multimap1.begin(), ahash_multimap1.end(), std::back_inserter(tvec1)); std::sort(tvec1.begin(), tvec1.end()); BOOST_CHECK(tvec == tvec1); - #endif - std::remove(testfile); + #endif +} + +int test_main( int /* argc */, char* /* argv */[] ) +{ + test_map(); + test_map_2(); + test_multimap(); + test_hash_map(); + test_hash_multimap(); return EXIT_SUCCESS; }