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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
39 #include "wine/test.h"
44 static HRESULT (WINAPI *pSHBindToParent)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*);
45 static BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
46 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
47 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
49 static void init_function_pointers(void)
54 hmod = GetModuleHandleA("shell32.dll");
57 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
58 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
59 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
63 hmod = GetModuleHandleA("shlwapi.dll");
66 pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
69 hr = SHGetMalloc(&ppM);
70 ok(hr == S_OK, "SHGetMalloc failed %08lx\n", hr);
73 static void test_ParseDisplayName(void)
76 IShellFolder *IDesktopFolder;
77 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
78 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
80 WCHAR cTestDirW [MAX_PATH] = {0};
84 hr = SHGetDesktopFolder(&IDesktopFolder);
85 if(hr != S_OK) return;
87 res = GetFileAttributesA(cNonExistDir1A);
88 if(res != INVALID_FILE_ATTRIBUTES) return;
90 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
91 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
92 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
93 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
94 "ParseDisplayName returned %08lx, expected 80070002 or E_FAIL\n", hr);
96 res = GetFileAttributesA(cNonExistDir2A);
97 if(res != INVALID_FILE_ATTRIBUTES) return;
99 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
100 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
101 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
102 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
103 "ParseDisplayName returned %08lx, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
105 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
106 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
107 * out it doesn't. The magic seems to happen in the file dialogs, then. */
108 if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
110 bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
111 ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %ld\n", GetLastError());
112 if (!bRes) goto finished;
114 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
115 ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08lx.\n", hr);
116 if (FAILED(hr)) goto finished;
118 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31, "Last pidl should be of type "
119 "PT_FOLDER, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
120 IMalloc_Free(ppM, newPIDL);
123 IShellFolder_Release(IDesktopFolder);
126 /* creates a file with the specified name for tests */
127 static void CreateTestFile(const CHAR *name)
132 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
133 if (file != INVALID_HANDLE_VALUE)
135 WriteFile(file, name, strlen(name), &written, NULL);
136 WriteFile(file, "\n", strlen("\n"), &written, NULL);
142 /* initializes the tests */
143 static void CreateFilesFolders(void)
145 CreateDirectoryA(".\\testdir", NULL);
146 CreateDirectoryA(".\\testdir\\test.txt", NULL);
147 CreateTestFile (".\\testdir\\test1.txt ");
148 CreateTestFile (".\\testdir\\test2.txt ");
149 CreateTestFile (".\\testdir\\test3.txt ");
150 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
151 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
154 /* cleans after tests */
155 static void Cleanup(void)
157 DeleteFileA(".\\testdir\\test1.txt");
158 DeleteFileA(".\\testdir\\test2.txt");
159 DeleteFileA(".\\testdir\\test3.txt");
160 RemoveDirectoryA(".\\testdir\\test.txt");
161 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
162 RemoveDirectoryA(".\\testdir\\testdir2");
163 RemoveDirectoryA(".\\testdir");
168 static void test_EnumObjects(IShellFolder *iFolder)
170 IEnumIDList *iEnumList;
171 LPITEMIDLIST newPIDL, idlArr[10];
176 static const WORD iResults [5][5] =
185 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
186 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
187 static const ULONG attrs[5] =
189 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
190 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
191 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
192 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
193 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
196 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
197 ok(hr == S_OK, "EnumObjects failed %08lx\n", hr);
199 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
200 * the filesystem shellfolders return S_OK even if less than 'celt' items are
201 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
202 * only ever returns a single entry per call. */
203 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
205 ok (i == 5, "i: %d\n", i);
207 hr = IEnumIDList_Release(iEnumList);
208 ok(hr == S_OK, "IEnumIDList_Release failed %08lx\n", hr);
210 /* Sort them first in case of wrong order from system */
211 for (i=0;i<5;i++) for (j=0;j<5;j++)
212 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
215 idlArr[i] = idlArr[j];
219 for (i=0;i<5;i++) for (j=0;j<5;j++)
221 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
222 ok(hr == iResults[i][j], "Got %lx expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
226 for (i = 0; i < 5; i++)
229 /* Native returns all flags no matter what we ask for */
230 flags = SFGAO_CANCOPY;
231 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
232 flags &= SFGAO_testfor;
233 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
234 ok(flags == (attrs[i]), "GetAttributesOf[%i] got %08lx, expected %08lx\n", i, flags, attrs[i]);
236 flags = SFGAO_testfor;
237 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
238 flags &= SFGAO_testfor;
239 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
240 ok(flags == attrs[i], "GetAttributesOf[%i] got %08lx, expected %08lx\n", i, flags, attrs[i]);
244 IMalloc_Free(ppM, idlArr[i]);
247 static void test_BindToObject(void)
251 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
252 SHITEMID emptyitem = { 0, { 0 } };
253 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
254 WCHAR wszSystemDir[MAX_PATH];
255 char szSystemDir[MAX_PATH];
256 WCHAR wszMyComputer[] = {
257 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
258 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
260 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
261 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
263 hr = SHGetDesktopFolder(&psfDesktop);
264 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
265 if (FAILED(hr)) return;
267 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
268 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
270 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
271 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
273 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
274 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
276 IShellFolder_Release(psfDesktop);
280 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
281 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
282 IShellFolder_Release(psfDesktop);
283 IMalloc_Free(ppM, pidlMyComputer);
284 if (FAILED(hr)) return;
286 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
287 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
290 /* this call segfaults on 98SE */
291 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
292 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
295 cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
296 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %08lx\n", GetLastError());
297 if (cChars == 0 || cChars >= MAX_PATH) {
298 IShellFolder_Release(psfMyComputer);
301 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
303 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
304 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08lx\n", hr);
306 IShellFolder_Release(psfMyComputer);
310 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
311 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08lx\n", hr);
312 IShellFolder_Release(psfMyComputer);
313 IMalloc_Free(ppM, pidlSystemDir);
314 if (FAILED(hr)) return;
316 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
317 ok (hr == E_INVALIDARG,
318 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
321 /* this call segfaults on 98SE */
322 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
323 ok (hr == E_INVALIDARG,
324 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
327 IShellFolder_Release(psfSystemDir);
330 static void test_GetDisplayName(void)
335 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
336 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
338 LPSHELLFOLDER psfDesktop, psfPersonal;
340 SHITEMID emptyitem = { 0, { 0 } };
341 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
342 LPCITEMIDLIST pidlLast;
343 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
344 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
346 /* I'm trying to figure if there is a functional difference between calling
347 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
348 * binding to the shellfolder. One thing I thought of was that perhaps
349 * SHGetPathFromIDList would be able to get the path to a file, which does
350 * not exist anymore, while the other method would'nt. It turns out there's
351 * no functional difference in this respect.
354 if(!pSHGetSpecialFolderPathW) return;
356 /* First creating a directory in MyDocuments and a file in this directory. */
357 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
358 ok(result, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
361 PathAddBackslashW(wszTestDir);
362 lstrcatW(wszTestDir, wszDirName);
363 WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
364 result = CreateDirectoryA(szTestDir, NULL);
365 ok(result, "CreateDirectoryA failed! Last error: %08lx\n", GetLastError());
368 lstrcpyW(wszTestFile, wszTestDir);
369 PathAddBackslashW(wszTestFile);
370 lstrcatW(wszTestFile, wszFileName);
371 WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
373 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
374 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %08lx\n", GetLastError());
375 if (hTestFile == INVALID_HANDLE_VALUE) return;
376 CloseHandle(hTestFile);
378 /* Getting an itemidlist for the file. */
379 hr = SHGetDesktopFolder(&psfDesktop);
380 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
381 if (FAILED(hr)) return;
383 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
384 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08lx\n", hr);
386 IShellFolder_Release(psfDesktop);
390 /* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
391 pidlLast = pILFindLastID(pidlTestFile);
392 ok(pidlLast->mkid.cb >=76, "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
393 if (pidlLast->mkid.cb >= 76) {
394 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
395 "WinXP stores the filename as a wchar-string at this position!\n");
398 /* It seems as if we cannot bind to regular files on windows, but only directories.
400 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
401 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08lx\n", hr); }
403 IShellFolder_Release(psfFile);
406 /* Some tests for IShellFolder::SetNameOf */
407 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
408 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08lx\n", hr);
410 /* It's ok to use this fixed path. Call will fail anyway. */
411 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
412 LPITEMIDLIST pidlNew;
414 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
415 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
416 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08lx\n", hr);
417 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
418 "pidl returned from SetNameOf should be simple!\n");
420 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
421 * is implemented on top of SHFileOperation in WinXP. */
422 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
423 SHGDN_FORPARSING, NULL);
424 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08lx\n", hr);
426 /* Rename the file back to it's original name. SetNameOf ignores the fact, that the
427 * SHGDN flags specify an absolute path. */
428 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
429 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08lx\n", hr);
432 IShellFolder_Release(psfPersonal);
435 /* Deleting the file and the directory */
436 DeleteFileA(szTestFile);
437 RemoveDirectoryA(szTestDir);
439 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
440 result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
441 ok (result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
442 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
444 if(!pSHBindToParent) return;
446 /* SHBindToParent fails, if called with a NULL PIDL. */
447 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
448 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
450 /* But it succeeds with an empty PIDL. */
451 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
452 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08lx\n", hr);
453 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
455 IShellFolder_Release(psfPersonal);
457 /* Binding to the folder and querying the display name of the file also works. */
458 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
459 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08lx\n", hr);
461 IShellFolder_Release(psfDesktop);
465 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
466 * pidlTestFile (In accordance with MSDN). */
467 ok (pILFindLastID(pidlTestFile) == pidlLast,
468 "SHBindToParent doesn't return the last id of the pidl param!\n");
470 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
471 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08lx\n", hr);
473 IShellFolder_Release(psfDesktop);
474 IShellFolder_Release(psfPersonal);
480 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
481 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08lx\n", hr);
482 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
485 IShellFolder_Release(psfDesktop);
486 IShellFolder_Release(psfPersonal);
489 static void test_CallForAttributes(void)
495 LPSHELLFOLDER psfDesktop;
496 LPITEMIDLIST pidlMyDocuments;
497 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
498 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
499 static const WCHAR wszCallForAttributes[] = {
500 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
501 static const WCHAR wszMyDocumentsKey[] = {
502 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
503 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
504 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
505 WCHAR wszMyDocuments[] = {
506 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
507 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
509 /* For the root of a namespace extension, the attributes are not queried by binding
510 * to the object and calling GetAttributesOf. Instead, the attributes are read from
511 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
513 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
514 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
515 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
516 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
518 hr = SHGetDesktopFolder(&psfDesktop);
519 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
520 if (FAILED(hr)) return;
522 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
523 &pidlMyDocuments, NULL);
525 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08lx\n", hr);
527 IShellFolder_Release(psfDesktop);
531 dwAttributes = 0xffffffff;
532 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
533 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
534 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
536 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
537 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
538 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
539 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
541 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
542 * key. So the test will return at this point, if run on wine.
544 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
545 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08lx\n", lResult);
546 if (lResult != ERROR_SUCCESS) {
547 IMalloc_Free(ppM, pidlMyDocuments);
548 IShellFolder_Release(psfDesktop);
552 /* Query MyDocuments' Attributes value, to be able to restore it later. */
553 dwSize = sizeof(DWORD);
554 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
555 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
556 if (lResult != ERROR_SUCCESS) {
558 IMalloc_Free(ppM, pidlMyDocuments);
559 IShellFolder_Release(psfDesktop);
563 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
564 dwSize = sizeof(DWORD);
565 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
566 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
567 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
568 if (lResult != ERROR_SUCCESS) {
570 IMalloc_Free(ppM, pidlMyDocuments);
571 IShellFolder_Release(psfDesktop);
575 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
576 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
577 * SFGAO_FILESYSTEM attributes. */
578 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
579 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
580 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
581 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
582 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
584 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
585 * GetAttributesOf. It seems that once there is a single attribute queried, for which
586 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
587 * the flags in Attributes are ignored.
589 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
590 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
591 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
592 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
594 ok (dwAttributes == SFGAO_FILESYSTEM,
595 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08lx\n",
598 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
599 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
600 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
601 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
603 IMalloc_Free(ppM, pidlMyDocuments);
604 IShellFolder_Release(psfDesktop);
607 static void test_GetAttributesOf(void)
610 LPSHELLFOLDER psfDesktop, psfMyComputer;
611 SHITEMID emptyitem = { 0, { 0 } };
612 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
613 LPITEMIDLIST pidlMyComputer;
615 static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
616 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
617 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
618 static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
619 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
620 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
621 WCHAR wszMyComputer[] = {
622 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
623 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
624 char cCurrDirA [MAX_PATH] = {0};
625 WCHAR cCurrDirW [MAX_PATH];
626 static const WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
627 static const WCHAR cBackSlash[] = {'\\',0};
628 IShellFolder *IDesktopFolder, *testIShellFolder;
632 hr = SHGetDesktopFolder(&psfDesktop);
633 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
634 if (FAILED(hr)) return;
636 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
637 dwFlags = 0xffffffff;
638 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
639 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08lx\n", hr);
640 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
641 dwFlags, dwDesktopFlags);
643 /* .. or with no itemidlist at all. */
644 dwFlags = 0xffffffff;
645 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
646 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
647 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
648 dwFlags, dwDesktopFlags);
650 /* Testing the attributes of the MyComputer shellfolder */
651 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
652 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
654 IShellFolder_Release(psfDesktop);
658 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
659 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
660 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
661 * should create a link to the original data". You can't create links on MyComputer on
662 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
663 * depends on this bug, we probably shouldn't imitate it.
665 dwFlags = 0xffffffff;
666 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
667 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08lx\n", hr);
668 ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
669 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags);
671 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
672 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
673 IShellFolder_Release(psfDesktop);
674 IMalloc_Free(ppM, pidlMyComputer);
675 if (FAILED(hr)) return;
677 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
678 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08lx\n", hr); }
680 dwFlags = 0xffffffff;
681 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
682 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
683 todo_wine { ok (dwFlags == dwMyComputerFlags,
684 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags); }
686 IShellFolder_Release(psfMyComputer);
688 /* create test directory */
689 CreateFilesFolders();
691 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
692 len = lstrlenA(cCurrDirA);
695 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
698 if(cCurrDirA[len-1] == '\\')
699 cCurrDirA[len-1] = 0;
701 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
703 hr = SHGetDesktopFolder(&IDesktopFolder);
704 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
706 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
707 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
709 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
710 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
712 IMalloc_Free(ppM, newPIDL);
714 /* get relative PIDL */
715 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, (LPWSTR)cTestDirW, NULL, &newPIDL, 0);
716 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
718 /* test the shell attributes of the test directory using the relative PIDL */
719 dwFlags = SFGAO_FOLDER;
720 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
721 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08lx\n", hr);
722 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08lx\n", dwFlags);
725 IMalloc_Free(ppM, newPIDL);
727 /* append testdirectory name to path */
728 lstrcatW(cCurrDirW, cBackSlash);
729 lstrcatW(cCurrDirW, cTestDirW);
731 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
732 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
734 /* test the shell attributes of the test directory using the absolute PIDL */
735 dwFlags = SFGAO_FOLDER;
736 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
737 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08lx\n", hr);
738 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08lx\n", dwFlags);
741 IMalloc_Free(ppM, newPIDL);
743 IShellFolder_Release(testIShellFolder);
747 IShellFolder_Release(IDesktopFolder);
750 static void test_SHGetPathFromIDList(void)
752 SHITEMID emptyitem = { 0, { 0 } };
753 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
754 LPITEMIDLIST pidlMyComputer;
755 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
758 LPSHELLFOLDER psfDesktop;
759 WCHAR wszMyComputer[] = {
760 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
761 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
762 WCHAR wszFileName[MAX_PATH];
763 LPITEMIDLIST pidlTestFile;
766 static WCHAR wszTestFile[] = {
767 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
768 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
770 LPITEMIDLIST pidlPrograms;
772 if(!pSHGetSpecialFolderPathW) return;
774 /* Calling SHGetPathFromIDList with no pidl should return the empty string */
777 result = SHGetPathFromIDListW(NULL, wszPath);
778 ok(!result, "Expected failure\n");
779 ok(!wszPath[0], "Expected empty string\n");
781 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
782 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
783 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %08lx\n", GetLastError());
786 result = SHGetPathFromIDListW(pidlEmpty, wszPath);
787 ok(result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
789 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
791 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
792 hr = SHGetDesktopFolder(&psfDesktop);
793 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
794 if (FAILED(hr)) return;
796 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
797 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
799 IShellFolder_Release(psfDesktop);
803 SetLastError(0xdeadbeef);
806 result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
807 ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
808 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %08lx\n", GetLastError());
809 ok (!wszPath[0], "Expected empty path\n");
811 IShellFolder_Release(psfDesktop);
815 IMalloc_Free(ppM, pidlMyComputer);
817 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
818 ok(result, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
820 IShellFolder_Release(psfDesktop);
823 PathAddBackslashW(wszFileName);
824 lstrcatW(wszFileName, wszTestFile);
825 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
826 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %08lx\n", GetLastError());
827 if (hTestFile == INVALID_HANDLE_VALUE) {
828 IShellFolder_Release(psfDesktop);
831 CloseHandle(hTestFile);
833 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
834 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08lx\n", hr);
836 IShellFolder_Release(psfDesktop);
837 DeleteFileW(wszFileName);
838 IMalloc_Free(ppM, pidlTestFile);
842 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
843 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
844 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
845 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08lx\n", hr);
846 IShellFolder_Release(psfDesktop);
847 DeleteFileW(wszFileName);
849 IMalloc_Free(ppM, pidlTestFile);
854 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
855 ok(0 == lstrcmpW(wszFileName, wszPath),
856 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
857 "returned incorrect path for file placed on desktop\n");
860 result = SHGetPathFromIDListW(pidlTestFile, wszPath);
861 ok(result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
862 IMalloc_Free(ppM, pidlTestFile);
864 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
867 /* Test if we can get the path from the start menu "program files" PIDL. */
868 hShell32 = GetModuleHandleA("shell32");
869 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
871 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
872 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08lx\n", hr);
874 SetLastError(0xdeadbeef);
875 result = SHGetPathFromIDListW(pidlPrograms, wszPath);
876 IMalloc_Free(ppM, pidlPrograms);
877 ok(result, "SHGetPathFromIDList failed\n");
880 static void test_EnumObjects_and_CompareIDs(void)
883 IShellFolder *IDesktopFolder, *testIShellFolder;
884 char cCurrDirA [MAX_PATH] = {0};
885 WCHAR cCurrDirW [MAX_PATH];
886 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
890 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
891 len = lstrlenA(cCurrDirA);
894 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
897 if(cCurrDirA[len-1] == '\\')
898 cCurrDirA[len-1] = 0;
900 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
901 lstrcatW(cCurrDirW, cTestDirW);
903 hr = SHGetDesktopFolder(&IDesktopFolder);
904 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
906 CreateFilesFolders();
908 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
909 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
911 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
912 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
914 test_EnumObjects(testIShellFolder);
916 IShellFolder_Release(testIShellFolder);
920 IMalloc_Free(ppM, newPIDL);
922 IShellFolder_Release(IDesktopFolder);
925 /* A simple implementation of an IPropertyBag, which returns fixed values for
926 * 'Target' and 'Attributes' properties.
928 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
934 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
937 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
938 return E_NOINTERFACE;
941 IPropertyBag_AddRef(iface);
945 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
949 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
953 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
954 VARIANT *pVar, IErrorLog *pErrorLog)
956 static const WCHAR wszTargetSpecialFolder[] = {
957 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
958 static const WCHAR wszTarget[] = {
959 'T','a','r','g','e','t',0 };
960 static const WCHAR wszAttributes[] = {
961 'A','t','t','r','i','b','u','t','e','s',0 };
962 static const WCHAR wszResolveLinkFlags[] = {
963 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
965 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
966 ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
970 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
972 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
976 if (!lstrcmpW(pszPropName, wszTarget)) {
977 WCHAR wszPath[MAX_PATH];
980 ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
981 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
983 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
984 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! x%08lx\n", GetLastError());
985 if (!result) return E_INVALIDARG;
987 V_BSTR(pVar) = SysAllocString(wszPath);
991 if (!lstrcmpW(pszPropName, wszAttributes)) {
992 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
993 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
994 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
995 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
999 ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
1000 return E_INVALIDARG;
1003 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1006 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1010 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1011 InitPropertyBag_IPropertyBag_QueryInterface,
1012 InitPropertyBag_IPropertyBag_AddRef,
1013 InitPropertyBag_IPropertyBag_Release,
1014 InitPropertyBag_IPropertyBag_Read,
1015 InitPropertyBag_IPropertyBag_Write
1018 struct IPropertyBag InitPropertyBag = {
1019 &InitPropertyBag_IPropertyBagVtbl
1022 void test_FolderShortcut(void) {
1023 IPersistPropertyBag *pPersistPropertyBag;
1024 IShellFolder *pShellFolder, *pDesktopFolder;
1025 IPersistFolder3 *pPersistFolder3;
1028 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1031 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1033 WCHAR wszWineTestFolder[] = {
1034 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1035 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1036 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1037 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1038 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1039 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1040 'N','a','m','e','S','p','a','c','e','\\',
1041 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1042 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1044 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1045 static const GUID CLSID_UnixDosFolder =
1046 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1048 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) return;
1050 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1051 * via their IPersistPropertyBag interface. And that the target folder
1052 * is taken from the IPropertyBag's 'Target' property.
1054 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1055 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1056 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08lx\n", hr);
1057 if (FAILED(hr)) return;
1059 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1060 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08lx\n", hr);
1062 IPersistPropertyBag_Release(pPersistPropertyBag);
1066 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1067 (LPVOID*)&pShellFolder);
1068 IPersistPropertyBag_Release(pPersistPropertyBag);
1069 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08lx\n", hr);
1070 if (FAILED(hr)) return;
1072 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1073 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08lx\n", hr);
1075 IShellFolder_Release(pShellFolder);
1079 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1080 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! 0x%08lx\n", GetLastError());
1081 if (!result) return;
1083 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1084 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1086 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1087 IShellFolder_Release(pShellFolder);
1088 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08lx\n", hr);
1089 if (FAILED(hr)) return;
1091 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1092 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08lx\n", hr);
1093 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1095 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1096 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08lx\n", hr);
1097 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1099 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1100 * shell namespace. The target folder, read from the property bag above, remains untouched.
1101 * The following tests show this: The itemidlist for some imaginary shellfolder object
1102 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1103 * itemidlist, but GetDisplayNameOf still returns the path from above.
1105 hr = SHGetDesktopFolder(&pDesktopFolder);
1106 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
1107 if (FAILED(hr)) return;
1109 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1110 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1111 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1112 RegCloseKey(hShellExtKey);
1113 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1114 &pidlWineTestFolder, NULL);
1115 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1116 IShellFolder_Release(pDesktopFolder);
1117 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08lx\n", hr);
1118 if (FAILED(hr)) return;
1120 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1121 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08lx\n", hr);
1123 IPersistFolder3_Release(pPersistFolder3);
1124 ILFree(pidlWineTestFolder);
1128 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1129 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08lx\n", hr);
1130 ok(ILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1131 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1132 ILFree(pidlCurrentFolder);
1133 ILFree(pidlWineTestFolder);
1135 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1136 IPersistFolder3_Release(pPersistFolder3);
1137 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08lx\n", hr);
1138 if (FAILED(hr)) return;
1140 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1141 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08lx\n", hr);
1143 IShellFolder_Release(pShellFolder);
1147 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1148 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1150 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1151 * but ShellFSFolders. */
1152 PathAddBackslashW(wszDesktopPath);
1153 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1154 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1155 IShellFolder_Release(pShellFolder);
1159 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1160 &pidlSubFolder, NULL);
1161 RemoveDirectoryW(wszDesktopPath);
1162 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08lx\n", hr);
1164 IShellFolder_Release(pShellFolder);
1168 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1169 (LPVOID*)&pPersistFolder3);
1170 IShellFolder_Release(pShellFolder);
1171 ILFree(pidlSubFolder);
1172 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08lx\n", hr);
1176 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1177 * a little bit and also allow CLSID_UnixDosFolder. */
1178 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1179 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08lx\n", hr);
1180 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1181 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1183 IPersistFolder3_Release(pPersistFolder3);
1186 #include "pshpack1.h"
1187 struct FileStructA {
1191 WORD uFileDate; /* In our current implementation this is */
1192 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1197 struct FileStructW {
1198 WORD cbLen; /* Length of this element. */
1199 BYTE abFooBar1[6]; /* Beyond any recognition. */
1200 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1201 WORD uTime; /* (this is currently speculation) */
1202 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1203 WORD uTime2; /* (this is currently speculation) */
1204 BYTE abFooBar2[4]; /* Beyond any recognition. */
1205 WCHAR wszName[1]; /* The long filename in unicode. */
1206 /* Just for documentation: Right after the unicode string: */
1207 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1208 * SHITEMID->cb == uOffset + cbLen */
1210 #include "poppack.h"
1212 void test_ITEMIDLIST_format(void) {
1213 WCHAR wszPersonal[MAX_PATH];
1214 LPSHELLFOLDER psfDesktop, psfPersonal;
1215 LPITEMIDLIST pidlPersonal, pidlFile;
1219 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1220 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1223 if(!pSHGetSpecialFolderPathW) return;
1225 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1226 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
1227 if (!bResult) return;
1229 bResult = SetCurrentDirectoryW(wszPersonal);
1230 ok(bResult, "SetCurrentDirectory failed! Last error: %ld\n", GetLastError());
1231 if (!bResult) return;
1233 hr = SHGetDesktopFolder(&psfDesktop);
1234 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08lx\n", hr);
1235 if (FAILED(hr)) return;
1237 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1238 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08lx\n", hr);
1240 IShellFolder_Release(psfDesktop);
1244 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1245 (LPVOID*)&psfPersonal);
1246 IShellFolder_Release(psfDesktop);
1247 ILFree(pidlPersonal);
1248 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08lx\n", hr);
1249 if (FAILED(hr)) return;
1251 for (i=0; i<3; i++) {
1252 CHAR szFile[MAX_PATH];
1253 struct FileStructA *pFileStructA;
1256 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1258 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1259 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%ld)\n", GetLastError());
1260 if (hFile == INVALID_HANDLE_VALUE) {
1261 IShellFolder_Release(psfPersonal);
1266 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1267 DeleteFileW(wszFile[i]);
1268 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08lx\n", hr);
1270 IShellFolder_Release(psfPersonal);
1274 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1275 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1276 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1277 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1279 if (i < 2) /* First two file names are already in valid 8.3 format */
1280 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1282 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1283 * can't implement this correctly, since unix filesystems don't support
1284 * this nasty short/long filename stuff. So we'll probably stay with our
1285 * current habbit of storing the long filename here, which seems to work
1287 todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
1289 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1290 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0',
1291 "Alignment byte, where there shouldn't be!\n");
1293 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1294 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1295 "There should be an alignment byte, but isn't!\n");
1297 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1298 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1299 ok (cbOffset >= sizeof(struct FileStructA) &&
1300 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
1301 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1303 if (cbOffset >= sizeof(struct FileStructA) &&
1304 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1306 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1308 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1309 "FileStructW's offset and length should add up to the PIDL's length!\n");
1311 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1312 /* Since we just created the file, time of creation,
1313 * time of last access and time of last write access just be the same.
1314 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1315 * after the first run. I do remember something with NTFS keeping the creation time
1316 * if a file is deleted and then created again within a couple of seconds or so.
1317 * Might be the reason. */
1318 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1319 pFileStructA->uFileTime == pFileStructW->uTime,
1320 "Last write time should match creation time!\n");
1322 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1323 pFileStructA->uFileTime == pFileStructW->uTime2,
1324 "Last write time should match last access time!\n");
1326 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
1327 "The filename should be stored in unicode at this position!\n");
1335 START_TEST(shlfolder)
1337 init_function_pointers();
1338 /* if OleInitialize doesn't get called, ParseDisplayName returns
1339 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1340 OleInitialize(NULL);
1342 test_ParseDisplayName();
1343 test_BindToObject();
1344 test_EnumObjects_and_CompareIDs();
1345 test_GetDisplayName();
1346 test_GetAttributesOf();
1347 test_SHGetPathFromIDList();
1348 test_CallForAttributes();
1349 test_FolderShortcut();
1350 test_ITEMIDLIST_format();