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 { |
pthatcher1
2016/06/03 00:34:45
Have you seen FakeClock in fakeclock.h? It looks *
nisse-webrtc
2016/06/03 11:40:07
It look very similar indeed. Great minds think ali
Taylor Brandstetter
2016/06/03 16:30:16
Aside from FakeTime taking a time in its construct
|
+ public: |
+ explicit ScopedFakeTime(uint64_t start_time) : FakeTime(start_time) { |
+ rtc::test::SetFakeTime(this); |
+ } |
+ ScopedFakeTime() : ScopedFakeTime(rtc::TimeNanos()) {} |
+ |
+ ~ScopedFakeTime() { |
+ rtc::test::SetFakeTime(nullptr); |
+ } |
+}; |
+ |
+} // namespace test |
+} // namespace rtc |
+ |
+#endif // WEBRTC_BASE_FAKETIME_H_ |