blob: 7f8b44ecec50e939c1765c9881548c526f05de53 [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"
12#include "rtc_base/fakeclock.h"
13#include "rtc_base/timedelta.h"
14#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();
22 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(100));
23 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