blob: e53dee2eff8099b6270ff5e7ef3ce5a33acee0ba [file] [log] [blame]
andrew@webrtc.orgf0a90c32013-03-05 01:12:491/*
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
13#include "testing/gtest/include/gtest/gtest.h"
pbos@webrtc.org956aa7e2013-05-21 13:52:3214#include "webrtc/modules/audio_processing/include/audio_processing.h"
Minyue2013aec2015-05-13 12:14:4215#include "webrtc/voice_engine/channel_manager.h"
16#include "webrtc/voice_engine/shared_data.h"
Jelena Marusic46bd31b2015-04-30 08:57:1017#include "webrtc/voice_engine/voice_engine_fixture.h"
Minyue2013aec2015-05-13 12:14:4218#include "webrtc/voice_engine/voice_engine_impl.h"
andrew@webrtc.orgf0a90c32013-03-05 01:12:4919
20namespace webrtc {
21
Jelena Marusic0b154452015-05-04 07:55:5922class VoEBaseTest : public VoiceEngineFixture {};
andrew@webrtc.orgf0a90c32013-03-05 01:12:4923
Jelena Marusic0b154452015-05-04 07:55:5924TEST_F(VoEBaseTest, InitWithExternalAudioDeviceAndAudioProcessing) {
andrew@webrtc.org46323b32015-01-13 06:48:0625 AudioProcessing* audioproc = AudioProcessing::Create();
Jelena Marusic06b08af2015-04-21 09:39:5726 EXPECT_EQ(0, base_->Init(&adm_, audioproc));
andrew@webrtc.orgf0a90c32013-03-05 01:12:4927 EXPECT_EQ(audioproc, base_->audio_processing());
Jelena Marusic06b08af2015-04-21 09:39:5728 EXPECT_EQ(0, base_->LastError());
andrew@webrtc.orgf0a90c32013-03-05 01:12:4929}
30
Jelena Marusic0b154452015-05-04 07:55:5931TEST_F(VoEBaseTest, InitWithExternalAudioDevice) {
Jelena Marusic06b08af2015-04-21 09:39:5732 EXPECT_EQ(nullptr, base_->audio_processing());
33 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
34 EXPECT_NE(nullptr, base_->audio_processing());
35 EXPECT_EQ(0, base_->LastError());
36}
37
Jelena Marusic0b154452015-05-04 07:55:5938TEST_F(VoEBaseTest, CreateChannelBeforeInitShouldFail) {
Jelena Marusic06b08af2015-04-21 09:39:5739 int channelID = base_->CreateChannel();
Jelena Marusic46bd31b2015-04-30 08:57:1040 EXPECT_EQ(channelID, -1);
Jelena Marusic06b08af2015-04-21 09:39:5741}
42
Jelena Marusic0b154452015-05-04 07:55:5943TEST_F(VoEBaseTest, CreateChannelAfterInit) {
Jelena Marusic06b08af2015-04-21 09:39:5744 EXPECT_EQ(0, base_->Init(&adm_, nullptr));
45 int channelID = base_->CreateChannel();
Jelena Marusic46bd31b2015-04-30 08:57:1046 EXPECT_NE(channelID, -1);
Jelena Marusic06b08af2015-04-21 09:39:5747 EXPECT_EQ(0, base_->DeleteChannel(channelID));
andrew@webrtc.orgf0a90c32013-03-05 01:12:4948}
49
Minyue2013aec2015-05-13 12:14:4250TEST_F(VoEBaseTest, AssociateSendChannel) {
51 AudioProcessing* audioproc = AudioProcessing::Create();
52 EXPECT_EQ(0, base_->Init(&adm_, audioproc));
53
54 const int channel_1 = base_->CreateChannel();
55
56 // Associating with a channel that does not exist should fail.
57 EXPECT_EQ(-1, base_->AssociateSendChannel(channel_1, channel_1 + 1));
58
59 const int channel_2 = base_->CreateChannel();
60
61 // Let the two channels associate with each other. This is not a normal use
62 // case. Actually, circular association should be avoided in practice. This
63 // is just to test that no crash is caused.
64 EXPECT_EQ(0, base_->AssociateSendChannel(channel_1, channel_2));
65 EXPECT_EQ(0, base_->AssociateSendChannel(channel_2, channel_1));
66
67 voe::SharedData* shared_data = static_cast<voe::SharedData*>(
68 static_cast<VoiceEngineImpl*>(voe_));
69 voe::ChannelOwner reference = shared_data->channel_manager()
70 .GetChannel(channel_1);
71 EXPECT_EQ(0, base_->DeleteChannel(channel_1));
72 // Make sure that the only use of the channel-to-delete is |reference|
73 // at this point.
74 EXPECT_EQ(1, reference.use_count());
75
76 reference = shared_data->channel_manager().GetChannel(channel_2);
77 EXPECT_EQ(0, base_->DeleteChannel(channel_2));
78 EXPECT_EQ(1, reference.use_count());
79}
80
solenberg2515af22015-12-02 14:19:3681TEST_F(VoEBaseTest, GetVersion) {
82 char v1[1024] = {75};
83 base_->GetVersion(v1);
84 std::string v2 = VoiceEngine::GetVersionString() + "\n";
85 EXPECT_EQ(v2, v1);
86}
andrew@webrtc.orgf0a90c32013-03-05 01:12:4987} // namespace webrtc