solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 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> |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame^] | 12 | #include <memory> |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 13 | |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 16 | #include "webrtc/audio_state.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 17 | #include "webrtc/call.h" |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 18 | #include "webrtc/test/mock_voice_engine.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 19 | |
| 20 | namespace { |
| 21 | |
| 22 | struct CallHelper { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 23 | CallHelper() { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 24 | webrtc::AudioState::Config audio_state_config; |
| 25 | audio_state_config.voice_engine = &voice_engine_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 26 | webrtc::Call::Config config; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 27 | config.audio_state = webrtc::AudioState::Create(audio_state_config); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 28 | call_.reset(webrtc::Call::Create(config)); |
| 29 | } |
| 30 | |
| 31 | webrtc::Call* operator->() { return call_.get(); } |
| 32 | |
| 33 | private: |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 34 | testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_; |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame^] | 35 | std::unique_ptr<webrtc::Call> call_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 36 | }; |
| 37 | } // namespace |
| 38 | |
| 39 | namespace webrtc { |
| 40 | |
| 41 | TEST(CallTest, ConstructDestruct) { |
| 42 | CallHelper call; |
| 43 | } |
| 44 | |
| 45 | TEST(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 | |
| 55 | TEST(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 | |
| 65 | TEST(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 | |
| 88 | TEST(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 |