OLD | NEW |
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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 using cricket::ICE_UFRAG_LENGTH; | 24 using cricket::ICE_UFRAG_LENGTH; |
25 using cricket::ICE_PWD_LENGTH; | 25 using cricket::ICE_PWD_LENGTH; |
26 | 26 |
27 static int kTimeout = 1000; | 27 static int kTimeout = 1000; |
28 static const SocketAddress kLocalAddr("11.11.11.11", 1); | 28 static const SocketAddress kLocalAddr("11.11.11.11", 1); |
29 static const SocketAddress kRemoteAddr("22.22.22.22", 2); | 29 static const SocketAddress kRemoteAddr("22.22.22.22", 2); |
30 | 30 |
31 class TCPPortTest : public testing::Test, public sigslot::has_slots<> { | 31 class TCPPortTest : public testing::Test, public sigslot::has_slots<> { |
32 public: | 32 public: |
33 TCPPortTest() | 33 TCPPortTest() |
34 : main_(rtc::Thread::Current()), | 34 : pss_(new rtc::PhysicalSocketServer), |
35 pss_(new rtc::PhysicalSocketServer), | |
36 ss_(new rtc::VirtualSocketServer(pss_.get())), | 35 ss_(new rtc::VirtualSocketServer(pss_.get())), |
37 ss_scope_(ss_.get()), | 36 main_(ss_.get()), |
38 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), | 37 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), |
39 socket_factory_(rtc::Thread::Current()), | 38 socket_factory_(rtc::Thread::Current()), |
40 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), | 39 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), |
41 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)) { | 40 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)) { |
42 network_.AddIP(rtc::IPAddress(INADDR_ANY)); | 41 network_.AddIP(rtc::IPAddress(INADDR_ANY)); |
43 } | 42 } |
44 | 43 |
45 void ConnectSignalSocketCreated() { | 44 void ConnectSignalSocketCreated() { |
46 ss_->SignalSocketCreated.connect(this, &TCPPortTest::OnSocketCreated); | 45 ss_->SignalSocketCreated.connect(this, &TCPPortTest::OnSocketCreated); |
47 } | 46 } |
48 | 47 |
49 void OnSocketCreated(rtc::VirtualSocket* socket) { | 48 void OnSocketCreated(rtc::VirtualSocket* socket) { |
50 LOG(LS_INFO) << "socket created "; | 49 LOG(LS_INFO) << "socket created "; |
51 socket->SignalAddressReady.connect( | 50 socket->SignalAddressReady.connect( |
52 this, &TCPPortTest::SetLocalhostAsAlternativeLocalAddress); | 51 this, &TCPPortTest::SetLocalhostAsAlternativeLocalAddress); |
53 } | 52 } |
54 | 53 |
55 void SetLocalhostAsAlternativeLocalAddress(rtc::VirtualSocket* socket, | 54 void SetLocalhostAsAlternativeLocalAddress(rtc::VirtualSocket* socket, |
56 const SocketAddress& address) { | 55 const SocketAddress& address) { |
57 SocketAddress local_address("127.0.0.1", 2000); | 56 SocketAddress local_address("127.0.0.1", 2000); |
58 socket->SetAlternativeLocalAddress(local_address); | 57 socket->SetAlternativeLocalAddress(local_address); |
59 } | 58 } |
60 | 59 |
61 TCPPort* CreateTCPPort(const SocketAddress& addr) { | 60 TCPPort* CreateTCPPort(const SocketAddress& addr) { |
62 return TCPPort::Create(main_, &socket_factory_, &network_, addr.ipaddr(), 0, | 61 return TCPPort::Create(&main_, &socket_factory_, &network_, addr.ipaddr(), |
63 0, username_, password_, true); | 62 0, 0, username_, password_, true); |
64 } | 63 } |
65 | 64 |
66 protected: | 65 protected: |
67 rtc::Thread* main_; | |
68 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 66 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
69 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 67 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
70 rtc::SocketServerScope ss_scope_; | 68 rtc::AutoSocketServerThread main_; |
71 rtc::Network network_; | 69 rtc::Network network_; |
72 rtc::BasicPacketSocketFactory socket_factory_; | 70 rtc::BasicPacketSocketFactory socket_factory_; |
73 std::string username_; | 71 std::string username_; |
74 std::string password_; | 72 std::string password_; |
75 }; | 73 }; |
76 | 74 |
77 TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) { | 75 TEST_F(TCPPortTest, TestTCPPortWithLocalhostAddress) { |
78 std::unique_ptr<TCPPort> lport(CreateTCPPort(kLocalAddr)); | 76 std::unique_ptr<TCPPort> lport(CreateTCPPort(kLocalAddr)); |
79 std::unique_ptr<TCPPort> rport(CreateTCPPort(kRemoteAddr)); | 77 std::unique_ptr<TCPPort> rport(CreateTCPPort(kRemoteAddr)); |
80 lport->PrepareAddress(); | 78 lport->PrepareAddress(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 SentPacketCounter client_counter(client.get()); | 131 SentPacketCounter client_counter(client.get()); |
134 SentPacketCounter server_counter(server.get()); | 132 SentPacketCounter server_counter(server.get()); |
135 static const char kData[] = "hello"; | 133 static const char kData[] = "hello"; |
136 for (int i = 0; i < 10; ++i) { | 134 for (int i = 0; i < 10; ++i) { |
137 client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()); | 135 client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()); |
138 server_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()); | 136 server_conn->Send(&kData, sizeof(kData), rtc::PacketOptions()); |
139 } | 137 } |
140 EXPECT_EQ_WAIT(10, client_counter.sent_packets(), kTimeout); | 138 EXPECT_EQ_WAIT(10, client_counter.sent_packets(), kTimeout); |
141 EXPECT_EQ_WAIT(10, server_counter.sent_packets(), kTimeout); | 139 EXPECT_EQ_WAIT(10, server_counter.sent_packets(), kTimeout); |
142 } | 140 } |
OLD | NEW |