aboutsummaryrefslogtreecommitdiff
path: root/webrtc/voice_engine/voe_base_unittest.cc
blob: e53dee2eff8099b6270ff5e7ef3ce5a33acee0ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "webrtc/voice_engine/include/voe_base.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/modules/audio_processing/include/audio_processing.h"
#include "webrtc/voice_engine/channel_manager.h"
#include "webrtc/voice_engine/shared_data.h"
#include "webrtc/voice_engine/voice_engine_fixture.h"
#include "webrtc/voice_engine/voice_engine_impl.h"

namespace webrtc {

class VoEBaseTest : public VoiceEngineFixture {};

TEST_F(VoEBaseTest, InitWithExternalAudioDeviceAndAudioProcessing) {
  AudioProcessing* audioproc = AudioProcessing::Create();
  EXPECT_EQ(0, base_->Init(&adm_, audioproc));
  EXPECT_EQ(audioproc, base_->audio_processing());
  EXPECT_EQ(0, base_->LastError());
}

TEST_F(VoEBaseTest, InitWithExternalAudioDevice) {
  EXPECT_EQ(nullptr, base_->audio_processing());
  EXPECT_EQ(0, base_->Init(&adm_, nullptr));
  EXPECT_NE(nullptr, base_->audio_processing());
  EXPECT_EQ(0, base_->LastError());
}

TEST_F(VoEBaseTest, CreateChannelBeforeInitShouldFail) {
  int channelID = base_->CreateChannel();
  EXPECT_EQ(channelID, -1);
}

TEST_F(VoEBaseTest, CreateChannelAfterInit) {
  EXPECT_EQ(0, base_->Init(&adm_, nullptr));
  int channelID = base_->CreateChannel();
  EXPECT_NE(channelID, -1);
  EXPECT_EQ(0, base_->DeleteChannel(channelID));
}

TEST_F(VoEBaseTest, AssociateSendChannel) {
  AudioProcessing* audioproc = AudioProcessing::Create();
  EXPECT_EQ(0, base_->Init(&adm_, audioproc));

  const int channel_1 = base_->CreateChannel();

  // Associating with a channel that does not exist should fail.
  EXPECT_EQ(-1, base_->AssociateSendChannel(channel_1, channel_1 + 1));

  const int channel_2 = base_->CreateChannel();

  // Let the two channels associate with each other. This is not a normal use
  // case. Actually, circular association should be avoided in practice. This
  // is just to test that no crash is caused.
  EXPECT_EQ(0, base_->AssociateSendChannel(channel_1, channel_2));
  EXPECT_EQ(0, base_->AssociateSendChannel(channel_2, channel_1));

  voe::SharedData* shared_data = static_cast<voe::SharedData*>(
      static_cast<VoiceEngineImpl*>(voe_));
  voe::ChannelOwner reference = shared_data->channel_manager()
      .GetChannel(channel_1);
  EXPECT_EQ(0, base_->DeleteChannel(channel_1));
  // Make sure that the only use of the channel-to-delete is |reference|
  // at this point.
  EXPECT_EQ(1, reference.use_count());

  reference = shared_data->channel_manager().GetChannel(channel_2);
  EXPECT_EQ(0, base_->DeleteChannel(channel_2));
  EXPECT_EQ(1, reference.use_count());
}

TEST_F(VoEBaseTest, GetVersion) {
  char v1[1024] = {75};
  base_->GetVersion(v1);
  std::string v2 = VoiceEngine::GetVersionString() + "\n";
  EXPECT_EQ(v2, v1);
}
}  // namespace webrtc