andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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/include/voe_base.h" |
| 12 | |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 13 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 14 | #include "webrtc/test/gtest.h" |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 15 | #include "webrtc/voice_engine/channel_manager.h" |
| 16 | #include "webrtc/voice_engine/shared_data.h" |
Jelena Marusic | 46bd31b | 2015-04-30 10:57:10 +0200 | [diff] [blame] | 17 | #include "webrtc/voice_engine/voice_engine_fixture.h" |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 18 | #include "webrtc/voice_engine/voice_engine_impl.h" |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
Jelena Marusic | 0b15445 | 2015-05-04 09:55:59 +0200 | [diff] [blame] | 22 | class VoEBaseTest : public VoiceEngineFixture {}; |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 23 | |
Jelena Marusic | 0b15445 | 2015-05-04 09:55:59 +0200 | [diff] [blame] | 24 | TEST_F(VoEBaseTest, InitWithExternalAudioDevice) { |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 25 | EXPECT_EQ(0, base_->Init(&adm_, apm_.get())); |
Jelena Marusic | 06b08af | 2015-04-21 11:39:57 +0200 | [diff] [blame] | 26 | EXPECT_EQ(0, base_->LastError()); |
| 27 | } |
| 28 | |
Jelena Marusic | 0b15445 | 2015-05-04 09:55:59 +0200 | [diff] [blame] | 29 | TEST_F(VoEBaseTest, CreateChannelBeforeInitShouldFail) { |
Jelena Marusic | 06b08af | 2015-04-21 11:39:57 +0200 | [diff] [blame] | 30 | int channelID = base_->CreateChannel(); |
Jelena Marusic | 46bd31b | 2015-04-30 10:57:10 +0200 | [diff] [blame] | 31 | EXPECT_EQ(channelID, -1); |
Jelena Marusic | 06b08af | 2015-04-21 11:39:57 +0200 | [diff] [blame] | 32 | } |
| 33 | |
Jelena Marusic | 0b15445 | 2015-05-04 09:55:59 +0200 | [diff] [blame] | 34 | TEST_F(VoEBaseTest, CreateChannelAfterInit) { |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 35 | EXPECT_EQ(0, base_->Init(&adm_, apm_.get(), nullptr)); |
Jelena Marusic | 06b08af | 2015-04-21 11:39:57 +0200 | [diff] [blame] | 36 | int channelID = base_->CreateChannel(); |
Jelena Marusic | 46bd31b | 2015-04-30 10:57:10 +0200 | [diff] [blame] | 37 | EXPECT_NE(channelID, -1); |
Jelena Marusic | 06b08af | 2015-04-21 11:39:57 +0200 | [diff] [blame] | 38 | EXPECT_EQ(0, base_->DeleteChannel(channelID)); |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 41 | TEST_F(VoEBaseTest, AssociateSendChannel) { |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 42 | EXPECT_EQ(0, base_->Init(&adm_, apm_.get())); |
Minyue | 2013aec | 2015-05-13 14:14:42 +0200 | [diff] [blame] | 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 | |
solenberg | 2515af2 | 2015-12-02 06:19:36 -0800 | [diff] [blame] | 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 | } |
andrew@webrtc.org | f0a90c3 | 2013-03-05 01:12:49 +0000 | [diff] [blame] | 77 | } // namespace webrtc |