| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/socket/tcp_socket.h" | 5 #include "net/socket/tcp_socket.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "build/build_config.h" | |
| 15 #include "net/base/address_list.h" | 14 #include "net/base/address_list.h" |
| 16 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 17 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
| 18 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 19 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
| 20 #include "net/socket/tcp_client_socket.h" | 19 #include "net/socket/tcp_client_socket.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
| 23 | 22 |
| 24 namespace net { | 23 namespace net { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 ASSERT_EQ(OK, result); | 192 ASSERT_EQ(OK, result); |
| 194 | 193 |
| 195 EXPECT_TRUE(accepted_socket.get()); | 194 EXPECT_TRUE(accepted_socket.get()); |
| 196 | 195 |
| 197 // Both sockets should be on the loopback network interface. | 196 // Both sockets should be on the loopback network interface. |
| 198 EXPECT_EQ(accepted_address.address(), local_address_.address()); | 197 EXPECT_EQ(accepted_address.address(), local_address_.address()); |
| 199 | 198 |
| 200 EXPECT_EQ(OK, connect_callback.WaitForResult()); | 199 EXPECT_EQ(OK, connect_callback.WaitForResult()); |
| 201 } | 200 } |
| 202 | 201 |
| 203 // TODO(yzshen): Enable it for other platforms once TCPSocketLibevent supports | |
| 204 // client socket operations. | |
| 205 #if defined(OS_WIN) | |
| 206 | |
| 207 TEST_F(TCPSocketTest, ReadWrite) { | 202 TEST_F(TCPSocketTest, ReadWrite) { |
| 208 ASSERT_NO_FATAL_FAILURE(SetUpListenIPv4()); | 203 ASSERT_NO_FATAL_FAILURE(SetUpListenIPv4()); |
| 209 | 204 |
| 210 TestCompletionCallback connect_callback; | 205 TestCompletionCallback connect_callback; |
| 211 TCPSocket connecting_socket(NULL, NetLog::Source()); | 206 TCPSocket connecting_socket(NULL, NetLog::Source()); |
| 212 int result = connecting_socket.Create(ADDRESS_FAMILY_IPV4); | 207 int result = connecting_socket.Create(ADDRESS_FAMILY_IPV4); |
| 213 ASSERT_EQ(OK, result); | 208 ASSERT_EQ(OK, result); |
| 214 connecting_socket.Connect(local_address_, connect_callback.callback()); | 209 connecting_socket.Connect(local_address_, connect_callback.callback()); |
| 215 | 210 |
| 216 TestCompletionCallback accept_callback; | 211 TestCompletionCallback accept_callback; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ASSERT_TRUE(read_result >= 0); | 252 ASSERT_TRUE(read_result >= 0); |
| 258 ASSERT_TRUE(bytes_read + read_result <= message.size()); | 253 ASSERT_TRUE(bytes_read + read_result <= message.size()); |
| 259 memmove(&buffer[bytes_read], read_buffer->data(), read_result); | 254 memmove(&buffer[bytes_read], read_buffer->data(), read_result); |
| 260 bytes_read += read_result; | 255 bytes_read += read_result; |
| 261 } | 256 } |
| 262 | 257 |
| 263 std::string received_message(buffer.begin(), buffer.end()); | 258 std::string received_message(buffer.begin(), buffer.end()); |
| 264 ASSERT_EQ(message, received_message); | 259 ASSERT_EQ(message, received_message); |
| 265 } | 260 } |
| 266 | 261 |
| 267 #endif | |
| 268 | |
| 269 } // namespace | 262 } // namespace |
| 270 } // namespace net | 263 } // namespace net |
| OLD | NEW |