diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index dda83b68..a906f4b6 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -33,6 +33,18 @@ project msvc:on ; +alias serialization + : usage-requirements + /boost//serialization + ; + +alias serialization + : usage-requirements + /boost//serialization/"/wd4127" + : requirements + msvc + ; + run unordered/prime_fmod_tests.cpp ; run unordered/fwd_set_test.cpp ; run unordered/fwd_map_test.cpp ; @@ -85,6 +97,7 @@ run unordered/copy_tests.cpp : : : BOOST_UNORDERED_USE_MOVE : bmove_copy run unordered/move_tests.cpp : : : BOOST_UNORDERED_USE_MOVE : bmove_move ; run unordered/assign_tests.cpp : : : BOOST_UNORDERED_USE_MOVE : bmove_assign ; +run unordered/serialization_tests.cpp serialization ; run exception/constructor_exception_tests.cpp ; run exception/copy_exception_tests.cpp ; diff --git a/test/objects/test.hpp b/test/objects/test.hpp index b1a253e5..17abed92 100644 --- a/test/objects/test.hpp +++ b/test/objects/test.hpp @@ -1,6 +1,7 @@ // Copyright 2006-2009 Daniel James. // Copyright 2022 Christian Mazakas +// Copyright 2023 Joaqui 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) @@ -11,6 +12,7 @@ #include "../helpers/fwd.hpp" #include "../helpers/memory.hpp" #include +#include #include #include @@ -74,6 +76,14 @@ namespace test { { return out << "(" << o.tag1_ << "," << o.tag2_ << ")"; } + + + template + 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 diff --git a/test/unordered/serialization_tests.cpp b/test/unordered/serialization_tests.cpp new file mode 100644 index 00000000..be5a9cf1 --- /dev/null +++ b/test/unordered/serialization_tests.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include + +#ifndef BOOST_NO_CXX11_HDR_RANDOM +#include +#endif + +namespace { + + template + void serialization_tests(Container*, ArchivePair*, test::random_generator generator) + { + typedef typename Container::iterator iterator; + typedef std::vector 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 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 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()