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

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: get_canonical_name -> canonical_name. iterator to indexing 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
« no previous file with comments | « net/socket/tcp_client_socket_libevent.cc ('k') | net/socket/tcp_client_socket_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(AddressList(server_address), NULL, NetLog::Source());
35 AddressList::CreateFromIPAddress(server_address.address(),
36 server_address.port()),
37 NULL, NetLog::Source());
38 34
39 EXPECT_EQ(OK, socket.Bind(IPEndPoint(lo_address, 0))); 35 EXPECT_EQ(OK, socket.Bind(IPEndPoint(lo_address, 0)));
40 36
41 TestCompletionCallback connect_callback; 37 TestCompletionCallback connect_callback;
42 EXPECT_EQ(ERR_IO_PENDING, socket.Connect(connect_callback.callback())); 38 EXPECT_EQ(ERR_IO_PENDING, socket.Connect(connect_callback.callback()));
43 39
44 TestCompletionCallback accept_callback; 40 TestCompletionCallback accept_callback;
45 scoped_ptr<StreamSocket> accepted_socket; 41 scoped_ptr<StreamSocket> accepted_socket;
46 int result = server.Accept(&accepted_socket, accept_callback.callback()); 42 int result = server.Accept(&accepted_socket, accept_callback.callback());
47 if (result == ERR_IO_PENDING) 43 if (result == ERR_IO_PENDING)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 TCPServerSocket server(NULL, NetLog::Source()); 77 TCPServerSocket server(NULL, NetLog::Source());
82 int listen_result = server.Listen(IPEndPoint(ipv6_lo_ip, 0), 1); 78 int listen_result = server.Listen(IPEndPoint(ipv6_lo_ip, 0), 1);
83 if (listen_result != OK) { 79 if (listen_result != OK) {
84 LOG(ERROR) << "Failed to listen on ::1 - probably because IPv6 is disabled." 80 LOG(ERROR) << "Failed to listen on ::1 - probably because IPv6 is disabled."
85 " Skipping the test"; 81 " Skipping the test";
86 return; 82 return;
87 } 83 }
88 84
89 IPEndPoint server_address; 85 IPEndPoint server_address;
90 ASSERT_EQ(OK, server.GetLocalAddress(&server_address)); 86 ASSERT_EQ(OK, server.GetLocalAddress(&server_address));
91 TCPClientSocket socket( 87 TCPClientSocket socket(AddressList(server_address), NULL, NetLog::Source());
92 AddressList::CreateFromIPAddress(server_address.address(),
93 server_address.port()),
94 NULL, NetLog::Source());
95 88
96 IPAddressNumber ipv4_lo_ip; 89 IPAddressNumber ipv4_lo_ip;
97 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ipv4_lo_ip)); 90 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &ipv4_lo_ip));
98 EXPECT_EQ(OK, socket.Bind(IPEndPoint(ipv4_lo_ip, 0))); 91 EXPECT_EQ(OK, socket.Bind(IPEndPoint(ipv4_lo_ip, 0)));
99 92
100 TestCompletionCallback connect_callback; 93 TestCompletionCallback connect_callback;
101 int result = socket.Connect(connect_callback.callback()); 94 int result = socket.Connect(connect_callback.callback());
102 if (result == ERR_IO_PENDING) 95 if (result == ERR_IO_PENDING)
103 result = connect_callback.WaitForResult(); 96 result = connect_callback.WaitForResult();
104 97
105 EXPECT_NE(OK, result); 98 EXPECT_NE(OK, result);
106 } 99 }
107 100
108 } // namespace 101 } // namespace
109 102
110 } // namespace net 103 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_client_socket_libevent.cc ('k') | net/socket/tcp_client_socket_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698