kernel32/tests: Add more tests for ReplaceFileA().

Also remove residue test files and remove no effect tests.

Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zhiyi Zhang 2019-04-09 23:54:13 +08:00 committed by Alexandre Julliard
parent 304fb43aaa
commit 57e8e2d59c
1 changed files with 25 additions and 8 deletions

View File

@ -3664,6 +3664,7 @@ static void test_ReplaceFileA(void)
"ReplaceFileA: unexpected error %d\n", GetLastError()); "ReplaceFileA: unexpected error %d\n", GetLastError());
/* re-create replacement file for pass w/ backup (backup-file not existing) */ /* re-create replacement file for pass w/ backup (backup-file not existing) */
DeleteFileA(replacement);
ret = GetTempFileNameA(temp_path, prefix, 0, replacement); ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
ok(ret != 0, "GetTempFileNameA error (replacement) %d\n", GetLastError()); ok(ret != 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
ret = DeleteFileA(backup); ret = DeleteFileA(backup);
@ -3679,6 +3680,7 @@ static void test_ReplaceFileA(void)
removeBackup = TRUE; removeBackup = TRUE;
/* re-create replacement file for pass w/ no permissions to "replaced" */ /* re-create replacement file for pass w/ no permissions to "replaced" */
DeleteFileA(replacement);
ret = GetTempFileNameA(temp_path, prefix, 0, replacement); ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
ok(ret != 0, "GetTempFileNameA error (replacement) %d\n", GetLastError()); ok(ret != 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
ret = SetFileAttributesA(replaced, FILE_ATTRIBUTE_READONLY); ret = SetFileAttributesA(replaced, FILE_ATTRIBUTE_READONLY);
@ -3700,21 +3702,25 @@ static void test_ReplaceFileA(void)
ok(ret || GetLastError() == ERROR_ACCESS_DENIED, ok(ret || GetLastError() == ERROR_ACCESS_DENIED,
"SetFileAttributesA: error setting to normal %d\n", GetLastError()); "SetFileAttributesA: error setting to normal %d\n", GetLastError());
/* replacement readonly */
DeleteFileA(replacement);
ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
ok(ret != 0, "GetTempFileNameA error (replacement) %#x\n", GetLastError());
ret = SetFileAttributesA(replacement, FILE_ATTRIBUTE_READONLY);
ok(ret, "SetFileAttributesA: error setting to readonly %#x\n", GetLastError());
ret = pReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
ok(GetLastError() == ERROR_ACCESS_DENIED, "ReplaceFileA: unexpected error %#x\n", GetLastError());
ret = SetFileAttributesA(replacement, FILE_ATTRIBUTE_NORMAL);
ok(ret, "SetFileAttributesA: error setting to normal %#x\n", GetLastError());
/* re-create replacement file for pass w/ replaced opened with /* re-create replacement file for pass w/ replaced opened with
* the same permissions as an exe (Replicating an exe trying to * the same permissions as an exe (Replicating an exe trying to
* replace itself) * replace itself)
*/ */
DeleteFileA(replacement);
ret = GetTempFileNameA(temp_path, prefix, 0, replacement); ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
ok(ret != 0, "GetTempFileNameA error (replacement) %d\n", GetLastError()); ok(ret != 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
SetLastError(0xdeadbeef);
/* make sure that the replacement file still exists */
hReplacementFile = CreateFileA(replacement, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
ok(hReplacementFile != INVALID_HANDLE_VALUE ||
broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* win2k */
"unexpected error, replacement file should still exist %d\n", GetLastError());
CloseHandle(hReplacementFile);
/* make sure that the replaced file is opened like an exe*/ /* make sure that the replaced file is opened like an exe*/
hReplacedFile = CreateFileA(replaced, GENERIC_READ | SYNCHRONIZE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, 0); hReplacedFile = CreateFileA(replaced, GENERIC_READ | SYNCHRONIZE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, 0);
ok(hReplacedFile != INVALID_HANDLE_VALUE, ok(hReplacedFile != INVALID_HANDLE_VALUE,
@ -3724,6 +3730,17 @@ static void test_ReplaceFileA(void)
todo_wine ok(ret, "ReplaceFileA: unexpected error %d\n", GetLastError()); todo_wine ok(ret, "ReplaceFileA: unexpected error %d\n", GetLastError());
CloseHandle(hReplacedFile); CloseHandle(hReplacedFile);
/* replace file while replacement is opened */
ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
ok(ret != 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
CreateFileA(replacement, GENERIC_READ | SYNCHRONIZE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, 0);
ok(hReplacementFile != INVALID_HANDLE_VALUE, "unexpected error, replacement file should be able to be opened %d\n",
GetLastError());
ret = pReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
ok(!ret, "expect failure\n");
ok(GetLastError() == ERROR_SHARING_VIOLATION, "expect ERROR_SHARING_VIOLATION, got %#x.\n", GetLastError());
CloseHandle(hReplacedFile);
/* replacement file still exists, make pass w/o "replaced" */ /* replacement file still exists, make pass w/o "replaced" */
ret = DeleteFileA(replaced); ret = DeleteFileA(replaced);
ok(ret || GetLastError() == ERROR_ACCESS_DENIED, ok(ret || GetLastError() == ERROR_ACCESS_DENIED,