blob: 0cabce8f5f346b3446956a33fb0f8f6d92fb942f [file] [log] [blame]
Sebastian Jansson7d6a2592019-03-22 14:38:161/*
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 Jansson7d6a2592019-03-22 14:38:1611#include "rtc_base/fake_clock.h"
12
Jonas Olssona4d87372019-07-05 17:08:3313#include "test/gtest.h"
14
Sebastian Jansson7d6a2592019-03-22 14:38:1615namespace rtc {
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
Sebastian Jansson40889f32019-04-17 10:11:2024 scoped.AdvanceTime(webrtc::TimeDelta::ms(1));
Sebastian Jansson7d6a2592019-03-22 14:38:1625 EXPECT_EQ(rtc::TimeMicros(), 1000);
26
Sebastian Jansson40889f32019-04-17 10:11:2027 scoped.SetTime(webrtc::Timestamp::us(kFixedTimeUs));
Sebastian Jansson7d6a2592019-03-22 14:38:1628 EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs);
29
Sebastian Jansson40889f32019-04-17 10:11:2030 scoped.AdvanceTime(webrtc::TimeDelta::ms(1));
Sebastian Jansson7d6a2592019-03-22 14:38:1631 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