| Web Wispers 1.2.0 C++ Unit Test Coverage |
|
|
|
|
|
Branch data Line data Source code
1 : : /*
2 : : * Copyright 2009 Savarese Software Research Corporation
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * http://www.savarese.com/software/ApacheLicense-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : #include <tests/TestCommon.h>
18 : : #include <ssrc/wispers/utility/serialize_unique_ptr.h>
19 : :
20 : : using namespace NS_SSRC_WSPR_UTILITY;
21 : :
22 : : struct Int {
23 : : int i;
24 : :
25 : : template<class Archive>
26 : 2 : void serialize(Archive & ar, const unsigned int) {
27 : 2 : ar & i;
28 : 2 : }
29 : : };
30 : :
31 : 1 : inline bool operator==(const Int & i1, const Int & i2) {
32 : 1 : return (i1.i == i2.i);
33 : : }
34 : :
35 [ - + ]: 3 : struct UniquePtrTest : public TestCase {
36 : :
37 : 1 : void 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 : CPPUNIT_ASSERT_NO_THROW(packer.pack(out, buffer));
- + - + -
+ - + - +
- # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # # ]
51 : :
52 [ + - + - + : 1 : CPPUNIT_ASSERT_EQUAL(expected, out->i);
- + - + -
+ - + - +
- ]
53 : :
54 [ + - ]: 1 : buffer.rewind();
55 : :
56 [ + - + - + : 1 : CPPUNIT_ASSERT_NO_THROW(unpacker.unpack(in, buffer));
- + - + -
+ - + - +
- # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # # ]
57 : :
58 [ + - + - + : 1 : CPPUNIT_ASSERT_EQUAL(expected, in->i);
- + - + -
+ - + - +
- ]
59 [ + - + - + : 1 : CPPUNIT_ASSERT(*out == *in);
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
60 : :
61 : : #ifdef WISPERS_HAVE_UNIQUE_PTR
62 [ + - + - + : 1 : CPPUNIT_ASSERT(out != in);
- + - + -
+ - + - +
- + - + -
+ - + - ]
63 : : #endif
64 : :
65 [ + - ]: 1 : out.reset();
66 [ + - ]: 1 : in.reset();
67 : :
68 [ + - ]: 1 : buffer.clear();
69 : :
70 [ + - + - + : 1 : CPPUNIT_ASSERT_NO_THROW(packer.pack(out, buffer));
- + - + -
+ - + - +
- # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # # ]
71 : :
72 [ + - ]: 1 : buffer.rewind();
73 : :
74 [ + - + - + : 1 : CPPUNIT_ASSERT_NO_THROW(unpacker.unpack(in, buffer));
- + - + -
+ - + - +
- # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # # ]
75 : :
76 : : #ifdef WISPERS_HAVE_UNIQUE_PTR
77 [ + - + - + : 1 : CPPUNIT_ASSERT(!out);
- + - + -
+ - + - +
- + - + -
+ - + - ]
78 [ + - + - + : 1 : CPPUNIT_ASSERT(!in);
- + - + -
+ - + - +
- + - + -
+ - + - ]
79 [ + - + - + : 1 : CPPUNIT_ASSERT(out == in);
- + - + -
+ - + - +
- + - + -
+ - + - ]
80 : : #endif
81 : 1 : }
82 : :
83 [ + - + - + : 4 : CPPUNIT_TEST_SUITE(UniquePtrTest);
- # # ]
84 [ + - + - + : 1 : CPPUNIT_TEST(test_serialize);
- + - + -
+ - + - +
- ]
85 [ + - + - + : 2 : CPPUNIT_TEST_SUITE_END();
- + - + -
+ - ]
86 : : };
87 : :
88 : 1 : CPPUNIT_TEST_SUITE_REGISTRATION(UniquePtrTest);
89 [ + - + - + : 6 : WISP_TEST_MAIN()
- + - + -
+ - + - +
- + - + -
+ - + - +
- ]
|
Copyright © 2010 Savarese Software Research Corporation. All rights reserved