| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2020, Joseph Mirabel | ||
| 2 | // Authors: Joseph Mirabel (joseph.mirabel@laas.fr) | ||
| 3 | // | ||
| 4 | |||
| 5 | // Redistribution and use in source and binary forms, with or without | ||
| 6 | // modification, are permitted provided that the following conditions are | ||
| 7 | // met: | ||
| 8 | // | ||
| 9 | // 1. Redistributions of source code must retain the above copyright | ||
| 10 | // notice, this list of conditions and the following disclaimer. | ||
| 11 | // | ||
| 12 | // 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | // notice, this list of conditions and the following disclaimer in the | ||
| 14 | // documentation and/or other materials provided with the distribution. | ||
| 15 | // | ||
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 20 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
| 27 | // DAMAGE. | ||
| 28 | |||
| 29 | #include "serialization.hh" | ||
| 30 | |||
| 31 | #include <hpp/util/serialization.hh> | ||
| 32 | #include <sstream> | ||
| 33 | |||
| 34 | #include "common.hh" | ||
| 35 | #include "config.h" | ||
| 36 | |||
| 37 | template <typename T> | ||
| 38 | 6 | int run_test_tpl() { | |
| 39 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | std::stringstream ss; |
| 40 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | T* t(new T(10)); |
| 41 | { | ||
| 42 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | hpp::serialization::xml_oarchive oa(ss); |
| 43 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
6 | oa << boost::serialization::make_nvp("t", t); |
| 44 | 6 | } | |
| 45 |
3/6✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
6 | std::cout << ss.str() << std::endl; |
| 46 | 6 | T* t_r = NULL; | |
| 47 | { | ||
| 48 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | hpp::serialization::xml_iarchive ia(ss); |
| 49 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
6 | ia >> boost::serialization::make_nvp("t", t_r); |
| 50 | 6 | } | |
| 51 | |||
| 52 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
6 | if (t_r == NULL || t_r->i_ != t->i_) { |
| 53 | std::cerr << "Failed to deserialize " << hpp::serialization::guid<T>() | ||
| 54 | ✗ | << " class" << std::endl; | |
| 55 | ✗ | return TEST_FAILED; | |
| 56 | } | ||
| 57 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
6 | delete t; |
| 58 | 6 | return TEST_SUCCEED; | |
| 59 | 6 | } | |
| 60 | |||
| 61 | 2 | int run_test_bar(bool check_throw) { | |
| 62 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | std::unique_ptr<Foo> foo(new Foo(1)); |
| 63 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | std::stringstream ss; |
| 64 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | Bar* t(new Bar(10)); |
| 65 | { | ||
| 66 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | hpp::serialization::xml_oarchive oa(ss); |
| 67 |
2/4✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
4 | oa.insert("foo", foo.get()); |
| 68 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | oa.initialize(); |
| 69 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | oa << boost::serialization::make_nvp("t", t); |
| 70 | 2 | } | |
| 71 |
3/6✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
2 | std::cout << ss.str() << std::endl; |
| 72 | 2 | Bar* t_r = NULL; | |
| 73 | bool caught_error; | ||
| 74 | { | ||
| 75 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | hpp::serialization::xml_iarchive ia(ss); |
| 76 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (!check_throw) |
| 77 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
3 | ia.insert("foo", foo.get()); |
| 78 | else | ||
| 79 |
3/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
3 | ia.insert("foo", new Bar(0)); |
| 80 | try { | ||
| 81 | 2 | caught_error = true; | |
| 82 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
|
2 | ia.initialize(); |
| 83 | 1 | caught_error = false; | |
| 84 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | ia >> boost::serialization::make_nvp("t", t_r); |
| 85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } catch (const std::invalid_argument& e) { |
| 86 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | std::cerr << e.what() << std::endl; |
| 87 | 1 | } | |
| 88 | 2 | } | |
| 89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (check_throw != caught_error) return TEST_FAILED; |
| 90 | |||
| 91 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
2 | if (check_throw && t_r != NULL) { |
| 92 | ✗ | std::cerr << "Deserialize Bar class while it shouldn't" << std::endl; | |
| 93 | ✗ | return TEST_FAILED; | |
| 94 | } | ||
| 95 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (!check_throw) { |
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (t_r->f_ != foo.get()) { |
| 97 | ✗ | std::cerr << "Failed to deserialize Bar::f_ Foo pointer" << std::endl; | |
| 98 | ✗ | return TEST_FAILED; | |
| 99 | } | ||
| 100 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (t_r == NULL || t_r->i_ != t->i_) { |
| 101 | ✗ | std::cerr << "Failed to deserialize Bar class" << std::endl; | |
| 102 | ✗ | return TEST_FAILED; | |
| 103 | } | ||
| 104 | } | ||
| 105 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | delete t; |
| 106 | 2 | return TEST_SUCCEED; | |
| 107 | 2 | } | |
| 108 | |||
| 109 | struct S1 { | ||
| 110 | 2 | virtual ~S1() = default; | |
| 111 | }; | ||
| 112 | struct S2 : S1 {}; | ||
| 113 | |||
| 114 | 1 | BOOST_CLASS_EXPORT_KEY(S1) | |
| 115 | 1 | BOOST_CLASS_EXPORT_KEY(S2) | |
| 116 | |||
| 117 | 1 | int run_test_holder_inheritance() { | |
| 118 | using namespace hpp::serialization; | ||
| 119 | 1 | archive_ptr_holder aph; | |
| 120 | 1 | S2 s2; | |
| 121 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | aph.insert<S1>("s1", &s2); |
| 122 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | aph.insertChildClass<S1>("s2", &s2); |
| 123 | |||
| 124 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | aph.template get<S1>("s1", true); |
| 125 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | aph.getChildClass<S1, S2>("s2", true); |
| 126 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | S1* s1 = aph.template get<S1>("s2", false); |
| 127 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (s1 == NULL) { |
| 128 | ✗ | std::cerr << "Failed to cast S2 into S1" << std::endl; | |
| 129 | ✗ | return TEST_FAILED; | |
| 130 | } | ||
| 131 | 1 | return TEST_SUCCEED; | |
| 132 | 1 | } | |
| 133 | |||
| 134 | ✗ | int run_test_archive_parents() { | |
| 135 | using namespace hpp::serialization; | ||
| 136 | struct P1 {}; | ||
| 137 | struct P2 {}; | ||
| 138 | typedef archive_tpl<boost::archive::xml_iarchive, P1, P2> type; | ||
| 139 | ✗ | std::stringstream ss; | |
| 140 | ✗ | type t(ss); | |
| 141 | (void)t; | ||
| 142 | ✗ | return TEST_SUCCEED; | |
| 143 | ✗ | } | |
| 144 | |||
| 145 | 1 | int run_test() { | |
| 146 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (run_test_tpl<Foo>() == TEST_FAILED) return TEST_FAILED; |
| 147 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (run_test_bar(true) == TEST_FAILED) return TEST_FAILED; |
| 148 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (run_test_bar(false) == TEST_FAILED) return TEST_FAILED; |
| 149 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (run_test_tpl<FooFree>() == TEST_FAILED) return TEST_FAILED; |
| 150 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (run_test_tpl<BarFree>() == TEST_FAILED) return TEST_FAILED; |
| 151 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (run_test_holder_inheritance() == TEST_FAILED) return TEST_FAILED; |
| 152 | 1 | return TEST_SUCCEED; | |
| 153 | } | ||
| 154 | |||
| 155 |
5/30✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
|
1 | GENERATE_TEST() |
| 156 |