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 <stdio.h> | 7 #include <stdio.h> |
8 #include <string> | 8 #include <string> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "ipc/ipc_channel_proxy.h" | 15 #include "ipc/ipc_channel_proxy.h" |
| 16 #include "ipc/ipc_multiprocess_test.h" |
16 #include "ipc/ipc_tests.h" | 17 #include "ipc/ipc_tests.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "testing/multiprocess_func_list.h" | 19 #include "testing/multiprocess_func_list.h" |
19 | 20 |
20 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
21 #include "base/file_descriptor_posix.h" | 22 #include "base/file_descriptor_posix.h" |
22 #endif | 23 #endif |
23 | 24 |
24 // IPC messages for testing --------------------------------------------------- | 25 // IPC messages for testing --------------------------------------------------- |
25 | 26 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 MessageLoop::current()->Quit(); | 102 MessageLoop::current()->Quit(); |
102 } | 103 } |
103 | 104 |
104 IPC::Channel* chan_; | 105 IPC::Channel* chan_; |
105 | 106 |
106 DISALLOW_COPY_AND_ASSIGN(SyncSocketServerListener); | 107 DISALLOW_COPY_AND_ASSIGN(SyncSocketServerListener); |
107 }; | 108 }; |
108 | 109 |
109 // Runs the fuzzing server child mode. Returns when the preset number | 110 // Runs the fuzzing server child mode. Returns when the preset number |
110 // of messages have been received. | 111 // of messages have been received. |
111 MULTIPROCESS_TEST_MAIN(RunSyncSocketServer) { | 112 MULTIPROCESS_IPC_TEST_MAIN(RunSyncSocketServer) { |
112 MessageLoopForIO main_message_loop; | 113 MessageLoopForIO main_message_loop; |
113 SyncSocketServerListener listener; | 114 SyncSocketServerListener listener; |
114 IPC::Channel chan(kSyncSocketChannel, IPC::Channel::MODE_CLIENT, &listener); | 115 IPC::Channel chan(kSyncSocketChannel, IPC::Channel::MODE_CLIENT, &listener); |
115 EXPECT_TRUE(chan.Connect()); | 116 EXPECT_TRUE(chan.Connect()); |
116 listener.Init(&chan); | 117 listener.Init(&chan); |
117 MessageLoop::current()->Run(); | 118 MessageLoop::current()->Run(); |
118 return 0; | 119 return 0; |
119 } | 120 } |
120 | 121 |
121 // The SyncSocket client listener only processes one sort of message, | 122 // The SyncSocket client listener only processes one sort of message, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 EXPECT_EQ(0U, pair[0].Send(kHelloString, kHelloStringLength)); | 300 EXPECT_EQ(0U, pair[0].Send(kHelloString, kHelloStringLength)); |
300 EXPECT_EQ(bytes_in_buffer, pair[1].Peek()); | 301 EXPECT_EQ(bytes_in_buffer, pair[1].Peek()); |
301 | 302 |
302 // 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. |
303 char hello[kHelloStringLength] = {0}; | 304 char hello[kHelloStringLength] = {0}; |
304 pair[1].Receive(&hello[0], sizeof(hello)); | 305 pair[1].Receive(&hello[0], sizeof(hello)); |
305 | 306 |
306 // Should be able to write more data to the buffer now. | 307 // Should be able to write more data to the buffer now. |
307 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); | 308 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); |
308 } | 309 } |
OLD | NEW |