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