Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: net/socket/tcp_client_socket_unittest.cc

Issue 10309002: Reimplements net::AddressList without struct addrinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_EXPORT to *PortOnAddressList. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file contains some tests for TCPClientSocket. 5 // This file contains some tests for TCPClientSocket.
6 // transport_client_socket_unittest.cc contans some other tests that 6 // transport_client_socket_unittest.cc contans some other tests that
7 // are common for TCP and other types of sockets. 7 // are common for TCP and other types of sockets.
8 8
9 #include "net/socket/tcp_client_socket.h" 9 #include "net/socket/tcp_client_socket.h"
10 10
11 #include "net/base/ip_endpoint.h" 11 #include "net/base/ip_endpoint.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "net/base/sys_addrinfo.h"
15 #include "net/base/test_completion_callback.h" 14 #include "net/base/test_completion_callback.h"
16 #include "net/socket/tcp_server_socket.h" 15 #include "net/socket/tcp_server_socket.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 17
19 namespace net { 18 namespace net {
20 19
21 namespace { 20 namespace {
22 21
23 // Try binding a socket to loopback interface and verify that we can 22 // Try binding a socket to loopback interface and verify that we can
24 // still connect to a server on the same interface. 23 // still connect to a server on the same interface.
25 TEST(TCPClientSocketTest, BindLoopbackToLoopback) { 24 TEST(TCPClientSocketTest, BindLoopbackToLoopback) {
26 IPAddressNumber lo_address; 25 IPAddressNumber lo_address;
27 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &lo_address)); 26 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &lo_address));
28 27
29 TCPServerSocket server(NULL, NetLog::Source()); 28 TCPServerSocket server(NULL, NetLog::Source());
30 ASSERT_EQ(OK, server.Listen(IPEndPoint(lo_address, 0), 1)); 29 ASSERT_EQ(OK, server.Listen(IPEndPoint(lo_address, 0), 1));
31 IPEndPoint server_address; 30 IPEndPoint server_address;
32 ASSERT_EQ(OK, server.GetLocalAddress(&server_address)); 31 ASSERT_EQ(OK, server.GetLocalAddress(&server_address));
33 32
34 TCPClientSocket socket( 33 TCPClientSocket socket(
35 AddressList::CreateFromIPAddress(server_address.address(), 34 AddressList(server_address),
eroman 2012/05/04 01:08:41 Fits on one line now.
36 server_address.port()),
37 NULL, NetLog::Source()); 35 NULL, NetLog::Source());
38 36
39 EXPECT_EQ(OK, socket.Bind(IPEndPoint(lo_address, 0))); 37 EXPECT_EQ(OK, socket.Bind(IPEndPoint(lo_address, 0)));
40 38
41 TestCompletionCallback connect_callback; 39 TestCompletionCallback connect_callback;
42 EXPECT_EQ(ERR_IO_PENDING, socket.Connect(connect_callback.callback())); 40 EXPECT_EQ(ERR_IO_PENDING, socket.Connect(connect_callback.callback()));
43 41
44 TestCompletionCallback accept_callback; 42 TestCompletionCallback accept_callback;
45 scoped_ptr<StreamSocket> accepted_socket; 43 scoped_ptr<StreamSocket> accepted_socket;
46 int result = server.Accept(&accepted_socket, accept_callback.callback()); 44 int result = server.Accept(&accepted_socket, accept_callback.callback());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 int listen_result = server.Listen(IPEndPoint(ipv6_lo_ip, 0), 1); 80 int listen_result = server.Listen(IPEndPoint(ipv6_lo_ip, 0), 1);
83 if (listen_result != OK) { 81 if (listen_result != OK) {
84 LOG(ERROR) << "Failed to listen on ::1 - probably because IPv6 is disabled." 82 LOG(ERROR) << "Failed to listen on ::1 - probably because IPv6 is disabled."
85 " Skipping the test"; 83 " Skipping the test";
86 return; 84 return;
87 } 85 }
88 86
89 IPEndPoint server_address; 87 IPEndPoint server_address;
90 ASSERT_EQ(OK, server.GetLocalAddress(&server_address)); 88 ASSERT_EQ(OK, server.GetLocalAddress(&server_address));
91 TCPClientSocket socket( 89 TCPClientSocket socket(
92 AddressList::CreateFromIPAddress(server_address.address(), 90 AddressList(server_address),
eroman 2012/05/04 01:08:41 One line dude.
93 server_address.port()),
94 NULL, NetLog::Source()); 91 NULL, NetLog::Source());
95 92
96 IPAddressNumber ipv4_lo_ip; 93 IPAddressNumber ipv4_lo_ip;
97 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ipv4_lo_ip)); 94 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ipv4_lo_ip));
98 EXPECT_EQ(OK, socket.Bind(IPEndPoint(ipv4_lo_ip, 0))); 95 EXPECT_EQ(OK, socket.Bind(IPEndPoint(ipv4_lo_ip, 0)));
99 96
100 TestCompletionCallback connect_callback; 97 TestCompletionCallback connect_callback;
101 int result = socket.Connect(connect_callback.callback()); 98 int result = socket.Connect(connect_callback.callback());
102 if (result == ERR_IO_PENDING) 99 if (result == ERR_IO_PENDING)
103 result = connect_callback.WaitForResult(); 100 result = connect_callback.WaitForResult();
104 101
105 EXPECT_NE(OK, result); 102 EXPECT_NE(OK, result);
106 } 103 }
107 104
108 } // namespace 105 } // namespace
109 106
110 } // namespace net 107 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698