| 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 |
| 11 #include <memory> |
| 12 |
| 11 #include "webrtc/p2p/base/asyncstuntcpsocket.h" | 13 #include "webrtc/p2p/base/asyncstuntcpsocket.h" |
| 12 #include "webrtc/base/asyncsocket.h" | 14 #include "webrtc/base/asyncsocket.h" |
| 13 #include "webrtc/base/gunit.h" | 15 #include "webrtc/base/gunit.h" |
| 14 #include "webrtc/base/physicalsocketserver.h" | 16 #include "webrtc/base/physicalsocketserver.h" |
| 15 #include "webrtc/base/virtualsocketserver.h" | 17 #include "webrtc/base/virtualsocketserver.h" |
| 16 | 18 |
| 17 namespace cricket { | 19 namespace cricket { |
| 18 | 20 |
| 19 static unsigned char kStunMessageWithZeroLength[] = { | 21 static unsigned char kStunMessageWithZeroLength[] = { |
| 20 0x00, 0x01, 0x00, 0x00, // length of 0 (last 2 bytes) | 22 0x00, 0x01, 0x00, 0x00, // length of 0 (last 2 bytes) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 bool CheckData(const void* data, int len) { | 117 bool CheckData(const void* data, int len) { |
| 116 bool ret = false; | 118 bool ret = false; |
| 117 if (recv_packets_.size()) { | 119 if (recv_packets_.size()) { |
| 118 std::string packet = recv_packets_.front(); | 120 std::string packet = recv_packets_.front(); |
| 119 recv_packets_.pop_front(); | 121 recv_packets_.pop_front(); |
| 120 ret = (memcmp(data, packet.c_str(), len) == 0); | 122 ret = (memcmp(data, packet.c_str(), len) == 0); |
| 121 } | 123 } |
| 122 return ret; | 124 return ret; |
| 123 } | 125 } |
| 124 | 126 |
| 125 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 127 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 126 rtc::SocketServerScope ss_scope_; | 128 rtc::SocketServerScope ss_scope_; |
| 127 rtc::scoped_ptr<AsyncStunTCPSocket> send_socket_; | 129 std::unique_ptr<AsyncStunTCPSocket> send_socket_; |
| 128 rtc::scoped_ptr<AsyncStunTCPSocket> recv_socket_; | 130 std::unique_ptr<AsyncStunTCPSocket> recv_socket_; |
| 129 rtc::scoped_ptr<rtc::AsyncPacketSocket> listen_socket_; | 131 std::unique_ptr<rtc::AsyncPacketSocket> listen_socket_; |
| 130 std::list<std::string> recv_packets_; | 132 std::list<std::string> recv_packets_; |
| 131 }; | 133 }; |
| 132 | 134 |
| 133 // Testing a stun packet sent/recv properly. | 135 // Testing a stun packet sent/recv properly. |
| 134 TEST_F(AsyncStunTCPSocketTest, TestSingleStunPacket) { | 136 TEST_F(AsyncStunTCPSocketTest, TestSingleStunPacket) { |
| 135 EXPECT_TRUE(Send(kStunMessageWithZeroLength, | 137 EXPECT_TRUE(Send(kStunMessageWithZeroLength, |
| 136 sizeof(kStunMessageWithZeroLength))); | 138 sizeof(kStunMessageWithZeroLength))); |
| 137 EXPECT_EQ(1u, recv_packets_.size()); | 139 EXPECT_EQ(1u, recv_packets_.size()); |
| 138 EXPECT_TRUE(CheckData(kStunMessageWithZeroLength, | 140 EXPECT_TRUE(CheckData(kStunMessageWithZeroLength, |
| 139 sizeof(kStunMessageWithZeroLength))); | 141 sizeof(kStunMessageWithZeroLength))); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 TEST_F(AsyncStunTCPSocketTest, DISABLED_TestWithSmallSendBuffer) { | 256 TEST_F(AsyncStunTCPSocketTest, DISABLED_TestWithSmallSendBuffer) { |
| 255 vss_->set_send_buffer_capacity(1); | 257 vss_->set_send_buffer_capacity(1); |
| 256 Send(kTurnChannelDataMessageWithOddLength, | 258 Send(kTurnChannelDataMessageWithOddLength, |
| 257 sizeof(kTurnChannelDataMessageWithOddLength)); | 259 sizeof(kTurnChannelDataMessageWithOddLength)); |
| 258 EXPECT_EQ(1u, recv_packets_.size()); | 260 EXPECT_EQ(1u, recv_packets_.size()); |
| 259 EXPECT_TRUE(CheckData(kTurnChannelDataMessageWithOddLength, | 261 EXPECT_TRUE(CheckData(kTurnChannelDataMessageWithOddLength, |
| 260 sizeof(kTurnChannelDataMessageWithOddLength))); | 262 sizeof(kTurnChannelDataMessageWithOddLength))); |
| 261 } | 263 } |
| 262 | 264 |
| 263 } // namespace cricket | 265 } // namespace cricket |
| OLD | NEW |