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);
49 static void (WINAPI *pILFree)(LPITEMIDLIST);
50 static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
52 static void init_function_pointers(void)
57 hmod = GetModuleHandleA("shell32.dll");
58 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
59 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
60 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
61 pILFree = (void*)GetProcAddress(hmod, (LPSTR)155);
62 pILIsEqual = (void*)GetProcAddress(hmod, (LPSTR)21);
64 hmod = GetModuleHandleA("shlwapi.dll");
65 pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
67 hr = SHGetMalloc(&ppM);
68 ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
71 static void test_ParseDisplayName(void)
74 IShellFolder *IDesktopFolder;
75 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
76 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
78 WCHAR cTestDirW [MAX_PATH] = {0};
82 hr = SHGetDesktopFolder(&IDesktopFolder);
83 if(hr != S_OK) return;
85 res = GetFileAttributesA(cNonExistDir1A);
86 if(res != INVALID_FILE_ATTRIBUTES) return;
88 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
89 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
90 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
91 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
92 "ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr);
94 res = GetFileAttributesA(cNonExistDir2A);
95 if(res != INVALID_FILE_ATTRIBUTES) return;
97 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
98 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
99 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
100 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
101 "ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
103 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
104 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
105 * out it doesn't. The magic seems to happen in the file dialogs, then. */
106 if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
108 bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
109 ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
110 if (!bRes) goto finished;
112 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
113 ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr);
114 if (FAILED(hr)) goto finished;
116 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31, "Last pidl should be of type "
117 "PT_FOLDER, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
118 IMalloc_Free(ppM, newPIDL);
121 IShellFolder_Release(IDesktopFolder);
124 /* creates a file with the specified name for tests */
125 static void CreateTestFile(const CHAR *name)
130 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
131 if (file != INVALID_HANDLE_VALUE)
133 WriteFile(file, name, strlen(name), &written, NULL);
134 WriteFile(file, "\n", strlen("\n"), &written, NULL);
140 /* initializes the tests */
141 static void CreateFilesFolders(void)
143 CreateDirectoryA(".\\testdir", NULL);
144 CreateDirectoryA(".\\testdir\\test.txt", NULL);
145 CreateTestFile (".\\testdir\\test1.txt ");
146 CreateTestFile (".\\testdir\\test2.txt ");
147 CreateTestFile (".\\testdir\\test3.txt ");
148 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
149 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
152 /* cleans after tests */
153 static void Cleanup(void)
155 DeleteFileA(".\\testdir\\test1.txt");
156 DeleteFileA(".\\testdir\\test2.txt");
157 DeleteFileA(".\\testdir\\test3.txt");
158 RemoveDirectoryA(".\\testdir\\test.txt");
159 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
160 RemoveDirectoryA(".\\testdir\\testdir2");
161 RemoveDirectoryA(".\\testdir");
166 static void test_EnumObjects(IShellFolder *iFolder)
168 IEnumIDList *iEnumList;
169 LPITEMIDLIST newPIDL, idlArr[10];
174 static const WORD iResults [5][5] =
183 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
184 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
185 static const ULONG attrs[5] =
187 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
188 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
189 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
190 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
191 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
194 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
195 ok(hr == S_OK, "EnumObjects failed %08x\n", hr);
197 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
198 * the filesystem shellfolders return S_OK even if less than 'celt' items are
199 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
200 * only ever returns a single entry per call. */
201 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
203 ok (i == 5, "i: %d\n", i);
205 hr = IEnumIDList_Release(iEnumList);
206 ok(hr == S_OK, "IEnumIDList_Release failed %08x\n", hr);
208 /* Sort them first in case of wrong order from system */
209 for (i=0;i<5;i++) for (j=0;j<5;j++)
210 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
213 idlArr[i] = idlArr[j];
217 for (i=0;i<5;i++) for (j=0;j<5;j++)
219 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
220 ok(hr == iResults[i][j], "Got %x expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
224 for (i = 0; i < 5; i++)
227 /* Native returns all flags no matter what we ask for */
228 flags = SFGAO_CANCOPY;
229 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
230 flags &= SFGAO_testfor;
231 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
232 ok(flags == (attrs[i]), "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
234 flags = SFGAO_testfor;
235 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
236 flags &= SFGAO_testfor;
237 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
238 ok(flags == attrs[i], "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
242 IMalloc_Free(ppM, idlArr[i]);
245 static void test_BindToObject(void)
249 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
250 SHITEMID emptyitem = { 0, { 0 } };
251 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
252 WCHAR wszSystemDir[MAX_PATH];
253 char szSystemDir[MAX_PATH];
254 WCHAR wszMyComputer[] = {
255 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
256 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
258 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
259 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
261 hr = SHGetDesktopFolder(&psfDesktop);
262 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
263 if (FAILED(hr)) return;
265 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
266 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
268 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
269 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
271 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
272 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
274 IShellFolder_Release(psfDesktop);
278 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
279 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
280 IShellFolder_Release(psfDesktop);
281 IMalloc_Free(ppM, pidlMyComputer);
282 if (FAILED(hr)) return;
284 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
285 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
288 /* this call segfaults on 98SE */
289 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
290 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
293 cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
294 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
295 if (cChars == 0 || cChars >= MAX_PATH) {
296 IShellFolder_Release(psfMyComputer);
299 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
301 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
302 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr);
304 IShellFolder_Release(psfMyComputer);
308 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
309 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr);
310 IShellFolder_Release(psfMyComputer);
311 IMalloc_Free(ppM, pidlSystemDir);
312 if (FAILED(hr)) return;
314 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
315 ok (hr == E_INVALIDARG,
316 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
319 /* this call segfaults on 98SE */
320 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
321 ok (hr == E_INVALIDARG,
322 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
325 IShellFolder_Release(psfSystemDir);
328 static void test_GetDisplayName(void)
333 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
334 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
337 LPSHELLFOLDER psfDesktop, psfPersonal;
339 SHITEMID emptyitem = { 0, { 0 } };
340 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
341 LPCITEMIDLIST pidlLast;
342 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
343 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
345 /* I'm trying to figure if there is a functional difference between calling
346 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
347 * binding to the shellfolder. One thing I thought of was that perhaps
348 * SHGetPathFromIDList would be able to get the path to a file, which does
349 * not exist anymore, while the other method would'nt. It turns out there's
350 * no functional difference in this respect.
353 if(!pSHGetSpecialFolderPathW) return;
355 /* First creating a directory in MyDocuments and a file in this directory. */
356 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
357 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
360 PathAddBackslashW(wszTestDir);
361 lstrcatW(wszTestDir, wszDirName);
362 /* Use ANSI file functions so this works on Windows 9x */
363 WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
364 CreateDirectoryA(szTestDir, NULL);
365 attr=GetFileAttributesA(szTestDir);
366 if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
368 ok(0, "unable to create the '%s' directory\n", szTestDir);
372 lstrcpyW(wszTestFile, wszTestDir);
373 PathAddBackslashW(wszTestFile);
374 lstrcatW(wszTestFile, wszFileName);
375 WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
377 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
378 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
379 if (hTestFile == INVALID_HANDLE_VALUE) return;
380 CloseHandle(hTestFile);
382 /* Getting an itemidlist for the file. */
383 hr = SHGetDesktopFolder(&psfDesktop);
384 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
385 if (FAILED(hr)) return;
387 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
388 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
390 IShellFolder_Release(psfDesktop);
394 /* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
395 pidlLast = pILFindLastID(pidlTestFile);
396 ok(pidlLast->mkid.cb >=76, "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
397 if (pidlLast->mkid.cb >= 76) {
398 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
399 "WinXP stores the filename as a wchar-string at this position!\n");
402 /* It seems as if we cannot bind to regular files on windows, but only directories.
404 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
405 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08x\n", hr); }
407 IShellFolder_Release(psfFile);
410 /* Some tests for IShellFolder::SetNameOf */
411 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
412 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
414 /* It's ok to use this fixed path. Call will fail anyway. */
415 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
416 LPITEMIDLIST pidlNew;
418 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
419 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
420 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
421 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
422 "pidl returned from SetNameOf should be simple!\n");
424 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
425 * is implemented on top of SHFileOperation in WinXP. */
426 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
427 SHGDN_FORPARSING, NULL);
428 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
430 /* Rename the file back to its original name. SetNameOf ignores the fact, that the
431 * SHGDN flags specify an absolute path. */
432 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
433 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
436 IShellFolder_Release(psfPersonal);
439 /* Deleting the file and the directory */
440 DeleteFileA(szTestFile);
441 RemoveDirectoryA(szTestDir);
443 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
444 result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
445 ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
446 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
448 if(!pSHBindToParent) return;
450 /* SHBindToParent fails, if called with a NULL PIDL. */
451 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
452 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
454 /* But it succeeds with an empty PIDL. */
455 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
456 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
457 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
459 IShellFolder_Release(psfPersonal);
461 /* Binding to the folder and querying the display name of the file also works. */
462 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
463 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
465 IShellFolder_Release(psfDesktop);
469 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
470 * pidlTestFile (In accordance with MSDN). */
471 ok (pILFindLastID(pidlTestFile) == pidlLast,
472 "SHBindToParent doesn't return the last id of the pidl param!\n");
474 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
475 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
477 IShellFolder_Release(psfDesktop);
478 IShellFolder_Release(psfPersonal);
484 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
485 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
486 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
489 IShellFolder_Release(psfDesktop);
490 IShellFolder_Release(psfPersonal);
493 static void test_CallForAttributes(void)
499 LPSHELLFOLDER psfDesktop;
500 LPITEMIDLIST pidlMyDocuments;
501 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
502 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
503 static const WCHAR wszCallForAttributes[] = {
504 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
505 static const WCHAR wszMyDocumentsKey[] = {
506 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
507 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
508 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
509 WCHAR wszMyDocuments[] = {
510 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
511 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
513 /* For the root of a namespace extension, the attributes are not queried by binding
514 * to the object and calling GetAttributesOf. Instead, the attributes are read from
515 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
517 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
518 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
519 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
520 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
522 hr = SHGetDesktopFolder(&psfDesktop);
523 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
524 if (FAILED(hr)) return;
526 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
527 &pidlMyDocuments, NULL);
529 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
531 IShellFolder_Release(psfDesktop);
535 dwAttributes = 0xffffffff;
536 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
537 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
538 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
540 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
541 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
542 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
543 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
545 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
546 * key. So the test will return at this point, if run on wine.
548 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
549 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
550 if (lResult != ERROR_SUCCESS) {
551 IMalloc_Free(ppM, pidlMyDocuments);
552 IShellFolder_Release(psfDesktop);
556 /* Query MyDocuments' Attributes value, to be able to restore it later. */
557 dwSize = sizeof(DWORD);
558 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
559 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
560 if (lResult != ERROR_SUCCESS) {
562 IMalloc_Free(ppM, pidlMyDocuments);
563 IShellFolder_Release(psfDesktop);
567 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
568 dwSize = sizeof(DWORD);
569 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
570 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
571 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
572 if (lResult != ERROR_SUCCESS) {
574 IMalloc_Free(ppM, pidlMyDocuments);
575 IShellFolder_Release(psfDesktop);
579 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
580 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
581 * SFGAO_FILESYSTEM attributes. */
582 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
583 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
584 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
585 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
586 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
588 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
589 * GetAttributesOf. It seems that once there is a single attribute queried, for which
590 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
591 * the flags in Attributes are ignored.
593 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
594 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
595 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
596 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
598 ok (dwAttributes == SFGAO_FILESYSTEM,
599 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n",
602 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
603 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
604 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
605 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
607 IMalloc_Free(ppM, pidlMyDocuments);
608 IShellFolder_Release(psfDesktop);
611 static void test_GetAttributesOf(void)
614 LPSHELLFOLDER psfDesktop, psfMyComputer;
615 SHITEMID emptyitem = { 0, { 0 } };
616 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
617 LPITEMIDLIST pidlMyComputer;
619 static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
620 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
621 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
622 static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
623 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
624 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
625 WCHAR wszMyComputer[] = {
626 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
627 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
628 char cCurrDirA [MAX_PATH] = {0};
629 WCHAR cCurrDirW [MAX_PATH];
630 static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
631 static const WCHAR cBackSlash[] = {'\\',0};
632 IShellFolder *IDesktopFolder, *testIShellFolder;
636 hr = SHGetDesktopFolder(&psfDesktop);
637 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
638 if (FAILED(hr)) return;
640 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
641 dwFlags = 0xffffffff;
642 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
643 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
644 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
645 dwFlags, dwDesktopFlags);
647 /* .. or with no itemidlist at all. */
648 dwFlags = 0xffffffff;
649 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
650 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
651 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
652 dwFlags, dwDesktopFlags);
654 /* Testing the attributes of the MyComputer shellfolder */
655 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
656 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
658 IShellFolder_Release(psfDesktop);
662 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
663 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
664 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
665 * should create a link to the original data". You can't create links on MyComputer on
666 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
667 * depends on this bug, we probably shouldn't imitate it.
669 dwFlags = 0xffffffff;
670 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
671 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
672 ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
673 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags);
675 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
676 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
677 IShellFolder_Release(psfDesktop);
678 IMalloc_Free(ppM, pidlMyComputer);
679 if (FAILED(hr)) return;
681 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
682 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr); }
684 dwFlags = 0xffffffff;
685 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
686 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
687 todo_wine { ok (dwFlags == dwMyComputerFlags,
688 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags); }
690 IShellFolder_Release(psfMyComputer);
692 /* create test directory */
693 CreateFilesFolders();
695 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
696 len = lstrlenA(cCurrDirA);
699 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
702 if(cCurrDirA[len-1] == '\\')
703 cCurrDirA[len-1] = 0;
705 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
707 hr = SHGetDesktopFolder(&IDesktopFolder);
708 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
710 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
711 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
713 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
714 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
716 IMalloc_Free(ppM, newPIDL);
718 /* get relative PIDL */
719 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
720 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
722 /* test the shell attributes of the test directory using the relative PIDL */
723 dwFlags = SFGAO_FOLDER;
724 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
725 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
726 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
729 IMalloc_Free(ppM, newPIDL);
731 /* append testdirectory name to path */
732 lstrcatW(cCurrDirW, cBackSlash);
733 lstrcatW(cCurrDirW, cTestDirW);
735 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
736 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
738 /* test the shell attributes of the test directory using the absolute PIDL */
739 dwFlags = SFGAO_FOLDER;
740 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
741 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
742 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
745 IMalloc_Free(ppM, newPIDL);
747 IShellFolder_Release(testIShellFolder);
751 IShellFolder_Release(IDesktopFolder);
754 static void test_SHGetPathFromIDList(void)
756 SHITEMID emptyitem = { 0, { 0 } };
757 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
758 LPITEMIDLIST pidlMyComputer;
759 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
762 LPSHELLFOLDER psfDesktop;
763 WCHAR wszMyComputer[] = {
764 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
765 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
766 WCHAR wszFileName[MAX_PATH];
767 LPITEMIDLIST pidlTestFile;
770 static WCHAR wszTestFile[] = {
771 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
772 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
774 LPITEMIDLIST pidlPrograms;
776 if(!pSHGetSpecialFolderPathW) return;
778 /* Calling SHGetPathFromIDList with no pidl should return the empty string */
781 result = SHGetPathFromIDListW(NULL, wszPath);
782 ok(!result, "Expected failure\n");
783 ok(!wszPath[0], "Expected empty string\n");
785 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
786 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
787 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
790 result = SHGetPathFromIDListW(pidlEmpty, wszPath);
791 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
793 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
795 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
796 hr = SHGetDesktopFolder(&psfDesktop);
797 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
798 if (FAILED(hr)) return;
800 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
801 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
803 IShellFolder_Release(psfDesktop);
807 SetLastError(0xdeadbeef);
810 result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
811 ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
812 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %u\n", GetLastError());
813 ok (!wszPath[0], "Expected empty path\n");
815 IShellFolder_Release(psfDesktop);
819 IMalloc_Free(ppM, pidlMyComputer);
821 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
822 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
824 IShellFolder_Release(psfDesktop);
827 PathAddBackslashW(wszFileName);
828 lstrcatW(wszFileName, wszTestFile);
829 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
830 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
831 if (hTestFile == INVALID_HANDLE_VALUE) {
832 IShellFolder_Release(psfDesktop);
835 CloseHandle(hTestFile);
837 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
838 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
840 IShellFolder_Release(psfDesktop);
841 DeleteFileW(wszFileName);
842 IMalloc_Free(ppM, pidlTestFile);
846 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
847 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
848 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
849 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
850 IShellFolder_Release(psfDesktop);
851 DeleteFileW(wszFileName);
853 IMalloc_Free(ppM, pidlTestFile);
858 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
859 ok(0 == lstrcmpW(wszFileName, wszPath),
860 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
861 "returned incorrect path for file placed on desktop\n");
864 result = SHGetPathFromIDListW(pidlTestFile, wszPath);
865 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
866 IMalloc_Free(ppM, pidlTestFile);
868 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
871 /* Test if we can get the path from the start menu "program files" PIDL. */
872 hShell32 = GetModuleHandleA("shell32");
873 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
875 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
876 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
878 SetLastError(0xdeadbeef);
879 result = SHGetPathFromIDListW(pidlPrograms, wszPath);
880 IMalloc_Free(ppM, pidlPrograms);
881 ok(result, "SHGetPathFromIDList failed\n");
884 static void test_EnumObjects_and_CompareIDs(void)
887 IShellFolder *IDesktopFolder, *testIShellFolder;
888 char cCurrDirA [MAX_PATH] = {0};
889 WCHAR cCurrDirW [MAX_PATH];
890 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
894 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
895 len = lstrlenA(cCurrDirA);
898 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
901 if(cCurrDirA[len-1] == '\\')
902 cCurrDirA[len-1] = 0;
904 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
905 lstrcatW(cCurrDirW, cTestDirW);
907 hr = SHGetDesktopFolder(&IDesktopFolder);
908 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
910 CreateFilesFolders();
912 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
913 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
915 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
916 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
918 test_EnumObjects(testIShellFolder);
920 IShellFolder_Release(testIShellFolder);
924 IMalloc_Free(ppM, newPIDL);
926 IShellFolder_Release(IDesktopFolder);
929 /* A simple implementation of an IPropertyBag, which returns fixed values for
930 * 'Target' and 'Attributes' properties.
932 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
938 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
941 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
942 return E_NOINTERFACE;
945 IPropertyBag_AddRef(iface);
949 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
953 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
957 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
958 VARIANT *pVar, IErrorLog *pErrorLog)
960 static const WCHAR wszTargetSpecialFolder[] = {
961 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
962 static const WCHAR wszTarget[] = {
963 'T','a','r','g','e','t',0 };
964 static const WCHAR wszAttributes[] = {
965 'A','t','t','r','i','b','u','t','e','s',0 };
966 static const WCHAR wszResolveLinkFlags[] = {
967 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
969 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
970 ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
974 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
976 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
980 if (!lstrcmpW(pszPropName, wszTarget)) {
981 WCHAR wszPath[MAX_PATH];
984 ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
985 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
987 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
988 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
989 if (!result) return E_INVALIDARG;
991 V_BSTR(pVar) = SysAllocString(wszPath);
995 if (!lstrcmpW(pszPropName, wszAttributes)) {
996 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
997 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
998 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
999 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1003 ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
1004 return E_INVALIDARG;
1007 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1010 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1014 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1015 InitPropertyBag_IPropertyBag_QueryInterface,
1016 InitPropertyBag_IPropertyBag_AddRef,
1017 InitPropertyBag_IPropertyBag_Release,
1018 InitPropertyBag_IPropertyBag_Read,
1019 InitPropertyBag_IPropertyBag_Write
1022 static struct IPropertyBag InitPropertyBag = {
1023 &InitPropertyBag_IPropertyBagVtbl
1026 static void test_FolderShortcut(void) {
1027 IPersistPropertyBag *pPersistPropertyBag;
1028 IShellFolder *pShellFolder, *pDesktopFolder;
1029 IPersistFolder3 *pPersistFolder3;
1032 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1035 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1037 WCHAR wszWineTestFolder[] = {
1038 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1039 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1040 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1041 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1042 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1043 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1044 'N','a','m','e','S','p','a','c','e','\\',
1045 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1046 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1048 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1049 static const GUID CLSID_UnixDosFolder =
1050 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1052 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) return;
1054 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1055 * via their IPersistPropertyBag interface. And that the target folder
1056 * is taken from the IPropertyBag's 'Target' property.
1058 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1059 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1060 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
1061 if (FAILED(hr)) return;
1063 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1064 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
1066 IPersistPropertyBag_Release(pPersistPropertyBag);
1070 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1071 (LPVOID*)&pShellFolder);
1072 IPersistPropertyBag_Release(pPersistPropertyBag);
1073 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1074 if (FAILED(hr)) return;
1076 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1077 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1079 IShellFolder_Release(pShellFolder);
1083 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1084 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1085 if (!result) return;
1087 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1088 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1090 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1091 IShellFolder_Release(pShellFolder);
1092 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
1093 if (FAILED(hr)) return;
1095 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1096 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1097 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1099 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1100 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1101 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1103 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1104 * shell namespace. The target folder, read from the property bag above, remains untouched.
1105 * The following tests show this: The itemidlist for some imaginary shellfolder object
1106 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1107 * itemidlist, but GetDisplayNameOf still returns the path from above.
1109 hr = SHGetDesktopFolder(&pDesktopFolder);
1110 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
1111 if (FAILED(hr)) return;
1113 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1114 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1115 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1116 RegCloseKey(hShellExtKey);
1117 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1118 &pidlWineTestFolder, NULL);
1119 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1120 IShellFolder_Release(pDesktopFolder);
1121 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1122 if (FAILED(hr)) return;
1124 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1125 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
1127 IPersistFolder3_Release(pPersistFolder3);
1128 pILFree(pidlWineTestFolder);
1132 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1133 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1134 ok(pILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1135 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1136 pILFree(pidlCurrentFolder);
1137 pILFree(pidlWineTestFolder);
1139 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1140 IPersistFolder3_Release(pPersistFolder3);
1141 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1142 if (FAILED(hr)) return;
1144 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1145 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1147 IShellFolder_Release(pShellFolder);
1151 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1152 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1154 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1155 * but ShellFSFolders. */
1156 PathAddBackslashW(wszDesktopPath);
1157 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1158 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1159 IShellFolder_Release(pShellFolder);
1163 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1164 &pidlSubFolder, NULL);
1165 RemoveDirectoryW(wszDesktopPath);
1166 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1168 IShellFolder_Release(pShellFolder);
1172 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1173 (LPVOID*)&pPersistFolder3);
1174 IShellFolder_Release(pShellFolder);
1175 pILFree(pidlSubFolder);
1176 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
1180 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1181 * a little bit and also allow CLSID_UnixDosFolder. */
1182 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1183 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1184 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1185 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1187 IPersistFolder3_Release(pPersistFolder3);
1190 #include "pshpack1.h"
1191 struct FileStructA {
1195 WORD uFileDate; /* In our current implementation this is */
1196 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1201 struct FileStructW {
1202 WORD cbLen; /* Length of this element. */
1203 BYTE abFooBar1[6]; /* Beyond any recognition. */
1204 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1205 WORD uTime; /* (this is currently speculation) */
1206 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1207 WORD uTime2; /* (this is currently speculation) */
1208 BYTE abFooBar2[4]; /* Beyond any recognition. */
1209 WCHAR wszName[1]; /* The long filename in unicode. */
1210 /* Just for documentation: Right after the unicode string: */
1211 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1212 * SHITEMID->cb == uOffset + cbLen */
1214 #include "poppack.h"
1216 static void test_ITEMIDLIST_format(void) {
1217 WCHAR wszPersonal[MAX_PATH];
1218 LPSHELLFOLDER psfDesktop, psfPersonal;
1219 LPITEMIDLIST pidlPersonal, pidlFile;
1223 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1224 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1227 if(!pSHGetSpecialFolderPathW) return;
1229 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1230 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1231 if (!bResult) return;
1233 bResult = SetCurrentDirectoryW(wszPersonal);
1234 ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1235 if (!bResult) return;
1237 hr = SHGetDesktopFolder(&psfDesktop);
1238 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
1239 if (FAILED(hr)) return;
1241 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1242 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
1244 IShellFolder_Release(psfDesktop);
1248 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1249 (LPVOID*)&psfPersonal);
1250 IShellFolder_Release(psfDesktop);
1251 pILFree(pidlPersonal);
1252 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
1253 if (FAILED(hr)) return;
1255 for (i=0; i<3; i++) {
1256 CHAR szFile[MAX_PATH];
1257 struct FileStructA *pFileStructA;
1260 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1262 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1263 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
1264 if (hFile == INVALID_HANDLE_VALUE) {
1265 IShellFolder_Release(psfPersonal);
1270 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1271 DeleteFileW(wszFile[i]);
1272 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
1274 IShellFolder_Release(psfPersonal);
1278 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1279 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1280 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1281 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1283 if (i < 2) /* First two file names are already in valid 8.3 format */
1284 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1286 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1287 * can't implement this correctly, since unix filesystems don't support
1288 * this nasty short/long filename stuff. So we'll probably stay with our
1289 * current habbit of storing the long filename here, which seems to work
1291 todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
1293 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1294 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0',
1295 "Alignment byte, where there shouldn't be!\n");
1297 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1298 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1299 "There should be an alignment byte, but isn't!\n");
1301 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1302 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1303 ok (cbOffset >= sizeof(struct FileStructA) &&
1304 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
1305 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1307 if (cbOffset >= sizeof(struct FileStructA) &&
1308 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1310 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1312 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1313 "FileStructW's offset and length should add up to the PIDL's length!\n");
1315 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1316 /* Since we just created the file, time of creation,
1317 * time of last access and time of last write access just be the same.
1318 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1319 * after the first run. I do remember something with NTFS keeping the creation time
1320 * if a file is deleted and then created again within a couple of seconds or so.
1321 * Might be the reason. */
1322 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1323 pFileStructA->uFileTime == pFileStructW->uTime,
1324 "Last write time should match creation time!\n");
1326 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1327 pFileStructA->uFileTime == pFileStructW->uTime2,
1328 "Last write time should match last access time!\n");
1330 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
1331 "The filename should be stored in unicode at this position!\n");
1339 START_TEST(shlfolder)
1341 init_function_pointers();
1342 /* if OleInitialize doesn't get called, ParseDisplayName returns
1343 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1344 OleInitialize(NULL);
1346 test_ParseDisplayName();
1347 test_BindToObject();
1348 test_EnumObjects_and_CompareIDs();
1349 test_GetDisplayName();
1350 test_GetAttributesOf();
1351 test_SHGetPathFromIDList();
1352 test_CallForAttributes();
1353 test_FolderShortcut();
1354 test_ITEMIDLIST_format();