Make dlls-kernel-tests-file.c work on Windows 95 and XP.
Jakob Eriksson
jakov at vmlinux.org
Sat Apr 24 10:35:10 CDT 2004
This patch makes "kernel32_crosstest.exe file" work without a hitch on both
Windows XP and Windows 95.
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 24 Apr 2004 15:31:51 -0000
@@ -28,6 +28,8 @@
#include "winbase.h"
#include "winerror.h"
+static int win9x_based;
+
LPCSTR filename = "testfile.xxx";
LPCSTR sillytext =
"en larvig liten text dx \033 gx hej 84 hej 4484 ! \001\033 bla bl\na.. bla bla."
@@ -681,7 +683,8 @@
ret = DeleteFileA("nul");
ok(!ret && (GetLastError() == ERROR_FILE_NOT_FOUND ||
- GetLastError() == ERROR_INVALID_PARAMETER),
+ GetLastError() == ERROR_INVALID_PARAMETER ||
+ GetLastError() == ERROR_ACCESS_DENIED),
"DeleteFileA(\"nul\") returned ret=%d error=%ld\n",ret,GetLastError());
}
@@ -897,7 +900,8 @@
ok( LockFile( handle, 0, 0, 0, 0 ), "LockFile failed\n" );
ok( UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile failed\n" );
- ok( !UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile succeeded\n" );
+
+ win9x_based || ok( !UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile succeeded\n" );
ok( LockFile( handle, 10, 0, 20, 0 ), "LockFile 10,20 failed\n" );
/* overlapping locks must fail */
@@ -914,17 +918,17 @@
overlapped.Offset = 100;
overlapped.OffsetHigh = 0;
overlapped.hEvent = 0;
- ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 100,100 failed\n" );
+ win9x_based || ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 100,100 failed\n" );
/* overlapping shared locks are OK */
overlapped.Offset = 150;
- ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 150,100 failed\n" );
+ win9x_based || ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 150,100 failed\n" );
/* but exclusive is not */
ok( !LockFileEx( handle, LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY, 0, 50, 0, &overlapped ),
"LockFileEx exclusive 150,50 succeeded\n" );
- ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 150,100 failed\n" );
+ win9x_based || ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 150,100 failed\n" );
ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 150,100 again succeeded\n" );
overlapped.Offset = 100;
- ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 100,100 failed\n" );
+ win9x_based || ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 100,100 failed\n" );
ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 100,100 again succeeded\n" );
ok( LockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "LockFile failed\n" );
@@ -935,16 +939,16 @@
/* wrap-around lock should not do anything */
/* (but still succeeds on NT4 so we don't check result) */
LockFile( handle, 0, 0x10000000, 0, 0xf0000001 );
- ok( LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 failed\n" );
- ok( UnlockFile( handle, ~0, ~0, 1, 0 ), "Unlockfile ~0,1 failed\n" );
+ win9x_based || ok( LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 failed\n" );
+ win9x_based || ok( UnlockFile( handle, ~0, ~0, 1, 0 ), "Unlockfile ~0,1 failed\n" );
/* zero-byte lock */
ok( LockFile( handle, 100, 0, 0, 0 ), "LockFile 100,0 failed\n" );
- ok( !LockFile( handle, 98, 0, 4, 0 ), "LockFile 98,4 succeeded\n" );
- ok( LockFile( handle, 90, 0, 10, 0 ), "LockFile 90,10 failed\n" );
- ok( LockFile( handle, 100, 0, 10, 0 ), "LockFile 100,10 failed\n" );
- ok( UnlockFile( handle, 90, 0, 10, 0 ), "UnlockFile 90,10 failed\n" );
- ok( UnlockFile( handle, 100, 0, 10, 0 ), "UnlockFile 100,10 failed\n" );
+ win9x_based || ok( !LockFile( handle, 98, 0, 4, 0 ), "LockFile 98,4 succeeded\n" );
+ win9x_based || ok( LockFile( handle, 90, 0, 10, 0 ), "LockFile 90,10 failed\n" );
+ win9x_based || ok( LockFile( handle, 100, 0, 10, 0 ), "LockFile 100,10 failed\n" );
+ win9x_based || ok( UnlockFile( handle, 90, 0, 10, 0 ), "UnlockFile 90,10 failed\n" );
+ win9x_based || ok( UnlockFile( handle, 100, 0, 10, 0 ), "UnlockFile 100,10 failed\n" );
ok( UnlockFile( handle, 100, 0, 0, 0 ), "UnlockFile 100,0 failed\n" );
CloseHandle( handle );
@@ -991,7 +995,7 @@
if (is_sharing_compatible( access_modes[a1], sharing_modes[s1],
access_modes[a2], sharing_modes[s2] ))
{
- ok( h2 != INVALID_HANDLE_VALUE,
+ win9x_based || ok( h2 != INVALID_HANDLE_VALUE,
"open failed for modes %lx/%lx/%lx/%lx err %ld\n",
access_modes[a1], sharing_modes[s1],
access_modes[a2], sharing_modes[s2], GetLastError() );
@@ -1048,18 +1052,45 @@
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;
+
+ ok(test_Mapfile_createtemp(&handle), "Couldn't create test file.\n");
+
+ hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0x1000, "named_file_map" );
+ ok( hmap != NULL, "mapping should work, I named it!\n" );
+
+ ok( CloseHandle( hmap ), "can't close mapping handle\n");
+ /* We have to close file before we try new stuff with mapping again.
+ Else we would always succeed on XP or block descriptors on 95. */
hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0, NULL );
+ ok( hmap != NULL, "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");
@@ -1071,10 +1102,8 @@
ok( hmap == NULL, "mapping should fail\n");
/* GetLastError() varies between win9x and WinNT */
- hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0x1000, NULL );
- ok( hmap != NULL, "mapping should succeed\n");
+ /* On XP you can now map again, on Win 95 you can not. */
- 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" );
}
@@ -1095,8 +1124,25 @@
DeleteFileA( filename );
}
+static int test_win9x_based()
+{
+ OSVERSIONINFOEX ver;
+
+ ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ ok( GetVersionEx ((OSVERSIONINFO *) &ver), " --- Can't get OS version.\n" );
+ if ((4 == ver.dwMajorVersion && 0 == ver.dwMinorVersion && 1381 == ver.dwBuildNumber)
+ || ver.dwMajorVersion >= 5)
+ {
+ return 0;
+ }
+
+ return 1;
+}
+
START_TEST(file)
{
+ win9x_based = test_win9x_based();
+
test__hread( );
test__hwrite( );
test__lclose( );
More information about the wine-patches
mailing list