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

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

Issue 2883313003: Remove VirtualSocketServer's dependency on PhysicalSocketServer. (Closed)
Patch Set: Created 3 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/stunserver_unittest.cc ('k') | webrtc/p2p/base/turnport_unittest.cc » ('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 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 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> 11 #include <memory>
12 12
13 #include "webrtc/base/gunit.h" 13 #include "webrtc/base/gunit.h"
14 #include "webrtc/base/physicalsocketserver.h"
15 #include "webrtc/base/thread.h" 14 #include "webrtc/base/thread.h"
16 #include "webrtc/base/virtualsocketserver.h" 15 #include "webrtc/base/virtualsocketserver.h"
17 #include "webrtc/p2p/base/basicpacketsocketfactory.h" 16 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
18 #include "webrtc/p2p/base/tcpport.h" 17 #include "webrtc/p2p/base/tcpport.h"
19 18
20 using rtc::SocketAddress; 19 using rtc::SocketAddress;
21 using cricket::Connection; 20 using cricket::Connection;
22 using cricket::Port; 21 using cricket::Port;
23 using cricket::TCPPort; 22 using cricket::TCPPort;
24 using cricket::ICE_UFRAG_LENGTH; 23 using cricket::ICE_UFRAG_LENGTH;
25 using cricket::ICE_PWD_LENGTH; 24 using cricket::ICE_PWD_LENGTH;
26 25
27 static int kTimeout = 1000; 26 static int kTimeout = 1000;
28 static const SocketAddress kLocalAddr("11.11.11.11", 1); 27 static const SocketAddress kLocalAddr("11.11.11.11", 1);
29 static const SocketAddress kRemoteAddr("22.22.22.22", 2); 28 static const SocketAddress kRemoteAddr("22.22.22.22", 2);
30 29
31 class TCPPortTest : public testing::Test, public sigslot::has_slots<> { 30 class TCPPortTest : public testing::Test, public sigslot::has_slots<> {
32 public: 31 public:
33 TCPPortTest() 32 TCPPortTest()
34 : pss_(new rtc::PhysicalSocketServer), 33 : ss_(new rtc::VirtualSocketServer()),
35 ss_(new rtc::VirtualSocketServer(pss_.get())),
36 main_(ss_.get()), 34 main_(ss_.get()),
37 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), 35 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32),
38 socket_factory_(rtc::Thread::Current()), 36 socket_factory_(rtc::Thread::Current()),
39 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), 37 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)),
40 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)) { 38 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)) {
41 network_.AddIP(rtc::IPAddress(INADDR_ANY)); 39 network_.AddIP(rtc::IPAddress(INADDR_ANY));
42 } 40 }
43 41
44 void ConnectSignalSocketCreated() { 42 void ConnectSignalSocketCreated() {
45 ss_->SignalSocketCreated.connect(this, &TCPPortTest::OnSocketCreated); 43 ss_->SignalSocketCreated.connect(this, &TCPPortTest::OnSocketCreated);
(...skipping 10 matching lines...) Expand all
56 SocketAddress local_address("127.0.0.1", 2000); 54 SocketAddress local_address("127.0.0.1", 2000);
57 socket->SetAlternativeLocalAddress(local_address); 55 socket->SetAlternativeLocalAddress(local_address);
58 } 56 }
59 57
60 TCPPort* CreateTCPPort(const SocketAddress& addr) { 58 TCPPort* CreateTCPPort(const SocketAddress& addr) {
61 return TCPPort::Create(&main_, &socket_factory_, &network_, addr.ipaddr(), 59 return TCPPort::Create(&main_, &socket_factory_, &network_, addr.ipaddr(),
62 0, 0, username_, password_, true); 60 0, 0, username_, password_, true);
63 } 61 }
64 62
65 protected: 63 protected:
66 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
67 std::unique_ptr<rtc::VirtualSocketServer> ss_; 64 std::unique_ptr<rtc::VirtualSocketServer> ss_;
68 rtc::AutoSocketServerThread main_; 65 rtc::AutoSocketServerThread main_;
69 rtc::Network network_; 66 rtc::Network network_;
70 rtc::BasicPacketSocketFactory socket_factory_; 67 rtc::BasicPacketSocketFactory socket_factory_;
71 std::string username_; 68 std::string username_;
72 std::string password_; 69 std::string password_;
73 }; 70 };
74 71
75 TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) { 72 TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) {
76 std::unique_ptr<TCPPort> lport(CreateTCPPort(kLocalAddr)); 73 std::unique_ptr<TCPPort> lport(CreateTCPPort(kLocalAddr));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 SentPacketCounter client_counter(client.get()); 128 SentPacketCounter client_counter(client.get());
132 SentPacketCounter server_counter(server.get()); 129 SentPacketCounter server_counter(server.get());
133 static const char kData[] = "hello"; 130 static const char kData[] = "hello";
134 for (int i = 0; i < 10; ++i) { 131 for (int i = 0; i < 10; ++i) {
135 client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()); 132 client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
136 server_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()); 133 server_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
137 } 134 }
138 EXPECT_EQ_WAIT(10, client_counter.sent_packets(), kTimeout); 135 EXPECT_EQ_WAIT(10, client_counter.sent_packets(), kTimeout);
139 EXPECT_EQ_WAIT(10, server_counter.sent_packets(), kTimeout); 136 EXPECT_EQ_WAIT(10, server_counter.sent_packets(), kTimeout);
140 } 137 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/stunserver_unittest.cc ('k') | webrtc/p2p/base/turnport_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698