mirror of
https://github.com/USCiLab/cereal.git
synced 2025-09-23 21:09:30 +02:00
last? conversions for #139
This commit is contained in:
parent
978b3b56b4
commit
66528b68be
@ -30,7 +30,6 @@
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
#include <future>
|
||||
static std::mutex boostTestMutex;
|
||||
#endif
|
||||
|
||||
struct PolyBaseA
|
||||
@ -258,6 +257,10 @@ void test_polymorphic()
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
static std::mutex testMutex;
|
||||
#endif
|
||||
|
||||
auto rngB = [&](){ return random_value<int>( gen ) % 2 == 0; };
|
||||
auto rngI = [&](){ return random_value<int>( gen ); };
|
||||
auto rngL = [&](){ return random_value<long>( gen ); };
|
||||
@ -319,7 +322,7 @@ void test_polymorphic()
|
||||
auto o_lockedA = o_weakA.lock();
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
std::lock_guard<std::mutex> lock( boostTestMutex );
|
||||
std::lock_guard<std::mutex> lock( testMutex );
|
||||
#endif
|
||||
|
||||
CHECK_EQ(i_shared.get(), i_locked.get());
|
||||
|
@ -24,119 +24,29 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "unordered_map.hpp"
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_unordered_map()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
TEST_SUITE("unordered_map");
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::unordered_map<std::string, int> o_podunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_podunordered_map.insert({random_value<std::string>(gen), random_value<int>(gen)});
|
||||
|
||||
std::unordered_map<uint16_t, StructInternalSerialize> o_iserunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_iserunordered_map.insert({random_value<uint16_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});
|
||||
|
||||
std::unordered_map<uint16_t, StructInternalSplit> o_isplunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_isplunordered_map.insert({random_value<uint16_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});
|
||||
|
||||
std::unordered_map<uint32_t, StructExternalSerialize> o_eserunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_eserunordered_map.insert({random_value<uint32_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});
|
||||
|
||||
std::unordered_map<int8_t, StructExternalSplit> o_esplunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_esplunordered_map.insert({random_value<char>(gen), { random_value<int>(gen), random_value<int>(gen) }});
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podunordered_map);
|
||||
oar(o_iserunordered_map);
|
||||
oar(o_isplunordered_map);
|
||||
oar(o_eserunordered_map);
|
||||
oar(o_esplunordered_map);
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, int> i_podunordered_map;
|
||||
std::unordered_map<uint16_t, StructInternalSerialize> i_iserunordered_map;
|
||||
std::unordered_map<uint16_t, StructInternalSplit> i_isplunordered_map;
|
||||
std::unordered_map<uint32_t, StructExternalSerialize> i_eserunordered_map;
|
||||
std::unordered_map<int8_t, StructExternalSplit> i_esplunordered_map;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podunordered_map);
|
||||
iar(i_iserunordered_map);
|
||||
iar(i_isplunordered_map);
|
||||
iar(i_eserunordered_map);
|
||||
iar(i_esplunordered_map);
|
||||
}
|
||||
|
||||
for(auto const & p : i_podunordered_map)
|
||||
{
|
||||
auto v = o_podunordered_map.find(p.first);
|
||||
BOOST_CHECK(v != o_podunordered_map.end());
|
||||
BOOST_CHECK_EQUAL(p.second, v->second);
|
||||
}
|
||||
|
||||
for(auto const & p : i_iserunordered_map)
|
||||
{
|
||||
auto v = o_iserunordered_map.find(p.first);
|
||||
BOOST_CHECK(v != o_iserunordered_map.end());
|
||||
BOOST_CHECK_EQUAL(p.second, v->second);
|
||||
}
|
||||
|
||||
for(auto const & p : i_isplunordered_map)
|
||||
{
|
||||
auto v = o_isplunordered_map.find(p.first);
|
||||
BOOST_CHECK(v != o_isplunordered_map.end());
|
||||
BOOST_CHECK_EQUAL(p.second, v->second);
|
||||
}
|
||||
|
||||
for(auto const & p : i_eserunordered_map)
|
||||
{
|
||||
auto v = o_eserunordered_map.find(p.first);
|
||||
BOOST_CHECK(v != o_eserunordered_map.end());
|
||||
BOOST_CHECK_EQUAL(p.second, v->second);
|
||||
}
|
||||
|
||||
for(auto const & p : i_esplunordered_map)
|
||||
{
|
||||
auto v = o_esplunordered_map.find(p.first);
|
||||
BOOST_CHECK(v != o_esplunordered_map.end());
|
||||
BOOST_CHECK_EQUAL(p.second, v->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_unordered_map )
|
||||
TEST_CASE("binary_unordered_map")
|
||||
{
|
||||
test_unordered_map<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_unordered_map )
|
||||
TEST_CASE("portable_binary_unordered_map")
|
||||
{
|
||||
test_unordered_map<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_unordered_map )
|
||||
TEST_CASE("xml_unordered_map")
|
||||
{
|
||||
test_unordered_map<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_unordered_map )
|
||||
TEST_CASE("json_unordered_map")
|
||||
{
|
||||
test_unordered_map<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
124
unittests/unordered_map.hpp
Normal file
124
unittests/unordered_map.hpp
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_UNORDERED_MAP_H_
|
||||
#define CEREAL_TEST_UNORDERED_MAP_H_
|
||||
#include "common.hpp"
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_unordered_map()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::unordered_map<std::string, int> o_podunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_podunordered_map.insert({random_value<std::string>(gen), random_value<int>(gen)});
|
||||
|
||||
std::unordered_map<uint16_t, StructInternalSerialize> o_iserunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_iserunordered_map.insert({random_value<uint16_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});
|
||||
|
||||
std::unordered_map<uint16_t, StructInternalSplit> o_isplunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_isplunordered_map.insert({random_value<uint16_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});
|
||||
|
||||
std::unordered_map<uint32_t, StructExternalSerialize> o_eserunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_eserunordered_map.insert({random_value<uint32_t>(gen), { random_value<int>(gen), random_value<int>(gen) }});
|
||||
|
||||
std::unordered_map<int8_t, StructExternalSplit> o_esplunordered_map;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_esplunordered_map.insert({random_value<char>(gen), { random_value<int>(gen), random_value<int>(gen) }});
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podunordered_map);
|
||||
oar(o_iserunordered_map);
|
||||
oar(o_isplunordered_map);
|
||||
oar(o_eserunordered_map);
|
||||
oar(o_esplunordered_map);
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, int> i_podunordered_map;
|
||||
std::unordered_map<uint16_t, StructInternalSerialize> i_iserunordered_map;
|
||||
std::unordered_map<uint16_t, StructInternalSplit> i_isplunordered_map;
|
||||
std::unordered_map<uint32_t, StructExternalSerialize> i_eserunordered_map;
|
||||
std::unordered_map<int8_t, StructExternalSplit> i_esplunordered_map;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podunordered_map);
|
||||
iar(i_iserunordered_map);
|
||||
iar(i_isplunordered_map);
|
||||
iar(i_eserunordered_map);
|
||||
iar(i_esplunordered_map);
|
||||
}
|
||||
|
||||
for(auto const & p : i_podunordered_map)
|
||||
{
|
||||
auto v = o_podunordered_map.find(p.first);
|
||||
CHECK_NE(v, o_podunordered_map.end());
|
||||
CHECK_EQ(p.second, v->second);
|
||||
}
|
||||
|
||||
for(auto const & p : i_iserunordered_map)
|
||||
{
|
||||
auto v = o_iserunordered_map.find(p.first);
|
||||
CHECK_NE(v, o_iserunordered_map.end());
|
||||
CHECK_EQ(p.second, v->second);
|
||||
}
|
||||
|
||||
for(auto const & p : i_isplunordered_map)
|
||||
{
|
||||
auto v = o_isplunordered_map.find(p.first);
|
||||
CHECK_NE(v, o_isplunordered_map.end());
|
||||
CHECK_EQ(p.second, v->second);
|
||||
}
|
||||
|
||||
for(auto const & p : i_eserunordered_map)
|
||||
{
|
||||
auto v = o_eserunordered_map.find(p.first);
|
||||
CHECK_NE(v, o_eserunordered_map.end());
|
||||
CHECK_EQ(p.second, v->second);
|
||||
}
|
||||
|
||||
for(auto const & p : i_esplunordered_map)
|
||||
{
|
||||
auto v = o_esplunordered_map.find(p.first);
|
||||
CHECK_NE(v, o_esplunordered_map.end());
|
||||
CHECK_EQ(p.second, v->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_UNORDERED_MAP_H_
|
@ -24,149 +24,29 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "unordered_multimap.hpp"
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_unordered_multimap()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
TEST_SUITE("unordered_multimap");
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::unordered_multimap<std::string, int> o_podunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<std::string>(gen);
|
||||
o_podunordered_multimap.insert({key, random_value<int>(gen)});
|
||||
o_podunordered_multimap.insert({key, random_value<int>(gen)});
|
||||
}
|
||||
|
||||
std::unordered_multimap<int, StructInternalSerialize> o_iserunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<int>(gen);
|
||||
o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
}
|
||||
|
||||
std::unordered_multimap<int, StructInternalSplit> o_isplunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<int>(gen);
|
||||
o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
}
|
||||
|
||||
std::unordered_multimap<uint32_t, StructExternalSerialize> o_eserunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<uint32_t>(gen);
|
||||
o_eserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
o_eserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
}
|
||||
|
||||
std::unordered_multimap<int8_t, StructExternalSplit> o_esplunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<char>(gen);
|
||||
o_esplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
o_esplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podunordered_multimap);
|
||||
oar(o_iserunordered_multimap);
|
||||
oar(o_isplunordered_multimap);
|
||||
oar(o_eserunordered_multimap);
|
||||
oar(o_esplunordered_multimap);
|
||||
}
|
||||
|
||||
std::unordered_multimap<std::string, int> i_podunordered_multimap;
|
||||
std::unordered_multimap<int, StructInternalSerialize> i_iserunordered_multimap;
|
||||
std::unordered_multimap<int, StructInternalSplit> i_isplunordered_multimap;
|
||||
std::unordered_multimap<uint32_t, StructExternalSerialize> i_eserunordered_multimap;
|
||||
std::unordered_multimap<int8_t, StructExternalSplit> i_esplunordered_multimap;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podunordered_multimap);
|
||||
iar(i_iserunordered_multimap);
|
||||
iar(i_isplunordered_multimap);
|
||||
iar(i_eserunordered_multimap);
|
||||
iar(i_esplunordered_multimap);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL(i_podunordered_multimap.size(), o_podunordered_multimap.size());
|
||||
BOOST_CHECK_EQUAL(i_iserunordered_multimap.size(), o_iserunordered_multimap.size());
|
||||
BOOST_CHECK_EQUAL(i_isplunordered_multimap.size(), o_isplunordered_multimap.size());
|
||||
BOOST_CHECK_EQUAL(i_eserunordered_multimap.size(), o_eserunordered_multimap.size());
|
||||
BOOST_CHECK_EQUAL(i_esplunordered_multimap.size(), o_esplunordered_multimap.size());
|
||||
|
||||
for(auto const & p : i_podunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_podunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_podunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_podunordered_multimap.end(bucket);
|
||||
BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
|
||||
}
|
||||
|
||||
for(auto const & p : i_iserunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_iserunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_iserunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_iserunordered_multimap.end(bucket);
|
||||
BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
|
||||
}
|
||||
|
||||
for(auto const & p : i_isplunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_isplunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_isplunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_isplunordered_multimap.end(bucket);
|
||||
BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
|
||||
}
|
||||
|
||||
for(auto const & p : i_eserunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_eserunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_eserunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_eserunordered_multimap.end(bucket);
|
||||
BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
|
||||
}
|
||||
|
||||
for(auto const & p : i_esplunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_esplunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_esplunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_esplunordered_multimap.end(bucket);
|
||||
BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_unordered_multimap )
|
||||
TEST_CASE("binary_unordered_multimap")
|
||||
{
|
||||
test_unordered_multimap<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_unordered_multimap )
|
||||
TEST_CASE("portable_binary_unordered_multimap")
|
||||
{
|
||||
test_unordered_multimap<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_unordered_multimap )
|
||||
TEST_CASE("xml_unordered_multimap")
|
||||
{
|
||||
test_unordered_multimap<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_unordered_multimap )
|
||||
TEST_CASE("json_unordered_multimap")
|
||||
{
|
||||
test_unordered_multimap<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
155
unittests/unordered_multimap.hpp
Normal file
155
unittests/unordered_multimap.hpp
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_UNORDERED_MULTIMAP_H_
|
||||
#define CEREAL_TEST_UNORDERED_MULTIMAP_H_
|
||||
#include "common.hpp"
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_unordered_multimap()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::unordered_multimap<std::string, int> o_podunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<std::string>(gen);
|
||||
o_podunordered_multimap.insert({key, random_value<int>(gen)});
|
||||
o_podunordered_multimap.insert({key, random_value<int>(gen)});
|
||||
}
|
||||
|
||||
std::unordered_multimap<int, StructInternalSerialize> o_iserunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<int>(gen);
|
||||
o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
}
|
||||
|
||||
std::unordered_multimap<int, StructInternalSplit> o_isplunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<int>(gen);
|
||||
o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
}
|
||||
|
||||
std::unordered_multimap<uint32_t, StructExternalSerialize> o_eserunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<uint32_t>(gen);
|
||||
o_eserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
o_eserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
}
|
||||
|
||||
std::unordered_multimap<int8_t, StructExternalSplit> o_esplunordered_multimap;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
auto key = random_value<char>(gen);
|
||||
o_esplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
o_esplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podunordered_multimap);
|
||||
oar(o_iserunordered_multimap);
|
||||
oar(o_isplunordered_multimap);
|
||||
oar(o_eserunordered_multimap);
|
||||
oar(o_esplunordered_multimap);
|
||||
}
|
||||
|
||||
std::unordered_multimap<std::string, int> i_podunordered_multimap;
|
||||
std::unordered_multimap<int, StructInternalSerialize> i_iserunordered_multimap;
|
||||
std::unordered_multimap<int, StructInternalSplit> i_isplunordered_multimap;
|
||||
std::unordered_multimap<uint32_t, StructExternalSerialize> i_eserunordered_multimap;
|
||||
std::unordered_multimap<int8_t, StructExternalSplit> i_esplunordered_multimap;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podunordered_multimap);
|
||||
iar(i_iserunordered_multimap);
|
||||
iar(i_isplunordered_multimap);
|
||||
iar(i_eserunordered_multimap);
|
||||
iar(i_esplunordered_multimap);
|
||||
}
|
||||
|
||||
CHECK_EQ(i_podunordered_multimap.size(), o_podunordered_multimap.size());
|
||||
CHECK_EQ(i_iserunordered_multimap.size(), o_iserunordered_multimap.size());
|
||||
CHECK_EQ(i_isplunordered_multimap.size(), o_isplunordered_multimap.size());
|
||||
CHECK_EQ(i_eserunordered_multimap.size(), o_eserunordered_multimap.size());
|
||||
CHECK_EQ(i_esplunordered_multimap.size(), o_esplunordered_multimap.size());
|
||||
|
||||
for(auto const & p : i_podunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_podunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_podunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_podunordered_multimap.end(bucket);
|
||||
CHECK_NE(std::find(bucket_begin, bucket_end, p), bucket_end);
|
||||
}
|
||||
|
||||
for(auto const & p : i_iserunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_iserunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_iserunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_iserunordered_multimap.end(bucket);
|
||||
CHECK_NE(std::find(bucket_begin, bucket_end, p), bucket_end);
|
||||
}
|
||||
|
||||
for(auto const & p : i_isplunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_isplunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_isplunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_isplunordered_multimap.end(bucket);
|
||||
CHECK_NE(std::find(bucket_begin, bucket_end, p), bucket_end);
|
||||
}
|
||||
|
||||
for(auto const & p : i_eserunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_eserunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_eserunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_eserunordered_multimap.end(bucket);
|
||||
CHECK_NE(std::find(bucket_begin, bucket_end, p), bucket_end);
|
||||
}
|
||||
|
||||
for(auto const & p : i_esplunordered_multimap)
|
||||
{
|
||||
size_t const bucket = o_esplunordered_multimap.bucket(p.first);
|
||||
auto bucket_begin = o_esplunordered_multimap.begin(bucket);
|
||||
auto bucket_end = o_esplunordered_multimap.end(bucket);
|
||||
CHECK_NE(std::find(bucket_begin, bucket_end, p), bucket_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_UNORDERED_MULTIMAP_H_
|
@ -24,129 +24,29 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "unordered_multiset.hpp"
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_unordered_multiset()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
TEST_SUITE("unordered_multiset");
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::unordered_multiset<int> o_podunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
int value = random_value<int>(gen);
|
||||
o_podunordered_multiset.insert(value);
|
||||
o_podunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::unordered_multiset<StructInternalSerialize, StructHash<StructInternalSerialize>> o_iserunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
StructInternalSerialize value = { random_value<int>(gen), random_value<int>(gen) };
|
||||
o_iserunordered_multiset.insert(value);
|
||||
o_iserunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::unordered_multiset<StructInternalSplit, StructHash<StructInternalSplit>> o_isplunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
StructInternalSplit value = { random_value<int>(gen), random_value<int>(gen) };
|
||||
o_isplunordered_multiset.insert(value);
|
||||
o_isplunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::unordered_multiset<StructExternalSerialize, StructHash<StructExternalSerialize>> o_eserunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
StructExternalSerialize value = { random_value<int>(gen), random_value<int>(gen) };
|
||||
o_eserunordered_multiset.insert(value);
|
||||
o_eserunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::unordered_multiset<StructExternalSplit, StructHash<StructExternalSplit>> o_esplunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
StructExternalSplit value = { random_value<int>(gen), random_value<int>(gen) };
|
||||
o_esplunordered_multiset.insert(value);
|
||||
o_esplunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podunordered_multiset);
|
||||
oar(o_iserunordered_multiset);
|
||||
oar(o_isplunordered_multiset);
|
||||
oar(o_eserunordered_multiset);
|
||||
oar(o_esplunordered_multiset);
|
||||
}
|
||||
|
||||
std::unordered_multiset<int> i_podunordered_multiset;
|
||||
std::unordered_multiset<StructInternalSerialize, StructHash<StructInternalSerialize>> i_iserunordered_multiset;
|
||||
std::unordered_multiset<StructInternalSplit, StructHash<StructInternalSplit>> i_isplunordered_multiset;
|
||||
std::unordered_multiset<StructExternalSerialize, StructHash<StructExternalSerialize>> i_eserunordered_multiset;
|
||||
std::unordered_multiset<StructExternalSplit, StructHash<StructExternalSplit>> i_esplunordered_multiset;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podunordered_multiset);
|
||||
iar(i_iserunordered_multiset);
|
||||
iar(i_isplunordered_multiset);
|
||||
iar(i_eserunordered_multiset);
|
||||
iar(i_esplunordered_multiset);
|
||||
}
|
||||
|
||||
for(auto const & p : i_podunordered_multiset)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_podunordered_multiset.count(p), i_podunordered_multiset.count(p));
|
||||
}
|
||||
|
||||
for(auto const & p : i_iserunordered_multiset)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_iserunordered_multiset.count(p), i_iserunordered_multiset.count(p));
|
||||
}
|
||||
|
||||
for(auto const & p : i_isplunordered_multiset)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_isplunordered_multiset.count(p), i_isplunordered_multiset.count(p));
|
||||
}
|
||||
|
||||
for(auto const & p : i_eserunordered_multiset)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_eserunordered_multiset.count(p), i_eserunordered_multiset.count(p));
|
||||
}
|
||||
|
||||
for(auto const & p : i_esplunordered_multiset)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_esplunordered_multiset.count(p), i_esplunordered_multiset.count(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_unordered_multiset )
|
||||
TEST_CASE("binary_unordered_multiset")
|
||||
{
|
||||
test_unordered_multiset<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_unordered_multiset )
|
||||
TEST_CASE("portable_binary_unordered_multiset")
|
||||
{
|
||||
test_unordered_multiset<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_unordered_multiset )
|
||||
TEST_CASE("xml_unordered_multiset")
|
||||
{
|
||||
test_unordered_multiset<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_unordered_multiset )
|
||||
TEST_CASE("json_unordered_multiset")
|
||||
{
|
||||
test_unordered_multiset<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
134
unittests/unordered_multiset.hpp
Normal file
134
unittests/unordered_multiset.hpp
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_UNORDERED_MULTISET_H_
|
||||
#define CEREAL_TEST_UNORDERED_MULTISET_H_
|
||||
#include "common.hpp"
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_unordered_multiset()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::unordered_multiset<int> o_podunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
int value = random_value<int>(gen);
|
||||
o_podunordered_multiset.insert(value);
|
||||
o_podunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::unordered_multiset<StructInternalSerialize, StructHash<StructInternalSerialize>> o_iserunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
StructInternalSerialize value = { random_value<int>(gen), random_value<int>(gen) };
|
||||
o_iserunordered_multiset.insert(value);
|
||||
o_iserunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::unordered_multiset<StructInternalSplit, StructHash<StructInternalSplit>> o_isplunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
StructInternalSplit value = { random_value<int>(gen), random_value<int>(gen) };
|
||||
o_isplunordered_multiset.insert(value);
|
||||
o_isplunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::unordered_multiset<StructExternalSerialize, StructHash<StructExternalSerialize>> o_eserunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
StructExternalSerialize value = { random_value<int>(gen), random_value<int>(gen) };
|
||||
o_eserunordered_multiset.insert(value);
|
||||
o_eserunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::unordered_multiset<StructExternalSplit, StructHash<StructExternalSplit>> o_esplunordered_multiset;
|
||||
for(int j=0; j<100; ++j)
|
||||
{
|
||||
StructExternalSplit value = { random_value<int>(gen), random_value<int>(gen) };
|
||||
o_esplunordered_multiset.insert(value);
|
||||
o_esplunordered_multiset.insert(value);
|
||||
}
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podunordered_multiset);
|
||||
oar(o_iserunordered_multiset);
|
||||
oar(o_isplunordered_multiset);
|
||||
oar(o_eserunordered_multiset);
|
||||
oar(o_esplunordered_multiset);
|
||||
}
|
||||
|
||||
std::unordered_multiset<int> i_podunordered_multiset;
|
||||
std::unordered_multiset<StructInternalSerialize, StructHash<StructInternalSerialize>> i_iserunordered_multiset;
|
||||
std::unordered_multiset<StructInternalSplit, StructHash<StructInternalSplit>> i_isplunordered_multiset;
|
||||
std::unordered_multiset<StructExternalSerialize, StructHash<StructExternalSerialize>> i_eserunordered_multiset;
|
||||
std::unordered_multiset<StructExternalSplit, StructHash<StructExternalSplit>> i_esplunordered_multiset;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podunordered_multiset);
|
||||
iar(i_iserunordered_multiset);
|
||||
iar(i_isplunordered_multiset);
|
||||
iar(i_eserunordered_multiset);
|
||||
iar(i_esplunordered_multiset);
|
||||
}
|
||||
|
||||
for(auto const & p : i_podunordered_multiset)
|
||||
{
|
||||
CHECK_EQ(o_podunordered_multiset.count(p), i_podunordered_multiset.count(p));
|
||||
}
|
||||
|
||||
for(auto const & p : i_iserunordered_multiset)
|
||||
{
|
||||
CHECK_EQ(o_iserunordered_multiset.count(p), i_iserunordered_multiset.count(p));
|
||||
}
|
||||
|
||||
for(auto const & p : i_isplunordered_multiset)
|
||||
{
|
||||
CHECK_EQ(o_isplunordered_multiset.count(p), i_isplunordered_multiset.count(p));
|
||||
}
|
||||
|
||||
for(auto const & p : i_eserunordered_multiset)
|
||||
{
|
||||
CHECK_EQ(o_eserunordered_multiset.count(p), i_eserunordered_multiset.count(p));
|
||||
}
|
||||
|
||||
for(auto const & p : i_esplunordered_multiset)
|
||||
{
|
||||
CHECK_EQ(o_esplunordered_multiset.count(p), i_esplunordered_multiset.count(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_UNORDERED_MULTISET_H_
|
@ -24,110 +24,29 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "unordered_set.hpp"
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_unordered_set()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
TEST_SUITE("unordered_set");
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::unordered_set<int> o_podunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_podunordered_set.insert(random_value<int>(gen));
|
||||
|
||||
std::unordered_set<StructInternalSerialize, StructHash<StructInternalSerialize>> o_iserunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_iserunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::unordered_set<StructInternalSplit, StructHash<StructInternalSplit>> o_isplunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_isplunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::unordered_set<StructExternalSerialize, StructHash<StructExternalSerialize>> o_eserunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_eserunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::unordered_set<StructExternalSplit, StructHash<StructExternalSplit>> o_esplunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_esplunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podunordered_set);
|
||||
oar(o_iserunordered_set);
|
||||
oar(o_isplunordered_set);
|
||||
oar(o_eserunordered_set);
|
||||
oar(o_esplunordered_set);
|
||||
}
|
||||
|
||||
std::unordered_set<int> i_podunordered_set;
|
||||
std::unordered_set<StructInternalSerialize, StructHash<StructInternalSerialize>> i_iserunordered_set;
|
||||
std::unordered_set<StructInternalSplit, StructHash<StructInternalSplit>> i_isplunordered_set;
|
||||
std::unordered_set<StructExternalSerialize, StructHash<StructExternalSerialize>> i_eserunordered_set;
|
||||
std::unordered_set<StructExternalSplit, StructHash<StructExternalSplit>> i_esplunordered_set;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podunordered_set);
|
||||
iar(i_iserunordered_set);
|
||||
iar(i_isplunordered_set);
|
||||
iar(i_eserunordered_set);
|
||||
iar(i_esplunordered_set);
|
||||
}
|
||||
|
||||
for(auto const & p : i_podunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_podunordered_set.count(p), 1lu);
|
||||
}
|
||||
|
||||
for(auto const & p : i_iserunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_iserunordered_set.count(p), 1lu);
|
||||
}
|
||||
|
||||
for(auto const & p : i_isplunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_isplunordered_set.count(p), 1lu);
|
||||
}
|
||||
|
||||
for(auto const & p : i_eserunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_eserunordered_set.count(p), 1lu);
|
||||
}
|
||||
|
||||
for(auto const & p : i_esplunordered_set)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(o_esplunordered_set.count(p), 1lu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_unordered_set )
|
||||
TEST_CASE("binary_unordered_set")
|
||||
{
|
||||
test_unordered_set<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_unordered_set )
|
||||
TEST_CASE("portable_binary_unordered_set")
|
||||
{
|
||||
test_unordered_set<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_unordered_set )
|
||||
TEST_CASE("xml_unordered_set")
|
||||
{
|
||||
test_unordered_set<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_unordered_set )
|
||||
TEST_CASE("json_unordered_set")
|
||||
{
|
||||
test_unordered_set<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
114
unittests/unordered_set.hpp
Normal file
114
unittests/unordered_set.hpp
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_UNORDERED_SET_H_
|
||||
#define CEREAL_TEST_UNORDERED_SET_H_
|
||||
#include "common.hpp"
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_unordered_set()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::unordered_set<int> o_podunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_podunordered_set.insert(random_value<int>(gen));
|
||||
|
||||
std::unordered_set<StructInternalSerialize, StructHash<StructInternalSerialize>> o_iserunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_iserunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::unordered_set<StructInternalSplit, StructHash<StructInternalSplit>> o_isplunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_isplunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::unordered_set<StructExternalSerialize, StructHash<StructExternalSerialize>> o_eserunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_eserunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::unordered_set<StructExternalSplit, StructHash<StructExternalSplit>> o_esplunordered_set;
|
||||
for(int j=0; j<100; ++j)
|
||||
o_esplunordered_set.insert({ random_value<int>(gen), random_value<int>(gen) });
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podunordered_set);
|
||||
oar(o_iserunordered_set);
|
||||
oar(o_isplunordered_set);
|
||||
oar(o_eserunordered_set);
|
||||
oar(o_esplunordered_set);
|
||||
}
|
||||
|
||||
std::unordered_set<int> i_podunordered_set;
|
||||
std::unordered_set<StructInternalSerialize, StructHash<StructInternalSerialize>> i_iserunordered_set;
|
||||
std::unordered_set<StructInternalSplit, StructHash<StructInternalSplit>> i_isplunordered_set;
|
||||
std::unordered_set<StructExternalSerialize, StructHash<StructExternalSerialize>> i_eserunordered_set;
|
||||
std::unordered_set<StructExternalSplit, StructHash<StructExternalSplit>> i_esplunordered_set;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podunordered_set);
|
||||
iar(i_iserunordered_set);
|
||||
iar(i_isplunordered_set);
|
||||
iar(i_eserunordered_set);
|
||||
iar(i_esplunordered_set);
|
||||
}
|
||||
|
||||
for(auto const & p : i_podunordered_set)
|
||||
{
|
||||
CHECK_EQ(o_podunordered_set.count(p), 1lu);
|
||||
}
|
||||
|
||||
for(auto const & p : i_iserunordered_set)
|
||||
{
|
||||
CHECK_EQ(o_iserunordered_set.count(p), 1lu);
|
||||
}
|
||||
|
||||
for(auto const & p : i_isplunordered_set)
|
||||
{
|
||||
CHECK_EQ(o_isplunordered_set.count(p), 1lu);
|
||||
}
|
||||
|
||||
for(auto const & p : i_eserunordered_set)
|
||||
{
|
||||
CHECK_EQ(o_eserunordered_set.count(p), 1lu);
|
||||
}
|
||||
|
||||
for(auto const & p : i_esplunordered_set)
|
||||
{
|
||||
CHECK_EQ(o_esplunordered_set.count(p), 1lu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_UNORDERED_SET_H_
|
@ -24,114 +24,29 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#define CEREAL_FUTURE_EXPERIMENTAL
|
||||
#include <cereal/archives/adapters.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "user_data_adapters.hpp"
|
||||
|
||||
struct SomeStruct {};
|
||||
TEST_SUITE("user_data_adapters");
|
||||
|
||||
struct UserData
|
||||
{
|
||||
UserData( SomeStruct * pp, SomeStruct & r ) :
|
||||
p(pp), ref(r) {}
|
||||
|
||||
SomeStruct * p;
|
||||
std::reference_wrapper<SomeStruct> ref;
|
||||
};
|
||||
|
||||
struct UserStruct
|
||||
{
|
||||
UserStruct( std::int32_t i,
|
||||
SomeStruct * pointer,
|
||||
SomeStruct & reference ) :
|
||||
i32( i ),
|
||||
p( pointer ),
|
||||
ref( reference )
|
||||
{ }
|
||||
|
||||
UserStruct & operator=( UserStruct const & ) = delete;
|
||||
|
||||
std::int32_t i32;
|
||||
SomeStruct const * p;
|
||||
SomeStruct & ref;
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar )
|
||||
{
|
||||
ar( i32 );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
static void load_and_construct( Archive & ar, cereal::construct<UserStruct> & construct )
|
||||
{
|
||||
std::int32_t ii;
|
||||
ar( ii );
|
||||
auto & data = cereal::get_user_data<UserData>( ar );
|
||||
construct( ii, data.p, data.ref.get() );
|
||||
}
|
||||
};
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_user_data_adapters()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
auto rng = [&](){ return random_value<int>(gen); };
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
SomeStruct ss;
|
||||
std::unique_ptr<UserStruct> o_ptr( new UserStruct( rng(), &ss, ss ) );
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_ptr);
|
||||
}
|
||||
|
||||
decltype( o_ptr ) i_ptr;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
UserData ud(&ss, ss);
|
||||
cereal::UserDataAdapter<UserData, IArchive> iar(ud, is);
|
||||
|
||||
iar(i_ptr);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL( i_ptr->p == o_ptr->p, true );
|
||||
BOOST_CHECK_EQUAL( std::addressof(i_ptr->ref) == std::addressof(o_ptr->ref), true );
|
||||
BOOST_CHECK_EQUAL( i_ptr->i32, o_ptr->i32 );
|
||||
|
||||
std::istringstream bad_is(os.str());
|
||||
{
|
||||
IArchive iar(bad_is);
|
||||
|
||||
BOOST_CHECK_THROW( iar(i_ptr), ::cereal::Exception );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_user_data_adapters )
|
||||
TEST_CASE("binary_user_data_adapters")
|
||||
{
|
||||
test_user_data_adapters<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_user_data_adapters )
|
||||
TEST_CASE("portable_binary_user_data_adapters")
|
||||
{
|
||||
test_user_data_adapters<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_user_data_adapters )
|
||||
TEST_CASE("xml_user_data_adapters")
|
||||
{
|
||||
test_user_data_adapters<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_user_data_adapters )
|
||||
TEST_CASE("json_user_data_adapters")
|
||||
{
|
||||
test_user_data_adapters<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
120
unittests/user_data_adapters.hpp
Normal file
120
unittests/user_data_adapters.hpp
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_USER_DATA_ADAPTERS_H_
|
||||
#define CEREAL_TEST_USER_DATA_ADAPTERS_H_
|
||||
|
||||
#include "common.hpp"
|
||||
#define CEREAL_FUTURE_EXPERIMENTAL
|
||||
#include <cereal/archives/adapters.hpp>
|
||||
|
||||
struct SomeStruct {};
|
||||
|
||||
struct UserData
|
||||
{
|
||||
UserData( SomeStruct * pp, SomeStruct & r ) :
|
||||
p(pp), ref(r) {}
|
||||
|
||||
SomeStruct * p;
|
||||
std::reference_wrapper<SomeStruct> ref;
|
||||
};
|
||||
|
||||
struct UserStruct
|
||||
{
|
||||
UserStruct( std::int32_t i,
|
||||
SomeStruct * pointer,
|
||||
SomeStruct & reference ) :
|
||||
i32( i ),
|
||||
p( pointer ),
|
||||
ref( reference )
|
||||
{ }
|
||||
|
||||
UserStruct & operator=( UserStruct const & ) = delete;
|
||||
|
||||
std::int32_t i32;
|
||||
SomeStruct const * p;
|
||||
SomeStruct & ref;
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar )
|
||||
{
|
||||
ar( i32 );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
static void load_and_construct( Archive & ar, cereal::construct<UserStruct> & construct )
|
||||
{
|
||||
std::int32_t ii;
|
||||
ar( ii );
|
||||
auto & data = cereal::get_user_data<UserData>( ar );
|
||||
construct( ii, data.p, data.ref.get() );
|
||||
}
|
||||
};
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_user_data_adapters()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
auto rng = [&](){ return random_value<int>(gen); };
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
SomeStruct ss;
|
||||
std::unique_ptr<UserStruct> o_ptr( new UserStruct( rng(), &ss, ss ) );
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_ptr);
|
||||
}
|
||||
|
||||
decltype( o_ptr ) i_ptr;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
UserData ud(&ss, ss);
|
||||
cereal::UserDataAdapter<UserData, IArchive> iar(ud, is);
|
||||
|
||||
iar(i_ptr);
|
||||
}
|
||||
|
||||
CHECK_EQ( i_ptr->p, o_ptr->p );
|
||||
CHECK_EQ( std::addressof(i_ptr->ref), std::addressof(o_ptr->ref) );
|
||||
CHECK_EQ( i_ptr->i32, o_ptr->i32 );
|
||||
|
||||
std::istringstream bad_is(os.str());
|
||||
{
|
||||
IArchive iar(bad_is);
|
||||
|
||||
CHECK_THROWS_AS( iar(i_ptr), ::cereal::Exception );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_USER_DATA_ADAPTERS_H_
|
@ -24,96 +24,29 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "valarray.hpp"
|
||||
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
TEST_SUITE("valarray");
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_valarray()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for (int ii = 0; ii<100; ++ii)
|
||||
{
|
||||
std::valarray<int> o_podvalarray(100);
|
||||
for (auto & elem : o_podvalarray)
|
||||
elem = random_value<int>(gen);
|
||||
|
||||
std::valarray<StructInternalSerialize> o_iservalarray(100);
|
||||
for (auto & elem : o_iservalarray)
|
||||
elem = StructInternalSerialize(random_value<int>(gen), random_value<int>(gen));
|
||||
|
||||
std::valarray<StructInternalSplit> o_isplvalarray(100);
|
||||
for (auto & elem : o_isplvalarray)
|
||||
elem = StructInternalSplit(random_value<int>(gen), random_value<int>(gen));
|
||||
|
||||
std::valarray<StructExternalSerialize> o_eservalarray(100);
|
||||
for (auto & elem : o_eservalarray)
|
||||
elem = StructExternalSerialize(random_value<int>(gen), random_value<int>(gen));
|
||||
|
||||
std::valarray<StructExternalSplit> o_esplvalarray(100);
|
||||
for (auto & elem : o_esplvalarray)
|
||||
elem = StructExternalSplit(random_value<int>(gen), random_value<int>(gen));
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podvalarray);
|
||||
oar(o_iservalarray);
|
||||
oar(o_isplvalarray);
|
||||
oar(o_eservalarray);
|
||||
oar(o_esplvalarray);
|
||||
}
|
||||
|
||||
std::valarray<int> i_podvalarray;
|
||||
std::valarray<StructInternalSerialize> i_iservalarray;
|
||||
std::valarray<StructInternalSplit> i_isplvalarray;
|
||||
std::valarray<StructExternalSerialize> i_eservalarray;
|
||||
std::valarray<StructExternalSplit> i_esplvalarray;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podvalarray);
|
||||
iar(i_iservalarray);
|
||||
iar(i_isplvalarray);
|
||||
iar(i_eservalarray);
|
||||
iar(i_esplvalarray);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL(i_podvalarray.size(), o_podvalarray.size());
|
||||
BOOST_CHECK_EQUAL(i_iservalarray.size(), o_iservalarray.size());
|
||||
BOOST_CHECK_EQUAL(i_isplvalarray.size(), o_isplvalarray.size());
|
||||
BOOST_CHECK_EQUAL(i_eservalarray.size(), o_eservalarray.size());
|
||||
BOOST_CHECK_EQUAL(i_esplvalarray.size(), o_esplvalarray.size());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(i_podvalarray), std::end(i_podvalarray), std::begin(o_podvalarray), std::end(o_podvalarray));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(i_iservalarray), std::end(i_iservalarray), std::begin(o_iservalarray), std::end(o_iservalarray));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(i_isplvalarray), std::end(i_isplvalarray), std::begin(o_isplvalarray), std::end(o_isplvalarray));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(i_eservalarray), std::end(i_eservalarray), std::begin(o_eservalarray), std::end(o_eservalarray));
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(std::begin(i_esplvalarray), std::end(i_esplvalarray), std::begin(o_esplvalarray), std::end(o_esplvalarray));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(binary_valarray)
|
||||
TEST_CASE("binary_valarray")
|
||||
{
|
||||
test_valarray<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(portable_binary_valarray)
|
||||
TEST_CASE("portable_binary_valarray")
|
||||
{
|
||||
test_valarray<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(xml_valarray)
|
||||
TEST_CASE("xml_valarray")
|
||||
{
|
||||
test_valarray<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(json_valarray)
|
||||
TEST_CASE("json_valarray")
|
||||
{
|
||||
test_valarray<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
101
unittests/valarray.hpp
Normal file
101
unittests/valarray.hpp
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_VALARRAY_H_
|
||||
#define CEREAL_TEST_VALARRAY_H_
|
||||
#include "common.hpp"
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_valarray()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for (int ii = 0; ii<100; ++ii)
|
||||
{
|
||||
std::valarray<int> o_podvalarray(100);
|
||||
for (auto & elem : o_podvalarray)
|
||||
elem = random_value<int>(gen);
|
||||
|
||||
std::valarray<StructInternalSerialize> o_iservalarray(100);
|
||||
for (auto & elem : o_iservalarray)
|
||||
elem = StructInternalSerialize(random_value<int>(gen), random_value<int>(gen));
|
||||
|
||||
std::valarray<StructInternalSplit> o_isplvalarray(100);
|
||||
for (auto & elem : o_isplvalarray)
|
||||
elem = StructInternalSplit(random_value<int>(gen), random_value<int>(gen));
|
||||
|
||||
std::valarray<StructExternalSerialize> o_eservalarray(100);
|
||||
for (auto & elem : o_eservalarray)
|
||||
elem = StructExternalSerialize(random_value<int>(gen), random_value<int>(gen));
|
||||
|
||||
std::valarray<StructExternalSplit> o_esplvalarray(100);
|
||||
for (auto & elem : o_esplvalarray)
|
||||
elem = StructExternalSplit(random_value<int>(gen), random_value<int>(gen));
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podvalarray);
|
||||
oar(o_iservalarray);
|
||||
oar(o_isplvalarray);
|
||||
oar(o_eservalarray);
|
||||
oar(o_esplvalarray);
|
||||
}
|
||||
|
||||
std::valarray<int> i_podvalarray;
|
||||
std::valarray<StructInternalSerialize> i_iservalarray;
|
||||
std::valarray<StructInternalSplit> i_isplvalarray;
|
||||
std::valarray<StructExternalSerialize> i_eservalarray;
|
||||
std::valarray<StructExternalSplit> i_esplvalarray;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podvalarray);
|
||||
iar(i_iservalarray);
|
||||
iar(i_isplvalarray);
|
||||
iar(i_eservalarray);
|
||||
iar(i_esplvalarray);
|
||||
}
|
||||
|
||||
CHECK_EQ(i_podvalarray.size(), o_podvalarray.size());
|
||||
CHECK_EQ(i_iservalarray.size(), o_iservalarray.size());
|
||||
CHECK_EQ(i_isplvalarray.size(), o_isplvalarray.size());
|
||||
CHECK_EQ(i_eservalarray.size(), o_eservalarray.size());
|
||||
CHECK_EQ(i_esplvalarray.size(), o_esplvalarray.size());
|
||||
|
||||
check_collection(i_podvalarray , o_podvalarray );
|
||||
check_collection(i_iservalarray, o_iservalarray);
|
||||
check_collection(i_isplvalarray, o_isplvalarray);
|
||||
check_collection(i_eservalarray, o_eservalarray);
|
||||
check_collection(i_esplvalarray, o_esplvalarray);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_VALARRAY_H_
|
@ -24,106 +24,29 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "vector.hpp"
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_vector()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
TEST_SUITE("vector");
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::vector<int> o_podvector(100);
|
||||
for(auto & elem : o_podvector)
|
||||
elem = random_value<int>(gen);
|
||||
|
||||
std::vector<bool> o_boolvector; o_boolvector.resize(100);
|
||||
for( size_t i = 0; i < 100; ++i )
|
||||
o_boolvector[i] = (random_value<int>(gen) % 2) == 0;
|
||||
|
||||
std::vector<StructInternalSerialize> o_iservector(100);
|
||||
for(auto & elem : o_iservector)
|
||||
elem = StructInternalSerialize( random_value<int>(gen), random_value<int>(gen) );
|
||||
|
||||
std::vector<StructInternalSplit> o_isplvector(100);
|
||||
for(auto & elem : o_isplvector)
|
||||
elem = StructInternalSplit( random_value<int>(gen), random_value<int>(gen) );
|
||||
|
||||
std::vector<StructExternalSerialize> o_eservector(100);
|
||||
for(auto & elem : o_eservector)
|
||||
elem = StructExternalSerialize( random_value<int>(gen), random_value<int>(gen) );
|
||||
|
||||
std::vector<StructExternalSplit> o_esplvector(100);
|
||||
for(auto & elem : o_esplvector)
|
||||
elem = StructExternalSplit( random_value<int>(gen), random_value<int>(gen) );
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podvector);
|
||||
oar(o_boolvector);
|
||||
oar(o_iservector);
|
||||
oar(o_isplvector);
|
||||
oar(o_eservector);
|
||||
oar(o_esplvector);
|
||||
}
|
||||
|
||||
std::vector<int> i_podvector;
|
||||
std::vector<bool> i_boolvector;
|
||||
std::vector<StructInternalSerialize> i_iservector;
|
||||
std::vector<StructInternalSplit> i_isplvector;
|
||||
std::vector<StructExternalSerialize> i_eservector;
|
||||
std::vector<StructExternalSplit> i_esplvector;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podvector);
|
||||
iar(i_boolvector);
|
||||
iar(i_iservector);
|
||||
iar(i_isplvector);
|
||||
iar(i_eservector);
|
||||
iar(i_esplvector);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL(i_podvector.size(), o_podvector.size());
|
||||
BOOST_CHECK_EQUAL(i_boolvector.size(), o_boolvector.size());
|
||||
BOOST_CHECK_EQUAL(i_iservector.size(), o_iservector.size());
|
||||
BOOST_CHECK_EQUAL(i_isplvector.size(), o_isplvector.size());
|
||||
BOOST_CHECK_EQUAL(i_eservector.size(), o_eservector.size());
|
||||
BOOST_CHECK_EQUAL(i_esplvector.size(), o_esplvector.size());
|
||||
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(i_podvector.begin(), i_podvector.end(), o_podvector.begin(), o_podvector.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(i_boolvector.begin(), i_boolvector.end(), o_boolvector.begin(), o_boolvector.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(i_iservector.begin(), i_iservector.end(), o_iservector.begin(), o_iservector.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(i_isplvector.begin(), i_isplvector.end(), o_isplvector.begin(), o_isplvector.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(i_eservector.begin(), i_eservector.end(), o_eservector.begin(), o_eservector.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(i_esplvector.begin(), i_esplvector.end(), o_esplvector.begin(), o_esplvector.end());
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_vector )
|
||||
TEST_CASE("binary_vector")
|
||||
{
|
||||
test_vector<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_vector )
|
||||
TEST_CASE("portable_binary_vector")
|
||||
{
|
||||
test_vector<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_vector )
|
||||
TEST_CASE("xml_vector")
|
||||
{
|
||||
test_vector<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_vector )
|
||||
TEST_CASE("json_vector")
|
||||
{
|
||||
test_vector<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
110
unittests/vector.hpp
Normal file
110
unittests/vector.hpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_VECTOR_H_
|
||||
#define CEREAL_TEST_VECTOR_H_
|
||||
#include "common.hpp"
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_vector()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for(int ii=0; ii<100; ++ii)
|
||||
{
|
||||
std::vector<int> o_podvector(100);
|
||||
for(auto & elem : o_podvector)
|
||||
elem = random_value<int>(gen);
|
||||
|
||||
std::vector<bool> o_boolvector; o_boolvector.resize(100);
|
||||
for( size_t i = 0; i < 100; ++i )
|
||||
o_boolvector[i] = (random_value<int>(gen) % 2) == 0;
|
||||
|
||||
std::vector<StructInternalSerialize> o_iservector(100);
|
||||
for(auto & elem : o_iservector)
|
||||
elem = StructInternalSerialize( random_value<int>(gen), random_value<int>(gen) );
|
||||
|
||||
std::vector<StructInternalSplit> o_isplvector(100);
|
||||
for(auto & elem : o_isplvector)
|
||||
elem = StructInternalSplit( random_value<int>(gen), random_value<int>(gen) );
|
||||
|
||||
std::vector<StructExternalSerialize> o_eservector(100);
|
||||
for(auto & elem : o_eservector)
|
||||
elem = StructExternalSerialize( random_value<int>(gen), random_value<int>(gen) );
|
||||
|
||||
std::vector<StructExternalSplit> o_esplvector(100);
|
||||
for(auto & elem : o_esplvector)
|
||||
elem = StructExternalSplit( random_value<int>(gen), random_value<int>(gen) );
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
|
||||
oar(o_podvector);
|
||||
oar(o_boolvector);
|
||||
oar(o_iservector);
|
||||
oar(o_isplvector);
|
||||
oar(o_eservector);
|
||||
oar(o_esplvector);
|
||||
}
|
||||
|
||||
std::vector<int> i_podvector;
|
||||
std::vector<bool> i_boolvector;
|
||||
std::vector<StructInternalSerialize> i_iservector;
|
||||
std::vector<StructInternalSplit> i_isplvector;
|
||||
std::vector<StructExternalSerialize> i_eservector;
|
||||
std::vector<StructExternalSplit> i_esplvector;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
|
||||
iar(i_podvector);
|
||||
iar(i_boolvector);
|
||||
iar(i_iservector);
|
||||
iar(i_isplvector);
|
||||
iar(i_eservector);
|
||||
iar(i_esplvector);
|
||||
}
|
||||
|
||||
CHECK_EQ(i_podvector.size(), o_podvector.size());
|
||||
CHECK_EQ(i_boolvector.size(), o_boolvector.size());
|
||||
CHECK_EQ(i_iservector.size(), o_iservector.size());
|
||||
CHECK_EQ(i_isplvector.size(), o_isplvector.size());
|
||||
CHECK_EQ(i_eservector.size(), o_eservector.size());
|
||||
CHECK_EQ(i_esplvector.size(), o_esplvector.size());
|
||||
|
||||
check_collection(i_podvector, o_podvector );
|
||||
check_collection(i_boolvector, o_boolvector);
|
||||
check_collection(i_iservector, o_iservector);
|
||||
check_collection(i_isplvector, o_isplvector);
|
||||
check_collection(i_eservector, o_eservector);
|
||||
check_collection(i_esplvector, o_esplvector);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CEREAL_TEST_VECTOR_H_
|
@ -24,227 +24,51 @@
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "versioning.hpp"
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
#include <future>
|
||||
static std::mutex boostTestMutex;
|
||||
#endif
|
||||
TEST_SUITE("versioning");
|
||||
|
||||
namespace Nested
|
||||
{
|
||||
struct NestedClass
|
||||
{
|
||||
int x;
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar )
|
||||
{ ar( x ); }
|
||||
};
|
||||
}
|
||||
|
||||
CEREAL_CLASS_VERSION( Nested::NestedClass, 1 )
|
||||
|
||||
class VersionStructMS
|
||||
{
|
||||
public:
|
||||
bool x;
|
||||
std::uint32_t v;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, std::uint32_t const version )
|
||||
{
|
||||
ar( x );
|
||||
v = version;
|
||||
}
|
||||
};
|
||||
|
||||
struct VersionStructMSP
|
||||
{
|
||||
uint8_t x;
|
||||
std::uint32_t v;
|
||||
template <class Archive>
|
||||
void save( Archive & ar, std::uint32_t const /*version*/ ) const
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, std::uint32_t const version )
|
||||
{
|
||||
ar( x );
|
||||
v = version;
|
||||
}
|
||||
};
|
||||
|
||||
struct VersionStructNMS
|
||||
{
|
||||
std::int32_t x;
|
||||
std::uint32_t v;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, VersionStructNMS & vnms, const std::uint32_t version )
|
||||
{
|
||||
ar( vnms.x );
|
||||
vnms.v = version;
|
||||
}
|
||||
|
||||
struct VersionStructNMSP
|
||||
{
|
||||
double x;
|
||||
std::uint32_t v;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ar, VersionStructNMSP const & vnms, const std::uint32_t /*version*/ )
|
||||
{
|
||||
ar( vnms.x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, VersionStructNMSP & vnms, const std::uint32_t version )
|
||||
{
|
||||
ar( vnms.x );
|
||||
vnms.v = version;
|
||||
}
|
||||
|
||||
CEREAL_CLASS_VERSION( VersionStructMSP, 33 )
|
||||
CEREAL_CLASS_VERSION( VersionStructNMS, 66 )
|
||||
CEREAL_CLASS_VERSION( VersionStructNMSP, 99 )
|
||||
|
||||
template <class IArchive, class OArchive>
|
||||
void test_versioning()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
for(size_t i=0; i<100; ++i)
|
||||
{
|
||||
VersionStructMS o_MS = {random_value<uint8_t>(gen) % 2 ? true : false, 1};
|
||||
VersionStructMSP o_MSP = {random_value<uint8_t>(gen), 1};
|
||||
VersionStructNMS o_NMS = {random_value<int32_t>(gen), 1};
|
||||
VersionStructNMSP o_NMSP = {random_value<double>(gen), 1};
|
||||
VersionStructMS o_MS2 = {random_value<uint8_t>(gen) % 2 ? true : false, 1};
|
||||
VersionStructMSP o_MSP2 = {random_value<uint8_t>(gen), 1};
|
||||
VersionStructNMS o_NMS2 = {random_value<int32_t>(gen), 1};
|
||||
VersionStructNMSP o_NMSP2 = {random_value<double>(gen), 1};
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
oar( o_MS );
|
||||
oar( o_MSP );
|
||||
oar( o_NMS );
|
||||
oar( o_NMSP );
|
||||
oar( o_MS2 );
|
||||
oar( o_MSP2 );
|
||||
oar( o_NMS2 );
|
||||
oar( o_NMSP2 );
|
||||
}
|
||||
|
||||
decltype(o_MS) i_MS;
|
||||
decltype(o_MSP) i_MSP;
|
||||
decltype(o_NMS) i_NMS;
|
||||
decltype(o_NMSP) i_NMSP;
|
||||
decltype(o_MS2) i_MS2;
|
||||
decltype(o_MSP2) i_MSP2;
|
||||
decltype(o_NMS2) i_NMS2;
|
||||
decltype(o_NMSP2) i_NMSP2;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
iar( i_MS );
|
||||
iar( i_MSP );
|
||||
iar( i_NMS );
|
||||
iar( i_NMSP );
|
||||
iar( i_MS2 );
|
||||
iar( i_MSP2 );
|
||||
iar( i_NMS2 );
|
||||
iar( i_NMSP2 );
|
||||
}
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
std::lock_guard<std::mutex> lock( boostTestMutex );
|
||||
#endif
|
||||
|
||||
BOOST_CHECK_EQUAL(o_MS.x, i_MS.x);
|
||||
BOOST_CHECK_EQUAL(i_MS.v, 0u);
|
||||
BOOST_CHECK_EQUAL(o_MSP.x, i_MSP.x);
|
||||
BOOST_CHECK_EQUAL(i_MSP.v, 33u);
|
||||
BOOST_CHECK_EQUAL(o_NMS.x, i_NMS.x);
|
||||
BOOST_CHECK_EQUAL(i_NMS.v, 66u);
|
||||
BOOST_CHECK_CLOSE(o_NMSP.x, i_NMSP.x, 1e-5);
|
||||
BOOST_CHECK_EQUAL(i_NMSP.v, 99u);
|
||||
|
||||
BOOST_CHECK_EQUAL(o_MS2.x, i_MS2.x);
|
||||
BOOST_CHECK_EQUAL(i_MS2.v, 0u);
|
||||
BOOST_CHECK_EQUAL(o_MSP2.x, i_MSP2.x);
|
||||
BOOST_CHECK_EQUAL(i_MSP2.v, 33u);
|
||||
BOOST_CHECK_EQUAL(o_NMS2.x, i_NMS2.x);
|
||||
BOOST_CHECK_EQUAL(i_NMS2.v, 66u);
|
||||
BOOST_CHECK_CLOSE(o_NMSP2.x, i_NMSP2.x, 1e-5);
|
||||
BOOST_CHECK_EQUAL(i_NMSP2.v, 99u);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_versioning )
|
||||
TEST_CASE("binary_versioning")
|
||||
{
|
||||
test_versioning<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_versioning )
|
||||
TEST_CASE("portable_binary_versioning")
|
||||
{
|
||||
test_versioning<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_versioning )
|
||||
TEST_CASE("xml_versioning")
|
||||
{
|
||||
test_versioning<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_versioning )
|
||||
TEST_CASE("json_versioning")
|
||||
{
|
||||
test_versioning<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
template <class IArchive, class OArchive>
|
||||
void test_versioning_threading()
|
||||
{
|
||||
std::vector<std::future<bool>> pool;
|
||||
for( size_t i = 0; i < 100; ++i )
|
||||
pool.emplace_back( std::async( std::launch::async,
|
||||
[](){ test_versioning<IArchive, OArchive>(); return true; } ) );
|
||||
|
||||
for( auto & future : pool )
|
||||
future.wait();
|
||||
|
||||
for( auto & future : pool )
|
||||
BOOST_CHECK( future.get() == true );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( binary_versioning_threading )
|
||||
TEST_CASE("binary_versioning_threading")
|
||||
{
|
||||
test_versioning_threading<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( portable_binary_versioning_threading )
|
||||
TEST_CASE("portable_binary_versioning_threading")
|
||||
{
|
||||
test_versioning_threading<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( xml_versioning_threading )
|
||||
TEST_CASE("xml_versioning_threading")
|
||||
{
|
||||
test_versioning_threading<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( json_versioning_threading )
|
||||
TEST_CASE("json_versioning_threading")
|
||||
{
|
||||
test_versioning_threading<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
||||
}
|
||||
#endif // CEREAL_THREAD_SAFE
|
||||
|
||||
TEST_SUITE_END();
|
||||
|
217
unittests/versioning.hpp
Normal file
217
unittests/versioning.hpp
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
Copyright (c) 2014, Randolph Voorhies, Shane Grant
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of cereal nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef CEREAL_TEST_VERSIONING_H_
|
||||
#define CEREAL_TEST_VERSIONING_H_
|
||||
#include "common.hpp"
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
#include <future>
|
||||
#endif
|
||||
|
||||
namespace Nested
|
||||
{
|
||||
struct NestedClass
|
||||
{
|
||||
int x;
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar )
|
||||
{ ar( x ); }
|
||||
};
|
||||
}
|
||||
|
||||
CEREAL_CLASS_VERSION( Nested::NestedClass, 1 )
|
||||
|
||||
class VersionStructMS
|
||||
{
|
||||
public:
|
||||
bool x;
|
||||
std::uint32_t v;
|
||||
|
||||
private:
|
||||
friend class cereal::access;
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, std::uint32_t const version )
|
||||
{
|
||||
ar( x );
|
||||
v = version;
|
||||
}
|
||||
};
|
||||
|
||||
struct VersionStructMSP
|
||||
{
|
||||
uint8_t x;
|
||||
std::uint32_t v;
|
||||
template <class Archive>
|
||||
void save( Archive & ar, std::uint32_t const /*version*/ ) const
|
||||
{
|
||||
ar( x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, std::uint32_t const version )
|
||||
{
|
||||
ar( x );
|
||||
v = version;
|
||||
}
|
||||
};
|
||||
|
||||
struct VersionStructNMS
|
||||
{
|
||||
std::int32_t x;
|
||||
std::uint32_t v;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void serialize( Archive & ar, VersionStructNMS & vnms, const std::uint32_t version )
|
||||
{
|
||||
ar( vnms.x );
|
||||
vnms.v = version;
|
||||
}
|
||||
|
||||
struct VersionStructNMSP
|
||||
{
|
||||
double x;
|
||||
std::uint32_t v;
|
||||
};
|
||||
|
||||
template <class Archive>
|
||||
void save( Archive & ar, VersionStructNMSP const & vnms, const std::uint32_t /*version*/ )
|
||||
{
|
||||
ar( vnms.x );
|
||||
}
|
||||
|
||||
template <class Archive>
|
||||
void load( Archive & ar, VersionStructNMSP & vnms, const std::uint32_t version )
|
||||
{
|
||||
ar( vnms.x );
|
||||
vnms.v = version;
|
||||
}
|
||||
|
||||
CEREAL_CLASS_VERSION( VersionStructMSP, 33 )
|
||||
CEREAL_CLASS_VERSION( VersionStructNMS, 66 )
|
||||
CEREAL_CLASS_VERSION( VersionStructNMSP, 99 )
|
||||
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_versioning()
|
||||
{
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
#include <future>
|
||||
static std::mutex testMutex;
|
||||
#endif
|
||||
|
||||
for(size_t i=0; i<100; ++i)
|
||||
{
|
||||
VersionStructMS o_MS = {random_value<uint8_t>(gen) % 2 ? true : false, 1};
|
||||
VersionStructMSP o_MSP = {random_value<uint8_t>(gen), 1};
|
||||
VersionStructNMS o_NMS = {random_value<int32_t>(gen), 1};
|
||||
VersionStructNMSP o_NMSP = {random_value<double>(gen), 1};
|
||||
VersionStructMS o_MS2 = {random_value<uint8_t>(gen) % 2 ? true : false, 1};
|
||||
VersionStructMSP o_MSP2 = {random_value<uint8_t>(gen), 1};
|
||||
VersionStructNMS o_NMS2 = {random_value<int32_t>(gen), 1};
|
||||
VersionStructNMSP o_NMSP2 = {random_value<double>(gen), 1};
|
||||
|
||||
std::ostringstream os;
|
||||
{
|
||||
OArchive oar(os);
|
||||
oar( o_MS );
|
||||
oar( o_MSP );
|
||||
oar( o_NMS );
|
||||
oar( o_NMSP );
|
||||
oar( o_MS2 );
|
||||
oar( o_MSP2 );
|
||||
oar( o_NMS2 );
|
||||
oar( o_NMSP2 );
|
||||
}
|
||||
|
||||
decltype(o_MS) i_MS;
|
||||
decltype(o_MSP) i_MSP;
|
||||
decltype(o_NMS) i_NMS;
|
||||
decltype(o_NMSP) i_NMSP;
|
||||
decltype(o_MS2) i_MS2;
|
||||
decltype(o_MSP2) i_MSP2;
|
||||
decltype(o_NMS2) i_NMS2;
|
||||
decltype(o_NMSP2) i_NMSP2;
|
||||
|
||||
std::istringstream is(os.str());
|
||||
{
|
||||
IArchive iar(is);
|
||||
iar( i_MS );
|
||||
iar( i_MSP );
|
||||
iar( i_NMS );
|
||||
iar( i_NMSP );
|
||||
iar( i_MS2 );
|
||||
iar( i_MSP2 );
|
||||
iar( i_NMS2 );
|
||||
iar( i_NMSP2 );
|
||||
}
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
std::lock_guard<std::mutex> lock( testMutex );
|
||||
#endif
|
||||
|
||||
CHECK_EQ(o_MS.x, i_MS.x);
|
||||
CHECK_EQ(i_MS.v, 0u);
|
||||
CHECK_EQ(o_MSP.x, i_MSP.x);
|
||||
CHECK_EQ(i_MSP.v, 33u);
|
||||
CHECK_EQ(o_NMS.x, i_NMS.x);
|
||||
CHECK_EQ(i_NMS.v, 66u);
|
||||
CHECK_EQ(o_NMSP.x, doctest::Approx(i_NMSP.x).epsilon(1e-5));
|
||||
CHECK_EQ(i_NMSP.v, 99u);
|
||||
|
||||
CHECK_EQ(o_MS2.x, i_MS2.x);
|
||||
CHECK_EQ(i_MS2.v, 0u);
|
||||
CHECK_EQ(o_MSP2.x, i_MSP2.x);
|
||||
CHECK_EQ(i_MSP2.v, 33u);
|
||||
CHECK_EQ(o_NMS2.x, i_NMS2.x);
|
||||
CHECK_EQ(i_NMS2.v, 66u);
|
||||
CHECK_EQ(o_NMSP2.x, doctest::Approx(i_NMSP2.x).epsilon(1e-5));
|
||||
CHECK_EQ(i_NMSP2.v, 99u);
|
||||
}
|
||||
}
|
||||
|
||||
#if CEREAL_THREAD_SAFE
|
||||
template <class IArchive, class OArchive> inline
|
||||
void test_versioning_threading()
|
||||
{
|
||||
std::vector<std::future<bool>> pool;
|
||||
for( size_t i = 0; i < 100; ++i )
|
||||
pool.emplace_back( std::async( std::launch::async,
|
||||
[](){ test_versioning<IArchive, OArchive>(); return true; } ) );
|
||||
|
||||
for( auto & future : pool )
|
||||
future.wait();
|
||||
|
||||
for( auto & future : pool )
|
||||
CHECK_UNARY( future.get() );
|
||||
}
|
||||
#endif // CEREAL_THREAD_SAFE
|
||||
|
||||
#endif // CEREAL_TEST_VERSIONING_H_
|
Loading…
x
Reference in New Issue
Block a user