mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
Adding unit tests for std::pair
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include <cereal/binary_archive/stack.hpp>
|
#include <cereal/binary_archive/stack.hpp>
|
||||||
#include <cereal/binary_archive/unordered_map.hpp>
|
#include <cereal/binary_archive/unordered_map.hpp>
|
||||||
#include <cereal/binary_archive/unordered_set.hpp>
|
#include <cereal/binary_archive/unordered_set.hpp>
|
||||||
|
#include <cereal/binary_archive/utility.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
@@ -1549,3 +1550,60 @@ BOOST_AUTO_TEST_CASE( binary_vector )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ######################################################################
|
||||||
|
BOOST_AUTO_TEST_CASE( binary_pair )
|
||||||
|
{
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
|
||||||
|
auto rng = [&](){ return random_value<int>(gen); };
|
||||||
|
|
||||||
|
for(int i=0; i<100; ++i)
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
cereal::BinaryOutputArchive oar(os);
|
||||||
|
|
||||||
|
std::pair<int, int> o_podpair = {rng(), rng()};
|
||||||
|
std::pair<StructInternalSerialize, StructInternalSerialize> o_iserpair = {{rng(), rng()}, {rng(), rng()}};
|
||||||
|
std::pair<StructInternalSplit, StructInternalSplit> o_isplpair = {{rng(), rng()}, {rng(), rng()}};
|
||||||
|
std::pair<StructExternalSerialize, StructExternalSerialize> o_eserpair = {{rng(), rng()}, {rng(), rng()}};
|
||||||
|
std::pair<StructExternalSplit, StructExternalSplit> o_esplpair = {{rng(), rng()}, {rng(), rng()}};
|
||||||
|
|
||||||
|
oar & o_podpair;
|
||||||
|
oar & o_iserpair;
|
||||||
|
oar & o_isplpair;
|
||||||
|
oar & o_eserpair;
|
||||||
|
oar & o_esplpair;
|
||||||
|
|
||||||
|
std::istringstream is(os.str());
|
||||||
|
cereal::BinaryInputArchive iar(is);
|
||||||
|
|
||||||
|
std::pair<int, int> i_podpair;
|
||||||
|
std::pair<StructInternalSerialize, StructInternalSerialize> i_iserpair;
|
||||||
|
std::pair<StructInternalSplit, StructInternalSplit> i_isplpair;
|
||||||
|
std::pair<StructExternalSerialize, StructExternalSerialize> i_eserpair;
|
||||||
|
std::pair<StructExternalSplit, StructExternalSplit> i_esplpair;
|
||||||
|
|
||||||
|
iar & i_podpair;
|
||||||
|
iar & i_iserpair;
|
||||||
|
iar & i_isplpair;
|
||||||
|
iar & i_eserpair;
|
||||||
|
iar & i_esplpair;
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( i_podpair.first, o_podpair.first );
|
||||||
|
BOOST_CHECK_EQUAL( i_podpair.second, o_podpair.second );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( i_iserpair.first, o_iserpair.first );
|
||||||
|
BOOST_CHECK_EQUAL( i_iserpair.second, o_iserpair.second );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( i_isplpair.first, o_isplpair.first );
|
||||||
|
BOOST_CHECK_EQUAL( i_isplpair.second, o_isplpair.second );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( i_eserpair.first, o_eserpair.first );
|
||||||
|
BOOST_CHECK_EQUAL( i_eserpair.second, o_eserpair.second );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( i_esplpair.first, o_esplpair.first );
|
||||||
|
BOOST_CHECK_EQUAL( i_esplpair.second, o_esplpair.second );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user