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

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

Issue 61213003: Test ShareToProcess within the same process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/memory/shared_memory.h" 7 #include "base/memory/shared_memory.h"
8 #include "base/process/kill.h" 8 #include "base/process/kill.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 else 354 else
355 EXPECT_EQ(0, pointers[j][0]); 355 EXPECT_EQ(0, pointers[j][0]);
356 } 356 }
357 } 357 }
358 358
359 for (int i = 0; i < count; i++) { 359 for (int i = 0; i < count; i++) {
360 memories[i].Close(); 360 memories[i].Close();
361 } 361 }
362 } 362 }
363 363
364 TEST(SharedMemoryTest, ShareToSelf) {
365 StringPiece contents = "Hello World";
366
367 SharedMemory shmem;
368 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size()));
369 memcpy(shmem.memory(), contents.data(), contents.size());
370 EXPECT_TRUE(shmem.Unmap());
371
372 SharedMemoryHandle shared_handle;
373 ASSERT_TRUE(shmem.ShareToProcess(GetCurrentProcessHandle(), &shared_handle));
374 SharedMemory shared(shared_handle, /*readonly=*/false);
375
376 ASSERT_TRUE(shared.Map(contents.size()));
377 EXPECT_EQ(
378 contents,
379 StringPiece(static_cast<const char*>(shared.memory()), contents.size()));
380 }
381
364 TEST(SharedMemoryTest, MapAt) { 382 TEST(SharedMemoryTest, MapAt) {
365 ASSERT_TRUE(SysInfo::VMAllocationGranularity() >= sizeof(uint32)); 383 ASSERT_TRUE(SysInfo::VMAllocationGranularity() >= sizeof(uint32));
366 const size_t kCount = SysInfo::VMAllocationGranularity(); 384 const size_t kCount = SysInfo::VMAllocationGranularity();
367 const size_t kDataSize = kCount * sizeof(uint32); 385 const size_t kDataSize = kCount * sizeof(uint32);
368 386
369 SharedMemory memory; 387 SharedMemory memory;
370 ASSERT_TRUE(memory.CreateAndMapAnonymous(kDataSize)); 388 ASSERT_TRUE(memory.CreateAndMapAnonymous(kDataSize));
371 ASSERT_TRUE(memory.Map(kDataSize)); 389 ASSERT_TRUE(memory.Map(kDataSize));
372 uint32* ptr = static_cast<uint32*>(memory.memory()); 390 uint32* ptr = static_cast<uint32*>(memory.memory());
373 ASSERT_NE(ptr, static_cast<void*>(NULL)); 391 ASSERT_NE(ptr, static_cast<void*>(NULL));
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 SharedMemoryProcessTest::CleanUp(); 570 SharedMemoryProcessTest::CleanUp();
553 } 571 }
554 572
555 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 573 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
556 return SharedMemoryProcessTest::TaskTestMain(); 574 return SharedMemoryProcessTest::TaskTestMain();
557 } 575 }
558 576
559 #endif // !OS_IOS 577 #endif // !OS_IOS
560 578
561 } // namespace base 579 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698