Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: talk/session/media/channelmanager_unittest.cc

Issue 1269863005: MediaController/Call instantiation. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove redundant reset(nullptr) Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/session/media/channelmanager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2008 Google Inc. 3 * Copyright 2008 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation 11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution. 12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products 13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/app/webrtc/mediacontroller.h"
28 #include "talk/media/base/fakecapturemanager.h" 29 #include "talk/media/base/fakecapturemanager.h"
29 #include "talk/media/base/fakemediaengine.h" 30 #include "talk/media/base/fakemediaengine.h"
30 #include "talk/media/base/fakemediaprocessor.h" 31 #include "talk/media/base/fakemediaprocessor.h"
31 #include "talk/media/base/testutils.h" 32 #include "talk/media/base/testutils.h"
32 #include "talk/media/devices/fakedevicemanager.h" 33 #include "talk/media/devices/fakedevicemanager.h"
34 #include "talk/media/webrtc/fakewebrtccall.h"
33 #include "webrtc/p2p/base/fakesession.h" 35 #include "webrtc/p2p/base/fakesession.h"
34 #include "talk/session/media/channelmanager.h" 36 #include "talk/session/media/channelmanager.h"
35 #include "webrtc/base/gunit.h" 37 #include "webrtc/base/gunit.h"
36 #include "webrtc/base/logging.h" 38 #include "webrtc/base/logging.h"
37 #include "webrtc/base/thread.h" 39 #include "webrtc/base/thread.h"
38 40
39 namespace cricket { 41 namespace cricket {
40 42
41 static const AudioCodec kAudioCodecs[] = { 43 static const AudioCodec kAudioCodecs[] = {
42 AudioCodec(97, "voice", 1, 2, 3, 0), 44 AudioCodec(97, "voice", 1, 2, 3, 0),
43 AudioCodec(111, "OPUS", 48000, 32000, 2, 0), 45 AudioCodec(111, "OPUS", 48000, 32000, 2, 0),
44 }; 46 };
45 47
46 static const VideoCodec kVideoCodecs[] = { 48 static const VideoCodec kVideoCodecs[] = {
47 VideoCodec(99, "H264", 100, 200, 300, 0), 49 VideoCodec(99, "H264", 100, 200, 300, 0),
48 VideoCodec(100, "VP8", 100, 200, 300, 0), 50 VideoCodec(100, "VP8", 100, 200, 300, 0),
49 VideoCodec(96, "rtx", 100, 200, 300, 0), 51 VideoCodec(96, "rtx", 100, 200, 300, 0),
50 }; 52 };
51 53
54 class FakeMediaController : public webrtc::MediaControllerInterface {
55 public:
56 explicit FakeMediaController(webrtc::Call* call) : call_(call) {
57 DCHECK(nullptr != call);
58 }
59 ~FakeMediaController() override {}
60 webrtc::Call* call_w() override { return call_; }
61 private:
62 webrtc::Call* call_;
63 };
64
52 class ChannelManagerTest : public testing::Test { 65 class ChannelManagerTest : public testing::Test {
53 protected: 66 protected:
54 ChannelManagerTest() : fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) { 67 ChannelManagerTest() : fake_call_(webrtc::Call::Config()),
55 } 68 fake_mc_(&fake_call_), fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) {}
56 69
57 virtual void SetUp() { 70 virtual void SetUp() {
58 fme_ = new cricket::FakeMediaEngine(); 71 fme_ = new cricket::FakeMediaEngine();
59 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); 72 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
60 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); 73 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
61 fdme_ = new cricket::FakeDataEngine(); 74 fdme_ = new cricket::FakeDataEngine();
62 fdm_ = new cricket::FakeDeviceManager(); 75 fdm_ = new cricket::FakeDeviceManager();
63 fcm_ = new cricket::FakeCaptureManager(); 76 fcm_ = new cricket::FakeCaptureManager();
64 cm_ = new cricket::ChannelManager( 77 cm_ = new cricket::ChannelManager(
65 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current()); 78 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current());
(...skipping 15 matching lines...) Expand all
81 delete session_; 94 delete session_;
82 delete cm_; 95 delete cm_;
83 cm_ = NULL; 96 cm_ = NULL;
84 fdm_ = NULL; 97 fdm_ = NULL;
85 fcm_ = NULL; 98 fcm_ = NULL;
86 fdme_ = NULL; 99 fdme_ = NULL;
87 fme_ = NULL; 100 fme_ = NULL;
88 } 101 }
89 102
90 rtc::Thread worker_; 103 rtc::Thread worker_;
104 cricket::FakeCall fake_call_;
105 cricket::FakeMediaController fake_mc_;
91 cricket::FakeMediaEngine* fme_; 106 cricket::FakeMediaEngine* fme_;
92 cricket::FakeDataEngine* fdme_; 107 cricket::FakeDataEngine* fdme_;
93 cricket::FakeDeviceManager* fdm_; 108 cricket::FakeDeviceManager* fdm_;
94 cricket::FakeCaptureManager* fcm_; 109 cricket::FakeCaptureManager* fcm_;
95 cricket::ChannelManager* cm_; 110 cricket::ChannelManager* cm_;
96 cricket::FakeSession* session_; 111 cricket::FakeSession* session_;
97 }; 112 };
98 113
99 // Test that we startup/shutdown properly. 114 // Test that we startup/shutdown properly.
100 TEST_F(ChannelManagerTest, StartupShutdown) { 115 TEST_F(ChannelManagerTest, StartupShutdown) {
(...skipping 17 matching lines...) Expand all
118 // Setting the worker thread while initialized should fail. 133 // Setting the worker thread while initialized should fail.
119 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); 134 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current()));
120 cm_->Terminate(); 135 cm_->Terminate();
121 EXPECT_FALSE(cm_->initialized()); 136 EXPECT_FALSE(cm_->initialized());
122 } 137 }
123 138
124 // Test that we can create and destroy a voice and video channel. 139 // Test that we can create and destroy a voice and video channel.
125 TEST_F(ChannelManagerTest, CreateDestroyChannels) { 140 TEST_F(ChannelManagerTest, CreateDestroyChannels) {
126 EXPECT_TRUE(cm_->Init()); 141 EXPECT_TRUE(cm_->Init());
127 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( 142 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
128 session_, cricket::CN_AUDIO, false, AudioOptions()); 143 &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions());
129 EXPECT_TRUE(voice_channel != nullptr); 144 EXPECT_TRUE(voice_channel != nullptr);
130 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( 145 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
131 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); 146 &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions());
132 EXPECT_TRUE(video_channel != nullptr); 147 EXPECT_TRUE(video_channel != nullptr);
133 cricket::DataChannel* data_channel = 148 cricket::DataChannel* data_channel =
134 cm_->CreateDataChannel(session_, cricket::CN_DATA, 149 cm_->CreateDataChannel(session_, cricket::CN_DATA,
135 false, cricket::DCT_RTP); 150 false, cricket::DCT_RTP);
136 EXPECT_TRUE(data_channel != nullptr); 151 EXPECT_TRUE(data_channel != nullptr);
137 cm_->DestroyVideoChannel(video_channel); 152 cm_->DestroyVideoChannel(video_channel);
138 cm_->DestroyVoiceChannel(voice_channel, nullptr); 153 cm_->DestroyVoiceChannel(voice_channel);
139 cm_->DestroyDataChannel(data_channel); 154 cm_->DestroyDataChannel(data_channel);
140 cm_->Terminate(); 155 cm_->Terminate();
141 } 156 }
142 157
143 // Test that we can create and destroy a voice and video channel with a worker. 158 // Test that we can create and destroy a voice and video channel with a worker.
144 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { 159 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) {
145 worker_.Start(); 160 worker_.Start();
146 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); 161 EXPECT_TRUE(cm_->set_worker_thread(&worker_));
147 EXPECT_TRUE(cm_->Init()); 162 EXPECT_TRUE(cm_->Init());
148 delete session_; 163 delete session_;
149 session_ = new cricket::FakeSession(&worker_, true); 164 session_ = new cricket::FakeSession(&worker_, true);
150 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( 165 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
151 session_, cricket::CN_AUDIO, false, AudioOptions()); 166 &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions());
152 EXPECT_TRUE(voice_channel != nullptr); 167 EXPECT_TRUE(voice_channel != nullptr);
153 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( 168 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
154 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); 169 &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions());
155 EXPECT_TRUE(video_channel != nullptr); 170 EXPECT_TRUE(video_channel != nullptr);
156 cricket::DataChannel* data_channel = 171 cricket::DataChannel* data_channel =
157 cm_->CreateDataChannel(session_, cricket::CN_DATA, 172 cm_->CreateDataChannel(session_, cricket::CN_DATA,
158 false, cricket::DCT_RTP); 173 false, cricket::DCT_RTP);
159 EXPECT_TRUE(data_channel != nullptr); 174 EXPECT_TRUE(data_channel != nullptr);
160 cm_->DestroyVideoChannel(video_channel); 175 cm_->DestroyVideoChannel(video_channel);
161 cm_->DestroyVoiceChannel(voice_channel, nullptr); 176 cm_->DestroyVoiceChannel(voice_channel);
162 cm_->DestroyDataChannel(data_channel); 177 cm_->DestroyDataChannel(data_channel);
163 cm_->Terminate(); 178 cm_->Terminate();
164 } 179 }
165 180
166 // Test that we fail to create a voice/video channel if the session is unable 181 // Test that we fail to create a voice/video channel if the session is unable
167 // to create a cricket::TransportChannel 182 // to create a cricket::TransportChannel
168 TEST_F(ChannelManagerTest, NoTransportChannelTest) { 183 TEST_F(ChannelManagerTest, NoTransportChannelTest) {
169 EXPECT_TRUE(cm_->Init()); 184 EXPECT_TRUE(cm_->Init());
170 session_->set_fail_channel_creation(true); 185 session_->set_fail_channel_creation(true);
171 // The test is useless unless the session does not fail creating 186 // The test is useless unless the session does not fail creating
172 // cricket::TransportChannel. 187 // cricket::TransportChannel.
173 ASSERT_TRUE(session_->CreateChannel( 188 ASSERT_TRUE(session_->CreateChannel(
174 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); 189 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr);
175 190
176 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( 191 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
177 session_, cricket::CN_AUDIO, false, AudioOptions()); 192 &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions());
178 EXPECT_TRUE(voice_channel == nullptr); 193 EXPECT_TRUE(voice_channel == nullptr);
179 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( 194 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
180 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); 195 &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions());
181 EXPECT_TRUE(video_channel == nullptr); 196 EXPECT_TRUE(video_channel == nullptr);
182 cricket::DataChannel* data_channel = 197 cricket::DataChannel* data_channel =
183 cm_->CreateDataChannel(session_, cricket::CN_DATA, 198 cm_->CreateDataChannel(session_, cricket::CN_DATA,
184 false, cricket::DCT_RTP); 199 false, cricket::DCT_RTP);
185 EXPECT_TRUE(data_channel == nullptr); 200 EXPECT_TRUE(data_channel == nullptr);
186 cm_->Terminate(); 201 cm_->Terminate();
187 } 202 }
188 203
189 // Test that SetDefaultVideoCodec passes through the right values. 204 // Test that SetDefaultVideoCodec passes through the right values.
190 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { 205 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) {
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); 592 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false));
578 593
579 // Can set again after terminate. 594 // Can set again after terminate.
580 cm_->Terminate(); 595 cm_->Terminate();
581 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); 596 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
582 cm_->GetSupportedVideoCodecs(&codecs); 597 cm_->GetSupportedVideoCodecs(&codecs);
583 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); 598 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
584 } 599 }
585 600
586 } // namespace cricket 601 } // namespace cricket
OLDNEW
« no previous file with comments | « talk/session/media/channelmanager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698