mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
Added list unit tests
This commit is contained in:
@@ -40,7 +40,7 @@ namespace cereal
|
|||||||
ar & i;
|
ar & i;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::array all other types to binary
|
//! Loading for std::array all other types from binary
|
||||||
template <class T, size_t N>
|
template <class T, size_t N>
|
||||||
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
|
||||||
load( BinaryInputArchive & ar, std::array<T, N> & array )
|
load( BinaryInputArchive & ar, std::array<T, N> & array )
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace cereal
|
|||||||
{
|
{
|
||||||
ar & deque.size();
|
ar & deque.size();
|
||||||
|
|
||||||
for( const auto & i : deque )
|
for( auto const & i : deque )
|
||||||
ar & i;
|
ar & i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace cereal
|
|||||||
// TODO: This is linear time! We may want to do something smarter
|
// TODO: This is linear time! We may want to do something smarter
|
||||||
ar & std::distance(forward_list.begin(), forward_list.end());
|
ar & std::distance(forward_list.begin(), forward_list.end());
|
||||||
|
|
||||||
for( const auto & i : forward_list )
|
for( auto const & i : forward_list )
|
||||||
ar & i;
|
ar & i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,17 +6,27 @@
|
|||||||
|
|
||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
//! Saving for std::list all other types to binary
|
//! Saving for std::list types to binary
|
||||||
template <class T, class A>
|
template <class T, class A>
|
||||||
void save( BinaryOutputArchive & ar, std::list<T, A> const & list )
|
void save( BinaryOutputArchive & ar, std::list<T, A> const & list )
|
||||||
{
|
{
|
||||||
ar & list.size();
|
ar & list.size();
|
||||||
|
|
||||||
for( const auto & i : list )
|
for( auto const & i : list )
|
||||||
ar & i;
|
ar & i;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Loading for std::list all other types to binary
|
//! Saving for std::list types to binary (non-const version)
|
||||||
|
template <class T, class A>
|
||||||
|
void save( BinaryOutputArchive & ar, std::list<T, A> & list )
|
||||||
|
{
|
||||||
|
ar & list.size();
|
||||||
|
|
||||||
|
for( auto & i : list )
|
||||||
|
ar & i;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Loading for std::list types from binary
|
||||||
template <class T, class A>
|
template <class T, class A>
|
||||||
void load( BinaryInputArchive & ar, std::list<T, A> & list )
|
void load( BinaryInputArchive & ar, std::list<T, A> & list )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace cereal
|
|||||||
typename std::enable_if<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type
|
typename std::enable_if<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type
|
||||||
save( BinaryOutputArchive & ar, std::vector<T, A> const & vector )
|
save( BinaryOutputArchive & ar, std::vector<T, A> const & vector )
|
||||||
{
|
{
|
||||||
const size_t dataSize = std::addressof(vector.back()) - std::addressof(vector.front()) + 1;
|
size_t const dataSize = std::addressof(vector.back()) - std::addressof(vector.front()) + 1;
|
||||||
|
|
||||||
ar & vector.size(); // number of elements
|
ar & vector.size(); // number of elements
|
||||||
ar & dataSize; // size of data (may be larger due to allocator strategy)
|
ar & dataSize; // size of data (may be larger due to allocator strategy)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <cereal/binary_archive/vector.hpp>
|
#include <cereal/binary_archive/vector.hpp>
|
||||||
#include <cereal/binary_archive/deque.hpp>
|
#include <cereal/binary_archive/deque.hpp>
|
||||||
#include <cereal/binary_archive/forward_list.hpp>
|
#include <cereal/binary_archive/forward_list.hpp>
|
||||||
|
#include <cereal/binary_archive/list.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
@@ -488,3 +489,63 @@ BOOST_AUTO_TEST_CASE( binary_forward_list )
|
|||||||
BOOST_CHECK_EQUAL_COLLECTIONS(i_esplforward_list.begin(), i_esplforward_list.end(), o_esplforward_list.begin(), o_esplforward_list.end());
|
BOOST_CHECK_EQUAL_COLLECTIONS(i_esplforward_list.begin(), i_esplforward_list.end(), o_esplforward_list.begin(), o_esplforward_list.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ######################################################################
|
||||||
|
BOOST_AUTO_TEST_CASE( binary_list )
|
||||||
|
{
|
||||||
|
std::random_device rd;
|
||||||
|
std::mt19937 gen(rd());
|
||||||
|
|
||||||
|
for(int i=0; i<100; ++i)
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
cereal::BinaryOutputArchive oar(os);
|
||||||
|
|
||||||
|
std::list<int> o_podlist(100);
|
||||||
|
for(auto & elem : o_podlist)
|
||||||
|
elem = random_value<decltype(o_podlist)::value_type>(gen);
|
||||||
|
|
||||||
|
std::list<StructInternalSerialize> o_iserlist(100);
|
||||||
|
for(auto & elem : o_iserlist)
|
||||||
|
elem = { random_value<int>(gen), random_value<int>(gen) };
|
||||||
|
|
||||||
|
std::list<StructInternalSplit> o_ispllist(100);
|
||||||
|
for(auto & elem : o_ispllist)
|
||||||
|
elem = { random_value<int>(gen), random_value<int>(gen) };
|
||||||
|
|
||||||
|
std::list<StructExternalSerialize> o_eserlist(100);
|
||||||
|
for(auto & elem : o_eserlist)
|
||||||
|
elem = { random_value<int>(gen), random_value<int>(gen) };
|
||||||
|
|
||||||
|
std::list<StructExternalSplit> o_espllist(100);
|
||||||
|
for(auto & elem : o_espllist)
|
||||||
|
elem = { random_value<int>(gen), random_value<int>(gen) };
|
||||||
|
|
||||||
|
oar & o_podlist;
|
||||||
|
oar & o_iserlist;
|
||||||
|
oar & o_ispllist;
|
||||||
|
oar & o_eserlist;
|
||||||
|
oar & o_espllist;
|
||||||
|
|
||||||
|
std::istringstream is(os.str());
|
||||||
|
cereal::BinaryInputArchive iar(is);
|
||||||
|
|
||||||
|
std::list<int> i_podlist;
|
||||||
|
std::list<StructInternalSerialize> i_iserlist;
|
||||||
|
std::list<StructInternalSplit> i_ispllist;
|
||||||
|
std::list<StructExternalSerialize> i_eserlist;
|
||||||
|
std::list<StructExternalSplit> i_espllist;
|
||||||
|
|
||||||
|
iar & i_podlist;
|
||||||
|
iar & i_iserlist;
|
||||||
|
iar & i_ispllist;
|
||||||
|
iar & i_eserlist;
|
||||||
|
iar & i_espllist;
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL_COLLECTIONS(i_podlist.begin(), i_podlist.end(), o_podlist.begin(), o_podlist.end());
|
||||||
|
BOOST_CHECK_EQUAL_COLLECTIONS(i_iserlist.begin(), i_iserlist.end(), o_iserlist.begin(), o_iserlist.end());
|
||||||
|
BOOST_CHECK_EQUAL_COLLECTIONS(i_ispllist.begin(), i_ispllist.end(), o_ispllist.begin(), o_ispllist.end());
|
||||||
|
BOOST_CHECK_EQUAL_COLLECTIONS(i_eserlist.begin(), i_eserlist.end(), o_eserlist.begin(), o_eserlist.end());
|
||||||
|
BOOST_CHECK_EQUAL_COLLECTIONS(i_espllist.begin(), i_espllist.end(), o_espllist.begin(), o_espllist.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user