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 <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 void SetHandle(base::SyncSocket::Handle handle) { | 88 void SetHandle(base::SyncSocket::Handle handle) { |
89 base::SyncSocket sync_socket(handle); | 89 base::SyncSocket sync_socket(handle); |
90 EXPECT_EQ(sync_socket.Send(kHelloString, kHelloStringLength), | 90 EXPECT_EQ(sync_socket.Send(kHelloString, kHelloStringLength), |
91 kHelloStringLength); | 91 kHelloStringLength); |
92 IPC::Message* msg = new MsgClassResponse(kHelloString); | 92 IPC::Message* msg = new MsgClassResponse(kHelloString); |
93 EXPECT_TRUE(chan_->Send(msg)); | 93 EXPECT_TRUE(chan_->Send(msg)); |
94 } | 94 } |
95 | 95 |
96 // When the client responds, it sends back a shutdown message, | 96 // When the client responds, it sends back a shutdown message, |
97 // which causes the message loop to exit. | 97 // which causes the message loop to exit. |
98 void OnMsgClassShutdown() { | 98 void OnMsgClassShutdown() { base::MessageLoop::current()->QuitWhenIdle(); } |
99 base::MessageLoop::current()->Quit(); | |
100 } | |
101 | 99 |
102 IPC::Channel* chan_; | 100 IPC::Channel* chan_; |
103 | 101 |
104 DISALLOW_COPY_AND_ASSIGN(SyncSocketServerListener); | 102 DISALLOW_COPY_AND_ASSIGN(SyncSocketServerListener); |
105 }; | 103 }; |
106 | 104 |
107 // Runs the fuzzing server child mode. Returns when the preset number of | 105 // Runs the fuzzing server child mode. Returns when the preset number of |
108 // messages have been received. | 106 // messages have been received. |
109 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SyncSocketServerClient) { | 107 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SyncSocketServerClient) { |
110 base::MessageLoopForIO main_message_loop; | 108 base::MessageLoopForIO main_message_loop; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // We rely on the order of sync_socket.Send() and chan_->Send() in | 144 // We rely on the order of sync_socket.Send() and chan_->Send() in |
147 // the SyncSocketServerListener object. | 145 // the SyncSocketServerListener object. |
148 EXPECT_EQ(kHelloStringLength, socket_->Peek()); | 146 EXPECT_EQ(kHelloStringLength, socket_->Peek()); |
149 char buf[kHelloStringLength]; | 147 char buf[kHelloStringLength]; |
150 socket_->Receive(static_cast<void*>(buf), kHelloStringLength); | 148 socket_->Receive(static_cast<void*>(buf), kHelloStringLength); |
151 EXPECT_EQ(strcmp(str.c_str(), buf), 0); | 149 EXPECT_EQ(strcmp(str.c_str(), buf), 0); |
152 // After receiving from the socket there should be no bytes left. | 150 // After receiving from the socket there should be no bytes left. |
153 EXPECT_EQ(0U, socket_->Peek()); | 151 EXPECT_EQ(0U, socket_->Peek()); |
154 IPC::Message* msg = new MsgClassShutdown(); | 152 IPC::Message* msg = new MsgClassShutdown(); |
155 EXPECT_TRUE(chan_->Send(msg)); | 153 EXPECT_TRUE(chan_->Send(msg)); |
156 base::MessageLoop::current()->Quit(); | 154 base::MessageLoop::current()->QuitWhenIdle(); |
157 } | 155 } |
158 | 156 |
159 base::SyncSocket* socket_; | 157 base::SyncSocket* socket_; |
160 IPC::Channel* chan_; | 158 IPC::Channel* chan_; |
161 | 159 |
162 DISALLOW_COPY_AND_ASSIGN(SyncSocketClientListener); | 160 DISALLOW_COPY_AND_ASSIGN(SyncSocketClientListener); |
163 }; | 161 }; |
164 | 162 |
165 class SyncSocketTest : public IPCTestBase { | 163 class SyncSocketTest : public IPCTestBase { |
166 }; | 164 }; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 308 |
311 // Read from another socket to free some space for a new write. | 309 // Read from another socket to free some space for a new write. |
312 char hello[kHelloStringLength] = {0}; | 310 char hello[kHelloStringLength] = {0}; |
313 pair[1].Receive(&hello[0], sizeof(hello)); | 311 pair[1].Receive(&hello[0], sizeof(hello)); |
314 | 312 |
315 // Should be able to write more data to the buffer now. | 313 // Should be able to write more data to the buffer now. |
316 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); | 314 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); |
317 } | 315 } |
318 | 316 |
319 } // namespace | 317 } // namespace |
OLD | NEW |