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