From: "Olivier F. R. Dierick" Subject: shell32/tests: Tests for broken apps that check GetLastError() after SHFileOperation() Message-Id: <1461420241.8506.16.camel@piezo3.piezo-forte.be> Date: Sat, 23 Apr 2016 16:04:01 +0200 See bug 36838 for comments and discussion. Supersedes patch submission 121605. Changes include adding a test in case of a failing file copy and testing the unicode version of SHFileOperation() too. Signed-off-by: Olivier F. R. Dierick --- dlls/shell32/tests/shlfileop.c | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) -- Olivier F. R. Dierick o.dierick@piezo-forte.be From 31aa26b14f4a6e54fff0b6668200f84b941c2581 Mon Sep 17 00:00:00 2001 From: "Olivier F. R. Dierick" Date: Sat, 23 Apr 2016 02:23:54 +0200 Subject: shell32/tests: Tests for broken apps that check GetLastError() after SHFileOperation() --- dlls/shell32/tests/shlfileop.c | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/dlls/shell32/tests/shlfileop.c b/dlls/shell32/tests/shlfileop.c index d33ad5b..a329bb6 100644 --- a/dlls/shell32/tests/shlfileop.c +++ b/dlls/shell32/tests/shlfileop.c @@ -1819,6 +1819,34 @@ static void test_copy(void) ok(DeleteFileA("abcdefgh.abc"), "Expected file to exist\n"); ok(DeleteFileA("dir\\abcdefgh.abc"), "Expected file to exist\n"); ok(RemoveDirectoryA("dir"), "Expected dir to exist\n"); + + /* Following tests are for broken apps that call GetLastError() after + * a file copy operation (see bug 36838). + */ + + /* Check last error after a successful file operation. */ + clean_after_shfo_tests(); + init_shfo_tests(); + shfo.pFrom = "test1.txt\0"; + shfo.pTo = "testdir2\0"; + shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI; + SetLastError(0xdeadbeef); + retval = SHFileOperationA(&shfo); + ok(retval == ERROR_SUCCESS, "File copy failed with %d\n", retval); + ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n"); + ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); + + /* Check last error after a failed file operation. */ + clean_after_shfo_tests(); + init_shfo_tests(); + shfo.pFrom = "nonexistent\0"; + shfo.pTo = "testdir2\0"; + shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI; + SetLastError(0xdeadbeef); + retval = SHFileOperationA(&shfo); + ok(retval != ERROR_SUCCESS, "Unexpected ERROR_SUCCESS\n"); + ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n"); + ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError()); } /* tests the FO_MOVE action */ @@ -2464,6 +2492,7 @@ static void test_unicode(void) SHFILEOPSTRUCTW shfoW; int ret; HANDLE file; + WCHAR UNICODE_PATH_TO[] = {'c',':','\\',0x00ae,0x00ae,'\0'}; if (!pSHFileOperationW) { @@ -2530,6 +2559,40 @@ static void test_unicode(void) ret = pSHFileOperationW(&shfoW); ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret); ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n"); + + /* Following tests are for broken apps that call GetLastError() after + * a file copy operation (see bug 36838). + */ + + shfoW.hwnd = NULL; + shfoW.wFunc = FO_COPY; + shfoW.pFrom = UNICODE_PATH; + shfoW.pTo = UNICODE_PATH_TO; + shfoW.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI; + shfoW.hNameMappings = NULL; + shfoW.lpszProgressTitle = NULL; + + /* Check last error after a successful file operation. */ + createTestFileW(UNICODE_PATH); + ok(file_existsW(UNICODE_PATH), "The file does not exist\n"); + SetLastError(0xdeadbeef); + ret = SHFileOperationW(&shfoW); + ok(ret == ERROR_SUCCESS, "File copy failed with %d\n", ret); + ok(!shfoW.fAnyOperationsAborted, "Didn't expect aborted operations\n"); + ok(GetLastError() == ERROR_SUCCESS || + broken(GetLastError() == ERROR_INVALID_HANDLE), /* WinXp, win2k3 */ + "Expected ERROR_SUCCESS, got %d\n", GetLastError()); + + /* Check last error after a failed file operation. */ + DeleteFileW(UNICODE_PATH); + ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n"); + SetLastError(0xdeadbeef); + ret = SHFileOperationW(&shfoW); + ok(ret != ERROR_SUCCESS, "Unexpected ERROR_SUCCESS\n"); + ok(!shfoW.fAnyOperationsAborted, "Didn't expect aborted operations\n"); + ok(GetLastError() == ERROR_SUCCESS || + broken(GetLastError() == ERROR_INVALID_HANDLE), /* WinXp, win2k3 */ + "Expected ERROR_SUCCESS, got %d\n", GetLastError()); } static void -- 1.7.10.4