saza | c58f8c0 | 2017-07-19 00:39:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "audio/time_interval.h" |
Sebastian Jansson | 5f83cf0 | 2018-05-08 14:52:22 +0200 | [diff] [blame] | 12 | #include "api/units/time_delta.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "rtc_base/fakeclock.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "test/gtest.h" |
saza | c58f8c0 | 2017-07-19 00:39:19 -0700 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | TEST(TimeIntervalTest, TimeInMs) { |
| 19 | rtc::ScopedFakeClock fake_clock; |
| 20 | TimeInterval interval; |
| 21 | interval.Extend(); |
Sebastian Jansson | 5f83cf0 | 2018-05-08 14:52:22 +0200 | [diff] [blame] | 22 | fake_clock.AdvanceTime(TimeDelta::ms(100)); |
saza | c58f8c0 | 2017-07-19 00:39:19 -0700 | [diff] [blame] | 23 | interval.Extend(); |
| 24 | EXPECT_EQ(interval.Length(), 100); |
| 25 | } |
| 26 | |
| 27 | TEST(TimeIntervalTest, Empty) { |
| 28 | TimeInterval interval; |
| 29 | EXPECT_TRUE(interval.Empty()); |
| 30 | interval.Extend(); |
| 31 | EXPECT_FALSE(interval.Empty()); |
| 32 | interval.Extend(200); |
| 33 | EXPECT_FALSE(interval.Empty()); |
| 34 | } |
| 35 | |
| 36 | TEST(TimeIntervalTest, MonotoneIncreasing) { |
| 37 | const size_t point_count = 7; |
| 38 | const int64_t interval_points[] = {3, 2, 5, 0, 4, 1, 6}; |
| 39 | const int64_t interval_differences[] = {0, 1, 3, 5, 5, 5, 6}; |
| 40 | TimeInterval interval; |
| 41 | EXPECT_TRUE(interval.Empty()); |
| 42 | for (size_t i = 0; i < point_count; ++i) { |
| 43 | interval.Extend(interval_points[i]); |
| 44 | EXPECT_EQ(interval_differences[i], interval.Length()); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | } // namespace webrtc |