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

Side by Side Diff: webrtc/base/faketime.h

Issue 2016863003: Implemented ScopedFakeTime, faking rtc::TimeNanos. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: New FakeTimeInterface. Eliminate one layer of indirection. 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2009 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 #ifndef WEBRTC_BASE_FAKETIME_H_
12 #define WEBRTC_BASE_FAKETIME_H_
13
14 #include "webrtc/base/checks.h"
15 #include "webrtc/base/timeutils.h"
16
17 namespace rtc {
18 namespace test {
19 class FakeTime : public FakeTimeInterface {
20 public:
21 explicit FakeTime(uint64_t start_time) : current_time_ns_(start_time) {}
22 uint64_t TimeNanos() override {
23 rtc::CritScope cs(&time_lock_);
24 return current_time_ns_;
25 }
26 void AdvanceTime(uint64_t interval) {
27 rtc::CritScope cs(&time_lock_);
28 current_time_ns_ += interval;
29 }
30 private:
31 CriticalSection time_lock_;
32 uint64_t current_time_ns_ GUARDED_BY(time_lock_);
33 };
34
35 class ScopedFakeTime : public FakeTime {
36 public:
37 explicit ScopedFakeTime(uint64_t start_time) : FakeTime(start_time) {
38 rtc::test::SetFakeTime(this);
39 }
40 ScopedFakeTime() : ScopedFakeTime(rtc::TimeNanos()) {}
pbos-webrtc 2016/05/31 22:35:35 Is this one useful or added prematurely?
nisse-webrtc 2016/06/01 07:35:35 It's all a bit premature, the unittest uses both c
41
42 ~ScopedFakeTime() {
43 rtc::test::SetFakeTime(nullptr);
44 }
45 };
46
47 } // namespace test
48 } // namespace rtc
49
50 #endif // WEBRTC_BASE_FAKETIME_H_
OLDNEW
« no previous file with comments | « webrtc/base/base_tests.gyp ('k') | webrtc/base/timeutils.h » ('j') | webrtc/base/timeutils.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698