| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <memory> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "webrtc/call/bitrate_allocator.h" | 16 #include "webrtc/call/bitrate_allocator.h" |
| 16 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 17 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 17 | 18 |
| 18 namespace webrtc { | 19 namespace webrtc { |
| 19 | 20 |
| 20 class TestBitrateObserver : public BitrateAllocatorObserver { | 21 class TestBitrateObserver : public BitrateAllocatorObserver { |
| 21 public: | 22 public: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 int64_t last_rtt_; | 35 int64_t last_rtt_; |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 class BitrateAllocatorTest : public ::testing::Test { | 38 class BitrateAllocatorTest : public ::testing::Test { |
| 38 protected: | 39 protected: |
| 39 BitrateAllocatorTest() : allocator_(new BitrateAllocator()) { | 40 BitrateAllocatorTest() : allocator_(new BitrateAllocator()) { |
| 40 allocator_->OnNetworkChanged(300000u, 0, 0); | 41 allocator_->OnNetworkChanged(300000u, 0, 0); |
| 41 } | 42 } |
| 42 ~BitrateAllocatorTest() {} | 43 ~BitrateAllocatorTest() {} |
| 43 | 44 |
| 44 rtc::scoped_ptr<BitrateAllocator> allocator_; | 45 std::unique_ptr<BitrateAllocator> allocator_; |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 TEST_F(BitrateAllocatorTest, UpdatingBitrateObserver) { | 48 TEST_F(BitrateAllocatorTest, UpdatingBitrateObserver) { |
| 48 TestBitrateObserver bitrate_observer; | 49 TestBitrateObserver bitrate_observer; |
| 49 int start_bitrate = | 50 int start_bitrate = |
| 50 allocator_->AddObserver(&bitrate_observer, 100000, 1500000); | 51 allocator_->AddObserver(&bitrate_observer, 100000, 1500000); |
| 51 EXPECT_EQ(300000, start_bitrate); | 52 EXPECT_EQ(300000, start_bitrate); |
| 52 allocator_->OnNetworkChanged(200000, 0, 0); | 53 allocator_->OnNetworkChanged(200000, 0, 0); |
| 53 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_); | 54 EXPECT_EQ(200000u, bitrate_observer.last_bitrate_); |
| 54 | 55 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 99 } |
| 99 | 100 |
| 100 class BitrateAllocatorTestNoEnforceMin : public ::testing::Test { | 101 class BitrateAllocatorTestNoEnforceMin : public ::testing::Test { |
| 101 protected: | 102 protected: |
| 102 BitrateAllocatorTestNoEnforceMin() : allocator_(new BitrateAllocator()) { | 103 BitrateAllocatorTestNoEnforceMin() : allocator_(new BitrateAllocator()) { |
| 103 allocator_->EnforceMinBitrate(false); | 104 allocator_->EnforceMinBitrate(false); |
| 104 allocator_->OnNetworkChanged(300000u, 0, 0); | 105 allocator_->OnNetworkChanged(300000u, 0, 0); |
| 105 } | 106 } |
| 106 ~BitrateAllocatorTestNoEnforceMin() {} | 107 ~BitrateAllocatorTestNoEnforceMin() {} |
| 107 | 108 |
| 108 rtc::scoped_ptr<BitrateAllocator> allocator_; | 109 std::unique_ptr<BitrateAllocator> allocator_; |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 // The following three tests verify that the EnforceMinBitrate() method works | 112 // The following three tests verify that the EnforceMinBitrate() method works |
| 112 // as intended. | 113 // as intended. |
| 113 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserver) { | 114 TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserver) { |
| 114 TestBitrateObserver bitrate_observer_1; | 115 TestBitrateObserver bitrate_observer_1; |
| 115 int start_bitrate = | 116 int start_bitrate = |
| 116 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000); | 117 allocator_->AddObserver(&bitrate_observer_1, 100000, 400000); |
| 117 EXPECT_EQ(300000, start_bitrate); | 118 EXPECT_EQ(300000, start_bitrate); |
| 118 | 119 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 allocator_->OnNetworkChanged(1000, 0, 0); | 197 allocator_->OnNetworkChanged(1000, 0, 0); |
| 197 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_); // Min cap. | 198 EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_); // Min cap. |
| 198 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_); // Min cap. | 199 EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_); // Min cap. |
| 199 EXPECT_EQ(300000u, bitrate_observer_3.last_bitrate_); // Min cap. | 200 EXPECT_EQ(300000u, bitrate_observer_3.last_bitrate_); // Min cap. |
| 200 | 201 |
| 201 allocator_->RemoveObserver(&bitrate_observer_1); | 202 allocator_->RemoveObserver(&bitrate_observer_1); |
| 202 allocator_->RemoveObserver(&bitrate_observer_2); | 203 allocator_->RemoveObserver(&bitrate_observer_2); |
| 203 allocator_->RemoveObserver(&bitrate_observer_3); | 204 allocator_->RemoveObserver(&bitrate_observer_3); |
| 204 } | 205 } |
| 205 } // namespace webrtc | 206 } // namespace webrtc |
| OLD | NEW |