blob: fb6cac11bcf529dcb095b1964aea6af759f337b0 [file] [log] [blame]
solenbergc7a8b082015-10-16 14:35:07 -07001/*
2 * Copyright (c) 2015 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 <list>
kwibergb25345e2016-03-12 06:10:44 -080012#include <memory>
solenbergc7a8b082015-10-16 14:35:07 -070013
14#include "testing/gtest/include/gtest/gtest.h"
15
solenberg566ef242015-11-06 15:34:49 -080016#include "webrtc/audio_state.h"
solenbergc7a8b082015-10-16 14:35:07 -070017#include "webrtc/call.h"
ossu29b1a8d2016-06-13 07:34:51 -070018#include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h"
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010019#include "webrtc/test/mock_voice_engine.h"
solenbergc7a8b082015-10-16 14:35:07 -070020
21namespace {
22
23struct CallHelper {
ossu29b1a8d2016-06-13 07:34:51 -070024 explicit CallHelper(
25 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr)
26 : voice_engine_(decoder_factory) {
solenberg566ef242015-11-06 15:34:49 -080027 webrtc::AudioState::Config audio_state_config;
28 audio_state_config.voice_engine = &voice_engine_;
solenbergc7a8b082015-10-16 14:35:07 -070029 webrtc::Call::Config config;
solenberg566ef242015-11-06 15:34:49 -080030 config.audio_state = webrtc::AudioState::Create(audio_state_config);
solenbergc7a8b082015-10-16 14:35:07 -070031 call_.reset(webrtc::Call::Create(config));
32 }
33
34 webrtc::Call* operator->() { return call_.get(); }
35
36 private:
solenberg3a941542015-11-16 07:34:50 -080037 testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_;
kwibergb25345e2016-03-12 06:10:44 -080038 std::unique_ptr<webrtc::Call> call_;
solenbergc7a8b082015-10-16 14:35:07 -070039};
40} // namespace
41
42namespace webrtc {
43
44TEST(CallTest, ConstructDestruct) {
45 CallHelper call;
46}
47
48TEST(CallTest, CreateDestroy_AudioSendStream) {
49 CallHelper call;
50 AudioSendStream::Config config(nullptr);
51 config.rtp.ssrc = 42;
52 config.voe_channel_id = 123;
53 AudioSendStream* stream = call->CreateAudioSendStream(config);
54 EXPECT_NE(stream, nullptr);
55 call->DestroyAudioSendStream(stream);
56}
57
58TEST(CallTest, CreateDestroy_AudioReceiveStream) {
ossu29b1a8d2016-06-13 07:34:51 -070059 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
60 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
61 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -070062 AudioReceiveStream::Config config;
63 config.rtp.remote_ssrc = 42;
64 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -070065 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -070066 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
67 EXPECT_NE(stream, nullptr);
68 call->DestroyAudioReceiveStream(stream);
69}
70
71TEST(CallTest, CreateDestroy_AudioSendStreams) {
72 CallHelper call;
73 AudioSendStream::Config config(nullptr);
74 config.voe_channel_id = 123;
75 std::list<AudioSendStream*> streams;
76 for (int i = 0; i < 2; ++i) {
77 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
78 config.rtp.ssrc = ssrc;
79 AudioSendStream* stream = call->CreateAudioSendStream(config);
80 EXPECT_NE(stream, nullptr);
81 if (ssrc & 1) {
82 streams.push_back(stream);
83 } else {
84 streams.push_front(stream);
85 }
86 }
87 for (auto s : streams) {
88 call->DestroyAudioSendStream(s);
89 }
90 streams.clear();
91 }
92}
93
94TEST(CallTest, CreateDestroy_AudioReceiveStreams) {
ossu29b1a8d2016-06-13 07:34:51 -070095 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
96 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
97 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -070098 AudioReceiveStream::Config config;
99 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -0700100 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -0700101 std::list<AudioReceiveStream*> streams;
102 for (int i = 0; i < 2; ++i) {
103 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
104 config.rtp.remote_ssrc = ssrc;
105 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
106 EXPECT_NE(stream, nullptr);
107 if (ssrc & 1) {
108 streams.push_back(stream);
109 } else {
110 streams.push_front(stream);
111 }
112 }
113 for (auto s : streams) {
114 call->DestroyAudioReceiveStream(s);
115 }
116 streams.clear();
117 }
118}
119} // namespace webrtc