3 * Copyright 2012 Alistair Leslie-Hughes
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
34 static IFileSystem3
*fs3
;
36 static void test_interfaces(void)
38 static const WCHAR nonexistent_dirW
[] = {
39 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', 0};
40 static const WCHAR pathW
[] = {'p','a','t','h',0};
41 static const WCHAR file_kernel32W
[] = {
42 '\\', 'k', 'e', 'r', 'n', 'e', 'l', '3', '2', '.', 'd', 'l', 'l', 0};
46 IObjectWithSite
*site
;
49 WCHAR windows_path
[MAX_PATH
];
50 WCHAR file_path
[MAX_PATH
];
52 IFileSystem3_QueryInterface(fs3
, &IID_IDispatch
, (void**)&disp
);
54 GetSystemDirectoryW(windows_path
, MAX_PATH
);
55 lstrcpyW(file_path
, windows_path
);
56 lstrcatW(file_path
, file_kernel32W
);
58 hr
= IDispatch_QueryInterface(disp
, &IID_IObjectWithSite
, (void**)&site
);
59 ok(hr
== E_NOINTERFACE
, "got 0x%08x, expected 0x%08x\n", hr
, E_NOINTERFACE
);
61 hr
= IDispatch_QueryInterface(disp
, &IID_IDispatchEx
, (void**)&dispex
);
62 ok(hr
== E_NOINTERFACE
, "got 0x%08x, expected 0x%08x\n", hr
, E_NOINTERFACE
);
65 hr
= IFileSystem3_FileExists(fs3
, NULL
, &b
);
66 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
67 ok(b
== VARIANT_FALSE
, "got %x\n", b
);
69 hr
= IFileSystem3_FileExists(fs3
, NULL
, NULL
);
70 ok(hr
== E_POINTER
, "got 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
72 path
= SysAllocString(pathW
);
74 hr
= IFileSystem3_FileExists(fs3
, path
, &b
);
75 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
76 ok(b
== VARIANT_FALSE
, "got %x\n", b
);
79 path
= SysAllocString(file_path
);
81 hr
= IFileSystem3_FileExists(fs3
, path
, &b
);
82 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
83 ok(b
== VARIANT_TRUE
, "got %x\n", b
);
86 path
= SysAllocString(windows_path
);
88 hr
= IFileSystem3_FileExists(fs3
, path
, &b
);
89 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
90 ok(b
== VARIANT_FALSE
, "got %x\n", b
);
94 hr
= IFileSystem3_FolderExists(fs3
, NULL
, NULL
);
95 ok(hr
== E_POINTER
, "got 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
97 path
= SysAllocString(windows_path
);
98 hr
= IFileSystem3_FolderExists(fs3
, path
, &b
);
99 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
100 ok(b
== VARIANT_TRUE
, "Folder doesn't exists\n");
103 path
= SysAllocString(nonexistent_dirW
);
104 hr
= IFileSystem3_FolderExists(fs3
, path
, &b
);
105 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
106 ok(b
== VARIANT_FALSE
, "Folder exists\n");
109 path
= SysAllocString(file_path
);
110 hr
= IFileSystem3_FolderExists(fs3
, path
, &b
);
111 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
112 ok(b
== VARIANT_FALSE
, "Folder exists\n");
115 IDispatch_Release(disp
);
118 static void test_createfolder(void)
121 WCHAR pathW
[MAX_PATH
];
125 /* create existing directory */
126 GetCurrentDirectoryW(sizeof(pathW
)/sizeof(WCHAR
), pathW
);
127 path
= SysAllocString(pathW
);
128 folder
= (void*)0xdeabeef;
129 hr
= IFileSystem3_CreateFolder(fs3
, path
, &folder
);
130 ok(hr
== CTL_E_FILEALREADYEXISTS
, "got 0x%08x\n", hr
);
131 ok(folder
== NULL
, "got %p\n", folder
);
135 static void test_textstream(void)
137 static WCHAR testfileW
[] = {'t','e','s','t','f','i','l','e','.','t','x','t',0};
144 file
= CreateFileW(testfileW
, GENERIC_READ
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
147 name
= SysAllocString(testfileW
);
149 hr
= IFileSystem3_FileExists(fs3
, name
, &b
);
150 ok(hr
== S_OK
, "got 0x%08x, expected 0x%08x\n", hr
, S_OK
);
151 ok(b
== VARIANT_TRUE
, "got %x\n", b
);
153 hr
= IFileSystem3_OpenTextFile(fs3
, name
, ForReading
, VARIANT_FALSE
, TristateFalse
, &stream
);
154 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
157 hr
= ITextStream_get_AtEndOfStream(stream
, &b
);
159 ok(hr
== S_FALSE
|| broken(hr
== S_OK
), "got 0x%08x\n", hr
);
160 ok(b
== VARIANT_TRUE
, "got 0x%x\n", b
);
162 ITextStream_Release(stream
);
164 hr
= IFileSystem3_OpenTextFile(fs3
, name
, ForWriting
, VARIANT_FALSE
, TristateFalse
, &stream
);
165 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
168 hr
= ITextStream_get_AtEndOfStream(stream
, &b
);
170 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
171 ok(b
== VARIANT_TRUE
|| broken(b
== 10), "got 0x%x\n", b
);
174 hr
= ITextStream_get_AtEndOfLine(stream
, &b
);
176 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
177 ok(b
== VARIANT_FALSE
|| broken(b
== 10), "got 0x%x\n", b
);
179 hr
= ITextStream_Read(stream
, 1, &data
);
180 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
182 hr
= ITextStream_ReadLine(stream
, &data
);
183 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
185 hr
= ITextStream_ReadAll(stream
, &data
);
186 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
188 ITextStream_Release(stream
);
190 hr
= IFileSystem3_OpenTextFile(fs3
, name
, ForAppending
, VARIANT_FALSE
, TristateFalse
, &stream
);
191 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
195 hr
= ITextStream_get_AtEndOfStream(stream
, &b
);
197 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
198 ok(b
== VARIANT_TRUE
|| broken(b
== 10), "got 0x%x\n", b
);
201 hr
= ITextStream_get_AtEndOfLine(stream
, &b
);
203 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
204 ok(b
== VARIANT_FALSE
|| broken(b
== 10), "got 0x%x\n", b
);
206 hr
= ITextStream_Read(stream
, 1, &data
);
207 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
209 hr
= ITextStream_ReadLine(stream
, &data
);
210 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
212 hr
= ITextStream_ReadAll(stream
, &data
);
213 ok(hr
== CTL_E_BADFILEMODE
, "got 0x%08x\n", hr
);
215 ITextStream_Release(stream
);
217 DeleteFileW(testfileW
);
220 static void test_GetFileVersion(void)
222 static const WCHAR k32W
[] = {'\\','k','e','r','n','e','l','3','2','.','d','l','l',0};
223 static const WCHAR k33W
[] = {'\\','k','e','r','n','e','l','3','3','.','d','l','l',0};
224 WCHAR pathW
[MAX_PATH
], filenameW
[MAX_PATH
];
228 GetSystemDirectoryW(pathW
, sizeof(pathW
)/sizeof(WCHAR
));
230 lstrcpyW(filenameW
, pathW
);
231 lstrcatW(filenameW
, k32W
);
233 path
= SysAllocString(filenameW
);
234 hr
= IFileSystem3_GetFileVersion(fs3
, path
, &version
);
235 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
236 ok(*version
!= 0, "got %s\n", wine_dbgstr_w(version
));
237 SysFreeString(version
);
240 lstrcpyW(filenameW
, pathW
);
241 lstrcatW(filenameW
, k33W
);
243 path
= SysAllocString(filenameW
);
244 version
= (void*)0xdeadbeef;
245 hr
= IFileSystem3_GetFileVersion(fs3
, path
, &version
);
246 ok(broken(hr
== S_OK
) || hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "got 0x%08x\n", hr
);
249 ok(*version
== 0, "got %s\n", wine_dbgstr_w(version
));
250 SysFreeString(version
);
253 ok(version
== (void*)0xdeadbeef, "got %p\n", version
);
257 START_TEST(filesystem
)
263 hr
= CoCreateInstance(&CLSID_FileSystemObject
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
264 &IID_IFileSystem3
, (void**)&fs3
);
266 win_skip("Could not create FileSystem object: %08x\n", hr
);
273 test_GetFileVersion();
275 IFileSystem3_Release(fs3
);