dlls/kernel/tests/file.c
Jakob Eriksson
jakov at vmlinux.org
Tue Apr 27 08:36:05 CDT 2004
Resending diff against current CVS:
-------------- next part --------------
Index: file.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/tests/file.c,v
retrieving revision 1.37
diff -u -r1.37 file.c
--- file.c 27 Apr 2004 02:27:47 -0000 1.37
+++ file.c 27 Apr 2004 13:34:29 -0000
@@ -1,7 +1,7 @@
/*
* Unit tests for file functions in Wine
*
- * Copyright (c) 2002 Jakob Eriksson
+ * Copyright (c) 2002, 2004 Jakob Eriksson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -28,6 +28,15 @@
#include "winbase.h"
#include "winerror.h"
+static int dll_capable(const char *dll, const char *function)
+{
+ HMODULE module = GetModuleHandleA(dll);
+ if (!module) return 0;
+
+ return (GetProcAddress(module, function) != NULL);
+}
+
+
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 +690,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());
}
@@ -879,6 +889,9 @@
HANDLE handle;
DWORD written;
OVERLAPPED overlapped;
+ int limited_LockFile;
+ int limited_UnLockFile;
+ int lockfileex_capable;
handle = CreateFileA( filename, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
@@ -892,7 +905,12 @@
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" );
+
+ limited_UnLockFile = 0;
+ if (UnlockFile( handle, 0, 0, 0, 0 ))
+ {
+ limited_UnLockFile = 1;
+ }
ok( LockFile( handle, 10, 0, 20, 0 ), "LockFile 10,20 failed\n" );
/* overlapping locks must fail */
@@ -909,18 +927,39 @@
overlapped.Offset = 100;
overlapped.OffsetHigh = 0;
overlapped.hEvent = 0;
- ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 100,100 failed\n" );
+
+ lockfileex_capable = dll_capable("kernel32", "LockFileEx");
+ if (lockfileex_capable)
+ {
+ /* Test for broken LockFileEx a la Windows 95 OSR2. */
+ if (LockFileEx( handle, 0, 0, 100, 0, &overlapped ))
+ {
+ /* LockFileEx is probably OK, test it more. */
+ 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" );
+ limited_UnLockFile || 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" );
- 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" );
- ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 100,100 again succeeded\n" );
+ if (lockfileex_capable)
+ {
+ ok( !LockFileEx( handle, LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
+ 0, 50, 0, &overlapped ),
+ "LockFileEx exclusive 150,50 succeeded\n" );
+ if (dll_capable("kernel32.dll", "UnlockFileEx"))
+ {
+ if (!UnlockFileEx( handle, 0, 100, 0, &overlapped ))
+ { /* UnLockFile is capable. */
+ overlapped.Offset = 100;
+ ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ),
+ "UnlockFileEx 150,100 again succeeded\n" );
+ }
+ }
+ }
ok( LockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "LockFile failed\n" );
ok( !LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 succeeded\n" );
@@ -930,16 +969,24 @@
/* 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" );
+
+ limited_LockFile = 0;
+ if (!LockFile( handle, ~0, ~0, 1, 0 ))
+ {
+ limited_LockFile = 1;
+ }
+
+ limited_UnLockFile || 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" );
+ limited_LockFile || 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" );
+ limited_LockFile || 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" );
+ !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 );
@@ -961,6 +1008,7 @@
static const DWORD access_modes[4] = { 0, GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE };
static const DWORD sharing_modes[4] = { 0, FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE };
int a1, s1, a2, s2;
+ int ret;
/* make sure the file exists */
HANDLE h = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
@@ -986,10 +1034,17 @@
if (is_sharing_compatible( access_modes[a1], sharing_modes[s1],
access_modes[a2], sharing_modes[s2] ))
{
- ok( h2 != INVALID_HANDLE_VALUE,
- "open failed for modes %lx/%lx/%lx/%lx err %ld\n",
+ ret = GetLastError();
+ ok( ERROR_SHARING_VIOLATION == ret || 0 == ret,
+ "Windows 95 sets GetLastError() = ERROR_SHARING_VIOLATION and\n"
+ " Windows XP GetLastError() = 0, but now it is %d.\n"
+ " indexes = %d, %d, %d, %d\n"
+ " modes =\n %lx/%lx/%lx/%lx\n",
+ ret,
+ a1, s1, a2, s2,
access_modes[a1], sharing_modes[s1],
- access_modes[a2], sharing_modes[s2], GetLastError() );
+ access_modes[a2], sharing_modes[s2]
+ );
}
else
{
@@ -1043,33 +1098,63 @@
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;
+ int ret;
+
+ 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");
hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0x1000, 0, NULL );
ok( hmap == NULL, "mapping should fail\n");
- /* GetLastError() varies between win9x and WinNT */
+ ret = GetLastError();
+ ok( ERROR_NOT_ENOUGH_MEMORY == ret || ERROR_NETNAME_DELETED == ret,
+ "GetLastError() = %d\n", ret );
hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0x1000, 0x10000, NULL );
ok( hmap == NULL, "mapping should fail\n");
- /* GetLastError() varies between win9x and WinNT */
+ ret = GetLastError();
+ ok( ERROR_NOT_ENOUGH_MEMORY == ret || ERROR_NETNAME_DELETED == ret,
+ "GetLastError() = %d\n", ret );
- 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" );
}
More information about the wine-patches
mailing list