From b2a302b667579fd22157be07a8e21673c038b092 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Fri, 7 Oct 2011 21:01:27 +0400 Subject: [PATCH] kernel32/tests: Shared lock can overlap exclusive if handles are equal. --- dlls/kernel32/tests/file.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 772e439bb76..f607cfd1eb5 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -1591,7 +1591,7 @@ static void test_offset_in_overlapped_structure(void) static void test_LockFile(void) { - HANDLE handle; + HANDLE handle, handle2; DWORD written; OVERLAPPED overlapped; int limited_LockFile; @@ -1606,6 +1606,14 @@ static void test_LockFile(void) ok(0,"couldn't create file \"%s\" (err=%d)\n",filename,GetLastError()); return; } + handle2 = CreateFileA( filename, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, 0 ); + if (handle2 == INVALID_HANDLE_VALUE) + { + ok( 0, "couldn't open file \"%s\" (err=%d)\n", filename, GetLastError() ); + goto cleanup; + } ok( WriteFile( handle, sillytext, strlen(sillytext), &written, NULL ), "write failed\n" ); ok( LockFile( handle, 0, 0, 0, 0 ), "LockFile failed\n" ); @@ -1656,6 +1664,23 @@ static void test_LockFile(void) "UnlockFileEx 150,100 again succeeded\n" ); } + /* shared lock can overlap exclusive if handles are equal */ + S(U(overlapped)).Offset = 300; + ok( LockFileEx( handle, LOCKFILE_EXCLUSIVE_LOCK, 0, 100, 0, &overlapped ), + "LockFileEx exclusive 300,100 failed\n" ); + ok( !LockFileEx( handle2, LOCKFILE_FAIL_IMMEDIATELY, 0, 100, 0, &overlapped ), + "LockFileEx handle2 300,100 succeeded\n" ); + ret = LockFileEx( handle, LOCKFILE_FAIL_IMMEDIATELY, 0, 100, 0, &overlapped ); + todo_wine + ok( ret, "LockFileEx 300,100 failed\n" ); + ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 300,100 failed\n" ); + /* exclusive lock is removed first */ + ok( LockFileEx( handle2, LOCKFILE_FAIL_IMMEDIATELY, 0, 100, 0, &overlapped ), + "LockFileEx handle2 300,100 failed\n" ); + ok( UnlockFileEx( handle2, 0, 100, 0, &overlapped ), "UnlockFileEx 300,100 failed\n" ); + if (ret) + ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 300,100 failed\n" ); + ret = LockFile( handle, 0, 0x10000000, 0, 0xf0000000 ); if (ret) { @@ -1689,6 +1714,8 @@ static void test_LockFile(void) ok( UnlockFile( handle, 100, 0, 0, 0 ), "UnlockFile 100,0 failed\n" ); + CloseHandle( handle2 ); +cleanup: CloseHandle( handle ); DeleteFileA( filename ); } -- 2.11.4.GIT