blob: 00a2c89cb5e874d518725bd560b5602ae3494a48 [file] [log] [blame]
Sebastian Jansson7d6a2592019-03-22 15:38:16 +01001/*
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 "test/gtest.h"
12
13#include "rtc_base/fake_clock.h"
14
15namespace 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
24 scoped.AdvanceTimeMicros(1000);
25 EXPECT_EQ(rtc::TimeMicros(), 1000);
26
27 scoped.SetTimeMicros(kFixedTimeUs);
28 EXPECT_EQ(rtc::TimeMicros(), kFixedTimeUs);
29
30 scoped.AdvanceTimeMicros(1000);
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