blob: b26024d91e5cb86582a7d5f5ea95049b86644827 [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() {
23 EXPECT_CALL(voice_engine_,
24 RegisterVoiceEngineObserver(testing::_)).WillOnce(testing::Return(0));
25 EXPECT_CALL(voice_engine_,
26 DeRegisterVoiceEngineObserver()).WillOnce(testing::Return(0));
27 EXPECT_CALL(voice_engine_,
28 GetEventLog()).WillOnce(testing::Return(nullptr));
29 webrtc::AudioState::Config audio_state_config;
30 audio_state_config.voice_engine = &voice_engine_;
solenbergc7a8b082015-10-16 14:35:07 -070031 webrtc::Call::Config config;
solenberg566ef242015-11-06 15:34:49 -080032 config.audio_state = webrtc::AudioState::Create(audio_state_config);
solenbergc7a8b082015-10-16 14:35:07 -070033 call_.reset(webrtc::Call::Create(config));
34 }
35
36 webrtc::Call* operator->() { return call_.get(); }
37
38 private:
solenberg566ef242015-11-06 15:34:49 -080039 webrtc::test::MockVoiceEngine voice_engine_;
solenbergc7a8b082015-10-16 14:35:07 -070040 rtc::scoped_ptr<webrtc::Call> call_;
41};
42} // namespace
43
44namespace webrtc {
45
46TEST(CallTest, ConstructDestruct) {
47 CallHelper call;
48}
49
50TEST(CallTest, CreateDestroy_AudioSendStream) {
51 CallHelper call;
52 AudioSendStream::Config config(nullptr);
53 config.rtp.ssrc = 42;
54 config.voe_channel_id = 123;
55 AudioSendStream* stream = call->CreateAudioSendStream(config);
56 EXPECT_NE(stream, nullptr);
57 call->DestroyAudioSendStream(stream);
58}
59
60TEST(CallTest, CreateDestroy_AudioReceiveStream) {
61 CallHelper call;
62 AudioReceiveStream::Config config;
63 config.rtp.remote_ssrc = 42;
64 config.voe_channel_id = 123;
65 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
66 EXPECT_NE(stream, nullptr);
67 call->DestroyAudioReceiveStream(stream);
68}
69
70TEST(CallTest, CreateDestroy_AudioSendStreams) {
71 CallHelper call;
72 AudioSendStream::Config config(nullptr);
73 config.voe_channel_id = 123;
74 std::list<AudioSendStream*> streams;
75 for (int i = 0; i < 2; ++i) {
76 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
77 config.rtp.ssrc = ssrc;
78 AudioSendStream* stream = call->CreateAudioSendStream(config);
79 EXPECT_NE(stream, nullptr);
80 if (ssrc & 1) {
81 streams.push_back(stream);
82 } else {
83 streams.push_front(stream);
84 }
85 }
86 for (auto s : streams) {
87 call->DestroyAudioSendStream(s);
88 }
89 streams.clear();
90 }
91}
92
93TEST(CallTest, CreateDestroy_AudioReceiveStreams) {
94 CallHelper call;
95 AudioReceiveStream::Config config;
96 config.voe_channel_id = 123;
97 std::list<AudioReceiveStream*> streams;
98 for (int i = 0; i < 2; ++i) {
99 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
100 config.rtp.remote_ssrc = ssrc;
101 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
102 EXPECT_NE(stream, nullptr);
103 if (ssrc & 1) {
104 streams.push_back(stream);
105 } else {
106 streams.push_front(stream);
107 }
108 }
109 for (auto s : streams) {
110 call->DestroyAudioReceiveStream(s);
111 }
112 streams.clear();
113 }
114}
115} // namespace webrtc