OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2017 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/rtc_base/time_interval.h" | |
12 #include "webrtc/rtc_base/thread.h" | |
13 #include "webrtc/test/gtest.h" | |
14 | |
15 namespace rtc { | |
16 | |
17 TEST(TimeIntervalTest, TimeInMs) { | |
18 TimeInterval interval; | |
19 interval.Extend(); | |
20 Thread::SleepMs(100); | |
ossu
2017/07/14 11:13:15
Use a fake clock for testing instead. This is pron
saza WebRTC
2017/07/17 14:27:29
Done.
| |
21 interval.Extend(); | |
22 // Allow for the thread to wakeup ~20ms early. | |
23 EXPECT_GE(*interval.Last(), *interval.First() + 80); | |
24 // Make sure the Time is not returning in smaller unit like microseconds. | |
25 EXPECT_LT(*interval.Last(), *interval.First() + 1000); | |
26 } | |
27 | |
28 TEST(TimeIntervalTest, Empty) { | |
29 TimeInterval interval; | |
30 EXPECT_TRUE(interval.Empty()); | |
31 interval.Extend(); | |
32 EXPECT_FALSE(interval.Empty()); | |
33 interval.Extend(200); | |
34 EXPECT_FALSE(interval.Empty()); | |
35 } | |
36 | |
37 TEST(TimeIntervalTest, MonotoneIncreasing) { | |
38 const size_t point_count = 7; | |
39 const int64_t interval_points[] = {3, 2, 5, 0, 4, 1, 6}; | |
40 const int64_t interval_differences[] = {0, 1, 3, 5, 5, 5, 6}; | |
41 TimeInterval interval; | |
42 EXPECT_FALSE(interval.First()); | |
43 for (size_t i = 0; i < point_count; ++i) { | |
44 interval.Extend(interval_points[i]); | |
45 EXPECT_EQ(interval_differences[i], *interval.Last() - *interval.First()); | |
46 } | |
47 } | |
48 | |
49 } // namespace rtc | |
OLD | NEW |