OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 "voice_engine/include/voe_base.h" | 11 #include "voice_engine/include/voe_base.h" |
12 | 12 |
13 #include "modules/audio_processing/include/audio_processing.h" | 13 #include "modules/audio_device/include/fake_audio_device.h" |
| 14 #include "modules/audio_processing/include/mock_audio_processing.h" |
14 #include "test/gtest.h" | 15 #include "test/gtest.h" |
15 #include "voice_engine/channel_manager.h" | |
16 #include "voice_engine/shared_data.h" | |
17 #include "voice_engine/voice_engine_fixture.h" | |
18 #include "voice_engine/voice_engine_impl.h" | |
19 | 16 |
20 namespace webrtc { | 17 namespace webrtc { |
21 | 18 |
22 class VoEBaseTest : public VoiceEngineFixture {}; | 19 class VoEBaseTest : public ::testing::Test { |
| 20 protected: |
| 21 VoEBaseTest() |
| 22 : voe_(VoiceEngine::Create()), |
| 23 base_(VoEBase::GetInterface(voe_)) { |
| 24 EXPECT_NE(nullptr, base_); |
| 25 apm_ = new rtc::RefCountedObject<test::MockAudioProcessing>(); |
| 26 } |
| 27 |
| 28 ~VoEBaseTest() { |
| 29 EXPECT_EQ(0, base_->Terminate()); |
| 30 EXPECT_EQ(1, base_->Release()); |
| 31 EXPECT_TRUE(VoiceEngine::Delete(voe_)); |
| 32 } |
| 33 |
| 34 VoiceEngine* voe_; |
| 35 VoEBase* base_; |
| 36 FakeAudioDeviceModule adm_; |
| 37 rtc::scoped_refptr<AudioProcessing> apm_; |
| 38 }; |
23 | 39 |
24 TEST_F(VoEBaseTest, InitWithExternalAudioDevice) { | 40 TEST_F(VoEBaseTest, InitWithExternalAudioDevice) { |
25 EXPECT_EQ(0, base_->Init(&adm_, apm_.get())); | 41 EXPECT_EQ(0, base_->Init(&adm_, apm_.get())); |
26 EXPECT_EQ(0, base_->LastError()); | |
27 } | 42 } |
28 | 43 |
29 TEST_F(VoEBaseTest, CreateChannelBeforeInitShouldFail) { | 44 TEST_F(VoEBaseTest, CreateChannelBeforeInitShouldFail) { |
30 int channelID = base_->CreateChannel(); | 45 int channelID = base_->CreateChannel(); |
31 EXPECT_EQ(channelID, -1); | 46 EXPECT_EQ(channelID, -1); |
32 } | 47 } |
33 | 48 |
34 TEST_F(VoEBaseTest, CreateChannelAfterInit) { | 49 TEST_F(VoEBaseTest, CreateChannelAfterInit) { |
35 EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr)); | 50 EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr)); |
36 int channelID = base_->CreateChannel(); | 51 int channelID = base_->CreateChannel(); |
37 EXPECT_NE(channelID, -1); | 52 EXPECT_NE(channelID, -1); |
38 EXPECT_EQ(0, base_->DeleteChannel(channelID)); | 53 EXPECT_EQ(0, base_->DeleteChannel(channelID)); |
39 } | 54 } |
40 | 55 |
41 TEST_F(VoEBaseTest, AssociateSendChannel) { | |
42 EXPECT_EQ(0, base_->Init(&adm_, apm_.get())); | |
43 | |
44 const int channel_1 = base_->CreateChannel(); | |
45 | |
46 // Associating with a channel that does not exist should fail. | |
47 EXPECT_EQ(-1, base_->AssociateSendChannel(channel_1, channel_1 + 1)); | |
48 | |
49 const int channel_2 = base_->CreateChannel(); | |
50 | |
51 // Let the two channels associate with each other. This is not a normal use | |
52 // case. Actually, circular association should be avoided in practice. This | |
53 // is just to test that no crash is caused. | |
54 EXPECT_EQ(0, base_->AssociateSendChannel(channel_1, channel_2)); | |
55 EXPECT_EQ(0, base_->AssociateSendChannel(channel_2, channel_1)); | |
56 | |
57 voe::SharedData* shared_data = static_cast<voe::SharedData*>( | |
58 static_cast<VoiceEngineImpl*>(voe_)); | |
59 voe::ChannelOwner reference = shared_data->channel_manager() | |
60 .GetChannel(channel_1); | |
61 EXPECT_EQ(0, base_->DeleteChannel(channel_1)); | |
62 // Make sure that the only use of the channel-to-delete is |reference| | |
63 // at this point. | |
64 EXPECT_EQ(1, reference.use_count()); | |
65 | |
66 reference = shared_data->channel_manager().GetChannel(channel_2); | |
67 EXPECT_EQ(0, base_->DeleteChannel(channel_2)); | |
68 EXPECT_EQ(1, reference.use_count()); | |
69 } | |
70 | |
71 TEST_F(VoEBaseTest, GetVersion) { | |
72 char v1[1024] = {75}; | |
73 base_->GetVersion(v1); | |
74 std::string v2 = VoiceEngine::GetVersionString() + "\n"; | |
75 EXPECT_EQ(v2, v1); | |
76 } | |
77 } // namespace webrtc | 56 } // namespace webrtc |
OLD | NEW |