Fix for test of CreateFileMapping in dlls/kernel/tests/file.c

Jakob Eriksson jakov at vmlinux.org
Fri Apr 23 17:54:41 CDT 2004


 From a run of winetest 20040423 on Windows XP:

file.c:1075: Test failed: mapping should succeed
file.c:1077: Test failed: can't close mapping handle
file: 487696 tests executed, 0 marked as todo, 2 failures.



Seems CreateFileMapping has some seriously strange behaviour.
I tested some more how XP behaves and produced a patch based on that.


regards,
Jakob

-------------- next part --------------
Index: file.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/tests/file.c,v
retrieving revision 1.36
diff -u -r1.36 file.c
--- file.c	22 Apr 2004 23:44:14 -0000	1.36
+++ file.c	23 Apr 2004 22:51:41 -0000
@@ -1048,18 +1048,51 @@
     ok ( err == ERROR_NO_MORE_FILES, "GetLastError should return ERROR_NO_MORE_FILES\n");
 }
 
-static void test_MapFile()
+static int test_Mapfile_createtemp(HANDLE *handle)
 {
-    HANDLE handle, hmap;
-
-    /* be sure to remove stale files */
     SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL);
     DeleteFile(filename);
-    handle = CreateFile( filename, GENERIC_READ|GENERIC_WRITE, 0, 0,
-                         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
-    ok( handle != INVALID_HANDLE_VALUE, "couldn't create test file\n");
+    *handle = CreateFile(filename, GENERIC_READ|GENERIC_WRITE, 0, 0,
+                         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+    if (handle != INVALID_HANDLE_VALUE) {
+
+        return 1;
+    }
+
+    return 0;
+}
 
+static void test_MapFile()
+{
+    HANDLE handle;
+    HANDLE hmap;
+    HANDLE hmap_2;
+
+    ok(test_Mapfile_createtemp(&handle), "Couldn't create test file.\n");
+
+    hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0x1000, "named_file_map" );
+    ok( hmap, "mapping should work, I named it!\n" );
+
+    hmap_2 = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0, NULL );
+    ok( hmap_2,
+        "Map is already created, for some reason we should be able to remap now...\n" );
+
+    ok( CloseHandle( hmap ), "can't close mapping handle\n");
+    ok( CloseHandle( hmap_2 ), "can't close mapping handle\n");
+
+    /* We have to close file before we try new stuff with mapping again.
+	   Else we would always succeed. */
     hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0, NULL );
+    ok( hmap, "We should still be able to map!\n" );
+    ok( CloseHandle( hmap ), "can't close mapping handle\n");
+    ok( CloseHandle( handle ), "can't close file handle\n");
+    handle = NULL;
+
+	ok(test_Mapfile_createtemp(&handle), "Couldn't create test file.\n");
+
+    hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0, NULL );
+    ok( hmap == NULL, "Mapping should not work, no name provided.\n" );
+
     ok( hmap == NULL, "mapped zero size file\n");
     ok( GetLastError() == ERROR_FILE_INVALID, "not ERROR_FILE_INVALID\n");
 
@@ -1072,9 +1105,8 @@
     /* GetLastError() varies between win9x and WinNT */
 
     hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0x1000, NULL );
-    ok( hmap != NULL, "mapping should succeed\n");
+    ok( hmap == NULL, "mapping should fail\n" );
 
-    ok( CloseHandle( hmap ), "can't close mapping handle\n");
     ok( CloseHandle( handle ), "can't close file handle\n");
     ok( DeleteFileA( filename ), "DeleteFile failed after map\n" );
 }


More information about the wine-patches mailing list