mirror of
https://github.com/boostorg/unordered.git
synced 2025-05-11 21:44:01 +00:00
added first tests of serialization support
This commit is contained in:
parent
ff9d08a917
commit
d83efc5ea4
@ -33,6 +33,18 @@ project
|
|||||||
<toolset>msvc:<warnings-as-errors>on
|
<toolset>msvc:<warnings-as-errors>on
|
||||||
;
|
;
|
||||||
|
|
||||||
|
alias serialization
|
||||||
|
: usage-requirements
|
||||||
|
<library>/boost//serialization
|
||||||
|
;
|
||||||
|
|
||||||
|
alias serialization
|
||||||
|
: usage-requirements
|
||||||
|
<library>/boost//serialization/<cxxflags>"/wd4127"
|
||||||
|
: requirements
|
||||||
|
<toolset>msvc
|
||||||
|
;
|
||||||
|
|
||||||
run unordered/prime_fmod_tests.cpp ;
|
run unordered/prime_fmod_tests.cpp ;
|
||||||
run unordered/fwd_set_test.cpp ;
|
run unordered/fwd_set_test.cpp ;
|
||||||
run unordered/fwd_map_test.cpp ;
|
run unordered/fwd_map_test.cpp ;
|
||||||
@ -85,6 +97,7 @@ run unordered/copy_tests.cpp : : : <define>BOOST_UNORDERED_USE_MOVE : bmove_copy
|
|||||||
run unordered/move_tests.cpp : : : <define>BOOST_UNORDERED_USE_MOVE : bmove_move ;
|
run unordered/move_tests.cpp : : : <define>BOOST_UNORDERED_USE_MOVE : bmove_move ;
|
||||||
run unordered/assign_tests.cpp : : : <define>BOOST_UNORDERED_USE_MOVE : bmove_assign ;
|
run unordered/assign_tests.cpp : : : <define>BOOST_UNORDERED_USE_MOVE : bmove_assign ;
|
||||||
|
|
||||||
|
run unordered/serialization_tests.cpp serialization ;
|
||||||
|
|
||||||
run exception/constructor_exception_tests.cpp ;
|
run exception/constructor_exception_tests.cpp ;
|
||||||
run exception/copy_exception_tests.cpp ;
|
run exception/copy_exception_tests.cpp ;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
// Copyright 2006-2009 Daniel James.
|
// Copyright 2006-2009 Daniel James.
|
||||||
// Copyright 2022 Christian Mazakas
|
// Copyright 2022 Christian Mazakas
|
||||||
|
// Copyright 2023 Joaqui M Lopez Munoz
|
||||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
@ -11,6 +12,7 @@
|
|||||||
#include "../helpers/fwd.hpp"
|
#include "../helpers/fwd.hpp"
|
||||||
#include "../helpers/memory.hpp"
|
#include "../helpers/memory.hpp"
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/core/serialization.hpp>
|
||||||
#include <boost/limits.hpp>
|
#include <boost/limits.hpp>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
@ -74,6 +76,14 @@ namespace test {
|
|||||||
{
|
{
|
||||||
return out << "(" << o.tag1_ << "," << o.tag2_ << ")";
|
return out << "(" << o.tag1_ << "," << o.tag2_ << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename Archive>
|
||||||
|
void serialize(Archive& ar,unsigned int)
|
||||||
|
{
|
||||||
|
ar & boost::core::make_nvp("tag1", tag1_);
|
||||||
|
ar & boost::core::make_nvp("tag2", tag2_);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class movable : private counted_object
|
class movable : private counted_object
|
||||||
|
142
test/unordered/serialization_tests.cpp
Normal file
142
test/unordered/serialization_tests.cpp
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
// Copyright (C) 2023 Joaquin M Lopez Munoz
|
||||||
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
#define BOOST_UNORDERED_FOA_TESTS
|
||||||
|
#include "../helpers/unordered.hpp"
|
||||||
|
|
||||||
|
#include "../objects/test.hpp"
|
||||||
|
#include "../helpers/random_values.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <boost/archive/text_oarchive.hpp>
|
||||||
|
#include <boost/archive/text_iarchive.hpp>
|
||||||
|
#include <boost/archive/xml_oarchive.hpp>
|
||||||
|
#include <boost/archive/xml_iarchive.hpp>
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/serialization/nvp.hpp>
|
||||||
|
#include <boost/serialization/vector.hpp>
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_CXX11_HDR_RANDOM
|
||||||
|
#include <random>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
template <class Container, typename ArchivePair>
|
||||||
|
void serialization_tests(Container*, ArchivePair*, test::random_generator generator)
|
||||||
|
{
|
||||||
|
typedef typename Container::iterator iterator;
|
||||||
|
typedef std::vector<iterator> iterator_vector;
|
||||||
|
typedef typename ArchivePair::first_type output_archive;
|
||||||
|
typedef typename ArchivePair::second_type input_archive;
|
||||||
|
|
||||||
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "serialization_tests1\n";
|
||||||
|
{
|
||||||
|
Container c;
|
||||||
|
iterator it = c.end();
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
{
|
||||||
|
output_archive oa(oss);
|
||||||
|
oa << boost::serialization::make_nvp("container", c);
|
||||||
|
oa << boost::serialization::make_nvp("iterator", it);
|
||||||
|
}
|
||||||
|
|
||||||
|
test::random_values<Container> values(100, generator);
|
||||||
|
Container c2(values.begin(), values.end());
|
||||||
|
iterator it2 = c2.begin();
|
||||||
|
std::istringstream iss(oss.str());
|
||||||
|
input_archive ia(iss);
|
||||||
|
ia >> boost::serialization::make_nvp("container", c2);
|
||||||
|
ia >> boost::serialization::make_nvp("iterator", it2);
|
||||||
|
BOOST_TEST(c2.empty());
|
||||||
|
BOOST_TEST(it2 == c2.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "serialization_tests2\n";
|
||||||
|
{
|
||||||
|
test::random_values<Container> values(100, generator);
|
||||||
|
Container c(values.begin(), values.end());
|
||||||
|
|
||||||
|
iterator_vector v;
|
||||||
|
for (iterator first = c.begin(), last=c.end(); ; ) {
|
||||||
|
v.push_back(first);
|
||||||
|
if(first == last) break;
|
||||||
|
++first;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_CXX11_HDR_RANDOM
|
||||||
|
std::shuffle(v.begin(), v.end(), std::mt19937(4213));
|
||||||
|
#else
|
||||||
|
std::random_shuffle(v.begin(), v.end());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
{
|
||||||
|
output_archive oa(oss);
|
||||||
|
oa << boost::serialization::make_nvp("container", c);
|
||||||
|
oa << boost::serialization::make_nvp("iterators", v);
|
||||||
|
}
|
||||||
|
|
||||||
|
Container c2;
|
||||||
|
iterator_vector v2;
|
||||||
|
std::istringstream iss(oss.str());
|
||||||
|
input_archive ia(iss);
|
||||||
|
ia >> boost::serialization::make_nvp("container", c2);
|
||||||
|
ia >> boost::serialization::make_nvp("iterators", v2);
|
||||||
|
BOOST_TEST_EQ(v.size(), v2.size());
|
||||||
|
|
||||||
|
for (int i=0; i < v.size(); ++i) {
|
||||||
|
iterator it = v[i];
|
||||||
|
iterator it2 = v2[i];
|
||||||
|
if (it == c.end()) {
|
||||||
|
BOOST_TEST(it2 == c2.end());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
BOOST_TEST(it2 != c2.end());
|
||||||
|
BOOST_TEST(*it == *it2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using test::default_generator;
|
||||||
|
|
||||||
|
std::pair<
|
||||||
|
boost::archive::text_oarchive, boost::archive::text_iarchive>* text_archive;
|
||||||
|
std::pair<
|
||||||
|
boost::archive::xml_oarchive, boost::archive::xml_iarchive>* xml_archive;
|
||||||
|
|
||||||
|
#ifdef BOOST_UNORDERED_FOA_TESTS
|
||||||
|
boost::unordered_flat_map<
|
||||||
|
test::object, test::object, test::hash, test::equal_to>* test_flat_map;
|
||||||
|
boost::unordered_node_map<
|
||||||
|
test::object, test::object, test::hash, test::equal_to>* test_node_map;
|
||||||
|
boost::unordered_flat_set<
|
||||||
|
test::object, test::hash, test::equal_to>* test_flat_set;
|
||||||
|
boost::unordered_node_set<
|
||||||
|
test::object, test::hash, test::equal_to>* test_node_set;
|
||||||
|
|
||||||
|
UNORDERED_TEST(serialization_tests,
|
||||||
|
((test_flat_map)(test_node_map)(test_flat_set)(test_node_set))
|
||||||
|
((text_archive)(xml_archive))
|
||||||
|
((default_generator)))
|
||||||
|
#else
|
||||||
|
boost::unordered_map<
|
||||||
|
test::object, test::object, test::hash, test::equal_to>* test_map;
|
||||||
|
boost::unordered_multimap<
|
||||||
|
test::object, test::object, test::hash, test::equal_to>* test_multimap;
|
||||||
|
boost::unordered_set<
|
||||||
|
test::object, test::hash, test::equal_to>* test_set;
|
||||||
|
boost::unordered_multiset<
|
||||||
|
test::object, test::hash, test::equal_to>* test_multiset;
|
||||||
|
|
||||||
|
UNORDERED_TEST(serialization_tests,
|
||||||
|
((test_map)(test_multimap)(test_set)(test_multiset))
|
||||||
|
((text_archive)(xml_archive))
|
||||||
|
((default_generator)))
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
RUN_TESTS()
|
Loading…
x
Reference in New Issue
Block a user