Index: webrtc/base/fakeclock.h |
diff --git a/webrtc/base/fakeclock.h b/webrtc/base/fakeclock.h |
index 2b3afdde05f684926621bcc95c2f917bfb7bd60f..da41d8dec4a7e65755004fda0f195d712ccafcfc 100644 |
--- a/webrtc/base/fakeclock.h |
+++ b/webrtc/base/fakeclock.h |
@@ -19,6 +19,8 @@ namespace rtc { |
// Fake clock for use with unit tests, which does not tick on its own. |
// Starts at time 0. |
+// |
+// TODO(deadbeef): Unify with webrtc::SimulatedClock. |
class FakeClock : public ClockInterface { |
public: |
~FakeClock() override {} |
@@ -38,6 +40,20 @@ class FakeClock : public ClockInterface { |
uint64_t time_ GUARDED_BY(lock_) = 0u; |
}; |
+// Helper class which creates and sets a fake clock as the global clock in |
+// its constructor, and unsets and deletes it in its destructor. |
+class ScopedFakeClock { |
+ public: |
+ ScopedFakeClock() { SetClock(&clock_); } |
+ |
+ ~ScopedFakeClock() { SetClock(nullptr); } |
+ |
+ FakeClock& clock() { return clock_; } |
+ |
+ private: |
+ FakeClock clock_; |
+}; |
+ |
} // namespace rtc |
#endif // WEBRTC_BASE_FAKECLOCK_H_ |