OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/listen_socket.h" | 7 #include "net/base/listen_socket.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 rv = callback.WaitForResult(); | 82 rv = callback.WaitForResult(); |
83 EXPECT_EQ(rv, net::OK); | 83 EXPECT_EQ(rv, net::OK); |
84 } | 84 } |
85 | 85 |
86 EXPECT_TRUE(sock.IsConnected()); | 86 EXPECT_TRUE(sock.IsConnected()); |
87 | 87 |
88 sock.Disconnect(); | 88 sock.Disconnect(); |
89 EXPECT_FALSE(sock.IsConnected()); | 89 EXPECT_FALSE(sock.IsConnected()); |
90 } | 90 } |
91 | 91 |
| 92 // TODO(wtc): Add unit tests for IsConnectedAndIdle: |
| 93 // - Server closes a connection. |
| 94 // - Server sends data unexpectedly. |
| 95 |
92 TEST_F(TCPClientSocketTest, Read) { | 96 TEST_F(TCPClientSocketTest, Read) { |
93 net::AddressList addr; | 97 net::AddressList addr; |
94 net::HostResolver resolver; | 98 net::HostResolver resolver; |
95 TestCompletionCallback callback; | 99 TestCompletionCallback callback; |
96 | 100 |
97 int rv = resolver.Resolve("localhost", listen_port_, &addr, &callback); | 101 int rv = resolver.Resolve("localhost", listen_port_, &addr, &callback); |
98 EXPECT_EQ(rv, net::ERR_IO_PENDING); | 102 EXPECT_EQ(rv, net::ERR_IO_PENDING); |
99 | 103 |
100 rv = callback.WaitForResult(); | 104 rv = callback.WaitForResult(); |
101 EXPECT_EQ(rv, net::OK); | 105 EXPECT_EQ(rv, net::OK); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // Do a partial read and then exit. This test should not crash! | 208 // Do a partial read and then exit. This test should not crash! |
205 char buf[512]; | 209 char buf[512]; |
206 rv = sock.Read(buf, sizeof(buf), &callback); | 210 rv = sock.Read(buf, sizeof(buf), &callback); |
207 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); | 211 EXPECT_TRUE(rv >= 0 || rv == net::ERR_IO_PENDING); |
208 | 212 |
209 if (rv == net::ERR_IO_PENDING) | 213 if (rv == net::ERR_IO_PENDING) |
210 rv = callback.WaitForResult(); | 214 rv = callback.WaitForResult(); |
211 | 215 |
212 EXPECT_NE(rv, 0); | 216 EXPECT_NE(rv, 0); |
213 } | 217 } |
OLD | NEW |