2012-03-22 06:24:24 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright 2012 Alistair Leslie-Hughes
|
2014-02-05 02:50:56 +01:00
|
|
|
* Copyright 2014 Dmitry Timoshkov
|
2012-03-22 06:24:24 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "ole2.h"
|
2012-11-04 22:59:00 +01:00
|
|
|
#include "olectl.h"
|
2012-07-12 00:00:42 +02:00
|
|
|
#include "oleauto.h"
|
2012-03-22 06:24:24 +01:00
|
|
|
#include "dispex.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
#include "initguid.h"
|
|
|
|
#include "scrrun.h"
|
|
|
|
|
2012-11-10 19:36:12 +01:00
|
|
|
static IFileSystem3 *fs3;
|
|
|
|
|
2014-01-03 13:35:07 +01:00
|
|
|
static inline ULONG get_refcount(IUnknown *iface)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
return IUnknown_Release(iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_REFCOUNT(iface) \
|
|
|
|
get_refcount((IUnknown*)iface)
|
|
|
|
|
2012-04-20 08:40:00 +02:00
|
|
|
static void test_interfaces(void)
|
2012-03-22 06:24:24 +01:00
|
|
|
{
|
2012-07-30 01:02:39 +02:00
|
|
|
static const WCHAR nonexistent_dirW[] = {
|
|
|
|
'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', 0};
|
2012-11-04 22:59:00 +01:00
|
|
|
static const WCHAR pathW[] = {'p','a','t','h',0};
|
2012-07-30 01:02:39 +02:00
|
|
|
static const WCHAR file_kernel32W[] = {
|
|
|
|
'\\', 'k', 'e', 'r', 'n', 'e', 'l', '3', '2', '.', 'd', 'l', 'l', 0};
|
2012-03-22 06:24:24 +01:00
|
|
|
HRESULT hr;
|
|
|
|
IDispatch *disp;
|
|
|
|
IDispatchEx *dispex;
|
|
|
|
IObjectWithSite *site;
|
2012-07-12 00:00:42 +02:00
|
|
|
VARIANT_BOOL b;
|
|
|
|
BSTR path;
|
2012-07-30 01:02:39 +02:00
|
|
|
WCHAR windows_path[MAX_PATH];
|
|
|
|
WCHAR file_path[MAX_PATH];
|
2012-03-22 06:24:24 +01:00
|
|
|
|
2012-11-10 19:36:12 +01:00
|
|
|
IFileSystem3_QueryInterface(fs3, &IID_IDispatch, (void**)&disp);
|
2012-03-22 06:24:24 +01:00
|
|
|
|
2012-07-30 01:02:39 +02:00
|
|
|
GetSystemDirectoryW(windows_path, MAX_PATH);
|
|
|
|
lstrcpyW(file_path, windows_path);
|
|
|
|
lstrcatW(file_path, file_kernel32W);
|
|
|
|
|
2012-03-22 06:24:24 +01:00
|
|
|
hr = IDispatch_QueryInterface(disp, &IID_IObjectWithSite, (void**)&site);
|
|
|
|
ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
|
|
|
|
|
|
|
|
hr = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
|
|
|
|
ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
|
|
|
|
|
2012-07-12 00:00:42 +02:00
|
|
|
b = VARIANT_TRUE;
|
|
|
|
hr = IFileSystem3_FileExists(fs3, NULL, &b);
|
|
|
|
ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
|
|
|
|
ok(b == VARIANT_FALSE, "got %x\n", b);
|
|
|
|
|
|
|
|
hr = IFileSystem3_FileExists(fs3, NULL, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x, expected 0x%08x\n", hr, E_POINTER);
|
|
|
|
|
|
|
|
path = SysAllocString(pathW);
|
|
|
|
b = VARIANT_TRUE;
|
|
|
|
hr = IFileSystem3_FileExists(fs3, path, &b);
|
|
|
|
ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
|
|
|
|
ok(b == VARIANT_FALSE, "got %x\n", b);
|
|
|
|
SysFreeString(path);
|
2012-08-06 00:38:17 +02:00
|
|
|
|
|
|
|
path = SysAllocString(file_path);
|
|
|
|
b = VARIANT_FALSE;
|
|
|
|
hr = IFileSystem3_FileExists(fs3, path, &b);
|
|
|
|
ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
|
|
|
|
ok(b == VARIANT_TRUE, "got %x\n", b);
|
|
|
|
SysFreeString(path);
|
|
|
|
|
|
|
|
path = SysAllocString(windows_path);
|
|
|
|
b = VARIANT_TRUE;
|
|
|
|
hr = IFileSystem3_FileExists(fs3, path, &b);
|
|
|
|
ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
|
|
|
|
ok(b == VARIANT_FALSE, "got %x\n", b);
|
|
|
|
SysFreeString(path);
|
2012-07-12 00:00:42 +02:00
|
|
|
|
2012-07-30 01:02:39 +02:00
|
|
|
/* Folder Exists */
|
|
|
|
hr = IFileSystem3_FolderExists(fs3, NULL, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x, expected 0x%08x\n", hr, E_POINTER);
|
|
|
|
|
|
|
|
path = SysAllocString(windows_path);
|
|
|
|
hr = IFileSystem3_FolderExists(fs3, path, &b);
|
|
|
|
ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
|
|
|
|
ok(b == VARIANT_TRUE, "Folder doesn't exists\n");
|
|
|
|
SysFreeString(path);
|
|
|
|
|
|
|
|
path = SysAllocString(nonexistent_dirW);
|
|
|
|
hr = IFileSystem3_FolderExists(fs3, path, &b);
|
|
|
|
ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
|
|
|
|
ok(b == VARIANT_FALSE, "Folder exists\n");
|
|
|
|
SysFreeString(path);
|
|
|
|
|
|
|
|
path = SysAllocString(file_path);
|
|
|
|
hr = IFileSystem3_FolderExists(fs3, path, &b);
|
|
|
|
ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
|
|
|
|
ok(b == VARIANT_FALSE, "Folder exists\n");
|
|
|
|
SysFreeString(path);
|
|
|
|
|
2012-03-22 06:24:24 +01:00
|
|
|
IDispatch_Release(disp);
|
|
|
|
}
|
|
|
|
|
2012-11-04 22:59:00 +01:00
|
|
|
static void test_createfolder(void)
|
|
|
|
{
|
2014-03-10 12:03:15 +01:00
|
|
|
WCHAR pathW[MAX_PATH], buffW[MAX_PATH];
|
2012-11-04 22:59:00 +01:00
|
|
|
HRESULT hr;
|
|
|
|
BSTR path;
|
|
|
|
IFolder *folder;
|
2014-03-10 12:03:15 +01:00
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
GetTempPathW(MAX_PATH, pathW);
|
|
|
|
GetTempFileNameW(pathW, NULL, 0, buffW);
|
|
|
|
DeleteFileW(buffW);
|
|
|
|
ret = CreateDirectoryW(buffW, NULL);
|
|
|
|
ok(ret, "got %d, %d\n", ret, GetLastError());
|
2012-11-04 22:59:00 +01:00
|
|
|
|
|
|
|
/* create existing directory */
|
2014-03-10 12:03:15 +01:00
|
|
|
path = SysAllocString(buffW);
|
2012-11-04 22:59:00 +01:00
|
|
|
folder = (void*)0xdeabeef;
|
|
|
|
hr = IFileSystem3_CreateFolder(fs3, path, &folder);
|
|
|
|
ok(hr == CTL_E_FILEALREADYEXISTS, "got 0x%08x\n", hr);
|
|
|
|
ok(folder == NULL, "got %p\n", folder);
|
|
|
|
SysFreeString(path);
|
2014-03-10 12:03:15 +01:00
|
|
|
RemoveDirectoryW(buffW);
|
2012-11-10 19:36:12 +01:00
|
|
|
}
|
2012-11-04 22:59:00 +01:00
|
|
|
|
2012-11-10 19:36:12 +01:00
|
|
|
static void test_textstream(void)
|
|
|
|
{
|
2013-12-28 14:10:45 +01:00
|
|
|
static const WCHAR testfileW[] = {'t','e','s','t','f','i','l','e','.','t','x','t',0};
|
2012-11-10 19:36:12 +01:00
|
|
|
ITextStream *stream;
|
|
|
|
VARIANT_BOOL b;
|
2014-03-19 07:21:27 +01:00
|
|
|
DWORD written;
|
2012-11-10 19:36:12 +01:00
|
|
|
HANDLE file;
|
|
|
|
HRESULT hr;
|
|
|
|
BSTR name, data;
|
2014-03-19 07:21:27 +01:00
|
|
|
BOOL ret;
|
2012-11-10 19:36:12 +01:00
|
|
|
|
|
|
|
file = CreateFileW(testfileW, GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
name = SysAllocString(testfileW);
|
|
|
|
b = VARIANT_FALSE;
|
|
|
|
hr = IFileSystem3_FileExists(fs3, name, &b);
|
|
|
|
ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
|
|
|
|
ok(b == VARIANT_TRUE, "got %x\n", b);
|
|
|
|
|
2014-03-16 13:06:28 +01:00
|
|
|
/* different mode combinations */
|
|
|
|
hr = IFileSystem3_OpenTextFile(fs3, name, ForWriting | ForAppending, VARIANT_FALSE, TristateFalse, &stream);
|
|
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_OpenTextFile(fs3, name, ForReading | ForAppending, VARIANT_FALSE, TristateFalse, &stream);
|
|
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_OpenTextFile(fs3, name, ForWriting | ForReading, VARIANT_FALSE, TristateFalse, &stream);
|
|
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_OpenTextFile(fs3, name, ForAppending, VARIANT_FALSE, TristateFalse, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
hr = ITextStream_Read(stream, 1, &data);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
|
|
|
hr = IFileSystem3_OpenTextFile(fs3, name, ForWriting, VARIANT_FALSE, TristateFalse, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
hr = ITextStream_Read(stream, 1, &data);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
2012-11-10 19:36:12 +01:00
|
|
|
hr = IFileSystem3_OpenTextFile(fs3, name, ForReading, VARIANT_FALSE, TristateFalse, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2014-03-18 07:58:08 +01:00
|
|
|
/* try to write when open for reading */
|
|
|
|
hr = ITextStream_WriteLine(stream, name);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = ITextStream_Write(stream, name);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
|
2014-03-19 07:21:27 +01:00
|
|
|
hr = ITextStream_get_AtEndOfStream(stream, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
2012-11-10 19:36:12 +01:00
|
|
|
b = 10;
|
|
|
|
hr = ITextStream_get_AtEndOfStream(stream, &b);
|
2014-03-19 07:21:27 +01:00
|
|
|
ok(hr == S_OK || broken(hr == S_FALSE), "got 0x%08x\n", hr);
|
2012-11-10 19:36:12 +01:00
|
|
|
ok(b == VARIANT_TRUE, "got 0x%x\n", b);
|
2014-03-19 07:21:27 +01:00
|
|
|
|
2012-11-10 19:36:12 +01:00
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
|
|
|
hr = IFileSystem3_OpenTextFile(fs3, name, ForWriting, VARIANT_FALSE, TristateFalse, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
b = 10;
|
|
|
|
hr = ITextStream_get_AtEndOfStream(stream, &b);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
ok(b == VARIANT_TRUE || broken(b == 10), "got 0x%x\n", b);
|
2014-03-19 07:21:27 +01:00
|
|
|
|
2012-11-10 19:36:12 +01:00
|
|
|
b = 10;
|
|
|
|
hr = ITextStream_get_AtEndOfLine(stream, &b);
|
|
|
|
todo_wine {
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
ok(b == VARIANT_FALSE || broken(b == 10), "got 0x%x\n", b);
|
|
|
|
}
|
|
|
|
hr = ITextStream_Read(stream, 1, &data);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = ITextStream_ReadLine(stream, &data);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = ITextStream_ReadAll(stream, &data);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
|
|
|
hr = IFileSystem3_OpenTextFile(fs3, name, ForAppending, VARIANT_FALSE, TristateFalse, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
b = 10;
|
|
|
|
hr = ITextStream_get_AtEndOfStream(stream, &b);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
ok(b == VARIANT_TRUE || broken(b == 10), "got 0x%x\n", b);
|
2014-03-19 07:21:27 +01:00
|
|
|
|
2012-11-10 19:36:12 +01:00
|
|
|
b = 10;
|
|
|
|
hr = ITextStream_get_AtEndOfLine(stream, &b);
|
|
|
|
todo_wine {
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
ok(b == VARIANT_FALSE || broken(b == 10), "got 0x%x\n", b);
|
|
|
|
}
|
|
|
|
hr = ITextStream_Read(stream, 1, &data);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = ITextStream_ReadLine(stream, &data);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = ITextStream_ReadAll(stream, &data);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
2014-03-19 07:21:27 +01:00
|
|
|
/* now with non-empty file */
|
|
|
|
file = CreateFileW(testfileW, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ret = WriteFile(file, testfileW, sizeof(testfileW), &written, NULL);
|
|
|
|
ok(ret && written == sizeof(testfileW), "got %d\n", ret);
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
hr = IFileSystem3_OpenTextFile(fs3, name, ForReading, VARIANT_FALSE, TristateFalse, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
b = 10;
|
|
|
|
hr = ITextStream_get_AtEndOfStream(stream, &b);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(b == VARIANT_FALSE, "got 0x%x\n", b);
|
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
|
|
|
SysFreeString(name);
|
2012-11-10 19:36:12 +01:00
|
|
|
DeleteFileW(testfileW);
|
2012-11-04 22:59:00 +01:00
|
|
|
}
|
|
|
|
|
2012-12-19 08:17:56 +01:00
|
|
|
static void test_GetFileVersion(void)
|
|
|
|
{
|
|
|
|
static const WCHAR k32W[] = {'\\','k','e','r','n','e','l','3','2','.','d','l','l',0};
|
|
|
|
static const WCHAR k33W[] = {'\\','k','e','r','n','e','l','3','3','.','d','l','l',0};
|
|
|
|
WCHAR pathW[MAX_PATH], filenameW[MAX_PATH];
|
|
|
|
BSTR path, version;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
GetSystemDirectoryW(pathW, sizeof(pathW)/sizeof(WCHAR));
|
|
|
|
|
|
|
|
lstrcpyW(filenameW, pathW);
|
|
|
|
lstrcatW(filenameW, k32W);
|
|
|
|
|
|
|
|
path = SysAllocString(filenameW);
|
|
|
|
hr = IFileSystem3_GetFileVersion(fs3, path, &version);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(*version != 0, "got %s\n", wine_dbgstr_w(version));
|
|
|
|
SysFreeString(version);
|
|
|
|
SysFreeString(path);
|
|
|
|
|
|
|
|
lstrcpyW(filenameW, pathW);
|
|
|
|
lstrcatW(filenameW, k33W);
|
|
|
|
|
|
|
|
path = SysAllocString(filenameW);
|
|
|
|
version = (void*)0xdeadbeef;
|
|
|
|
hr = IFileSystem3_GetFileVersion(fs3, path, &version);
|
|
|
|
ok(broken(hr == S_OK) || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
ok(*version == 0, "got %s\n", wine_dbgstr_w(version));
|
|
|
|
SysFreeString(version);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok(version == (void*)0xdeadbeef, "got %p\n", version);
|
|
|
|
SysFreeString(path);
|
|
|
|
}
|
|
|
|
|
2013-07-23 18:50:46 +02:00
|
|
|
static void test_GetParentFolderName(void)
|
|
|
|
{
|
|
|
|
static const WCHAR path1[] = {'a',0};
|
|
|
|
static const WCHAR path2[] = {'a','/','a','/','a',0};
|
|
|
|
static const WCHAR path3[] = {'a','\\','a','\\','a',0};
|
|
|
|
static const WCHAR path4[] = {'a','/','a','/','/','\\','\\',0};
|
|
|
|
static const WCHAR path5[] = {'c',':','\\','\\','a',0};
|
|
|
|
static const WCHAR path6[] = {'a','c',':','\\','a',0};
|
|
|
|
static const WCHAR result2[] = {'a','/','a',0};
|
|
|
|
static const WCHAR result3[] = {'a','\\','a',0};
|
|
|
|
static const WCHAR result4[] = {'a',0};
|
|
|
|
static const WCHAR result5[] = {'c',':','\\',0};
|
|
|
|
static const WCHAR result6[] = {'a','c',':',0};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
const WCHAR *path;
|
|
|
|
const WCHAR *result;
|
|
|
|
} tests[] = {
|
|
|
|
{NULL, NULL},
|
|
|
|
{path1, NULL},
|
|
|
|
{path2, result2},
|
|
|
|
{path3, result3},
|
|
|
|
{path4, result4},
|
|
|
|
{path5, result5},
|
|
|
|
{path6, result6}
|
|
|
|
};
|
|
|
|
|
|
|
|
BSTR path, result;
|
|
|
|
HRESULT hr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hr = IFileSystem3_GetParentFolderName(fs3, NULL, NULL);
|
|
|
|
ok(hr == E_POINTER, "GetParentFolderName returned %x, expected E_POINTER\n", hr);
|
|
|
|
|
|
|
|
for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
|
|
|
|
result = (BSTR)0xdeadbeef;
|
|
|
|
path = tests[i].path ? SysAllocString(tests[i].path) : NULL;
|
|
|
|
hr = IFileSystem3_GetParentFolderName(fs3, path, &result);
|
|
|
|
ok(hr == S_OK, "%d) GetParentFolderName returned %x, expected S_OK\n", i, hr);
|
|
|
|
if(!tests[i].result)
|
|
|
|
ok(!result, "%d) result = %s\n", i, wine_dbgstr_w(result));
|
|
|
|
else
|
|
|
|
ok(!lstrcmpW(result, tests[i].result), "%d) result = %s\n", i, wine_dbgstr_w(result));
|
|
|
|
SysFreeString(path);
|
|
|
|
SysFreeString(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-23 18:50:57 +02:00
|
|
|
static void test_GetFileName(void)
|
|
|
|
{
|
|
|
|
static const WCHAR path1[] = {'a',0};
|
|
|
|
static const WCHAR path2[] = {'a','/','a','.','b',0};
|
|
|
|
static const WCHAR path3[] = {'a','\\',0};
|
|
|
|
static const WCHAR path4[] = {'c',':',0};
|
|
|
|
static const WCHAR path5[] = {'/','\\',0};
|
|
|
|
static const WCHAR result2[] = {'a','.','b',0};
|
|
|
|
static const WCHAR result3[] = {'a',0};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
const WCHAR *path;
|
|
|
|
const WCHAR *result;
|
|
|
|
} tests[] = {
|
|
|
|
{NULL, NULL},
|
|
|
|
{path1, path1},
|
|
|
|
{path2, result2},
|
|
|
|
{path3, result3},
|
|
|
|
{path4, NULL},
|
|
|
|
{path5, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
BSTR path, result;
|
|
|
|
HRESULT hr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hr = IFileSystem3_GetFileName(fs3, NULL, NULL);
|
|
|
|
ok(hr == E_POINTER, "GetFileName returned %x, expected E_POINTER\n", hr);
|
|
|
|
|
|
|
|
for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
|
|
|
|
result = (BSTR)0xdeadbeef;
|
|
|
|
path = tests[i].path ? SysAllocString(tests[i].path) : NULL;
|
|
|
|
hr = IFileSystem3_GetFileName(fs3, path, &result);
|
|
|
|
ok(hr == S_OK, "%d) GetFileName returned %x, expected S_OK\n", i, hr);
|
|
|
|
if(!tests[i].result)
|
|
|
|
ok(!result, "%d) result = %s\n", i, wine_dbgstr_w(result));
|
|
|
|
else
|
|
|
|
ok(!lstrcmpW(result, tests[i].result), "%d) result = %s\n", i, wine_dbgstr_w(result));
|
|
|
|
SysFreeString(path);
|
|
|
|
SysFreeString(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-23 18:51:05 +02:00
|
|
|
static void test_GetBaseName(void)
|
|
|
|
{
|
|
|
|
static const WCHAR path1[] = {'a',0};
|
|
|
|
static const WCHAR path2[] = {'a','/','a','.','b','.','c',0};
|
|
|
|
static const WCHAR path3[] = {'a','.','b','\\',0};
|
|
|
|
static const WCHAR path4[] = {'c',':',0};
|
|
|
|
static const WCHAR path5[] = {'/','\\',0};
|
|
|
|
static const WCHAR path6[] = {'.','a',0};
|
|
|
|
static const WCHAR result1[] = {'a',0};
|
|
|
|
static const WCHAR result2[] = {'a','.','b',0};
|
|
|
|
static const WCHAR result6[] = {0};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
const WCHAR *path;
|
|
|
|
const WCHAR *result;
|
|
|
|
} tests[] = {
|
|
|
|
{NULL, NULL},
|
|
|
|
{path1, result1},
|
|
|
|
{path2, result2},
|
|
|
|
{path3, result1},
|
|
|
|
{path4, NULL},
|
|
|
|
{path5, NULL},
|
|
|
|
{path6, result6}
|
|
|
|
};
|
|
|
|
|
|
|
|
BSTR path, result;
|
|
|
|
HRESULT hr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hr = IFileSystem3_GetBaseName(fs3, NULL, NULL);
|
|
|
|
ok(hr == E_POINTER, "GetBaseName returned %x, expected E_POINTER\n", hr);
|
|
|
|
|
|
|
|
for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
|
|
|
|
result = (BSTR)0xdeadbeef;
|
|
|
|
path = tests[i].path ? SysAllocString(tests[i].path) : NULL;
|
|
|
|
hr = IFileSystem3_GetBaseName(fs3, path, &result);
|
|
|
|
ok(hr == S_OK, "%d) GetBaseName returned %x, expected S_OK\n", i, hr);
|
|
|
|
if(!tests[i].result)
|
|
|
|
ok(!result, "%d) result = %s\n", i, wine_dbgstr_w(result));
|
|
|
|
else
|
|
|
|
ok(!lstrcmpW(result, tests[i].result), "%d) result = %s\n", i, wine_dbgstr_w(result));
|
|
|
|
SysFreeString(path);
|
|
|
|
SysFreeString(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-25 15:13:26 +02:00
|
|
|
static void test_GetAbsolutePathName(void)
|
|
|
|
{
|
|
|
|
static const WCHAR dir1[] = {'t','e','s','t','_','d','i','r','1',0};
|
|
|
|
static const WCHAR dir2[] = {'t','e','s','t','_','d','i','r','2',0};
|
|
|
|
static const WCHAR dir_match1[] = {'t','e','s','t','_','d','i','r','*',0};
|
|
|
|
static const WCHAR dir_match2[] = {'t','e','s','t','_','d','i','*',0};
|
|
|
|
static const WCHAR cur_dir[] = {'.',0};
|
|
|
|
|
|
|
|
WIN32_FIND_DATAW fdata;
|
|
|
|
HANDLE find;
|
2013-08-01 11:46:50 +02:00
|
|
|
WCHAR buf[MAX_PATH], buf2[MAX_PATH];
|
2013-07-25 15:13:26 +02:00
|
|
|
BSTR path, result;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IFileSystem3_GetAbsolutePathName(fs3, NULL, NULL);
|
|
|
|
ok(hr == E_POINTER, "GetAbsolutePathName returned %x, expected E_POINTER\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_GetAbsolutePathName(fs3, NULL, &result);
|
|
|
|
ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
|
|
|
|
GetFullPathNameW(cur_dir, MAX_PATH, buf, NULL);
|
2013-09-03 19:03:25 +02:00
|
|
|
ok(!lstrcmpiW(buf, result), "result = %s, expected %s\n", wine_dbgstr_w(result), wine_dbgstr_w(buf));
|
2013-07-25 15:13:26 +02:00
|
|
|
SysFreeString(result);
|
|
|
|
|
|
|
|
find = FindFirstFileW(dir_match2, &fdata);
|
|
|
|
if(find != INVALID_HANDLE_VALUE) {
|
|
|
|
skip("GetAbsolutePathName tests\n");
|
|
|
|
FindClose(find);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = SysAllocString(dir_match1);
|
|
|
|
hr = IFileSystem3_GetAbsolutePathName(fs3, path, &result);
|
|
|
|
ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
|
2013-08-01 11:46:50 +02:00
|
|
|
GetFullPathNameW(dir_match1, MAX_PATH, buf2, NULL);
|
2013-09-03 19:03:25 +02:00
|
|
|
ok(!lstrcmpiW(buf2, result), "result = %s, expected %s\n", wine_dbgstr_w(result), wine_dbgstr_w(buf2));
|
2013-07-25 15:13:26 +02:00
|
|
|
SysFreeString(result);
|
|
|
|
|
|
|
|
ok(CreateDirectoryW(dir1, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(dir1));
|
|
|
|
hr = IFileSystem3_GetAbsolutePathName(fs3, path, &result);
|
|
|
|
ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
|
|
|
|
GetFullPathNameW(dir1, MAX_PATH, buf, NULL);
|
2013-09-03 19:03:25 +02:00
|
|
|
ok(!lstrcmpiW(buf, result) || broken(!lstrcmpiW(buf2, result)), "result = %s, expected %s\n",
|
2013-08-01 11:46:50 +02:00
|
|
|
wine_dbgstr_w(result), wine_dbgstr_w(buf));
|
2013-07-25 15:13:26 +02:00
|
|
|
SysFreeString(result);
|
|
|
|
|
|
|
|
ok(CreateDirectoryW(dir2, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(dir2));
|
|
|
|
hr = IFileSystem3_GetAbsolutePathName(fs3, path, &result);
|
|
|
|
ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
|
2013-09-03 19:03:25 +02:00
|
|
|
if(!lstrcmpiW(buf, result) || !lstrcmpiW(buf2, result)) {
|
|
|
|
ok(!lstrcmpiW(buf, result) || broken(!lstrcmpiW(buf2, result)), "result = %s, expected %s\n",
|
2013-07-25 15:13:26 +02:00
|
|
|
wine_dbgstr_w(result), wine_dbgstr_w(buf));
|
|
|
|
}else {
|
|
|
|
GetFullPathNameW(dir2, MAX_PATH, buf, NULL);
|
2013-09-03 19:03:25 +02:00
|
|
|
ok(!lstrcmpiW(buf, result), "result = %s, expected %s\n",
|
2013-07-25 15:13:26 +02:00
|
|
|
wine_dbgstr_w(result), wine_dbgstr_w(buf));
|
|
|
|
}
|
|
|
|
SysFreeString(result);
|
|
|
|
|
|
|
|
SysFreeString(path);
|
|
|
|
path = SysAllocString(dir_match2);
|
|
|
|
hr = IFileSystem3_GetAbsolutePathName(fs3, path, &result);
|
|
|
|
ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
|
|
|
|
GetFullPathNameW(dir_match2, MAX_PATH, buf, NULL);
|
2013-09-03 19:03:25 +02:00
|
|
|
ok(!lstrcmpiW(buf, result), "result = %s, expected %s\n", wine_dbgstr_w(result), wine_dbgstr_w(buf));
|
2013-07-25 15:13:26 +02:00
|
|
|
SysFreeString(result);
|
|
|
|
SysFreeString(path);
|
|
|
|
|
|
|
|
RemoveDirectoryW(dir1);
|
|
|
|
RemoveDirectoryW(dir2);
|
|
|
|
}
|
|
|
|
|
2013-07-25 15:13:46 +02:00
|
|
|
static void test_GetFile(void)
|
|
|
|
{
|
|
|
|
static const WCHAR get_file[] = {'g','e','t','_','f','i','l','e','.','t','s','t',0};
|
|
|
|
|
|
|
|
BSTR path = SysAllocString(get_file);
|
2013-07-30 11:31:07 +02:00
|
|
|
FileAttribute fa;
|
2013-07-30 11:31:19 +02:00
|
|
|
VARIANT size;
|
2013-07-30 11:31:07 +02:00
|
|
|
DWORD gfa;
|
2013-07-25 15:13:46 +02:00
|
|
|
IFile *file;
|
|
|
|
HRESULT hr;
|
|
|
|
HANDLE hf;
|
|
|
|
|
|
|
|
hr = IFileSystem3_GetFile(fs3, path, NULL);
|
|
|
|
ok(hr == E_POINTER, "GetFile returned %x, expected E_POINTER\n", hr);
|
|
|
|
hr = IFileSystem3_GetFile(fs3, NULL, &file);
|
|
|
|
ok(hr == E_INVALIDARG, "GetFile returned %x, expected E_INVALIDARG\n", hr);
|
|
|
|
|
2013-08-01 11:46:34 +02:00
|
|
|
if(GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES) {
|
2013-07-25 15:13:46 +02:00
|
|
|
skip("File already exists, skipping GetFile tests\n");
|
|
|
|
SysFreeString(path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = (IFile*)0xdeadbeef;
|
|
|
|
hr = IFileSystem3_GetFile(fs3, path, &file);
|
|
|
|
ok(!file, "file != NULL\n");
|
|
|
|
ok(hr == CTL_E_FILENOTFOUND, "GetFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
|
|
|
|
|
2013-07-30 11:31:32 +02:00
|
|
|
hf = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_READONLY, NULL);
|
2013-07-25 15:13:46 +02:00
|
|
|
if(hf == INVALID_HANDLE_VALUE) {
|
|
|
|
skip("Can't create temporary file\n");
|
|
|
|
SysFreeString(path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CloseHandle(hf);
|
|
|
|
|
|
|
|
hr = IFileSystem3_GetFile(fs3, path, &file);
|
|
|
|
ok(hr == S_OK, "GetFile returned %x, expected S_OK\n", hr);
|
2013-07-30 11:31:07 +02:00
|
|
|
|
|
|
|
hr = IFile_get_Attributes(file, &fa);
|
2013-08-01 11:46:34 +02:00
|
|
|
gfa = GetFileAttributesW(get_file) & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN |
|
|
|
|
FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ARCHIVE |
|
|
|
|
FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_COMPRESSED);
|
2013-07-30 11:31:07 +02:00
|
|
|
ok(hr == S_OK, "get_Attributes returned %x, expected S_OK\n", hr);
|
|
|
|
ok(fa == gfa, "fa = %x, expected %x\n", fa, gfa);
|
2013-07-30 11:31:19 +02:00
|
|
|
|
|
|
|
hr = IFile_get_Size(file, &size);
|
|
|
|
ok(hr == S_OK, "get_Size returned %x, expected S_OK\n", hr);
|
|
|
|
ok(V_VT(&size) == VT_I4, "V_VT(&size) = %d, expected VT_I4\n", V_VT(&size));
|
|
|
|
ok(V_I4(&size) == 0, "V_I4(&size) = %d, expected 0\n", V_I4(&size));
|
2013-07-25 15:13:46 +02:00
|
|
|
IFile_Release(file);
|
|
|
|
|
2013-07-30 11:31:32 +02:00
|
|
|
hr = IFileSystem3_DeleteFile(fs3, path, FALSE);
|
|
|
|
ok(hr==CTL_E_PERMISSIONDENIED || broken(hr==S_OK),
|
|
|
|
"DeleteFile returned %x, expected CTL_E_PERMISSIONDENIED\n", hr);
|
|
|
|
if(hr != S_OK) {
|
|
|
|
hr = IFileSystem3_DeleteFile(fs3, path, TRUE);
|
|
|
|
ok(hr == S_OK, "DeleteFile returned %x, expected S_OK\n", hr);
|
|
|
|
}
|
|
|
|
hr = IFileSystem3_DeleteFile(fs3, path, TRUE);
|
|
|
|
ok(hr == CTL_E_FILENOTFOUND, "DeleteFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
|
|
|
|
|
2013-07-25 15:13:46 +02:00
|
|
|
SysFreeString(path);
|
|
|
|
}
|
|
|
|
|
2013-07-30 11:32:27 +02:00
|
|
|
static inline BOOL create_file(const WCHAR *name)
|
|
|
|
{
|
|
|
|
HANDLE f = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
|
|
|
|
CloseHandle(f);
|
|
|
|
return f != INVALID_HANDLE_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void create_path(const WCHAR *folder, const WCHAR *name, WCHAR *ret)
|
|
|
|
{
|
|
|
|
DWORD len = lstrlenW(folder);
|
|
|
|
memmove(ret, folder, len*sizeof(WCHAR));
|
|
|
|
ret[len] = '\\';
|
|
|
|
memmove(ret+len+1, name, (lstrlenW(name)+1)*sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CopyFolder(void)
|
|
|
|
{
|
|
|
|
static const WCHAR filesystem3_dir[] = {'f','i','l','e','s','y','s','t','e','m','3','_','t','e','s','t',0};
|
|
|
|
static const WCHAR s1[] = {'s','r','c','1',0};
|
|
|
|
static const WCHAR s[] = {'s','r','c','*',0};
|
|
|
|
static const WCHAR d[] = {'d','s','t',0};
|
|
|
|
static const WCHAR empty[] = {0};
|
|
|
|
|
|
|
|
WCHAR tmp[MAX_PATH];
|
|
|
|
BSTR bsrc, bdst;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if(!CreateDirectoryW(filesystem3_dir, NULL)) {
|
|
|
|
skip("can't create temporary directory\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
create_path(filesystem3_dir, s1, tmp);
|
|
|
|
bsrc = SysAllocString(tmp);
|
|
|
|
create_path(filesystem3_dir, d, tmp);
|
|
|
|
bdst = SysAllocString(tmp);
|
|
|
|
hr = IFileSystem3_CopyFile(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == CTL_E_FILENOTFOUND, "CopyFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == CTL_E_PATHNOTFOUND, "CopyFolder returned %x, expected CTL_E_PATHNOTFOUND\n", hr);
|
|
|
|
|
|
|
|
ok(create_file(bsrc), "can't create %s file\n", wine_dbgstr_w(bsrc));
|
|
|
|
hr = IFileSystem3_CopyFile(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == S_OK, "CopyFile returned %x, expected S_OK\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == CTL_E_PATHNOTFOUND, "CopyFolder returned %x, expected CTL_E_PATHNOTFOUND\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_DeleteFile(fs3, bsrc, VARIANT_FALSE);
|
|
|
|
ok(hr == S_OK, "DeleteFile returned %x, expected S_OK\n", hr);
|
|
|
|
|
|
|
|
ok(CreateDirectoryW(bsrc, NULL), "can't create %s\n", wine_dbgstr_w(bsrc));
|
|
|
|
hr = IFileSystem3_CopyFile(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == CTL_E_FILENOTFOUND, "CopyFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == CTL_E_FILEALREADYEXISTS, "CopyFolder returned %x, expected CTL_E_FILEALREADYEXISTS\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_DeleteFile(fs3, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == S_OK, "DeleteFile returned %x, expected S_OK\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
|
|
|
|
create_path(tmp, s1, tmp);
|
|
|
|
ok(GetFileAttributesW(tmp) == INVALID_FILE_ATTRIBUTES,
|
|
|
|
"%s file exists\n", wine_dbgstr_w(tmp));
|
|
|
|
|
|
|
|
create_path(filesystem3_dir, d, tmp);
|
|
|
|
create_path(tmp, empty, tmp);
|
|
|
|
SysFreeString(bdst);
|
|
|
|
bdst = SysAllocString(tmp);
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
|
|
|
|
create_path(tmp, s1, tmp);
|
|
|
|
ok(GetFileAttributesW(tmp) != INVALID_FILE_ATTRIBUTES,
|
|
|
|
"%s directory doesn't exist\n", wine_dbgstr_w(tmp));
|
|
|
|
ok(RemoveDirectoryW(tmp), "can't remove %s directory\n", wine_dbgstr_w(tmp));
|
|
|
|
create_path(filesystem3_dir, d, tmp);
|
|
|
|
SysFreeString(bdst);
|
|
|
|
bdst = SysAllocString(tmp);
|
|
|
|
|
|
|
|
|
|
|
|
create_path(filesystem3_dir, s, tmp);
|
|
|
|
SysFreeString(bsrc);
|
|
|
|
bsrc = SysAllocString(tmp);
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
|
|
|
|
create_path(filesystem3_dir, d, tmp);
|
|
|
|
create_path(tmp, s1, tmp);
|
|
|
|
ok(GetFileAttributesW(tmp) != INVALID_FILE_ATTRIBUTES,
|
|
|
|
"%s directory doesn't exist\n", wine_dbgstr_w(tmp));
|
|
|
|
|
|
|
|
hr = IFileSystem3_DeleteFolder(fs3, bdst, VARIANT_FALSE);
|
|
|
|
ok(hr == S_OK, "DeleteFolder returned %x, expected S_OK\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == CTL_E_PATHNOTFOUND, "CopyFolder returned %x, expected CTL_E_PATHNOTFOUND\n", hr);
|
|
|
|
|
|
|
|
create_path(filesystem3_dir, s1, tmp);
|
|
|
|
SysFreeString(bsrc);
|
|
|
|
bsrc = SysAllocString(tmp);
|
|
|
|
create_path(tmp, s1, tmp);
|
|
|
|
ok(create_file(tmp), "can't create %s file\n", wine_dbgstr_w(tmp));
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_FALSE);
|
|
|
|
ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_FALSE);
|
|
|
|
ok(hr == CTL_E_FILEALREADYEXISTS, "CopyFolder returned %x, expected CTL_E_FILEALREADYEXISTS\n", hr);
|
|
|
|
|
|
|
|
hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
|
|
|
|
ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
|
|
|
|
SysFreeString(bsrc);
|
|
|
|
SysFreeString(bdst);
|
|
|
|
|
|
|
|
bsrc = SysAllocString(filesystem3_dir);
|
|
|
|
hr = IFileSystem3_DeleteFolder(fs3, bsrc, VARIANT_FALSE);
|
|
|
|
ok(hr == S_OK, "DeleteFolder returned %x, expected S_OK\n", hr);
|
|
|
|
SysFreeString(bsrc);
|
|
|
|
}
|
|
|
|
|
2013-11-17 08:49:53 +01:00
|
|
|
static BSTR bstr_from_str(const char *str)
|
|
|
|
{
|
|
|
|
int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
|
|
|
|
BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct buildpath_test
|
|
|
|
{
|
|
|
|
const char *path;
|
|
|
|
const char *name;
|
|
|
|
const char *result;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct buildpath_test buildpath_data[] =
|
|
|
|
{
|
|
|
|
{ "C:\\path", "..\\name.tmp", "C:\\path\\..\\name.tmp" },
|
|
|
|
{ "C:\\path", "\\name.tmp", "C:\\path\\name.tmp" },
|
|
|
|
{ "C:\\path", "name.tmp", "C:\\path\\name.tmp" },
|
|
|
|
{ "C:\\path\\", "name.tmp", "C:\\path\\name.tmp" },
|
|
|
|
{ "C:\\path", "\\\\name.tmp", "C:\\path\\\\name.tmp" },
|
|
|
|
{ "C:\\path\\", "\\name.tmp", "C:\\path\\name.tmp" },
|
|
|
|
{ "C:\\path\\", "\\\\name.tmp", "C:\\path\\\\name.tmp" },
|
|
|
|
{ "C:\\path\\\\", "\\\\name.tmp", "C:\\path\\\\\\name.tmp" },
|
|
|
|
{ "C:\\\\", "\\name.tmp", "C:\\\\name.tmp" },
|
|
|
|
{ "C:", "name.tmp", "C:name.tmp" },
|
|
|
|
{ "C:", "\\\\name.tmp", "C:\\\\name.tmp" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_BuildPath(void)
|
|
|
|
{
|
|
|
|
struct buildpath_test *ptr = buildpath_data;
|
|
|
|
BSTR ret, path;
|
|
|
|
HRESULT hr;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
hr = IFileSystem3_BuildPath(fs3, NULL, NULL, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ret = (BSTR)0xdeadbeef;
|
|
|
|
hr = IFileSystem3_BuildPath(fs3, NULL, NULL, &ret);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(*ret == 0, "got %p\n", ret);
|
|
|
|
SysFreeString(ret);
|
|
|
|
|
|
|
|
ret = (BSTR)0xdeadbeef;
|
|
|
|
path = bstr_from_str("path");
|
|
|
|
hr = IFileSystem3_BuildPath(fs3, path, NULL, &ret);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(!lstrcmpW(ret, path), "got %s\n", wine_dbgstr_w(ret));
|
|
|
|
SysFreeString(ret);
|
|
|
|
SysFreeString(path);
|
|
|
|
|
|
|
|
ret = (BSTR)0xdeadbeef;
|
|
|
|
path = bstr_from_str("path");
|
|
|
|
hr = IFileSystem3_BuildPath(fs3, NULL, path, &ret);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(!lstrcmpW(ret, path), "got %s\n", wine_dbgstr_w(ret));
|
|
|
|
SysFreeString(ret);
|
|
|
|
SysFreeString(path);
|
|
|
|
|
|
|
|
while (ptr->path)
|
|
|
|
{
|
|
|
|
BSTR name, result;
|
|
|
|
|
|
|
|
ret = NULL;
|
|
|
|
path = bstr_from_str(ptr->path);
|
|
|
|
name = bstr_from_str(ptr->name);
|
|
|
|
result = bstr_from_str(ptr->result);
|
|
|
|
hr = IFileSystem3_BuildPath(fs3, path, name, &ret);
|
|
|
|
ok(hr == S_OK, "%d: got 0x%08x\n", i, hr);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
ok(!lstrcmpW(ret, result), "%d: got wrong path %s, expected %s\n", i, wine_dbgstr_w(ret),
|
|
|
|
wine_dbgstr_w(result));
|
|
|
|
SysFreeString(ret);
|
|
|
|
}
|
|
|
|
SysFreeString(path);
|
|
|
|
SysFreeString(name);
|
|
|
|
SysFreeString(result);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-02 18:27:45 +01:00
|
|
|
static void test_GetFolder(void)
|
|
|
|
{
|
|
|
|
static const WCHAR dummyW[] = {'d','u','m','m','y',0};
|
|
|
|
WCHAR buffW[MAX_PATH];
|
|
|
|
IFolder *folder;
|
|
|
|
HRESULT hr;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
folder = (void*)0xdeadbeef;
|
|
|
|
hr = IFileSystem3_GetFolder(fs3, NULL, &folder);
|
|
|
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
|
|
|
ok(folder == NULL, "got %p\n", folder);
|
|
|
|
|
|
|
|
hr = IFileSystem3_GetFolder(fs3, NULL, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
/* something that doesn't exist */
|
|
|
|
str = SysAllocString(dummyW);
|
|
|
|
|
|
|
|
hr = IFileSystem3_GetFolder(fs3, str, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
folder = (void*)0xdeadbeef;
|
|
|
|
hr = IFileSystem3_GetFolder(fs3, str, &folder);
|
|
|
|
ok(hr == CTL_E_PATHNOTFOUND, "got 0x%08x\n", hr);
|
|
|
|
ok(folder == NULL, "got %p\n", folder);
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
GetWindowsDirectoryW(buffW, MAX_PATH);
|
|
|
|
str = SysAllocString(buffW);
|
|
|
|
hr = IFileSystem3_GetFolder(fs3, str, &folder);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
SysFreeString(str);
|
|
|
|
IFolder_Release(folder);
|
|
|
|
}
|
|
|
|
|
2014-02-05 02:50:56 +01:00
|
|
|
/* Please keep the tests for IFolderCollection and IFileCollection in sync */
|
2014-01-03 13:33:43 +01:00
|
|
|
static void test_FolderCollection(void)
|
|
|
|
{
|
2014-03-12 07:07:24 +01:00
|
|
|
static const WCHAR fooW[] = {'f','o','o',0};
|
2014-01-03 13:34:44 +01:00
|
|
|
static const WCHAR aW[] = {'\\','a',0};
|
|
|
|
static const WCHAR bW[] = {'\\','b',0};
|
2014-01-28 03:35:43 +01:00
|
|
|
static const WCHAR cW[] = {'\\','c',0};
|
2014-01-03 13:33:43 +01:00
|
|
|
IFolderCollection *folders;
|
2014-01-28 03:35:43 +01:00
|
|
|
WCHAR buffW[MAX_PATH], pathW[MAX_PATH];
|
2014-01-03 13:35:07 +01:00
|
|
|
IEnumVARIANT *enumvar, *clone;
|
2014-01-28 03:35:43 +01:00
|
|
|
LONG count, ref, ref2, i;
|
2014-01-03 13:35:07 +01:00
|
|
|
IUnknown *unk, *unk2;
|
2014-01-03 13:33:43 +01:00
|
|
|
IFolder *folder;
|
2014-01-05 22:22:08 +01:00
|
|
|
ULONG fetched;
|
2014-01-28 03:35:43 +01:00
|
|
|
VARIANT var, var2[2];
|
2014-01-03 13:33:43 +01:00
|
|
|
HRESULT hr;
|
|
|
|
BSTR str;
|
2014-01-28 03:35:43 +01:00
|
|
|
int found_a = 0, found_b = 0, found_c = 0;
|
2014-01-03 13:33:43 +01:00
|
|
|
|
2014-01-28 03:35:43 +01:00
|
|
|
GetTempPathW(MAX_PATH, pathW);
|
|
|
|
GetTempFileNameW(pathW, fooW, 0, buffW);
|
|
|
|
DeleteFileW(buffW);
|
|
|
|
CreateDirectoryW(buffW, NULL);
|
2014-01-03 13:34:44 +01:00
|
|
|
|
2014-01-03 13:33:43 +01:00
|
|
|
str = SysAllocString(buffW);
|
|
|
|
hr = IFileSystem3_GetFolder(fs3, str, &folder);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
hr = IFolder_get_SubFolders(folder, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
2014-03-12 07:07:24 +01:00
|
|
|
hr = IFolder_get_Path(folder, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IFolder_get_Path(folder, &str);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(!lstrcmpW(buffW, str), "got %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(buffW));
|
|
|
|
SysFreeString(str);
|
|
|
|
|
2014-01-03 13:34:44 +01:00
|
|
|
lstrcpyW(pathW, buffW);
|
|
|
|
lstrcatW(pathW, aW);
|
|
|
|
CreateDirectoryW(pathW, NULL);
|
|
|
|
|
2014-01-28 03:35:43 +01:00
|
|
|
lstrcpyW(pathW, buffW);
|
|
|
|
lstrcatW(pathW, bW);
|
|
|
|
CreateDirectoryW(pathW, NULL);
|
|
|
|
|
2014-01-03 13:33:43 +01:00
|
|
|
hr = IFolder_get_SubFolders(folder, &folders);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2014-01-05 22:22:08 +01:00
|
|
|
IFolder_Release(folder);
|
2014-01-03 13:33:43 +01:00
|
|
|
|
2014-01-03 13:34:44 +01:00
|
|
|
count = 0;
|
|
|
|
hr = IFolderCollection_get_Count(folders, &count);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2014-01-28 03:35:43 +01:00
|
|
|
ok(count == 2, "got %d\n", count);
|
2014-01-03 13:34:44 +01:00
|
|
|
|
2014-01-28 03:35:43 +01:00
|
|
|
lstrcpyW(pathW, buffW);
|
|
|
|
lstrcatW(pathW, cW);
|
|
|
|
CreateDirectoryW(pathW, NULL);
|
2014-01-03 13:34:44 +01:00
|
|
|
|
|
|
|
/* every time property is requested it scans directory */
|
2014-01-28 03:35:43 +01:00
|
|
|
count = 0;
|
|
|
|
hr = IFolderCollection_get_Count(folders, &count);
|
2014-01-03 13:34:44 +01:00
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2014-01-28 03:35:43 +01:00
|
|
|
ok(count == 3, "got %d\n", count);
|
2014-01-03 13:34:44 +01:00
|
|
|
|
2014-01-03 13:35:07 +01:00
|
|
|
hr = IFolderCollection_get__NewEnum(folders, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IFolderCollection_QueryInterface(folders, &IID_IEnumVARIANT, (void**)&unk);
|
|
|
|
ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
/* NewEnum creates new instance each time it's called */
|
|
|
|
ref = GET_REFCOUNT(folders);
|
|
|
|
|
|
|
|
unk = NULL;
|
|
|
|
hr = IFolderCollection_get__NewEnum(folders, &unk);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ref2 = GET_REFCOUNT(folders);
|
|
|
|
ok(ref2 == ref + 1, "got %d, %d\n", ref2, ref);
|
|
|
|
|
|
|
|
unk2 = NULL;
|
|
|
|
hr = IFolderCollection_get__NewEnum(folders, &unk2);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(unk != unk2, "got %p, %p\n", unk2, unk);
|
|
|
|
IUnknown_Release(unk2);
|
|
|
|
|
|
|
|
/* now get IEnumVARIANT */
|
|
|
|
ref = GET_REFCOUNT(folders);
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (void**)&enumvar);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ref2 = GET_REFCOUNT(folders);
|
|
|
|
ok(ref2 == ref, "got %d, %d\n", ref2, ref);
|
|
|
|
|
|
|
|
/* clone enumerator */
|
|
|
|
hr = IEnumVARIANT_Clone(enumvar, &clone);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(clone != enumvar, "got %p, %p\n", enumvar, clone);
|
|
|
|
IEnumVARIANT_Release(clone);
|
2014-01-03 13:35:31 +01:00
|
|
|
|
|
|
|
hr = IEnumVARIANT_Reset(enumvar);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2014-01-28 03:35:43 +01:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
VariantInit(&var);
|
|
|
|
fetched = 0;
|
|
|
|
hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
|
|
|
|
ok(hr == S_OK, "%d: got 0x%08x\n", i, hr);
|
|
|
|
ok(fetched == 1, "%d: got %d\n", i, fetched);
|
|
|
|
ok(V_VT(&var) == VT_DISPATCH, "%d: got type %d\n", i, V_VT(&var));
|
|
|
|
|
|
|
|
hr = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IFolder, (void**)&folder);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
str = NULL;
|
|
|
|
hr = IFolder_get_Name(folder, &str);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
if (!lstrcmpW(str, aW + 1))
|
|
|
|
found_a++;
|
|
|
|
else if (!lstrcmpW(str, bW + 1))
|
|
|
|
found_b++;
|
|
|
|
else if (!lstrcmpW(str, cW + 1))
|
|
|
|
found_c++;
|
2014-02-05 02:50:56 +01:00
|
|
|
else
|
|
|
|
ok(0, "unexpected folder %s was found\n", wine_dbgstr_w(str));
|
2014-01-28 03:35:43 +01:00
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
IFolder_Release(folder);
|
|
|
|
VariantClear(&var);
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(found_a == 1 && found_b == 1 && found_c == 1,
|
|
|
|
"each folder should be found 1 time instead of %d/%d/%d\n",
|
|
|
|
found_a, found_b, found_c);
|
|
|
|
|
2014-01-05 22:22:08 +01:00
|
|
|
VariantInit(&var);
|
2014-01-28 03:35:43 +01:00
|
|
|
fetched = -1;
|
2014-01-05 22:22:08 +01:00
|
|
|
hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
|
2014-01-28 03:35:43 +01:00
|
|
|
ok(hr == S_FALSE, "got 0x%08x\n", hr);
|
|
|
|
ok(fetched == 0, "got %d\n", fetched);
|
2014-01-05 22:22:08 +01:00
|
|
|
|
2014-01-28 03:35:43 +01:00
|
|
|
hr = IEnumVARIANT_Reset(enumvar);
|
2014-01-05 22:22:08 +01:00
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
2014-01-28 03:35:43 +01:00
|
|
|
hr = IEnumVARIANT_Skip(enumvar, 2);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
hr = IEnumVARIANT_Skip(enumvar, 0);
|
2014-01-05 22:22:32 +01:00
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2014-01-28 03:35:43 +01:00
|
|
|
VariantInit(&var2[0]);
|
|
|
|
VariantInit(&var2[1]);
|
|
|
|
fetched = -1;
|
|
|
|
hr = IEnumVARIANT_Next(enumvar, 0, var2, &fetched);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(fetched == 0, "got %d\n", fetched);
|
|
|
|
fetched = -1;
|
|
|
|
hr = IEnumVARIANT_Next(enumvar, 2, var2, &fetched);
|
|
|
|
ok(hr == S_FALSE, "got 0x%08x\n", hr);
|
|
|
|
ok(fetched == 1, "got %d\n", fetched);
|
|
|
|
ok(V_VT(&var2[0]) == VT_DISPATCH, "got type %d\n", V_VT(&var2[0]));
|
|
|
|
VariantClear(&var2[0]);
|
|
|
|
VariantClear(&var2[1]);
|
2014-01-05 22:22:08 +01:00
|
|
|
|
2014-01-03 13:35:07 +01:00
|
|
|
IEnumVARIANT_Release(enumvar);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
2014-01-28 03:35:43 +01:00
|
|
|
lstrcpyW(pathW, buffW);
|
|
|
|
lstrcatW(pathW, aW);
|
|
|
|
RemoveDirectoryW(pathW);
|
|
|
|
lstrcpyW(pathW, buffW);
|
|
|
|
lstrcatW(pathW, bW);
|
|
|
|
RemoveDirectoryW(pathW);
|
|
|
|
lstrcpyW(pathW, buffW);
|
|
|
|
lstrcatW(pathW, cW);
|
2014-01-03 13:34:44 +01:00
|
|
|
RemoveDirectoryW(pathW);
|
2014-01-28 03:35:43 +01:00
|
|
|
RemoveDirectoryW(buffW);
|
2014-01-03 13:34:44 +01:00
|
|
|
|
2014-01-03 13:33:43 +01:00
|
|
|
IFolderCollection_Release(folders);
|
|
|
|
}
|
|
|
|
|
2014-02-05 02:50:56 +01:00
|
|
|
/* Please keep the tests for IFolderCollection and IFileCollection in sync */
|
2014-01-05 22:23:03 +01:00
|
|
|
static void test_FileCollection(void)
|
|
|
|
{
|
2014-02-05 02:50:56 +01:00
|
|
|
static const WCHAR fooW[] = {'\\','f','o','o',0};
|
|
|
|
static const WCHAR aW[] = {'\\','a',0};
|
|
|
|
static const WCHAR bW[] = {'\\','b',0};
|
|
|
|
static const WCHAR cW[] = {'\\','c',0};
|
|
|
|
WCHAR buffW[MAX_PATH], pathW[MAX_PATH];
|
2014-01-05 22:23:03 +01:00
|
|
|
IFolder *folder;
|
2014-02-05 02:50:56 +01:00
|
|
|
IFileCollection *files;
|
|
|
|
IFile *file;
|
|
|
|
IEnumVARIANT *enumvar, *clone;
|
|
|
|
LONG count, ref, ref2, i;
|
|
|
|
IUnknown *unk, *unk2;
|
|
|
|
ULONG fetched;
|
|
|
|
VARIANT var, var2[2];
|
2014-01-05 22:23:03 +01:00
|
|
|
HRESULT hr;
|
|
|
|
BSTR str;
|
2014-02-05 02:50:56 +01:00
|
|
|
HANDLE file_a, file_b, file_c;
|
|
|
|
int found_a = 0, found_b = 0, found_c = 0;
|
2014-01-05 22:23:03 +01:00
|
|
|
|
2014-02-05 02:50:56 +01:00
|
|
|
GetTempPathW(MAX_PATH, pathW);
|
|
|
|
GetTempFileNameW(pathW, fooW, 0, buffW);
|
|
|
|
DeleteFileW(buffW);
|
|
|
|
CreateDirectoryW(buffW, NULL);
|
2014-01-05 22:23:03 +01:00
|
|
|
|
|
|
|
str = SysAllocString(buffW);
|
|
|
|
hr = IFileSystem3_GetFolder(fs3, str, &folder);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
SysFreeString(str);
|
|
|
|
|
|
|
|
hr = IFolder_get_Files(folder, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
2014-02-05 02:50:56 +01:00
|
|
|
lstrcpyW(pathW, buffW);
|
|
|
|
lstrcatW(pathW, aW);
|
|
|
|
file_a = CreateFileW(pathW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
|
|
|
FILE_FLAG_DELETE_ON_CLOSE, 0);
|
|
|
|
lstrcpyW(pathW, buffW);
|
|
|
|
lstrcatW(pathW, bW);
|
|
|
|
file_b = CreateFileW(pathW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
|
|
|
FILE_FLAG_DELETE_ON_CLOSE, 0);
|
|
|
|
|
2014-01-05 22:23:03 +01:00
|
|
|
hr = IFolder_get_Files(folder, &files);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
IFolder_Release(folder);
|
2014-02-05 02:50:56 +01:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
hr = IFileCollection_get_Count(files, &count);
|
|
|
|
todo_wine
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
todo_wine
|
|
|
|
ok(count == 2, "got %d\n", count);
|
|
|
|
|
|
|
|
lstrcpyW(pathW, buffW);
|
|
|
|
lstrcatW(pathW, cW);
|
|
|
|
file_c = CreateFileW(pathW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
|
|
|
FILE_FLAG_DELETE_ON_CLOSE, 0);
|
|
|
|
|
|
|
|
/* every time property is requested it scans directory */
|
|
|
|
count = 0;
|
|
|
|
hr = IFileCollection_get_Count(files, &count);
|
|
|
|
todo_wine
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
todo_wine
|
|
|
|
ok(count == 3, "got %d\n", count);
|
|
|
|
|
|
|
|
hr = IFileCollection_get__NewEnum(files, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IFileCollection_QueryInterface(files, &IID_IEnumVARIANT, (void**)&unk);
|
|
|
|
ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
/* NewEnum creates new instance each time it's called */
|
|
|
|
ref = GET_REFCOUNT(files);
|
|
|
|
|
|
|
|
unk = NULL;
|
|
|
|
hr = IFileCollection_get__NewEnum(files, &unk);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ref2 = GET_REFCOUNT(files);
|
|
|
|
ok(ref2 == ref + 1, "got %d, %d\n", ref2, ref);
|
|
|
|
|
|
|
|
unk2 = NULL;
|
|
|
|
hr = IFileCollection_get__NewEnum(files, &unk2);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(unk != unk2, "got %p, %p\n", unk2, unk);
|
|
|
|
IUnknown_Release(unk2);
|
|
|
|
|
|
|
|
/* now get IEnumVARIANT */
|
|
|
|
ref = GET_REFCOUNT(files);
|
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (void**)&enumvar);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ref2 = GET_REFCOUNT(files);
|
|
|
|
ok(ref2 == ref, "got %d, %d\n", ref2, ref);
|
|
|
|
|
|
|
|
/* clone enumerator */
|
|
|
|
hr = IEnumVARIANT_Clone(enumvar, &clone);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(clone != enumvar, "got %p, %p\n", enumvar, clone);
|
|
|
|
IEnumVARIANT_Release(clone);
|
|
|
|
|
|
|
|
hr = IEnumVARIANT_Reset(enumvar);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
VariantInit(&var);
|
|
|
|
fetched = 0;
|
|
|
|
hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
|
|
|
|
ok(hr == S_OK, "%d: got 0x%08x\n", i, hr);
|
|
|
|
ok(fetched == 1, "%d: got %d\n", i, fetched);
|
|
|
|
ok(V_VT(&var) == VT_DISPATCH, "%d: got type %d\n", i, V_VT(&var));
|
|
|
|
|
|
|
|
hr = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IFile, (void **)&file);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
str = NULL;
|
|
|
|
hr = IFile_get_Name(file, &str);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
if (!lstrcmpW(str, aW + 1))
|
|
|
|
found_a++;
|
|
|
|
else if (!lstrcmpW(str, bW + 1))
|
|
|
|
found_b++;
|
|
|
|
else if (!lstrcmpW(str, cW + 1))
|
|
|
|
found_c++;
|
|
|
|
else
|
|
|
|
ok(0, "unexpected file %s was found\n", wine_dbgstr_w(str));
|
|
|
|
SysFreeString(str);
|
|
|
|
|
2014-03-10 10:23:14 +01:00
|
|
|
IFile_Release(file);
|
2014-02-05 02:50:56 +01:00
|
|
|
VariantClear(&var);
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(found_a == 1 && found_b == 1 && found_c == 1,
|
|
|
|
"each file should be found 1 time instead of %d/%d/%d\n",
|
|
|
|
found_a, found_b, found_c);
|
|
|
|
|
|
|
|
VariantInit(&var);
|
|
|
|
fetched = -1;
|
|
|
|
hr = IEnumVARIANT_Next(enumvar, 1, &var, &fetched);
|
|
|
|
ok(hr == S_FALSE, "got 0x%08x\n", hr);
|
|
|
|
ok(fetched == 0, "got %d\n", fetched);
|
|
|
|
|
|
|
|
hr = IEnumVARIANT_Reset(enumvar);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
hr = IEnumVARIANT_Skip(enumvar, 2);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
hr = IEnumVARIANT_Skip(enumvar, 0);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
VariantInit(&var2[0]);
|
|
|
|
VariantInit(&var2[1]);
|
|
|
|
fetched = -1;
|
|
|
|
hr = IEnumVARIANT_Next(enumvar, 0, var2, &fetched);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(fetched == 0, "got %d\n", fetched);
|
|
|
|
fetched = -1;
|
|
|
|
hr = IEnumVARIANT_Next(enumvar, 2, var2, &fetched);
|
|
|
|
ok(hr == S_FALSE, "got 0x%08x\n", hr);
|
|
|
|
ok(fetched == 1, "got %d\n", fetched);
|
|
|
|
ok(V_VT(&var2[0]) == VT_DISPATCH, "got type %d\n", V_VT(&var2[0]));
|
|
|
|
VariantClear(&var2[0]);
|
|
|
|
VariantClear(&var2[1]);
|
|
|
|
|
|
|
|
IEnumVARIANT_Release(enumvar);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
|
|
|
|
CloseHandle(file_a);
|
|
|
|
CloseHandle(file_b);
|
|
|
|
CloseHandle(file_c);
|
|
|
|
RemoveDirectoryW(buffW);
|
|
|
|
|
|
|
|
IFileCollection_Release(files);
|
2014-01-05 22:23:03 +01:00
|
|
|
}
|
|
|
|
|
2014-03-10 21:20:48 +01:00
|
|
|
static void test_DriveCollection(void)
|
|
|
|
{
|
|
|
|
IDriveCollection *drives;
|
|
|
|
IEnumVARIANT *enumvar;
|
|
|
|
ULONG fetched;
|
|
|
|
VARIANT var;
|
|
|
|
HRESULT hr;
|
|
|
|
LONG count;
|
|
|
|
|
|
|
|
hr = IFileSystem3_get_Drives(fs3, &drives);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IDriveCollection_get__NewEnum(drives, (IUnknown**)&enumvar);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
2014-03-10 21:21:03 +01:00
|
|
|
hr = IDriveCollection_get_Count(drives, NULL);
|
|
|
|
ok(hr == E_POINTER, "got 0x%08x\n", hr);
|
|
|
|
|
2014-03-10 21:20:48 +01:00
|
|
|
count = 0;
|
|
|
|
hr = IDriveCollection_get_Count(drives, &count);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(count > 0, "got %d\n", count);
|
2014-03-10 21:21:03 +01:00
|
|
|
|
2014-03-10 21:20:48 +01:00
|
|
|
V_VT(&var) = VT_EMPTY;
|
|
|
|
fetched = -1;
|
|
|
|
hr = IEnumVARIANT_Next(enumvar, 0, &var, &fetched);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ok(fetched == 0, "got %d\n", fetched);
|
|
|
|
|
|
|
|
hr = IEnumVARIANT_Skip(enumvar, 0);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IEnumVARIANT_Skip(enumvar, count);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = IEnumVARIANT_Skip(enumvar, 1);
|
|
|
|
ok(hr == S_FALSE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
IEnumVARIANT_Release(enumvar);
|
|
|
|
IDriveCollection_Release(drives);
|
|
|
|
}
|
|
|
|
|
2014-03-16 13:06:28 +01:00
|
|
|
static void test_CreateTextFile(void)
|
|
|
|
{
|
|
|
|
static const WCHAR scrrunW[] = {'s','c','r','r','u','n','\\',0};
|
|
|
|
static const WCHAR testfileW[] = {'t','e','s','t','.','t','x','t',0};
|
|
|
|
WCHAR pathW[MAX_PATH], dirW[MAX_PATH];
|
|
|
|
ITextStream *stream;
|
|
|
|
BSTR nameW, str;
|
|
|
|
HANDLE file;
|
|
|
|
HRESULT hr;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
GetTempPathW(sizeof(pathW)/sizeof(WCHAR), pathW);
|
|
|
|
lstrcatW(pathW, scrrunW);
|
|
|
|
lstrcpyW(dirW, pathW);
|
|
|
|
lstrcatW(pathW, testfileW);
|
|
|
|
|
|
|
|
/* dir doesn't exist */
|
|
|
|
nameW = SysAllocString(pathW);
|
|
|
|
hr = IFileSystem3_CreateTextFile(fs3, nameW, VARIANT_FALSE, VARIANT_FALSE, &stream);
|
|
|
|
ok(hr == CTL_E_PATHNOTFOUND, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ret = CreateDirectoryW(dirW, NULL);
|
|
|
|
ok(ret, "got %d, %d\n", ret, GetLastError());
|
|
|
|
|
|
|
|
hr = IFileSystem3_CreateTextFile(fs3, nameW, VARIANT_FALSE, VARIANT_FALSE, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = ITextStream_Read(stream, 1, &str);
|
|
|
|
ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
|
|
|
/* check it's created */
|
|
|
|
file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "got %p\n", file);
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
/* try to create again with no-overwrite mode */
|
|
|
|
hr = IFileSystem3_CreateTextFile(fs3, nameW, VARIANT_FALSE, VARIANT_FALSE, &stream);
|
|
|
|
ok(hr == CTL_E_FILEALREADYEXISTS, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
/* now overwrite */
|
|
|
|
hr = IFileSystem3_CreateTextFile(fs3, nameW, VARIANT_TRUE, VARIANT_FALSE, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
|
|
|
DeleteFileW(nameW);
|
|
|
|
RemoveDirectoryW(dirW);
|
|
|
|
SysFreeString(nameW);
|
|
|
|
}
|
|
|
|
|
2014-03-18 07:58:08 +01:00
|
|
|
static void test_WriteLine(void)
|
|
|
|
{
|
|
|
|
static const WCHAR scrrunW[] = {'s','c','r','r','u','n','\\',0};
|
|
|
|
static const WCHAR testfileW[] = {'t','e','s','t','.','t','x','t',0};
|
|
|
|
static const WCHAR crlfW[] = {'\r','\n',0};
|
|
|
|
WCHAR pathW[MAX_PATH], dirW[MAX_PATH];
|
|
|
|
WCHAR buffW[MAX_PATH], buff2W[MAX_PATH];
|
|
|
|
char buffA[MAX_PATH];
|
|
|
|
ITextStream *stream;
|
|
|
|
DWORD r, len;
|
|
|
|
HANDLE file;
|
|
|
|
BSTR nameW;
|
|
|
|
HRESULT hr;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
GetTempPathW(sizeof(pathW)/sizeof(WCHAR), pathW);
|
|
|
|
lstrcatW(pathW, scrrunW);
|
|
|
|
lstrcpyW(dirW, pathW);
|
|
|
|
lstrcatW(pathW, testfileW);
|
|
|
|
|
|
|
|
ret = CreateDirectoryW(dirW, NULL);
|
|
|
|
ok(ret, "got %d, %d\n", ret, GetLastError());
|
|
|
|
|
|
|
|
/* create as ASCII file first */
|
|
|
|
nameW = SysAllocString(pathW);
|
|
|
|
hr = IFileSystem3_CreateTextFile(fs3, nameW, VARIANT_FALSE, VARIANT_FALSE, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = ITextStream_WriteLine(stream, nameW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
|
|
|
/* check contents */
|
|
|
|
file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "got %p\n", file);
|
|
|
|
r = 0;
|
|
|
|
ret = ReadFile(file, buffA, sizeof(buffA), &r, NULL);
|
|
|
|
ok(ret && r, "read %d, got %d, %d\n", r, ret, GetLastError());
|
|
|
|
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, buffA, r, buffW, sizeof(buffW)/sizeof(WCHAR));
|
|
|
|
buffW[len] = 0;
|
|
|
|
lstrcpyW(buff2W, nameW);
|
|
|
|
lstrcatW(buff2W, crlfW);
|
|
|
|
ok(!lstrcmpW(buff2W, buffW), "got %s, expected %s\n", wine_dbgstr_w(buffW), wine_dbgstr_w(buff2W));
|
|
|
|
CloseHandle(file);
|
|
|
|
DeleteFileW(nameW);
|
|
|
|
|
|
|
|
/* same for unicode file */
|
|
|
|
hr = IFileSystem3_CreateTextFile(fs3, nameW, VARIANT_FALSE, VARIANT_TRUE, &stream);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
|
|
|
|
hr = ITextStream_WriteLine(stream, nameW);
|
|
|
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
|
|
|
ITextStream_Release(stream);
|
|
|
|
|
|
|
|
/* check contents */
|
|
|
|
file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "got %p\n", file);
|
|
|
|
r = 0;
|
|
|
|
ret = ReadFile(file, buffW, sizeof(buffW), &r, NULL);
|
|
|
|
ok(ret && r, "read %d, got %d, %d\n", r, ret, GetLastError());
|
|
|
|
buffW[r/sizeof(WCHAR)] = 0;
|
|
|
|
|
|
|
|
buff2W[0] = 0xfeff;
|
|
|
|
buff2W[1] = 0;
|
|
|
|
lstrcatW(buff2W, nameW);
|
|
|
|
lstrcatW(buff2W, crlfW);
|
|
|
|
ok(!lstrcmpW(buff2W, buffW), "got %s, expected %s\n", wine_dbgstr_w(buffW), wine_dbgstr_w(buff2W));
|
|
|
|
CloseHandle(file);
|
|
|
|
DeleteFileW(nameW);
|
|
|
|
|
|
|
|
RemoveDirectoryW(dirW);
|
|
|
|
SysFreeString(nameW);
|
|
|
|
}
|
|
|
|
|
2012-03-22 06:24:24 +01:00
|
|
|
START_TEST(filesystem)
|
|
|
|
{
|
2012-11-10 19:36:12 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2012-03-22 06:24:24 +01:00
|
|
|
CoInitialize(NULL);
|
|
|
|
|
2012-11-10 19:36:12 +01:00
|
|
|
hr = CoCreateInstance(&CLSID_FileSystemObject, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
|
|
|
&IID_IFileSystem3, (void**)&fs3);
|
|
|
|
if(FAILED(hr)) {
|
|
|
|
win_skip("Could not create FileSystem object: %08x\n", hr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-22 06:24:24 +01:00
|
|
|
test_interfaces();
|
2012-11-04 22:59:00 +01:00
|
|
|
test_createfolder();
|
2012-11-10 19:36:12 +01:00
|
|
|
test_textstream();
|
2012-12-19 08:17:56 +01:00
|
|
|
test_GetFileVersion();
|
2013-07-23 18:50:46 +02:00
|
|
|
test_GetParentFolderName();
|
2013-07-23 18:50:57 +02:00
|
|
|
test_GetFileName();
|
2013-07-23 18:51:05 +02:00
|
|
|
test_GetBaseName();
|
2013-07-25 15:13:26 +02:00
|
|
|
test_GetAbsolutePathName();
|
2013-07-25 15:13:46 +02:00
|
|
|
test_GetFile();
|
2013-07-30 11:32:27 +02:00
|
|
|
test_CopyFolder();
|
2013-11-17 08:49:53 +01:00
|
|
|
test_BuildPath();
|
2014-01-02 18:27:45 +01:00
|
|
|
test_GetFolder();
|
2014-01-03 13:33:43 +01:00
|
|
|
test_FolderCollection();
|
2014-01-05 22:23:03 +01:00
|
|
|
test_FileCollection();
|
2014-03-10 21:20:48 +01:00
|
|
|
test_DriveCollection();
|
2014-03-16 13:06:28 +01:00
|
|
|
test_CreateTextFile();
|
2014-03-18 07:58:08 +01:00
|
|
|
test_WriteLine();
|
2012-11-10 19:36:12 +01:00
|
|
|
|
|
|
|
IFileSystem3_Release(fs3);
|
2012-03-22 06:24:24 +01:00
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|