blob: b00075ceb56ef48cf3253d7842269da64ac6bfda [file] [log] [blame]
Ruslan Burakov428dcb22019-04-18 17:49:49 +02001/*
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
Jonas Olssona4d87372019-07-05 19:08:33 +020011#include "pc/jitter_buffer_delay.h"
12
Ruslan Burakov428dcb22019-04-18 17:49:49 +020013#include <stdint.h>
14
15#include "absl/types/optional.h"
Ruslan Burakov428dcb22019-04-18 17:49:49 +020016#include "test/gtest.h"
17
Ruslan Burakov428dcb22019-04-18 17:49:49 +020018namespace webrtc {
19
20class JitterBufferDelayTest : public ::testing::Test {
21 public:
Tommi4ccdf932021-05-17 14:50:10 +020022 JitterBufferDelayTest() {}
Ruslan Burakov428dcb22019-04-18 17:49:49 +020023
24 protected:
Tommi4ccdf932021-05-17 14:50:10 +020025 JitterBufferDelay delay_;
Ruslan Burakov428dcb22019-04-18 17:49:49 +020026};
27
28TEST_F(JitterBufferDelayTest, Set) {
Ruslan Burakov428dcb22019-04-18 17:49:49 +020029 // Delay in seconds.
Tommi4ccdf932021-05-17 14:50:10 +020030 delay_.Set(3.0);
31 EXPECT_EQ(delay_.GetMs(), 3000);
Ruslan Burakov428dcb22019-04-18 17:49:49 +020032}
33
Tommi4ccdf932021-05-17 14:50:10 +020034TEST_F(JitterBufferDelayTest, DefaultValue) {
35 EXPECT_EQ(delay_.GetMs(), 0); // Default value is 0ms.
Ruslan Burakov428dcb22019-04-18 17:49:49 +020036}
37
38TEST_F(JitterBufferDelayTest, Clamping) {
Ruslan Burakov428dcb22019-04-18 17:49:49 +020039 // In current Jitter Buffer implementation (Audio or Video) maximum supported
40 // value is 10000 milliseconds.
Tommi4ccdf932021-05-17 14:50:10 +020041 delay_.Set(10.5);
42 EXPECT_EQ(delay_.GetMs(), 10000);
Ruslan Burakov428dcb22019-04-18 17:49:49 +020043
44 // Test int overflow.
Tommi4ccdf932021-05-17 14:50:10 +020045 delay_.Set(21474836470.0);
46 EXPECT_EQ(delay_.GetMs(), 10000);
Ruslan Burakov428dcb22019-04-18 17:49:49 +020047
Tommi4ccdf932021-05-17 14:50:10 +020048 delay_.Set(-21474836470.0);
49 EXPECT_EQ(delay_.GetMs(), 0);
Ruslan Burakov428dcb22019-04-18 17:49:49 +020050
51 // Boundary value in seconds to milliseconds conversion.
Tommi4ccdf932021-05-17 14:50:10 +020052 delay_.Set(0.0009);
53 EXPECT_EQ(delay_.GetMs(), 0);
Ruslan Burakov428dcb22019-04-18 17:49:49 +020054
Tommi4ccdf932021-05-17 14:50:10 +020055 delay_.Set(-2.0);
56 EXPECT_EQ(delay_.GetMs(), 0);
Ruslan Burakov428dcb22019-04-18 17:49:49 +020057}
58
59} // namespace webrtc