OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/modules/audio_coding/neteq/tick_timer.h" | |
12 | |
13 #include "testing/gmock/include/gmock/gmock.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace webrtc { | |
17 | |
18 TEST(TickTimer, Increment) { | |
19 TickTimer tt; | |
20 EXPECT_EQ(0u, tt.ticks()); | |
21 tt.Increment(); | |
22 EXPECT_EQ(1u, tt.ticks()); | |
23 | |
24 for (int i = 0; i < 17; ++i) { | |
25 tt.Increment(); | |
26 } | |
27 EXPECT_EQ(18u, tt.ticks()); | |
28 | |
29 tt.Increment(17); | |
30 EXPECT_EQ(35u, tt.ticks()); | |
31 } | |
32 | |
33 TEST(TickTimer, WrapAround) { | |
34 TickTimer tt; | |
35 tt.Increment(UINT64_MAX); | |
36 EXPECT_EQ(UINT64_MAX, tt.ticks()); | |
37 tt.Increment(); | |
38 EXPECT_EQ(0u, tt.ticks()); | |
39 } | |
40 | |
41 TEST(TickTimer, Stopwatch) { | |
42 TickTimer tt; | |
43 // Increment it a "random" number of steps. | |
44 tt.Increment(17); | |
45 | |
46 std::unique_ptr<TickTimer::Stopwatch> sw = tt.GetNewStopwatch(); | |
47 ASSERT_TRUE(sw); | |
48 | |
49 EXPECT_EQ(0u, sw->ElapsedTicks()); // Starts at zero. | |
50 EXPECT_EQ(0u, sw->ElapsedMs()); | |
51 tt.Increment(); | |
52 EXPECT_EQ(1u, sw->ElapsedTicks()); // Increases with the TickTimer. | |
53 EXPECT_EQ(10u, sw->ElapsedMs()); | |
54 } | |
55 | |
56 TEST(TickTimer, StopwatchWrapAround) { | |
57 TickTimer tt; | |
58 tt.Increment(UINT64_MAX); | |
59 | |
60 std::unique_ptr<TickTimer::Stopwatch> sw = tt.GetNewStopwatch(); | |
61 ASSERT_TRUE(sw); | |
62 | |
63 tt.Increment(); | |
64 EXPECT_EQ(0u, tt.ticks()); | |
65 EXPECT_EQ(1u, sw->ElapsedTicks()); | |
66 EXPECT_EQ(10u, sw->ElapsedMs()); | |
67 | |
68 tt.Increment(); | |
69 EXPECT_EQ(1u, tt.ticks()); | |
70 EXPECT_EQ(2u, sw->ElapsedTicks()); | |
71 EXPECT_EQ(20u, sw->ElapsedMs()); | |
72 } | |
73 | |
74 TEST(TickTimer, StopwatchMsOverflow) { | |
75 TickTimer tt; | |
76 std::unique_ptr<TickTimer::Stopwatch> sw = tt.GetNewStopwatch(); | |
77 ASSERT_TRUE(sw); | |
78 | |
79 tt.Increment(UINT64_MAX / 10); | |
80 EXPECT_EQ(UINT64_MAX, sw->ElapsedMs()); | |
81 | |
82 tt.Increment(); | |
83 EXPECT_EQ(UINT64_MAX, sw->ElapsedMs()); | |
84 | |
85 tt.Increment(UINT64_MAX - tt.ticks()); | |
86 EXPECT_EQ(UINT64_MAX, tt.ticks()); | |
87 EXPECT_EQ(UINT64_MAX, sw->ElapsedMs()); | |
tlegrand-webrtc
2016/04/21 10:37:44
Is the expected behavior that we cap at UINT64_MAX
hlundin-webrtc
2016/04/21 13:50:58
ElapsedMs will cap, which is what we test. Since t
tlegrand-webrtc
2016/04/22 11:43:21
Acknowledged.
| |
88 } | |
89 | |
90 TEST(TickTimer, Countdown) { | |
91 TickTimer tt; | |
92 // Increment it a "random" number of steps. | |
93 tt.Increment(4711); | |
94 | |
95 std::unique_ptr<TickTimer::Countdown> cd = tt.GetNewCountdown(17); | |
96 ASSERT_TRUE(cd); | |
97 | |
98 EXPECT_FALSE(cd->Finished()); | |
99 tt.Increment(); | |
100 EXPECT_FALSE(cd->Finished()); | |
101 | |
102 tt.Increment(16); // Total increment is now 17. | |
103 EXPECT_TRUE(cd->Finished()); | |
104 | |
105 // Further increments do not change the state. | |
106 tt.Increment(); | |
107 EXPECT_TRUE(cd->Finished()); | |
108 tt.Increment(1234); | |
109 EXPECT_TRUE(cd->Finished()); | |
110 } | |
111 } // namespace webrtc | |
OLD | NEW |