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

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

Issue 71013004: Base: Remove Receive() from ScopedHandle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix delegate_execute for google_chrome_build Created 7 years 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 | « base/base.gyp ('k') | base/process/launch.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 (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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 EXPECT_EQ(MAP_FAILED, writable) 418 EXPECT_EQ(MAP_FAILED, writable)
419 << "It shouldn't be possible to re-mmap the descriptor writable."; 419 << "It shouldn't be possible to re-mmap the descriptor writable.";
420 EXPECT_EQ(EACCES, mmap_errno) << strerror(mmap_errno); 420 EXPECT_EQ(EACCES, mmap_errno) << strerror(mmap_errno);
421 if (writable != MAP_FAILED) 421 if (writable != MAP_FAILED)
422 EXPECT_EQ(0, munmap(writable, readonly_shmem.mapped_size())); 422 EXPECT_EQ(0, munmap(writable, readonly_shmem.mapped_size()));
423 423
424 #elif defined(OS_WIN) 424 #elif defined(OS_WIN)
425 EXPECT_EQ(NULL, MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0)) 425 EXPECT_EQ(NULL, MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0))
426 << "Shouldn't be able to map memory writable."; 426 << "Shouldn't be able to map memory writable.";
427 427
428 base::win::ScopedHandle writable_handle; 428 HANDLE temp_handle;
429 EXPECT_EQ(0, 429 BOOL rv = ::DuplicateHandle(GetCurrentProcess(),
430 ::DuplicateHandle(GetCurrentProcess(),
431 handle, 430 handle,
432 GetCurrentProcess, 431 GetCurrentProcess,
433 writable_handle.Receive(), 432 &temp_handle,
434 FILE_MAP_ALL_ACCESS, 433 FILE_MAP_ALL_ACCESS,
435 false, 434 false,
436 0)) 435 0);
436 EXPECT_EQ(FALSE, rv)
437 << "Shouldn't be able to duplicate the handle into a writable one."; 437 << "Shouldn't be able to duplicate the handle into a writable one.";
438 if (rv)
439 base::win::ScopedHandle writable_handle(temp_handle);
438 #else 440 #else
439 #error Unexpected platform; write a test that tries to make 'handle' writable. 441 #error Unexpected platform; write a test that tries to make 'handle' writable.
440 #endif // defined(OS_POSIX) || defined(OS_WIN) 442 #endif // defined(OS_POSIX) || defined(OS_WIN)
441 } 443 }
442 444
443 TEST(SharedMemoryTest, ShareToSelf) { 445 TEST(SharedMemoryTest, ShareToSelf) {
444 StringPiece contents = "Hello World"; 446 StringPiece contents = "Hello World";
445 447
446 SharedMemory shmem; 448 SharedMemory shmem;
447 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size())); 449 ASSERT_TRUE(shmem.CreateAndMapAnonymous(contents.size()));
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 SharedMemoryProcessTest::CleanUp(); 659 SharedMemoryProcessTest::CleanUp();
658 } 660 }
659 661
660 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 662 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
661 return SharedMemoryProcessTest::TaskTestMain(); 663 return SharedMemoryProcessTest::TaskTestMain();
662 } 664 }
663 665
664 #endif // !OS_IOS 666 #endif // !OS_IOS
665 667
666 } // namespace base 668 } // namespace base
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/process/launch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698