#include "common.hpp" template void test_map() { std::random_device rd; std::mt19937 gen(rd()); for(int ii=0; ii<100; ++ii) { std::map> o_vectormap; for(int j=0; j<10; ++j) { size_t id = random_value(gen); for(int k=0; k<100; ++k) o_vectormap[id].emplace_back(random_value(gen), random_value(gen)); } std::map o_podmap; for(int j=0; j<100; ++j) o_podmap.insert({random_value(gen), random_value(gen)}); std::map o_isermap; for(int j=0; j<100; ++j) o_isermap.insert({random_value(gen), { random_value(gen), random_value(gen) }}); std::map o_isplmap; for(int j=0; j<100; ++j) o_isplmap.insert({random_value(gen), { random_value(gen), random_value(gen) }}); std::map o_esermap; for(int j=0; j<100; ++j) o_esermap.insert({random_value(gen), { random_value(gen), random_value(gen) }}); std::map o_esplmap; for(int j=0; j<100; ++j) o_esplmap.insert({random_value(gen), { random_value(gen), random_value(gen) }}); std::ostringstream os; { OArchive oar(os); oar(o_vectormap); oar(o_podmap); oar(o_isermap); oar(o_isplmap); oar(o_esermap); oar(o_esplmap); } std::map> i_vectormap; std::map i_podmap; std::map i_isermap; std::map i_isplmap; std::map i_esermap; std::map i_esplmap; std::istringstream is(os.str()); { IArchive iar(is); iar(i_vectormap); iar(i_podmap); iar(i_isermap); iar(i_isplmap); iar(i_esermap); iar(i_esplmap); } BOOST_CHECK_EQUAL(i_vectormap.size(), o_vectormap.size()); auto o_v_it = o_vectormap.begin(); auto i_v_it = i_vectormap.begin(); for(;o_v_it != o_vectormap.end(); ++o_v_it, ++i_v_it) { BOOST_CHECK_EQUAL(i_v_it->second.size(), o_v_it->second.size()); BOOST_CHECK_EQUAL_COLLECTIONS(i_v_it->second.begin(), i_v_it->second.end(), o_v_it->second.begin(), o_v_it->second.end()); } BOOST_CHECK_EQUAL_COLLECTIONS(i_podmap.begin(), i_podmap.end(), o_podmap.begin(), o_podmap.end()); BOOST_CHECK_EQUAL_COLLECTIONS(i_isermap.begin(), i_isermap.end(), o_isermap.begin(), o_isermap.end()); BOOST_CHECK_EQUAL_COLLECTIONS(i_isplmap.begin(), i_isplmap.end(), o_isplmap.begin(), o_isplmap.end()); BOOST_CHECK_EQUAL_COLLECTIONS(i_esermap.begin(), i_esermap.end(), o_esermap.begin(), o_esermap.end()); BOOST_CHECK_EQUAL_COLLECTIONS(i_esplmap.begin(), i_esplmap.end(), o_esplmap.begin(), o_esplmap.end()); } } template void test_map_memory() { std::random_device rd; std::mt19937 gen(rd()); for(int ii=0; ii<100; ++ii) { std::map> o_uniqueptrMap; std::map> o_sharedptrMap; for(int j=0; j<100; ++j) { #ifdef CEREAL_OLDER_GCC o_uniqueptrMap.insert( std::make_pair(random_value(gen), std::unique_ptr( new int( random_value(gen) ) )) ); o_sharedptrMap.insert( std::make_pair(random_value(gen), std::make_shared( random_value(gen) )) ); #else // NOT CEREAL_OLDER_GCC o_uniqueptrMap.emplace( random_value(gen), std::unique_ptr( new int( random_value(gen) ) ) ); o_sharedptrMap.emplace( random_value(gen), std::make_shared( random_value(gen) ) ); #endif // NOT CEREAL_OLDER_GCC } std::ostringstream os; { OArchive oar(os); oar( o_uniqueptrMap ); oar( o_sharedptrMap ); } decltype( o_uniqueptrMap ) i_uniqueptrMap; decltype( o_sharedptrMap ) i_sharedptrMap; std::istringstream is(os.str()); { IArchive iar(is); iar( i_uniqueptrMap ); iar( i_sharedptrMap ); } BOOST_CHECK_EQUAL(o_sharedptrMap.size(), i_sharedptrMap.size()); BOOST_CHECK_EQUAL(o_uniqueptrMap.size(), i_uniqueptrMap.size()); auto o_v_it = o_uniqueptrMap.begin(); auto i_v_it = i_uniqueptrMap.begin(); for(;o_v_it != o_uniqueptrMap.end(); ++o_v_it, ++i_v_it) { BOOST_CHECK_EQUAL(i_v_it->first, o_v_it->first); BOOST_CHECK_EQUAL(*i_v_it->second, *o_v_it->second); } } } BOOST_AUTO_TEST_CASE( binary_map ) { test_map(); } BOOST_AUTO_TEST_CASE( portable_binary_map ) { test_map(); } BOOST_AUTO_TEST_CASE( xml_map ) { test_map(); } BOOST_AUTO_TEST_CASE( json_map ) { test_map(); } BOOST_AUTO_TEST_CASE( binary_map_memory ) { test_map_memory(); } BOOST_AUTO_TEST_CASE( portable_binary_map_memory ) { test_map_memory(); } BOOST_AUTO_TEST_CASE( xml_map_memory ) { test_map_memory(); } BOOST_AUTO_TEST_CASE( json_map_memory ) { test_map_memory(); }