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
40 #include "wine/test.h"
45 static HRESULT (WINAPI *pSHBindToParent)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*);
46 static BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
47 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
48 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
50 static void init_function_pointers(void)
55 hmod = GetModuleHandleA("shell32.dll");
58 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
59 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
60 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
64 hmod = GetModuleHandleA("shlwapi.dll");
67 pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
70 hr = SHGetMalloc(&ppM);
71 ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
74 static void test_ParseDisplayName(void)
77 IShellFolder *IDesktopFolder;
78 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
79 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
81 WCHAR cTestDirW [MAX_PATH] = {0};
85 hr = SHGetDesktopFolder(&IDesktopFolder);
86 if(hr != S_OK) return;
88 res = GetFileAttributesA(cNonExistDir1A);
89 if(res != INVALID_FILE_ATTRIBUTES) return;
91 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
92 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
93 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
94 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
95 "ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr);
97 res = GetFileAttributesA(cNonExistDir2A);
98 if(res != INVALID_FILE_ATTRIBUTES) return;
100 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
101 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
102 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
103 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
104 "ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
106 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
107 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
108 * out it doesn't. The magic seems to happen in the file dialogs, then. */
109 if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
111 bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
112 ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
113 if (!bRes) goto finished;
115 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
116 ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr);
117 if (FAILED(hr)) goto finished;
119 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31, "Last pidl should be of type "
120 "PT_FOLDER, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
121 IMalloc_Free(ppM, newPIDL);
124 IShellFolder_Release(IDesktopFolder);
127 /* creates a file with the specified name for tests */
128 static void CreateTestFile(const CHAR *name)
133 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
134 if (file != INVALID_HANDLE_VALUE)
136 WriteFile(file, name, strlen(name), &written, NULL);
137 WriteFile(file, "\n", strlen("\n"), &written, NULL);
143 /* initializes the tests */
144 static void CreateFilesFolders(void)
146 CreateDirectoryA(".\\testdir", NULL);
147 CreateDirectoryA(".\\testdir\\test.txt", NULL);
148 CreateTestFile (".\\testdir\\test1.txt ");
149 CreateTestFile (".\\testdir\\test2.txt ");
150 CreateTestFile (".\\testdir\\test3.txt ");
151 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
152 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
155 /* cleans after tests */
156 static void Cleanup(void)
158 DeleteFileA(".\\testdir\\test1.txt");
159 DeleteFileA(".\\testdir\\test2.txt");
160 DeleteFileA(".\\testdir\\test3.txt");
161 RemoveDirectoryA(".\\testdir\\test.txt");
162 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
163 RemoveDirectoryA(".\\testdir\\testdir2");
164 RemoveDirectoryA(".\\testdir");
169 static void test_EnumObjects(IShellFolder *iFolder)
171 IEnumIDList *iEnumList;
172 LPITEMIDLIST newPIDL, idlArr[10];
177 static const WORD iResults [5][5] =
186 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
187 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
188 static const ULONG attrs[5] =
190 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
191 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
192 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
193 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
194 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
197 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
198 ok(hr == S_OK, "EnumObjects failed %08x\n", hr);
200 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
201 * the filesystem shellfolders return S_OK even if less than 'celt' items are
202 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
203 * only ever returns a single entry per call. */
204 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
206 ok (i == 5, "i: %d\n", i);
208 hr = IEnumIDList_Release(iEnumList);
209 ok(hr == S_OK, "IEnumIDList_Release failed %08x\n", hr);
211 /* Sort them first in case of wrong order from system */
212 for (i=0;i<5;i++) for (j=0;j<5;j++)
213 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
216 idlArr[i] = idlArr[j];
220 for (i=0;i<5;i++) for (j=0;j<5;j++)
222 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
223 ok(hr == iResults[i][j], "Got %x expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
227 for (i = 0; i < 5; i++)
230 /* Native returns all flags no matter what we ask for */
231 flags = SFGAO_CANCOPY;
232 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
233 flags &= SFGAO_testfor;
234 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
235 ok(flags == (attrs[i]), "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
237 flags = SFGAO_testfor;
238 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
239 flags &= SFGAO_testfor;
240 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
241 ok(flags == attrs[i], "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
245 IMalloc_Free(ppM, idlArr[i]);
248 static void test_BindToObject(void)
252 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
253 SHITEMID emptyitem = { 0, { 0 } };
254 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
255 WCHAR wszSystemDir[MAX_PATH];
256 char szSystemDir[MAX_PATH];
257 WCHAR wszMyComputer[] = {
258 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
259 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
261 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
262 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
264 hr = SHGetDesktopFolder(&psfDesktop);
265 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
266 if (FAILED(hr)) return;
268 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
269 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
271 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
272 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
274 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
275 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
277 IShellFolder_Release(psfDesktop);
281 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
282 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
283 IShellFolder_Release(psfDesktop);
284 IMalloc_Free(ppM, pidlMyComputer);
285 if (FAILED(hr)) return;
287 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
288 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
291 /* this call segfaults on 98SE */
292 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
293 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
296 cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
297 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
298 if (cChars == 0 || cChars >= MAX_PATH) {
299 IShellFolder_Release(psfMyComputer);
302 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
304 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
305 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr);
307 IShellFolder_Release(psfMyComputer);
311 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
312 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr);
313 IShellFolder_Release(psfMyComputer);
314 IMalloc_Free(ppM, pidlSystemDir);
315 if (FAILED(hr)) return;
317 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
318 ok (hr == E_INVALIDARG,
319 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
322 /* this call segfaults on 98SE */
323 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
324 ok (hr == E_INVALIDARG,
325 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
328 IShellFolder_Release(psfSystemDir);
331 static void test_GetDisplayName(void)
336 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
337 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
339 LPSHELLFOLDER psfDesktop, psfPersonal;
341 SHITEMID emptyitem = { 0, { 0 } };
342 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
343 LPCITEMIDLIST pidlLast;
344 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
345 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
347 /* I'm trying to figure if there is a functional difference between calling
348 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
349 * binding to the shellfolder. One thing I thought of was that perhaps
350 * SHGetPathFromIDList would be able to get the path to a file, which does
351 * not exist anymore, while the other method would'nt. It turns out there's
352 * no functional difference in this respect.
355 if(!pSHGetSpecialFolderPathW) return;
357 /* First creating a directory in MyDocuments and a file in this directory. */
358 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
359 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
362 PathAddBackslashW(wszTestDir);
363 lstrcatW(wszTestDir, wszDirName);
364 WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
365 result = CreateDirectoryA(szTestDir, NULL);
366 ok(result, "CreateDirectoryA failed! Last error: %u\n", GetLastError());
369 lstrcpyW(wszTestFile, wszTestDir);
370 PathAddBackslashW(wszTestFile);
371 lstrcatW(wszTestFile, wszFileName);
372 WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
374 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
375 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
376 if (hTestFile == INVALID_HANDLE_VALUE) return;
377 CloseHandle(hTestFile);
379 /* Getting an itemidlist for the file. */
380 hr = SHGetDesktopFolder(&psfDesktop);
381 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
382 if (FAILED(hr)) return;
384 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
385 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
387 IShellFolder_Release(psfDesktop);
391 /* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
392 pidlLast = pILFindLastID(pidlTestFile);
393 ok(pidlLast->mkid.cb >=76, "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
394 if (pidlLast->mkid.cb >= 76) {
395 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
396 "WinXP stores the filename as a wchar-string at this position!\n");
399 /* It seems as if we cannot bind to regular files on windows, but only directories.
401 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
402 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08x\n", hr); }
404 IShellFolder_Release(psfFile);
407 /* Some tests for IShellFolder::SetNameOf */
408 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
409 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
411 /* It's ok to use this fixed path. Call will fail anyway. */
412 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
413 LPITEMIDLIST pidlNew;
415 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
416 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
417 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
418 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
419 "pidl returned from SetNameOf should be simple!\n");
421 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
422 * is implemented on top of SHFileOperation in WinXP. */
423 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
424 SHGDN_FORPARSING, NULL);
425 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
427 /* Rename the file back to it's original name. SetNameOf ignores the fact, that the
428 * SHGDN flags specify an absolute path. */
429 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
430 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
433 IShellFolder_Release(psfPersonal);
436 /* Deleting the file and the directory */
437 DeleteFileA(szTestFile);
438 RemoveDirectoryA(szTestDir);
440 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
441 result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
442 ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
443 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
445 if(!pSHBindToParent) return;
447 /* SHBindToParent fails, if called with a NULL PIDL. */
448 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
449 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
451 /* But it succeeds with an empty PIDL. */
452 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
453 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
454 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
456 IShellFolder_Release(psfPersonal);
458 /* Binding to the folder and querying the display name of the file also works. */
459 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
460 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
462 IShellFolder_Release(psfDesktop);
466 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
467 * pidlTestFile (In accordance with MSDN). */
468 ok (pILFindLastID(pidlTestFile) == pidlLast,
469 "SHBindToParent doesn't return the last id of the pidl param!\n");
471 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
472 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
474 IShellFolder_Release(psfDesktop);
475 IShellFolder_Release(psfPersonal);
481 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
482 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
483 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
486 IShellFolder_Release(psfDesktop);
487 IShellFolder_Release(psfPersonal);
490 static void test_CallForAttributes(void)
496 LPSHELLFOLDER psfDesktop;
497 LPITEMIDLIST pidlMyDocuments;
498 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
499 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
500 static const WCHAR wszCallForAttributes[] = {
501 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
502 static const WCHAR wszMyDocumentsKey[] = {
503 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
504 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
505 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
506 WCHAR wszMyDocuments[] = {
507 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
508 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
510 /* For the root of a namespace extension, the attributes are not queried by binding
511 * to the object and calling GetAttributesOf. Instead, the attributes are read from
512 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
514 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
515 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
516 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
517 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
519 hr = SHGetDesktopFolder(&psfDesktop);
520 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
521 if (FAILED(hr)) return;
523 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
524 &pidlMyDocuments, NULL);
526 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
528 IShellFolder_Release(psfDesktop);
532 dwAttributes = 0xffffffff;
533 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
534 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
535 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
537 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
538 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
539 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
540 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
542 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
543 * key. So the test will return at this point, if run on wine.
545 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
546 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
547 if (lResult != ERROR_SUCCESS) {
548 IMalloc_Free(ppM, pidlMyDocuments);
549 IShellFolder_Release(psfDesktop);
553 /* Query MyDocuments' Attributes value, to be able to restore it later. */
554 dwSize = sizeof(DWORD);
555 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
556 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
557 if (lResult != ERROR_SUCCESS) {
559 IMalloc_Free(ppM, pidlMyDocuments);
560 IShellFolder_Release(psfDesktop);
564 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
565 dwSize = sizeof(DWORD);
566 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
567 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
568 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
569 if (lResult != ERROR_SUCCESS) {
571 IMalloc_Free(ppM, pidlMyDocuments);
572 IShellFolder_Release(psfDesktop);
576 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
577 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
578 * SFGAO_FILESYSTEM attributes. */
579 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
580 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
581 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
582 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
583 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
585 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
586 * GetAttributesOf. It seems that once there is a single attribute queried, for which
587 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
588 * the flags in Attributes are ignored.
590 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
591 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
592 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
593 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
595 ok (dwAttributes == SFGAO_FILESYSTEM,
596 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n",
599 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
600 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
601 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
602 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
604 IMalloc_Free(ppM, pidlMyDocuments);
605 IShellFolder_Release(psfDesktop);
608 static void test_GetAttributesOf(void)
611 LPSHELLFOLDER psfDesktop, psfMyComputer;
612 SHITEMID emptyitem = { 0, { 0 } };
613 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
614 LPITEMIDLIST pidlMyComputer;
616 static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
617 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
618 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
619 static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
620 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
621 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
622 WCHAR wszMyComputer[] = {
623 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
624 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
625 char cCurrDirA [MAX_PATH] = {0};
626 WCHAR cCurrDirW [MAX_PATH];
627 static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
628 static const WCHAR cBackSlash[] = {'\\',0};
629 IShellFolder *IDesktopFolder, *testIShellFolder;
633 hr = SHGetDesktopFolder(&psfDesktop);
634 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
635 if (FAILED(hr)) return;
637 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
638 dwFlags = 0xffffffff;
639 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
640 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
641 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
642 dwFlags, dwDesktopFlags);
644 /* .. or with no itemidlist at all. */
645 dwFlags = 0xffffffff;
646 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
647 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
648 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
649 dwFlags, dwDesktopFlags);
651 /* Testing the attributes of the MyComputer shellfolder */
652 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
653 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
655 IShellFolder_Release(psfDesktop);
659 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
660 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
661 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
662 * should create a link to the original data". You can't create links on MyComputer on
663 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
664 * depends on this bug, we probably shouldn't imitate it.
666 dwFlags = 0xffffffff;
667 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
668 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
669 ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
670 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags);
672 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
673 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
674 IShellFolder_Release(psfDesktop);
675 IMalloc_Free(ppM, pidlMyComputer);
676 if (FAILED(hr)) return;
678 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
679 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr); }
681 dwFlags = 0xffffffff;
682 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
683 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
684 todo_wine { ok (dwFlags == dwMyComputerFlags,
685 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags); }
687 IShellFolder_Release(psfMyComputer);
689 /* create test directory */
690 CreateFilesFolders();
692 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
693 len = lstrlenA(cCurrDirA);
696 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
699 if(cCurrDirA[len-1] == '\\')
700 cCurrDirA[len-1] = 0;
702 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
704 hr = SHGetDesktopFolder(&IDesktopFolder);
705 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
707 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
708 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
710 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
711 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
713 IMalloc_Free(ppM, newPIDL);
715 /* get relative PIDL */
716 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
717 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
719 /* test the shell attributes of the test directory using the relative PIDL */
720 dwFlags = SFGAO_FOLDER;
721 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
722 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
723 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
726 IMalloc_Free(ppM, newPIDL);
728 /* append testdirectory name to path */
729 lstrcatW(cCurrDirW, cBackSlash);
730 lstrcatW(cCurrDirW, cTestDirW);
732 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
733 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
735 /* test the shell attributes of the test directory using the absolute PIDL */
736 dwFlags = SFGAO_FOLDER;
737 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
738 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
739 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
742 IMalloc_Free(ppM, newPIDL);
744 IShellFolder_Release(testIShellFolder);
748 IShellFolder_Release(IDesktopFolder);
751 static void test_SHGetPathFromIDList(void)
753 SHITEMID emptyitem = { 0, { 0 } };
754 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
755 LPITEMIDLIST pidlMyComputer;
756 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
759 LPSHELLFOLDER psfDesktop;
760 WCHAR wszMyComputer[] = {
761 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
762 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
763 WCHAR wszFileName[MAX_PATH];
764 LPITEMIDLIST pidlTestFile;
767 static WCHAR wszTestFile[] = {
768 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
769 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
771 LPITEMIDLIST pidlPrograms;
773 if(!pSHGetSpecialFolderPathW) return;
775 /* Calling SHGetPathFromIDList with no pidl should return the empty string */
778 result = SHGetPathFromIDListW(NULL, wszPath);
779 ok(!result, "Expected failure\n");
780 ok(!wszPath[0], "Expected empty string\n");
782 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
783 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
784 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
787 result = SHGetPathFromIDListW(pidlEmpty, wszPath);
788 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
790 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
792 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
793 hr = SHGetDesktopFolder(&psfDesktop);
794 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
795 if (FAILED(hr)) return;
797 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
798 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
800 IShellFolder_Release(psfDesktop);
804 SetLastError(0xdeadbeef);
807 result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
808 ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
809 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %u\n", GetLastError());
810 ok (!wszPath[0], "Expected empty path\n");
812 IShellFolder_Release(psfDesktop);
816 IMalloc_Free(ppM, pidlMyComputer);
818 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
819 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
821 IShellFolder_Release(psfDesktop);
824 PathAddBackslashW(wszFileName);
825 lstrcatW(wszFileName, wszTestFile);
826 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
827 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
828 if (hTestFile == INVALID_HANDLE_VALUE) {
829 IShellFolder_Release(psfDesktop);
832 CloseHandle(hTestFile);
834 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
835 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
837 IShellFolder_Release(psfDesktop);
838 DeleteFileW(wszFileName);
839 IMalloc_Free(ppM, pidlTestFile);
843 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
844 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
845 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
846 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
847 IShellFolder_Release(psfDesktop);
848 DeleteFileW(wszFileName);
850 IMalloc_Free(ppM, pidlTestFile);
855 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
856 ok(0 == lstrcmpW(wszFileName, wszPath),
857 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
858 "returned incorrect path for file placed on desktop\n");
861 result = SHGetPathFromIDListW(pidlTestFile, wszPath);
862 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
863 IMalloc_Free(ppM, pidlTestFile);
865 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
868 /* Test if we can get the path from the start menu "program files" PIDL. */
869 hShell32 = GetModuleHandleA("shell32");
870 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
872 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
873 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
875 SetLastError(0xdeadbeef);
876 result = SHGetPathFromIDListW(pidlPrograms, wszPath);
877 IMalloc_Free(ppM, pidlPrograms);
878 ok(result, "SHGetPathFromIDList failed\n");
881 static void test_EnumObjects_and_CompareIDs(void)
884 IShellFolder *IDesktopFolder, *testIShellFolder;
885 char cCurrDirA [MAX_PATH] = {0};
886 WCHAR cCurrDirW [MAX_PATH];
887 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
891 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
892 len = lstrlenA(cCurrDirA);
895 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
898 if(cCurrDirA[len-1] == '\\')
899 cCurrDirA[len-1] = 0;
901 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
902 lstrcatW(cCurrDirW, cTestDirW);
904 hr = SHGetDesktopFolder(&IDesktopFolder);
905 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
907 CreateFilesFolders();
909 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
910 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
912 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
913 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
915 test_EnumObjects(testIShellFolder);
917 IShellFolder_Release(testIShellFolder);
921 IMalloc_Free(ppM, newPIDL);
923 IShellFolder_Release(IDesktopFolder);
926 /* A simple implementation of an IPropertyBag, which returns fixed values for
927 * 'Target' and 'Attributes' properties.
929 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
935 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
938 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
939 return E_NOINTERFACE;
942 IPropertyBag_AddRef(iface);
946 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
950 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
954 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
955 VARIANT *pVar, IErrorLog *pErrorLog)
957 static const WCHAR wszTargetSpecialFolder[] = {
958 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
959 static const WCHAR wszTarget[] = {
960 'T','a','r','g','e','t',0 };
961 static const WCHAR wszAttributes[] = {
962 'A','t','t','r','i','b','u','t','e','s',0 };
963 static const WCHAR wszResolveLinkFlags[] = {
964 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
966 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
967 ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
971 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
973 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
977 if (!lstrcmpW(pszPropName, wszTarget)) {
978 WCHAR wszPath[MAX_PATH];
981 ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
982 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
984 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
985 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
986 if (!result) return E_INVALIDARG;
988 V_BSTR(pVar) = SysAllocString(wszPath);
992 if (!lstrcmpW(pszPropName, wszAttributes)) {
993 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
994 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
995 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
996 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1000 ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
1001 return E_INVALIDARG;
1004 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1007 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1011 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1012 InitPropertyBag_IPropertyBag_QueryInterface,
1013 InitPropertyBag_IPropertyBag_AddRef,
1014 InitPropertyBag_IPropertyBag_Release,
1015 InitPropertyBag_IPropertyBag_Read,
1016 InitPropertyBag_IPropertyBag_Write
1019 static struct IPropertyBag InitPropertyBag = {
1020 &InitPropertyBag_IPropertyBagVtbl
1023 static void test_FolderShortcut(void) {
1024 IPersistPropertyBag *pPersistPropertyBag;
1025 IShellFolder *pShellFolder, *pDesktopFolder;
1026 IPersistFolder3 *pPersistFolder3;
1029 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1032 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1034 WCHAR wszWineTestFolder[] = {
1035 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1036 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1037 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1038 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1039 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1040 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1041 'N','a','m','e','S','p','a','c','e','\\',
1042 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1043 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1045 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1046 static const GUID CLSID_UnixDosFolder =
1047 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1049 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) return;
1051 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1052 * via their IPersistPropertyBag interface. And that the target folder
1053 * is taken from the IPropertyBag's 'Target' property.
1055 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1056 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1057 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
1058 if (FAILED(hr)) return;
1060 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1061 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
1063 IPersistPropertyBag_Release(pPersistPropertyBag);
1067 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1068 (LPVOID*)&pShellFolder);
1069 IPersistPropertyBag_Release(pPersistPropertyBag);
1070 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1071 if (FAILED(hr)) return;
1073 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1074 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1076 IShellFolder_Release(pShellFolder);
1080 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1081 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1082 if (!result) return;
1084 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1085 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1087 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1088 IShellFolder_Release(pShellFolder);
1089 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
1090 if (FAILED(hr)) return;
1092 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1093 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1094 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1096 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1097 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1098 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1100 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1101 * shell namespace. The target folder, read from the property bag above, remains untouched.
1102 * The following tests show this: The itemidlist for some imaginary shellfolder object
1103 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1104 * itemidlist, but GetDisplayNameOf still returns the path from above.
1106 hr = SHGetDesktopFolder(&pDesktopFolder);
1107 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
1108 if (FAILED(hr)) return;
1110 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1111 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1112 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1113 RegCloseKey(hShellExtKey);
1114 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1115 &pidlWineTestFolder, NULL);
1116 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1117 IShellFolder_Release(pDesktopFolder);
1118 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1119 if (FAILED(hr)) return;
1121 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1122 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
1124 IPersistFolder3_Release(pPersistFolder3);
1125 ILFree(pidlWineTestFolder);
1129 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1130 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1131 ok(ILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1132 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1133 ILFree(pidlCurrentFolder);
1134 ILFree(pidlWineTestFolder);
1136 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1137 IPersistFolder3_Release(pPersistFolder3);
1138 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1139 if (FAILED(hr)) return;
1141 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1142 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1144 IShellFolder_Release(pShellFolder);
1148 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1149 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1151 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1152 * but ShellFSFolders. */
1153 PathAddBackslashW(wszDesktopPath);
1154 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1155 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1156 IShellFolder_Release(pShellFolder);
1160 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1161 &pidlSubFolder, NULL);
1162 RemoveDirectoryW(wszDesktopPath);
1163 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1165 IShellFolder_Release(pShellFolder);
1169 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1170 (LPVOID*)&pPersistFolder3);
1171 IShellFolder_Release(pShellFolder);
1172 ILFree(pidlSubFolder);
1173 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
1177 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1178 * a little bit and also allow CLSID_UnixDosFolder. */
1179 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1180 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1181 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1182 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1184 IPersistFolder3_Release(pPersistFolder3);
1187 #include "pshpack1.h"
1188 struct FileStructA {
1192 WORD uFileDate; /* In our current implementation this is */
1193 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1198 struct FileStructW {
1199 WORD cbLen; /* Length of this element. */
1200 BYTE abFooBar1[6]; /* Beyond any recognition. */
1201 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1202 WORD uTime; /* (this is currently speculation) */
1203 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1204 WORD uTime2; /* (this is currently speculation) */
1205 BYTE abFooBar2[4]; /* Beyond any recognition. */
1206 WCHAR wszName[1]; /* The long filename in unicode. */
1207 /* Just for documentation: Right after the unicode string: */
1208 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1209 * SHITEMID->cb == uOffset + cbLen */
1211 #include "poppack.h"
1213 static void test_ITEMIDLIST_format(void) {
1214 WCHAR wszPersonal[MAX_PATH];
1215 LPSHELLFOLDER psfDesktop, psfPersonal;
1216 LPITEMIDLIST pidlPersonal, pidlFile;
1220 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1221 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1224 if(!pSHGetSpecialFolderPathW) return;
1226 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1227 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1228 if (!bResult) return;
1230 bResult = SetCurrentDirectoryW(wszPersonal);
1231 ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1232 if (!bResult) return;
1234 hr = SHGetDesktopFolder(&psfDesktop);
1235 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
1236 if (FAILED(hr)) return;
1238 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1239 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
1241 IShellFolder_Release(psfDesktop);
1245 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1246 (LPVOID*)&psfPersonal);
1247 IShellFolder_Release(psfDesktop);
1248 ILFree(pidlPersonal);
1249 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
1250 if (FAILED(hr)) return;
1252 for (i=0; i<3; i++) {
1253 CHAR szFile[MAX_PATH];
1254 struct FileStructA *pFileStructA;
1257 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1259 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1260 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
1261 if (hFile == INVALID_HANDLE_VALUE) {
1262 IShellFolder_Release(psfPersonal);
1267 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1268 DeleteFileW(wszFile[i]);
1269 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
1271 IShellFolder_Release(psfPersonal);
1275 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1276 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1277 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1278 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1280 if (i < 2) /* First two file names are already in valid 8.3 format */
1281 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1283 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1284 * can't implement this correctly, since unix filesystems don't support
1285 * this nasty short/long filename stuff. So we'll probably stay with our
1286 * current habbit of storing the long filename here, which seems to work
1288 todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
1290 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1291 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0',
1292 "Alignment byte, where there shouldn't be!\n");
1294 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1295 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1296 "There should be an alignment byte, but isn't!\n");
1298 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1299 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1300 ok (cbOffset >= sizeof(struct FileStructA) &&
1301 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
1302 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1304 if (cbOffset >= sizeof(struct FileStructA) &&
1305 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1307 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1309 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1310 "FileStructW's offset and length should add up to the PIDL's length!\n");
1312 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1313 /* Since we just created the file, time of creation,
1314 * time of last access and time of last write access just be the same.
1315 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1316 * after the first run. I do remember something with NTFS keeping the creation time
1317 * if a file is deleted and then created again within a couple of seconds or so.
1318 * Might be the reason. */
1319 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1320 pFileStructA->uFileTime == pFileStructW->uTime,
1321 "Last write time should match creation time!\n");
1323 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1324 pFileStructA->uFileTime == pFileStructW->uTime2,
1325 "Last write time should match last access time!\n");
1327 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
1328 "The filename should be stored in unicode at this position!\n");
1336 START_TEST(shlfolder)
1338 init_function_pointers();
1339 /* if OleInitialize doesn't get called, ParseDisplayName returns
1340 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1341 OleInitialize(NULL);
1343 test_ParseDisplayName();
1344 test_BindToObject();
1345 test_EnumObjects_and_CompareIDs();
1346 test_GetDisplayName();
1347 test_GetAttributesOf();
1348 test_SHGetPathFromIDList();
1349 test_CallForAttributes();
1350 test_FolderShortcut();
1351 test_ITEMIDLIST_format();