OLD | NEW |
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 #include "base/sync_socket.h" | 5 #include "base/sync_socket.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 base::SyncSocket* socket_; | 161 base::SyncSocket* socket_; |
162 IPC::Channel* chan_; | 162 IPC::Channel* chan_; |
163 | 163 |
164 DISALLOW_COPY_AND_ASSIGN(SyncSocketClientListener); | 164 DISALLOW_COPY_AND_ASSIGN(SyncSocketClientListener); |
165 }; | 165 }; |
166 | 166 |
167 class SyncSocketTest : public IPCTestBase { | 167 class SyncSocketTest : public IPCTestBase { |
168 }; | 168 }; |
169 | 169 |
170 #if defined(OS_ANDROID) | 170 TEST_F(SyncSocketTest, SanityTest) { |
171 #define MAYBE_SanityTest DISABLED_SanityTest | |
172 #else | |
173 #define MAYBE_SanityTest SanityTest | |
174 #endif | |
175 TEST_F(SyncSocketTest, MAYBE_SanityTest) { | |
176 Init("SyncSocketServerClient"); | 171 Init("SyncSocketServerClient"); |
177 | 172 |
178 SyncSocketClientListener listener; | 173 SyncSocketClientListener listener; |
179 CreateChannel(&listener); | 174 CreateChannel(&listener); |
180 ASSERT_TRUE(StartClient()); | 175 ASSERT_TRUE(StartClient()); |
181 // Create a pair of SyncSockets. | 176 // Create a pair of SyncSockets. |
182 base::SyncSocket pair[2]; | 177 base::SyncSocket pair[2]; |
183 base::SyncSocket::CreatePair(&pair[0], &pair[1]); | 178 base::SyncSocket::CreatePair(&pair[0], &pair[1]); |
184 // Immediately after creation there should be no pending bytes. | 179 // Immediately after creation there should be no pending bytes. |
185 EXPECT_EQ(0U, pair[0].Peek()); | 180 EXPECT_EQ(0U, pair[0].Peek()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 242 |
248 // Now shut down the socket that the thread is issuing a blocking read on | 243 // Now shut down the socket that the thread is issuing a blocking read on |
249 // which should cause Receive to return with an error. | 244 // which should cause Receive to return with an error. |
250 pair[0].Shutdown(); | 245 pair[0].Shutdown(); |
251 | 246 |
252 worker.Stop(); | 247 worker.Stop(); |
253 | 248 |
254 EXPECT_EQ(0U, received); | 249 EXPECT_EQ(0U, received); |
255 } | 250 } |
256 | 251 |
257 #if defined(OS_ANDROID) | |
258 #define MAYBE_BlockingReceiveTest DISABLED_BlockingReceiveTest | |
259 #else | |
260 #define MAYBE_BlockingReceiveTest BlockingReceiveTest | |
261 #endif | |
262 // Tests that read is a blocking operation. | 252 // Tests that read is a blocking operation. |
263 TEST_F(SyncSocketTest, MAYBE_BlockingReceiveTest) { | 253 TEST_F(SyncSocketTest, BlockingReceiveTest) { |
264 base::CancelableSyncSocket pair[2]; | 254 base::CancelableSyncSocket pair[2]; |
265 ASSERT_TRUE(base::CancelableSyncSocket::CreatePair(&pair[0], &pair[1])); | 255 ASSERT_TRUE(base::CancelableSyncSocket::CreatePair(&pair[0], &pair[1])); |
266 | 256 |
267 base::Thread worker("BlockingThread"); | 257 base::Thread worker("BlockingThread"); |
268 worker.Start(); | 258 worker.Start(); |
269 | 259 |
270 // Try to do a blocking read from one of the sockets on the worker thread. | 260 // Try to do a blocking read from one of the sockets on the worker thread. |
271 char buf[kHelloStringLength] = {0}; | 261 char buf[kHelloStringLength] = {0}; |
272 size_t received = 1U; // Initialize to an unexpected value. | 262 size_t received = 1U; // Initialize to an unexpected value. |
273 worker.task_runner()->PostTask(FROM_HERE, | 263 worker.task_runner()->PostTask(FROM_HERE, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 302 |
313 // Read from another socket to free some space for a new write. | 303 // Read from another socket to free some space for a new write. |
314 char hello[kHelloStringLength] = {0}; | 304 char hello[kHelloStringLength] = {0}; |
315 pair[1].Receive(&hello[0], sizeof(hello)); | 305 pair[1].Receive(&hello[0], sizeof(hello)); |
316 | 306 |
317 // Should be able to write more data to the buffer now. | 307 // Should be able to write more data to the buffer now. |
318 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); | 308 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); |
319 } | 309 } |
320 | 310 |
321 } // namespace | 311 } // namespace |
OLD | NEW |