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/utility/TimeValue.h>
17 : :
18 : : #include <utility>
19 : :
20 : : #define BOOST_TEST_MODULE TimeValueTest
21 : : #include <boost/test/unit_test.hpp>
22 : :
23 : : using namespace NS_SSRC_WISP_UTILITY;
24 : :
25 [ + - + - : 3 : BOOST_AUTO_TEST_CASE(test_constructor) {
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
26 [ + - ]: 1 : const TimeValue t1, t2(4,5), t3(3617);
27 : :
28 [ + - + - : 1 : BOOST_CHECK_EQUAL(t1.seconds(), 0);
+ - + - +
- - + ]
29 [ + - + - : 1 : BOOST_CHECK_EQUAL(t1.nanoseconds(), 0);
+ - + - +
- - + ]
30 [ + - + - : 1 : BOOST_CHECK_EQUAL(t2.seconds(), 4);
+ - + - +
- - + ]
31 [ + - + - : 1 : BOOST_CHECK_EQUAL(t2.nanoseconds(), 5);
+ - + - +
- - + ]
32 [ + - + - : 1 : BOOST_CHECK_EQUAL(t3.seconds(), 3);
+ - + - +
- - + ]
33 [ + - + - : 1 : BOOST_CHECK_EQUAL(t3.nanoseconds(), 617000000L);
+ - + - +
- - + ]
34 : 1 : }
35 : :
36 [ + - + - : 3 : BOOST_AUTO_TEST_CASE(test_to_milliseconds) {
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
37 [ + - ]: 1 : const TimeValue t(10, 40249000);
38 [ + - + - : 1 : BOOST_CHECK_EQUAL(t.to_milliseconds(), 10041);
+ - + - +
- - + ]
39 : 1 : }
40 : :
41 [ + - + - : 3 : BOOST_AUTO_TEST_CASE(test_equality) {
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
42 : 1 : TimeValue t1, t2;
43 : :
44 [ + - + - : 1 : BOOST_CHECK(t1 == t2);
+ - + - +
- + - -
+ ]
45 : 1 : }
46 : :
47 [ + - + - : 3 : BOOST_AUTO_TEST_CASE(test_subtraction) {
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
48 [ + - + - ]: 1 : TimeValue t1(5, 1), t2(2, 3);
49 : 1 : TimeValue t3 = t1 - t2;
50 : :
51 [ + - + - : 1 : BOOST_CHECK_EQUAL(t3.seconds(), 2);
+ - + - +
- - + ]
52 [ + - + - : 1 : BOOST_CHECK_EQUAL(t3.nanoseconds(), 999999998);
+ - + - +
- - + ]
53 : 1 : }
54 : :
55 [ + - + - : 3 : BOOST_AUTO_TEST_CASE(test_addition) {
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
56 [ + - + - ]: 1 : TimeValue t1(5, 4), t2(2, 999999999);
57 : 1 : TimeValue t3 = t1 + t2;
58 : :
59 [ + - + - : 1 : BOOST_CHECK_EQUAL(t3.seconds(), 8);
+ - + - +
- - + ]
60 [ + - + - : 1 : BOOST_CHECK_EQUAL(t3.nanoseconds(), 3);
+ - + - +
- - + ]
61 : 1 : }
62 : :
63 [ + - + - : 3 : BOOST_AUTO_TEST_CASE(test_comparison) {
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - ]
64 : : using namespace std::rel_ops;
65 [ + - + - ]: 1 : TimeValue t1(8, 2), t2(2, 8);
66 : :
67 [ + - + - : 1 : BOOST_CHECK(t2 < t1);
+ - + - +
- + - -
+ ]
68 [ + - + - : 1 : BOOST_CHECK(t2 <= t1);
+ - + - +
- + - -
+ ]
69 [ + - + - : 1 : BOOST_CHECK(t1 > t2);
+ - + - +
- + - -
+ ]
70 [ + - + - : 1 : BOOST_CHECK(t1 >= t2);
+ - + - +
- + - -
+ ]
71 [ + - + - : 1 : BOOST_CHECK(t1 != t2);
+ - + - +
- + - -
+ ]
72 [ + - + - : 1 : BOOST_CHECK(t1 < InfiniteTimeValue);
+ - + - +
- + - -
+ ]
73 [ + - + - : 1 : BOOST_CHECK(InfiniteTimeValue > t1);
+ - + - +
- + - -
+ ]
74 [ + - + - ]: 4 : }
|