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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // which causes the message loop to exit. | 102 // which causes the message loop to exit. |
103 void OnMsgClassShutdown() { base::MessageLoop::current()->QuitWhenIdle(); } | 103 void OnMsgClassShutdown() { base::MessageLoop::current()->QuitWhenIdle(); } |
104 | 104 |
105 IPC::Channel* chan_; | 105 IPC::Channel* chan_; |
106 | 106 |
107 DISALLOW_COPY_AND_ASSIGN(SyncSocketServerListener); | 107 DISALLOW_COPY_AND_ASSIGN(SyncSocketServerListener); |
108 }; | 108 }; |
109 | 109 |
110 // Runs the fuzzing server child mode. Returns when the preset number of | 110 // Runs the fuzzing server child mode. Returns when the preset number of |
111 // messages have been received. | 111 // messages have been received. |
112 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(SyncSocketServerClient) { | 112 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(SyncSocketServerClient) { |
113 base::MessageLoopForIO main_message_loop; | |
114 SyncSocketServerListener listener; | 113 SyncSocketServerListener listener; |
115 std::unique_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( | 114 Connect(&listener); |
116 IPCTestBase::GetChannelName("SyncSocketServerClient"), &listener, | 115 listener.Init(channel()); |
117 main_message_loop.task_runner())); | |
118 EXPECT_TRUE(channel->Connect()); | |
119 listener.Init(channel.get()); | |
120 base::RunLoop().Run(); | 116 base::RunLoop().Run(); |
121 return 0; | 117 Close(); |
122 } | 118 } |
123 | 119 |
124 // The SyncSocket client listener only processes one sort of message, | 120 // The SyncSocket client listener only processes one sort of message, |
125 // a response from the server. | 121 // a response from the server. |
126 class SyncSocketClientListener : public IPC::Listener { | 122 class SyncSocketClientListener : public IPC::Listener { |
127 public: | 123 public: |
128 SyncSocketClientListener() { | 124 SyncSocketClientListener() { |
129 } | 125 } |
130 | 126 |
131 void Init(base::SyncSocket* socket, IPC::Channel* chan) { | 127 void Init(base::SyncSocket* socket, IPC::Channel* chan) { |
(...skipping 27 matching lines...) Expand all Loading... |
159 EXPECT_TRUE(chan_->Send(msg)); | 155 EXPECT_TRUE(chan_->Send(msg)); |
160 base::MessageLoop::current()->QuitWhenIdle(); | 156 base::MessageLoop::current()->QuitWhenIdle(); |
161 } | 157 } |
162 | 158 |
163 base::SyncSocket* socket_; | 159 base::SyncSocket* socket_; |
164 IPC::Channel* chan_; | 160 IPC::Channel* chan_; |
165 | 161 |
166 DISALLOW_COPY_AND_ASSIGN(SyncSocketClientListener); | 162 DISALLOW_COPY_AND_ASSIGN(SyncSocketClientListener); |
167 }; | 163 }; |
168 | 164 |
169 class SyncSocketTest : public IPCTestBase { | 165 using SyncSocketTest = IPCChannelMojoTestBase; |
170 }; | |
171 | 166 |
172 TEST_F(SyncSocketTest, SanityTest) { | 167 TEST_F(SyncSocketTest, SanityTest) { |
173 Init("SyncSocketServerClient"); | 168 Init("SyncSocketServerClient"); |
174 | 169 |
175 SyncSocketClientListener listener; | 170 SyncSocketClientListener listener; |
176 CreateChannel(&listener); | 171 CreateChannel(&listener); |
177 ASSERT_TRUE(StartClient()); | |
178 // Create a pair of SyncSockets. | 172 // Create a pair of SyncSockets. |
179 base::SyncSocket pair[2]; | 173 base::SyncSocket pair[2]; |
180 base::SyncSocket::CreatePair(&pair[0], &pair[1]); | 174 base::SyncSocket::CreatePair(&pair[0], &pair[1]); |
181 // Immediately after creation there should be no pending bytes. | 175 // Immediately after creation there should be no pending bytes. |
182 EXPECT_EQ(0U, pair[0].Peek()); | 176 EXPECT_EQ(0U, pair[0].Peek()); |
183 EXPECT_EQ(0U, pair[1].Peek()); | 177 EXPECT_EQ(0U, pair[1].Peek()); |
184 base::SyncSocket::Handle target_handle; | 178 base::SyncSocket::Handle target_handle; |
185 // Connect the channel and listener. | 179 // Connect the channel and listener. |
186 ASSERT_TRUE(ConnectChannel()); | 180 ASSERT_TRUE(ConnectChannel()); |
187 listener.Init(&pair[0], channel()); | 181 listener.Init(&pair[0], channel()); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 298 |
305 // Read from another socket to free some space for a new write. | 299 // Read from another socket to free some space for a new write. |
306 char hello[kHelloStringLength] = {0}; | 300 char hello[kHelloStringLength] = {0}; |
307 pair[1].Receive(&hello[0], sizeof(hello)); | 301 pair[1].Receive(&hello[0], sizeof(hello)); |
308 | 302 |
309 // Should be able to write more data to the buffer now. | 303 // Should be able to write more data to the buffer now. |
310 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); | 304 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); |
311 } | 305 } |
312 | 306 |
313 } // namespace | 307 } // namespace |
OLD | NEW |