OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 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 #if defined(WEBRTC_POSIX) | 10 #if defined(WEBRTC_POSIX) |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "webrtc/p2p/base/udpport.h" | 22 #include "webrtc/p2p/base/udpport.h" |
23 #include "webrtc/base/asynctcpsocket.h" | 23 #include "webrtc/base/asynctcpsocket.h" |
24 #include "webrtc/base/buffer.h" | 24 #include "webrtc/base/buffer.h" |
25 #include "webrtc/base/checks.h" | 25 #include "webrtc/base/checks.h" |
26 #include "webrtc/base/dscp.h" | 26 #include "webrtc/base/dscp.h" |
27 #include "webrtc/base/fakeclock.h" | 27 #include "webrtc/base/fakeclock.h" |
28 #include "webrtc/base/firewallsocketserver.h" | 28 #include "webrtc/base/firewallsocketserver.h" |
29 #include "webrtc/base/gunit.h" | 29 #include "webrtc/base/gunit.h" |
30 #include "webrtc/base/helpers.h" | 30 #include "webrtc/base/helpers.h" |
31 #include "webrtc/base/logging.h" | 31 #include "webrtc/base/logging.h" |
32 #include "webrtc/base/physicalsocketserver.h" | |
33 #include "webrtc/base/socketadapters.h" | 32 #include "webrtc/base/socketadapters.h" |
34 #include "webrtc/base/socketaddress.h" | 33 #include "webrtc/base/socketaddress.h" |
35 #include "webrtc/base/ssladapter.h" | 34 #include "webrtc/base/ssladapter.h" |
36 #include "webrtc/base/thread.h" | 35 #include "webrtc/base/thread.h" |
37 #include "webrtc/base/virtualsocketserver.h" | 36 #include "webrtc/base/virtualsocketserver.h" |
38 | 37 |
39 using rtc::SocketAddress; | 38 using rtc::SocketAddress; |
40 | 39 |
41 static const SocketAddress kLocalAddr1("11.11.11.11", 0); | 40 static const SocketAddress kLocalAddr1("11.11.11.11", 0); |
42 static const SocketAddress kLocalAddr2("22.22.22.22", 0); | 41 static const SocketAddress kLocalAddr2("22.22.22.22", 0); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 99 } |
101 closedir(dir); | 100 closedir(dir); |
102 return fd_count; | 101 return fd_count; |
103 } | 102 } |
104 #endif | 103 #endif |
105 | 104 |
106 namespace cricket { | 105 namespace cricket { |
107 | 106 |
108 class TurnPortTestVirtualSocketServer : public rtc::VirtualSocketServer { | 107 class TurnPortTestVirtualSocketServer : public rtc::VirtualSocketServer { |
109 public: | 108 public: |
110 explicit TurnPortTestVirtualSocketServer(SocketServer* ss) | 109 TurnPortTestVirtualSocketServer() { |
111 : VirtualSocketServer(ss) { | |
112 // This configures the virtual socket server to always add a simulated | 110 // This configures the virtual socket server to always add a simulated |
113 // delay of exactly half of kSimulatedRtt. | 111 // delay of exactly half of kSimulatedRtt. |
114 set_delay_mean(kSimulatedRtt / 2); | 112 set_delay_mean(kSimulatedRtt / 2); |
115 UpdateDelayDistribution(); | 113 UpdateDelayDistribution(); |
116 } | 114 } |
117 | 115 |
118 using rtc::VirtualSocketServer::LookupBinding; | 116 using rtc::VirtualSocketServer::LookupBinding; |
119 }; | 117 }; |
120 | 118 |
121 class TestConnectionWrapper : public sigslot::has_slots<> { | 119 class TestConnectionWrapper : public sigslot::has_slots<> { |
(...skipping 14 matching lines...) Expand all Loading... |
136 Connection* connection_; | 134 Connection* connection_; |
137 }; | 135 }; |
138 | 136 |
139 // Note: This test uses a fake clock with a simulated network round trip | 137 // Note: This test uses a fake clock with a simulated network round trip |
140 // (between local port and TURN server) of kSimulatedRtt. | 138 // (between local port and TURN server) of kSimulatedRtt. |
141 class TurnPortTest : public testing::Test, | 139 class TurnPortTest : public testing::Test, |
142 public sigslot::has_slots<>, | 140 public sigslot::has_slots<>, |
143 public rtc::MessageHandler { | 141 public rtc::MessageHandler { |
144 public: | 142 public: |
145 TurnPortTest() | 143 TurnPortTest() |
146 : pss_(new rtc::PhysicalSocketServer), | 144 : ss_(new TurnPortTestVirtualSocketServer()), |
147 ss_(new TurnPortTestVirtualSocketServer(pss_.get())), | |
148 main_(ss_.get()), | 145 main_(ss_.get()), |
149 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), | 146 network_("unittest", "unittest", rtc::IPAddress(INADDR_ANY), 32), |
150 socket_factory_(rtc::Thread::Current()), | 147 socket_factory_(rtc::Thread::Current()), |
151 turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr), | 148 turn_server_(&main_, kTurnUdpIntAddr, kTurnUdpExtAddr), |
152 turn_ready_(false), | 149 turn_ready_(false), |
153 turn_error_(false), | 150 turn_error_(false), |
154 turn_unknown_address_(false), | 151 turn_unknown_address_(false), |
155 turn_create_permission_success_(false), | 152 turn_create_permission_success_(false), |
156 udp_ready_(false), | 153 udp_ready_(false), |
157 test_finish_(false) { | 154 test_finish_(false) { |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 ASSERT_EQ(num_packets, udp_packets_.size()); | 609 ASSERT_EQ(num_packets, udp_packets_.size()); |
613 for (size_t i = 0; i < num_packets; ++i) { | 610 for (size_t i = 0; i < num_packets; ++i) { |
614 EXPECT_EQ(i + 1, turn_packets_[i].size()); | 611 EXPECT_EQ(i + 1, turn_packets_[i].size()); |
615 EXPECT_EQ(i + 1, udp_packets_[i].size()); | 612 EXPECT_EQ(i + 1, udp_packets_[i].size()); |
616 EXPECT_EQ(turn_packets_[i], udp_packets_[i]); | 613 EXPECT_EQ(turn_packets_[i], udp_packets_[i]); |
617 } | 614 } |
618 } | 615 } |
619 | 616 |
620 protected: | 617 protected: |
621 rtc::ScopedFakeClock fake_clock_; | 618 rtc::ScopedFakeClock fake_clock_; |
622 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | |
623 std::unique_ptr<TurnPortTestVirtualSocketServer> ss_; | 619 std::unique_ptr<TurnPortTestVirtualSocketServer> ss_; |
624 rtc::AutoSocketServerThread main_; | 620 rtc::AutoSocketServerThread main_; |
625 rtc::Network network_; | 621 rtc::Network network_; |
626 rtc::BasicPacketSocketFactory socket_factory_; | 622 rtc::BasicPacketSocketFactory socket_factory_; |
627 std::unique_ptr<rtc::AsyncPacketSocket> socket_; | 623 std::unique_ptr<rtc::AsyncPacketSocket> socket_; |
628 TestTurnServer turn_server_; | 624 TestTurnServer turn_server_; |
629 std::unique_ptr<TurnPort> turn_port_; | 625 std::unique_ptr<TurnPort> turn_port_; |
630 std::unique_ptr<UDPPort> udp_port_; | 626 std::unique_ptr<UDPPort> udp_port_; |
631 bool turn_ready_; | 627 bool turn_ready_; |
632 bool turn_error_; | 628 bool turn_error_; |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 EXPECT_TRUE(turn_port_->Candidates().empty()); | 1287 EXPECT_TRUE(turn_port_->Candidates().empty()); |
1292 turn_port_.reset(); | 1288 turn_port_.reset(); |
1293 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); | 1289 rtc::Thread::Current()->Post(RTC_FROM_HERE, this, MSG_TESTFINISH); |
1294 // Waiting for above message to be processed. | 1290 // Waiting for above message to be processed. |
1295 ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_); | 1291 ASSERT_TRUE_SIMULATED_WAIT(test_finish_, 1, fake_clock_); |
1296 EXPECT_EQ(last_fd_count, GetFDCount()); | 1292 EXPECT_EQ(last_fd_count, GetFDCount()); |
1297 } | 1293 } |
1298 #endif | 1294 #endif |
1299 | 1295 |
1300 } // namespace cricket | 1296 } // namespace cricket |
OLD | NEW |