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

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

Issue 1643253003: Add member ownership_passes_to_ipc_ to SharedMemoryHandle on windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minimal test. Created 4 years, 10 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_handle_win.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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/atomicops.h" 8 #include "base/atomicops.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 TEST(SharedMemoryTest, ShareToSelf) { 404 TEST(SharedMemoryTest, ShareToSelf) {
405 StringPiece contents = "Hello World"; 405 StringPiece contents = "Hello World";
406 406
407 SharedMemory shmem; 407 SharedMemory shmem;
408 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size())); 408 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size()));
409 memcpy(shmem.memory(), contents.data(), contents.size()); 409 memcpy(shmem.memory(), contents.data(), contents.size());
410 EXPECT_TRUE(shmem.Unmap()); 410 EXPECT_TRUE(shmem.Unmap());
411 411
412 SharedMemoryHandle shared_handle; 412 SharedMemoryHandle shared_handle;
413 ASSERT_TRUE(shmem.ShareToProcess(GetCurrentProcessHandle(), &shared_handle)); 413 ASSERT_TRUE(shmem.ShareToProcess(GetCurrentProcessHandle(), &shared_handle));
414 #if defined(OS_WIN)
415 ASSERT_TRUE(shared_handle.OwnershipPassesToIPC());
416 #endif
414 SharedMemory shared(shared_handle, /*readonly=*/false); 417 SharedMemory shared(shared_handle, /*readonly=*/false);
415 418
416 ASSERT_TRUE(shared.Map(contents.size())); 419 ASSERT_TRUE(shared.Map(contents.size()));
417 EXPECT_EQ( 420 EXPECT_EQ(
418 contents, 421 contents,
419 StringPiece(static_cast<const char*>(shared.memory()), contents.size())); 422 StringPiece(static_cast<const char*>(shared.memory()), contents.size()));
420 423
421 shared_handle = SharedMemoryHandle(); 424 shared_handle = SharedMemoryHandle();
422 ASSERT_TRUE(shmem.ShareToProcess(GetCurrentProcessHandle(), &shared_handle)); 425 ASSERT_TRUE(shmem.ShareToProcess(GetCurrentProcessHandle(), &shared_handle));
426 #if defined(OS_WIN)
427 ASSERT_TRUE(shared_handle.OwnershipPassesToIPC());
428 #endif
423 SharedMemory readonly(shared_handle, /*readonly=*/true); 429 SharedMemory readonly(shared_handle, /*readonly=*/true);
424 430
425 ASSERT_TRUE(readonly.Map(contents.size())); 431 ASSERT_TRUE(readonly.Map(contents.size()));
426 EXPECT_EQ(contents, 432 EXPECT_EQ(contents,
427 StringPiece(static_cast<const char*>(readonly.memory()), 433 StringPiece(static_cast<const char*>(readonly.memory()),
428 contents.size())); 434 contents.size()));
429 } 435 }
430 436
431 TEST(SharedMemoryTest, MapAt) { 437 TEST(SharedMemoryTest, MapAt) {
432 ASSERT_TRUE(SysInfo::VMAllocationGranularity() >= sizeof(uint32_t)); 438 ASSERT_TRUE(SysInfo::VMAllocationGranularity() >= sizeof(uint32_t));
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 memory.Close(); 705 memory.Close();
700 SharedMemoryProcessTest::CleanUp(); 706 SharedMemoryProcessTest::CleanUp();
701 } 707 }
702 708
703 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 709 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
704 return SharedMemoryProcessTest::TaskTestMain(); 710 return SharedMemoryProcessTest::TaskTestMain();
705 } 711 }
706 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 712 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
707 713
708 } // namespace base 714 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_handle_win.cc ('k') | base/memory/shared_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698