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

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

Issue 10803027: Fix TCPClientSocket::GetLocalAddress() to work when socket is not connected. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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.cc » ('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) 2012 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
(...skipping 16 matching lines...) Expand all
27 27
28 TCPServerSocket server(NULL, NetLog::Source()); 28 TCPServerSocket server(NULL, NetLog::Source());
29 ASSERT_EQ(OK, server.Listen(IPEndPoint(lo_address, 0), 1)); 29 ASSERT_EQ(OK, server.Listen(IPEndPoint(lo_address, 0), 1));
30 IPEndPoint server_address; 30 IPEndPoint server_address;
31 ASSERT_EQ(OK, server.GetLocalAddress(&server_address)); 31 ASSERT_EQ(OK, server.GetLocalAddress(&server_address));
32 32
33 TCPClientSocket socket(AddressList(server_address), NULL, NetLog::Source()); 33 TCPClientSocket socket(AddressList(server_address), NULL, NetLog::Source());
34 34
35 EXPECT_EQ(OK, socket.Bind(IPEndPoint(lo_address, 0))); 35 EXPECT_EQ(OK, socket.Bind(IPEndPoint(lo_address, 0)));
36 36
37 IPEndPoint local_address_result;
38 EXPECT_EQ(OK, socket.GetLocalAddress(&local_address_result));
39 EXPECT_EQ(lo_address, local_address_result.address());
40
37 TestCompletionCallback connect_callback; 41 TestCompletionCallback connect_callback;
38 EXPECT_EQ(ERR_IO_PENDING, socket.Connect(connect_callback.callback())); 42 EXPECT_EQ(ERR_IO_PENDING, socket.Connect(connect_callback.callback()));
39 43
40 TestCompletionCallback accept_callback; 44 TestCompletionCallback accept_callback;
41 scoped_ptr<StreamSocket> accepted_socket; 45 scoped_ptr<StreamSocket> accepted_socket;
42 int result = server.Accept(&accepted_socket, accept_callback.callback()); 46 int result = server.Accept(&accepted_socket, accept_callback.callback());
43 if (result == ERR_IO_PENDING) 47 if (result == ERR_IO_PENDING)
44 result = accept_callback.WaitForResult(); 48 result = accept_callback.WaitForResult();
45 ASSERT_EQ(OK, result); 49 ASSERT_EQ(OK, result);
46 50
47 EXPECT_EQ(OK, connect_callback.WaitForResult()); 51 EXPECT_EQ(OK, connect_callback.WaitForResult());
52
53 socket.Disconnect();
wtc 2012/07/19 22:39:26 Thank you for adding this test. Ideally we should
Sergey Ulanov 2012/07/19 23:48:48 Done.
54 EXPECT_FALSE(socket.IsConnected());
wtc 2012/07/19 22:39:26 Here ideally we want to test that the internal soc
55 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED,
56 socket.GetLocalAddress(&local_address_result));
48 } 57 }
49 58
50 // Try to bind socket to the loopback interface and connect to an 59 // Try to bind socket to the loopback interface and connect to an
51 // external address, verify that connection fails. 60 // external address, verify that connection fails.
52 TEST(TCPClientSocketTest, BindLoopbackToExternal) { 61 TEST(TCPClientSocketTest, BindLoopbackToExternal) {
53 IPAddressNumber external_ip; 62 IPAddressNumber external_ip;
54 ASSERT_TRUE(ParseIPLiteralToNumber("72.14.213.105", &external_ip)); 63 ASSERT_TRUE(ParseIPLiteralToNumber("72.14.213.105", &external_ip));
55 TCPClientSocket socket(AddressList::CreateFromIPAddress(external_ip, 80), 64 TCPClientSocket socket(AddressList::CreateFromIPAddress(external_ip, 80),
56 NULL, NetLog::Source()); 65 NULL, NetLog::Source());
57 66
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 int result = socket.Connect(connect_callback.callback()); 103 int result = socket.Connect(connect_callback.callback());
95 if (result == ERR_IO_PENDING) 104 if (result == ERR_IO_PENDING)
96 result = connect_callback.WaitForResult(); 105 result = connect_callback.WaitForResult();
97 106
98 EXPECT_NE(OK, result); 107 EXPECT_NE(OK, result);
99 } 108 }
100 109
101 } // namespace 110 } // namespace
102 111
103 } // namespace net 112 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_client_socket_libevent.cc ('k') | net/socket/tcp_client_socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698