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

Unified Diff: webrtc/base/timeutils_unittest.cc

Issue 2016863003: Implemented ScopedFakeTime, faking rtc::TimeNanos. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comments. Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« webrtc/base/faketime.h ('K') | « webrtc/base/timeutils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« webrtc/base/faketime.h ('K') | « webrtc/base/timeutils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698