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

Side by Side Diff: mojo/edk/test/mojo_test_base.cc

Issue 1689053003: Support read-only duplicates of Mojo shared buffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-shm-interop
Patch Set: Rebase and fix comment. Created 4 years, 8 months 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 | « mojo/edk/test/mojo_test_base.h ('k') | mojo/public/c/system/buffer.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/test/mojo_test_base.h" 5 #include "mojo/edk/test/mojo_test_base.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "mojo/edk/embedder/embedder.h" 9 #include "mojo/edk/embedder/embedder.h"
10 #include "mojo/edk/system/handle_signals_state.h" 10 #include "mojo/edk/system/handle_signals_state.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 217 }
218 218
219 // static 219 // static
220 MojoHandle MojoTestBase::CreateBuffer(uint64_t size) { 220 MojoHandle MojoTestBase::CreateBuffer(uint64_t size) {
221 MojoHandle h; 221 MojoHandle h;
222 EXPECT_EQ(MojoCreateSharedBuffer(nullptr, size, &h), MOJO_RESULT_OK); 222 EXPECT_EQ(MojoCreateSharedBuffer(nullptr, size, &h), MOJO_RESULT_OK);
223 return h; 223 return h;
224 } 224 }
225 225
226 // static 226 // static
227 MojoHandle MojoTestBase::DuplicateBuffer(MojoHandle h) { 227 MojoHandle MojoTestBase::DuplicateBuffer(MojoHandle h, bool read_only) {
228 MojoHandle new_handle; 228 MojoHandle new_handle;
229 MojoDuplicateBufferHandleOptions options = {
230 sizeof(MojoDuplicateBufferHandleOptions),
231 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE
232 };
233 if (read_only)
234 options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
229 EXPECT_EQ(MOJO_RESULT_OK, 235 EXPECT_EQ(MOJO_RESULT_OK,
230 MojoDuplicateBufferHandle(h, nullptr, &new_handle)); 236 MojoDuplicateBufferHandle(h, &options, &new_handle));
231 return new_handle; 237 return new_handle;
232 } 238 }
233 239
234 // static 240 // static
235 void MojoTestBase::WriteToBuffer(MojoHandle h, 241 void MojoTestBase::WriteToBuffer(MojoHandle h,
236 size_t offset, 242 size_t offset,
237 const base::StringPiece& s) { 243 const base::StringPiece& s) {
238 char* data; 244 char* data;
239 EXPECT_EQ(MOJO_RESULT_OK, 245 EXPECT_EQ(MOJO_RESULT_OK,
240 MojoMapBuffer(h, offset, s.size(), reinterpret_cast<void**>(&data), 246 MojoMapBuffer(h, offset, s.size(), reinterpret_cast<void**>(&data),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE), 299 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE),
294 MOJO_RESULT_OK); 300 MOJO_RESULT_OK);
295 CHECK_EQ(num_bytes, static_cast<uint32_t>(size)); 301 CHECK_EQ(num_bytes, static_cast<uint32_t>(size));
296 302
297 return std::string(buffer.data(), buffer.size()); 303 return std::string(buffer.data(), buffer.size());
298 } 304 }
299 305
300 } // namespace test 306 } // namespace test
301 } // namespace edk 307 } // namespace edk
302 } // namespace mojo 308 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/test/mojo_test_base.h ('k') | mojo/public/c/system/buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698