108 lines
4.1 KiB
C++
108 lines
4.1 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.
|
||
|
*/
|
||
|
#ifndef CEREAL_TEST_QUEUE_H_
|
||
|
#define CEREAL_TEST_QUEUE_H_
|
||
|
#include "common.hpp"
|
||
|
|
||
|
template <class IArchive, class OArchive> inline
|
||
|
void test_queue()
|
||
|
{
|
||
|
std::random_device rd;
|
||
|
std::mt19937 gen(rd());
|
||
|
|
||
|
for(int ii=0; ii<100; ++ii)
|
||
|
{
|
||
|
std::queue<int> o_podqueue;
|
||
|
for(int j=0; j<100; ++j)
|
||
|
o_podqueue.push(random_value<int>(gen));
|
||
|
|
||
|
std::queue<StructInternalSerialize> o_iserqueue;
|
||
|
for(int j=0; j<100; ++j)
|
||
|
o_iserqueue.push({ random_value<int>(gen), random_value<int>(gen) });
|
||
|
|
||
|
std::queue<StructInternalSplit> o_isplqueue;
|
||
|
for(int j=0; j<100; ++j)
|
||
|
o_isplqueue.push({ random_value<int>(gen), random_value<int>(gen) });
|
||
|
|
||
|
std::queue<StructExternalSerialize> o_eserqueue;
|
||
|
for(int j=0; j<100; ++j)
|
||
|
o_eserqueue.push({ random_value<int>(gen), random_value<int>(gen) });
|
||
|
|
||
|
std::queue<StructExternalSplit> o_esplqueue;
|
||
|
for(int j=0; j<100; ++j)
|
||
|
o_esplqueue.push({ random_value<int>(gen), random_value<int>(gen) });
|
||
|
|
||
|
std::ostringstream os;
|
||
|
{
|
||
|
OArchive oar(os);
|
||
|
|
||
|
oar(o_podqueue);
|
||
|
oar(o_iserqueue);
|
||
|
oar(o_isplqueue);
|
||
|
oar(o_eserqueue);
|
||
|
oar(o_esplqueue);
|
||
|
}
|
||
|
|
||
|
std::queue<int> i_podqueue;
|
||
|
std::queue<StructInternalSerialize> i_iserqueue;
|
||
|
std::queue<StructInternalSplit> i_isplqueue;
|
||
|
std::queue<StructExternalSerialize> i_eserqueue;
|
||
|
std::queue<StructExternalSplit> i_esplqueue;
|
||
|
|
||
|
std::istringstream is(os.str());
|
||
|
{
|
||
|
IArchive iar(is);
|
||
|
|
||
|
iar(i_podqueue);
|
||
|
iar(i_iserqueue);
|
||
|
iar(i_isplqueue);
|
||
|
iar(i_eserqueue);
|
||
|
iar(i_esplqueue);
|
||
|
}
|
||
|
|
||
|
auto & i_podqueue_c = cereal::queue_detail::container(i_podqueue);
|
||
|
auto & i_iserqueue_c = cereal::queue_detail::container(i_iserqueue);
|
||
|
auto & i_isplqueue_c = cereal::queue_detail::container(i_isplqueue);
|
||
|
auto & i_eserqueue_c = cereal::queue_detail::container(i_eserqueue);
|
||
|
auto & i_esplqueue_c = cereal::queue_detail::container(i_esplqueue);
|
||
|
|
||
|
auto & o_podqueue_c = cereal::queue_detail::container(o_podqueue);
|
||
|
auto & o_iserqueue_c = cereal::queue_detail::container(o_iserqueue);
|
||
|
auto & o_isplqueue_c = cereal::queue_detail::container(o_isplqueue);
|
||
|
auto & o_eserqueue_c = cereal::queue_detail::container(o_eserqueue);
|
||
|
auto & o_esplqueue_c = cereal::queue_detail::container(o_esplqueue);
|
||
|
|
||
|
check_collection(i_podqueue_c, o_podqueue_c);
|
||
|
check_collection(i_iserqueue_c, o_iserqueue_c);
|
||
|
check_collection(i_isplqueue_c, o_isplqueue_c);
|
||
|
check_collection(i_eserqueue_c, o_eserqueue_c);
|
||
|
check_collection(i_esplqueue_c, o_esplqueue_c);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endif // CEREAL_TEST_QUEUE_H_
|