Chromium Code Reviews| Index: webrtc/modules/audio_coding/audio_network_adaptor/channel_controller_unittest.cc |
| diff --git a/webrtc/modules/audio_coding/audio_network_adaptor/channel_controller_unittest.cc b/webrtc/modules/audio_coding/audio_network_adaptor/channel_controller_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..58a074ceade7db8f64265be17aee053fc66d0cc0 |
| --- /dev/null |
| +++ b/webrtc/modules/audio_coding/audio_network_adaptor/channel_controller_unittest.cc |
| @@ -0,0 +1,76 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include <memory> |
| + |
| +#include "webrtc/modules/audio_coding/audio_network_adaptor/channel_controller.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace webrtc { |
| + |
| +namespace { |
| +constexpr size_t kNumChannels = 2; |
| +constexpr int kChannel1To2BandwidthBps = 31000; |
| +constexpr int kChannel2To1BandwidthBps = 29000; |
| +} // namespace |
| + |
| +class ChannelControllerTest : public ::testing::Test { |
|
hlundin-webrtc
2016/09/08 07:47:44
I think you should avoid having a test fixture. Th
minyue-webrtc
2016/09/08 08:37:00
Ok. I removed the fixture.
|
| + protected: |
| + ChannelControllerTest() |
| + : channel_controller_(new ChannelController( |
| + ChannelController::Config(kNumChannels, |
| + kNumChannels, |
| + kChannel1To2BandwidthBps, |
| + kChannel2To1BandwidthBps))) {} |
| + |
| + void SetUplinkBandwidth(int uplink_bandwidth_bps) { |
| + metrics_.uplink_bandwidth_bps = rtc::Optional<int>(uplink_bandwidth_bps); |
| + } |
| + |
| + void CheckChannelDecision(size_t channel) const { |
| + AudioNetworkAdaptor::EncoderRuntimeConfig config; |
| + channel_controller_->MakeDecision(metrics_, &config); |
| + ASSERT_TRUE(config.num_channels); |
|
hlundin-webrtc
2016/09/08 07:47:44
You can replace these two lines with one:
EXPECT_E
minyue-webrtc
2016/09/08 08:37:00
Done.
|
| + EXPECT_EQ(channel, *config.num_channels); |
| + } |
| + |
| + std::unique_ptr<ChannelController> channel_controller_; |
| + Controller::NetworkMetrics metrics_; |
| +}; |
| + |
| +TEST_F(ChannelControllerTest, OutputInitValueWhenUplinkBandwidthUnknown) { |
| + CheckChannelDecision(kNumChannels); |
| +} |
| + |
| +TEST_F(ChannelControllerTest, OutputCorrectValuesWhenUplinkBandwidthChanges) { |
| + // Use low bandwidth to ensure output is 1. |
| + SetUplinkBandwidth(kChannel2To1BandwidthBps); |
| + CheckChannelDecision(1); |
| + |
| + constexpr int kBandwidth = |
| + (kChannel1To2BandwidthBps + kChannel2To1BandwidthBps) / 2; |
| + // Use between-thresholds bandwidth to check output remains at 1. |
| + SetUplinkBandwidth(kBandwidth); |
| + CheckChannelDecision(1); |
| + |
| + // Use high bandwidth to check output switch to 2. |
| + SetUplinkBandwidth(kChannel1To2BandwidthBps); |
| + CheckChannelDecision(2); |
| + |
| + // Use between-thresholds bandwidth to check output remains at 2. |
| + SetUplinkBandwidth(kBandwidth); |
| + CheckChannelDecision(2); |
| + |
| + // Use low bandwidth to check output switch to 1. |
| + SetUplinkBandwidth(kChannel2To1BandwidthBps); |
| + CheckChannelDecision(1); |
|
hlundin-webrtc
2016/09/08 07:47:45
Add tests to verify that it switches immediately f
minyue-webrtc
2016/09/08 08:37:00
Done.
|
| +} |
| + |
| +} // namespace webrtc |