Web Wispers 1.2.2 C++ Unit Test Coverage |
|
|
|
|
Branch data Line data Source code
1 : : /* Copyright 2009 Savarese Software Research Corporation
2 : : *
3 : : * Licensed under the Apache License, Version 2.0 (the "License");
4 : : * you may not use this file except in compliance with the License.
5 : : * You may obtain a copy of the License at
6 : : *
7 : : * https://www.savarese.com/software/ApacheLicense-2.0
8 : : *
9 : : * Unless required by applicable law or agreed to in writing, software
10 : : * distributed under the License is distributed on an "AS IS" BASIS,
11 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : : * See the License for the specific language governing permissions and
13 : : * limitations under the License.
14 : : */
15 : :
16 : : #include <ssrc/wispers/utility/serialize_unique_ptr.h>
17 : : #include <ssrc/wisp/serialization.h>
18 : :
19 : : #define BOOST_TEST_MODULE UniquePtrTest
20 : : #include <boost/test/unit_test.hpp>
21 : :
22 : : using namespace NS_SSRC_WSPR_UTILITY;
23 : :
24 : : struct Int {
25 : : int i;
26 : :
27 : : template<class Archive>
28 : 2 : void serialize(Archive & ar, const unsigned int) {
29 : 2 : ar & i;
30 : 2 : }
31 : : };
32 : :
33 : 1 : inline bool operator==(const Int & i1, const Int & i2) {
34 : 1 : return (i1.i == i2.i);
35 : : }
36 : :
37 [ + - + - ]: 3 : BOOST_AUTO_TEST_CASE(test_serialize) {
38 : : using ssrc::wisp::Packer;
39 : : using ssrc::wisp::Unpacker;
40 : : using ssrc::spread::detail::ByteBuffer;
41 : :
42 : 2 : ByteBuffer buffer(4096);;
43 [ + - + - ]: 2 : Packer<boost::archive::binary_oarchive> packer;
44 [ + - + - ]: 2 : Unpacker<boost::archive::binary_iarchive> unpacker;
45 [ + - + - : 2 : SSRC_UNIQUE_PTR<Int> out(new Int), in;
+ - + - ]
46 : 1 : const int expected = 1776;
47 : :
48 [ + - ]: 1 : out->i = expected;
49 : :
50 [ + - + - : 1 : BOOST_REQUIRE_NO_THROW(packer.pack(out, buffer));
+ - + - +
- + - + -
+ - - + #
# # # # #
# # # # #
# # # # #
# # ]
51 : :
52 [ + - + - : 1 : BOOST_CHECK_EQUAL(out->i, expected);
+ - + - +
- + - -
+ ]
53 : :
54 [ + - ]: 1 : buffer.rewind();
55 : :
56 [ + - + - : 1 : BOOST_REQUIRE_NO_THROW(unpacker.unpack(in, buffer));
+ - + - +
- + - + -
+ - - + #
# # # # #
# # # # #
# # # # #
# # ]
57 : :
58 [ + - + - : 1 : BOOST_CHECK_EQUAL(in->i, expected);
+ - + - +
- + - -
+ ]
59 [ + - + - : 1 : BOOST_CHECK(*out == *in);
+ - + - +
- + - + -
+ - + - +
- - + ]
60 : :
61 : : #ifdef WISPERS_HAVE_UNIQUE_PTR
62 [ + - + - : 1 : BOOST_CHECK(out != in);
+ - + - +
- + - + -
+ - - + ]
63 : : #endif
64 : :
65 [ + - ]: 1 : out.reset();
66 [ + - ]: 1 : in.reset();
67 : :
68 [ + - ]: 1 : buffer.clear();
69 : :
70 [ + - + - : 1 : BOOST_REQUIRE_NO_THROW(packer.pack(out, buffer));
+ - + - +
- + - + -
+ - - + #
# # # # #
# # # # #
# # # # #
# # ]
71 : :
72 [ + - ]: 1 : buffer.rewind();
73 : :
74 [ + - + - : 1 : BOOST_REQUIRE_NO_THROW(unpacker.unpack(in, buffer));
+ - + - +
- + - + -
+ - - + #
# # # # #
# # # # #
# # # # #
# # ]
75 : :
76 : : #ifdef WISPERS_HAVE_UNIQUE_PTR
77 [ + - + - : 1 : BOOST_CHECK(!out);
+ - + - +
- + - + -
+ - - + ]
78 [ + - + - : 1 : BOOST_CHECK(!in);
+ - + - +
- + - + -
+ - - + ]
79 [ + - + - : 1 : BOOST_CHECK(out == in);
+ - + - +
- + - + -
+ - - + ]
80 : : #endif
81 [ + - + - : 6 : }
+ - + - ]
|
Copyright © 2017 Savarese Software Research Corporation. All rights reserved