1 /*
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
15 #include "webrtc/audio_state.h"
16 #include "webrtc/call.h"
17 #include "webrtc/test/mock_voice_engine.h"
18
19 namespace {
20
21 struct CallHelper {
CallHelper__anon498bc9f70111::CallHelper22 CallHelper() {
23 webrtc::AudioState::Config audio_state_config;
24 audio_state_config.voice_engine = &voice_engine_;
25 webrtc::Call::Config config;
26 config.audio_state = webrtc::AudioState::Create(audio_state_config);
27 call_.reset(webrtc::Call::Create(config));
28 }
29
operator ->__anon498bc9f70111::CallHelper30 webrtc::Call* operator->() { return call_.get(); }
31
32 private:
33 testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_;
34 rtc::scoped_ptr<webrtc::Call> call_;
35 };
36 } // namespace
37
38 namespace webrtc {
39
TEST(CallTest,ConstructDestruct)40 TEST(CallTest, ConstructDestruct) {
41 CallHelper call;
42 }
43
TEST(CallTest,CreateDestroy_AudioSendStream)44 TEST(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
TEST(CallTest,CreateDestroy_AudioReceiveStream)54 TEST(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
TEST(CallTest,CreateDestroy_AudioSendStreams)64 TEST(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
TEST(CallTest,CreateDestroy_AudioReceiveStreams)87 TEST(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
110