|
| 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_PRIORITY_QUEUE_H_ |
| 28 | +#define CEREAL_TEST_PRIORITY_QUEUE_H_ |
| 29 | +#include "common.hpp" |
| 30 | + |
| 31 | +template <class IArchive, class OArchive> inline |
| 32 | +void test_priority_queue() |
| 33 | +{ |
| 34 | + std::random_device rd; |
| 35 | + std::mt19937 gen(rd()); |
| 36 | + |
| 37 | + for(int ii=0; ii<100; ++ii) |
| 38 | + { |
| 39 | + std::priority_queue<int> o_podpriority_queue; |
| 40 | + for(int j=0; j<100; ++j) |
| 41 | + o_podpriority_queue.push(random_value<int>(gen)); |
| 42 | + |
| 43 | + std::priority_queue<StructInternalSerialize> o_iserpriority_queue; |
| 44 | + for(int j=0; j<100; ++j) |
| 45 | + o_iserpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) }); |
| 46 | + |
| 47 | + std::priority_queue<StructInternalSplit> o_isplpriority_queue; |
| 48 | + for(int j=0; j<100; ++j) |
| 49 | + o_isplpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) }); |
| 50 | + |
| 51 | + std::priority_queue<StructExternalSerialize> o_eserpriority_queue; |
| 52 | + for(int j=0; j<100; ++j) |
| 53 | + o_eserpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) }); |
| 54 | + |
| 55 | + std::priority_queue<StructExternalSplit> o_esplpriority_queue; |
| 56 | + for(int j=0; j<100; ++j) |
| 57 | + o_esplpriority_queue.push({ random_value<int>(gen), random_value<int>(gen) }); |
| 58 | + |
| 59 | + std::ostringstream os; |
| 60 | + { |
| 61 | + OArchive oar(os); |
| 62 | + |
| 63 | + oar(o_podpriority_queue); |
| 64 | + oar(o_iserpriority_queue); |
| 65 | + oar(o_isplpriority_queue); |
| 66 | + oar(o_eserpriority_queue); |
| 67 | + oar(o_esplpriority_queue); |
| 68 | + } |
| 69 | + |
| 70 | + std::priority_queue<int> i_podpriority_queue; |
| 71 | + std::priority_queue<StructInternalSerialize> i_iserpriority_queue; |
| 72 | + std::priority_queue<StructInternalSplit> i_isplpriority_queue; |
| 73 | + std::priority_queue<StructExternalSerialize> i_eserpriority_queue; |
| 74 | + std::priority_queue<StructExternalSplit> i_esplpriority_queue; |
| 75 | + |
| 76 | + std::istringstream is(os.str()); |
| 77 | + { |
| 78 | + IArchive iar(is); |
| 79 | + |
| 80 | + iar(i_podpriority_queue); |
| 81 | + iar(i_iserpriority_queue); |
| 82 | + iar(i_isplpriority_queue); |
| 83 | + iar(i_eserpriority_queue); |
| 84 | + iar(i_esplpriority_queue); |
| 85 | + } |
| 86 | + |
| 87 | + auto & i_podpriority_queue_c = cereal::queue_detail::container(i_podpriority_queue); |
| 88 | + auto & i_iserpriority_queue_c = cereal::queue_detail::container(i_iserpriority_queue); |
| 89 | + auto & i_isplpriority_queue_c = cereal::queue_detail::container(i_isplpriority_queue); |
| 90 | + auto & i_eserpriority_queue_c = cereal::queue_detail::container(i_eserpriority_queue); |
| 91 | + auto & i_esplpriority_queue_c = cereal::queue_detail::container(i_esplpriority_queue); |
| 92 | + |
| 93 | + auto & o_podpriority_queue_c = cereal::queue_detail::container(o_podpriority_queue); |
| 94 | + auto & o_iserpriority_queue_c = cereal::queue_detail::container(o_iserpriority_queue); |
| 95 | + auto & o_isplpriority_queue_c = cereal::queue_detail::container(o_isplpriority_queue); |
| 96 | + auto & o_eserpriority_queue_c = cereal::queue_detail::container(o_eserpriority_queue); |
| 97 | + auto & o_esplpriority_queue_c = cereal::queue_detail::container(o_esplpriority_queue); |
| 98 | + |
| 99 | + check_collection(i_podpriority_queue_c, o_podpriority_queue_c); |
| 100 | + check_collection(i_iserpriority_queue_c, o_iserpriority_queue_c); |
| 101 | + check_collection(i_isplpriority_queue_c, o_isplpriority_queue_c); |
| 102 | + check_collection(i_eserpriority_queue_c, o_eserpriority_queue_c); |
| 103 | + check_collection(i_esplpriority_queue_c, o_esplpriority_queue_c); |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +#endif // CEREAL_TEST_PRIORITY_QUEUE_H_ |
0 commit comments