| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2013 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 kServerAddr.family(), SOCK_STREAM); | 79 kServerAddr.family(), SOCK_STREAM); |
| 80 server->Bind(kServerAddr); | 80 server->Bind(kServerAddr); |
| 81 recv_socket_.reset(new AsyncStunTCPSocket(server, true)); | 81 recv_socket_.reset(new AsyncStunTCPSocket(server, true)); |
| 82 recv_socket_->SignalNewConnection.connect( | 82 recv_socket_->SignalNewConnection.connect( |
| 83 this, &AsyncStunTCPSocketTest::OnNewConnection); | 83 this, &AsyncStunTCPSocketTest::OnNewConnection); |
| 84 | 84 |
| 85 rtc::AsyncSocket* client = vss_->CreateAsyncSocket( | 85 rtc::AsyncSocket* client = vss_->CreateAsyncSocket( |
| 86 kClientAddr.family(), SOCK_STREAM); | 86 kClientAddr.family(), SOCK_STREAM); |
| 87 send_socket_.reset(AsyncStunTCPSocket::Create( | 87 send_socket_.reset(AsyncStunTCPSocket::Create( |
| 88 client, kClientAddr, recv_socket_->GetLocalAddress())); | 88 client, kClientAddr, recv_socket_->GetLocalAddress())); |
| 89 send_socket_->SignalSentPacket.connect( |
| 90 this, &AsyncStunTCPSocketTest::OnSentPacket); |
| 89 ASSERT_TRUE(send_socket_.get() != NULL); | 91 ASSERT_TRUE(send_socket_.get() != NULL); |
| 90 vss_->ProcessMessagesUntilIdle(); | 92 vss_->ProcessMessagesUntilIdle(); |
| 91 } | 93 } |
| 92 | 94 |
| 93 void OnReadPacket(rtc::AsyncPacketSocket* socket, const char* data, | 95 void OnReadPacket(rtc::AsyncPacketSocket* socket, const char* data, |
| 94 size_t len, const rtc::SocketAddress& remote_addr, | 96 size_t len, const rtc::SocketAddress& remote_addr, |
| 95 const rtc::PacketTime& packet_time) { | 97 const rtc::PacketTime& packet_time) { |
| 96 recv_packets_.push_back(std::string(data, len)); | 98 recv_packets_.push_back(std::string(data, len)); |
| 97 } | 99 } |
| 98 | 100 |
| 101 void OnSentPacket(rtc::AsyncPacketSocket* socket, |
| 102 const rtc::SentPacket& packet) { |
| 103 ++sent_packets_; |
| 104 } |
| 105 |
| 99 void OnNewConnection(rtc::AsyncPacketSocket* server, | 106 void OnNewConnection(rtc::AsyncPacketSocket* server, |
| 100 rtc::AsyncPacketSocket* new_socket) { | 107 rtc::AsyncPacketSocket* new_socket) { |
| 101 listen_socket_.reset(new_socket); | 108 listen_socket_.reset(new_socket); |
| 102 new_socket->SignalReadPacket.connect( | 109 new_socket->SignalReadPacket.connect( |
| 103 this, &AsyncStunTCPSocketTest::OnReadPacket); | 110 this, &AsyncStunTCPSocketTest::OnReadPacket); |
| 104 } | 111 } |
| 105 | 112 |
| 106 bool Send(const void* data, size_t len) { | 113 bool Send(const void* data, size_t len) { |
| 107 rtc::PacketOptions options; | 114 rtc::PacketOptions options; |
| 108 size_t ret = send_socket_->Send( | 115 size_t ret = send_socket_->Send( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 120 } | 127 } |
| 121 return ret; | 128 return ret; |
| 122 } | 129 } |
| 123 | 130 |
| 124 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 131 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 125 rtc::AutoSocketServerThread thread_; | 132 rtc::AutoSocketServerThread thread_; |
| 126 std::unique_ptr<AsyncStunTCPSocket> send_socket_; | 133 std::unique_ptr<AsyncStunTCPSocket> send_socket_; |
| 127 std::unique_ptr<AsyncStunTCPSocket> recv_socket_; | 134 std::unique_ptr<AsyncStunTCPSocket> recv_socket_; |
| 128 std::unique_ptr<rtc::AsyncPacketSocket> listen_socket_; | 135 std::unique_ptr<rtc::AsyncPacketSocket> listen_socket_; |
| 129 std::list<std::string> recv_packets_; | 136 std::list<std::string> recv_packets_; |
| 137 int sent_packets_ = 0; |
| 130 }; | 138 }; |
| 131 | 139 |
| 132 // Testing a stun packet sent/recv properly. | 140 // Testing a stun packet sent/recv properly. |
| 133 TEST_F(AsyncStunTCPSocketTest, TestSingleStunPacket) { | 141 TEST_F(AsyncStunTCPSocketTest, TestSingleStunPacket) { |
| 134 EXPECT_TRUE(Send(kStunMessageWithZeroLength, | 142 EXPECT_TRUE(Send(kStunMessageWithZeroLength, |
| 135 sizeof(kStunMessageWithZeroLength))); | 143 sizeof(kStunMessageWithZeroLength))); |
| 136 EXPECT_EQ(1u, recv_packets_.size()); | 144 EXPECT_EQ(1u, recv_packets_.size()); |
| 137 EXPECT_TRUE(CheckData(kStunMessageWithZeroLength, | 145 EXPECT_TRUE(CheckData(kStunMessageWithZeroLength, |
| 138 sizeof(kStunMessageWithZeroLength))); | 146 sizeof(kStunMessageWithZeroLength))); |
| 139 } | 147 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // Investigate why WriteEvent is not signaled from VSS. | 260 // Investigate why WriteEvent is not signaled from VSS. |
| 253 TEST_F(AsyncStunTCPSocketTest, DISABLED_TestWithSmallSendBuffer) { | 261 TEST_F(AsyncStunTCPSocketTest, DISABLED_TestWithSmallSendBuffer) { |
| 254 vss_->set_send_buffer_capacity(1); | 262 vss_->set_send_buffer_capacity(1); |
| 255 Send(kTurnChannelDataMessageWithOddLength, | 263 Send(kTurnChannelDataMessageWithOddLength, |
| 256 sizeof(kTurnChannelDataMessageWithOddLength)); | 264 sizeof(kTurnChannelDataMessageWithOddLength)); |
| 257 EXPECT_EQ(1u, recv_packets_.size()); | 265 EXPECT_EQ(1u, recv_packets_.size()); |
| 258 EXPECT_TRUE(CheckData(kTurnChannelDataMessageWithOddLength, | 266 EXPECT_TRUE(CheckData(kTurnChannelDataMessageWithOddLength, |
| 259 sizeof(kTurnChannelDataMessageWithOddLength))); | 267 sizeof(kTurnChannelDataMessageWithOddLength))); |
| 260 } | 268 } |
| 261 | 269 |
| 270 // Test that SignalSentPacket is fired when a packet is sent. |
| 271 TEST_F(AsyncStunTCPSocketTest, SignalSentPacketFiredWhenPacketSent) { |
| 272 ASSERT_TRUE( |
| 273 Send(kStunMessageWithZeroLength, sizeof(kStunMessageWithZeroLength))); |
| 274 EXPECT_EQ(1, sent_packets_); |
| 275 // Send another packet for good measure. |
| 276 ASSERT_TRUE( |
| 277 Send(kStunMessageWithZeroLength, sizeof(kStunMessageWithZeroLength))); |
| 278 EXPECT_EQ(2, sent_packets_); |
| 279 } |
| 280 |
| 281 // Test that SignalSentPacket isn't fired when a packet isn't sent (for |
| 282 // example, because it's invalid). |
| 283 TEST_F(AsyncStunTCPSocketTest, SignalSentPacketNotFiredWhenPacketNotSent) { |
| 284 // Attempt to send a packet that's too small; since it isn't sent, |
| 285 // SignalSentPacket shouldn't fire. |
| 286 char data[1]; |
| 287 ASSERT_FALSE(Send(data, sizeof(data))); |
| 288 EXPECT_EQ(0, sent_packets_); |
| 289 } |
| 290 |
| 262 } // namespace cricket | 291 } // namespace cricket |
| OLD | NEW |