mirror of
https://github.com/USCiLab/cereal.git
synced 2025-07-21 07:32:01 +02:00

Integrates the changes proposed by #236 Bitset will now use a chunking method when serializing to BinaryData capable archives, which should be faster, especially for larger bitsets. Archives that do not support BinaryData will continue to use the old method. Also added a larger bitset to the test case
101 lines
3.2 KiB
C++
101 lines
3.2 KiB
C++
/*
|
|
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.
|
|
*/
|
|
#include "common.hpp"
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
template <class IArchive, class OArchive>
|
|
void test_bitset()
|
|
{
|
|
std::random_device rd;
|
|
std::mt19937 gen(rd());
|
|
|
|
auto rng32 = [&](){ return random_binary_string<32>( gen ); };
|
|
auto rng65 = [&](){ return random_binary_string<65>( gen ); };
|
|
auto rng256 = [&](){ return random_binary_string<256>( gen ); };
|
|
auto rng512 = [&](){ return random_binary_string<512>( gen ); };
|
|
|
|
for(int ii=0; ii<100; ++ii)
|
|
{
|
|
std::bitset<32> o_bit32( rng32() );
|
|
std::bitset<65> o_bit65( rng65() );
|
|
std::bitset<256> o_bit256( rng256() );
|
|
std::bitset<512> o_bit512( rng512() );
|
|
|
|
std::ostringstream os;
|
|
{
|
|
OArchive oar(os);
|
|
|
|
oar(o_bit32);
|
|
oar(o_bit65);
|
|
oar(o_bit256);
|
|
oar(o_bit512);
|
|
}
|
|
|
|
std::bitset<32> i_bit32;
|
|
std::bitset<65> i_bit65;
|
|
std::bitset<256> i_bit256;
|
|
std::bitset<512> i_bit512;
|
|
|
|
std::istringstream is(os.str());
|
|
{
|
|
IArchive iar(is);
|
|
|
|
iar(i_bit32);
|
|
iar(i_bit65);
|
|
iar(i_bit256);
|
|
iar(i_bit512);
|
|
}
|
|
|
|
BOOST_CHECK_EQUAL( o_bit32, i_bit32 );
|
|
BOOST_CHECK_EQUAL( o_bit65, i_bit65 );
|
|
BOOST_CHECK_EQUAL( o_bit256, i_bit256 );
|
|
BOOST_CHECK_EQUAL( o_bit512, i_bit512 );
|
|
}
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE( binary_bitset )
|
|
{
|
|
test_bitset<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE( portable_binary_bitset )
|
|
{
|
|
test_bitset<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE( xml_bitset )
|
|
{
|
|
test_bitset<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE( json_bitset )
|
|
{
|
|
test_bitset<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
|
|
}
|
|
|
|
|