Index: webrtc/base/timeutils_unittest.cc |
diff --git a/webrtc/base/timeutils_unittest.cc b/webrtc/base/timeutils_unittest.cc |
index 0971c037fa551a8c6bca1fe9403a839b6748460f..754a8df9547121568d27b893ec3908283502552b 100644 |
--- a/webrtc/base/timeutils_unittest.cc |
+++ b/webrtc/base/timeutils_unittest.cc |
@@ -13,6 +13,7 @@ |
#include "webrtc/base/helpers.h" |
#include "webrtc/base/thread.h" |
#include "webrtc/base/timeutils.h" |
+#include "webrtc/base/faketime.h" |
namespace rtc { |
@@ -205,4 +206,27 @@ TEST_F(TmToSeconds, TestTmToSeconds) { |
TestTmToSeconds(100000); |
} |
+TEST(FakeTime, TestScoping) { |
+ static const uint64_t kMaxDuration = rtc::kNumNanosecsPerSec; |
+ uint64_t before = rtc::TimeNanos(); |
+ { |
+ test::ScopedFakeTime fake_time(10000); |
+ EXPECT_EQ(rtc::TimeNanos(), 10000u); |
+ fake_time.AdvanceTime(15); |
+ EXPECT_EQ(rtc::TimeNanos(), 10015u); |
+ } |
+ { |
+ test::ScopedFakeTime fake_time; |
+ uint64_t t = rtc::TimeNanos(); |
+ EXPECT_LE(before, t); |
+ EXPECT_LE(t, before + kMaxDuration); |
+ fake_time.AdvanceTime(17); |
+ EXPECT_EQ(rtc::TimeNanos(), t + 17); |
+ } |
+ |
+ uint64_t after = rtc::TimeNanos(); |
+ EXPECT_LE(before, after); |
+ EXPECT_LE(after - before, kMaxDuration); |
+} |
+ |
} // namespace rtc |