kernel32: Add a test for read-only mapping of a write-only section, test actual page access rights of the mapping

Dmitry Timoshkov dmitry at codeweavers.com
Mon Sep 24 09:41:08 CDT 2007


Hello,

this test passes under XP SP2.

Changelog:
    kernel32: Add a test for read-only mapping of a write-only section,
    test actual page access rights of the mapping.

---
 dlls/kernel32/tests/virtual.c |   38 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c
index 78c5643..56f2af9 100644
--- a/dlls/kernel32/tests/virtual.c
+++ b/dlls/kernel32/tests/virtual.c
@@ -84,7 +84,7 @@ static void test_VirtualAllocEx(void)
     src = HeapAlloc( GetProcessHeap(), 0, alloc_size );
     dst = HeapAlloc( GetProcessHeap(), 0, alloc_size );
     for (i = 0; i < alloc_size; i++)
-        src[i] = i & 0xff;
+        src[i] = (char)(i & 0xff);
 
     ok(addr1 != NULL, "VirtualAllocEx error %u\n", GetLastError());
     b = WriteProcessMemory(hProcess, addr1, src, alloc_size, &bytes_written);
@@ -271,6 +271,7 @@ static void test_MapViewOfFile(void)
     static const char testfile[] = "testfile.xxx";
     HANDLE file, mapping;
     void *ptr;
+    MEMORY_BASIC_INFORMATION info;
 
     SetLastError(0xdeadbeef);
     file = CreateFileA( testfile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
@@ -457,6 +458,41 @@ static void test_MapViewOfFile(void)
     ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 0 );
 todo_wine ok( !ptr, "MapViewOfFile FILE_MAP_WRITE should fail\n" );
 todo_wine ok( GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
+    SetLastError(0xdeadbeef);
+    ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
+    ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ error %u\n", GetLastError() );
+    SetLastError(0xdeadbeef);
+    ok( VirtualQuery( ptr, &info, sizeof(info) ) == sizeof(info),
+        "VirtualQuery error %u\n", GetLastError() );
+    ok( info.BaseAddress == ptr, "%p != %p\n", info.BaseAddress, ptr );
+    ok( info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr );
+todo_wine ok( info.AllocationProtect == PAGE_READONLY, "%x != PAGE_READONLY\n", info.AllocationProtect );
+    ok( info.RegionSize == 4096, "%lx != 4096\n", info.RegionSize );
+    ok( info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State );
+todo_wine ok( info.Protect == PAGE_READONLY, "%x != PAGE_READONLY\n", info.Protect );
+    UnmapViewOfFile( ptr );
+    CloseHandle( mapping );
+
+    SetLastError(0xdeadbeef);
+    mapping = OpenFileMapping( FILE_MAP_WRITE, FALSE, "Global\\Foo" );
+    ok( mapping != 0, "OpenFileMapping FILE_MAP_WRITE error %u\n", GetLastError() );
+    SetLastError(0xdeadbeef);
+    ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
+todo_wine ok( !ptr, "MapViewOfFile FILE_MAP_READ should fail\n" );
+todo_wine ok( GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %d\n", GetLastError() );
+    SetLastError(0xdeadbeef);
+    ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 0 );
+    ok( ptr != NULL, "MapViewOfFile FILE_MAP_WRITE error %u\n", GetLastError() );
+    SetLastError(0xdeadbeef);
+    ok( VirtualQuery( ptr, &info, sizeof(info) ) == sizeof(info),
+        "VirtualQuery error %u\n", GetLastError() );
+    ok( info.BaseAddress == ptr, "%p != %p\n", info.BaseAddress, ptr );
+    ok( info.AllocationBase == ptr, "%p != %p\n", info.AllocationBase, ptr );
+    ok( info.AllocationProtect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.AllocationProtect );
+    ok( info.RegionSize == 4096, "%lx != 4096\n", info.RegionSize );
+    ok( info.State == MEM_COMMIT, "%x != MEM_COMMIT\n", info.State );
+    ok( info.Protect == PAGE_READWRITE, "%x != PAGE_READWRITE\n", info.Protect );
+    UnmapViewOfFile( ptr );
     CloseHandle( mapping );
 
     CloseHandle( file );
-- 
1.5.3.2






More information about the wine-patches mailing list