2 Copyright (c) 2014, Randolph Voorhies, Shane Grant
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.
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.
28 #include <boost/test/unit_test.hpp>
30 template <class IArchive, class OArchive>
31 void test_unordered_multimap()
33 std::random_device rd;
34 std::mt19937 gen(rd());
36 for(int ii=0; ii<100; ++ii)
38 std::unordered_multimap<std::string, int> o_podunordered_multimap;
39 for(int j=0; j<100; ++j)
41 auto key = random_value<std::string>(gen);
42 o_podunordered_multimap.insert({key, random_value<int>(gen)});
43 o_podunordered_multimap.insert({key, random_value<int>(gen)});
46 std::unordered_multimap<int, StructInternalSerialize> o_iserunordered_multimap;
47 for(int j=0; j<100; ++j)
49 auto key = random_value<int>(gen);
50 o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
51 o_iserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
54 std::unordered_multimap<int, StructInternalSplit> o_isplunordered_multimap;
55 for(int j=0; j<100; ++j)
57 auto key = random_value<int>(gen);
58 o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
59 o_isplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
62 std::unordered_multimap<uint32_t, StructExternalSerialize> o_eserunordered_multimap;
63 for(int j=0; j<100; ++j)
65 auto key = random_value<uint32_t>(gen);
66 o_eserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
67 o_eserunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
70 std::unordered_multimap<int8_t, StructExternalSplit> o_esplunordered_multimap;
71 for(int j=0; j<100; ++j)
73 auto key = random_value<char>(gen);
74 o_esplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
75 o_esplunordered_multimap.insert({key, { random_value<int>(gen), random_value<int>(gen) }});
78 std::ostringstream os;
82 oar(o_podunordered_multimap);
83 oar(o_iserunordered_multimap);
84 oar(o_isplunordered_multimap);
85 oar(o_eserunordered_multimap);
86 oar(o_esplunordered_multimap);
89 std::unordered_multimap<std::string, int> i_podunordered_multimap;
90 std::unordered_multimap<int, StructInternalSerialize> i_iserunordered_multimap;
91 std::unordered_multimap<int, StructInternalSplit> i_isplunordered_multimap;
92 std::unordered_multimap<uint32_t, StructExternalSerialize> i_eserunordered_multimap;
93 std::unordered_multimap<int8_t, StructExternalSplit> i_esplunordered_multimap;
95 std::istringstream is(os.str());
99 iar(i_podunordered_multimap);
100 iar(i_iserunordered_multimap);
101 iar(i_isplunordered_multimap);
102 iar(i_eserunordered_multimap);
103 iar(i_esplunordered_multimap);
106 BOOST_CHECK_EQUAL(i_podunordered_multimap.size(), o_podunordered_multimap.size());
107 BOOST_CHECK_EQUAL(i_iserunordered_multimap.size(), o_iserunordered_multimap.size());
108 BOOST_CHECK_EQUAL(i_isplunordered_multimap.size(), o_isplunordered_multimap.size());
109 BOOST_CHECK_EQUAL(i_eserunordered_multimap.size(), o_eserunordered_multimap.size());
110 BOOST_CHECK_EQUAL(i_esplunordered_multimap.size(), o_esplunordered_multimap.size());
112 for(auto const & p : i_podunordered_multimap)
114 size_t const bucket = o_podunordered_multimap.bucket(p.first);
115 auto bucket_begin = o_podunordered_multimap.begin(bucket);
116 auto bucket_end = o_podunordered_multimap.end(bucket);
117 BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
120 for(auto const & p : i_iserunordered_multimap)
122 size_t const bucket = o_iserunordered_multimap.bucket(p.first);
123 auto bucket_begin = o_iserunordered_multimap.begin(bucket);
124 auto bucket_end = o_iserunordered_multimap.end(bucket);
125 BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
128 for(auto const & p : i_isplunordered_multimap)
130 size_t const bucket = o_isplunordered_multimap.bucket(p.first);
131 auto bucket_begin = o_isplunordered_multimap.begin(bucket);
132 auto bucket_end = o_isplunordered_multimap.end(bucket);
133 BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
136 for(auto const & p : i_eserunordered_multimap)
138 size_t const bucket = o_eserunordered_multimap.bucket(p.first);
139 auto bucket_begin = o_eserunordered_multimap.begin(bucket);
140 auto bucket_end = o_eserunordered_multimap.end(bucket);
141 BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
144 for(auto const & p : i_esplunordered_multimap)
146 size_t const bucket = o_esplunordered_multimap.bucket(p.first);
147 auto bucket_begin = o_esplunordered_multimap.begin(bucket);
148 auto bucket_end = o_esplunordered_multimap.end(bucket);
149 BOOST_CHECK(std::find(bucket_begin, bucket_end, p) != bucket_end);
154 BOOST_AUTO_TEST_CASE( binary_unordered_multimap )
156 test_unordered_multimap<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
159 BOOST_AUTO_TEST_CASE( portable_binary_unordered_multimap )
161 test_unordered_multimap<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
164 BOOST_AUTO_TEST_CASE( xml_unordered_multimap )
166 test_unordered_multimap<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
169 BOOST_AUTO_TEST_CASE( json_unordered_multimap )
171 test_unordered_multimap<cereal::JSONInputArchive, cereal::JSONOutputArchive>();