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> |
| 12 | |
| 13 | #include "testing/gtest/include/gtest/gtest.h" |
| 14 | |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 15 | #include "webrtc/audio_state.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 16 | #include "webrtc/call.h" |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 17 | #include "webrtc/test/mock_voice_engine.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 18 | |
| 19 | namespace { |
| 20 | |
| 21 | struct CallHelper { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 22 | 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_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 31 | webrtc::Call::Config config; |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 32 | config.audio_state = webrtc::AudioState::Create(audio_state_config); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 33 | call_.reset(webrtc::Call::Create(config)); |
| 34 | } |
| 35 | |
| 36 | webrtc::Call* operator->() { return call_.get(); } |
| 37 | |
| 38 | private: |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 39 | webrtc::test::MockVoiceEngine voice_engine_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 40 | rtc::scoped_ptr<webrtc::Call> call_; |
| 41 | }; |
| 42 | } // namespace |
| 43 | |
| 44 | namespace webrtc { |
| 45 | |
| 46 | TEST(CallTest, ConstructDestruct) { |
| 47 | CallHelper call; |
| 48 | } |
| 49 | |
| 50 | TEST(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 | |
| 60 | TEST(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 | |
| 70 | TEST(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 | |
| 93 | TEST(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 |