Skip to content

Commit 07818f4

Browse files
committed
1 parent b5e500d commit 07818f4

File tree

8 files changed

+558
-420
lines changed

8 files changed

+558
-420
lines changed

unittests/set.cpp

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,90 +24,29 @@
2424
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
27-
#include "common.hpp"
28-
#include <boost/test/unit_test.hpp>
27+
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
28+
#include "set.hpp"
2929

30-
template <class IArchive, class OArchive>
31-
void test_set()
32-
{
33-
std::random_device rd;
34-
std::mt19937 gen(rd());
35-
36-
for(int ii=0; ii<100; ++ii)
37-
{
38-
std::set<int> o_podset;
39-
for(int j=0; j<100; ++j)
40-
o_podset.insert(random_value<int>(gen));
41-
42-
std::set<StructInternalSerialize> o_iserset;
43-
for(int j=0; j<100; ++j)
44-
o_iserset.insert({ random_value<int>(gen), random_value<int>(gen) });
45-
46-
std::set<StructInternalSplit> o_isplset;
47-
for(int j=0; j<100; ++j)
48-
o_isplset.insert({ random_value<int>(gen), random_value<int>(gen) });
49-
50-
std::set<StructExternalSerialize> o_eserset;
51-
for(int j=0; j<100; ++j)
52-
o_eserset.insert({ random_value<int>(gen), random_value<int>(gen) });
53-
54-
std::set<StructExternalSplit> o_esplset;
55-
for(int j=0; j<100; ++j)
56-
o_esplset.insert({ random_value<int>(gen), random_value<int>(gen) });
57-
58-
std::ostringstream os;
59-
{
60-
OArchive oar(os);
61-
62-
oar(o_podset);
63-
oar(o_iserset);
64-
oar(o_isplset);
65-
oar(o_eserset);
66-
oar(o_esplset);
67-
}
68-
69-
std::set<int> i_podset;
70-
std::set<StructInternalSerialize> i_iserset;
71-
std::set<StructInternalSplit> i_isplset;
72-
std::set<StructExternalSerialize> i_eserset;
73-
std::set<StructExternalSplit> i_esplset;
74-
75-
std::istringstream is(os.str());
76-
{
77-
IArchive iar(is);
78-
79-
iar(i_podset);
80-
iar(i_iserset);
81-
iar(i_isplset);
82-
iar(i_eserset);
83-
iar(i_esplset);
84-
}
85-
86-
BOOST_CHECK_EQUAL_COLLECTIONS(i_podset.begin(), i_podset.end(), o_podset.begin(), o_podset.end());
87-
BOOST_CHECK_EQUAL_COLLECTIONS(i_iserset.begin(), i_iserset.end(), o_iserset.begin(), o_iserset.end());
88-
BOOST_CHECK_EQUAL_COLLECTIONS(i_isplset.begin(), i_isplset.end(), o_isplset.begin(), o_isplset.end());
89-
BOOST_CHECK_EQUAL_COLLECTIONS(i_eserset.begin(), i_eserset.end(), o_eserset.begin(), o_eserset.end());
90-
BOOST_CHECK_EQUAL_COLLECTIONS(i_esplset.begin(), i_esplset.end(), o_esplset.begin(), o_esplset.end());
91-
}
92-
}
30+
TEST_SUITE("set");
9331

94-
BOOST_AUTO_TEST_CASE( binary_set )
32+
TEST_CASE("binary_set")
9533
{
9634
test_set<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
9735
}
9836

99-
BOOST_AUTO_TEST_CASE( portable_binary_set )
37+
TEST_CASE("portable_binary_set")
10038
{
10139
test_set<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
10240
}
10341

104-
BOOST_AUTO_TEST_CASE( xml_set )
42+
TEST_CASE("xml_set")
10543
{
10644
test_set<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
10745
}
10846

109-
BOOST_AUTO_TEST_CASE( json_set )
47+
TEST_CASE("json_set")
11048
{
11149
test_set<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
11250
}
11351

52+
TEST_SUITE_END();

unittests/set.hpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Copyright (c) 2014, Randolph Voorhies, Shane Grant
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
* Neither the name of cereal nor the
13+
names of its contributors may be used to endorse or promote products
14+
derived from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
20+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
#ifndef CEREAL_TEST_SET_H_
28+
#define CEREAL_TEST_SET_H_
29+
#include "common.hpp"
30+
31+
template <class IArchive, class OArchive> inline
32+
void test_set()
33+
{
34+
std::random_device rd;
35+
std::mt19937 gen(rd());
36+
37+
for(int ii=0; ii<100; ++ii)
38+
{
39+
std::set<int> o_podset;
40+
for(int j=0; j<100; ++j)
41+
o_podset.insert(random_value<int>(gen));
42+
43+
std::set<StructInternalSerialize> o_iserset;
44+
for(int j=0; j<100; ++j)
45+
o_iserset.insert({ random_value<int>(gen), random_value<int>(gen) });
46+
47+
std::set<StructInternalSplit> o_isplset;
48+
for(int j=0; j<100; ++j)
49+
o_isplset.insert({ random_value<int>(gen), random_value<int>(gen) });
50+
51+
std::set<StructExternalSerialize> o_eserset;
52+
for(int j=0; j<100; ++j)
53+
o_eserset.insert({ random_value<int>(gen), random_value<int>(gen) });
54+
55+
std::set<StructExternalSplit> o_esplset;
56+
for(int j=0; j<100; ++j)
57+
o_esplset.insert({ random_value<int>(gen), random_value<int>(gen) });
58+
59+
std::ostringstream os;
60+
{
61+
OArchive oar(os);
62+
63+
oar(o_podset);
64+
oar(o_iserset);
65+
oar(o_isplset);
66+
oar(o_eserset);
67+
oar(o_esplset);
68+
}
69+
70+
std::set<int> i_podset;
71+
std::set<StructInternalSerialize> i_iserset;
72+
std::set<StructInternalSplit> i_isplset;
73+
std::set<StructExternalSerialize> i_eserset;
74+
std::set<StructExternalSplit> i_esplset;
75+
76+
std::istringstream is(os.str());
77+
{
78+
IArchive iar(is);
79+
80+
iar(i_podset);
81+
iar(i_iserset);
82+
iar(i_isplset);
83+
iar(i_eserset);
84+
iar(i_esplset);
85+
}
86+
87+
check_collection(i_podset, o_podset);
88+
check_collection(i_iserset, o_iserset);
89+
check_collection(i_isplset, o_isplset);
90+
check_collection(i_eserset, o_eserset);
91+
check_collection(i_esplset, o_esplset);
92+
}
93+
}
94+
95+
#endif // CEREAL_TEST_SET_H_

unittests/stack.cpp

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,102 +24,29 @@
2424
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
*/
27-
#include "common.hpp"
28-
#include <boost/test/unit_test.hpp>
27+
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
28+
#include "stack.hpp"
2929

30-
template <class IArchive, class OArchive>
31-
void test_stack()
32-
{
33-
std::random_device rd;
34-
std::mt19937 gen(rd());
35-
36-
for(int ii=0; ii<100; ++ii)
37-
{
38-
std::stack<int> o_podstack;
39-
for(int j=0; j<100; ++j)
40-
o_podstack.push(random_value<int>(gen));
41-
42-
std::stack<StructInternalSerialize> o_iserstack;
43-
for(int j=0; j<100; ++j)
44-
o_iserstack.push({ random_value<int>(gen), random_value<int>(gen) });
45-
46-
std::stack<StructInternalSplit> o_isplstack;
47-
for(int j=0; j<100; ++j)
48-
o_isplstack.push({ random_value<int>(gen), random_value<int>(gen) });
49-
50-
std::stack<StructExternalSerialize> o_eserstack;
51-
for(int j=0; j<100; ++j)
52-
o_eserstack.push({ random_value<int>(gen), random_value<int>(gen) });
53-
54-
std::stack<StructExternalSplit> o_esplstack;
55-
for(int j=0; j<100; ++j)
56-
o_esplstack.push({ random_value<int>(gen), random_value<int>(gen) });
57-
58-
std::ostringstream os;
59-
{
60-
OArchive oar(os);
61-
62-
oar(o_podstack);
63-
oar(o_iserstack);
64-
oar(o_isplstack);
65-
oar(o_eserstack);
66-
oar(o_esplstack);
67-
}
68-
69-
std::stack<int> i_podstack;
70-
std::stack<StructInternalSerialize> i_iserstack;
71-
std::stack<StructInternalSplit> i_isplstack;
72-
std::stack<StructExternalSerialize> i_eserstack;
73-
std::stack<StructExternalSplit> i_esplstack;
74-
75-
std::istringstream is(os.str());
76-
{
77-
IArchive iar(is);
78-
79-
iar(i_podstack);
80-
iar(i_iserstack);
81-
iar(i_isplstack);
82-
iar(i_eserstack);
83-
iar(i_esplstack);
84-
}
85-
86-
auto & i_podstack_c = cereal::stack_detail::container(i_podstack);
87-
auto & i_iserstack_c = cereal::stack_detail::container(i_iserstack);
88-
auto & i_isplstack_c = cereal::stack_detail::container(i_isplstack);
89-
auto & i_eserstack_c = cereal::stack_detail::container(i_eserstack);
90-
auto & i_esplstack_c = cereal::stack_detail::container(i_esplstack);
91-
92-
auto & o_podstack_c = cereal::stack_detail::container(o_podstack);
93-
auto & o_iserstack_c = cereal::stack_detail::container(o_iserstack);
94-
auto & o_isplstack_c = cereal::stack_detail::container(o_isplstack);
95-
auto & o_eserstack_c = cereal::stack_detail::container(o_eserstack);
96-
auto & o_esplstack_c = cereal::stack_detail::container(o_esplstack);
97-
98-
BOOST_CHECK_EQUAL_COLLECTIONS(i_podstack_c.begin(), i_podstack_c.end(), o_podstack_c.begin(), o_podstack_c.end());
99-
BOOST_CHECK_EQUAL_COLLECTIONS(i_iserstack_c.begin(), i_iserstack_c.end(), o_iserstack_c.begin(), o_iserstack_c.end());
100-
BOOST_CHECK_EQUAL_COLLECTIONS(i_isplstack_c.begin(), i_isplstack_c.end(), o_isplstack_c.begin(), o_isplstack_c.end());
101-
BOOST_CHECK_EQUAL_COLLECTIONS(i_eserstack_c.begin(), i_eserstack_c.end(), o_eserstack_c.begin(), o_eserstack_c.end());
102-
BOOST_CHECK_EQUAL_COLLECTIONS(i_esplstack_c.begin(), i_esplstack_c.end(), o_esplstack_c.begin(), o_esplstack_c.end());
103-
}
104-
}
30+
TEST_SUITE("stack");
10531

106-
BOOST_AUTO_TEST_CASE( binary_stack )
32+
TEST_CASE("binary_stack")
10733
{
10834
test_stack<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
10935
}
11036

111-
BOOST_AUTO_TEST_CASE( portable_binary_stack )
37+
TEST_CASE("portable_binary_stack")
11238
{
11339
test_stack<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
11440
}
11541

116-
BOOST_AUTO_TEST_CASE( xml_stack )
42+
TEST_CASE("xml_stack")
11743
{
11844
test_stack<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
11945
}
12046

121-
BOOST_AUTO_TEST_CASE( json_stack )
47+
TEST_CASE("json_stack")
12248
{
12349
test_stack<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
12450
}
12551

52+
TEST_SUITE_END();

0 commit comments

Comments
 (0)