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

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

Issue 1320783002: Make SharedMemoryHandle a class on windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_global
Patch Set: Rebase. Created 5 years, 2 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 "base/atomicops.h" 5 #include "base/atomicops.h"
6 #include "base/basictypes.h" 6 #include "base/basictypes.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/process/kill.h" 9 #include "base/process/kill.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 void* writable = mmap(NULL, contents.size(), PROT_READ | PROT_WRITE, 362 void* writable = mmap(NULL, contents.size(), PROT_READ | PROT_WRITE,
363 MAP_SHARED, handle_fd, 0); 363 MAP_SHARED, handle_fd, 0);
364 int mmap_errno = errno; 364 int mmap_errno = errno;
365 EXPECT_EQ(MAP_FAILED, writable) 365 EXPECT_EQ(MAP_FAILED, writable)
366 << "It shouldn't be possible to re-mmap the descriptor writable."; 366 << "It shouldn't be possible to re-mmap the descriptor writable.";
367 EXPECT_EQ(EACCES, mmap_errno) << strerror(mmap_errno); 367 EXPECT_EQ(EACCES, mmap_errno) << strerror(mmap_errno);
368 if (writable != MAP_FAILED) 368 if (writable != MAP_FAILED)
369 EXPECT_EQ(0, munmap(writable, readonly_shmem.mapped_size())); 369 EXPECT_EQ(0, munmap(writable, readonly_shmem.mapped_size()));
370 370
371 #elif defined(OS_WIN) 371 #elif defined(OS_WIN)
372 EXPECT_EQ(NULL, MapViewOfFile(handle, FILE_MAP_WRITE, 0, 0, 0)) 372 EXPECT_EQ(NULL, MapViewOfFile(handle.GetHandle(), FILE_MAP_WRITE, 0, 0, 0))
373 << "Shouldn't be able to map memory writable."; 373 << "Shouldn't be able to map memory writable.";
374 374
375 HANDLE temp_handle; 375 HANDLE temp_handle;
376 BOOL rv = ::DuplicateHandle(GetCurrentProcess(), 376 BOOL rv = ::DuplicateHandle(GetCurrentProcess(), handle.GetHandle(),
377 handle, 377 GetCurrentProcess(), &temp_handle,
378 GetCurrentProcess(), 378 FILE_MAP_ALL_ACCESS, false, 0);
379 &temp_handle,
380 FILE_MAP_ALL_ACCESS,
381 false,
382 0);
383 EXPECT_EQ(FALSE, rv) 379 EXPECT_EQ(FALSE, rv)
384 << "Shouldn't be able to duplicate the handle into a writable one."; 380 << "Shouldn't be able to duplicate the handle into a writable one.";
385 if (rv) 381 if (rv)
386 win::ScopedHandle writable_handle(temp_handle); 382 win::ScopedHandle writable_handle(temp_handle);
387 rv = ::DuplicateHandle(GetCurrentProcess(), 383 rv = ::DuplicateHandle(GetCurrentProcess(), handle.GetHandle(),
388 handle, 384 GetCurrentProcess(), &temp_handle, FILE_MAP_READ,
389 GetCurrentProcess(), 385 false, 0);
390 &temp_handle,
391 FILE_MAP_READ,
392 false,
393 0);
394 EXPECT_EQ(TRUE, rv) 386 EXPECT_EQ(TRUE, rv)
395 << "Should be able to duplicate the handle into a readable one."; 387 << "Should be able to duplicate the handle into a readable one.";
396 if (rv) 388 if (rv)
397 win::ScopedHandle writable_handle(temp_handle); 389 win::ScopedHandle writable_handle(temp_handle);
398 #else 390 #else
399 #error Unexpected platform; write a test that tries to make 'handle' writable. 391 #error Unexpected platform; write a test that tries to make 'handle' writable.
400 #endif // defined(OS_POSIX) || defined(OS_WIN) 392 #endif // defined(OS_POSIX) || defined(OS_WIN)
401 } 393 }
402 394
403 TEST(SharedMemoryTest, ShareToSelf) { 395 TEST(SharedMemoryTest, ShareToSelf) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 memory.Close(); 628 memory.Close();
637 SharedMemoryProcessTest::CleanUp(); 629 SharedMemoryProcessTest::CleanUp();
638 } 630 }
639 631
640 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) { 632 MULTIPROCESS_TEST_MAIN(SharedMemoryTestMain) {
641 return SharedMemoryProcessTest::TaskTestMain(); 633 return SharedMemoryProcessTest::TaskTestMain();
642 } 634 }
643 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX) 635 #endif // !defined(OS_IOS) && !defined(OS_ANDROID) && !defined(OS_MACOSX)
644 636
645 } // namespace base 637 } // 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