blob: 0da91a9bf739ee0fbe0174286d9b84e278b1c411 [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"
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010018#include "webrtc/test/mock_voice_engine.h"
solenbergc7a8b082015-10-16 14:35:07 -070019
20namespace {
21
22struct CallHelper {
solenberg566ef242015-11-06 15:34:49 -080023 CallHelper() {
solenberg566ef242015-11-06 15:34:49 -080024 webrtc::AudioState::Config audio_state_config;
25 audio_state_config.voice_engine = &voice_engine_;
solenbergc7a8b082015-10-16 14:35:07 -070026 webrtc::Call::Config config;
solenberg566ef242015-11-06 15:34:49 -080027 config.audio_state = webrtc::AudioState::Create(audio_state_config);
solenbergc7a8b082015-10-16 14:35:07 -070028 call_.reset(webrtc::Call::Create(config));
29 }
30
31 webrtc::Call* operator->() { return call_.get(); }
32
33 private:
solenberg3a941542015-11-16 07:34:50 -080034 testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_;
kwibergb25345e2016-03-12 06:10:44 -080035 std::unique_ptr<webrtc::Call> call_;
solenbergc7a8b082015-10-16 14:35:07 -070036};
37} // namespace
38
39namespace webrtc {
40
41TEST(CallTest, ConstructDestruct) {
42 CallHelper call;
43}
44
45TEST(CallTest, CreateDestroy_AudioSendStream) {
46 CallHelper call;
47 AudioSendStream::Config config(nullptr);
48 config.rtp.ssrc = 42;
49 config.voe_channel_id = 123;
50 AudioSendStream* stream = call->CreateAudioSendStream(config);
51 EXPECT_NE(stream, nullptr);
52 call->DestroyAudioSendStream(stream);
53}
54
55TEST(CallTest, CreateDestroy_AudioReceiveStream) {
56 CallHelper call;
57 AudioReceiveStream::Config config;
58 config.rtp.remote_ssrc = 42;
59 config.voe_channel_id = 123;
60 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
61 EXPECT_NE(stream, nullptr);
62 call->DestroyAudioReceiveStream(stream);
63}
64
65TEST(CallTest, CreateDestroy_AudioSendStreams) {
66 CallHelper call;
67 AudioSendStream::Config config(nullptr);
68 config.voe_channel_id = 123;
69 std::list<AudioSendStream*> streams;
70 for (int i = 0; i < 2; ++i) {
71 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
72 config.rtp.ssrc = ssrc;
73 AudioSendStream* stream = call->CreateAudioSendStream(config);
74 EXPECT_NE(stream, nullptr);
75 if (ssrc & 1) {
76 streams.push_back(stream);
77 } else {
78 streams.push_front(stream);
79 }
80 }
81 for (auto s : streams) {
82 call->DestroyAudioSendStream(s);
83 }
84 streams.clear();
85 }
86}
87
88TEST(CallTest, CreateDestroy_AudioReceiveStreams) {
89 CallHelper call;
90 AudioReceiveStream::Config config;
91 config.voe_channel_id = 123;
92 std::list<AudioReceiveStream*> streams;
93 for (int i = 0; i < 2; ++i) {
94 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
95 config.rtp.remote_ssrc = ssrc;
96 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
97 EXPECT_NE(stream, nullptr);
98 if (ssrc & 1) {
99 streams.push_back(stream);
100 } else {
101 streams.push_front(stream);
102 }
103 }
104 for (auto s : streams) {
105 call->DestroyAudioReceiveStream(s);
106 }
107 streams.clear();
108 }
109}
110} // namespace webrtc