2 * Unit test of the IShellFolder functions.
4 * Copyright 2004 Vitaliy Margolen
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include "wine/unicode.h"
39 #include "wine/test.h"
44 static HRESULT (WINAPI *pSHBindToParent)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*);
45 static BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
47 static void init_function_pointers(void)
49 HMODULE hmod = GetModuleHandleA("shell32.dll");
54 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
55 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
58 hr = SHGetMalloc(&ppM);
59 ok(hr == S_OK, "SHGetMalloc failed %08lx\n", hr);
62 /* creates a file with the specified name for tests */
63 static void CreateTestFile(const CHAR *name)
68 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
69 if (file != INVALID_HANDLE_VALUE)
71 WriteFile(file, name, strlen(name), &written, NULL);
72 WriteFile(file, "\n", strlen("\n"), &written, NULL);
78 /* initializes the tests */
79 static void CreateFilesFolders(void)
81 CreateDirectoryA(".\\testdir", NULL);
82 CreateDirectoryA(".\\testdir\\test.txt", NULL);
83 CreateTestFile (".\\testdir\\test1.txt ");
84 CreateTestFile (".\\testdir\\test2.txt ");
85 CreateTestFile (".\\testdir\\test3.txt ");
86 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
87 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
90 /* cleans after tests */
91 static void Cleanup(void)
93 DeleteFileA(".\\testdir\\test1.txt");
94 DeleteFileA(".\\testdir\\test2.txt");
95 DeleteFileA(".\\testdir\\test3.txt");
96 RemoveDirectoryA(".\\testdir\\test.txt");
97 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
98 RemoveDirectoryA(".\\testdir\\testdir2");
99 RemoveDirectoryA(".\\testdir");
104 static void test_EnumObjects(IShellFolder *iFolder)
106 IEnumIDList *iEnumList;
107 LPITEMIDLIST newPIDL, idlArr[10];
112 static const WORD iResults [5][5] =
121 /* Just test SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR for now */
122 static const ULONG attrs[5] =
124 SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
125 SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
131 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
132 ok(hr == S_OK, "EnumObjects failed %08lx\n", hr);
134 /* This is to show that, contrary to what is said on MSDN on IEnumIDList::Next,
135 * the filesystem shellfolders return S_OK even if less then 'celt' items are
136 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
137 * only ever returns a single entry per call. */
138 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
140 ok (i == 5, "i: %d\n", i);
142 hr = IEnumIDList_Release(iEnumList);
143 ok(hr == S_OK, "IEnumIDList_Release failed %08lx\n", hr);
145 /* Sort them first in case of wrong order from system */
146 for (i=0;i<5;i++) for (j=0;j<5;j++)
147 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
150 idlArr[i] = idlArr[j];
154 for (i=0;i<5;i++) for (j=0;j<5;j++)
156 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
157 ok(hr == iResults[i][j], "Got %lx expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
161 for (i = 0; i < 5; i++)
164 flags = SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR;
165 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
166 flags &= SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR;
167 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
168 ok(flags == attrs[i], "GetAttributesOf gets attrs %08lx, expects %08lx\n", flags, attrs[i]);
172 IMalloc_Free(ppM, idlArr[i]);
175 static void test_BindToObject(void)
179 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
180 SHITEMID emptyitem = { 0, { 0 } };
181 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
182 WCHAR wszSystemDir[MAX_PATH];
183 WCHAR wszMyComputer[] = {
184 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
185 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
187 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
188 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
190 hr = SHGetDesktopFolder(&psfDesktop);
191 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
192 if (FAILED(hr)) return;
194 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
195 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
197 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
198 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
200 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
201 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
203 IShellFolder_Release(psfDesktop);
207 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
208 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
209 IShellFolder_Release(psfDesktop);
210 IMalloc_Free(ppM, pidlMyComputer);
211 if (FAILED(hr)) return;
213 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
214 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
216 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
217 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
219 cChars = GetSystemDirectoryW(wszSystemDir, MAX_PATH);
220 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryW failed! LastError: %08lx\n", GetLastError());
221 if (cChars == 0 || cChars >= MAX_PATH) {
222 IShellFolder_Release(psfMyComputer);
226 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
227 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08lx\n", hr);
229 IShellFolder_Release(psfMyComputer);
233 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
234 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08lx\n", hr);
235 IShellFolder_Release(psfMyComputer);
236 IMalloc_Free(ppM, pidlSystemDir);
237 if (FAILED(hr)) return;
239 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
240 ok (hr == E_INVALIDARG,
241 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
243 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
244 ok (hr == E_INVALIDARG,
245 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
247 IShellFolder_Release(psfSystemDir);
250 static void test_GetDisplayName(void)
255 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
257 LPSHELLFOLDER psfDesktop, psfPersonal;
259 LPITEMIDLIST pidlTestFile;
260 LPCITEMIDLIST pidlLast;
261 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
262 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
264 /* I'm trying to figure if there is a functional difference between calling
265 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
266 * binding to the shellfolder. One thing I thought of was that perhaps
267 * SHGetPathFromIDList would be able to get the path to a file, which does
268 * not exist anymore, while the other method would'nt. It turns out there's
269 * no functional difference in this respect.
272 if(!pSHGetSpecialFolderPathW) return;
274 /* First creating a directory in MyDocuments and a file in this directory. */
275 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
276 ok(result, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
279 PathAddBackslashW(wszTestDir);
280 lstrcatW(wszTestDir, wszDirName);
281 result = CreateDirectoryW(wszTestDir, NULL);
282 ok(result, "CreateDirectoryW failed! Last error: %08lx\n", GetLastError());
285 lstrcpyW(wszTestFile, wszTestDir);
286 PathAddBackslashW(wszTestFile);
287 lstrcatW(wszTestFile, wszFileName);
289 hTestFile = CreateFileW(wszTestFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
290 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %08lx\n", GetLastError());
291 if (hTestFile == INVALID_HANDLE_VALUE) return;
292 CloseHandle(hTestFile);
294 /* Getting an itemidlist for the file. */
295 hr = SHGetDesktopFolder(&psfDesktop);
296 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
297 if (FAILED(hr)) return;
299 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
300 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08lx\n", hr);
302 IShellFolder_Release(psfDesktop);
306 /* It seems as if we cannot bind to regular files on windows, but only directories.
308 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
309 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08lx\n", hr); }
311 IShellFolder_Release(psfFile);
314 /* Deleting the file and the directory */
315 DeleteFileW(wszTestFile);
316 RemoveDirectoryW(wszTestDir);
318 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
319 result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
320 ok (result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
321 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
323 if(!pSHBindToParent) return;
325 /* Binding to the folder and querying the display name of the file also works. */
326 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
327 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08lx\n", hr);
329 IShellFolder_Release(psfDesktop);
333 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
334 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08lx\n", hr);
336 IShellFolder_Release(psfDesktop);
337 IShellFolder_Release(psfPersonal);
341 hr = StrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
342 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08lx\n", hr);
343 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
345 IShellFolder_Release(psfDesktop);
346 IShellFolder_Release(psfPersonal);
349 static void test_CallForAttributes(void)
355 LPSHELLFOLDER psfDesktop;
356 LPITEMIDLIST pidlMyDocuments;
357 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
358 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
359 static const WCHAR wszCallForAttributes[] = {
360 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
361 static const WCHAR wszMyDocumentsKey[] = {
362 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
363 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
364 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
365 WCHAR wszMyDocuments[] = {
366 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
367 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
369 /* For the root of a namespace extension, the attributes are not queried by binding
370 * to the object and calling GetAttributesOf. Instead, the attributes are read from
371 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
373 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
374 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
375 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
376 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
378 hr = SHGetDesktopFolder(&psfDesktop);
379 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
380 if (FAILED(hr)) return;
382 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
383 &pidlMyDocuments, NULL);
385 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08lx\n", hr);
387 IShellFolder_Release(psfDesktop);
391 dwAttributes = 0xffffffff;
392 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
393 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
394 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
396 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
397 todo_wine{ ok (dwAttributes & SFGAO_FILESYSTEM,
398 "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n"); }
399 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
400 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
402 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
403 * key. So the test will return at this point, if run on wine.
405 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
406 todo_wine { ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08lx\n", lResult); }
407 if (lResult != ERROR_SUCCESS) {
408 IMalloc_Free(ppM, pidlMyDocuments);
409 IShellFolder_Release(psfDesktop);
413 /* Query MyDocuments' Attributes value, to be able to restore it later. */
414 dwSize = sizeof(DWORD);
415 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
416 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
417 if (lResult != ERROR_SUCCESS) {
419 IMalloc_Free(ppM, pidlMyDocuments);
420 IShellFolder_Release(psfDesktop);
424 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
425 dwSize = sizeof(DWORD);
426 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
427 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
428 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
429 if (lResult != ERROR_SUCCESS) {
431 IMalloc_Free(ppM, pidlMyDocuments);
432 IShellFolder_Release(psfDesktop);
436 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
437 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
438 * SFGAO_FILESYSTEM attributes. */
439 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
440 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
441 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
442 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
443 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
445 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
446 * GetAttributesOf. It seems that once there is a single attribute queried, for which
447 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
448 * the flags in Attributes are ignored.
450 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
451 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
452 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
453 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
455 ok (dwAttributes == SFGAO_FILESYSTEM,
456 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08lx\n",
459 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
460 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
461 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
462 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
464 IMalloc_Free(ppM, pidlMyDocuments);
465 IShellFolder_Release(psfDesktop);
468 static void test_GetAttributesOf(void)
471 LPSHELLFOLDER psfDesktop, psfMyComputer;
472 SHITEMID emptyitem = { 0, { 0 } };
473 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
474 LPITEMIDLIST pidlMyComputer;
476 const static DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
477 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGE_ANCESTOR |
478 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
479 const static DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
480 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
481 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
482 WCHAR wszMyComputer[] = {
483 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
484 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
486 hr = SHGetDesktopFolder(&psfDesktop);
487 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
488 if (FAILED(hr)) return;
490 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
491 dwFlags = 0xffffffff;
492 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
493 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08lx\n", hr);
494 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
495 dwFlags, dwDesktopFlags);
497 /* .. or with no itemidlist at all. */
498 dwFlags = 0xffffffff;
499 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
500 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
501 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
502 dwFlags, dwDesktopFlags);
504 /* Testing the attributes of the MyComputer shellfolder */
505 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
506 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
508 IShellFolder_Release(psfDesktop);
512 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
513 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
514 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
515 * should create a link to the original data". You can't create links on MyComputer on
516 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
517 * depends on this bug, we probably shouldn't imitate it.
519 dwFlags = 0xffffffff;
520 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
521 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08lx\n", hr);
522 todo_wine { ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
523 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags); }
525 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
526 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
527 IShellFolder_Release(psfDesktop);
528 IMalloc_Free(ppM, pidlMyComputer);
529 if (FAILED(hr)) return;
531 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
532 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08lx\n", hr); }
534 dwFlags = 0xffffffff;
535 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
536 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
537 todo_wine { ok (dwFlags == dwMyComputerFlags,
538 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags); }
540 IShellFolder_Release(psfMyComputer);
543 static void test_SHGetPathFromIDList(void)
545 SHITEMID emptyitem = { 0, { 0 } };
546 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
547 LPITEMIDLIST pidlMyComputer;
548 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
551 LPSHELLFOLDER psfDesktop;
552 WCHAR wszMyComputer[] = {
553 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
554 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
556 if(!pSHGetSpecialFolderPathW) return;
558 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
559 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
560 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %08lx\n", GetLastError());
563 result = SHGetPathFromIDListW(pidlEmpty, wszPath);
564 ok(result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
566 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
568 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
569 hr = SHGetDesktopFolder(&psfDesktop);
570 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
571 if (FAILED(hr)) return;
573 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
574 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
575 IShellFolder_Release(psfDesktop);
576 if (FAILED(hr)) return;
578 SetLastError(0xdeadbeef);
579 result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
580 ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
581 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %08lx\n", GetLastError());
583 IMalloc_Free(ppM, pidlMyComputer);
586 static void test_EnumObjects_and_CompareIDs(void)
589 IShellFolder *IDesktopFolder, *testIShellFolder;
590 char cCurrDirA [MAX_PATH] = {0};
591 WCHAR cCurrDirW [MAX_PATH];
592 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
595 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
596 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
597 strcatW(cCurrDirW, cTestDirW);
599 hr = SHGetDesktopFolder(&IDesktopFolder);
600 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
602 CreateFilesFolders();
604 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
605 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
607 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
608 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
610 test_EnumObjects(testIShellFolder);
612 hr = IShellFolder_Release(testIShellFolder);
613 ok(hr == S_OK, "IShellFolder_Release failed %08lx\n", hr);
617 IMalloc_Free(ppM, newPIDL);
620 START_TEST(shlfolder)
622 init_function_pointers();
623 /* if OleInitialize doesn't get called, ParseDisplayName returns
624 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
628 test_EnumObjects_and_CompareIDs();
629 test_GetDisplayName();
630 test_GetAttributesOf();
631 test_SHGetPathFromIDList();
632 test_CallForAttributes();