OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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 <memory> |
| 12 #include <utility> |
| 13 |
| 14 #include "webrtc/modules/remote_bitrate_estimator/probing_interval_estimator.h" |
| 15 #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_aimd_rate_co
ntrol.h" |
| 16 #include "webrtc/test/gmock.h" |
| 17 #include "webrtc/test/gtest.h" |
| 18 |
| 19 using ::testing::Return; |
| 20 |
| 21 namespace webrtc { |
| 22 |
| 23 namespace { |
| 24 |
| 25 constexpr int kMinIntervalMs = 2000; |
| 26 constexpr int kMaxIntervalMs = 50000; |
| 27 |
| 28 struct ProbingIntervalEstimatorStates { |
| 29 std::unique_ptr<ProbingIntervalEstimator> probing_interval_estimator; |
| 30 std::unique_ptr<MockAimdRateControl> aimd_rate_control; |
| 31 }; |
| 32 |
| 33 ProbingIntervalEstimatorStates CreateProbingIntervalEstimatorStates() { |
| 34 ProbingIntervalEstimatorStates states; |
| 35 states.aimd_rate_control.reset(new MockAimdRateControl()); |
| 36 states.probing_interval_estimator.reset(new ProbingIntervalEstimator( |
| 37 kMinIntervalMs, kMaxIntervalMs, states.aimd_rate_control.get())); |
| 38 return states; |
| 39 } |
| 40 } // namespace |
| 41 |
| 42 TEST(ProbingIntervalEstimatorTest, NoIntervalTillWeHaveDropAndIncrease) { |
| 43 auto states = CreateProbingIntervalEstimatorStates(); |
| 44 EXPECT_CALL(*states.aimd_rate_control, GetLastDecrease()) |
| 45 .WillOnce(Return(rtc::Optional<int>())); |
| 46 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRate()) |
| 47 .WillOnce(Return(rtc::Optional<int>())); |
| 48 EXPECT_EQ(rtc::Optional<int>(), |
| 49 states.probing_interval_estimator->GetIntervalMs()); |
| 50 |
| 51 EXPECT_CALL(*states.aimd_rate_control, GetLastDecrease()) |
| 52 .WillOnce(Return(rtc::Optional<int>(10))); |
| 53 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRate()) |
| 54 .WillOnce(Return(rtc::Optional<int>())); |
| 55 EXPECT_EQ(rtc::Optional<int>(), |
| 56 states.probing_interval_estimator->GetIntervalMs()); |
| 57 |
| 58 EXPECT_CALL(*states.aimd_rate_control, GetLastDecrease()) |
| 59 .WillOnce(Return(rtc::Optional<int>())); |
| 60 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRate()) |
| 61 .WillOnce(Return(rtc::Optional<int>(10))); |
| 62 EXPECT_EQ(rtc::Optional<int>(), |
| 63 states.probing_interval_estimator->GetIntervalMs()); |
| 64 } |
| 65 |
| 66 TEST(ProbingIntervalEstimatorTest, CalcInterval) { |
| 67 auto states = CreateProbingIntervalEstimatorStates(); |
| 68 EXPECT_CALL(*states.aimd_rate_control, GetLastDecrease()) |
| 69 .WillOnce(Return(rtc::Optional<int>(20000))); |
| 70 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRate()) |
| 71 .WillOnce(Return(rtc::Optional<int>(5000))); |
| 72 EXPECT_EQ(rtc::Optional<int>(4000), |
| 73 states.probing_interval_estimator->GetIntervalMs()); |
| 74 } |
| 75 |
| 76 TEST(ProbingIntervalEstimatorTest, IntervalNotExceedMin) { |
| 77 auto states = CreateProbingIntervalEstimatorStates(); |
| 78 EXPECT_CALL(*states.aimd_rate_control, GetLastDecrease()) |
| 79 .WillOnce(Return(rtc::Optional<int>(1000))); |
| 80 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRate()) |
| 81 .WillOnce(Return(rtc::Optional<int>(5000))); |
| 82 EXPECT_EQ(rtc::Optional<int>(kMinIntervalMs), |
| 83 states.probing_interval_estimator->GetIntervalMs()); |
| 84 } |
| 85 |
| 86 TEST(ProbingIntervalEstimatorTest, IntervalNotExceedMax) { |
| 87 auto states = CreateProbingIntervalEstimatorStates(); |
| 88 EXPECT_CALL(*states.aimd_rate_control, GetLastDecrease()) |
| 89 .WillOnce(Return(rtc::Optional<int>(50000))); |
| 90 EXPECT_CALL(*states.aimd_rate_control, GetNearMaxIncreaseRate()) |
| 91 .WillOnce(Return(rtc::Optional<int>(100))); |
| 92 EXPECT_EQ(rtc::Optional<int>(kMaxIntervalMs), |
| 93 states.probing_interval_estimator->GetIntervalMs()); |
| 94 } |
| 95 } // namespace webrtc |
OLD | NEW |