74873765f00b96c6258b25e91026a7456a326151
[reactos.git] / rostests / winetests / shell32 / shlfolder.c
1 /*
2 * Unit test of the IShellFolder functions.
3 *
4 * Copyright 2004 Vitaliy Margolen
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25 #define CONST_VTABLE
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wtypes.h"
30 #include "shellapi.h"
31
32
33 #include "shlguid.h"
34 #include "shlobj.h"
35 #include "shobjidl.h"
36 #include "shlwapi.h"
37 #include "ocidl.h"
38 #include "oleauto.h"
39
40 #include "wine/test.h"
41
42
43 static IMalloc *ppM;
44
45 static HRESULT (WINAPI *pSHBindToParent)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*);
46 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
47 static HRESULT (WINAPI *pSHGetFolderPathAndSubDirA)(HWND, int, HANDLE, DWORD, LPCSTR, LPSTR);
48 static BOOL (WINAPI *pSHGetPathFromIDListW)(LPCITEMIDLIST,LPWSTR);
49 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
50 static BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
51 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
52 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
53 static void (WINAPI *pILFree)(LPITEMIDLIST);
54 static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
55 static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);
56 static LPITEMIDLIST (WINAPI *pILCombine)(LPCITEMIDLIST,LPCITEMIDLIST);
57
58
59 static void init_function_pointers(void)
60 {
61 HMODULE hmod;
62 HRESULT hr;
63
64 hmod = GetModuleHandleA("shell32.dll");
65 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
66 pSHGetFolderPathA = (void*)GetProcAddress(hmod, "SHGetFolderPathA");
67 pSHGetFolderPathAndSubDirA = (void*)GetProcAddress(hmod, "SHGetFolderPathAndSubDirA");
68 pSHGetPathFromIDListW = (void*)GetProcAddress(hmod, "SHGetPathFromIDListW");
69 pSHGetSpecialFolderPathA = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathA");
70 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
71 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
72 pILFree = (void*)GetProcAddress(hmod, (LPSTR)155);
73 pILIsEqual = (void*)GetProcAddress(hmod, (LPSTR)21);
74 pSHCreateShellItem = (void*)GetProcAddress(hmod, "SHCreateShellItem");
75 pILCombine = (void*)GetProcAddress(hmod, (LPSTR)25);
76
77 hmod = GetModuleHandleA("shlwapi.dll");
78 pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
79
80 hr = SHGetMalloc(&ppM);
81 ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
82 }
83
84 static const char *wine_dbgstr_w(LPCWSTR str)
85 {
86 static char buf[512];
87 if (!str)
88 return "(null)";
89 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
90 return buf;
91 }
92
93 static void test_ParseDisplayName(void)
94 {
95 HRESULT hr;
96 IShellFolder *IDesktopFolder;
97 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
98 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
99 static const char *cInetTestA = "http:\\yyy";
100 static const char *cInetTest2A = "xx:yyy";
101 DWORD res;
102 WCHAR cTestDirW [MAX_PATH] = {0};
103 ITEMIDLIST *newPIDL;
104 BOOL bRes;
105
106 hr = SHGetDesktopFolder(&IDesktopFolder);
107 if(hr != S_OK) return;
108
109 MultiByteToWideChar(CP_ACP, 0, cInetTestA, -1, cTestDirW, MAX_PATH);
110 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
111 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
112 todo_wine ok((SUCCEEDED(hr) || broken(hr == E_FAIL) /* NT4 */),
113 "ParseDisplayName returned %08x, expected SUCCESS or E_FAIL\n", hr);
114 if (SUCCEEDED(hr))
115 {
116 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x61, "Last pidl should be of type "
117 "PT_IESPECIAL1, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
118 IMalloc_Free(ppM, newPIDL);
119 }
120
121 MultiByteToWideChar(CP_ACP, 0, cInetTest2A, -1, cTestDirW, MAX_PATH);
122 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
123 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
124 todo_wine ok((SUCCEEDED(hr) || broken(hr == E_FAIL) /* NT4 */),
125 "ParseDisplayName returned %08x, expected SUCCESS or E_FAIL\n", hr);
126 if (SUCCEEDED(hr))
127 {
128 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x61, "Last pidl should be of type "
129 "PT_IESPECIAL1, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
130 IMalloc_Free(ppM, newPIDL);
131 }
132
133 res = GetFileAttributesA(cNonExistDir1A);
134 if(res != INVALID_FILE_ATTRIBUTES) return;
135
136 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
137 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
138 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
139 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
140 "ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr);
141
142 res = GetFileAttributesA(cNonExistDir2A);
143 if(res != INVALID_FILE_ATTRIBUTES) return;
144
145 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
146 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
147 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
148 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
149 "ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
150
151 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
152 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
153 * out it doesn't. The magic seems to happen in the file dialogs, then. */
154 if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
155
156 bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
157 ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
158 if (!bRes) goto finished;
159
160 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
161 ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr);
162 if (FAILED(hr)) goto finished;
163
164 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31 ||
165 pILFindLastID(newPIDL)->mkid.abID[0] == 0xb1, /* Win98 */
166 "Last pidl should be of type PT_FOLDER or PT_IESPECIAL2, but is: %02x\n",
167 pILFindLastID(newPIDL)->mkid.abID[0]);
168 IMalloc_Free(ppM, newPIDL);
169
170 finished:
171 IShellFolder_Release(IDesktopFolder);
172 }
173
174 /* creates a file with the specified name for tests */
175 static void CreateTestFile(const CHAR *name)
176 {
177 HANDLE file;
178 DWORD written;
179
180 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
181 if (file != INVALID_HANDLE_VALUE)
182 {
183 WriteFile(file, name, strlen(name), &written, NULL);
184 WriteFile(file, "\n", strlen("\n"), &written, NULL);
185 CloseHandle(file);
186 }
187 }
188
189
190 /* initializes the tests */
191 static void CreateFilesFolders(void)
192 {
193 CreateDirectoryA(".\\testdir", NULL);
194 CreateDirectoryA(".\\testdir\\test.txt", NULL);
195 CreateTestFile (".\\testdir\\test1.txt ");
196 CreateTestFile (".\\testdir\\test2.txt ");
197 CreateTestFile (".\\testdir\\test3.txt ");
198 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
199 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
200 }
201
202 /* cleans after tests */
203 static void Cleanup(void)
204 {
205 DeleteFileA(".\\testdir\\test1.txt");
206 DeleteFileA(".\\testdir\\test2.txt");
207 DeleteFileA(".\\testdir\\test3.txt");
208 RemoveDirectoryA(".\\testdir\\test.txt");
209 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
210 RemoveDirectoryA(".\\testdir\\testdir2");
211 RemoveDirectoryA(".\\testdir");
212 }
213
214
215 /* perform test */
216 static void test_EnumObjects(IShellFolder *iFolder)
217 {
218 IEnumIDList *iEnumList;
219 LPITEMIDLIST newPIDL, idlArr[10];
220 ULONG NumPIDLs;
221 int i=0, j;
222 HRESULT hr;
223
224 static const WORD iResults [5][5] =
225 {
226 { 0,-1,-1,-1,-1},
227 { 1, 0,-1,-1,-1},
228 { 1, 1, 0,-1,-1},
229 { 1, 1, 1, 0,-1},
230 { 1, 1, 1, 1, 0}
231 };
232
233 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
234 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
235 static const ULONG attrs[5] =
236 {
237 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
238 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
239 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
240 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
241 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
242 };
243
244 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
245 ok(hr == S_OK, "EnumObjects failed %08x\n", hr);
246
247 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
248 * the filesystem shellfolders return S_OK even if less than 'celt' items are
249 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
250 * only ever returns a single entry per call. */
251 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
252 i += NumPIDLs;
253 ok (i == 5, "i: %d\n", i);
254
255 hr = IEnumIDList_Release(iEnumList);
256 ok(hr == S_OK, "IEnumIDList_Release failed %08x\n", hr);
257
258 /* Sort them first in case of wrong order from system */
259 for (i=0;i<5;i++) for (j=0;j<5;j++)
260 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
261 {
262 newPIDL = idlArr[i];
263 idlArr[i] = idlArr[j];
264 idlArr[j] = newPIDL;
265 }
266
267 for (i=0;i<5;i++) for (j=0;j<5;j++)
268 {
269 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
270 ok(hr == iResults[i][j], "Got %x expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
271 }
272
273
274 for (i = 0; i < 5; i++)
275 {
276 SFGAOF flags;
277 #define SFGAO_VISTA SFGAO_DROPTARGET | SFGAO_CANLINK | SFGAO_CANCOPY
278 /* Native returns all flags no matter what we ask for */
279 flags = SFGAO_CANCOPY;
280 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
281 flags &= SFGAO_testfor;
282 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
283 ok(flags == (attrs[i]) ||
284 flags == (attrs[i] & ~SFGAO_FILESYSANCESTOR) || /* Win9x, NT4 */
285 flags == ((attrs[i] & ~SFGAO_CAPABILITYMASK) | SFGAO_VISTA), /* Vista and higher */
286 "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
287
288 flags = SFGAO_testfor;
289 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
290 flags &= SFGAO_testfor;
291 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
292 ok(flags == attrs[i] ||
293 flags == (attrs[i] & ~SFGAO_FILESYSANCESTOR), /* Win9x, NT4 */
294 "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
295 }
296
297 for (i=0;i<5;i++)
298 IMalloc_Free(ppM, idlArr[i]);
299 }
300
301 static void test_BindToObject(void)
302 {
303 HRESULT hr;
304 UINT cChars;
305 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
306 SHITEMID emptyitem = { 0, { 0 } };
307 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
308 WCHAR wszSystemDir[MAX_PATH];
309 char szSystemDir[MAX_PATH];
310 WCHAR wszMyComputer[] = {
311 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
312 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
313
314 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
315 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
316 */
317 hr = SHGetDesktopFolder(&psfDesktop);
318 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
319 if (FAILED(hr)) return;
320
321 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
322 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
323
324 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
325 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
326
327 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
328 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
329 if (FAILED(hr)) {
330 IShellFolder_Release(psfDesktop);
331 return;
332 }
333
334 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
335 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
336 IShellFolder_Release(psfDesktop);
337 IMalloc_Free(ppM, pidlMyComputer);
338 if (FAILED(hr)) return;
339
340 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
341 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
342
343 #if 0
344 /* this call segfaults on 98SE */
345 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
346 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
347 #endif
348
349 cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
350 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
351 if (cChars == 0 || cChars >= MAX_PATH) {
352 IShellFolder_Release(psfMyComputer);
353 return;
354 }
355 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
356
357 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
358 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr);
359 if (FAILED(hr)) {
360 IShellFolder_Release(psfMyComputer);
361 return;
362 }
363
364 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
365 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr);
366 IShellFolder_Release(psfMyComputer);
367 IMalloc_Free(ppM, pidlSystemDir);
368 if (FAILED(hr)) return;
369
370 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
371 ok (hr == E_INVALIDARG,
372 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
373
374 #if 0
375 /* this call segfaults on 98SE */
376 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
377 ok (hr == E_INVALIDARG,
378 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
379 #endif
380
381 IShellFolder_Release(psfSystemDir);
382 }
383
384 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
385 static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
386 {
387 size_t iLen;
388
389 if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
390 return NULL;
391
392 if (iLen)
393 {
394 lpszPath += iLen;
395 if (lpszPath[-1] != '\\')
396 {
397 *lpszPath++ = '\\';
398 *lpszPath = '\0';
399 }
400 }
401 return lpszPath;
402 }
403
404 static void test_GetDisplayName(void)
405 {
406 BOOL result;
407 HRESULT hr;
408 HANDLE hTestFile;
409 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH];
410 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
411 DWORD attr;
412 STRRET strret;
413 LPSHELLFOLDER psfDesktop, psfPersonal;
414 IUnknown *psfFile;
415 SHITEMID emptyitem = { 0, { 0 } };
416 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
417 LPCITEMIDLIST pidlLast;
418 static const CHAR szFileName[] = "winetest.foo";
419 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
420 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
421
422 /* I'm trying to figure if there is a functional difference between calling
423 * SHGetPathFromIDListW and calling GetDisplayNameOf(SHGDN_FORPARSING) after
424 * binding to the shellfolder. One thing I thought of was that perhaps
425 * SHGetPathFromIDListW would be able to get the path to a file, which does
426 * not exist anymore, while the other method wouldn't. It turns out there's
427 * no functional difference in this respect.
428 */
429
430 if(!pSHGetSpecialFolderPathA) {
431 win_skip("SHGetSpecialFolderPathA is not available\n");
432 return;
433 }
434
435 /* First creating a directory in MyDocuments and a file in this directory. */
436 result = pSHGetSpecialFolderPathA(NULL, szTestDir, CSIDL_PERSONAL, FALSE);
437 ok(result, "SHGetSpecialFolderPathA failed! Last error: %u\n", GetLastError());
438 if (!result) return;
439
440 /* Use ANSI file functions so this works on Windows 9x */
441 lstrcatA(szTestDir, "\\winetest");
442 CreateDirectoryA(szTestDir, NULL);
443 attr=GetFileAttributesA(szTestDir);
444 if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
445 {
446 ok(0, "unable to create the '%s' directory\n", szTestDir);
447 return;
448 }
449
450 lstrcpyA(szTestFile, szTestDir);
451 lstrcatA(szTestFile, "\\");
452 lstrcatA(szTestFile, szFileName);
453 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
454 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
455 if (hTestFile == INVALID_HANDLE_VALUE) return;
456 CloseHandle(hTestFile);
457
458 /* Getting an itemidlist for the file. */
459 hr = SHGetDesktopFolder(&psfDesktop);
460 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
461 if (FAILED(hr)) return;
462
463 MultiByteToWideChar(CP_ACP, 0, szTestFile, -1, wszTestFile, MAX_PATH);
464
465 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
466 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
467 if (FAILED(hr)) {
468 IShellFolder_Release(psfDesktop);
469 return;
470 }
471
472 pidlLast = pILFindLastID(pidlTestFile);
473 ok(pidlLast->mkid.cb >=76 ||
474 broken(pidlLast->mkid.cb == 28) || /* W2K */
475 broken(pidlLast->mkid.cb == 40), /* Win9x, WinME */
476 "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
477 if (pidlLast->mkid.cb >= 28) {
478 ok(!lstrcmpA((CHAR*)&pidlLast->mkid.abID[12], szFileName),
479 "Filename should be stored as ansi-string at this position!\n");
480 }
481 /* WinXP and up store the filenames as both ANSI and UNICODE in the pidls */
482 if (pidlLast->mkid.cb >= 76) {
483 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName) ||
484 (pidlLast->mkid.cb >= 94 && !lstrcmpW((WCHAR*)&pidlLast->mkid.abID[64], wszFileName)), /* Vista */
485 "Filename should be stored as wchar-string at this position!\n");
486 }
487
488 /* It seems as if we cannot bind to regular files on windows, but only directories.
489 */
490 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
491 todo_wine
492 ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
493 hr == E_NOTIMPL || /* Vista */
494 broken(SUCCEEDED(hr)), /* Win9x, W2K */
495 "hr = %08x\n", hr);
496 if (SUCCEEDED(hr)) {
497 IShellFolder_Release(psfFile);
498 }
499
500 if (!pSHBindToParent)
501 {
502 win_skip("SHBindToParent is missing\n");
503 DeleteFileA(szTestFile);
504 RemoveDirectoryA(szTestDir);
505 return;
506 }
507
508 /* Some tests for IShellFolder::SetNameOf */
509 if (pSHGetFolderPathAndSubDirA)
510 {
511 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
512 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
513 if (SUCCEEDED(hr)) {
514 /* It's ok to use this fixed path. Call will fail anyway. */
515 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
516 LPITEMIDLIST pidlNew;
517
518 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
519 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
520 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
521 if (hr == S_OK)
522 {
523 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
524 "pidl returned from SetNameOf should be simple!\n");
525
526 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
527 * is implemented on top of SHFileOperation in WinXP. */
528 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
529 SHGDN_FORPARSING, NULL);
530 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
531
532 /* Rename the file back to its original name. SetNameOf ignores the fact, that the
533 * SHGDN flags specify an absolute path. */
534 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
535 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
536
537 pILFree(pidlNew);
538 }
539
540 IShellFolder_Release(psfPersonal);
541 }
542 }
543 else
544 win_skip("Avoid needs of interaction on Win2k\n");
545
546 /* Deleting the file and the directory */
547 DeleteFileA(szTestFile);
548 RemoveDirectoryA(szTestDir);
549
550 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
551 if (pSHGetPathFromIDListW)
552 {
553 result = pSHGetPathFromIDListW(pidlTestFile, wszTestFile2);
554 ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
555 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
556 }
557
558 /* SHBindToParent fails, if called with a NULL PIDL. */
559 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
560 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
561
562 /* But it succeeds with an empty PIDL. */
563 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
564 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
565 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
566 if (SUCCEEDED(hr))
567 IShellFolder_Release(psfPersonal);
568
569 /* Binding to the folder and querying the display name of the file also works. */
570 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
571 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
572 if (FAILED(hr)) {
573 IShellFolder_Release(psfDesktop);
574 return;
575 }
576
577 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
578 * pidlTestFile (In accordance with MSDN). */
579 ok (pILFindLastID(pidlTestFile) == pidlLast,
580 "SHBindToParent doesn't return the last id of the pidl param!\n");
581
582 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
583 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
584 if (FAILED(hr)) {
585 IShellFolder_Release(psfDesktop);
586 IShellFolder_Release(psfPersonal);
587 return;
588 }
589
590 if (pStrRetToBufW)
591 {
592 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
593 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
594 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
595 }
596
597 IShellFolder_Release(psfDesktop);
598 IShellFolder_Release(psfPersonal);
599 }
600
601 static void test_CallForAttributes(void)
602 {
603 HKEY hKey;
604 LONG lResult;
605 HRESULT hr;
606 DWORD dwSize;
607 LPSHELLFOLDER psfDesktop;
608 LPITEMIDLIST pidlMyDocuments;
609 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
610 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
611 static const WCHAR wszCallForAttributes[] = {
612 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
613 static const WCHAR wszMyDocumentsKey[] = {
614 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
615 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
616 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
617 WCHAR wszMyDocuments[] = {
618 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
619 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
620
621 /* For the root of a namespace extension, the attributes are not queried by binding
622 * to the object and calling GetAttributesOf. Instead, the attributes are read from
623 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
624 *
625 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
626 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
627 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
628 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
629 */
630 hr = SHGetDesktopFolder(&psfDesktop);
631 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
632 if (FAILED(hr)) return;
633
634 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
635 &pidlMyDocuments, NULL);
636 ok (SUCCEEDED(hr) ||
637 broken(hr == E_INVALIDARG), /* Win95, NT4 */
638 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
639 if (FAILED(hr)) {
640 IShellFolder_Release(psfDesktop);
641 return;
642 }
643
644 dwAttributes = 0xffffffff;
645 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
646 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
647 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
648
649 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
650 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
651 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
652 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
653
654 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
655 * key. So the test will return at this point, if run on wine.
656 */
657 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
658 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
659 if (lResult != ERROR_SUCCESS) {
660 IMalloc_Free(ppM, pidlMyDocuments);
661 IShellFolder_Release(psfDesktop);
662 return;
663 }
664
665 /* Query MyDocuments' Attributes value, to be able to restore it later. */
666 dwSize = sizeof(DWORD);
667 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
668 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
669 if (lResult != ERROR_SUCCESS) {
670 RegCloseKey(hKey);
671 IMalloc_Free(ppM, pidlMyDocuments);
672 IShellFolder_Release(psfDesktop);
673 return;
674 }
675
676 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
677 dwSize = sizeof(DWORD);
678 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
679 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
680 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
681 if (lResult != ERROR_SUCCESS) {
682 RegCloseKey(hKey);
683 IMalloc_Free(ppM, pidlMyDocuments);
684 IShellFolder_Release(psfDesktop);
685 return;
686 }
687
688 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
689 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
690 * SFGAO_FILESYSTEM attributes. */
691 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
692 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
693 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
694 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
695 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
696
697 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
698 * GetAttributesOf. It seems that once there is a single attribute queried, for which
699 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
700 * the flags in Attributes are ignored.
701 */
702 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
703 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
704 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
705 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
706 if (SUCCEEDED(hr))
707 ok (dwAttributes == SFGAO_FILESYSTEM,
708 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n",
709 dwAttributes);
710
711 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
712 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
713 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
714 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
715 RegCloseKey(hKey);
716 IMalloc_Free(ppM, pidlMyDocuments);
717 IShellFolder_Release(psfDesktop);
718 }
719
720 static void test_GetAttributesOf(void)
721 {
722 HRESULT hr;
723 LPSHELLFOLDER psfDesktop, psfMyComputer;
724 SHITEMID emptyitem = { 0, { 0 } };
725 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
726 LPITEMIDLIST pidlMyComputer;
727 DWORD dwFlags;
728 static const DWORD desktopFlags[] = {
729 /* WinXP */
730 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR | SFGAO_FILESYSANCESTOR |
731 SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER,
732 /* Win2k */
733 SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_STREAM | SFGAO_FILESYSANCESTOR |
734 SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER,
735 /* WinMe, Win9x, WinNT*/
736 SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_FILESYSANCESTOR |
737 SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER
738 };
739 static const DWORD myComputerFlags[] = {
740 /* WinXP */
741 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET |
742 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER,
743 /* Win2k */
744 SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET | SFGAO_STREAM |
745 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER,
746 /* WinMe, Win9x, WinNT */
747 SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR |
748 SFGAO_FOLDER | SFGAO_HASSUBFOLDER,
749 /* Win95, WinNT when queried directly */
750 SFGAO_CANLINK | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR |
751 SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER
752 };
753 WCHAR wszMyComputer[] = {
754 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
755 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
756 char cCurrDirA [MAX_PATH] = {0};
757 WCHAR cCurrDirW [MAX_PATH];
758 static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
759 IShellFolder *IDesktopFolder, *testIShellFolder;
760 ITEMIDLIST *newPIDL;
761 int len, i;
762 BOOL foundFlagsMatch;
763
764 hr = SHGetDesktopFolder(&psfDesktop);
765 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
766 if (FAILED(hr)) return;
767
768 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
769 dwFlags = 0xffffffff;
770 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
771 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
772 for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
773 i < sizeof(desktopFlags) / sizeof(desktopFlags[0]); i++)
774 {
775 if (desktopFlags[i] == dwFlags)
776 foundFlagsMatch = TRUE;
777 }
778 ok (foundFlagsMatch, "Wrong Desktop attributes: %08x\n", dwFlags);
779
780 /* .. or with no itemidlist at all. */
781 dwFlags = 0xffffffff;
782 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
783 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
784 for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
785 i < sizeof(desktopFlags) / sizeof(desktopFlags[0]); i++)
786 {
787 if (desktopFlags[i] == dwFlags)
788 foundFlagsMatch = TRUE;
789 }
790 ok (foundFlagsMatch, "Wrong Desktop attributes: %08x\n", dwFlags);
791
792 /* Testing the attributes of the MyComputer shellfolder */
793 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
794 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
795 if (FAILED(hr)) {
796 IShellFolder_Release(psfDesktop);
797 return;
798 }
799
800 /* Windows sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
801 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
802 */
803 dwFlags = 0xffffffff;
804 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
805 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
806 for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
807 i < sizeof(myComputerFlags) / sizeof(myComputerFlags[0]); i++)
808 {
809 if ((myComputerFlags[i] | SFGAO_CANLINK) == dwFlags)
810 foundFlagsMatch = TRUE;
811 }
812 todo_wine
813 ok (foundFlagsMatch, "Wrong MyComputer attributes: %08x\n", dwFlags);
814
815 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
816 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
817 IShellFolder_Release(psfDesktop);
818 IMalloc_Free(ppM, pidlMyComputer);
819 if (FAILED(hr)) return;
820
821 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
822 todo_wine
823 ok (hr == E_INVALIDARG ||
824 broken(SUCCEEDED(hr)), /* W2K and earlier */
825 "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr);
826
827 dwFlags = 0xffffffff;
828 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
829 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
830 for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
831 i < sizeof(myComputerFlags) / sizeof(myComputerFlags[0]); i++)
832 {
833 if (myComputerFlags[i] == dwFlags)
834 foundFlagsMatch = TRUE;
835 }
836 todo_wine
837 ok (foundFlagsMatch, "Wrong MyComputer attributes: %08x\n", dwFlags);
838
839 IShellFolder_Release(psfMyComputer);
840
841 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
842 len = lstrlenA(cCurrDirA);
843
844 if (len == 0) {
845 win_skip("GetCurrentDirectoryA returned empty string. Skipping test_GetAttributesOf\n");
846 return;
847 }
848 if (len > 3 && cCurrDirA[len-1] == '\\')
849 cCurrDirA[len-1] = 0;
850
851 /* create test directory */
852 CreateFilesFolders();
853
854 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
855
856 hr = SHGetDesktopFolder(&IDesktopFolder);
857 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
858
859 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
860 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
861
862 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
863 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
864
865 IMalloc_Free(ppM, newPIDL);
866
867 /* get relative PIDL */
868 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
869 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
870
871 /* test the shell attributes of the test directory using the relative PIDL */
872 dwFlags = SFGAO_FOLDER;
873 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
874 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
875 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
876
877 /* free memory */
878 IMalloc_Free(ppM, newPIDL);
879
880 /* append testdirectory name to path */
881 if (cCurrDirA[len-1] == '\\')
882 cCurrDirA[len-1] = 0;
883 lstrcatA(cCurrDirA, "\\testdir");
884 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
885
886 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
887 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
888
889 /* test the shell attributes of the test directory using the absolute PIDL */
890 dwFlags = SFGAO_FOLDER;
891 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
892 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
893 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
894
895 /* free memory */
896 IMalloc_Free(ppM, newPIDL);
897
898 IShellFolder_Release(testIShellFolder);
899
900 Cleanup();
901
902 IShellFolder_Release(IDesktopFolder);
903 }
904
905 static void test_SHGetPathFromIDList(void)
906 {
907 SHITEMID emptyitem = { 0, { 0 } };
908 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
909 LPITEMIDLIST pidlMyComputer;
910 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
911 BOOL result;
912 HRESULT hr;
913 LPSHELLFOLDER psfDesktop;
914 WCHAR wszMyComputer[] = {
915 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
916 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
917 WCHAR wszFileName[MAX_PATH];
918 LPITEMIDLIST pidlTestFile;
919 HANDLE hTestFile;
920 STRRET strret;
921 static WCHAR wszTestFile[] = {
922 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
923 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
924 HMODULE hShell32;
925 LPITEMIDLIST pidlPrograms;
926
927 if(!pSHGetPathFromIDListW || !pSHGetSpecialFolderPathW)
928 {
929 win_skip("SHGetPathFromIDListW() or SHGetSpecialFolderPathW() is missing\n");
930 return;
931 }
932
933 /* Calling SHGetPathFromIDListW with no pidl should return the empty string */
934 wszPath[0] = 'a';
935 wszPath[1] = '\0';
936 result = pSHGetPathFromIDListW(NULL, wszPath);
937 ok(!result, "Expected failure\n");
938 ok(!wszPath[0], "Expected empty string\n");
939
940 /* Calling SHGetPathFromIDListW with an empty pidl should return the desktop folder's path. */
941 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
942 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
943 if (!result) return;
944
945 /* Check if we are on Win9x */
946 SetLastError(0xdeadbeef);
947 lstrcmpiW(wszDesktop, wszDesktop);
948 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
949 {
950 win_skip("Most W-calls are not implemented\n");
951 return;
952 }
953
954 result = pSHGetPathFromIDListW(pidlEmpty, wszPath);
955 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
956 if (!result) return;
957 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDListW didn't return desktop path for empty pidl!\n");
958
959 /* MyComputer does not map to a filesystem path. SHGetPathFromIDListW should fail. */
960 hr = SHGetDesktopFolder(&psfDesktop);
961 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
962 if (FAILED(hr)) return;
963
964 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
965 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
966 if (FAILED(hr)) {
967 IShellFolder_Release(psfDesktop);
968 return;
969 }
970
971 SetLastError(0xdeadbeef);
972 wszPath[0] = 'a';
973 wszPath[1] = '\0';
974 result = pSHGetPathFromIDListW(pidlMyComputer, wszPath);
975 ok (!result, "SHGetPathFromIDListW succeeded where it shouldn't!\n");
976 ok (GetLastError()==0xdeadbeef ||
977 GetLastError()==ERROR_SUCCESS, /* Vista and higher */
978 "Unexpected last error from SHGetPathFromIDListW: %u\n", GetLastError());
979 ok (!wszPath[0], "Expected empty path\n");
980 if (result) {
981 IShellFolder_Release(psfDesktop);
982 return;
983 }
984
985 IMalloc_Free(ppM, pidlMyComputer);
986
987 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
988 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
989 if (!result) {
990 IShellFolder_Release(psfDesktop);
991 return;
992 }
993 myPathAddBackslashW(wszFileName);
994 lstrcatW(wszFileName, wszTestFile);
995 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
996 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
997 if (hTestFile == INVALID_HANDLE_VALUE) {
998 IShellFolder_Release(psfDesktop);
999 return;
1000 }
1001 CloseHandle(hTestFile);
1002
1003 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
1004 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
1005 if (FAILED(hr)) {
1006 IShellFolder_Release(psfDesktop);
1007 DeleteFileW(wszFileName);
1008 IMalloc_Free(ppM, pidlTestFile);
1009 return;
1010 }
1011
1012 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
1013 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
1014 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
1015 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
1016 IShellFolder_Release(psfDesktop);
1017 DeleteFileW(wszFileName);
1018 if (FAILED(hr)) {
1019 IMalloc_Free(ppM, pidlTestFile);
1020 return;
1021 }
1022 if (pStrRetToBufW)
1023 {
1024 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
1025 ok(0 == lstrcmpW(wszFileName, wszPath),
1026 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
1027 "returned incorrect path for file placed on desktop\n");
1028 }
1029
1030 result = pSHGetPathFromIDListW(pidlTestFile, wszPath);
1031 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
1032 IMalloc_Free(ppM, pidlTestFile);
1033 if (!result) return;
1034 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
1035
1036
1037 /* Test if we can get the path from the start menu "program files" PIDL. */
1038 hShell32 = GetModuleHandleA("shell32");
1039 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
1040
1041 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
1042 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
1043
1044 SetLastError(0xdeadbeef);
1045 result = pSHGetPathFromIDListW(pidlPrograms, wszPath);
1046 IMalloc_Free(ppM, pidlPrograms);
1047 ok(result, "SHGetPathFromIDListW failed\n");
1048 }
1049
1050 static void test_EnumObjects_and_CompareIDs(void)
1051 {
1052 ITEMIDLIST *newPIDL;
1053 IShellFolder *IDesktopFolder, *testIShellFolder;
1054 char cCurrDirA [MAX_PATH] = {0};
1055 static const CHAR cTestDirA[] = "\\testdir";
1056 WCHAR cTestDirW[MAX_PATH];
1057 int len;
1058 HRESULT hr;
1059
1060 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
1061 len = lstrlenA(cCurrDirA);
1062
1063 if(len == 0) {
1064 win_skip("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
1065 return;
1066 }
1067 if(cCurrDirA[len-1] == '\\')
1068 cCurrDirA[len-1] = 0;
1069
1070 lstrcatA(cCurrDirA, cTestDirA);
1071 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cTestDirW, MAX_PATH);
1072
1073 hr = SHGetDesktopFolder(&IDesktopFolder);
1074 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
1075
1076 CreateFilesFolders();
1077
1078 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
1079 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1080
1081 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
1082 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
1083
1084 test_EnumObjects(testIShellFolder);
1085
1086 IShellFolder_Release(testIShellFolder);
1087
1088 Cleanup();
1089
1090 IMalloc_Free(ppM, newPIDL);
1091
1092 IShellFolder_Release(IDesktopFolder);
1093 }
1094
1095 /* A simple implementation of an IPropertyBag, which returns fixed values for
1096 * 'Target' and 'Attributes' properties.
1097 */
1098 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
1099 void **ppvObject)
1100 {
1101 if (!ppvObject)
1102 return E_INVALIDARG;
1103
1104 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
1105 *ppvObject = iface;
1106 } else {
1107 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
1108 return E_NOINTERFACE;
1109 }
1110
1111 IPropertyBag_AddRef(iface);
1112 return S_OK;
1113 }
1114
1115 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
1116 return 2;
1117 }
1118
1119 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
1120 return 1;
1121 }
1122
1123 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
1124 VARIANT *pVar, IErrorLog *pErrorLog)
1125 {
1126 static const WCHAR wszTargetSpecialFolder[] = {
1127 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
1128 static const WCHAR wszTarget[] = {
1129 'T','a','r','g','e','t',0 };
1130 static const WCHAR wszAttributes[] = {
1131 'A','t','t','r','i','b','u','t','e','s',0 };
1132 static const WCHAR wszResolveLinkFlags[] = {
1133 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
1134 static const WCHAR wszTargetKnownFolder[] = {
1135 'T','a','r','g','e','t','K','n','o','w','n','F','o','l','d','e','r',0 };
1136 static const WCHAR wszCLSID[] = {
1137 'C','L','S','I','D',0 };
1138
1139 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
1140 ok(V_VT(pVar) == VT_I4 ||
1141 broken(V_VT(pVar) == VT_BSTR), /* Win2k */
1142 "Wrong variant type for 'TargetSpecialFolder' property!\n");
1143 return E_INVALIDARG;
1144 }
1145
1146 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
1147 {
1148 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
1149 return E_INVALIDARG;
1150 }
1151
1152 if (!lstrcmpW(pszPropName, wszTarget)) {
1153 WCHAR wszPath[MAX_PATH];
1154 BOOL result;
1155
1156 ok(V_VT(pVar) == VT_BSTR ||
1157 broken(V_VT(pVar) == VT_EMPTY), /* Win2k */
1158 "Wrong variant type for 'Target' property!\n");
1159 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
1160
1161 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1162 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1163 if (!result) return E_INVALIDARG;
1164
1165 V_BSTR(pVar) = SysAllocString(wszPath);
1166 return S_OK;
1167 }
1168
1169 if (!lstrcmpW(pszPropName, wszAttributes)) {
1170 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
1171 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
1172 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
1173 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1174 return S_OK;
1175 }
1176
1177 if (!lstrcmpW(pszPropName, wszTargetKnownFolder)) {
1178 ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'TargetKnownFolder' property!\n");
1179 /* TODO */
1180 return E_INVALIDARG;
1181 }
1182
1183 if (!lstrcmpW(pszPropName, wszCLSID)) {
1184 ok(V_VT(pVar) == VT_EMPTY, "Wrong variant type for 'CLSID' property!\n");
1185 /* TODO */
1186 return E_INVALIDARG;
1187 }
1188
1189 ok(FALSE, "PropertyBag was asked for unknown property %s (vt=%d)!\n", wine_dbgstr_w(pszPropName), V_VT(pVar));
1190 return E_INVALIDARG;
1191 }
1192
1193 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1194 VARIANT *pVar)
1195 {
1196 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1197 return E_NOTIMPL;
1198 }
1199
1200 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1201 InitPropertyBag_IPropertyBag_QueryInterface,
1202 InitPropertyBag_IPropertyBag_AddRef,
1203 InitPropertyBag_IPropertyBag_Release,
1204 InitPropertyBag_IPropertyBag_Read,
1205 InitPropertyBag_IPropertyBag_Write
1206 };
1207
1208 static struct IPropertyBag InitPropertyBag = {
1209 &InitPropertyBag_IPropertyBagVtbl
1210 };
1211
1212 static void test_FolderShortcut(void) {
1213 IPersistPropertyBag *pPersistPropertyBag;
1214 IShellFolder *pShellFolder, *pDesktopFolder;
1215 IPersistFolder3 *pPersistFolder3;
1216 HRESULT hr;
1217 STRRET strret;
1218 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1219 BOOL result;
1220 CLSID clsid;
1221 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1222 HKEY hShellExtKey;
1223 WCHAR wszWineTestFolder[] = {
1224 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1225 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1226 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1227 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1228 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1229 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1230 'N','a','m','e','S','p','a','c','e','\\',
1231 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1232 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1233
1234 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1235 static const GUID CLSID_UnixDosFolder =
1236 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1237
1238 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) {
1239 win_skip("SHGetSpecialFolderPathW and/or StrRetToBufW are not available\n");
1240 return;
1241 }
1242
1243 if (!pSHGetFolderPathAndSubDirA)
1244 {
1245 win_skip("FolderShortcut test doesn't work on Win2k\n");
1246 return;
1247 }
1248
1249 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1250 * via their IPersistPropertyBag interface. And that the target folder
1251 * is taken from the IPropertyBag's 'Target' property.
1252 */
1253 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1254 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1255 if (hr == REGDB_E_CLASSNOTREG) {
1256 win_skip("CLSID_FolderShortcut is not implemented\n");
1257 return;
1258 }
1259 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
1260 if (FAILED(hr)) return;
1261
1262 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1263 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
1264 if (FAILED(hr)) {
1265 IPersistPropertyBag_Release(pPersistPropertyBag);
1266 return;
1267 }
1268
1269 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1270 (LPVOID*)&pShellFolder);
1271 IPersistPropertyBag_Release(pPersistPropertyBag);
1272 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1273 if (FAILED(hr)) return;
1274
1275 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1276 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1277 if (FAILED(hr)) {
1278 IShellFolder_Release(pShellFolder);
1279 return;
1280 }
1281
1282 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1283 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1284 if (!result) return;
1285
1286 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1287 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1288
1289 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1290 IShellFolder_Release(pShellFolder);
1291 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
1292 if (FAILED(hr)) return;
1293
1294 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1295 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1296 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1297
1298 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1299 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1300 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1301
1302 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1303 * shell namespace. The target folder, read from the property bag above, remains untouched.
1304 * The following tests show this: The itemidlist for some imaginary shellfolder object
1305 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1306 * itemidlist, but GetDisplayNameOf still returns the path from above.
1307 */
1308 hr = SHGetDesktopFolder(&pDesktopFolder);
1309 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
1310 if (FAILED(hr)) return;
1311
1312 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1313 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1314 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1315 RegCloseKey(hShellExtKey);
1316 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1317 &pidlWineTestFolder, NULL);
1318 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1319 IShellFolder_Release(pDesktopFolder);
1320 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1321 if (FAILED(hr)) return;
1322
1323 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1324 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
1325 if (FAILED(hr)) {
1326 IPersistFolder3_Release(pPersistFolder3);
1327 pILFree(pidlWineTestFolder);
1328 return;
1329 }
1330
1331 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1332 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1333 ok(pILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1334 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1335 pILFree(pidlCurrentFolder);
1336 pILFree(pidlWineTestFolder);
1337
1338 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1339 IPersistFolder3_Release(pPersistFolder3);
1340 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1341 if (FAILED(hr)) return;
1342
1343 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1344 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1345 if (FAILED(hr)) {
1346 IShellFolder_Release(pShellFolder);
1347 return;
1348 }
1349
1350 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1351 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1352
1353 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1354 * but ShellFSFolders. */
1355 myPathAddBackslashW(wszDesktopPath);
1356 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1357 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1358 IShellFolder_Release(pShellFolder);
1359 return;
1360 }
1361
1362 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1363 &pidlSubFolder, NULL);
1364 RemoveDirectoryW(wszDesktopPath);
1365 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1366 if (FAILED(hr)) {
1367 IShellFolder_Release(pShellFolder);
1368 return;
1369 }
1370
1371 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1372 (LPVOID*)&pPersistFolder3);
1373 IShellFolder_Release(pShellFolder);
1374 pILFree(pidlSubFolder);
1375 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
1376 if (FAILED(hr))
1377 return;
1378
1379 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1380 * a little bit and also allow CLSID_UnixDosFolder. */
1381 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1382 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1383 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1384 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1385
1386 IPersistFolder3_Release(pPersistFolder3);
1387 }
1388
1389 #include "pshpack1.h"
1390 struct FileStructA {
1391 BYTE type;
1392 BYTE dummy;
1393 DWORD dwFileSize;
1394 WORD uFileDate; /* In our current implementation this is */
1395 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1396 WORD uFileAttribs;
1397 CHAR szName[1];
1398 };
1399
1400 struct FileStructW {
1401 WORD cbLen; /* Length of this element. */
1402 BYTE abFooBar1[6]; /* Beyond any recognition. */
1403 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1404 WORD uTime; /* (this is currently speculation) */
1405 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1406 WORD uTime2; /* (this is currently speculation) */
1407 BYTE abFooBar2[4]; /* Beyond any recognition. */
1408 WCHAR wszName[1]; /* The long filename in unicode. */
1409 /* Just for documentation: Right after the unicode string: */
1410 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1411 * SHITEMID->cb == uOffset + cbLen */
1412 };
1413 #include "poppack.h"
1414
1415 static void test_ITEMIDLIST_format(void) {
1416 WCHAR wszPersonal[MAX_PATH];
1417 LPSHELLFOLDER psfDesktop, psfPersonal;
1418 LPITEMIDLIST pidlPersonal, pidlFile;
1419 HANDLE hFile;
1420 HRESULT hr;
1421 BOOL bResult;
1422 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1423 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1424 int i;
1425
1426 if (!pSHGetSpecialFolderPathW) return;
1427
1428 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1429 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1430 if (!bResult) return;
1431
1432 SetLastError(0xdeadbeef);
1433 bResult = SetCurrentDirectoryW(wszPersonal);
1434 if (!bResult && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
1435 win_skip("Most W-calls are not implemented\n");
1436 return;
1437 }
1438 ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1439 if (!bResult) return;
1440
1441 hr = SHGetDesktopFolder(&psfDesktop);
1442 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
1443 if (FAILED(hr)) return;
1444
1445 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1446 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
1447 if (FAILED(hr)) {
1448 IShellFolder_Release(psfDesktop);
1449 return;
1450 }
1451
1452 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1453 (LPVOID*)&psfPersonal);
1454 IShellFolder_Release(psfDesktop);
1455 pILFree(pidlPersonal);
1456 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
1457 if (FAILED(hr)) return;
1458
1459 for (i=0; i<3; i++) {
1460 CHAR szFile[MAX_PATH];
1461 struct FileStructA *pFileStructA;
1462 WORD cbOffset;
1463
1464 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1465
1466 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1467 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
1468 if (hFile == INVALID_HANDLE_VALUE) {
1469 IShellFolder_Release(psfPersonal);
1470 return;
1471 }
1472 CloseHandle(hFile);
1473
1474 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1475 DeleteFileW(wszFile[i]);
1476 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
1477 if (FAILED(hr)) {
1478 IShellFolder_Release(psfPersonal);
1479 return;
1480 }
1481
1482 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1483 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1484 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1485 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1486
1487 if (i < 2) /* First two file names are already in valid 8.3 format */
1488 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1489 else
1490 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1491 * can't implement this correctly, since unix filesystems don't support
1492 * this nasty short/long filename stuff. So we'll probably stay with our
1493 * current habbit of storing the long filename here, which seems to work
1494 * just fine. */
1495 todo_wine
1496 ok(pidlFile->mkid.abID[18] == '~' ||
1497 broken(pidlFile->mkid.abID[34] == '~'), /* Win2k */
1498 "Should be derived 8.3 name!\n");
1499
1500 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1501 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0' ||
1502 broken(pidlFile->mkid.cb == 2 + 12 + strlen(szFile) + 1 + 1), /* Win2k */
1503 "Alignment byte, where there shouldn't be!\n");
1504
1505 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1506 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1507 "There should be an alignment byte, but isn't!\n");
1508
1509 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1510 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1511 ok ((cbOffset >= sizeof(struct FileStructA) &&
1512 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW)) ||
1513 broken(pidlFile->mkid.cb == 2 + 12 + strlen(szFile) + 1 + 1) || /* Win2k on short names */
1514 broken(pidlFile->mkid.cb == 2 + 12 + strlen(szFile) + 1 + 12 + 1), /* Win2k on long names */
1515 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1516
1517 if (cbOffset >= sizeof(struct FileStructA) &&
1518 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1519 {
1520 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1521
1522 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1523 "FileStructW's offset and length should add up to the PIDL's length!\n");
1524
1525 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1526 /* Since we just created the file, time of creation,
1527 * time of last access and time of last write access just be the same.
1528 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1529 * after the first run. I do remember something with NTFS keeping the creation time
1530 * if a file is deleted and then created again within a couple of seconds or so.
1531 * Might be the reason. */
1532 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1533 pFileStructA->uFileTime == pFileStructW->uTime,
1534 "Last write time should match creation time!\n");
1535
1536 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1537 pFileStructA->uFileTime == pFileStructW->uTime2,
1538 "Last write time should match last access time!\n");
1539
1540 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName) ||
1541 !lstrcmpW(wszFile[i], (WCHAR *)(pFileStructW->abFooBar2 + 22)), /* Vista */
1542 "The filename should be stored in unicode at this position!\n");
1543 }
1544 }
1545
1546 pILFree(pidlFile);
1547 }
1548 }
1549
1550 static void testSHGetFolderPathAndSubDirA(void)
1551 {
1552 HRESULT ret;
1553 BOOL delret;
1554 DWORD dwret;
1555 int i;
1556 static char wine[] = "wine";
1557 static char winetemp[] = "wine\\temp";
1558 static char appdata[MAX_PATH];
1559 static char testpath[MAX_PATH];
1560 static char toolongpath[MAX_PATH+1];
1561
1562 if(!pSHGetFolderPathA) {
1563 win_skip("SHGetFolderPathA not present!\n");
1564 return;
1565 }
1566 if(FAILED(pSHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdata)))
1567 {
1568 skip("SHGetFolderPathA failed for CSIDL_LOCAL_APPDATA!\n");
1569 return;
1570 }
1571
1572 sprintf(testpath, "%s\\%s", appdata, winetemp);
1573 delret = RemoveDirectoryA(testpath);
1574 if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) ) {
1575 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1576 return;
1577 }
1578
1579 sprintf(testpath, "%s\\%s", appdata, wine);
1580 delret = RemoveDirectoryA(testpath);
1581 if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) && (ERROR_FILE_NOT_FOUND != GetLastError())) {
1582 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1583 return;
1584 }
1585
1586 /* test invalid second parameter */
1587 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | 0xff, NULL, SHGFP_TYPE_CURRENT, wine, testpath);
1588 ok(E_INVALIDARG == ret, "expected E_INVALIDARG, got %x\n", ret);
1589
1590 /* test fourth parameter */
1591 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, 2, winetemp, testpath);
1592 switch(ret) {
1593 case S_OK: /* winvista */
1594 ok(!strncmp(appdata, testpath, strlen(appdata)),
1595 "expected %s to start with %s\n", testpath, appdata);
1596 ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1597 "expected %s to end with %s\n", testpath, winetemp);
1598 break;
1599 case E_INVALIDARG: /* winxp, win2k3 */
1600 break;
1601 default:
1602 ok(0, "expected S_OK or E_INVALIDARG, got %x\n", ret);
1603 }
1604
1605 /* test fifth parameter */
1606 testpath[0] = '\0';
1607 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, NULL, testpath);
1608 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1609 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1610
1611 testpath[0] = '\0';
1612 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "", testpath);
1613 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1614 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1615
1616 testpath[0] = '\0';
1617 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "\\", testpath);
1618 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1619 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1620
1621 for(i=0; i< MAX_PATH; i++)
1622 toolongpath[i] = '0' + i % 10;
1623 toolongpath[MAX_PATH] = '\0';
1624 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, toolongpath, testpath);
1625 ok(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE) == ret,
1626 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE), ret);
1627
1628 testpath[0] = '\0';
1629 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, wine, NULL);
1630 ok((S_OK == ret) || (E_INVALIDARG == ret), "expected S_OK or E_INVALIDARG, got %x\n", ret);
1631
1632 /* test a not existing path */
1633 testpath[0] = '\0';
1634 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1635 ok(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == ret,
1636 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), ret);
1637
1638 /* create a directory inside a not existing directory */
1639 testpath[0] = '\0';
1640 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_CREATE | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1641 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1642 ok(!strncmp(appdata, testpath, strlen(appdata)),
1643 "expected %s to start with %s\n", testpath, appdata);
1644 ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1645 "expected %s to end with %s\n", testpath, winetemp);
1646 dwret = GetFileAttributes(testpath);
1647 ok(FILE_ATTRIBUTE_DIRECTORY | dwret, "expected %x to contain FILE_ATTRIBUTE_DIRECTORY\n", dwret);
1648
1649 /* cleanup */
1650 sprintf(testpath, "%s\\%s", appdata, winetemp);
1651 RemoveDirectoryA(testpath);
1652 sprintf(testpath, "%s\\%s", appdata, wine);
1653 RemoveDirectoryA(testpath);
1654 }
1655
1656 static void test_LocalizedNames(void)
1657 {
1658 static char cCurrDirA[MAX_PATH];
1659 WCHAR cCurrDirW[MAX_PATH], tempbufW[25];
1660 IShellFolder *IDesktopFolder, *testIShellFolder;
1661 ITEMIDLIST *newPIDL;
1662 int len;
1663 HRESULT hr;
1664 static char resourcefile[MAX_PATH];
1665 DWORD res;
1666 HANDLE file;
1667 STRRET strret;
1668
1669 static const char desktopini_contents1[] =
1670 "[.ShellClassInfo]\r\n"
1671 "LocalizedResourceName=@";
1672 static const char desktopini_contents2[] =
1673 ",-1\r\n";
1674 static WCHAR foldernameW[] = {'t','e','s','t','f','o','l','d','e','r',0};
1675 static const WCHAR folderdisplayW[] = {'F','o','l','d','e','r',' ','N','a','m','e',' ','R','e','s','o','u','r','c','e',0};
1676
1677 /* create folder with desktop.ini and localized name in GetModuleFileNameA(NULL) */
1678 CreateDirectoryA(".\\testfolder", NULL);
1679
1680 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")|FILE_ATTRIBUTE_SYSTEM);
1681
1682 GetModuleFileNameA(NULL, resourcefile, MAX_PATH);
1683
1684 file = CreateFileA(".\\testfolder\\desktop.ini", GENERIC_WRITE, 0, NULL,
1685 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1686 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %i\n", GetLastError());
1687 ok(WriteFile(file, desktopini_contents1, strlen(desktopini_contents1), &res, NULL) &&
1688 WriteFile(file, resourcefile, strlen(resourcefile), &res, NULL) &&
1689 WriteFile(file, desktopini_contents2, strlen(desktopini_contents2), &res, NULL),
1690 "WriteFile failed %i\n", GetLastError());
1691 CloseHandle(file);
1692
1693 /* get IShellFolder for parent */
1694 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
1695 len = lstrlenA(cCurrDirA);
1696
1697 if (len == 0) {
1698 trace("GetCurrentDirectoryA returned empty string. Skipping test_LocalizedNames\n");
1699 goto cleanup;
1700 }
1701 if(cCurrDirA[len-1] == '\\')
1702 cCurrDirA[len-1] = 0;
1703
1704 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
1705
1706 hr = SHGetDesktopFolder(&IDesktopFolder);
1707 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
1708
1709 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
1710 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1711
1712 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
1713 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
1714
1715 IMalloc_Free(ppM, newPIDL);
1716
1717 /* windows reads the display name from the resource */
1718 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, foldernameW, NULL, &newPIDL, 0);
1719 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1720
1721 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER, &strret);
1722 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1723
1724 if (SUCCEEDED(hr) && pStrRetToBufW)
1725 {
1726 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1727 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1728 todo_wine
1729 ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1730 broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1731 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1732 }
1733
1734 /* editing name is also read from the resource */
1735 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FOREDITING, &strret);
1736 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1737
1738 if (SUCCEEDED(hr) && pStrRetToBufW)
1739 {
1740 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1741 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1742 todo_wine
1743 ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1744 broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1745 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1746 }
1747
1748 /* parsing name is unchanged */
1749 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FORPARSING, &strret);
1750 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1751
1752 if (SUCCEEDED(hr) && pStrRetToBufW)
1753 {
1754 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1755 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1756 ok (!lstrcmpiW(tempbufW, foldernameW), "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1757 }
1758
1759 IShellFolder_Release(IDesktopFolder);
1760 IShellFolder_Release(testIShellFolder);
1761
1762 IMalloc_Free(ppM, newPIDL);
1763
1764 cleanup:
1765 DeleteFileA(".\\testfolder\\desktop.ini");
1766 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")&~FILE_ATTRIBUTE_SYSTEM);
1767 RemoveDirectoryA(".\\testfolder");
1768 }
1769
1770 static void test_SHCreateShellItem(void)
1771 {
1772 IShellItem *shellitem, *shellitem2;
1773 IPersistIDList *persistidl;
1774 LPITEMIDLIST pidl_cwd=NULL, pidl_testfile, pidl_abstestfile, pidl_test;
1775 HRESULT ret;
1776 char curdirA[MAX_PATH];
1777 WCHAR curdirW[MAX_PATH];
1778 IShellFolder *desktopfolder=NULL, *currentfolder=NULL;
1779 static WCHAR testfileW[] = {'t','e','s','t','f','i','l','e',0};
1780
1781 GetCurrentDirectoryA(MAX_PATH, curdirA);
1782
1783 if (!lstrlenA(curdirA))
1784 {
1785 win_skip("GetCurrentDirectoryA returned empty string, skipping test_SHCreateShellItem\n");
1786 return;
1787 }
1788
1789 MultiByteToWideChar(CP_ACP, 0, curdirA, -1, curdirW, MAX_PATH);
1790
1791 ret = SHGetDesktopFolder(&desktopfolder);
1792 ok(SUCCEEDED(ret), "SHGetShellFolder returned %x\n", ret);
1793
1794 ret = IShellFolder_ParseDisplayName(desktopfolder, NULL, NULL, curdirW, NULL, &pidl_cwd, NULL);
1795 ok(SUCCEEDED(ret), "ParseDisplayName returned %x\n", ret);
1796
1797 ret = IShellFolder_BindToObject(desktopfolder, pidl_cwd, NULL, &IID_IShellFolder, (void**)&currentfolder);
1798 ok(SUCCEEDED(ret), "BindToObject returned %x\n", ret);
1799
1800 CreateTestFile(".\\testfile");
1801
1802 ret = IShellFolder_ParseDisplayName(currentfolder, NULL, NULL, testfileW, NULL, &pidl_testfile, NULL);
1803 ok(SUCCEEDED(ret), "ParseDisplayName returned %x\n", ret);
1804
1805 pidl_abstestfile = pILCombine(pidl_cwd, pidl_testfile);
1806
1807 ret = pSHCreateShellItem(NULL, NULL, NULL, &shellitem);
1808 ok(ret == E_INVALIDARG, "SHCreateShellItem returned %x\n", ret);
1809
1810 if (0) /* crashes on Windows XP */
1811 {
1812 pSHCreateShellItem(NULL, NULL, pidl_cwd, NULL);
1813 pSHCreateShellItem(pidl_cwd, NULL, NULL, &shellitem);
1814 pSHCreateShellItem(NULL, currentfolder, NULL, &shellitem);
1815 pSHCreateShellItem(pidl_cwd, currentfolder, NULL, &shellitem);
1816 }
1817
1818 ret = pSHCreateShellItem(NULL, NULL, pidl_cwd, &shellitem);
1819 ok(SUCCEEDED(ret), "SHCreateShellItem returned %x\n", ret);
1820 if (SUCCEEDED(ret))
1821 {
1822 ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl);
1823 ok(SUCCEEDED(ret), "QueryInterface returned %x\n", ret);
1824 if (SUCCEEDED(ret))
1825 {
1826 ret = IPersistIDList_GetIDList(persistidl, &pidl_test);
1827 ok(SUCCEEDED(ret), "GetIDList returned %x\n", ret);
1828 if (SUCCEEDED(ret))
1829 {
1830 ok(ILIsEqual(pidl_cwd, pidl_test), "id lists are not equal\n");
1831 pILFree(pidl_test);
1832 }
1833 IPersistIDList_Release(persistidl);
1834 }
1835 IShellItem_Release(shellitem);
1836 }
1837
1838 ret = pSHCreateShellItem(pidl_cwd, NULL, pidl_testfile, &shellitem);
1839 ok(SUCCEEDED(ret), "SHCreateShellItem returned %x\n", ret);
1840 if (SUCCEEDED(ret))
1841 {
1842 ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl);
1843 ok(SUCCEEDED(ret), "QueryInterface returned %x\n", ret);
1844 if (SUCCEEDED(ret))
1845 {
1846 ret = IPersistIDList_GetIDList(persistidl, &pidl_test);
1847 ok(SUCCEEDED(ret), "GetIDList returned %x\n", ret);
1848 if (SUCCEEDED(ret))
1849 {
1850 ok(ILIsEqual(pidl_abstestfile, pidl_test), "id lists are not equal\n");
1851 pILFree(pidl_test);
1852 }
1853 IPersistIDList_Release(persistidl);
1854 }
1855
1856 ret = IShellItem_GetParent(shellitem, &shellitem2);
1857 ok(SUCCEEDED(ret), "GetParent returned %x\n", ret);
1858 if (SUCCEEDED(ret))
1859 {
1860 ret = IShellItem_QueryInterface(shellitem2, &IID_IPersistIDList, (void**)&persistidl);
1861 ok(SUCCEEDED(ret), "QueryInterface returned %x\n", ret);
1862 if (SUCCEEDED(ret))
1863 {
1864 ret = IPersistIDList_GetIDList(persistidl, &pidl_test);
1865 ok(SUCCEEDED(ret), "GetIDList returned %x\n", ret);
1866 if (SUCCEEDED(ret))
1867 {
1868 ok(ILIsEqual(pidl_cwd, pidl_test), "id lists are not equal\n");
1869 pILFree(pidl_test);
1870 }
1871 IPersistIDList_Release(persistidl);
1872 }
1873 IShellItem_Release(shellitem2);
1874 }
1875
1876 IShellItem_Release(shellitem);
1877 }
1878
1879 ret = pSHCreateShellItem(NULL, currentfolder, pidl_testfile, &shellitem);
1880 ok(SUCCEEDED(ret), "SHCreateShellItem returned %x\n", ret);
1881 if (SUCCEEDED(ret))
1882 {
1883 ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl);
1884 ok(SUCCEEDED(ret), "QueryInterface returned %x\n", ret);
1885 if (SUCCEEDED(ret))
1886 {
1887 ret = IPersistIDList_GetIDList(persistidl, &pidl_test);
1888 ok(SUCCEEDED(ret), "GetIDList returned %x\n", ret);
1889 if (SUCCEEDED(ret))
1890 {
1891 ok(ILIsEqual(pidl_abstestfile, pidl_test), "id lists are not equal\n");
1892 pILFree(pidl_test);
1893 }
1894 IPersistIDList_Release(persistidl);
1895 }
1896 IShellItem_Release(shellitem);
1897 }
1898
1899 /* if a parent pidl and shellfolder are specified, the shellfolder is ignored */
1900 ret = pSHCreateShellItem(pidl_cwd, desktopfolder, pidl_testfile, &shellitem);
1901 ok(SUCCEEDED(ret), "SHCreateShellItem returned %x\n", ret);
1902 if (SUCCEEDED(ret))
1903 {
1904 ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl);
1905 ok(SUCCEEDED(ret), "QueryInterface returned %x\n", ret);
1906 if (SUCCEEDED(ret))
1907 {
1908 ret = IPersistIDList_GetIDList(persistidl, &pidl_test);
1909 ok(SUCCEEDED(ret), "GetIDList returned %x\n", ret);
1910 if (SUCCEEDED(ret))
1911 {
1912 ok(ILIsEqual(pidl_abstestfile, pidl_test), "id lists are not equal\n");
1913 pILFree(pidl_test);
1914 }
1915 IPersistIDList_Release(persistidl);
1916 }
1917 IShellItem_Release(shellitem);
1918 }
1919
1920 DeleteFileA(".\\testfile");
1921 pILFree(pidl_abstestfile);
1922 pILFree(pidl_testfile);
1923 pILFree(pidl_cwd);
1924 IShellFolder_Release(currentfolder);
1925 IShellFolder_Release(desktopfolder);
1926 }
1927
1928 START_TEST(shlfolder)
1929 {
1930 init_function_pointers();
1931 /* if OleInitialize doesn't get called, ParseDisplayName returns
1932 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1933 OleInitialize(NULL);
1934
1935 test_ParseDisplayName();
1936 test_BindToObject();
1937 test_EnumObjects_and_CompareIDs();
1938 test_GetDisplayName();
1939 test_GetAttributesOf();
1940 test_SHGetPathFromIDList();
1941 test_CallForAttributes();
1942 test_FolderShortcut();
1943 test_ITEMIDLIST_format();
1944 if(pSHGetFolderPathAndSubDirA)
1945 testSHGetFolderPathAndSubDirA();
1946 else
1947 skip("SHGetFolderPathAndSubDirA not present\n");
1948 test_LocalizedNames();
1949 if(pSHCreateShellItem)
1950 test_SHCreateShellItem();
1951 else
1952 win_skip("test_SHCreateShellItem not present\n");
1953
1954 OleUninitialize();
1955 }