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 ITEMIDLIST *newPIDL, *(idlArr [5]);
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 while (IEnumIDList_Next(iEnumList, 1, &newPIDL, &NumPIDLs) == S_OK)
136 idlArr[i++] = newPIDL;
139 hr = IEnumIDList_Release(iEnumList);
140 ok(hr == S_OK, "IEnumIDList_Release failed %08lx\n", hr);
142 /* Sort them first in case of wrong order from system */
143 for (i=0;i<5;i++) for (j=0;j<5;j++)
144 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
147 idlArr[i] = idlArr[j];
151 for (i=0;i<5;i++) for (j=0;j<5;j++)
153 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
154 ok(hr == iResults[i][j], "Got %lx expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
158 for (i = 0; i < 5; i++)
161 flags = SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR;
162 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
163 flags &= SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR;
164 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
165 ok(flags == attrs[i], "GetAttributesOf gets attrs %08lx, expects %08lx\n", flags, attrs[i]);
169 IMalloc_Free(ppM, idlArr[i]);
172 static void test_BindToObject(void)
176 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
177 SHITEMID emptyitem = { 0, { 0 } };
178 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
179 WCHAR wszSystemDir[MAX_PATH];
180 WCHAR wszMyComputer[] = {
181 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
182 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
184 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
185 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
187 hr = SHGetDesktopFolder(&psfDesktop);
188 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
189 if (FAILED(hr)) return;
191 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
192 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
194 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
195 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
197 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
198 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
200 IShellFolder_Release(psfDesktop);
204 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
205 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
206 IShellFolder_Release(psfDesktop);
207 IMalloc_Free(ppM, pidlMyComputer);
208 if (FAILED(hr)) return;
210 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
211 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
213 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
214 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
216 cChars = GetSystemDirectoryW(wszSystemDir, MAX_PATH);
217 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryW failed! LastError: %08lx\n", GetLastError());
218 if (cChars == 0 || cChars >= MAX_PATH) {
219 IShellFolder_Release(psfMyComputer);
223 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
224 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08lx\n", hr);
226 IShellFolder_Release(psfMyComputer);
230 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
231 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08lx\n", hr);
232 IShellFolder_Release(psfMyComputer);
233 IMalloc_Free(ppM, pidlSystemDir);
234 if (FAILED(hr)) return;
236 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
237 ok (hr == E_INVALIDARG,
238 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
240 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
241 ok (hr == E_INVALIDARG,
242 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
244 IShellFolder_Release(psfSystemDir);
247 static void test_GetDisplayName(void)
252 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
254 LPSHELLFOLDER psfDesktop, psfPersonal;
256 LPITEMIDLIST pidlTestFile;
257 LPCITEMIDLIST pidlLast;
258 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
259 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
261 /* I'm trying to figure if there is a functional difference between calling
262 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
263 * binding to the shellfolder. One thing I thought of was that perhaps
264 * SHGetPathFromIDList would be able to get the path to a file, which does
265 * not exist anymore, while the other method would'nt. It turns out there's
266 * no functional difference in this respect.
269 if(!pSHGetSpecialFolderPathW) return;
271 /* First creating a directory in MyDocuments and a file in this directory. */
272 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
273 ok(result, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
276 PathAddBackslashW(wszTestDir);
277 lstrcatW(wszTestDir, wszDirName);
278 result = CreateDirectoryW(wszTestDir, NULL);
279 ok(result, "CreateDirectoryW failed! Last error: %08lx\n", GetLastError());
282 lstrcpyW(wszTestFile, wszTestDir);
283 PathAddBackslashW(wszTestFile);
284 lstrcatW(wszTestFile, wszFileName);
286 hTestFile = CreateFileW(wszTestFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
287 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %08lx\n", GetLastError());
288 if (hTestFile == INVALID_HANDLE_VALUE) return;
289 CloseHandle(hTestFile);
291 /* Getting an itemidlist for the file. */
292 hr = SHGetDesktopFolder(&psfDesktop);
293 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
294 if (FAILED(hr)) return;
296 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
297 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08lx\n", hr);
299 IShellFolder_Release(psfDesktop);
303 /* It seems as if we cannot bind to regular files on windows, but only directories.
305 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
306 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08lx\n", hr); }
308 IShellFolder_Release(psfFile);
311 /* Deleting the file and the directory */
312 DeleteFileW(wszTestFile);
313 RemoveDirectoryW(wszTestDir);
315 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
316 result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
317 ok (result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
318 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
320 if(!pSHBindToParent) return;
322 /* Binding to the folder and querying the display name of the file also works. */
323 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
324 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08lx\n", hr);
326 IShellFolder_Release(psfDesktop);
330 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
331 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08lx\n", hr);
333 IShellFolder_Release(psfDesktop);
334 IShellFolder_Release(psfPersonal);
338 hr = StrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
339 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08lx\n", hr);
340 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
342 IShellFolder_Release(psfDesktop);
343 IShellFolder_Release(psfPersonal);
346 static void test_CallForAttributes(void)
352 LPSHELLFOLDER psfDesktop;
353 LPITEMIDLIST pidlMyDocuments;
354 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
355 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
356 static const WCHAR wszCallForAttributes[] = {
357 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
358 static const WCHAR wszMyDocumentsKey[] = {
359 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
360 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
361 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
362 WCHAR wszMyDocuments[] = {
363 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
364 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
366 /* For the root of a namespace extension, the attributes are not queried by binding
367 * to the object and calling GetAttributesOf. Instead, the attributes are read from
368 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
370 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
371 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
372 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
373 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
375 hr = SHGetDesktopFolder(&psfDesktop);
376 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
377 if (FAILED(hr)) return;
379 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
380 &pidlMyDocuments, NULL);
382 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08lx\n", hr);
384 IShellFolder_Release(psfDesktop);
388 dwAttributes = 0xffffffff;
389 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
390 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
391 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
393 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
394 todo_wine{ ok (dwAttributes & SFGAO_FILESYSTEM,
395 "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n"); }
396 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
397 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
399 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
400 * key. So the test will return at this point, if run on wine.
402 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
403 todo_wine { ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08lx\n", lResult); }
404 if (lResult != ERROR_SUCCESS) {
405 IMalloc_Free(ppM, pidlMyDocuments);
406 IShellFolder_Release(psfDesktop);
410 /* Query MyDocuments' Attributes value, to be able to restore it later. */
411 dwSize = sizeof(DWORD);
412 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
413 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
414 if (lResult != ERROR_SUCCESS) {
416 IMalloc_Free(ppM, pidlMyDocuments);
417 IShellFolder_Release(psfDesktop);
421 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
422 dwSize = sizeof(DWORD);
423 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
424 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
425 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
426 if (lResult != ERROR_SUCCESS) {
428 IMalloc_Free(ppM, pidlMyDocuments);
429 IShellFolder_Release(psfDesktop);
433 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
434 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
435 * SFGAO_FILESYSTEM attributes. */
436 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
437 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
438 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
439 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
440 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
442 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
443 * GetAttributesOf. It seems that once there is a single attribute queried, for which
444 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
445 * the flags in Attributes are ignored.
447 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
448 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
449 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
450 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
452 ok (dwAttributes == SFGAO_FILESYSTEM,
453 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08lx\n",
456 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
457 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
458 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
459 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
461 IMalloc_Free(ppM, pidlMyDocuments);
462 IShellFolder_Release(psfDesktop);
465 static void test_GetAttributesOf(void)
468 LPSHELLFOLDER psfDesktop, psfMyComputer;
469 SHITEMID emptyitem = { 0, { 0 } };
470 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
471 LPITEMIDLIST pidlMyComputer;
473 const static DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
474 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGE_ANCESTOR |
475 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
476 const static DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
477 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
478 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
479 WCHAR wszMyComputer[] = {
480 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
481 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
483 hr = SHGetDesktopFolder(&psfDesktop);
484 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
485 if (FAILED(hr)) return;
487 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
488 dwFlags = 0xffffffff;
489 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
490 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08lx\n", hr);
491 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
492 dwFlags, dwDesktopFlags);
494 /* .. or with no itemidlist at all. */
495 dwFlags = 0xffffffff;
496 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
497 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
498 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
499 dwFlags, dwDesktopFlags);
501 /* Testing the attributes of the MyComputer shellfolder */
502 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
503 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
505 IShellFolder_Release(psfDesktop);
509 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
510 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
511 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
512 * should create a link to the original data". You can't create links on MyComputer on
513 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
514 * depends on this bug, we probably shouldn't imitate it.
516 dwFlags = 0xffffffff;
517 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
518 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08lx\n", hr);
519 todo_wine { ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
520 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags); }
522 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
523 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
524 IShellFolder_Release(psfDesktop);
525 IMalloc_Free(ppM, pidlMyComputer);
526 if (FAILED(hr)) return;
528 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
529 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08lx\n", hr); }
531 dwFlags = 0xffffffff;
532 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
533 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
534 todo_wine { ok (dwFlags == dwMyComputerFlags,
535 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags); }
537 IShellFolder_Release(psfMyComputer);
540 static void test_SHGetPathFromIDList(void)
542 SHITEMID emptyitem = { 0, { 0 } };
543 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
544 LPITEMIDLIST pidlMyComputer;
545 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
548 LPSHELLFOLDER psfDesktop;
549 WCHAR wszMyComputer[] = {
550 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
551 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
553 if(!pSHGetSpecialFolderPathW) return;
555 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
556 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
557 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %08lx\n", GetLastError());
560 result = SHGetPathFromIDListW(pidlEmpty, wszPath);
561 ok(result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
563 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
565 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
566 hr = SHGetDesktopFolder(&psfDesktop);
567 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
568 if (FAILED(hr)) return;
570 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
571 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
572 IShellFolder_Release(psfDesktop);
573 if (FAILED(hr)) return;
575 SetLastError(0xdeadbeef);
576 result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
577 ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
578 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %08lx\n", GetLastError());
580 IMalloc_Free(ppM, pidlMyComputer);
583 static void test_EnumObjects_and_CompareIDs(void)
586 IShellFolder *IDesktopFolder, *testIShellFolder;
587 char cCurrDirA [MAX_PATH] = {0};
588 WCHAR cCurrDirW [MAX_PATH];
589 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
592 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
593 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
594 strcatW(cCurrDirW, cTestDirW);
596 hr = SHGetDesktopFolder(&IDesktopFolder);
597 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
599 CreateFilesFolders();
601 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
602 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
604 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
605 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
607 test_EnumObjects(testIShellFolder);
609 hr = IShellFolder_Release(testIShellFolder);
610 ok(hr == S_OK, "IShellFolder_Release failed %08lx\n", hr);
614 IMalloc_Free(ppM, newPIDL);
617 START_TEST(shlfolder)
619 init_function_pointers();
620 /* if OleInitialize doesn't get called, ParseDisplayName returns
621 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
625 test_EnumObjects_and_CompareIDs();
626 test_GetDisplayName();
627 test_GetAttributesOf();
628 test_SHGetPathFromIDList();
629 test_CallForAttributes();