1 /*
2 * Copyright (c) 2012 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 "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
12
13 class AgcConfigTest : public AfterStreamingFixture {
14 protected:
SetUp()15 void SetUp() {
16 // These should be defaults for the AGC config.
17 default_agc_config_.digitalCompressionGaindB = 9;
18 default_agc_config_.limiterEnable = true;
19 default_agc_config_.targetLeveldBOv = 3;
20 }
21
22 webrtc::AgcConfig default_agc_config_;
23 };
24
TEST_F(AgcConfigTest,HasCorrectDefaultConfiguration)25 TEST_F(AgcConfigTest, HasCorrectDefaultConfiguration) {
26 webrtc::AgcConfig agc_config;
27
28 EXPECT_EQ(0, voe_apm_->GetAgcConfig(agc_config));
29
30 EXPECT_EQ(default_agc_config_.targetLeveldBOv, agc_config.targetLeveldBOv);
31 EXPECT_EQ(default_agc_config_.digitalCompressionGaindB,
32 agc_config.digitalCompressionGaindB);
33 EXPECT_EQ(default_agc_config_.limiterEnable, agc_config.limiterEnable);
34 }
35
TEST_F(AgcConfigTest,DealsWithInvalidParameters)36 TEST_F(AgcConfigTest, DealsWithInvalidParameters) {
37 webrtc::AgcConfig agc_config = default_agc_config_;
38 agc_config.digitalCompressionGaindB = 91;
39 EXPECT_EQ(-1, voe_apm_->SetAgcConfig(agc_config)) << "Should not be able "
40 "to set gain to more than 90 dB.";
41 EXPECT_EQ(VE_APM_ERROR, voe_base_->LastError());
42
43 agc_config = default_agc_config_;
44 agc_config.targetLeveldBOv = 32;
45 EXPECT_EQ(-1, voe_apm_->SetAgcConfig(agc_config)) << "Should not be able "
46 "to set target level to more than 31.";
47 EXPECT_EQ(VE_APM_ERROR, voe_base_->LastError());
48 }
49
TEST_F(AgcConfigTest,CanGetAndSetAgcStatus)50 TEST_F(AgcConfigTest, CanGetAndSetAgcStatus) {
51 webrtc::AgcConfig agc_config;
52 agc_config.digitalCompressionGaindB = 17;
53 agc_config.targetLeveldBOv = 11;
54 agc_config.limiterEnable = false;
55
56 webrtc::AgcConfig actual_config;
57 EXPECT_EQ(0, voe_apm_->SetAgcConfig(agc_config));
58 EXPECT_EQ(0, voe_apm_->GetAgcConfig(actual_config));
59
60 EXPECT_EQ(agc_config.digitalCompressionGaindB,
61 actual_config.digitalCompressionGaindB);
62 EXPECT_EQ(agc_config.limiterEnable,
63 actual_config.limiterEnable);
64 EXPECT_EQ(agc_config.targetLeveldBOv,
65 actual_config.targetLeveldBOv);
66 }
67
TEST_F(AgcConfigTest,HasCorrectDefaultRxConfiguration)68 TEST_F(AgcConfigTest, HasCorrectDefaultRxConfiguration) {
69 webrtc::AgcConfig agc_config;
70
71 EXPECT_EQ(0, voe_apm_->GetRxAgcConfig(channel_, agc_config));
72
73 EXPECT_EQ(default_agc_config_.targetLeveldBOv, agc_config.targetLeveldBOv);
74 EXPECT_EQ(default_agc_config_.digitalCompressionGaindB,
75 agc_config.digitalCompressionGaindB);
76 EXPECT_EQ(default_agc_config_.limiterEnable, agc_config.limiterEnable);
77 }
78
TEST_F(AgcConfigTest,DealsWithInvalidRxParameters)79 TEST_F(AgcConfigTest, DealsWithInvalidRxParameters) {
80 webrtc::AgcConfig agc_config = default_agc_config_;
81 agc_config.digitalCompressionGaindB = 91;
82 EXPECT_EQ(-1, voe_apm_->SetRxAgcConfig(channel_, agc_config)) <<
83 "Should not be able to set RX gain to more than 90 dB.";
84 EXPECT_EQ(VE_APM_ERROR, voe_base_->LastError());
85
86 agc_config = default_agc_config_;
87 agc_config.targetLeveldBOv = 32;
88 EXPECT_EQ(-1, voe_apm_->SetRxAgcConfig(channel_, agc_config)) <<
89 "Should not be able to set target level to more than 31.";
90 EXPECT_EQ(VE_APM_ERROR, voe_base_->LastError());
91 }
92
TEST_F(AgcConfigTest,CanGetAndSetRxAgcStatus)93 TEST_F(AgcConfigTest, CanGetAndSetRxAgcStatus) {
94 webrtc::AgcConfig agc_config;
95 agc_config.digitalCompressionGaindB = 17;
96 agc_config.targetLeveldBOv = 11;
97 agc_config.limiterEnable = false;
98
99 webrtc::AgcConfig actual_config;
100 EXPECT_EQ(0, voe_apm_->SetRxAgcConfig(channel_, agc_config));
101 EXPECT_EQ(0, voe_apm_->GetRxAgcConfig(channel_, actual_config));
102
103 EXPECT_EQ(agc_config.digitalCompressionGaindB,
104 actual_config.digitalCompressionGaindB);
105 EXPECT_EQ(agc_config.limiterEnable,
106 actual_config.limiterEnable);
107 EXPECT_EQ(agc_config.targetLeveldBOv,
108 actual_config.targetLeveldBOv);
109 }
110