1 /* 2 * Copyright 2019 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "rtc_base/fake_clock.h" 12 13 #include "test/gtest.h" 14 15 namespace rtc { TEST(ScopedFakeClockTest,OverridesGlobalClock)16TEST(ScopedFakeClockTest, OverridesGlobalClock) { 17 const int64_t kFixedTimeUs = 100000; 18 int64_t real_time_us = rtc::TimeMicros(); 19 EXPECT_NE(real_time_us, 0); 20 { 21 ScopedFakeClock scoped; 22 EXPECT_EQ(rtc::TimeMicros(), 0); 23 24 scoped.AdvanceTime(webrtc::TimeDelta::Millis(1)); 25 EXPECT_EQ(rtc::TimeMicros(), 1000); 26 27 scoped.SetTime(webrtc::Timestamp::Micros(kFixedTimeUs)); 28 EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs); 29 30 scoped.AdvanceTime(webrtc::TimeDelta::Millis(1)); 31 EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs + 1000); 32 } 33 34 EXPECT_NE(rtc::TimeMicros(), kFixedTimeUs + 1000); 35 EXPECT_GE(rtc::TimeMicros(), real_time_us); 36 } 37 } // namespace rtc 38