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

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

Issue 2852803002: Remove base::SharedMemory::ShareToProcess. (Closed)
Patch Set: Compile error. 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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 403 }
404 404
405 TEST(SharedMemoryTest, ShareToSelf) { 405 TEST(SharedMemoryTest, ShareToSelf) {
406 StringPiece contents = "Hello World"; 406 StringPiece contents = "Hello World";
407 407
408 SharedMemory shmem; 408 SharedMemory shmem;
409 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size())); 409 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size()));
410 memcpy(shmem.memory(), contents.data(), contents.size()); 410 memcpy(shmem.memory(), contents.data(), contents.size());
411 EXPECT_TRUE(shmem.Unmap()); 411 EXPECT_TRUE(shmem.Unmap());
412 412
413 SharedMemoryHandle shared_handle; 413 SharedMemoryHandle shared_handle = shmem.handle().Duplicate();
414 ASSERT_TRUE(shmem.ShareToProcess(GetCurrentProcessHandle(), &shared_handle)); 414 ASSERT_TRUE(shared_handle.IsValid());
415 #if defined(OS_WIN) 415 #if defined(OS_WIN)
416 ASSERT_TRUE(shared_handle.OwnershipPassesToIPC()); 416 ASSERT_TRUE(shared_handle.OwnershipPassesToIPC());
417 #endif 417 #endif
418 SharedMemory shared(shared_handle, /*readonly=*/false); 418 SharedMemory shared(shared_handle, /*readonly=*/false);
419 419
420 ASSERT_TRUE(shared.Map(contents.size())); 420 ASSERT_TRUE(shared.Map(contents.size()));
421 EXPECT_EQ( 421 EXPECT_EQ(
422 contents, 422 contents,
423 StringPiece(static_cast<const char*>(shared.memory()), contents.size())); 423 StringPiece(static_cast<const char*>(shared.memory()), contents.size()));
424 424
425 shared_handle = SharedMemoryHandle(); 425 shared_handle = shmem.handle().Duplicate();
426 ASSERT_TRUE(shmem.ShareToProcess(GetCurrentProcessHandle(), &shared_handle)); 426 ASSERT_TRUE(shared_handle.IsValid());
427 #if defined(OS_WIN) 427 #if defined(OS_WIN)
428 ASSERT_TRUE(shared_handle.OwnershipPassesToIPC()); 428 ASSERT_TRUE(shared_handle.OwnershipPassesToIPC());
429 #endif 429 #endif
430 SharedMemory readonly(shared_handle, /*readonly=*/true); 430 SharedMemory readonly(shared_handle, /*readonly=*/true);
431 431
432 ASSERT_TRUE(readonly.Map(contents.size())); 432 ASSERT_TRUE(readonly.Map(contents.size()));
433 EXPECT_EQ(contents, 433 EXPECT_EQ(contents,
434 StringPiece(static_cast<const char*>(readonly.memory()), 434 StringPiece(static_cast<const char*>(readonly.memory()),
435 contents.size())); 435 contents.size()));
436 } 436 }
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 memory.Close(); 700 memory.Close();
701 SharedMemoryProcessTest::CleanUp(); 701 SharedMemoryProcessTest::CleanUp();
702 } 702 }
703 703
704 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 704 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
705 return SharedMemoryProcessTest::TaskTestMain(); 705 return SharedMemoryProcessTest::TaskTestMain();
706 } 706 }
707 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 707 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
708 708
709 } // 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