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");
60 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
61 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
62 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
63 pILFree = (void*)GetProcAddress(hmod, (LPSTR)155);
64 pILIsEqual = (void*)GetProcAddress(hmod, (LPSTR)21);
67 hmod = GetModuleHandleA("shlwapi.dll");
70 pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
73 hr = SHGetMalloc(&ppM);
74 ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
77 static void test_ParseDisplayName(void)
80 IShellFolder *IDesktopFolder;
81 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
82 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
84 WCHAR cTestDirW [MAX_PATH] = {0};
88 hr = SHGetDesktopFolder(&IDesktopFolder);
89 if(hr != S_OK) return;
91 res = GetFileAttributesA(cNonExistDir1A);
92 if(res != INVALID_FILE_ATTRIBUTES) return;
94 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
95 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
96 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
97 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
98 "ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr);
100 res = GetFileAttributesA(cNonExistDir2A);
101 if(res != INVALID_FILE_ATTRIBUTES) return;
103 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
104 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
105 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
106 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
107 "ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
109 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
110 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
111 * out it doesn't. The magic seems to happen in the file dialogs, then. */
112 if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
114 bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
115 ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
116 if (!bRes) goto finished;
118 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
119 ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr);
120 if (FAILED(hr)) goto finished;
122 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31, "Last pidl should be of type "
123 "PT_FOLDER, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
124 IMalloc_Free(ppM, newPIDL);
127 IShellFolder_Release(IDesktopFolder);
130 /* creates a file with the specified name for tests */
131 static void CreateTestFile(const CHAR *name)
136 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
137 if (file != INVALID_HANDLE_VALUE)
139 WriteFile(file, name, strlen(name), &written, NULL);
140 WriteFile(file, "\n", strlen("\n"), &written, NULL);
146 /* initializes the tests */
147 static void CreateFilesFolders(void)
149 CreateDirectoryA(".\\testdir", NULL);
150 CreateDirectoryA(".\\testdir\\test.txt", NULL);
151 CreateTestFile (".\\testdir\\test1.txt ");
152 CreateTestFile (".\\testdir\\test2.txt ");
153 CreateTestFile (".\\testdir\\test3.txt ");
154 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
155 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
158 /* cleans after tests */
159 static void Cleanup(void)
161 DeleteFileA(".\\testdir\\test1.txt");
162 DeleteFileA(".\\testdir\\test2.txt");
163 DeleteFileA(".\\testdir\\test3.txt");
164 RemoveDirectoryA(".\\testdir\\test.txt");
165 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
166 RemoveDirectoryA(".\\testdir\\testdir2");
167 RemoveDirectoryA(".\\testdir");
172 static void test_EnumObjects(IShellFolder *iFolder)
174 IEnumIDList *iEnumList;
175 LPITEMIDLIST newPIDL, idlArr[10];
180 static const WORD iResults [5][5] =
189 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
190 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
191 static const ULONG attrs[5] =
193 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
194 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
195 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
196 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
197 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
200 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
201 ok(hr == S_OK, "EnumObjects failed %08x\n", hr);
203 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
204 * the filesystem shellfolders return S_OK even if less than 'celt' items are
205 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
206 * only ever returns a single entry per call. */
207 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
209 ok (i == 5, "i: %d\n", i);
211 hr = IEnumIDList_Release(iEnumList);
212 ok(hr == S_OK, "IEnumIDList_Release failed %08x\n", hr);
214 /* Sort them first in case of wrong order from system */
215 for (i=0;i<5;i++) for (j=0;j<5;j++)
216 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
219 idlArr[i] = idlArr[j];
223 for (i=0;i<5;i++) for (j=0;j<5;j++)
225 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
226 ok(hr == iResults[i][j], "Got %x expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
230 for (i = 0; i < 5; i++)
233 /* Native returns all flags no matter what we ask for */
234 flags = SFGAO_CANCOPY;
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]);
240 flags = SFGAO_testfor;
241 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
242 flags &= SFGAO_testfor;
243 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
244 ok(flags == attrs[i], "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
248 IMalloc_Free(ppM, idlArr[i]);
251 static void test_BindToObject(void)
255 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
256 SHITEMID emptyitem = { 0, { 0 } };
257 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
258 WCHAR wszSystemDir[MAX_PATH];
259 char szSystemDir[MAX_PATH];
260 WCHAR wszMyComputer[] = {
261 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
262 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
264 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
265 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
267 hr = SHGetDesktopFolder(&psfDesktop);
268 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
269 if (FAILED(hr)) return;
271 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
272 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
274 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
275 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
277 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
278 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
280 IShellFolder_Release(psfDesktop);
284 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
285 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
286 IShellFolder_Release(psfDesktop);
287 IMalloc_Free(ppM, pidlMyComputer);
288 if (FAILED(hr)) return;
290 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
291 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
294 /* this call segfaults on 98SE */
295 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
296 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
299 cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
300 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
301 if (cChars == 0 || cChars >= MAX_PATH) {
302 IShellFolder_Release(psfMyComputer);
305 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
307 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
308 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr);
310 IShellFolder_Release(psfMyComputer);
314 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
315 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr);
316 IShellFolder_Release(psfMyComputer);
317 IMalloc_Free(ppM, pidlSystemDir);
318 if (FAILED(hr)) return;
320 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
321 ok (hr == E_INVALIDARG,
322 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
325 /* this call segfaults on 98SE */
326 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
327 ok (hr == E_INVALIDARG,
328 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
331 IShellFolder_Release(psfSystemDir);
334 static void test_GetDisplayName(void)
339 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
340 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
343 LPSHELLFOLDER psfDesktop, psfPersonal;
345 SHITEMID emptyitem = { 0, { 0 } };
346 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
347 LPCITEMIDLIST pidlLast;
348 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
349 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
351 /* I'm trying to figure if there is a functional difference between calling
352 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
353 * binding to the shellfolder. One thing I thought of was that perhaps
354 * SHGetPathFromIDList would be able to get the path to a file, which does
355 * not exist anymore, while the other method would'nt. It turns out there's
356 * no functional difference in this respect.
359 if(!pSHGetSpecialFolderPathW) return;
361 /* First creating a directory in MyDocuments and a file in this directory. */
362 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
363 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
366 PathAddBackslashW(wszTestDir);
367 lstrcatW(wszTestDir, wszDirName);
368 /* Use ANSI file functions so this works on Windows 9x */
369 WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
370 CreateDirectoryA(szTestDir, NULL);
371 attr=GetFileAttributesA(szTestDir);
372 if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
374 ok(0, "unable to create the '%s' directory\n", szTestDir);
378 lstrcpyW(wszTestFile, wszTestDir);
379 PathAddBackslashW(wszTestFile);
380 lstrcatW(wszTestFile, wszFileName);
381 WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
383 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
384 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
385 if (hTestFile == INVALID_HANDLE_VALUE) return;
386 CloseHandle(hTestFile);
388 /* Getting an itemidlist for the file. */
389 hr = SHGetDesktopFolder(&psfDesktop);
390 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
391 if (FAILED(hr)) return;
393 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
394 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
396 IShellFolder_Release(psfDesktop);
400 /* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
401 pidlLast = pILFindLastID(pidlTestFile);
402 ok(pidlLast->mkid.cb >=76, "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
403 if (pidlLast->mkid.cb >= 76) {
404 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
405 "WinXP stores the filename as a wchar-string at this position!\n");
408 /* It seems as if we cannot bind to regular files on windows, but only directories.
410 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
411 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08x\n", hr); }
413 IShellFolder_Release(psfFile);
416 /* Some tests for IShellFolder::SetNameOf */
417 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
418 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
420 /* It's ok to use this fixed path. Call will fail anyway. */
421 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
422 LPITEMIDLIST pidlNew;
424 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
425 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
426 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
427 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
428 "pidl returned from SetNameOf should be simple!\n");
430 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
431 * is implemented on top of SHFileOperation in WinXP. */
432 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
433 SHGDN_FORPARSING, NULL);
434 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
436 /* Rename the file back to its original name. SetNameOf ignores the fact, that the
437 * SHGDN flags specify an absolute path. */
438 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
439 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
442 IShellFolder_Release(psfPersonal);
445 /* Deleting the file and the directory */
446 DeleteFileA(szTestFile);
447 RemoveDirectoryA(szTestDir);
449 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
450 result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
451 ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
452 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
454 if(!pSHBindToParent) return;
456 /* SHBindToParent fails, if called with a NULL PIDL. */
457 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
458 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
460 /* But it succeeds with an empty PIDL. */
461 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
462 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
463 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
465 IShellFolder_Release(psfPersonal);
467 /* Binding to the folder and querying the display name of the file also works. */
468 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
469 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
471 IShellFolder_Release(psfDesktop);
475 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
476 * pidlTestFile (In accordance with MSDN). */
477 ok (pILFindLastID(pidlTestFile) == pidlLast,
478 "SHBindToParent doesn't return the last id of the pidl param!\n");
480 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
481 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
483 IShellFolder_Release(psfDesktop);
484 IShellFolder_Release(psfPersonal);
490 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
491 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
492 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
495 IShellFolder_Release(psfDesktop);
496 IShellFolder_Release(psfPersonal);
499 static void test_CallForAttributes(void)
505 LPSHELLFOLDER psfDesktop;
506 LPITEMIDLIST pidlMyDocuments;
507 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
508 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
509 static const WCHAR wszCallForAttributes[] = {
510 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
511 static const WCHAR wszMyDocumentsKey[] = {
512 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
513 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
514 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
515 WCHAR wszMyDocuments[] = {
516 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
517 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
519 /* For the root of a namespace extension, the attributes are not queried by binding
520 * to the object and calling GetAttributesOf. Instead, the attributes are read from
521 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
523 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
524 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
525 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
526 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
528 hr = SHGetDesktopFolder(&psfDesktop);
529 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
530 if (FAILED(hr)) return;
532 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
533 &pidlMyDocuments, NULL);
535 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
537 IShellFolder_Release(psfDesktop);
541 dwAttributes = 0xffffffff;
542 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
543 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
544 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
546 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
547 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
548 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
549 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
551 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
552 * key. So the test will return at this point, if run on wine.
554 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
555 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
556 if (lResult != ERROR_SUCCESS) {
557 IMalloc_Free(ppM, pidlMyDocuments);
558 IShellFolder_Release(psfDesktop);
562 /* Query MyDocuments' Attributes value, to be able to restore it later. */
563 dwSize = sizeof(DWORD);
564 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
565 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
566 if (lResult != ERROR_SUCCESS) {
568 IMalloc_Free(ppM, pidlMyDocuments);
569 IShellFolder_Release(psfDesktop);
573 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
574 dwSize = sizeof(DWORD);
575 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
576 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
577 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
578 if (lResult != ERROR_SUCCESS) {
580 IMalloc_Free(ppM, pidlMyDocuments);
581 IShellFolder_Release(psfDesktop);
585 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
586 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
587 * SFGAO_FILESYSTEM attributes. */
588 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
589 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
590 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
591 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
592 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
594 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
595 * GetAttributesOf. It seems that once there is a single attribute queried, for which
596 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
597 * the flags in Attributes are ignored.
599 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
600 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
601 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
602 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
604 ok (dwAttributes == SFGAO_FILESYSTEM,
605 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n",
608 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
609 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
610 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
611 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
613 IMalloc_Free(ppM, pidlMyDocuments);
614 IShellFolder_Release(psfDesktop);
617 static void test_GetAttributesOf(void)
620 LPSHELLFOLDER psfDesktop, psfMyComputer;
621 SHITEMID emptyitem = { 0, { 0 } };
622 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
623 LPITEMIDLIST pidlMyComputer;
625 static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
626 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
627 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
628 static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
629 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
630 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
631 WCHAR wszMyComputer[] = {
632 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
633 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
634 char cCurrDirA [MAX_PATH] = {0};
635 WCHAR cCurrDirW [MAX_PATH];
636 static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
637 static const WCHAR cBackSlash[] = {'\\',0};
638 IShellFolder *IDesktopFolder, *testIShellFolder;
642 hr = SHGetDesktopFolder(&psfDesktop);
643 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
644 if (FAILED(hr)) return;
646 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
647 dwFlags = 0xffffffff;
648 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
649 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
650 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
651 dwFlags, dwDesktopFlags);
653 /* .. or with no itemidlist at all. */
654 dwFlags = 0xffffffff;
655 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
656 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
657 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
658 dwFlags, dwDesktopFlags);
660 /* Testing the attributes of the MyComputer shellfolder */
661 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
662 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
664 IShellFolder_Release(psfDesktop);
668 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
669 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
670 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
671 * should create a link to the original data". You can't create links on MyComputer on
672 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
673 * depends on this bug, we probably shouldn't imitate it.
675 dwFlags = 0xffffffff;
676 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
677 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
678 ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
679 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags);
681 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
682 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
683 IShellFolder_Release(psfDesktop);
684 IMalloc_Free(ppM, pidlMyComputer);
685 if (FAILED(hr)) return;
687 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
688 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr); }
690 dwFlags = 0xffffffff;
691 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
692 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
693 todo_wine { ok (dwFlags == dwMyComputerFlags,
694 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags); }
696 IShellFolder_Release(psfMyComputer);
698 /* create test directory */
699 CreateFilesFolders();
701 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
702 len = lstrlenA(cCurrDirA);
705 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
708 if(cCurrDirA[len-1] == '\\')
709 cCurrDirA[len-1] = 0;
711 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
713 hr = SHGetDesktopFolder(&IDesktopFolder);
714 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
716 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
717 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
719 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
720 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
722 IMalloc_Free(ppM, newPIDL);
724 /* get relative PIDL */
725 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
726 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
728 /* test the shell attributes of the test directory using the relative PIDL */
729 dwFlags = SFGAO_FOLDER;
730 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
731 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
732 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
735 IMalloc_Free(ppM, newPIDL);
737 /* append testdirectory name to path */
738 lstrcatW(cCurrDirW, cBackSlash);
739 lstrcatW(cCurrDirW, cTestDirW);
741 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
742 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
744 /* test the shell attributes of the test directory using the absolute PIDL */
745 dwFlags = SFGAO_FOLDER;
746 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
747 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
748 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
751 IMalloc_Free(ppM, newPIDL);
753 IShellFolder_Release(testIShellFolder);
757 IShellFolder_Release(IDesktopFolder);
760 static void test_SHGetPathFromIDList(void)
762 SHITEMID emptyitem = { 0, { 0 } };
763 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
764 LPITEMIDLIST pidlMyComputer;
765 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
768 LPSHELLFOLDER psfDesktop;
769 WCHAR wszMyComputer[] = {
770 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
771 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
772 WCHAR wszFileName[MAX_PATH];
773 LPITEMIDLIST pidlTestFile;
776 static WCHAR wszTestFile[] = {
777 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
778 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
780 LPITEMIDLIST pidlPrograms;
782 if(!pSHGetSpecialFolderPathW) return;
784 /* Calling SHGetPathFromIDList with no pidl should return the empty string */
787 result = SHGetPathFromIDListW(NULL, wszPath);
788 ok(!result, "Expected failure\n");
789 ok(!wszPath[0], "Expected empty string\n");
791 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
792 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
793 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
796 result = SHGetPathFromIDListW(pidlEmpty, wszPath);
797 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
799 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
801 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
802 hr = SHGetDesktopFolder(&psfDesktop);
803 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
804 if (FAILED(hr)) return;
806 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
807 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
809 IShellFolder_Release(psfDesktop);
813 SetLastError(0xdeadbeef);
816 result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
817 ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
818 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %u\n", GetLastError());
819 ok (!wszPath[0], "Expected empty path\n");
821 IShellFolder_Release(psfDesktop);
825 IMalloc_Free(ppM, pidlMyComputer);
827 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
828 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
830 IShellFolder_Release(psfDesktop);
833 PathAddBackslashW(wszFileName);
834 lstrcatW(wszFileName, wszTestFile);
835 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
836 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
837 if (hTestFile == INVALID_HANDLE_VALUE) {
838 IShellFolder_Release(psfDesktop);
841 CloseHandle(hTestFile);
843 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
844 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
846 IShellFolder_Release(psfDesktop);
847 DeleteFileW(wszFileName);
848 IMalloc_Free(ppM, pidlTestFile);
852 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
853 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
854 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
855 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
856 IShellFolder_Release(psfDesktop);
857 DeleteFileW(wszFileName);
859 IMalloc_Free(ppM, pidlTestFile);
864 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
865 ok(0 == lstrcmpW(wszFileName, wszPath),
866 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
867 "returned incorrect path for file placed on desktop\n");
870 result = SHGetPathFromIDListW(pidlTestFile, wszPath);
871 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
872 IMalloc_Free(ppM, pidlTestFile);
874 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
877 /* Test if we can get the path from the start menu "program files" PIDL. */
878 hShell32 = GetModuleHandleA("shell32");
879 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
881 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
882 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
884 SetLastError(0xdeadbeef);
885 result = SHGetPathFromIDListW(pidlPrograms, wszPath);
886 IMalloc_Free(ppM, pidlPrograms);
887 ok(result, "SHGetPathFromIDList failed\n");
890 static void test_EnumObjects_and_CompareIDs(void)
893 IShellFolder *IDesktopFolder, *testIShellFolder;
894 char cCurrDirA [MAX_PATH] = {0};
895 WCHAR cCurrDirW [MAX_PATH];
896 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
900 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
901 len = lstrlenA(cCurrDirA);
904 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
907 if(cCurrDirA[len-1] == '\\')
908 cCurrDirA[len-1] = 0;
910 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
911 lstrcatW(cCurrDirW, cTestDirW);
913 hr = SHGetDesktopFolder(&IDesktopFolder);
914 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
916 CreateFilesFolders();
918 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
919 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
921 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
922 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
924 test_EnumObjects(testIShellFolder);
926 IShellFolder_Release(testIShellFolder);
930 IMalloc_Free(ppM, newPIDL);
932 IShellFolder_Release(IDesktopFolder);
935 /* A simple implementation of an IPropertyBag, which returns fixed values for
936 * 'Target' and 'Attributes' properties.
938 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
944 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
947 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
948 return E_NOINTERFACE;
951 IPropertyBag_AddRef(iface);
955 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
959 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
963 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
964 VARIANT *pVar, IErrorLog *pErrorLog)
966 static const WCHAR wszTargetSpecialFolder[] = {
967 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
968 static const WCHAR wszTarget[] = {
969 'T','a','r','g','e','t',0 };
970 static const WCHAR wszAttributes[] = {
971 'A','t','t','r','i','b','u','t','e','s',0 };
972 static const WCHAR wszResolveLinkFlags[] = {
973 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
975 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
976 ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
980 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
982 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
986 if (!lstrcmpW(pszPropName, wszTarget)) {
987 WCHAR wszPath[MAX_PATH];
990 ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
991 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
993 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
994 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
995 if (!result) return E_INVALIDARG;
997 V_BSTR(pVar) = SysAllocString(wszPath);
1001 if (!lstrcmpW(pszPropName, wszAttributes)) {
1002 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
1003 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
1004 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
1005 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1009 ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
1010 return E_INVALIDARG;
1013 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1016 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1020 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1021 InitPropertyBag_IPropertyBag_QueryInterface,
1022 InitPropertyBag_IPropertyBag_AddRef,
1023 InitPropertyBag_IPropertyBag_Release,
1024 InitPropertyBag_IPropertyBag_Read,
1025 InitPropertyBag_IPropertyBag_Write
1028 static struct IPropertyBag InitPropertyBag = {
1029 &InitPropertyBag_IPropertyBagVtbl
1032 static void test_FolderShortcut(void) {
1033 IPersistPropertyBag *pPersistPropertyBag;
1034 IShellFolder *pShellFolder, *pDesktopFolder;
1035 IPersistFolder3 *pPersistFolder3;
1038 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1041 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1043 WCHAR wszWineTestFolder[] = {
1044 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1045 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1046 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1047 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1048 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1049 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1050 'N','a','m','e','S','p','a','c','e','\\',
1051 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1052 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1054 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1055 static const GUID CLSID_UnixDosFolder =
1056 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1058 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) return;
1060 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1061 * via their IPersistPropertyBag interface. And that the target folder
1062 * is taken from the IPropertyBag's 'Target' property.
1064 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1065 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1066 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
1067 if (FAILED(hr)) return;
1069 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1070 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
1072 IPersistPropertyBag_Release(pPersistPropertyBag);
1076 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1077 (LPVOID*)&pShellFolder);
1078 IPersistPropertyBag_Release(pPersistPropertyBag);
1079 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1080 if (FAILED(hr)) return;
1082 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1083 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1085 IShellFolder_Release(pShellFolder);
1089 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1090 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1091 if (!result) return;
1093 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1094 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1096 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1097 IShellFolder_Release(pShellFolder);
1098 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
1099 if (FAILED(hr)) return;
1101 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1102 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1103 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1105 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1106 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1107 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1109 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1110 * shell namespace. The target folder, read from the property bag above, remains untouched.
1111 * The following tests show this: The itemidlist for some imaginary shellfolder object
1112 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1113 * itemidlist, but GetDisplayNameOf still returns the path from above.
1115 hr = SHGetDesktopFolder(&pDesktopFolder);
1116 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
1117 if (FAILED(hr)) return;
1119 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1120 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1121 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1122 RegCloseKey(hShellExtKey);
1123 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1124 &pidlWineTestFolder, NULL);
1125 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1126 IShellFolder_Release(pDesktopFolder);
1127 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1128 if (FAILED(hr)) return;
1130 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1131 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
1133 IPersistFolder3_Release(pPersistFolder3);
1134 pILFree(pidlWineTestFolder);
1138 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1139 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1140 ok(pILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1141 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1142 pILFree(pidlCurrentFolder);
1143 pILFree(pidlWineTestFolder);
1145 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1146 IPersistFolder3_Release(pPersistFolder3);
1147 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1148 if (FAILED(hr)) return;
1150 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1151 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1153 IShellFolder_Release(pShellFolder);
1157 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1158 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1160 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1161 * but ShellFSFolders. */
1162 PathAddBackslashW(wszDesktopPath);
1163 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1164 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1165 IShellFolder_Release(pShellFolder);
1169 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1170 &pidlSubFolder, NULL);
1171 RemoveDirectoryW(wszDesktopPath);
1172 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1174 IShellFolder_Release(pShellFolder);
1178 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1179 (LPVOID*)&pPersistFolder3);
1180 IShellFolder_Release(pShellFolder);
1181 pILFree(pidlSubFolder);
1182 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
1186 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1187 * a little bit and also allow CLSID_UnixDosFolder. */
1188 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1189 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1190 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1191 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1193 IPersistFolder3_Release(pPersistFolder3);
1196 #include "pshpack1.h"
1197 struct FileStructA {
1201 WORD uFileDate; /* In our current implementation this is */
1202 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1207 struct FileStructW {
1208 WORD cbLen; /* Length of this element. */
1209 BYTE abFooBar1[6]; /* Beyond any recognition. */
1210 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1211 WORD uTime; /* (this is currently speculation) */
1212 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1213 WORD uTime2; /* (this is currently speculation) */
1214 BYTE abFooBar2[4]; /* Beyond any recognition. */
1215 WCHAR wszName[1]; /* The long filename in unicode. */
1216 /* Just for documentation: Right after the unicode string: */
1217 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1218 * SHITEMID->cb == uOffset + cbLen */
1220 #include "poppack.h"
1222 static void test_ITEMIDLIST_format(void) {
1223 WCHAR wszPersonal[MAX_PATH];
1224 LPSHELLFOLDER psfDesktop, psfPersonal;
1225 LPITEMIDLIST pidlPersonal, pidlFile;
1229 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1230 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1233 if(!pSHGetSpecialFolderPathW) return;
1235 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1236 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1237 if (!bResult) return;
1239 bResult = SetCurrentDirectoryW(wszPersonal);
1240 ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1241 if (!bResult) return;
1243 hr = SHGetDesktopFolder(&psfDesktop);
1244 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
1245 if (FAILED(hr)) return;
1247 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1248 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
1250 IShellFolder_Release(psfDesktop);
1254 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1255 (LPVOID*)&psfPersonal);
1256 IShellFolder_Release(psfDesktop);
1257 pILFree(pidlPersonal);
1258 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
1259 if (FAILED(hr)) return;
1261 for (i=0; i<3; i++) {
1262 CHAR szFile[MAX_PATH];
1263 struct FileStructA *pFileStructA;
1266 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1268 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1269 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
1270 if (hFile == INVALID_HANDLE_VALUE) {
1271 IShellFolder_Release(psfPersonal);
1276 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1277 DeleteFileW(wszFile[i]);
1278 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
1280 IShellFolder_Release(psfPersonal);
1284 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1285 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1286 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1287 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1289 if (i < 2) /* First two file names are already in valid 8.3 format */
1290 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1292 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1293 * can't implement this correctly, since unix filesystems don't support
1294 * this nasty short/long filename stuff. So we'll probably stay with our
1295 * current habbit of storing the long filename here, which seems to work
1297 todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
1299 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1300 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0',
1301 "Alignment byte, where there shouldn't be!\n");
1303 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1304 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1305 "There should be an alignment byte, but isn't!\n");
1307 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1308 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1309 ok (cbOffset >= sizeof(struct FileStructA) &&
1310 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
1311 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1313 if (cbOffset >= sizeof(struct FileStructA) &&
1314 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1316 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1318 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1319 "FileStructW's offset and length should add up to the PIDL's length!\n");
1321 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1322 /* Since we just created the file, time of creation,
1323 * time of last access and time of last write access just be the same.
1324 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1325 * after the first run. I do remember something with NTFS keeping the creation time
1326 * if a file is deleted and then created again within a couple of seconds or so.
1327 * Might be the reason. */
1328 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1329 pFileStructA->uFileTime == pFileStructW->uTime,
1330 "Last write time should match creation time!\n");
1332 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1333 pFileStructA->uFileTime == pFileStructW->uTime2,
1334 "Last write time should match last access time!\n");
1336 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
1337 "The filename should be stored in unicode at this position!\n");
1345 START_TEST(shlfolder)
1347 init_function_pointers();
1348 /* if OleInitialize doesn't get called, ParseDisplayName returns
1349 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1350 OleInitialize(NULL);
1352 test_ParseDisplayName();
1353 test_BindToObject();
1354 test_EnumObjects_and_CompareIDs();
1355 test_GetDisplayName();
1356 test_GetAttributesOf();
1357 test_SHGetPathFromIDList();
1358 test_CallForAttributes();
1359 test_FolderShortcut();
1360 test_ITEMIDLIST_format();