2002-08-27 03:34:33 +02:00
|
|
|
/*
|
|
|
|
* Unit test of the SHFileOperation function.
|
|
|
|
*
|
|
|
|
* Copyright 2002 Andriy Palamarchuk
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-08-27 03:34:33 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-08-27 03:34:33 +02:00
|
|
|
#include <stdio.h>
|
2004-10-28 22:58:38 +02:00
|
|
|
|
2003-09-27 05:47:35 +02:00
|
|
|
#define WINE_NOWINSOCK
|
2006-08-24 12:16:01 +02:00
|
|
|
#include <windows.h>
|
2002-10-29 22:24:35 +01:00
|
|
|
#include "shellapi.h"
|
2004-10-28 22:58:38 +02:00
|
|
|
#include "shlobj.h"
|
2002-10-29 22:24:35 +01:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
2002-08-27 03:34:33 +02:00
|
|
|
|
2006-08-24 12:16:01 +02:00
|
|
|
#ifndef FOF_NORECURSION
|
|
|
|
#define FOF_NORECURSION 0x1000
|
|
|
|
#endif
|
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
CHAR CURR_DIR[MAX_PATH];
|
|
|
|
|
2004-12-06 12:45:13 +01:00
|
|
|
static HMODULE hshell32;
|
|
|
|
static int (WINAPI *pSHCreateDirectoryExA)(HWND, LPCSTR, LPSECURITY_ATTRIBUTES);
|
|
|
|
|
|
|
|
static void InitFunctionPointers(void)
|
|
|
|
{
|
|
|
|
hshell32 = GetModuleHandleA("shell32.dll");
|
|
|
|
|
|
|
|
if(hshell32)
|
|
|
|
pSHCreateDirectoryExA = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExA");
|
|
|
|
}
|
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
/* creates a file with the specified name for tests */
|
2005-06-20 12:30:15 +02:00
|
|
|
static void createTestFile(const CHAR *name)
|
2002-08-27 03:34:33 +02:00
|
|
|
{
|
|
|
|
HANDLE file;
|
|
|
|
DWORD written;
|
|
|
|
|
2003-01-15 00:43:41 +01:00
|
|
|
file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
|
2002-08-27 03:34:33 +02:00
|
|
|
WriteFile(file, name, strlen(name), &written, NULL);
|
|
|
|
WriteFile(file, "\n", strlen("\n"), &written, NULL);
|
|
|
|
CloseHandle(file);
|
|
|
|
}
|
|
|
|
|
2005-06-20 12:30:15 +02:00
|
|
|
static BOOL file_exists(const CHAR *name)
|
2002-08-27 03:34:33 +02:00
|
|
|
{
|
2003-10-16 21:12:49 +02:00
|
|
|
return GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES;
|
2002-08-27 03:34:33 +02:00
|
|
|
}
|
|
|
|
|
2007-02-09 17:13:25 +01:00
|
|
|
static BOOL file_has_content(const CHAR *name, const CHAR *content)
|
|
|
|
{
|
|
|
|
CHAR buf[MAX_PATH];
|
|
|
|
HANDLE file;
|
|
|
|
DWORD read;
|
|
|
|
|
|
|
|
file = CreateFileA(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
ReadFile(file, buf, MAX_PATH - 1, &read, NULL);
|
|
|
|
buf[read] = 0;
|
|
|
|
CloseHandle(file);
|
|
|
|
return strcmp(buf, content)==0;
|
|
|
|
}
|
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
/* initializes the tests */
|
2005-06-20 12:30:15 +02:00
|
|
|
static void init_shfo_tests(void)
|
2002-08-27 03:34:33 +02:00
|
|
|
{
|
2005-08-08 20:03:47 +02:00
|
|
|
int len;
|
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
|
2005-08-08 20:03:47 +02:00
|
|
|
len = lstrlenA(CURR_DIR);
|
|
|
|
|
|
|
|
if(len && (CURR_DIR[len-1] == '\\'))
|
|
|
|
CURR_DIR[len-1] = 0;
|
|
|
|
|
2005-12-21 21:18:19 +01:00
|
|
|
createTestFile("test1.txt");
|
|
|
|
createTestFile("test2.txt");
|
|
|
|
createTestFile("test3.txt");
|
2005-12-26 12:56:06 +01:00
|
|
|
createTestFile("test_5.txt");
|
2005-12-21 21:18:19 +01:00
|
|
|
CreateDirectoryA("test4.txt", NULL);
|
|
|
|
CreateDirectoryA("testdir2", NULL);
|
2005-12-26 12:56:06 +01:00
|
|
|
CreateDirectoryA("testdir2\\nested", NULL);
|
|
|
|
createTestFile("testdir2\\one.txt");
|
|
|
|
createTestFile("testdir2\\nested\\two.txt");
|
2002-08-27 03:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cleans after tests */
|
2005-06-20 12:30:15 +02:00
|
|
|
static void clean_after_shfo_tests(void)
|
2002-08-27 03:34:33 +02:00
|
|
|
{
|
2005-12-21 21:18:19 +01:00
|
|
|
DeleteFileA("test1.txt");
|
|
|
|
DeleteFileA("test2.txt");
|
|
|
|
DeleteFileA("test3.txt");
|
2005-12-26 12:56:06 +01:00
|
|
|
DeleteFileA("test_5.txt");
|
2007-02-09 17:13:25 +01:00
|
|
|
DeleteFileA("one.txt");
|
2005-12-21 21:18:19 +01:00
|
|
|
DeleteFileA("test4.txt\\test1.txt");
|
|
|
|
DeleteFileA("test4.txt\\test2.txt");
|
|
|
|
DeleteFileA("test4.txt\\test3.txt");
|
|
|
|
RemoveDirectoryA("test4.txt");
|
2005-12-26 12:56:06 +01:00
|
|
|
DeleteFileA("testdir2\\one.txt");
|
2005-12-21 21:18:19 +01:00
|
|
|
DeleteFileA("testdir2\\test1.txt");
|
|
|
|
DeleteFileA("testdir2\\test2.txt");
|
|
|
|
DeleteFileA("testdir2\\test3.txt");
|
|
|
|
DeleteFileA("testdir2\\test4.txt\\test1.txt");
|
2005-12-26 12:56:06 +01:00
|
|
|
DeleteFileA("testdir2\\nested\\two.txt");
|
2005-12-21 21:18:19 +01:00
|
|
|
RemoveDirectoryA("testdir2\\test4.txt");
|
2005-12-26 12:56:06 +01:00
|
|
|
RemoveDirectoryA("testdir2\\nested");
|
2005-12-21 21:18:19 +01:00
|
|
|
RemoveDirectoryA("testdir2");
|
2006-06-07 21:08:27 +02:00
|
|
|
RemoveDirectoryA("c:\\testdir3");
|
2005-12-26 12:56:06 +01:00
|
|
|
DeleteFileA("nonexistent\\notreal\\test2.txt");
|
|
|
|
RemoveDirectoryA("nonexistent\\notreal");
|
2005-12-21 21:18:19 +01:00
|
|
|
RemoveDirectoryA("nonexistent");
|
2002-08-27 03:34:33 +02:00
|
|
|
}
|
|
|
|
|
2007-01-06 19:24:06 +01:00
|
|
|
|
|
|
|
static void test_get_file_info(void)
|
|
|
|
{
|
2007-01-18 16:23:05 +01:00
|
|
|
DWORD rc, rc2;
|
|
|
|
SHFILEINFO shfi, shfi2;
|
|
|
|
char notepad[MAX_PATH];
|
|
|
|
|
|
|
|
/* Test some flag combinations that MSDN claims are not allowed,
|
|
|
|
* but which work anyway
|
|
|
|
*/
|
|
|
|
shfi.dwAttributes=0xdeadbeef;
|
|
|
|
rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
|
|
|
|
&shfi, sizeof(shfi),
|
|
|
|
SHGFI_ATTRIBUTES | SHGFI_USEFILEATTRIBUTES);
|
|
|
|
todo_wine ok(rc, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) failed\n");
|
|
|
|
if (rc)
|
|
|
|
ok(shfi.dwAttributes != 0xdeadbeef, "dwFileAttributes is not set\n");
|
2007-01-06 19:24:06 +01:00
|
|
|
|
2007-01-18 16:23:05 +01:00
|
|
|
rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
|
|
|
|
&shfi, sizeof(shfi),
|
|
|
|
SHGFI_EXETYPE | SHGFI_USEFILEATTRIBUTES);
|
|
|
|
todo_wine ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) returned %d\n", rc);
|
|
|
|
|
|
|
|
/* Test SHGFI_USEFILEATTRIBUTES support */
|
2007-01-06 19:24:06 +01:00
|
|
|
strcpy(shfi.szDisplayName, "dummy");
|
|
|
|
shfi.iIcon=0xdeadbeef;
|
|
|
|
rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
|
|
|
|
&shfi, sizeof(shfi),
|
|
|
|
SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
|
2007-01-18 16:23:30 +01:00
|
|
|
ok(rc, "SHGetFileInfoA(c:\\nonexistent) failed\n");
|
2007-01-06 19:24:06 +01:00
|
|
|
if (rc)
|
|
|
|
{
|
|
|
|
ok(strcpy(shfi.szDisplayName, "dummy") != 0, "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
|
|
|
|
ok(shfi.iIcon != 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
|
|
|
|
}
|
2007-01-18 16:23:05 +01:00
|
|
|
|
|
|
|
/* Wine does not have a default icon for text files, and Windows 98 fails
|
|
|
|
* if we give it an empty executable. So use notepad.exe as the test
|
|
|
|
*/
|
|
|
|
if (SearchPath(NULL, "notepad.exe", NULL, sizeof(notepad), notepad, NULL))
|
|
|
|
{
|
|
|
|
strcpy(shfi.szDisplayName, "dummy");
|
|
|
|
shfi.iIcon=0xdeadbeef;
|
|
|
|
rc=SHGetFileInfoA(notepad, GetFileAttributes(notepad),
|
|
|
|
&shfi, sizeof(shfi),
|
|
|
|
SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
|
2007-01-18 16:23:30 +01:00
|
|
|
ok(rc, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) failed\n", notepad);
|
2007-01-18 16:23:05 +01:00
|
|
|
strcpy(shfi2.szDisplayName, "dummy");
|
|
|
|
shfi2.iIcon=0xdeadbeef;
|
|
|
|
rc2=SHGetFileInfoA(notepad, 0,
|
|
|
|
&shfi2, sizeof(shfi2),
|
|
|
|
SHGFI_ICONLOCATION);
|
|
|
|
ok(rc2, "SHGetFileInfoA(%s) failed\n", notepad);
|
|
|
|
if (rc && rc2)
|
|
|
|
{
|
|
|
|
ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
|
|
|
|
ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* with a directory now */
|
|
|
|
strcpy(shfi.szDisplayName, "dummy");
|
|
|
|
shfi.iIcon=0xdeadbeef;
|
|
|
|
rc=SHGetFileInfoA("test4.txt", GetFileAttributes("test4.txt"),
|
|
|
|
&shfi, sizeof(shfi),
|
|
|
|
SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
|
2007-01-18 16:23:30 +01:00
|
|
|
ok(rc, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) failed\n");
|
2007-01-18 16:23:05 +01:00
|
|
|
strcpy(shfi2.szDisplayName, "dummy");
|
|
|
|
shfi2.iIcon=0xdeadbeef;
|
|
|
|
rc2=SHGetFileInfoA("test4.txt", 0,
|
|
|
|
&shfi2, sizeof(shfi2),
|
|
|
|
SHGFI_ICONLOCATION);
|
|
|
|
ok(rc2, "SHGetFileInfoA(test4.txt/) failed\n");
|
|
|
|
if (rc && rc2)
|
|
|
|
{
|
|
|
|
ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
|
|
|
|
ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
|
|
|
|
}
|
2007-01-06 19:24:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-04 20:46:29 +02:00
|
|
|
/*
|
2002-08-27 03:34:33 +02:00
|
|
|
puts into the specified buffer file names with current directory.
|
|
|
|
files - string with file names, separated by null characters. Ends on a double
|
2002-09-04 20:46:29 +02:00
|
|
|
null characters
|
|
|
|
*/
|
2005-06-20 12:30:15 +02:00
|
|
|
static void set_curr_dir_path(CHAR *buf, const CHAR* files)
|
2002-08-27 03:34:33 +02:00
|
|
|
{
|
|
|
|
buf[0] = 0;
|
|
|
|
while (files[0])
|
|
|
|
{
|
|
|
|
strcpy(buf, CURR_DIR);
|
|
|
|
buf += strlen(buf);
|
|
|
|
buf[0] = '\\';
|
|
|
|
buf++;
|
|
|
|
strcpy(buf, files);
|
|
|
|
buf += strlen(buf) + 1;
|
|
|
|
files += strlen(files) + 1;
|
|
|
|
}
|
|
|
|
buf[0] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* tests the FO_DELETE action */
|
2005-06-20 12:30:15 +02:00
|
|
|
static void test_delete(void)
|
2002-08-27 03:34:33 +02:00
|
|
|
{
|
|
|
|
SHFILEOPSTRUCTA shfo;
|
2004-10-28 22:58:38 +02:00
|
|
|
DWORD ret;
|
2002-08-27 03:34:33 +02:00
|
|
|
CHAR buf[MAX_PATH];
|
|
|
|
|
|
|
|
sprintf(buf, "%s\\%s", CURR_DIR, "test?.txt");
|
|
|
|
buf[strlen(buf) + 1] = '\0';
|
|
|
|
|
2003-01-15 00:43:41 +01:00
|
|
|
shfo.hwnd = NULL;
|
2002-08-27 03:34:33 +02:00
|
|
|
shfo.wFunc = FO_DELETE;
|
|
|
|
shfo.pFrom = buf;
|
|
|
|
shfo.pTo = "\0";
|
|
|
|
shfo.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;
|
|
|
|
shfo.hNameMappings = NULL;
|
|
|
|
shfo.lpszProgressTitle = NULL;
|
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Deletion was successful\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test4.txt"), "Directory should not be removed\n");
|
|
|
|
ok(!file_exists("test1.txt"), "File should be removed\n");
|
2002-08-27 03:34:33 +02:00
|
|
|
|
2004-10-28 22:58:38 +02:00
|
|
|
ret = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(!ret, "Directory exists, but is not removed, ret=%d\n", ret);
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test4.txt"), "Directory should not be removed\n");
|
2002-08-27 03:34:33 +02:00
|
|
|
|
2002-09-04 20:46:29 +02:00
|
|
|
shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
|
2002-08-27 03:34:33 +02:00
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Directory removed\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("test4.txt"), "Directory should be removed\n");
|
2002-08-27 03:34:33 +02:00
|
|
|
|
2004-10-28 22:58:38 +02:00
|
|
|
ret = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(!ret, "The requested file does not exist, ret=%d\n", ret);
|
2002-08-27 03:34:33 +02:00
|
|
|
|
|
|
|
init_shfo_tests();
|
|
|
|
sprintf(buf, "%s\\%s", CURR_DIR, "test4.txt");
|
|
|
|
buf[strlen(buf) + 1] = '\0';
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Fill the subdirectory\n");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Directory removed\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("test4.txt"), "Directory is removed\n");
|
2002-08-27 03:34:33 +02:00
|
|
|
|
|
|
|
init_shfo_tests();
|
2005-12-21 21:18:19 +01:00
|
|
|
shfo.pFrom = "test1.txt\0test4.txt\0";
|
|
|
|
ok(!SHFileOperationA(&shfo), "Directory and a file removed\n");
|
|
|
|
ok(!file_exists("test1.txt"), "The file should be removed\n");
|
|
|
|
ok(!file_exists("test4.txt"), "Directory should be removed\n");
|
|
|
|
ok(file_exists("test2.txt"), "This file should not be removed\n");
|
2005-12-22 11:15:42 +01:00
|
|
|
|
|
|
|
/* FOF_FILESONLY does not delete a dir matching a wildcard */
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.fFlags |= FOF_FILESONLY;
|
|
|
|
shfo.pFrom = "*.txt\0";
|
|
|
|
ok(!SHFileOperation(&shfo), "Failed to delete files\n");
|
|
|
|
ok(!file_exists("test1.txt"), "test1.txt should be removed\n");
|
2005-12-26 12:56:06 +01:00
|
|
|
ok(!file_exists("test_5.txt"), "test_5.txt should be removed\n");
|
2005-12-22 11:15:42 +01:00
|
|
|
ok(file_exists("test4.txt"), "test4.txt should not be removed\n");
|
|
|
|
|
|
|
|
/* FOF_FILESONLY only deletes a dir if explicitly specified */
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "test_?.txt\0test4.txt\0";
|
|
|
|
ok(!SHFileOperation(&shfo), "Failed to delete files\n");
|
|
|
|
ok(!file_exists("test4.txt"), "test4.txt should be removed\n");
|
2005-12-26 12:56:06 +01:00
|
|
|
ok(!file_exists("test_5.txt"), "test_5.txt should be removed\n");
|
2005-12-22 11:15:42 +01:00
|
|
|
ok(file_exists("test1.txt"), "test1.txt should not be removed\n");
|
|
|
|
|
|
|
|
/* try to delete an invalid filename */
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "\0";
|
|
|
|
shfo.fFlags &= ~FOF_FILESONLY;
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
ret = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
|
2005-12-22 11:15:42 +01:00
|
|
|
ok(!shfo.fAnyOperationsAborted, "Expected no aborted operations\n");
|
|
|
|
ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
|
|
|
|
|
|
|
|
/* try an invalid function */
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "test1.txt\0";
|
|
|
|
shfo.wFunc = 0;
|
|
|
|
ret = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
|
2005-12-22 11:15:42 +01:00
|
|
|
ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
|
|
|
|
|
|
|
|
/* try an invalid list, only one null terminator */
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "";
|
|
|
|
shfo.wFunc = FO_DELETE;
|
|
|
|
ret = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
|
2005-12-22 11:15:42 +01:00
|
|
|
ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
|
|
|
|
|
|
|
|
/* delete a dir, and then a file inside the dir, same as
|
|
|
|
* deleting a nonexistent file
|
|
|
|
*/
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "testdir2\0testdir2\\one.txt\0";
|
|
|
|
ret = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(ret == ERROR_PATH_NOT_FOUND, "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret);
|
2005-12-22 11:15:42 +01:00
|
|
|
ok(!file_exists("testdir2"), "Expected testdir2 to not exist\n");
|
|
|
|
ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
|
|
|
|
|
|
|
|
/* try the FOF_NORECURSION flag, continues deleting subdirs */
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "testdir2\0";
|
|
|
|
shfo.fFlags |= FOF_NORECURSION;
|
|
|
|
ret = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
|
2005-12-26 12:56:06 +01:00
|
|
|
ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
|
|
|
|
ok(!file_exists("testdir2\\nested"), "Expected testdir2\\nested to exist\n");
|
2002-08-27 03:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tests the FO_RENAME action */
|
2005-06-20 12:30:15 +02:00
|
|
|
static void test_rename(void)
|
2002-08-27 03:34:33 +02:00
|
|
|
{
|
2002-09-04 20:46:29 +02:00
|
|
|
SHFILEOPSTRUCTA shfo, shfo2;
|
2007-02-04 23:52:39 +01:00
|
|
|
CHAR from[5*MAX_PATH];
|
|
|
|
CHAR to[5*MAX_PATH];
|
2003-09-27 05:47:35 +02:00
|
|
|
DWORD retval;
|
2002-08-27 03:34:33 +02:00
|
|
|
|
2003-01-15 00:43:41 +01:00
|
|
|
shfo.hwnd = NULL;
|
2002-08-27 03:34:33 +02:00
|
|
|
shfo.wFunc = FO_RENAME;
|
|
|
|
shfo.pFrom = from;
|
|
|
|
shfo.pTo = to;
|
|
|
|
shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
|
|
|
|
shfo.hNameMappings = NULL;
|
|
|
|
shfo.lpszProgressTitle = NULL;
|
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0");
|
|
|
|
set_curr_dir_path(to, "test4.txt\0");
|
|
|
|
ok(SHFileOperationA(&shfo), "File is not renamed moving to other directory "
|
2004-01-26 21:23:25 +01:00
|
|
|
"when specifying directory name only\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test1.txt"), "The file is removed\n");
|
2002-08-27 03:34:33 +02:00
|
|
|
|
|
|
|
set_curr_dir_path(from, "test3.txt\0");
|
|
|
|
set_curr_dir_path(to, "test4.txt\\test1.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "File is renamed moving to other directory\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
|
2002-08-27 03:34:33 +02:00
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
|
2003-09-27 05:47:35 +02:00
|
|
|
retval = SHFileOperationA(&shfo); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
|
2005-03-25 21:47:50 +01:00
|
|
|
ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
|
2006-10-07 20:18:17 +02:00
|
|
|
"Can't rename many files, retval = %d\n", retval);
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
|
2002-08-27 03:34:33 +02:00
|
|
|
|
2002-09-04 20:46:29 +02:00
|
|
|
memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
|
|
|
|
shfo2.fFlags |= FOF_MULTIDESTFILES;
|
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
|
2003-09-27 05:47:35 +02:00
|
|
|
retval = SHFileOperationA(&shfo2); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
|
2005-03-25 21:47:50 +01:00
|
|
|
ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
|
2006-10-07 20:18:17 +02:00
|
|
|
"Can't rename many files, retval = %d\n", retval);
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
set_curr_dir_path(from, "test1.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0");
|
2005-03-25 21:47:50 +01:00
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(!retval, "Rename file failed, retval = %d\n", retval);
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("test1.txt"), "The file is not renamed\n");
|
|
|
|
ok(file_exists("test6.txt"), "The file is not renamed\n");
|
2005-03-25 21:47:50 +01:00
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
set_curr_dir_path(from, "test6.txt\0");
|
|
|
|
set_curr_dir_path(to, "test1.txt\0");
|
2005-03-25 21:47:50 +01:00
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(!retval, "Rename file back failed, retval = %d\n", retval);
|
2002-08-27 03:34:33 +02:00
|
|
|
|
|
|
|
set_curr_dir_path(from, "test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0");
|
2005-03-25 21:47:50 +01:00
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(!retval, "Rename dir failed, retval = %d\n", retval);
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("test4.txt"), "The dir is not renamed\n");
|
|
|
|
ok(file_exists("test6.txt"), "The dir is not renamed\n");
|
2005-03-25 21:47:50 +01:00
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
set_curr_dir_path(from, "test6.txt\0");
|
|
|
|
set_curr_dir_path(to, "test4.txt\0");
|
2005-03-25 21:47:50 +01:00
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(!retval, "Rename dir back failed, retval = %d\n", retval);
|
2005-12-22 11:16:57 +01:00
|
|
|
|
|
|
|
/* try to rename more than one file to a single file */
|
|
|
|
shfo.pFrom = "test1.txt\0test2.txt\0";
|
|
|
|
shfo.pTo = "a.txt\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_GEN_FAILURE, "Expected ERROR_GEN_FAILURE, got %d\n", retval);
|
2005-12-22 11:16:57 +01:00
|
|
|
ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
|
|
|
|
ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
|
|
|
|
|
2005-12-26 12:56:06 +01:00
|
|
|
/* pFrom doesn't exist */
|
|
|
|
shfo.pFrom = "idontexist\0";
|
|
|
|
shfo.pTo = "newfile\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == 1026, "Expected 1026, got %d\n", retval);
|
2005-12-26 12:56:06 +01:00
|
|
|
ok(!file_exists("newfile"), "Expected newfile to not exist\n");
|
|
|
|
|
|
|
|
/* pTo already exist */
|
|
|
|
shfo.pFrom = "test1.txt\0";
|
|
|
|
shfo.pTo = "test2.txt\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_ALREADY_EXISTS, "Expected ERROR_ALREADY_EXISTS, got %d\n", retval);
|
2005-12-26 12:56:06 +01:00
|
|
|
|
2005-12-22 11:16:57 +01:00
|
|
|
/* pFrom is valid, but pTo is empty */
|
|
|
|
shfo.pFrom = "test1.txt\0";
|
|
|
|
shfo.pTo = "\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:16:57 +01:00
|
|
|
ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
|
|
|
|
|
|
|
|
/* pFrom is empty */
|
|
|
|
shfo.pFrom = "\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", retval);
|
2005-12-22 11:16:57 +01:00
|
|
|
|
2006-06-29 20:51:49 +02:00
|
|
|
/* pFrom is NULL, commented out because it crashes on nt 4.0 */
|
|
|
|
#if 0
|
2005-12-22 11:16:57 +01:00
|
|
|
shfo.pFrom = NULL;
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval);
|
2006-06-29 20:51:49 +02:00
|
|
|
#endif
|
2002-08-27 03:34:33 +02:00
|
|
|
}
|
|
|
|
|
2002-09-04 20:46:29 +02:00
|
|
|
/* tests the FO_COPY action */
|
2005-06-20 12:30:15 +02:00
|
|
|
static void test_copy(void)
|
2002-09-04 20:46:29 +02:00
|
|
|
{
|
|
|
|
SHFILEOPSTRUCTA shfo, shfo2;
|
2007-02-04 23:52:39 +01:00
|
|
|
CHAR from[5*MAX_PATH];
|
|
|
|
CHAR to[5*MAX_PATH];
|
2002-09-04 20:46:29 +02:00
|
|
|
FILEOP_FLAGS tmp_flags;
|
2003-04-01 06:41:12 +02:00
|
|
|
DWORD retval;
|
2002-09-04 20:46:29 +02:00
|
|
|
|
2003-01-15 00:43:41 +01:00
|
|
|
shfo.hwnd = NULL;
|
2002-09-04 20:46:29 +02:00
|
|
|
shfo.wFunc = FO_COPY;
|
|
|
|
shfo.pFrom = from;
|
|
|
|
shfo.pTo = to;
|
|
|
|
shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
|
|
|
|
shfo.hNameMappings = NULL;
|
|
|
|
shfo.lpszProgressTitle = NULL;
|
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SHFileOperationA(&shfo), "Can't copy many files\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("test6.txt"), "The file is not copied - many files are "
|
2004-01-26 21:23:25 +01:00
|
|
|
"specified as a target\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
|
|
|
|
shfo2.fFlags |= FOF_MULTIDESTFILES;
|
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo2), "Can't copy many files\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test6.txt"), "The file is copied - many files are "
|
2004-01-26 21:23:25 +01:00
|
|
|
"specified as a target\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
DeleteFileA("test6.txt");
|
|
|
|
DeleteFileA("test7.txt");
|
|
|
|
RemoveDirectoryA("test8.txt");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
/* number of sources do not correspond to number of targets */
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0test7.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SHFileOperationA(&shfo2), "Can't copy many files\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("test6.txt"), "The file is not copied - many files are "
|
2004-01-26 21:23:25 +01:00
|
|
|
"specified as a target\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0");
|
|
|
|
set_curr_dir_path(to, "test4.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are copied recursively\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
set_curr_dir_path(from, "test?.txt\0");
|
|
|
|
set_curr_dir_path(to, "testdir2\0");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
|
|
|
|
ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Files and directories are copied to directory\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
|
|
|
|
ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
|
|
|
|
ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
clean_after_shfo_tests();
|
|
|
|
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.fFlags |= FOF_FILESONLY;
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
|
|
|
|
ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
|
|
|
|
ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
clean_after_shfo_tests();
|
|
|
|
|
|
|
|
init_shfo_tests();
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
|
|
|
|
ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
|
2005-11-10 13:14:56 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
|
|
|
|
ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
clean_after_shfo_tests();
|
|
|
|
|
2003-04-01 06:41:12 +02:00
|
|
|
/* Copying multiple files with one not existing as source, fails the
|
|
|
|
entire operation in Win98/ME/2K/XP, but not in 95/NT */
|
2002-09-04 20:46:29 +02:00
|
|
|
init_shfo_tests();
|
|
|
|
tmp_flags = shfo.fFlags;
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test10.txt\0test2.txt\0");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
|
|
|
|
ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
|
2003-04-01 06:41:12 +02:00
|
|
|
retval = SHFileOperationA(&shfo);
|
|
|
|
if (!retval)
|
2005-12-22 11:17:19 +01:00
|
|
|
/* Win 95/NT returns success but copies only the files up to the nonexistent source */
|
|
|
|
ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
|
2003-04-01 06:41:12 +02:00
|
|
|
else
|
|
|
|
{
|
2005-12-22 11:17:19 +01:00
|
|
|
/* Win 98/ME/2K/XP fail the entire operation with return code 1026 if one source file does not exist */
|
|
|
|
ok(retval == 1026, "Files are copied to other directory\n");
|
|
|
|
ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
|
2003-04-01 06:41:12 +02:00
|
|
|
}
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
shfo.fFlags = tmp_flags;
|
2005-10-11 21:26:47 +02:00
|
|
|
|
|
|
|
/* copy into a nonexistent directory */
|
|
|
|
init_shfo_tests();
|
2006-01-23 11:22:59 +01:00
|
|
|
shfo.fFlags = FOF_NOCONFIRMMKDIR;
|
2005-10-11 21:26:47 +02:00
|
|
|
set_curr_dir_path(from, "test1.txt\0");
|
2005-12-22 11:17:19 +01:00
|
|
|
set_curr_dir_path(to, "nonexistent\\notreal\\test2.txt\0");
|
2005-10-11 21:26:47 +02:00
|
|
|
retval= SHFileOperation(&shfo);
|
|
|
|
ok(!retval, "Error copying into nonexistent directory\n");
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(file_exists("nonexistent"), "nonexistent not created\n");
|
|
|
|
ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
|
|
|
|
ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
|
|
|
|
ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
|
|
|
|
|
|
|
|
/* a relative dest directory is OK */
|
|
|
|
clean_after_shfo_tests();
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
|
|
|
|
shfo.pTo = "testdir2\0";
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2006-01-03 12:10:37 +01:00
|
|
|
ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
|
2005-12-22 11:17:19 +01:00
|
|
|
|
|
|
|
/* try to copy files to a file */
|
|
|
|
clean_after_shfo_tests();
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = from;
|
|
|
|
shfo.pTo = to;
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0");
|
|
|
|
set_curr_dir_path(to, "test3.txt\0");
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
|
|
|
|
ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
|
|
|
|
|
|
|
|
/* try to copy many files to nonexistent directory */
|
|
|
|
DeleteFile(to);
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
|
|
|
|
ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
|
|
|
|
ok(RemoveDirectory(to), "Expected test3.txt to exist\n");
|
|
|
|
|
|
|
|
/* send in FOF_MULTIDESTFILES with too many destination files */
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
|
|
|
|
shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
|
|
|
|
shfo.fFlags |= FOF_NOERRORUI | FOF_MULTIDESTFILES;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
|
|
|
|
ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
|
|
|
|
|
|
|
|
/* send in FOF_MULTIDESTFILES with too many destination files */
|
|
|
|
shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
|
|
|
|
shfo.pTo = "e.txt\0f.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
|
|
|
|
ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
|
|
|
|
|
|
|
|
/* use FOF_MULTIDESTFILES with files and a source directory */
|
|
|
|
shfo.pFrom = "test1.txt\0test2.txt\0test4.txt\0";
|
|
|
|
shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
|
|
|
|
ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
|
|
|
|
ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
|
|
|
|
|
2005-12-26 12:56:06 +01:00
|
|
|
/* try many dest files without FOF_MULTIDESTFILES flag */
|
|
|
|
shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
|
|
|
|
shfo.pTo = "a.txt\0b.txt\0c.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
shfo.fFlags &= ~FOF_MULTIDESTFILES;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-26 12:56:06 +01:00
|
|
|
ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
|
|
|
|
|
2005-12-22 11:17:19 +01:00
|
|
|
/* try a glob */
|
|
|
|
shfo.pFrom = "test?.txt\0";
|
|
|
|
shfo.pTo = "testdir2\0";
|
|
|
|
shfo.fFlags &= ~FOF_MULTIDESTFILES;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
|
|
|
|
|
|
|
|
/* try a glob with FOF_FILESONLY */
|
|
|
|
clean_after_shfo_tests();
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "test?.txt\0";
|
|
|
|
shfo.fFlags |= FOF_FILESONLY;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
|
|
|
|
ok(!file_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
|
|
|
|
|
|
|
|
/* try a glob with FOF_MULTIDESTFILES and the same number
|
|
|
|
* of dest files that we would expect
|
|
|
|
*/
|
|
|
|
clean_after_shfo_tests();
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
|
|
|
|
shfo.fFlags &= ~FOF_FILESONLY;
|
|
|
|
shfo.fFlags |= FOF_MULTIDESTFILES;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
|
|
|
|
ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
|
|
|
|
ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
|
|
|
|
|
|
|
|
/* copy one file to two others, second is ignored */
|
|
|
|
clean_after_shfo_tests();
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "test1.txt\0";
|
|
|
|
shfo.pTo = "b.txt\0c.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
|
|
|
|
ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
|
|
|
|
|
|
|
|
/* copy two file to three others, all fail */
|
|
|
|
shfo.pFrom = "test1.txt\0test2.txt\0";
|
|
|
|
shfo.pTo = "b.txt\0c.txt\0d.txt\0";
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
|
|
|
|
ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
|
|
|
|
|
|
|
|
/* copy one file and one directory to three others */
|
|
|
|
shfo.pFrom = "test1.txt\0test4.txt\0";
|
|
|
|
shfo.pTo = "b.txt\0c.txt\0d.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
|
|
|
|
ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
|
|
|
|
ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
|
|
|
|
|
|
|
|
/* copy a directory with a file beneath it, plus some files */
|
|
|
|
createTestFile("test4.txt\\a.txt");
|
|
|
|
shfo.pFrom = "test4.txt\0test1.txt\0";
|
|
|
|
shfo.pTo = "testdir2\0";
|
|
|
|
shfo.fFlags &= ~FOF_MULTIDESTFILES;
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(DeleteFile("testdir2\\test1.txt"), "Expected newdir\\test1.txt to exist\n");
|
|
|
|
ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
|
|
|
|
ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
|
|
|
|
|
|
|
|
/* copy one directory and a file in that dir to another dir */
|
|
|
|
shfo.pFrom = "test4.txt\0test4.txt\\a.txt\0";
|
|
|
|
shfo.pTo = "testdir2\0";
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
|
|
|
|
ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
|
|
|
|
|
|
|
|
/* copy a file in a directory first, and then the directory to a nonexistent dir */
|
|
|
|
shfo.pFrom = "test4.txt\\a.txt\0test4.txt\0";
|
|
|
|
shfo.pTo = "nonexistent\0";
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
|
|
|
|
ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
|
|
|
|
DeleteFile("test4.txt\\a.txt");
|
|
|
|
|
|
|
|
/* destination is same as source file */
|
|
|
|
shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
|
|
|
|
shfo.pTo = "b.txt\0test2.txt\0c.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
shfo.fFlags = FOF_NOERRORUI | FOF_MULTIDESTFILES;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2005-12-26 12:56:06 +01:00
|
|
|
ok(retval == ERROR_NO_MORE_SEARCH_HANDLES,
|
2006-10-07 20:18:17 +02:00
|
|
|
"Expected ERROR_NO_MORE_SEARCH_HANDLES, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(!shfo.fAnyOperationsAborted, "Expected no operations to be aborted\n");
|
|
|
|
ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
|
|
|
|
ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
|
|
|
|
|
|
|
|
/* destination is same as source directory */
|
|
|
|
shfo.pFrom = "test1.txt\0test4.txt\0test3.txt\0";
|
|
|
|
shfo.pTo = "b.txt\0test4.txt\0c.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
|
|
|
|
ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
|
|
|
|
|
|
|
|
/* copy a directory into itself, error displayed in UI */
|
|
|
|
shfo.pFrom = "test4.txt\0";
|
|
|
|
shfo.pTo = "test4.txt\\newdir\0";
|
|
|
|
shfo.fFlags &= ~FOF_MULTIDESTFILES;
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
|
|
|
|
|
|
|
|
/* copy a directory to itself, error displayed in UI */
|
|
|
|
shfo.pFrom = "test4.txt\0";
|
|
|
|
shfo.pTo = "test4.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
|
|
|
|
/* copy a file into a directory, and the directory into itself */
|
|
|
|
shfo.pFrom = "test1.txt\0test4.txt\0";
|
|
|
|
shfo.pTo = "test4.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
2006-01-23 11:22:59 +01:00
|
|
|
shfo.fFlags |= FOF_NOCONFIRMATION;
|
2005-12-22 11:17:19 +01:00
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
|
|
|
|
|
|
|
|
/* copy a file to a file, and the directory into itself */
|
|
|
|
shfo.pFrom = "test1.txt\0test4.txt\0";
|
|
|
|
shfo.pTo = "test4.txt\\a.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
|
|
|
|
|
|
|
|
/* copy a nonexistent file to a nonexistent directory */
|
|
|
|
shfo.pFrom = "e.txt\0";
|
|
|
|
shfo.pTo = "nonexistent\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
retval = SHFileOperation(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == 1026, "Expected 1026, got %d\n", retval);
|
2005-12-22 11:17:19 +01:00
|
|
|
ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
|
2005-12-26 12:56:06 +01:00
|
|
|
ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
|
2007-02-09 17:13:25 +01:00
|
|
|
|
|
|
|
/* Overwrite tests */
|
|
|
|
clean_after_shfo_tests();
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.fFlags = FOF_NOCONFIRMATION;
|
|
|
|
shfo.pFrom = "test1.txt\0";
|
|
|
|
shfo.pTo = "test2.txt\0";
|
|
|
|
shfo.fAnyOperationsAborted = FALSE;
|
|
|
|
/* without FOF_NOCOFIRMATION the confirmation is Yes/No */
|
|
|
|
retval = SHFileOperation(&shfo);
|
|
|
|
ok(retval == 0, "Expected 0, got %d\n", retval);
|
|
|
|
ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
|
|
|
|
|
|
|
|
shfo.pFrom = "test3.txt\0test1.txt\0";
|
|
|
|
shfo.pTo = "test2.txt\0one.txt\0";
|
|
|
|
shfo.fFlags = FOF_NOCONFIRMATION | FOF_MULTIDESTFILES;
|
|
|
|
/* without FOF_NOCOFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
|
|
|
|
retval = SHFileOperation(&shfo);
|
|
|
|
ok(retval == 0, "Expected 0, got %d\n", retval);
|
|
|
|
ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
|
|
|
|
|
|
|
|
shfo.pFrom = "one.txt\0";
|
|
|
|
shfo.pTo = "testdir2\0";
|
|
|
|
shfo.fFlags = FOF_NOCONFIRMATION;
|
|
|
|
/* without FOF_NOCOFIRMATION the confirmation is Yes/No */
|
|
|
|
retval = SHFileOperation(&shfo);
|
|
|
|
ok(retval == 0, "Expected 0, got %d\n", retval);
|
|
|
|
ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
|
|
|
|
|
|
|
|
createTestFile("test4.txt\\test1.txt");
|
|
|
|
shfo.pFrom = "test4.txt\0";
|
|
|
|
shfo.pTo = "testdir2\0";
|
|
|
|
shfo.fFlags = FOF_NOCONFIRMATION;
|
|
|
|
ok(!SHFileOperation(&shfo), "First SHFileOperation failed\n");
|
|
|
|
createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
|
|
|
|
/* without FOF_NOCOFIRMATION the confirmation is "This folder already contains a folder named ..." */
|
|
|
|
retval = SHFileOperation(&shfo);
|
|
|
|
ok(retval == 0, "Expected 0, got %d\n", retval);
|
|
|
|
ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tests the FO_MOVE action */
|
2005-06-20 12:30:15 +02:00
|
|
|
static void test_move(void)
|
2002-09-04 20:46:29 +02:00
|
|
|
{
|
|
|
|
SHFILEOPSTRUCTA shfo, shfo2;
|
2007-02-04 23:52:39 +01:00
|
|
|
CHAR from[5*MAX_PATH];
|
|
|
|
CHAR to[5*MAX_PATH];
|
2005-12-22 11:19:13 +01:00
|
|
|
DWORD retval;
|
2002-09-04 20:46:29 +02:00
|
|
|
|
2003-01-15 00:43:41 +01:00
|
|
|
shfo.hwnd = NULL;
|
2002-09-04 20:46:29 +02:00
|
|
|
shfo.wFunc = FO_MOVE;
|
|
|
|
shfo.pFrom = from;
|
|
|
|
shfo.pTo = to;
|
|
|
|
shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
|
|
|
|
shfo.hNameMappings = NULL;
|
|
|
|
shfo.lpszProgressTitle = NULL;
|
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0");
|
|
|
|
set_curr_dir_path(to, "test4.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are moved recursively\n");
|
2005-12-22 11:19:13 +01:00
|
|
|
ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
|
|
|
|
ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
set_curr_dir_path(from, "test?.txt\0");
|
|
|
|
set_curr_dir_path(to, "testdir2\0");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
|
|
|
|
ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Files and directories are moved to directory\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
|
|
|
|
ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
|
|
|
|
ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
clean_after_shfo_tests();
|
|
|
|
init_shfo_tests();
|
|
|
|
|
|
|
|
memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
|
|
|
|
shfo2.fFlags |= FOF_MULTIDESTFILES;
|
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo2), "Move many files\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test6.txt"), "The file is moved - many files are "
|
2004-01-26 21:23:25 +01:00
|
|
|
"specified as a target\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
DeleteFileA("test6.txt");
|
|
|
|
DeleteFileA("test7.txt");
|
|
|
|
RemoveDirectoryA("test8.txt");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
init_shfo_tests();
|
|
|
|
|
|
|
|
/* number of sources do not correspond to number of targets */
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0test7.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(SHFileOperationA(&shfo2), "Can't move many files\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("test6.txt"), "The file is not moved - many files are "
|
2004-01-26 21:23:25 +01:00
|
|
|
"specified as a target\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
init_shfo_tests();
|
|
|
|
|
|
|
|
set_curr_dir_path(from, "test3.txt\0");
|
|
|
|
set_curr_dir_path(to, "test4.txt\\test1.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "File is moved moving to other directory\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test4.txt\\test1.txt"), "The file is moved\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
|
2005-05-06 17:44:31 +02:00
|
|
|
ok(SHFileOperationA(&shfo), "Cannot move many files\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("test1.txt"), "The file is not moved. Many files are specified\n");
|
|
|
|
ok(file_exists("test4.txt"), "The directory is not moved. Many files are specified\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
set_curr_dir_path(from, "test1.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Move file\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("test1.txt"), "The file is moved\n");
|
|
|
|
ok(file_exists("test6.txt"), "The file is moved\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
set_curr_dir_path(from, "test6.txt\0");
|
|
|
|
set_curr_dir_path(to, "test1.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Move file back\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
set_curr_dir_path(from, "test4.txt\0");
|
|
|
|
set_curr_dir_path(to, "test6.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Move dir\n");
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(!file_exists("test4.txt"), "The dir is moved\n");
|
|
|
|
ok(file_exists("test6.txt"), "The dir is moved\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
set_curr_dir_path(from, "test6.txt\0");
|
|
|
|
set_curr_dir_path(to, "test4.txt\0");
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(!SHFileOperationA(&shfo), "Move dir back\n");
|
2005-12-22 11:19:13 +01:00
|
|
|
|
|
|
|
/* move one file to two others */
|
|
|
|
init_shfo_tests();
|
|
|
|
shfo.pFrom = "test1.txt\0";
|
|
|
|
shfo.pTo = "a.txt\0b.txt\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:19:13 +01:00
|
|
|
ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
|
|
|
|
ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
|
|
|
|
ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
|
|
|
|
|
|
|
|
/* move two files to one other */
|
|
|
|
shfo.pFrom = "test2.txt\0test3.txt\0";
|
|
|
|
shfo.pTo = "test1.txt\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:19:13 +01:00
|
|
|
ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
|
|
|
|
ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
|
|
|
|
ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
|
|
|
|
|
|
|
|
/* move a directory into itself */
|
|
|
|
shfo.pFrom = "test4.txt\0";
|
|
|
|
shfo.pTo = "test4.txt\\b.txt\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:19:13 +01:00
|
|
|
ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
|
|
|
|
ok(file_exists("test4.txt"), "Expected test4.txt to exist\n");
|
|
|
|
|
|
|
|
/* move many files without FOF_MULTIDESTFILES */
|
|
|
|
shfo.pFrom = "test2.txt\0test3.txt\0";
|
|
|
|
shfo.pTo = "d.txt\0e.txt\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:19:13 +01:00
|
|
|
ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
|
|
|
|
ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
|
|
|
|
|
|
|
|
/* number of sources != number of targets */
|
|
|
|
shfo.pTo = "d.txt\0";
|
|
|
|
shfo.fFlags |= FOF_MULTIDESTFILES;
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-22 11:19:13 +01:00
|
|
|
ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
|
|
|
|
|
|
|
|
/* FO_MOVE does not create dest directories */
|
|
|
|
shfo.pFrom = "test2.txt\0";
|
|
|
|
shfo.pTo = "dir1\\dir2\\test2.txt\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
|
2005-12-26 12:56:06 +01:00
|
|
|
ok(!file_exists("dir1"), "Expected dir1 to not exist\n");
|
2005-12-22 11:19:13 +01:00
|
|
|
|
|
|
|
/* try to overwrite an existing file */
|
|
|
|
shfo.pTo = "test3.txt\0";
|
|
|
|
retval = SHFileOperationA(&shfo);
|
2006-10-07 20:18:17 +02:00
|
|
|
ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
|
2005-12-22 11:19:13 +01:00
|
|
|
ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
|
|
|
|
ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
|
2002-09-04 20:46:29 +02:00
|
|
|
}
|
|
|
|
|
2005-06-20 12:30:15 +02:00
|
|
|
static void test_sh_create_dir(void)
|
2004-10-28 22:58:38 +02:00
|
|
|
{
|
|
|
|
CHAR path[MAX_PATH];
|
|
|
|
int ret;
|
|
|
|
|
2004-12-06 12:45:13 +01:00
|
|
|
if(!pSHCreateDirectoryExA)
|
|
|
|
{
|
|
|
|
trace("skipping SHCreateDirectoryExA tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-28 22:58:38 +02:00
|
|
|
set_curr_dir_path(path, "testdir2\\test4.txt\0");
|
2004-12-06 12:45:13 +01:00
|
|
|
ret = pSHCreateDirectoryExA(NULL, path, NULL);
|
2004-10-28 22:58:38 +02:00
|
|
|
ok(ERROR_SUCCESS == ret, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret);
|
2005-12-21 21:18:19 +01:00
|
|
|
ok(file_exists("testdir2"), "The first directory is not created\n");
|
|
|
|
ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
|
2004-10-28 22:58:38 +02:00
|
|
|
|
2004-12-06 12:45:13 +01:00
|
|
|
ret = pSHCreateDirectoryExA(NULL, path, NULL);
|
2004-10-28 22:58:38 +02:00
|
|
|
ok(ERROR_ALREADY_EXISTS == ret, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret);
|
2006-06-07 21:08:27 +02:00
|
|
|
|
|
|
|
ret = pSHCreateDirectoryExA(NULL, "c:\\testdir3", NULL);
|
|
|
|
ok(file_exists("c:\\testdir3"), "The directory is not created\n");
|
2004-10-28 22:58:38 +02:00
|
|
|
}
|
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
START_TEST(shlfileop)
|
|
|
|
{
|
2004-12-06 12:45:13 +01:00
|
|
|
InitFunctionPointers();
|
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
clean_after_shfo_tests();
|
|
|
|
|
2007-01-18 16:23:05 +01:00
|
|
|
init_shfo_tests();
|
2007-01-06 19:24:06 +01:00
|
|
|
test_get_file_info();
|
2007-01-18 16:23:05 +01:00
|
|
|
clean_after_shfo_tests();
|
2007-01-06 19:24:06 +01:00
|
|
|
|
2002-08-27 03:34:33 +02:00
|
|
|
init_shfo_tests();
|
|
|
|
test_delete();
|
|
|
|
clean_after_shfo_tests();
|
|
|
|
|
|
|
|
init_shfo_tests();
|
|
|
|
test_rename();
|
|
|
|
clean_after_shfo_tests();
|
2002-09-04 20:46:29 +02:00
|
|
|
|
|
|
|
init_shfo_tests();
|
|
|
|
test_copy();
|
|
|
|
clean_after_shfo_tests();
|
|
|
|
|
|
|
|
init_shfo_tests();
|
|
|
|
test_move();
|
|
|
|
clean_after_shfo_tests();
|
2004-10-28 22:58:38 +02:00
|
|
|
|
|
|
|
test_sh_create_dir();
|
|
|
|
clean_after_shfo_tests();
|
2002-08-27 03:34:33 +02:00
|
|
|
}
|