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 static void test_ParseDisplayName(void)
65 IShellFolder *IDesktopFolder;
66 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
67 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
69 WCHAR cTestDirW [MAX_PATH] = {0};
72 hr = SHGetDesktopFolder(&IDesktopFolder);
73 if(hr != S_OK) return;
75 res = GetFileAttributesA(cNonExistDir1A);
76 if(res != INVALID_FILE_ATTRIBUTES) return;
78 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
79 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
80 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
81 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
82 "ParseDisplayName returned %08lx, expected 80070002 or E_FAIL\n", hr);
84 res = GetFileAttributesA(cNonExistDir2A);
85 if(res != INVALID_FILE_ATTRIBUTES) return;
87 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
88 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
89 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
90 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
91 "ParseDisplayName returned %08lx, expected 80070002 or E_FAIL\n", hr);
94 /* creates a file with the specified name for tests */
95 static void CreateTestFile(const CHAR *name)
100 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
101 if (file != INVALID_HANDLE_VALUE)
103 WriteFile(file, name, strlen(name), &written, NULL);
104 WriteFile(file, "\n", strlen("\n"), &written, NULL);
110 /* initializes the tests */
111 static void CreateFilesFolders(void)
113 CreateDirectoryA(".\\testdir", NULL);
114 CreateDirectoryA(".\\testdir\\test.txt", NULL);
115 CreateTestFile (".\\testdir\\test1.txt ");
116 CreateTestFile (".\\testdir\\test2.txt ");
117 CreateTestFile (".\\testdir\\test3.txt ");
118 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
119 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
122 /* cleans after tests */
123 static void Cleanup(void)
125 DeleteFileA(".\\testdir\\test1.txt");
126 DeleteFileA(".\\testdir\\test2.txt");
127 DeleteFileA(".\\testdir\\test3.txt");
128 RemoveDirectoryA(".\\testdir\\test.txt");
129 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
130 RemoveDirectoryA(".\\testdir\\testdir2");
131 RemoveDirectoryA(".\\testdir");
136 static void test_EnumObjects(IShellFolder *iFolder)
138 IEnumIDList *iEnumList;
139 LPITEMIDLIST newPIDL, idlArr[10];
144 static const WORD iResults [5][5] =
153 /* Just test SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR for now */
154 static const ULONG attrs[5] =
156 SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
157 SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
163 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
164 ok(hr == S_OK, "EnumObjects failed %08lx\n", hr);
166 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
167 * the filesystem shellfolders return S_OK even if less than 'celt' items are
168 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
169 * only ever returns a single entry per call. */
170 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
172 ok (i == 5, "i: %d\n", i);
174 hr = IEnumIDList_Release(iEnumList);
175 ok(hr == S_OK, "IEnumIDList_Release failed %08lx\n", hr);
177 /* Sort them first in case of wrong order from system */
178 for (i=0;i<5;i++) for (j=0;j<5;j++)
179 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
182 idlArr[i] = idlArr[j];
186 for (i=0;i<5;i++) for (j=0;j<5;j++)
188 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
189 ok(hr == iResults[i][j], "Got %lx expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
193 for (i = 0; i < 5; i++)
196 flags = SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR;
197 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
198 flags &= SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR;
199 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
200 ok(flags == attrs[i], "GetAttributesOf gets attrs %08lx, expects %08lx\n", flags, attrs[i]);
204 IMalloc_Free(ppM, idlArr[i]);
207 static void test_BindToObject(void)
211 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
212 SHITEMID emptyitem = { 0, { 0 } };
213 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
214 WCHAR wszSystemDir[MAX_PATH];
215 WCHAR wszMyComputer[] = {
216 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
217 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
219 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
220 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
222 hr = SHGetDesktopFolder(&psfDesktop);
223 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
224 if (FAILED(hr)) return;
226 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
227 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
229 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
230 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
232 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
233 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
235 IShellFolder_Release(psfDesktop);
239 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
240 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
241 IShellFolder_Release(psfDesktop);
242 IMalloc_Free(ppM, pidlMyComputer);
243 if (FAILED(hr)) return;
245 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
246 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
248 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
249 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
251 cChars = GetSystemDirectoryW(wszSystemDir, MAX_PATH);
252 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryW failed! LastError: %08lx\n", GetLastError());
253 if (cChars == 0 || cChars >= MAX_PATH) {
254 IShellFolder_Release(psfMyComputer);
258 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
259 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08lx\n", hr);
261 IShellFolder_Release(psfMyComputer);
265 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
266 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08lx\n", hr);
267 IShellFolder_Release(psfMyComputer);
268 IMalloc_Free(ppM, pidlSystemDir);
269 if (FAILED(hr)) return;
271 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
272 ok (hr == E_INVALIDARG,
273 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
275 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
276 ok (hr == E_INVALIDARG,
277 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
279 IShellFolder_Release(psfSystemDir);
282 static void test_GetDisplayName(void)
287 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
289 LPSHELLFOLDER psfDesktop, psfPersonal;
291 LPITEMIDLIST pidlTestFile;
292 LPCITEMIDLIST pidlLast;
293 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
294 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
296 /* I'm trying to figure if there is a functional difference between calling
297 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
298 * binding to the shellfolder. One thing I thought of was that perhaps
299 * SHGetPathFromIDList would be able to get the path to a file, which does
300 * not exist anymore, while the other method would'nt. It turns out there's
301 * no functional difference in this respect.
304 if(!pSHGetSpecialFolderPathW) return;
306 /* First creating a directory in MyDocuments and a file in this directory. */
307 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
308 ok(result, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
311 PathAddBackslashW(wszTestDir);
312 lstrcatW(wszTestDir, wszDirName);
313 result = CreateDirectoryW(wszTestDir, NULL);
314 ok(result, "CreateDirectoryW failed! Last error: %08lx\n", GetLastError());
317 lstrcpyW(wszTestFile, wszTestDir);
318 PathAddBackslashW(wszTestFile);
319 lstrcatW(wszTestFile, wszFileName);
321 hTestFile = CreateFileW(wszTestFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
322 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %08lx\n", GetLastError());
323 if (hTestFile == INVALID_HANDLE_VALUE) return;
324 CloseHandle(hTestFile);
326 /* Getting an itemidlist for the file. */
327 hr = SHGetDesktopFolder(&psfDesktop);
328 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
329 if (FAILED(hr)) return;
331 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
332 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08lx\n", hr);
334 IShellFolder_Release(psfDesktop);
338 /* It seems as if we cannot bind to regular files on windows, but only directories.
340 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
341 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08lx\n", hr); }
343 IShellFolder_Release(psfFile);
346 /* Deleting the file and the directory */
347 DeleteFileW(wszTestFile);
348 RemoveDirectoryW(wszTestDir);
350 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
351 result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
352 ok (result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
353 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
355 if(!pSHBindToParent) return;
357 /* Binding to the folder and querying the display name of the file also works. */
358 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
359 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08lx\n", hr);
361 IShellFolder_Release(psfDesktop);
365 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
366 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08lx\n", hr);
368 IShellFolder_Release(psfDesktop);
369 IShellFolder_Release(psfPersonal);
373 hr = StrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
374 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08lx\n", hr);
375 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
377 IShellFolder_Release(psfDesktop);
378 IShellFolder_Release(psfPersonal);
381 static void test_CallForAttributes(void)
387 LPSHELLFOLDER psfDesktop;
388 LPITEMIDLIST pidlMyDocuments;
389 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
390 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
391 static const WCHAR wszCallForAttributes[] = {
392 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
393 static const WCHAR wszMyDocumentsKey[] = {
394 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
395 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
396 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
397 WCHAR wszMyDocuments[] = {
398 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
399 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
401 /* For the root of a namespace extension, the attributes are not queried by binding
402 * to the object and calling GetAttributesOf. Instead, the attributes are read from
403 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
405 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
406 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
407 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
408 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
410 hr = SHGetDesktopFolder(&psfDesktop);
411 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
412 if (FAILED(hr)) return;
414 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
415 &pidlMyDocuments, NULL);
417 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08lx\n", hr);
419 IShellFolder_Release(psfDesktop);
423 dwAttributes = 0xffffffff;
424 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
425 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
426 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
428 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
429 todo_wine{ ok (dwAttributes & SFGAO_FILESYSTEM,
430 "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n"); }
431 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
432 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
434 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
435 * key. So the test will return at this point, if run on wine.
437 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
438 todo_wine { ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08lx\n", lResult); }
439 if (lResult != ERROR_SUCCESS) {
440 IMalloc_Free(ppM, pidlMyDocuments);
441 IShellFolder_Release(psfDesktop);
445 /* Query MyDocuments' Attributes value, to be able to restore it later. */
446 dwSize = sizeof(DWORD);
447 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
448 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
449 if (lResult != ERROR_SUCCESS) {
451 IMalloc_Free(ppM, pidlMyDocuments);
452 IShellFolder_Release(psfDesktop);
456 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
457 dwSize = sizeof(DWORD);
458 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
459 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
460 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
461 if (lResult != ERROR_SUCCESS) {
463 IMalloc_Free(ppM, pidlMyDocuments);
464 IShellFolder_Release(psfDesktop);
468 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
469 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
470 * SFGAO_FILESYSTEM attributes. */
471 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
472 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
473 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
474 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
475 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
477 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
478 * GetAttributesOf. It seems that once there is a single attribute queried, for which
479 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
480 * the flags in Attributes are ignored.
482 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
483 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
484 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
485 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
487 ok (dwAttributes == SFGAO_FILESYSTEM,
488 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08lx\n",
491 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
492 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
493 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
494 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
496 IMalloc_Free(ppM, pidlMyDocuments);
497 IShellFolder_Release(psfDesktop);
500 static void test_GetAttributesOf(void)
503 LPSHELLFOLDER psfDesktop, psfMyComputer;
504 SHITEMID emptyitem = { 0, { 0 } };
505 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
506 LPITEMIDLIST pidlMyComputer;
508 const static DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
509 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
510 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
511 const static DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
512 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
513 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
514 WCHAR wszMyComputer[] = {
515 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
516 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
518 hr = SHGetDesktopFolder(&psfDesktop);
519 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
520 if (FAILED(hr)) return;
522 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
523 dwFlags = 0xffffffff;
524 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
525 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08lx\n", hr);
526 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
527 dwFlags, dwDesktopFlags);
529 /* .. or with no itemidlist at all. */
530 dwFlags = 0xffffffff;
531 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
532 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
533 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
534 dwFlags, dwDesktopFlags);
536 /* Testing the attributes of the MyComputer shellfolder */
537 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
538 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
540 IShellFolder_Release(psfDesktop);
544 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
545 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
546 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
547 * should create a link to the original data". You can't create links on MyComputer on
548 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
549 * depends on this bug, we probably shouldn't imitate it.
551 dwFlags = 0xffffffff;
552 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
553 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08lx\n", hr);
554 todo_wine { ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
555 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags); }
557 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
558 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
559 IShellFolder_Release(psfDesktop);
560 IMalloc_Free(ppM, pidlMyComputer);
561 if (FAILED(hr)) return;
563 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
564 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08lx\n", hr); }
566 dwFlags = 0xffffffff;
567 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
568 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
569 todo_wine { ok (dwFlags == dwMyComputerFlags,
570 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags); }
572 IShellFolder_Release(psfMyComputer);
575 static void test_SHGetPathFromIDList(void)
577 SHITEMID emptyitem = { 0, { 0 } };
578 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
579 LPITEMIDLIST pidlMyComputer;
580 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
583 LPSHELLFOLDER psfDesktop;
584 WCHAR wszMyComputer[] = {
585 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
586 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
588 if(!pSHGetSpecialFolderPathW) return;
590 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
591 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
592 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %08lx\n", GetLastError());
595 result = SHGetPathFromIDListW(pidlEmpty, wszPath);
596 ok(result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
598 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
600 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
601 hr = SHGetDesktopFolder(&psfDesktop);
602 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
603 if (FAILED(hr)) return;
605 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
606 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
607 IShellFolder_Release(psfDesktop);
608 if (FAILED(hr)) return;
610 SetLastError(0xdeadbeef);
611 result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
612 ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
613 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %08lx\n", GetLastError());
615 IMalloc_Free(ppM, pidlMyComputer);
618 static void test_EnumObjects_and_CompareIDs(void)
621 IShellFolder *IDesktopFolder, *testIShellFolder;
622 char cCurrDirA [MAX_PATH] = {0};
623 WCHAR cCurrDirW [MAX_PATH];
624 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
628 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
629 len = lstrlenA(cCurrDirA);
632 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
635 if(cCurrDirA[len-1] == '\\')
636 cCurrDirA[len-1] = 0;
638 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
639 strcatW(cCurrDirW, cTestDirW);
641 hr = SHGetDesktopFolder(&IDesktopFolder);
642 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
644 CreateFilesFolders();
646 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
647 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
649 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
650 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
652 test_EnumObjects(testIShellFolder);
654 hr = IShellFolder_Release(testIShellFolder);
655 ok(hr == S_OK, "IShellFolder_Release failed %08lx\n", hr);
659 IMalloc_Free(ppM, newPIDL);
662 START_TEST(shlfolder)
664 init_function_pointers();
665 /* if OleInitialize doesn't get called, ParseDisplayName returns
666 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
669 test_ParseDisplayName();
671 test_EnumObjects_and_CompareIDs();
672 test_GetDisplayName();
673 test_GetAttributesOf();
674 test_SHGetPathFromIDList();
675 test_CallForAttributes();