Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: mojo/edk/embedder/platform_channel_pair_unittest.cc

Issue 1478503003: EDK: Convert most uses of PlatformHandleVector to std::vector<ScopedPlatformHandle>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/edk/embedder/platform_channel_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/edk/embedder/platform_channel_pair.h" 5 #include "mojo/edk/embedder/platform_channel_pair.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <poll.h> 8 #include <poll.h>
9 #include <signal.h> 9 #include <signal.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 for (size_t i = 0; i < 10; i++) { 111 for (size_t i = 0; i < 10; i++) {
112 std::string send_string(1 << i, 'A' + i); 112 std::string send_string(1 << i, 'A' + i);
113 113
114 EXPECT_EQ(static_cast<ssize_t>(send_string.size()), 114 EXPECT_EQ(static_cast<ssize_t>(send_string.size()),
115 PlatformChannelWrite(server_handle.get(), send_string.data(), 115 PlatformChannelWrite(server_handle.get(), send_string.data(),
116 send_string.size())); 116 send_string.size()));
117 117
118 WaitReadable(client_handle.get()); 118 WaitReadable(client_handle.get());
119 119
120 char buf[10000] = {}; 120 char buf[10000] = {};
121 std::deque<PlatformHandle> received_handles; 121 std::deque<ScopedPlatformHandle> received_handles;
122 ssize_t result = PlatformChannelRecvmsg(client_handle.get(), buf, 122 ssize_t result = PlatformChannelRecvmsg(client_handle.get(), buf,
123 sizeof(buf), &received_handles); 123 sizeof(buf), &received_handles);
124 EXPECT_EQ(static_cast<ssize_t>(send_string.size()), result); 124 EXPECT_EQ(static_cast<ssize_t>(send_string.size()), result);
125 EXPECT_EQ(send_string, std::string(buf, static_cast<size_t>(result))); 125 EXPECT_EQ(send_string, std::string(buf, static_cast<size_t>(result)));
126 EXPECT_TRUE(received_handles.empty()); 126 EXPECT_TRUE(received_handles.empty());
127 } 127 }
128 } 128 }
129 129
130 TEST_F(PlatformChannelPairTest, SendReceiveFDs) { 130 TEST_F(PlatformChannelPairTest, SendReceiveFDs) {
131 mojo::system::test::ScopedTestDir test_dir; 131 mojo::system::test::ScopedTestDir test_dir;
(...skipping 29 matching lines...) Expand all
161 struct iovec iov = {const_cast<char*>(kHello), sizeof(kHello)}; 161 struct iovec iov = {const_cast<char*>(kHello), sizeof(kHello)};
162 // We assume that the |sendmsg()| actually sends all the data. 162 // We assume that the |sendmsg()| actually sends all the data.
163 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)), 163 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
164 PlatformChannelSendmsgWithHandles(server_handle.get(), &iov, 1, 164 PlatformChannelSendmsgWithHandles(server_handle.get(), &iov, 1,
165 &platform_handles->at(0), 165 &platform_handles->at(0),
166 platform_handles->size())); 166 platform_handles->size()));
167 167
168 WaitReadable(client_handle.get()); 168 WaitReadable(client_handle.get());
169 169
170 char buf[10000] = {}; 170 char buf[10000] = {};
171 std::deque<PlatformHandle> received_handles; 171 std::deque<ScopedPlatformHandle> received_handles;
172 // We assume that the |recvmsg()| actually reads all the data. 172 // We assume that the |recvmsg()| actually reads all the data.
173 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)), 173 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
174 PlatformChannelRecvmsg(client_handle.get(), buf, sizeof(buf), 174 PlatformChannelRecvmsg(client_handle.get(), buf, sizeof(buf),
175 &received_handles)); 175 &received_handles));
176 EXPECT_STREQ(kHello, buf); 176 EXPECT_STREQ(kHello, buf);
177 EXPECT_EQ(i, received_handles.size()); 177 EXPECT_EQ(i, received_handles.size());
178 178
179 for (size_t j = 0; !received_handles.empty(); j++) { 179 for (size_t j = 0; !received_handles.empty(); j++) {
180 util::ScopedFILE fp(test::FILEFromPlatformHandle( 180 util::ScopedFILE fp(test::FILEFromPlatformHandle(
181 ScopedPlatformHandle(received_handles.front()), "rb")); 181 std::move(received_handles.front()), "rb"));
182 received_handles.pop_front(); 182 received_handles.pop_front();
183 ASSERT_TRUE(fp); 183 ASSERT_TRUE(fp);
184 rewind(fp.get()); 184 rewind(fp.get());
185 char read_buf[kNumHandlesToSend]; 185 char read_buf[kNumHandlesToSend];
186 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get()); 186 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get());
187 EXPECT_EQ(j + 1, bytes_read); 187 EXPECT_EQ(j + 1, bytes_read);
188 EXPECT_EQ(std::string(j + 1, c), std::string(read_buf, bytes_read)); 188 EXPECT_EQ(std::string(j + 1, c), std::string(read_buf, bytes_read));
189 } 189 }
190 } 190 }
191 } 191 }
(...skipping 24 matching lines...) Expand all
216 // We assume that the |sendmsg()| actually sends all the data. 216 // We assume that the |sendmsg()| actually sends all the data.
217 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)), 217 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
218 PlatformChannelSendmsgWithHandles(server_handle.get(), &iov, 1, 218 PlatformChannelSendmsgWithHandles(server_handle.get(), &iov, 1,
219 &platform_handles->at(0), 219 &platform_handles->at(0),
220 platform_handles->size())); 220 platform_handles->size()));
221 } 221 }
222 222
223 WaitReadable(client_handle.get()); 223 WaitReadable(client_handle.get());
224 224
225 // Start with an invalid handle in the deque. 225 // Start with an invalid handle in the deque.
226 std::deque<PlatformHandle> received_handles; 226 std::deque<ScopedPlatformHandle> received_handles;
227 received_handles.push_back(PlatformHandle()); 227 received_handles.push_back(ScopedPlatformHandle());
228 228
229 char buf[100] = {}; 229 char buf[100] = {};
230 // We assume that the |recvmsg()| actually reads all the data. 230 // We assume that the |recvmsg()| actually reads all the data.
231 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)), 231 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
232 PlatformChannelRecvmsg(client_handle.get(), buf, sizeof(buf), 232 PlatformChannelRecvmsg(client_handle.get(), buf, sizeof(buf),
233 &received_handles)); 233 &received_handles));
234 EXPECT_STREQ(kHello, buf); 234 EXPECT_STREQ(kHello, buf);
235 ASSERT_EQ(2u, received_handles.size()); 235 ASSERT_EQ(2u, received_handles.size());
236 EXPECT_FALSE(received_handles[0].is_valid()); 236 EXPECT_FALSE(received_handles[0].is_valid());
237 EXPECT_TRUE(received_handles[1].is_valid()); 237 EXPECT_TRUE(received_handles[1].is_valid());
238 238
239 { 239 {
240 util::ScopedFILE fp(test::FILEFromPlatformHandle( 240 util::ScopedFILE fp(
241 ScopedPlatformHandle(received_handles[1]), "rb")); 241 test::FILEFromPlatformHandle(std::move(received_handles[1]), "rb"));
242 received_handles[1] = PlatformHandle();
243 ASSERT_TRUE(fp); 242 ASSERT_TRUE(fp);
244 rewind(fp.get()); 243 rewind(fp.get());
245 char read_buf[100]; 244 char read_buf[100];
246 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get()); 245 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get());
247 EXPECT_EQ(file_contents.size(), bytes_read); 246 EXPECT_EQ(file_contents.size(), bytes_read);
248 EXPECT_EQ(file_contents, std::string(read_buf, bytes_read)); 247 EXPECT_EQ(file_contents, std::string(read_buf, bytes_read));
249 } 248 }
250 } 249 }
251 250
252 } // namespace 251 } // namespace
253 } // namespace embedder 252 } // namespace embedder
254 } // namespace mojo 253 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/embedder/platform_channel_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698