Branch data Line data Source code
1 : : /* Copyright 2006-2011 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 : : * http://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/wisp/serialization.h>
17 : : #include <ssrc/spread/Message.h>
18 : :
19 : : #define BOOST_TEST_MODULE SerializationTest
20 : : #include <boost/test/unit_test.hpp>
21 : :
22 : : using namespace NS_SSRC_WISP;
23 : :
24 [ + - ]: 2 : struct PackUnpack {
25 : : BinaryPacker packer;
26 : : BinaryUnpacker unpacker;
27 : : };
28 : :
29 [ + - + - : 5 : BOOST_FIXTURE_TEST_CASE(test_pack_unpack, PackUnpack) {
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - ]
30 : 1 : unsigned int num(5), bytes, size;
31 [ + - ]: 2 : std::string str("hello");
32 [ + - ]: 2 : ssrc::spread::Message message;
33 : :
34 [ + - ]: 1 : bytes = packer.pack(num, message);
35 : :
36 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.size(), bytes);
+ - + - +
- + - -
+ ]
37 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.offset(), bytes);
+ - + - +
- - + ]
38 : :
39 [ + - ]: 1 : bytes += packer.pack(str, message);
40 : :
41 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.size(), bytes);
+ - + - +
- + - -
+ ]
42 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.offset(), bytes);
+ - + - +
- - + ]
43 : :
44 : 1 : num = 0;
45 [ + - ]: 1 : str = "foobar";
46 : :
47 [ + - ]: 1 : size = message.size();
48 [ + - ]: 1 : message.rewind();
49 : :
50 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.size(), size);
+ - + - +
- + - -
+ ]
51 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.offset(), 0u);
+ - + - +
- - + ]
52 : :
53 [ + - ]: 1 : bytes = unpacker.unpack(num, message);
54 : :
55 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.size(), size);
+ - + - +
- + - -
+ ]
56 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.offset(), bytes);
+ - + - +
- - + ]
57 : :
58 [ + - ]: 1 : bytes += unpacker.unpack(str, message);
59 : :
60 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.size(), size);
+ - + - +
- + - -
+ ]
61 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(message.offset(), bytes);
+ - + - +
- - + ]
62 : :
63 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(num, 5u);
+ - + - +
- - + ]
64 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(str, "hello");
+ - + - +
- - + ]
65 : :
66 : 1 : num = 0;
67 [ + - ]: 1 : str = "foobar";
68 : :
69 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(num, 0u);
+ - + - +
- - + ]
70 [ + - + - : 1 : BOOST_REQUIRE(str == "foobar");
+ - + - +
- + - + -
- + ]
71 : :
72 [ + - + - ]: 1 : bytes = unpacker.unpack(num, &message[0], message.size());
73 : :
74 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(num, 5u);
+ - + - +
- - + ]
75 : :
76 [ + - + - ]: 1 : unpacker.unpack(str, &message[bytes], message.size() - bytes);
77 : :
78 [ + - + - : 1 : BOOST_REQUIRE_EQUAL(str, "hello");
+ - + - +
- - + ]
79 [ + - + - ]: 4 : }
|