Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: webrtc/base/timeutils_unittest.cc

Issue 2016863003: Implemented ScopedFakeTime, faking rtc::TimeNanos. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comments. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« webrtc/base/faketime.h ('K') | « webrtc/base/timeutils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/common.h" 11 #include "webrtc/base/common.h"
12 #include "webrtc/base/gunit.h" 12 #include "webrtc/base/gunit.h"
13 #include "webrtc/base/helpers.h" 13 #include "webrtc/base/helpers.h"
14 #include "webrtc/base/thread.h" 14 #include "webrtc/base/thread.h"
15 #include "webrtc/base/timeutils.h" 15 #include "webrtc/base/timeutils.h"
16 #include "webrtc/base/faketime.h"
16 17
17 namespace rtc { 18 namespace rtc {
18 19
19 TEST(TimeTest, TimeInMs) { 20 TEST(TimeTest, TimeInMs) {
20 int64_t ts_earlier = TimeMillis(); 21 int64_t ts_earlier = TimeMillis();
21 Thread::SleepMs(100); 22 Thread::SleepMs(100);
22 int64_t ts_now = TimeMillis(); 23 int64_t ts_now = TimeMillis();
23 // Allow for the thread to wakeup ~20ms early. 24 // Allow for the thread to wakeup ~20ms early.
24 EXPECT_GE(ts_now, ts_earlier + 80); 25 EXPECT_GE(ts_now, ts_earlier + 80);
25 // Make sure the Time is not returning in smaller unit like microseconds. 26 // Make sure the Time is not returning in smaller unit like microseconds.
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 EXPECT_TRUE(rtc::TmToSeconds(tm) == t); 199 EXPECT_TRUE(rtc::TmToSeconds(tm) == t);
199 #endif 200 #endif
200 } 201 }
201 } 202 }
202 }; 203 };
203 204
204 TEST_F(TmToSeconds, TestTmToSeconds) { 205 TEST_F(TmToSeconds, TestTmToSeconds) {
205 TestTmToSeconds(100000); 206 TestTmToSeconds(100000);
206 } 207 }
207 208
209 TEST(FakeTime, TestScoping) {
210 static const uint64_t kMaxDuration = rtc::kNumNanosecsPerSec;
211 uint64_t before = rtc::TimeNanos();
212 {
213 test::ScopedFakeTime fake_time(10000);
214 EXPECT_EQ(rtc::TimeNanos(), 10000u);
215 fake_time.AdvanceTime(15);
216 EXPECT_EQ(rtc::TimeNanos(), 10015u);
217 }
218 {
219 test::ScopedFakeTime fake_time;
220 uint64_t t = rtc::TimeNanos();
221 EXPECT_LE(before, t);
222 EXPECT_LE(t, before + kMaxDuration);
223 fake_time.AdvanceTime(17);
224 EXPECT_EQ(rtc::TimeNanos(), t + 17);
225 }
226
227 uint64_t after = rtc::TimeNanos();
228 EXPECT_LE(before, after);
229 EXPECT_LE(after - before, kMaxDuration);
230 }
231
208 } // namespace rtc 232 } // namespace rtc
OLDNEW
« webrtc/base/faketime.h ('K') | « webrtc/base/timeutils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698