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

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

Issue 16549: Add an easy way to do a synchronous connect from test code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
« net/base/tcp_client_socket.h ('K') | « net/base/tcp_client_socket.h ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/base/address_list.h" 5 #include "net/base/address_list.h"
6 #include "net/base/host_resolver.h" 6 #include "net/base/host_resolver.h"
7 #include "net/base/net_errors.h" 7 #include "net/base/net_errors.h"
8 #include "net/base/scoped_host_mapper.h" 8 #include "net/base/scoped_host_mapper.h"
9 #include "net/base/tcp_client_socket.h" 9 #include "net/base/tcp_client_socket.h"
10 #include "net/base/test_completion_callback.h" 10 #include "net/base/test_completion_callback.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 rv = callback.WaitForResult(); 42 rv = callback.WaitForResult();
43 EXPECT_EQ(rv, net::OK); 43 EXPECT_EQ(rv, net::OK);
44 } 44 }
45 45
46 EXPECT_TRUE(sock.IsConnected()); 46 EXPECT_TRUE(sock.IsConnected());
47 47
48 sock.Disconnect(); 48 sock.Disconnect();
49 EXPECT_FALSE(sock.IsConnected()); 49 EXPECT_FALSE(sock.IsConnected());
50 } 50 }
51 51
52 TEST_F(TCPClientSocketTest, SyncConnect) {
53 net::AddressList addr;
54 net::HostResolver resolver;
55
56 int rv = resolver.Resolve("www.google.com", 80, &addr, NULL);
57 EXPECT_EQ(rv, net::OK);
58
59 net::TCPClientSocket sock(addr);
60
61 EXPECT_FALSE(sock.IsConnected());
62
63 rv = net::TCPClientSocketSyncConnector::Connect(&sock);
64 EXPECT_EQ(rv, net::OK);
65 EXPECT_TRUE(sock.IsConnected());
66 }
67
52 TEST_F(TCPClientSocketTest, Read) { 68 TEST_F(TCPClientSocketTest, Read) {
53 net::AddressList addr; 69 net::AddressList addr;
54 net::HostResolver resolver; 70 net::HostResolver resolver;
55 TestCompletionCallback callback; 71 TestCompletionCallback callback;
56 72
57 int rv = resolver.Resolve("www.google.com", 80, &addr, &callback); 73 int rv = resolver.Resolve("www.google.com", 80, &addr, &callback);
58 EXPECT_EQ(rv, net::ERR_IO_PENDING); 74 EXPECT_EQ(rv, net::ERR_IO_PENDING);
59 75
60 rv = callback.WaitForResult(); 76 rv = callback.WaitForResult();
61 EXPECT_EQ(rv, net::OK); 77 EXPECT_EQ(rv, net::OK);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // Do a partial read and then exit. This test should not crash! 180 // Do a partial read and then exit. This test should not crash!
165 char buf[512]; 181 char buf[512];
166 rv = sock.Read(buf, sizeof(buf), &callback); 182 rv = sock.Read(buf, sizeof(buf), &callback);
167 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); 183 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING);
168 184
169 if (rv == net::ERR_IO_PENDING) 185 if (rv == net::ERR_IO_PENDING)
170 rv = callback.WaitForResult(); 186 rv = callback.WaitForResult();
171 187
172 EXPECT_NE(rv, 0); 188 EXPECT_NE(rv, 0);
173 } 189 }
OLDNEW
« net/base/tcp_client_socket.h ('K') | « net/base/tcp_client_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698