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/unicode.h"
41 #include "wine/test.h"
46 static HRESULT (WINAPI *pSHBindToParent)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*);
47 static BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
48 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
49 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
51 static void init_function_pointers(void)
56 hmod = GetModuleHandleA("shell32.dll");
59 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
60 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
61 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
65 hmod = GetModuleHandleA("shlwapi.dll");
68 pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
71 hr = SHGetMalloc(&ppM);
72 ok(hr == S_OK, "SHGetMalloc failed %08lx\n", hr);
75 static void test_ParseDisplayName(void)
78 IShellFolder *IDesktopFolder;
79 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
80 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
82 WCHAR cTestDirW [MAX_PATH] = {0};
86 hr = SHGetDesktopFolder(&IDesktopFolder);
87 if(hr != S_OK) return;
89 res = GetFileAttributesA(cNonExistDir1A);
90 if(res != INVALID_FILE_ATTRIBUTES) return;
92 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
93 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
94 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
95 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
96 "ParseDisplayName returned %08lx, expected 80070002 or E_FAIL\n", hr);
98 res = GetFileAttributesA(cNonExistDir2A);
99 if(res != INVALID_FILE_ATTRIBUTES) return;
101 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
102 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
103 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
104 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
105 "ParseDisplayName returned %08lx, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
107 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
108 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
109 * out it doesn't. The magic seems to happen in the file dialogs, then. */
110 if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
112 bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
113 ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %ld\n", GetLastError());
114 if (!bRes) goto finished;
116 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
117 ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08lx.\n", hr);
118 if (FAILED(hr)) goto finished;
120 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31, "Last pidl should be of type "
121 "PT_FOLDER, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
122 IMalloc_Free(ppM, newPIDL);
125 IShellFolder_Release(IDesktopFolder);
128 /* creates a file with the specified name for tests */
129 static void CreateTestFile(const CHAR *name)
134 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
135 if (file != INVALID_HANDLE_VALUE)
137 WriteFile(file, name, strlen(name), &written, NULL);
138 WriteFile(file, "\n", strlen("\n"), &written, NULL);
144 /* initializes the tests */
145 static void CreateFilesFolders(void)
147 CreateDirectoryA(".\\testdir", NULL);
148 CreateDirectoryA(".\\testdir\\test.txt", NULL);
149 CreateTestFile (".\\testdir\\test1.txt ");
150 CreateTestFile (".\\testdir\\test2.txt ");
151 CreateTestFile (".\\testdir\\test3.txt ");
152 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
153 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
156 /* cleans after tests */
157 static void Cleanup(void)
159 DeleteFileA(".\\testdir\\test1.txt");
160 DeleteFileA(".\\testdir\\test2.txt");
161 DeleteFileA(".\\testdir\\test3.txt");
162 RemoveDirectoryA(".\\testdir\\test.txt");
163 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
164 RemoveDirectoryA(".\\testdir\\testdir2");
165 RemoveDirectoryA(".\\testdir");
170 static void test_EnumObjects(IShellFolder *iFolder)
172 IEnumIDList *iEnumList;
173 LPITEMIDLIST newPIDL, idlArr[10];
178 static const WORD iResults [5][5] =
187 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
188 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
189 static const ULONG attrs[5] =
191 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
192 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
193 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
194 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
195 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
198 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
199 ok(hr == S_OK, "EnumObjects failed %08lx\n", hr);
201 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
202 * the filesystem shellfolders return S_OK even if less than 'celt' items are
203 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
204 * only ever returns a single entry per call. */
205 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
207 ok (i == 5, "i: %d\n", i);
209 hr = IEnumIDList_Release(iEnumList);
210 ok(hr == S_OK, "IEnumIDList_Release failed %08lx\n", hr);
212 /* Sort them first in case of wrong order from system */
213 for (i=0;i<5;i++) for (j=0;j<5;j++)
214 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
217 idlArr[i] = idlArr[j];
221 for (i=0;i<5;i++) for (j=0;j<5;j++)
223 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
224 ok(hr == iResults[i][j], "Got %lx expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
228 for (i = 0; i < 5; i++)
231 /* Native returns all flags no matter what we ask for */
232 flags = SFGAO_CANCOPY;
233 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
234 flags &= SFGAO_testfor;
235 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
236 ok(flags == (attrs[i]), "GetAttributesOf[%i] got %08lx, expected %08lx\n", i, flags, attrs[i]);
238 flags = SFGAO_testfor;
239 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
240 flags &= SFGAO_testfor;
241 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
242 ok(flags == attrs[i], "GetAttributesOf[%i] got %08lx, expected %08lx\n", i, flags, attrs[i]);
246 IMalloc_Free(ppM, idlArr[i]);
249 static void test_BindToObject(void)
253 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
254 SHITEMID emptyitem = { 0, { 0 } };
255 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
256 WCHAR wszSystemDir[MAX_PATH];
257 char szSystemDir[MAX_PATH];
258 WCHAR wszMyComputer[] = {
259 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
260 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
262 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
263 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
265 hr = SHGetDesktopFolder(&psfDesktop);
266 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
267 if (FAILED(hr)) return;
269 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
270 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
272 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
273 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
275 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
276 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
278 IShellFolder_Release(psfDesktop);
282 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
283 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
284 IShellFolder_Release(psfDesktop);
285 IMalloc_Free(ppM, pidlMyComputer);
286 if (FAILED(hr)) return;
288 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
289 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
292 /* this call segfaults on 98SE */
293 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
294 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
297 cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
298 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %08lx\n", GetLastError());
299 if (cChars == 0 || cChars >= MAX_PATH) {
300 IShellFolder_Release(psfMyComputer);
303 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
305 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
306 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08lx\n", hr);
308 IShellFolder_Release(psfMyComputer);
312 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
313 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08lx\n", hr);
314 IShellFolder_Release(psfMyComputer);
315 IMalloc_Free(ppM, pidlSystemDir);
316 if (FAILED(hr)) return;
318 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
319 ok (hr == E_INVALIDARG,
320 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
323 /* this call segfaults on 98SE */
324 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
325 ok (hr == E_INVALIDARG,
326 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
329 IShellFolder_Release(psfSystemDir);
332 static void test_GetDisplayName(void)
337 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
338 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
340 LPSHELLFOLDER psfDesktop, psfPersonal;
342 SHITEMID emptyitem = { 0, { 0 } };
343 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
344 LPCITEMIDLIST pidlLast;
345 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
346 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
348 /* I'm trying to figure if there is a functional difference between calling
349 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
350 * binding to the shellfolder. One thing I thought of was that perhaps
351 * SHGetPathFromIDList would be able to get the path to a file, which does
352 * not exist anymore, while the other method would'nt. It turns out there's
353 * no functional difference in this respect.
356 if(!pSHGetSpecialFolderPathW) return;
358 /* First creating a directory in MyDocuments and a file in this directory. */
359 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
360 ok(result, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
363 PathAddBackslashW(wszTestDir);
364 lstrcatW(wszTestDir, wszDirName);
365 WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
366 result = CreateDirectoryA(szTestDir, NULL);
367 ok(result, "CreateDirectoryA failed! Last error: %08lx\n", GetLastError());
370 lstrcpyW(wszTestFile, wszTestDir);
371 PathAddBackslashW(wszTestFile);
372 lstrcatW(wszTestFile, wszFileName);
373 WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
375 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
376 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %08lx\n", GetLastError());
377 if (hTestFile == INVALID_HANDLE_VALUE) return;
378 CloseHandle(hTestFile);
380 /* Getting an itemidlist for the file. */
381 hr = SHGetDesktopFolder(&psfDesktop);
382 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
383 if (FAILED(hr)) return;
385 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
386 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08lx\n", hr);
388 IShellFolder_Release(psfDesktop);
392 /* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
393 pidlLast = pILFindLastID(pidlTestFile);
394 ok(pidlLast->mkid.cb >=76, "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
395 if (pidlLast->mkid.cb >= 76) {
396 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
397 "WinXP stores the filename as a wchar-string at this position!\n");
400 /* It seems as if we cannot bind to regular files on windows, but only directories.
402 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
403 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08lx\n", hr); }
405 IShellFolder_Release(psfFile);
408 /* Some tests for IShellFolder::SetNameOf */
409 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
410 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08lx\n", hr);
412 /* It's ok to use this fixed path. Call will fail anyway. */
413 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
414 LPITEMIDLIST pidlNew;
416 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
417 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
418 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08lx\n", hr);
419 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
420 "pidl returned from SetNameOf should be simple!\n");
422 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
423 * is implemented on top of SHFileOperation in WinXP. */
424 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
425 SHGDN_FORPARSING, NULL);
426 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08lx\n", hr);
428 /* Rename the file back to it's original name. SetNameOf ignores the fact, that the
429 * SHGDN flags specify an absolute path. */
430 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
431 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08lx\n", hr);
434 IShellFolder_Release(psfPersonal);
437 /* Deleting the file and the directory */
438 DeleteFileA(szTestFile);
439 RemoveDirectoryA(szTestDir);
441 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
442 result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
443 ok (result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
444 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
446 if(!pSHBindToParent) return;
448 /* SHBindToParent fails, if called with a NULL PIDL. */
449 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
450 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
452 /* But it succeeds with an empty PIDL. */
453 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
454 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08lx\n", hr);
455 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
457 IShellFolder_Release(psfPersonal);
459 /* Binding to the folder and querying the display name of the file also works. */
460 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
461 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08lx\n", hr);
463 IShellFolder_Release(psfDesktop);
467 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
468 * pidlTestFile (In accordance with MSDN). */
469 ok (pILFindLastID(pidlTestFile) == pidlLast,
470 "SHBindToParent doesn't return the last id of the pidl param!\n");
472 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
473 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08lx\n", hr);
475 IShellFolder_Release(psfDesktop);
476 IShellFolder_Release(psfPersonal);
482 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
483 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08lx\n", hr);
484 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
487 IShellFolder_Release(psfDesktop);
488 IShellFolder_Release(psfPersonal);
491 static void test_CallForAttributes(void)
497 LPSHELLFOLDER psfDesktop;
498 LPITEMIDLIST pidlMyDocuments;
499 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
500 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
501 static const WCHAR wszCallForAttributes[] = {
502 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
503 static const WCHAR wszMyDocumentsKey[] = {
504 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
505 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
506 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
507 WCHAR wszMyDocuments[] = {
508 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
509 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
511 /* For the root of a namespace extension, the attributes are not queried by binding
512 * to the object and calling GetAttributesOf. Instead, the attributes are read from
513 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
515 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
516 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
517 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
518 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
520 hr = SHGetDesktopFolder(&psfDesktop);
521 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
522 if (FAILED(hr)) return;
524 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
525 &pidlMyDocuments, NULL);
527 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08lx\n", hr);
529 IShellFolder_Release(psfDesktop);
533 dwAttributes = 0xffffffff;
534 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
535 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
536 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
538 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
539 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
540 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
541 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
543 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
544 * key. So the test will return at this point, if run on wine.
546 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
547 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08lx\n", lResult);
548 if (lResult != ERROR_SUCCESS) {
549 IMalloc_Free(ppM, pidlMyDocuments);
550 IShellFolder_Release(psfDesktop);
554 /* Query MyDocuments' Attributes value, to be able to restore it later. */
555 dwSize = sizeof(DWORD);
556 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
557 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
558 if (lResult != ERROR_SUCCESS) {
560 IMalloc_Free(ppM, pidlMyDocuments);
561 IShellFolder_Release(psfDesktop);
565 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
566 dwSize = sizeof(DWORD);
567 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
568 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
569 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
570 if (lResult != ERROR_SUCCESS) {
572 IMalloc_Free(ppM, pidlMyDocuments);
573 IShellFolder_Release(psfDesktop);
577 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
578 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
579 * SFGAO_FILESYSTEM attributes. */
580 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
581 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
582 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
583 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
584 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
586 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
587 * GetAttributesOf. It seems that once there is a single attribute queried, for which
588 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
589 * the flags in Attributes are ignored.
591 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
592 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
593 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
594 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
596 ok (dwAttributes == SFGAO_FILESYSTEM,
597 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08lx\n",
600 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
601 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
602 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
603 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
605 IMalloc_Free(ppM, pidlMyDocuments);
606 IShellFolder_Release(psfDesktop);
609 static void test_GetAttributesOf(void)
612 LPSHELLFOLDER psfDesktop, psfMyComputer;
613 SHITEMID emptyitem = { 0, { 0 } };
614 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
615 LPITEMIDLIST pidlMyComputer;
617 static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
618 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
619 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
620 static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
621 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
622 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
623 WCHAR wszMyComputer[] = {
624 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
625 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
626 char cCurrDirA [MAX_PATH] = {0};
627 WCHAR cCurrDirW [MAX_PATH];
628 static const WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
629 static const WCHAR cBackSlash[] = {'\\',0};
630 IShellFolder *IDesktopFolder, *testIShellFolder;
634 hr = SHGetDesktopFolder(&psfDesktop);
635 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
636 if (FAILED(hr)) return;
638 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
639 dwFlags = 0xffffffff;
640 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
641 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08lx\n", hr);
642 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
643 dwFlags, dwDesktopFlags);
645 /* .. or with no itemidlist at all. */
646 dwFlags = 0xffffffff;
647 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
648 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
649 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
650 dwFlags, dwDesktopFlags);
652 /* Testing the attributes of the MyComputer shellfolder */
653 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
654 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
656 IShellFolder_Release(psfDesktop);
660 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
661 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
662 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
663 * should create a link to the original data". You can't create links on MyComputer on
664 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
665 * depends on this bug, we probably shouldn't imitate it.
667 dwFlags = 0xffffffff;
668 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
669 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08lx\n", hr);
670 ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
671 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags);
673 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
674 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
675 IShellFolder_Release(psfDesktop);
676 IMalloc_Free(ppM, pidlMyComputer);
677 if (FAILED(hr)) return;
679 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
680 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08lx\n", hr); }
682 dwFlags = 0xffffffff;
683 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
684 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
685 todo_wine { ok (dwFlags == dwMyComputerFlags,
686 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags); }
688 IShellFolder_Release(psfMyComputer);
690 /* create test directory */
691 CreateFilesFolders();
693 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
694 len = lstrlenA(cCurrDirA);
697 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
700 if(cCurrDirA[len-1] == '\\')
701 cCurrDirA[len-1] = 0;
703 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
705 hr = SHGetDesktopFolder(&IDesktopFolder);
706 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
708 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
709 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
711 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
712 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
714 IMalloc_Free(ppM, newPIDL);
716 /* get relative PIDL */
717 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, (LPWSTR)cTestDirW, NULL, &newPIDL, 0);
718 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
720 /* test the shell attributes of the test directory using the relative PIDL */
721 dwFlags = SFGAO_FOLDER;
722 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
723 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08lx\n", hr);
724 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08lx\n", dwFlags);
727 IMalloc_Free(ppM, newPIDL);
729 /* append testdirectory name to path */
730 strcatW(cCurrDirW, cBackSlash);
731 strcatW(cCurrDirW, cTestDirW);
733 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
734 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
736 /* test the shell attributes of the test directory using the absolute PIDL */
737 dwFlags = SFGAO_FOLDER;
738 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
739 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08lx\n", hr);
740 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08lx\n", dwFlags);
743 IMalloc_Free(ppM, newPIDL);
745 IShellFolder_Release(testIShellFolder);
749 IShellFolder_Release(IDesktopFolder);
752 static void test_SHGetPathFromIDList(void)
754 SHITEMID emptyitem = { 0, { 0 } };
755 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
756 LPITEMIDLIST pidlMyComputer;
757 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
760 LPSHELLFOLDER psfDesktop;
761 WCHAR wszMyComputer[] = {
762 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
763 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
764 WCHAR wszFileName[MAX_PATH];
765 LPITEMIDLIST pidlTestFile;
768 static WCHAR wszTestFile[] = {
769 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
770 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
772 LPITEMIDLIST pidlPrograms;
774 if(!pSHGetSpecialFolderPathW) return;
776 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
777 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
778 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %08lx\n", GetLastError());
781 result = SHGetPathFromIDListW(pidlEmpty, wszPath);
782 ok(result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
784 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
786 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
787 hr = SHGetDesktopFolder(&psfDesktop);
788 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
789 if (FAILED(hr)) return;
791 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
792 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
794 IShellFolder_Release(psfDesktop);
798 SetLastError(0xdeadbeef);
799 result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
800 ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
801 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %08lx\n", GetLastError());
803 IShellFolder_Release(psfDesktop);
807 IMalloc_Free(ppM, pidlMyComputer);
809 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
810 ok(result, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
812 IShellFolder_Release(psfDesktop);
815 PathAddBackslashW(wszFileName);
816 lstrcatW(wszFileName, wszTestFile);
817 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
818 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %08lx\n", GetLastError());
819 if (hTestFile == INVALID_HANDLE_VALUE) {
820 IShellFolder_Release(psfDesktop);
823 CloseHandle(hTestFile);
825 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
826 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08lx\n", hr);
828 IShellFolder_Release(psfDesktop);
829 DeleteFileW(wszFileName);
830 IMalloc_Free(ppM, pidlTestFile);
834 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
835 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
836 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
837 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08lx\n", hr);
838 IShellFolder_Release(psfDesktop);
839 DeleteFileW(wszFileName);
841 IMalloc_Free(ppM, pidlTestFile);
846 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
847 ok(0 == lstrcmpW(wszFileName, wszPath),
848 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
849 "returned incorrect path for file placed on desktop\n");
852 result = SHGetPathFromIDListW(pidlTestFile, wszPath);
853 ok(result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
854 IMalloc_Free(ppM, pidlTestFile);
856 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
859 /* Test if we can get the path from the start menu "program files" PIDL. */
860 hShell32 = GetModuleHandleA("shell32");
861 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
863 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
864 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08lx\n", hr);
866 SetLastError(0xdeadbeef);
867 result = SHGetPathFromIDListW(pidlPrograms, wszPath);
868 IMalloc_Free(ppM, pidlPrograms);
869 ok(result, "SHGetPathFromIDList failed\n");
872 static void test_EnumObjects_and_CompareIDs(void)
875 IShellFolder *IDesktopFolder, *testIShellFolder;
876 char cCurrDirA [MAX_PATH] = {0};
877 WCHAR cCurrDirW [MAX_PATH];
878 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
882 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
883 len = lstrlenA(cCurrDirA);
886 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
889 if(cCurrDirA[len-1] == '\\')
890 cCurrDirA[len-1] = 0;
892 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
893 strcatW(cCurrDirW, cTestDirW);
895 hr = SHGetDesktopFolder(&IDesktopFolder);
896 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
898 CreateFilesFolders();
900 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
901 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
903 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
904 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
906 test_EnumObjects(testIShellFolder);
908 IShellFolder_Release(testIShellFolder);
912 IMalloc_Free(ppM, newPIDL);
914 IShellFolder_Release(IDesktopFolder);
917 /* A simple implementation of an IPropertyBag, which returns fixed values for
918 * 'Target' and 'Attributes' properties.
920 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
926 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
929 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
930 return E_NOINTERFACE;
933 IPropertyBag_AddRef(iface);
937 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
941 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
945 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
946 VARIANT *pVar, IErrorLog *pErrorLog)
948 static const WCHAR wszTargetSpecialFolder[] = {
949 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
950 static const WCHAR wszTarget[] = {
951 'T','a','r','g','e','t',0 };
952 static const WCHAR wszAttributes[] = {
953 'A','t','t','r','i','b','u','t','e','s',0 };
954 static const WCHAR wszResolveLinkFlags[] = {
955 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
957 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
958 ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
962 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
964 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
968 if (!lstrcmpW(pszPropName, wszTarget)) {
969 WCHAR wszPath[MAX_PATH];
972 ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
973 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
975 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
976 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! x%08lx\n", GetLastError());
977 if (!result) return E_INVALIDARG;
979 V_BSTR(pVar) = SysAllocString(wszPath);
983 if (!lstrcmpW(pszPropName, wszAttributes)) {
984 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
985 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
986 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
987 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
991 ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
995 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
998 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1002 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1003 InitPropertyBag_IPropertyBag_QueryInterface,
1004 InitPropertyBag_IPropertyBag_AddRef,
1005 InitPropertyBag_IPropertyBag_Release,
1006 InitPropertyBag_IPropertyBag_Read,
1007 InitPropertyBag_IPropertyBag_Write
1010 struct IPropertyBag InitPropertyBag = {
1011 &InitPropertyBag_IPropertyBagVtbl
1014 void test_FolderShortcut(void) {
1015 IPersistPropertyBag *pPersistPropertyBag;
1016 IShellFolder *pShellFolder, *pDesktopFolder;
1017 IPersistFolder3 *pPersistFolder3;
1020 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1023 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1025 WCHAR wszWineTestFolder[] = {
1026 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1027 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1028 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1029 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1030 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1031 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1032 'N','a','m','e','S','p','a','c','e','\\',
1033 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1034 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1036 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1037 static const GUID CLSID_UnixDosFolder =
1038 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1040 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) return;
1042 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1043 * via their IPersistPropertyBag interface. And that the target folder
1044 * is taken from the IPropertyBag's 'Target' property.
1046 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1047 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1048 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08lx\n", hr);
1049 if (FAILED(hr)) return;
1051 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1052 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08lx\n", hr);
1054 IPersistPropertyBag_Release(pPersistPropertyBag);
1058 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1059 (LPVOID*)&pShellFolder);
1060 IPersistPropertyBag_Release(pPersistPropertyBag);
1061 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08lx\n", hr);
1062 if (FAILED(hr)) return;
1064 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1065 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08lx\n", hr);
1067 IShellFolder_Release(pShellFolder);
1071 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1072 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! 0x%08lx\n", GetLastError());
1073 if (!result) return;
1075 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1076 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1078 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1079 IShellFolder_Release(pShellFolder);
1080 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08lx\n", hr);
1081 if (FAILED(hr)) return;
1083 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1084 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08lx\n", hr);
1085 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1087 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1088 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08lx\n", hr);
1089 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1091 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1092 * shell namespace. The target folder, read from the property bag above, remains untouched.
1093 * The following tests show this: The itemidlist for some imaginary shellfolder object
1094 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1095 * itemidlist, but GetDisplayNameOf still returns the path from above.
1097 hr = SHGetDesktopFolder(&pDesktopFolder);
1098 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
1099 if (FAILED(hr)) return;
1101 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1102 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1103 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1104 RegCloseKey(hShellExtKey);
1105 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1106 &pidlWineTestFolder, NULL);
1107 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1108 IShellFolder_Release(pDesktopFolder);
1109 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08lx\n", hr);
1110 if (FAILED(hr)) return;
1112 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1113 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08lx\n", hr);
1115 IPersistFolder3_Release(pPersistFolder3);
1116 ILFree(pidlWineTestFolder);
1120 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1121 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08lx\n", hr);
1122 ok(ILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1123 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1124 ILFree(pidlCurrentFolder);
1125 ILFree(pidlWineTestFolder);
1127 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1128 IPersistFolder3_Release(pPersistFolder3);
1129 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08lx\n", hr);
1130 if (FAILED(hr)) return;
1132 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1133 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08lx\n", hr);
1135 IShellFolder_Release(pShellFolder);
1139 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1140 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1142 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1143 * but ShellFSFolders. */
1144 PathAddBackslashW(wszDesktopPath);
1145 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1146 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1147 IShellFolder_Release(pShellFolder);
1151 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1152 &pidlSubFolder, NULL);
1153 RemoveDirectoryW(wszDesktopPath);
1154 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08lx\n", hr);
1156 IShellFolder_Release(pShellFolder);
1160 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1161 (LPVOID*)&pPersistFolder3);
1162 IShellFolder_Release(pShellFolder);
1163 ILFree(pidlSubFolder);
1164 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08lx\n", hr);
1168 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1169 * a little bit and also allow CLSID_UnixDosFolder. */
1170 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1171 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08lx\n", hr);
1172 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1173 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1175 IPersistFolder3_Release(pPersistFolder3);
1178 #include "pshpack1.h"
1179 struct FileStructA {
1183 WORD uFileDate; /* In our current implementation this is */
1184 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1189 struct FileStructW {
1190 WORD cbLen; /* Length of this element. */
1191 BYTE abFooBar1[6]; /* Beyond any recognition. */
1192 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1193 WORD uTime; /* (this is currently speculation) */
1194 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1195 WORD uTime2; /* (this is currently speculation) */
1196 BYTE abFooBar2[4]; /* Beyond any recognition. */
1197 WCHAR wszName[1]; /* The long filename in unicode. */
1198 /* Just for documentation: Right after the unicode string: */
1199 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1200 * SHITEMID->cb == uOffset + cbLen */
1202 #include "poppack.h"
1204 void test_ITEMIDLIST_format(void) {
1205 WCHAR wszPersonal[MAX_PATH];
1206 LPSHELLFOLDER psfDesktop, psfPersonal;
1207 LPITEMIDLIST pidlPersonal, pidlFile;
1211 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1212 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1215 if(!pSHGetSpecialFolderPathW) return;
1217 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1218 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
1219 if (!bResult) return;
1221 bResult = SetCurrentDirectoryW(wszPersonal);
1222 ok(bResult, "SetCurrentDirectory failed! Last error: %ld\n", GetLastError());
1223 if (!bResult) return;
1225 hr = SHGetDesktopFolder(&psfDesktop);
1226 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08lx\n", hr);
1227 if (FAILED(hr)) return;
1229 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1230 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08lx\n", hr);
1232 IShellFolder_Release(psfDesktop);
1236 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1237 (LPVOID*)&psfPersonal);
1238 IShellFolder_Release(psfDesktop);
1239 ILFree(pidlPersonal);
1240 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08lx\n", hr);
1241 if (FAILED(hr)) return;
1243 for (i=0; i<3; i++) {
1244 CHAR szFile[MAX_PATH];
1245 struct FileStructA *pFileStructA;
1248 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1250 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1251 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%ld)\n", GetLastError());
1252 if (hFile == INVALID_HANDLE_VALUE) {
1253 IShellFolder_Release(psfPersonal);
1258 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1259 DeleteFileW(wszFile[i]);
1260 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08lx\n", hr);
1262 IShellFolder_Release(psfPersonal);
1266 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1267 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1268 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1269 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1271 if (i < 2) /* First two file names are already in valid 8.3 format */
1272 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1274 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1275 * can't implement this correctly, since unix filesystems don't support
1276 * this nasty short/long filename stuff. So we'll probably stay with our
1277 * current habbit of storing the long filename here, which seems to work
1279 todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
1281 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1282 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0',
1283 "Alignment byte, where there shouldn't be!\n");
1285 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1286 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1287 "There should be an alignment byte, but isn't!\n");
1289 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1290 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1291 ok (cbOffset >= sizeof(struct FileStructA) &&
1292 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
1293 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1295 if (cbOffset >= sizeof(struct FileStructA) &&
1296 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1298 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1300 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1301 "FileStructW's offset and length should add up to the PIDL's length!\n");
1303 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1304 /* Since we just created the file, time of creation,
1305 * time of last access and time of last write access just be the same.
1306 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1307 * after the first run. I do remember something with NTFS keeping the creation time
1308 * if a file is deleted and then created again within a couple of seconds or so.
1309 * Might be the reason. */
1310 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1311 pFileStructA->uFileTime == pFileStructW->uTime,
1312 "Last write time should match creation time!\n");
1314 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1315 pFileStructA->uFileTime == pFileStructW->uTime2,
1316 "Last write time should match last access time!\n");
1318 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
1319 "The filename should be stored in unicode at this position!\n");
1327 START_TEST(shlfolder)
1329 init_function_pointers();
1330 /* if OleInitialize doesn't get called, ParseDisplayName returns
1331 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1332 OleInitialize(NULL);
1334 test_ParseDisplayName();
1335 test_BindToObject();
1336 test_EnumObjects_and_CompareIDs();
1337 test_GetDisplayName();
1338 test_GetAttributesOf();
1339 test_SHGetPathFromIDList();
1340 test_CallForAttributes();
1341 test_FolderShortcut();
1342 test_ITEMIDLIST_format();