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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 1923163003: Replace scoped_ptr with unique_ptr in webrtc/p2p/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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 | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/port.h » ('j') | 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 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 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/p2p/base/p2ptransportchannel.h" 13 #include "webrtc/p2p/base/p2ptransportchannel.h"
12 #include "webrtc/p2p/base/testrelayserver.h" 14 #include "webrtc/p2p/base/testrelayserver.h"
13 #include "webrtc/p2p/base/teststunserver.h" 15 #include "webrtc/p2p/base/teststunserver.h"
14 #include "webrtc/p2p/base/testturnserver.h" 16 #include "webrtc/p2p/base/testturnserver.h"
15 #include "webrtc/p2p/client/basicportallocator.h" 17 #include "webrtc/p2p/client/basicportallocator.h"
16 #include "webrtc/p2p/client/fakeportallocator.h" 18 #include "webrtc/p2p/client/fakeportallocator.h"
17 #include "webrtc/base/dscp.h" 19 #include "webrtc/base/dscp.h"
18 #include "webrtc/base/fakenetwork.h" 20 #include "webrtc/base/fakenetwork.h"
19 #include "webrtc/base/firewallsocketserver.h" 21 #include "webrtc/base/firewallsocketserver.h"
20 #include "webrtc/base/gunit.h" 22 #include "webrtc/base/gunit.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (!ch_packets_.empty()) { 206 if (!ch_packets_.empty()) {
205 std::string packet = ch_packets_.front(); 207 std::string packet = ch_packets_.front();
206 ret = (packet == std::string(data, len)); 208 ret = (packet == std::string(data, len));
207 ch_packets_.pop_front(); 209 ch_packets_.pop_front();
208 } 210 }
209 return ret; 211 return ret;
210 } 212 }
211 213
212 std::string name_; // TODO - Currently not used. 214 std::string name_; // TODO - Currently not used.
213 std::list<std::string> ch_packets_; 215 std::list<std::string> ch_packets_;
214 rtc::scoped_ptr<cricket::P2PTransportChannel> ch_; 216 std::unique_ptr<cricket::P2PTransportChannel> ch_;
215 }; 217 };
216 218
217 struct CandidatesData : public rtc::MessageData { 219 struct CandidatesData : public rtc::MessageData {
218 CandidatesData(cricket::TransportChannel* ch, const cricket::Candidate& c) 220 CandidatesData(cricket::TransportChannel* ch, const cricket::Candidate& c)
219 : channel(ch), candidates(1, c) {} 221 : channel(ch), candidates(1, c) {}
220 CandidatesData(cricket::TransportChannel* ch, 222 CandidatesData(cricket::TransportChannel* ch,
221 const std::vector<cricket::Candidate>& cc) 223 const std::vector<cricket::Candidate>& cc)
222 : channel(ch), candidates(cc) {} 224 : channel(ch), candidates(cc) {}
223 cricket::TransportChannel* channel; 225 cricket::TransportChannel* channel;
224 cricket::Candidates candidates; 226 cricket::Candidates candidates;
(...skipping 23 matching lines...) Expand all
248 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; } 250 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; }
249 bool role_conflict() { return role_conflict_; } 251 bool role_conflict() { return role_conflict_; }
250 void SetAllocationStepDelay(uint32_t delay) { 252 void SetAllocationStepDelay(uint32_t delay) {
251 allocator_->set_step_delay(delay); 253 allocator_->set_step_delay(delay);
252 } 254 }
253 void SetAllowTcpListen(bool allow_tcp_listen) { 255 void SetAllowTcpListen(bool allow_tcp_listen) {
254 allocator_->set_allow_tcp_listen(allow_tcp_listen); 256 allocator_->set_allow_tcp_listen(allow_tcp_listen);
255 } 257 }
256 258
257 rtc::FakeNetworkManager network_manager_; 259 rtc::FakeNetworkManager network_manager_;
258 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; 260 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
259 ChannelData cd1_; 261 ChannelData cd1_;
260 ChannelData cd2_; 262 ChannelData cd2_;
261 cricket::IceRole role_; 263 cricket::IceRole role_;
262 uint64_t tiebreaker_; 264 uint64_t tiebreaker_;
263 bool role_conflict_; 265 bool role_conflict_;
264 bool save_candidates_; 266 bool save_candidates_;
265 std::vector<CandidatesData*> saved_candidates_; 267 std::vector<CandidatesData*> saved_candidates_;
266 }; 268 };
267 269
268 ChannelData* GetChannelData(cricket::TransportChannel* channel) { 270 ChannelData* GetChannelData(cricket::TransportChannel* channel) {
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 for (; it != ed->saved_candidates_.end(); ++it) { 697 for (; it != ed->saved_candidates_.end(); ++it) {
696 main_->Post(this, MSG_ADD_CANDIDATES, *it); 698 main_->Post(this, MSG_ADD_CANDIDATES, *it);
697 } 699 }
698 ed->saved_candidates_.clear(); 700 ed->saved_candidates_.clear();
699 ed->save_candidates_ = false; 701 ed->save_candidates_ = false;
700 } 702 }
701 703
702 void OnMessage(rtc::Message* msg) { 704 void OnMessage(rtc::Message* msg) {
703 switch (msg->message_id) { 705 switch (msg->message_id) {
704 case MSG_ADD_CANDIDATES: { 706 case MSG_ADD_CANDIDATES: {
705 rtc::scoped_ptr<CandidatesData> data( 707 std::unique_ptr<CandidatesData> data(
706 static_cast<CandidatesData*>(msg->pdata)); 708 static_cast<CandidatesData*>(msg->pdata));
707 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); 709 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel);
708 for (auto& c : data->candidates) { 710 for (auto& c : data->candidates) {
709 if (clear_remote_candidates_ufrag_pwd_) { 711 if (clear_remote_candidates_ufrag_pwd_) {
710 c.set_username(""); 712 c.set_username("");
711 c.set_password(""); 713 c.set_password("");
712 } 714 }
713 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" 715 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->"
714 << rch->component() << "): " << c.ToString(); 716 << rch->component() << "): " << c.ToString();
715 rch->AddRemoteCandidate(c); 717 rch->AddRemoteCandidate(c);
716 } 718 }
717 break; 719 break;
718 } 720 }
719 case MSG_REMOVE_CANDIDATES: { 721 case MSG_REMOVE_CANDIDATES: {
720 rtc::scoped_ptr<CandidatesData> data( 722 std::unique_ptr<CandidatesData> data(
721 static_cast<CandidatesData*>(msg->pdata)); 723 static_cast<CandidatesData*>(msg->pdata));
722 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); 724 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel);
723 for (cricket::Candidate& c : data->candidates) { 725 for (cricket::Candidate& c : data->candidates) {
724 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); 726 LOG(LS_INFO) << "Removed remote candidate " << c.ToString();
725 rch->RemoveRemoteCandidate(c); 727 rch->RemoveRemoteCandidate(c);
726 } 728 }
727 break; 729 break;
728 } 730 }
729 } 731 }
730 } 732 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 void set_clear_remote_candidates_ufrag_pwd(bool clear) { 792 void set_clear_remote_candidates_ufrag_pwd(bool clear) {
791 clear_remote_candidates_ufrag_pwd_ = clear; 793 clear_remote_candidates_ufrag_pwd_ = clear;
792 } 794 }
793 795
794 void set_force_relay(bool relay) { 796 void set_force_relay(bool relay) {
795 force_relay_ = relay; 797 force_relay_ = relay;
796 } 798 }
797 799
798 private: 800 private:
799 rtc::Thread* main_; 801 rtc::Thread* main_;
800 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; 802 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
801 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; 803 std::unique_ptr<rtc::VirtualSocketServer> vss_;
802 rtc::scoped_ptr<rtc::NATSocketServer> nss_; 804 std::unique_ptr<rtc::NATSocketServer> nss_;
803 rtc::scoped_ptr<rtc::FirewallSocketServer> ss_; 805 std::unique_ptr<rtc::FirewallSocketServer> ss_;
804 rtc::SocketServerScope ss_scope_; 806 rtc::SocketServerScope ss_scope_;
805 rtc::scoped_ptr<cricket::TestStunServer> stun_server_; 807 std::unique_ptr<cricket::TestStunServer> stun_server_;
806 cricket::TestTurnServer turn_server_; 808 cricket::TestTurnServer turn_server_;
807 cricket::TestRelayServer relay_server_; 809 cricket::TestRelayServer relay_server_;
808 rtc::SocksProxyServer socks_server1_; 810 rtc::SocksProxyServer socks_server1_;
809 rtc::SocksProxyServer socks_server2_; 811 rtc::SocksProxyServer socks_server2_;
810 Endpoint ep1_; 812 Endpoint ep1_;
811 Endpoint ep2_; 813 Endpoint ep2_;
812 bool clear_remote_candidates_ufrag_pwd_; 814 bool clear_remote_candidates_ufrag_pwd_;
813 bool force_relay_; 815 bool force_relay_;
814 }; 816 };
815 817
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 } 1989 }
1988 1990
1989 cricket::CandidatePairInterface* last_selected_candidate_pair() { 1991 cricket::CandidatePairInterface* last_selected_candidate_pair() {
1990 return last_selected_candidate_pair_; 1992 return last_selected_candidate_pair_;
1991 } 1993 }
1992 int last_sent_packet_id() { return last_sent_packet_id_; } 1994 int last_sent_packet_id() { return last_sent_packet_id_; }
1993 bool channel_ready_to_send() { return channel_ready_to_send_; } 1995 bool channel_ready_to_send() { return channel_ready_to_send_; }
1994 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } 1996 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; }
1995 1997
1996 private: 1998 private:
1997 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; 1999 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1998 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; 2000 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1999 rtc::SocketServerScope ss_scope_; 2001 rtc::SocketServerScope ss_scope_;
2000 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; 2002 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr;
2001 int last_sent_packet_id_ = -1; 2003 int last_sent_packet_id_ = -1;
2002 bool channel_ready_to_send_ = false; 2004 bool channel_ready_to_send_ = false;
2003 }; 2005 };
2004 2006
2005 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { 2007 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
2006 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2008 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2007 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); 2009 cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
2008 PrepareChannel(&ch); 2010 PrepareChannel(&ch);
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
2633 cricket::Candidate CreateRelayCandidate(const std::string& ip, 2635 cricket::Candidate CreateRelayCandidate(const std::string& ip,
2634 int port, 2636 int port,
2635 int priority, 2637 int priority,
2636 const std::string& ufrag = "") { 2638 const std::string& ufrag = "") {
2637 cricket::Candidate c = CreateHostCandidate(ip, port, priority, ufrag); 2639 cricket::Candidate c = CreateHostCandidate(ip, port, priority, ufrag);
2638 c.set_type(cricket::RELAY_PORT_TYPE); 2640 c.set_type(cricket::RELAY_PORT_TYPE);
2639 return c; 2641 return c;
2640 } 2642 }
2641 2643
2642 private: 2644 private:
2643 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; 2645 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
2644 rtc::FakeNetworkManager network_manager_; 2646 rtc::FakeNetworkManager network_manager_;
2645 cricket::TestTurnServer turn_server_; 2647 cricket::TestTurnServer turn_server_;
2646 rtc::scoped_ptr<cricket::P2PTransportChannel> channel_; 2648 std::unique_ptr<cricket::P2PTransportChannel> channel_;
2647 }; 2649 };
2648 2650
2649 // Test that Relay/Relay connections will be pinged first when no other 2651 // Test that Relay/Relay connections will be pinged first when no other
2650 // connections have been pinged yet, unless we need to ping a trigger check or 2652 // connections have been pinged yet, unless we need to ping a trigger check or
2651 // we have a best connection. 2653 // we have a best connection.
2652 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 2654 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
2653 TestRelayRelayFirstWhenNothingPingedYet) { 2655 TestRelayRelayFirstWhenNothingPingedYet) {
2654 const int max_strong_interval = 100; 2656 const int max_strong_interval = 100;
2655 cricket::P2PTransportChannel& ch = 2657 cricket::P2PTransportChannel& ch =
2656 StartTransportChannel(true, max_strong_interval); 2658 StartTransportChannel(true, max_strong_interval);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2795 2797
2796 // TCP Relay/Relay is the next. 2798 // TCP Relay/Relay is the next.
2797 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, 2799 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
2798 cricket::RELAY_PORT_TYPE, 2800 cricket::RELAY_PORT_TYPE,
2799 cricket::TCP_PROTOCOL_NAME); 2801 cricket::TCP_PROTOCOL_NAME);
2800 2802
2801 // Finally, Local/Relay will be pinged. 2803 // Finally, Local/Relay will be pinged.
2802 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, 2804 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
2803 cricket::RELAY_PORT_TYPE); 2805 cricket::RELAY_PORT_TYPE);
2804 } 2806 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.h ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698