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

Side by Side Diff: webrtc/pc/channelmanager_unittest.cc

Issue 2685093002: Switching some interfaces to use std::unique_ptr<>. (Closed)
Patch Set: Rebase onto master Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright 2008 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2008 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory>
12
11 #include "webrtc/base/gunit.h" 13 #include "webrtc/base/gunit.h"
12 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
13 #include "webrtc/base/thread.h" 15 #include "webrtc/base/thread.h"
14 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 16 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
15 #include "webrtc/media/base/fakemediaengine.h" 17 #include "webrtc/media/base/fakemediaengine.h"
16 #include "webrtc/media/base/fakevideocapturer.h" 18 #include "webrtc/media/base/fakevideocapturer.h"
17 #include "webrtc/media/base/testutils.h" 19 #include "webrtc/media/base/testutils.h"
18 #include "webrtc/media/engine/fakewebrtccall.h" 20 #include "webrtc/media/engine/fakewebrtccall.h"
19 #include "webrtc/p2p/base/faketransportcontroller.h" 21 #include "webrtc/p2p/base/faketransportcontroller.h"
20 #include "webrtc/pc/channelmanager.h" 22 #include "webrtc/pc/channelmanager.h"
(...skipping 12 matching lines...) Expand all
33 35
34 static const VideoCodec kVideoCodecs[] = { 36 static const VideoCodec kVideoCodecs[] = {
35 VideoCodec(99, "H264"), VideoCodec(100, "VP8"), VideoCodec(96, "rtx"), 37 VideoCodec(99, "H264"), VideoCodec(100, "VP8"), VideoCodec(96, "rtx"),
36 }; 38 };
37 39
38 class ChannelManagerTest : public testing::Test { 40 class ChannelManagerTest : public testing::Test {
39 protected: 41 protected:
40 ChannelManagerTest() 42 ChannelManagerTest()
41 : fme_(new cricket::FakeMediaEngine()), 43 : fme_(new cricket::FakeMediaEngine()),
42 fdme_(new cricket::FakeDataEngine()), 44 fdme_(new cricket::FakeDataEngine()),
43 cm_(new cricket::ChannelManager(fme_, fdme_, rtc::Thread::Current())), 45 cm_(new cricket::ChannelManager(
46 std::unique_ptr<MediaEngineInterface>(fme_),
47 std::unique_ptr<DataEngineInterface>(fdme_),
48 rtc::Thread::Current())),
44 fake_call_(webrtc::Call::Config(&event_log_)), 49 fake_call_(webrtc::Call::Config(&event_log_)),
45 fake_mc_(cm_, &fake_call_), 50 fake_mc_(cm_.get(), &fake_call_),
46 transport_controller_( 51 transport_controller_(
47 new cricket::FakeTransportController(ICEROLE_CONTROLLING)) {} 52 new cricket::FakeTransportController(ICEROLE_CONTROLLING)) {
48
49 virtual void SetUp() {
50 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); 53 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
51 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); 54 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
52 } 55 }
53 56
54 virtual void TearDown() {
55 delete transport_controller_;
56 delete cm_;
57 cm_ = NULL;
58 fdme_ = NULL;
59 fme_ = NULL;
60 }
61
62 webrtc::RtcEventLogNullImpl event_log_; 57 webrtc::RtcEventLogNullImpl event_log_;
63 rtc::Thread network_; 58 rtc::Thread network_;
64 rtc::Thread worker_; 59 rtc::Thread worker_;
60 // |fme_| and |fdme_| are actually owned by |cm_|.
65 cricket::FakeMediaEngine* fme_; 61 cricket::FakeMediaEngine* fme_;
66 cricket::FakeDataEngine* fdme_; 62 cricket::FakeDataEngine* fdme_;
67 cricket::ChannelManager* cm_; 63 std::unique_ptr<cricket::ChannelManager> cm_;
68 cricket::FakeCall fake_call_; 64 cricket::FakeCall fake_call_;
69 cricket::FakeMediaController fake_mc_; 65 cricket::FakeMediaController fake_mc_;
70 cricket::FakeTransportController* transport_controller_; 66 std::unique_ptr<cricket::FakeTransportController> transport_controller_;
71 }; 67 };
72 68
73 // Test that we startup/shutdown properly. 69 // Test that we startup/shutdown properly.
74 TEST_F(ChannelManagerTest, StartupShutdown) { 70 TEST_F(ChannelManagerTest, StartupShutdown) {
75 EXPECT_FALSE(cm_->initialized()); 71 EXPECT_FALSE(cm_->initialized());
76 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); 72 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
77 EXPECT_TRUE(cm_->Init()); 73 EXPECT_TRUE(cm_->Init());
78 EXPECT_TRUE(cm_->initialized()); 74 EXPECT_TRUE(cm_->initialized());
79 cm_->Terminate(); 75 cm_->Terminate();
80 EXPECT_FALSE(cm_->initialized()); 76 EXPECT_FALSE(cm_->initialized());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 cm_->Terminate(); 122 cm_->Terminate();
127 } 123 }
128 124
129 // Test that we can create and destroy a voice and video channel with a worker. 125 // Test that we can create and destroy a voice and video channel with a worker.
130 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { 126 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) {
131 network_.Start(); 127 network_.Start();
132 worker_.Start(); 128 worker_.Start();
133 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); 129 EXPECT_TRUE(cm_->set_worker_thread(&worker_));
134 EXPECT_TRUE(cm_->set_network_thread(&network_)); 130 EXPECT_TRUE(cm_->set_network_thread(&network_));
135 EXPECT_TRUE(cm_->Init()); 131 EXPECT_TRUE(cm_->Init());
136 delete transport_controller_; 132 transport_controller_.reset(
137 transport_controller_ = 133 new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING));
138 new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING);
139 cricket::DtlsTransportInternal* rtp_transport = 134 cricket::DtlsTransportInternal* rtp_transport =
140 transport_controller_->CreateDtlsTransport( 135 transport_controller_->CreateDtlsTransport(
141 cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); 136 cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP);
142 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( 137 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
143 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, 138 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/,
144 rtc::Thread::Current(), cricket::CN_AUDIO, nullptr, 139 rtc::Thread::Current(), cricket::CN_AUDIO, nullptr,
145 kDefaultRtcpMuxRequired, kDefaultSrtpRequired, AudioOptions()); 140 kDefaultRtcpMuxRequired, kDefaultSrtpRequired, AudioOptions());
146 EXPECT_TRUE(voice_channel != nullptr); 141 EXPECT_TRUE(voice_channel != nullptr);
147 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( 142 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
148 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/, 143 &fake_mc_, rtp_transport, nullptr /*rtcp_transport*/,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); 179 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false));
185 180
186 // Can set again after terminate. 181 // Can set again after terminate.
187 cm_->Terminate(); 182 cm_->Terminate();
188 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); 183 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
189 cm_->GetSupportedVideoCodecs(&codecs); 184 cm_->GetSupportedVideoCodecs(&codecs);
190 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); 185 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
191 } 186 }
192 187
193 } // namespace cricket 188 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698