blob: deff6e363da2161dbdee680719872fb296526e97 [file] [log] [blame]
sazac58f8c02017-07-19 00:39:19 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "audio/time_interval.h"
Sebastian Jansson5f83cf02018-05-08 14:52:22 +020012#include "api/units/time_delta.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/fakeclock.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "test/gtest.h"
sazac58f8c02017-07-19 00:39:19 -070015
16namespace webrtc {
17
18TEST(TimeIntervalTest, TimeInMs) {
19 rtc::ScopedFakeClock fake_clock;
20 TimeInterval interval;
21 interval.Extend();
Sebastian Jansson5f83cf02018-05-08 14:52:22 +020022 fake_clock.AdvanceTime(TimeDelta::ms(100));
sazac58f8c02017-07-19 00:39:19 -070023 interval.Extend();
24 EXPECT_EQ(interval.Length(), 100);
25}
26
27TEST(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
36TEST(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