OLD | NEW |
| (Empty) |
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/tools/agc/agc_manager.h" | |
12 | |
13 #include "testing/gmock/include/gmock/gmock.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 #include "webrtc/base/scoped_ptr.h" | |
16 #include "webrtc/modules/audio_processing/agc/mock_agc.h" | |
17 #include "webrtc/modules/audio_processing/include/audio_processing.h" | |
18 #include "webrtc/system_wrappers/interface/sleep.h" | |
19 #include "webrtc/test/channel_transport/include/channel_transport.h" | |
20 #include "webrtc/test/testsupport/gtest_disable.h" | |
21 #include "webrtc/voice_engine/include/voe_base.h" | |
22 #include "webrtc/voice_engine/include/voe_external_media.h" | |
23 #include "webrtc/voice_engine/include/voe_network.h" | |
24 #include "webrtc/voice_engine/include/voe_volume_control.h" | |
25 | |
26 using ::testing::_; | |
27 using ::testing::AtLeast; | |
28 using ::testing::Mock; | |
29 using ::testing::Return; | |
30 | |
31 namespace webrtc { | |
32 | |
33 class AgcManagerTest : public ::testing::Test { | |
34 protected: | |
35 AgcManagerTest() | |
36 : voe_(VoiceEngine::Create()), | |
37 base_(VoEBase::GetInterface(voe_)), | |
38 agc_(new MockAgc()), | |
39 manager_(new AgcManager(VoEExternalMedia::GetInterface(voe_), | |
40 VoEVolumeControl::GetInterface(voe_), | |
41 agc_, | |
42 AudioProcessing::Create())), | |
43 channel_(-1) { | |
44 } | |
45 | |
46 virtual void SetUp() { | |
47 ASSERT_TRUE(voe_ != NULL); | |
48 ASSERT_TRUE(base_ != NULL); | |
49 ASSERT_EQ(0, base_->Init()); | |
50 channel_ = base_->CreateChannel(); | |
51 ASSERT_NE(-1, channel_); | |
52 | |
53 VoENetwork* network = VoENetwork::GetInterface(voe_); | |
54 ASSERT_TRUE(network != NULL); | |
55 channel_transport_.reset( | |
56 new test::VoiceChannelTransport(network, channel_)); | |
57 ASSERT_EQ(0, channel_transport_->SetSendDestination("127.0.0.1", 1234)); | |
58 network->Release(); | |
59 } | |
60 | |
61 virtual void TearDown() { | |
62 channel_transport_.reset(NULL); | |
63 ASSERT_EQ(0, base_->DeleteChannel(channel_)); | |
64 ASSERT_EQ(0, base_->Terminate()); | |
65 delete manager_; | |
66 // Test that the manager has released all VoE interfaces. The last | |
67 // reference is released in VoiceEngine::Delete. | |
68 EXPECT_EQ(1, base_->Release()); | |
69 ASSERT_TRUE(VoiceEngine::Delete(voe_)); | |
70 } | |
71 | |
72 VoiceEngine* voe_; | |
73 VoEBase* base_; | |
74 MockAgc* agc_; | |
75 rtc::scoped_ptr<test::VoiceChannelTransport> channel_transport_; | |
76 // We use a pointer for the manager, so we can tear it down and test | |
77 // base_->Release() in the destructor. | |
78 AgcManager* manager_; | |
79 int channel_; | |
80 }; | |
81 | |
82 TEST_F(AgcManagerTest, DISABLED_ON_ANDROID(EnableSucceeds)) { | |
83 EXPECT_EQ(0, manager_->Enable(true)); | |
84 EXPECT_TRUE(manager_->enabled()); | |
85 EXPECT_EQ(0, manager_->Enable(false)); | |
86 EXPECT_FALSE(manager_->enabled()); | |
87 } | |
88 | |
89 TEST_F(AgcManagerTest, DISABLED_ON_ANDROID(ProcessIsNotCalledByDefault)) { | |
90 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)).Times(0); | |
91 EXPECT_CALL(*agc_, Process(_, _, _)).Times(0); | |
92 EXPECT_CALL(*agc_, GetRmsErrorDb(_)).Times(0); | |
93 ASSERT_EQ(0, base_->StartSend(channel_)); | |
94 SleepMs(100); | |
95 ASSERT_EQ(0, base_->StopSend(channel_)); | |
96 } | |
97 | |
98 TEST_F(AgcManagerTest, DISABLED_ProcessIsCalledOnlyWhenEnabled) { | |
99 EXPECT_CALL(*agc_, Reset()); | |
100 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)) | |
101 .Times(AtLeast(1)) | |
102 .WillRepeatedly(Return(0)); | |
103 EXPECT_CALL(*agc_, Process(_, _, _)) | |
104 .Times(AtLeast(1)) | |
105 .WillRepeatedly(Return(0)); | |
106 EXPECT_CALL(*agc_, GetRmsErrorDb(_)) | |
107 .Times(AtLeast(1)) | |
108 .WillRepeatedly(Return(false)); | |
109 EXPECT_EQ(0, manager_->Enable(true)); | |
110 ASSERT_EQ(0, base_->StartSend(channel_)); | |
111 SleepMs(100); | |
112 EXPECT_EQ(0, manager_->Enable(false)); | |
113 SleepMs(100); | |
114 Mock::VerifyAndClearExpectations(agc_); | |
115 | |
116 EXPECT_CALL(*agc_, AnalyzePreproc(_, _)).Times(0); | |
117 EXPECT_CALL(*agc_, Process(_, _, _)).Times(0); | |
118 EXPECT_CALL(*agc_, GetRmsErrorDb(_)).Times(0); | |
119 SleepMs(100); | |
120 ASSERT_EQ(0, base_->StopSend(channel_)); | |
121 } | |
122 | |
123 } // namespace webrtc | |
OLD | NEW |