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

Side by Side Diff: base/memory/shared_memory_unittest.cc

Issue 2845113005: Replace base::SharedMemory read-only methods with GetReadOnlyHandle. (Closed)
Patch Set: Comments from thakis. Created 3 years, 7 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 | « base/memory/shared_memory_posix.cc ('k') | base/memory/shared_memory_win.cc » ('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 (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/memory/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 else 309 else
310 EXPECT_EQ(0, pointers[j][0]); 310 EXPECT_EQ(0, pointers[j][0]);
311 } 311 }
312 } 312 }
313 313
314 for (int i = 0; i < count; i++) { 314 for (int i = 0; i < count; i++) {
315 memories[i].Close(); 315 memories[i].Close();
316 } 316 }
317 } 317 }
318 318
319 TEST(SharedMemoryTest, ShareReadOnly) { 319 TEST(SharedMemoryTest, GetReadOnlyHandle) {
320 StringPiece contents = "Hello World"; 320 StringPiece contents = "Hello World";
321 321
322 SharedMemory writable_shmem; 322 SharedMemory writable_shmem;
323 SharedMemoryCreateOptions options; 323 SharedMemoryCreateOptions options;
324 options.size = contents.size(); 324 options.size = contents.size();
325 options.share_read_only = true; 325 options.share_read_only = true;
326 #if defined(OS_MACOSX) && !defined(OS_IOS) 326 #if defined(OS_MACOSX) && !defined(OS_IOS)
327 // The Mach functionality is tested in shared_memory_mac_unittest.cc. 327 // The Mach functionality is tested in shared_memory_mac_unittest.cc.
328 options.type = SharedMemoryHandle::POSIX; 328 options.type = SharedMemoryHandle::POSIX;
329 #endif 329 #endif
330 ASSERT_TRUE(writable_shmem.Create(options)); 330 ASSERT_TRUE(writable_shmem.Create(options));
331 ASSERT_TRUE(writable_shmem.Map(options.size)); 331 ASSERT_TRUE(writable_shmem.Map(options.size));
332 memcpy(writable_shmem.memory(), contents.data(), contents.size()); 332 memcpy(writable_shmem.memory(), contents.data(), contents.size());
333 EXPECT_TRUE(writable_shmem.Unmap()); 333 EXPECT_TRUE(writable_shmem.Unmap());
334 334
335 SharedMemoryHandle readonly_handle; 335 SharedMemoryHandle readonly_handle = writable_shmem.GetReadOnlyHandle();
336 ASSERT_TRUE(writable_shmem.ShareReadOnlyToProcess(GetCurrentProcessHandle(), 336 ASSERT_TRUE(readonly_handle.IsValid());
337 &readonly_handle));
338 SharedMemory readonly_shmem(readonly_handle, /*readonly=*/true); 337 SharedMemory readonly_shmem(readonly_handle, /*readonly=*/true);
339 338
340 ASSERT_TRUE(readonly_shmem.Map(contents.size())); 339 ASSERT_TRUE(readonly_shmem.Map(contents.size()));
341 EXPECT_EQ(contents, 340 EXPECT_EQ(contents,
342 StringPiece(static_cast<const char*>(readonly_shmem.memory()), 341 StringPiece(static_cast<const char*>(readonly_shmem.memory()),
343 contents.size())); 342 contents.size()));
344 EXPECT_TRUE(readonly_shmem.Unmap()); 343 EXPECT_TRUE(readonly_shmem.Unmap());
345 344
346 // Make sure the writable instance is still writable. 345 // Make sure the writable instance is still writable.
347 ASSERT_TRUE(writable_shmem.Map(contents.size())); 346 ASSERT_TRUE(writable_shmem.Map(contents.size()));
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 memory.Close(); 700 memory.Close();
702 SharedMemoryProcessTest::CleanUp(); 701 SharedMemoryProcessTest::CleanUp();
703 } 702 }
704 703
705 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 704 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
706 return SharedMemoryProcessTest::TaskTestMain(); 705 return SharedMemoryProcessTest::TaskTestMain();
707 } 706 }
708 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 707 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
709 708
710 } // namespace base 709 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_posix.cc ('k') | base/memory/shared_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698