mirror of
https://github.com/boostorg/serialization.git
synced 2026-01-30 08:12:09 +00:00
add test for map::value_type
[SVN r30803]
This commit is contained in:
@@ -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<int, int> a(11, 22);
|
||||
std::map<int, int> b;
|
||||
b[0] = 0;
|
||||
b[-1] = -1;
|
||||
b[1] = 1;
|
||||
{
|
||||
test_ostream os(testfile, TEST_STREAM_FLAGS);
|
||||
std::pair<int, int> * const pa = &a;
|
||||
std::map<int, int> * 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<int, int> *pa = 0;
|
||||
std::map<int, int> *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<random_key, A> 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<random_key, A> 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<random_key, A> 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<random_key, A> > 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user