Sebastian Jansson | 7d6a259 | 2019-03-22 14:38:16 | [diff] [blame] | 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 | |
Sebastian Jansson | 7d6a259 | 2019-03-22 14:38:16 | [diff] [blame] | 11 | #include "rtc_base/fake_clock.h" |
| 12 | |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 13 | #include "test/gtest.h" |
| 14 | |
Sebastian Jansson | 7d6a259 | 2019-03-22 14:38:16 | [diff] [blame] | 15 | namespace rtc { |
| 16 | TEST(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 | |
Sebastian Jansson | 40889f3 | 2019-04-17 10:11:20 | [diff] [blame] | 24 | scoped.AdvanceTime(webrtc::TimeDelta::ms(1)); |
Sebastian Jansson | 7d6a259 | 2019-03-22 14:38:16 | [diff] [blame] | 25 | EXPECT_EQ(rtc::TimeMicros(), 1000); |
| 26 | |
Sebastian Jansson | 40889f3 | 2019-04-17 10:11:20 | [diff] [blame] | 27 | scoped.SetTime(webrtc::Timestamp::us(kFixedTimeUs)); |
Sebastian Jansson | 7d6a259 | 2019-03-22 14:38:16 | [diff] [blame] | 28 | EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs); |
| 29 | |
Sebastian Jansson | 40889f3 | 2019-04-17 10:11:20 | [diff] [blame] | 30 | scoped.AdvanceTime(webrtc::TimeDelta::ms(1)); |
Sebastian Jansson | 7d6a259 | 2019-03-22 14:38:16 | [diff] [blame] | 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 |