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

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

Issue 728553002: Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 TEST_F(PlatformChannelPairPosixTest, SendReceiveData) { 106 TEST_F(PlatformChannelPairPosixTest, SendReceiveData) {
107 PlatformChannelPair channel_pair; 107 PlatformChannelPair channel_pair;
108 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass(); 108 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass();
109 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass(); 109 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass();
110 110
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( 115 PlatformChannelWrite(server_handle.get(), send_string.data(),
116 server_handle.get(), send_string.data(), 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<PlatformHandle> received_handles;
122 ssize_t result = PlatformChannelRecvmsg( 122 ssize_t result = PlatformChannelRecvmsg(client_handle.get(), buf,
123 client_handle.get(), buf, 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(PlatformChannelPairPosixTest, SendReceiveFDs) { 130 TEST_F(PlatformChannelPairPosixTest, SendReceiveFDs) {
131 base::ScopedTempDir temp_dir; 131 base::ScopedTempDir temp_dir;
132 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 132 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
133 133
(...skipping 14 matching lines...) Expand all
148 ASSERT_EQ(j, fwrite(std::string(j, '0' + i).data(), 1, j, fp.get())); 148 ASSERT_EQ(j, fwrite(std::string(j, '0' + i).data(), 1, j, fp.get()));
149 platform_handles.push_back( 149 platform_handles.push_back(
150 test::PlatformHandleFromFILE(fp.Pass()).release()); 150 test::PlatformHandleFromFILE(fp.Pass()).release());
151 ASSERT_TRUE(platform_handles.back().is_valid()); 151 ASSERT_TRUE(platform_handles.back().is_valid());
152 } 152 }
153 153
154 // Send the FDs (+ "hello"). 154 // Send the FDs (+ "hello").
155 struct iovec iov = {const_cast<char*>(kHello), sizeof(kHello)}; 155 struct iovec iov = {const_cast<char*>(kHello), sizeof(kHello)};
156 // We assume that the |sendmsg()| actually sends all the data. 156 // We assume that the |sendmsg()| actually sends all the data.
157 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)), 157 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
158 PlatformChannelSendmsgWithHandles(server_handle.get(), 158 PlatformChannelSendmsgWithHandles(server_handle.get(), &iov, 1,
159 &iov,
160 1,
161 &platform_handles[0], 159 &platform_handles[0],
162 platform_handles.size())); 160 platform_handles.size()));
163 161
164 WaitReadable(client_handle.get()); 162 WaitReadable(client_handle.get());
165 163
166 char buf[100] = {}; 164 char buf[100] = {};
167 std::deque<PlatformHandle> received_handles; 165 std::deque<PlatformHandle> received_handles;
168 // We assume that the |recvmsg()| actually reads all the data. 166 // We assume that the |recvmsg()| actually reads all the data.
169 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)), 167 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
170 PlatformChannelRecvmsg( 168 PlatformChannelRecvmsg(client_handle.get(), buf, sizeof(buf),
171 client_handle.get(), buf, sizeof(buf), &received_handles)); 169 &received_handles));
172 EXPECT_STREQ(kHello, buf); 170 EXPECT_STREQ(kHello, buf);
173 EXPECT_EQ(i, received_handles.size()); 171 EXPECT_EQ(i, received_handles.size());
174 172
175 for (size_t j = 0; !received_handles.empty(); j++) { 173 for (size_t j = 0; !received_handles.empty(); j++) {
176 base::ScopedFILE fp(test::FILEFromPlatformHandle( 174 base::ScopedFILE fp(test::FILEFromPlatformHandle(
177 ScopedPlatformHandle(received_handles.front()), "rb")); 175 ScopedPlatformHandle(received_handles.front()), "rb"));
178 received_handles.pop_front(); 176 received_handles.pop_front();
179 ASSERT_TRUE(fp); 177 ASSERT_TRUE(fp);
180 rewind(fp.get()); 178 rewind(fp.get());
181 char read_buf[100]; 179 char read_buf[100];
(...skipping 25 matching lines...) Expand all
207 fwrite(file_contents.data(), 1, file_contents.size(), fp.get())); 205 fwrite(file_contents.data(), 1, file_contents.size(), fp.get()));
208 PlatformHandleVector platform_handles; 206 PlatformHandleVector platform_handles;
209 platform_handles.push_back( 207 platform_handles.push_back(
210 test::PlatformHandleFromFILE(fp.Pass()).release()); 208 test::PlatformHandleFromFILE(fp.Pass()).release());
211 ASSERT_TRUE(platform_handles.back().is_valid()); 209 ASSERT_TRUE(platform_handles.back().is_valid());
212 210
213 // Send the FD (+ "hello"). 211 // Send the FD (+ "hello").
214 struct iovec iov = {const_cast<char*>(kHello), sizeof(kHello)}; 212 struct iovec iov = {const_cast<char*>(kHello), sizeof(kHello)};
215 // We assume that the |sendmsg()| actually sends all the data. 213 // We assume that the |sendmsg()| actually sends all the data.
216 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)), 214 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
217 PlatformChannelSendmsgWithHandles(server_handle.get(), 215 PlatformChannelSendmsgWithHandles(server_handle.get(), &iov, 1,
218 &iov,
219 1,
220 &platform_handles[0], 216 &platform_handles[0],
221 platform_handles.size())); 217 platform_handles.size()));
222 } 218 }
223 219
224 WaitReadable(client_handle.get()); 220 WaitReadable(client_handle.get());
225 221
226 // Start with an invalid handle in the deque. 222 // Start with an invalid handle in the deque.
227 std::deque<PlatformHandle> received_handles; 223 std::deque<PlatformHandle> received_handles;
228 received_handles.push_back(PlatformHandle()); 224 received_handles.push_back(PlatformHandle());
229 225
230 char buf[100] = {}; 226 char buf[100] = {};
231 // We assume that the |recvmsg()| actually reads all the data. 227 // We assume that the |recvmsg()| actually reads all the data.
232 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)), 228 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
233 PlatformChannelRecvmsg( 229 PlatformChannelRecvmsg(client_handle.get(), buf, sizeof(buf),
234 client_handle.get(), buf, sizeof(buf), &received_handles)); 230 &received_handles));
235 EXPECT_STREQ(kHello, buf); 231 EXPECT_STREQ(kHello, buf);
236 ASSERT_EQ(2u, received_handles.size()); 232 ASSERT_EQ(2u, received_handles.size());
237 EXPECT_FALSE(received_handles[0].is_valid()); 233 EXPECT_FALSE(received_handles[0].is_valid());
238 EXPECT_TRUE(received_handles[1].is_valid()); 234 EXPECT_TRUE(received_handles[1].is_valid());
239 235
240 { 236 {
241 base::ScopedFILE fp(test::FILEFromPlatformHandle( 237 base::ScopedFILE fp(test::FILEFromPlatformHandle(
242 ScopedPlatformHandle(received_handles[1]), "rb")); 238 ScopedPlatformHandle(received_handles[1]), "rb"));
243 received_handles[1] = PlatformHandle(); 239 received_handles[1] = PlatformHandle();
244 ASSERT_TRUE(fp); 240 ASSERT_TRUE(fp);
245 rewind(fp.get()); 241 rewind(fp.get());
246 char read_buf[100]; 242 char read_buf[100];
247 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get()); 243 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get());
248 EXPECT_EQ(file_contents.size(), bytes_read); 244 EXPECT_EQ(file_contents.size(), bytes_read);
249 EXPECT_EQ(file_contents, std::string(read_buf, bytes_read)); 245 EXPECT_EQ(file_contents, std::string(read_buf, bytes_read));
250 } 246 }
251 } 247 }
252 248
253 } // namespace 249 } // namespace
254 } // namespace embedder 250 } // namespace embedder
255 } // namespace mojo 251 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_channel_pair_posix.cc ('k') | mojo/edk/embedder/platform_channel_pair_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698