Index: webrtc/base/faketime.h |
diff --git a/webrtc/base/faketime.h b/webrtc/base/faketime.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a45a2d7a99db1ea24c804b77f229b5d2a9f0a8af |
--- /dev/null |
+++ b/webrtc/base/faketime.h |
@@ -0,0 +1,50 @@ |
+/* |
+ * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#ifndef WEBRTC_BASE_FAKETIME_H_ |
+#define WEBRTC_BASE_FAKETIME_H_ |
+ |
+#include "webrtc/base/checks.h" |
+#include "webrtc/base/timeutils.h" |
+ |
+namespace rtc { |
+namespace test { |
+class FakeTime : public FakeTimeInterface { |
+ public: |
+ explicit FakeTime(uint64_t start_time) : current_time_ns_(start_time) {} |
+ uint64_t TimeNanos() override { |
+ rtc::CritScope cs(&time_lock_); |
+ return current_time_ns_; |
+ } |
+ void AdvanceTime(uint64_t interval) { |
+ rtc::CritScope cs(&time_lock_); |
+ current_time_ns_ += interval; |
+ } |
+ private: |
+ CriticalSection time_lock_; |
+ uint64_t current_time_ns_ GUARDED_BY(time_lock_); |
+}; |
+ |
+class ScopedFakeTime : public FakeTime { |
+ public: |
+ explicit ScopedFakeTime(uint64_t start_time) : FakeTime(start_time) { |
+ rtc::test::SetFakeTime(this); |
+ } |
+ 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
|
+ |
+ ~ScopedFakeTime() { |
+ rtc::test::SetFakeTime(nullptr); |
+ } |
+}; |
+ |
+} // namespace test |
+} // namespace rtc |
+ |
+#endif // WEBRTC_BASE_FAKETIME_H_ |