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 HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
47 static HRESULT (WINAPI *pSHGetFolderPathAndSubDirA)(HWND, int, HANDLE, DWORD, LPCSTR, LPSTR);
48 static BOOL (WINAPI *pSHGetPathFromIDListW)(LPCITEMIDLIST,LPWSTR);
49 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
50 static BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
51 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
52 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
53 static void (WINAPI *pILFree)(LPITEMIDLIST);
54 static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
56 static void init_function_pointers(void)
61 hmod = GetModuleHandleA("shell32.dll");
62 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
63 pSHGetFolderPathA = (void*)GetProcAddress(hmod, "SHGetFolderPathA");
64 pSHGetFolderPathAndSubDirA = (void*)GetProcAddress(hmod, "SHGetFolderPathAndSubDirA");
65 pSHGetPathFromIDListW = (void*)GetProcAddress(hmod, "SHGetPathFromIDListW");
66 pSHGetSpecialFolderPathA = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathA");
67 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
68 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
69 pILFree = (void*)GetProcAddress(hmod, (LPSTR)155);
70 pILIsEqual = (void*)GetProcAddress(hmod, (LPSTR)21);
72 hmod = GetModuleHandleA("shlwapi.dll");
73 pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
75 hr = SHGetMalloc(&ppM);
76 ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
79 static void test_ParseDisplayName(void)
82 IShellFolder *IDesktopFolder;
83 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
84 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
86 WCHAR cTestDirW [MAX_PATH] = {0};
90 hr = SHGetDesktopFolder(&IDesktopFolder);
91 if(hr != S_OK) return;
93 res = GetFileAttributesA(cNonExistDir1A);
94 if(res != INVALID_FILE_ATTRIBUTES) return;
96 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
97 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
98 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
99 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
100 "ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr);
102 res = GetFileAttributesA(cNonExistDir2A);
103 if(res != INVALID_FILE_ATTRIBUTES) return;
105 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
106 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
107 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
108 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
109 "ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
111 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
112 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
113 * out it doesn't. The magic seems to happen in the file dialogs, then. */
114 if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
116 bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
117 ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
118 if (!bRes) goto finished;
120 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
121 ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr);
122 if (FAILED(hr)) goto finished;
124 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31, "Last pidl should be of type "
125 "PT_FOLDER, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
126 IMalloc_Free(ppM, newPIDL);
129 IShellFolder_Release(IDesktopFolder);
132 /* creates a file with the specified name for tests */
133 static void CreateTestFile(const CHAR *name)
138 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
139 if (file != INVALID_HANDLE_VALUE)
141 WriteFile(file, name, strlen(name), &written, NULL);
142 WriteFile(file, "\n", strlen("\n"), &written, NULL);
148 /* initializes the tests */
149 static void CreateFilesFolders(void)
151 CreateDirectoryA(".\\testdir", NULL);
152 CreateDirectoryA(".\\testdir\\test.txt", NULL);
153 CreateTestFile (".\\testdir\\test1.txt ");
154 CreateTestFile (".\\testdir\\test2.txt ");
155 CreateTestFile (".\\testdir\\test3.txt ");
156 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
157 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
160 /* cleans after tests */
161 static void Cleanup(void)
163 DeleteFileA(".\\testdir\\test1.txt");
164 DeleteFileA(".\\testdir\\test2.txt");
165 DeleteFileA(".\\testdir\\test3.txt");
166 RemoveDirectoryA(".\\testdir\\test.txt");
167 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
168 RemoveDirectoryA(".\\testdir\\testdir2");
169 RemoveDirectoryA(".\\testdir");
174 static void test_EnumObjects(IShellFolder *iFolder)
176 IEnumIDList *iEnumList;
177 LPITEMIDLIST newPIDL, idlArr[10];
182 static const WORD iResults [5][5] =
191 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
192 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
193 static const ULONG attrs[5] =
195 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
196 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
197 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
198 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
199 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
202 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
203 ok(hr == S_OK, "EnumObjects failed %08x\n", hr);
205 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
206 * the filesystem shellfolders return S_OK even if less than 'celt' items are
207 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
208 * only ever returns a single entry per call. */
209 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
211 ok (i == 5, "i: %d\n", i);
213 hr = IEnumIDList_Release(iEnumList);
214 ok(hr == S_OK, "IEnumIDList_Release failed %08x\n", hr);
216 /* Sort them first in case of wrong order from system */
217 for (i=0;i<5;i++) for (j=0;j<5;j++)
218 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
221 idlArr[i] = idlArr[j];
225 for (i=0;i<5;i++) for (j=0;j<5;j++)
227 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
228 ok(hr == iResults[i][j], "Got %x expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
232 for (i = 0; i < 5; i++)
235 /* Native returns all flags no matter what we ask for */
236 flags = SFGAO_CANCOPY;
237 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
238 flags &= SFGAO_testfor;
239 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
240 ok(flags == (attrs[i]), "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
242 flags = SFGAO_testfor;
243 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
244 flags &= SFGAO_testfor;
245 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
246 ok(flags == attrs[i], "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
250 IMalloc_Free(ppM, idlArr[i]);
253 static void test_BindToObject(void)
257 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
258 SHITEMID emptyitem = { 0, { 0 } };
259 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
260 WCHAR wszSystemDir[MAX_PATH];
261 char szSystemDir[MAX_PATH];
262 WCHAR wszMyComputer[] = {
263 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
264 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
266 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
267 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
269 hr = SHGetDesktopFolder(&psfDesktop);
270 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
271 if (FAILED(hr)) return;
273 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
274 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
276 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
277 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
279 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
280 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
282 IShellFolder_Release(psfDesktop);
286 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
287 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
288 IShellFolder_Release(psfDesktop);
289 IMalloc_Free(ppM, pidlMyComputer);
290 if (FAILED(hr)) return;
292 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
293 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
296 /* this call segfaults on 98SE */
297 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
298 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
301 cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
302 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
303 if (cChars == 0 || cChars >= MAX_PATH) {
304 IShellFolder_Release(psfMyComputer);
307 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
309 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
310 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr);
312 IShellFolder_Release(psfMyComputer);
316 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
317 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr);
318 IShellFolder_Release(psfMyComputer);
319 IMalloc_Free(ppM, pidlSystemDir);
320 if (FAILED(hr)) return;
322 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
323 ok (hr == E_INVALIDARG,
324 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
327 /* this call segfaults on 98SE */
328 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
329 ok (hr == E_INVALIDARG,
330 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
333 IShellFolder_Release(psfSystemDir);
336 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
337 static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
341 if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
347 if (lpszPath[-1] != '\\')
356 static void test_GetDisplayName(void)
361 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH];
362 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
365 LPSHELLFOLDER psfDesktop, psfPersonal;
367 SHITEMID emptyitem = { 0, { 0 } };
368 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
369 LPCITEMIDLIST pidlLast;
370 static const CHAR szFileName[] = "winetest.foo";
371 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
372 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
374 /* I'm trying to figure if there is a functional difference between calling
375 * SHGetPathFromIDListW and calling GetDisplayNameOf(SHGDN_FORPARSING) after
376 * binding to the shellfolder. One thing I thought of was that perhaps
377 * SHGetPathFromIDListW would be able to get the path to a file, which does
378 * not exist anymore, while the other method wouldn't. It turns out there's
379 * no functional difference in this respect.
382 if(!pSHGetSpecialFolderPathA) {
383 win_skip("SHGetSpecialFolderPathA is not available\n");
387 /* First creating a directory in MyDocuments and a file in this directory. */
388 result = pSHGetSpecialFolderPathA(NULL, szTestDir, CSIDL_PERSONAL, FALSE);
389 ok(result, "SHGetSpecialFolderPathA failed! Last error: %u\n", GetLastError());
392 /* Use ANSI file functions so this works on Windows 9x */
393 lstrcatA(szTestDir, "\\winetest");
394 CreateDirectoryA(szTestDir, NULL);
395 attr=GetFileAttributesA(szTestDir);
396 if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
398 ok(0, "unable to create the '%s' directory\n", szTestDir);
402 lstrcpyA(szTestFile, szTestDir);
403 lstrcatA(szTestFile, "\\");
404 lstrcatA(szTestFile, szFileName);
405 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
406 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
407 if (hTestFile == INVALID_HANDLE_VALUE) return;
408 CloseHandle(hTestFile);
410 /* Getting an itemidlist for the file. */
411 hr = SHGetDesktopFolder(&psfDesktop);
412 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
413 if (FAILED(hr)) return;
415 MultiByteToWideChar(CP_ACP, 0, szTestFile, -1, wszTestFile, MAX_PATH);
417 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
418 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
420 IShellFolder_Release(psfDesktop);
424 pidlLast = pILFindLastID(pidlTestFile);
425 ok(pidlLast->mkid.cb >=76 ||
426 broken(pidlLast->mkid.cb == 28) || /* W2K */
427 broken(pidlLast->mkid.cb == 40), /* Win9x, WinME */
428 "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
429 if (pidlLast->mkid.cb >= 28) {
430 ok(!lstrcmpA((CHAR*)&pidlLast->mkid.abID[12], szFileName),
431 "Filename should be stored as ansi-string at this position!\n");
433 /* WinXP and up store the filenames as both ANSI and UNICODE in the pidls */
434 if (pidlLast->mkid.cb >= 76) {
435 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
436 "Filename should be stored as wchar-string at this position!\n");
439 /* It seems as if we cannot bind to regular files on windows, but only directories.
441 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
443 ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
444 broken(SUCCEEDED(hr)), /* Win9x, W2K */
447 IShellFolder_Release(psfFile);
452 win_skip("SHBindToParent is missing\n");
453 DeleteFileA(szTestFile);
454 RemoveDirectoryA(szTestDir);
458 /* Some tests for IShellFolder::SetNameOf */
459 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
460 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
462 /* It's ok to use this fixed path. Call will fail anyway. */
463 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
464 LPITEMIDLIST pidlNew;
466 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
467 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
468 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
471 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
472 "pidl returned from SetNameOf should be simple!\n");
474 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
475 * is implemented on top of SHFileOperation in WinXP. */
476 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
477 SHGDN_FORPARSING, NULL);
478 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
480 /* Rename the file back to its original name. SetNameOf ignores the fact, that the
481 * SHGDN flags specify an absolute path. */
482 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
483 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
488 IShellFolder_Release(psfPersonal);
491 /* Deleting the file and the directory */
492 DeleteFileA(szTestFile);
493 RemoveDirectoryA(szTestDir);
495 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
496 if (pSHGetPathFromIDListW)
498 result = pSHGetPathFromIDListW(pidlTestFile, wszTestFile2);
499 ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
500 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
503 /* SHBindToParent fails, if called with a NULL PIDL. */
504 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
505 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
507 /* But it succeeds with an empty PIDL. */
508 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
509 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
510 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
512 IShellFolder_Release(psfPersonal);
514 /* Binding to the folder and querying the display name of the file also works. */
515 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
516 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
518 IShellFolder_Release(psfDesktop);
522 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
523 * pidlTestFile (In accordance with MSDN). */
524 ok (pILFindLastID(pidlTestFile) == pidlLast,
525 "SHBindToParent doesn't return the last id of the pidl param!\n");
527 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
528 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
530 IShellFolder_Release(psfDesktop);
531 IShellFolder_Release(psfPersonal);
537 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
538 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
539 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
542 IShellFolder_Release(psfDesktop);
543 IShellFolder_Release(psfPersonal);
546 static void test_CallForAttributes(void)
552 LPSHELLFOLDER psfDesktop;
553 LPITEMIDLIST pidlMyDocuments;
554 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
555 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
556 static const WCHAR wszCallForAttributes[] = {
557 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
558 static const WCHAR wszMyDocumentsKey[] = {
559 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
560 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
561 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
562 WCHAR wszMyDocuments[] = {
563 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
564 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
566 /* For the root of a namespace extension, the attributes are not queried by binding
567 * to the object and calling GetAttributesOf. Instead, the attributes are read from
568 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
570 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
571 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
572 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
573 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
575 hr = SHGetDesktopFolder(&psfDesktop);
576 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
577 if (FAILED(hr)) return;
579 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
580 &pidlMyDocuments, NULL);
582 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
584 IShellFolder_Release(psfDesktop);
588 dwAttributes = 0xffffffff;
589 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
590 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
591 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
593 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
594 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
595 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
596 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
598 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
599 * key. So the test will return at this point, if run on wine.
601 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
602 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
603 if (lResult != ERROR_SUCCESS) {
604 IMalloc_Free(ppM, pidlMyDocuments);
605 IShellFolder_Release(psfDesktop);
609 /* Query MyDocuments' Attributes value, to be able to restore it later. */
610 dwSize = sizeof(DWORD);
611 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
612 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
613 if (lResult != ERROR_SUCCESS) {
615 IMalloc_Free(ppM, pidlMyDocuments);
616 IShellFolder_Release(psfDesktop);
620 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
621 dwSize = sizeof(DWORD);
622 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
623 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
624 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
625 if (lResult != ERROR_SUCCESS) {
627 IMalloc_Free(ppM, pidlMyDocuments);
628 IShellFolder_Release(psfDesktop);
632 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
633 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
634 * SFGAO_FILESYSTEM attributes. */
635 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
636 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
637 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
638 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
639 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
641 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
642 * GetAttributesOf. It seems that once there is a single attribute queried, for which
643 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
644 * the flags in Attributes are ignored.
646 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
647 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
648 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
649 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
651 ok (dwAttributes == SFGAO_FILESYSTEM,
652 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n",
655 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
656 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
657 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
658 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
660 IMalloc_Free(ppM, pidlMyDocuments);
661 IShellFolder_Release(psfDesktop);
664 static void test_GetAttributesOf(void)
667 LPSHELLFOLDER psfDesktop, psfMyComputer;
668 SHITEMID emptyitem = { 0, { 0 } };
669 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
670 LPITEMIDLIST pidlMyComputer;
672 static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
673 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
674 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
675 static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
676 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
677 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
678 WCHAR wszMyComputer[] = {
679 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
680 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
681 char cCurrDirA [MAX_PATH] = {0};
682 WCHAR cCurrDirW [MAX_PATH];
683 static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
684 static const WCHAR cBackSlash[] = {'\\',0};
685 IShellFolder *IDesktopFolder, *testIShellFolder;
689 hr = SHGetDesktopFolder(&psfDesktop);
690 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
691 if (FAILED(hr)) return;
693 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
694 dwFlags = 0xffffffff;
695 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
696 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
697 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
698 dwFlags, dwDesktopFlags);
700 /* .. or with no itemidlist at all. */
701 dwFlags = 0xffffffff;
702 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
703 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
704 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
705 dwFlags, dwDesktopFlags);
707 /* Testing the attributes of the MyComputer shellfolder */
708 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
709 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
711 IShellFolder_Release(psfDesktop);
715 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
716 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
717 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
718 * should create a link to the original data". You can't create links on MyComputer on
719 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
720 * depends on this bug, we probably shouldn't imitate it.
722 dwFlags = 0xffffffff;
723 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
724 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
725 ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
726 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags);
728 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
729 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
730 IShellFolder_Release(psfDesktop);
731 IMalloc_Free(ppM, pidlMyComputer);
732 if (FAILED(hr)) return;
734 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
735 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr); }
737 dwFlags = 0xffffffff;
738 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
739 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
740 todo_wine { ok (dwFlags == dwMyComputerFlags,
741 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags); }
743 IShellFolder_Release(psfMyComputer);
745 /* create test directory */
746 CreateFilesFolders();
748 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
749 len = lstrlenA(cCurrDirA);
752 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
755 if(cCurrDirA[len-1] == '\\')
756 cCurrDirA[len-1] = 0;
758 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
760 hr = SHGetDesktopFolder(&IDesktopFolder);
761 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
763 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
764 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
766 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
767 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
769 IMalloc_Free(ppM, newPIDL);
771 /* get relative PIDL */
772 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
773 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
775 /* test the shell attributes of the test directory using the relative PIDL */
776 dwFlags = SFGAO_FOLDER;
777 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
778 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
779 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
782 IMalloc_Free(ppM, newPIDL);
784 /* append testdirectory name to path */
785 lstrcatW(cCurrDirW, cBackSlash);
786 lstrcatW(cCurrDirW, cTestDirW);
788 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
789 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
791 /* test the shell attributes of the test directory using the absolute PIDL */
792 dwFlags = SFGAO_FOLDER;
793 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
794 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
795 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
798 IMalloc_Free(ppM, newPIDL);
800 IShellFolder_Release(testIShellFolder);
804 IShellFolder_Release(IDesktopFolder);
807 static void test_SHGetPathFromIDList(void)
809 SHITEMID emptyitem = { 0, { 0 } };
810 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
811 LPITEMIDLIST pidlMyComputer;
812 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
815 LPSHELLFOLDER psfDesktop;
816 WCHAR wszMyComputer[] = {
817 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
818 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
819 WCHAR wszFileName[MAX_PATH];
820 LPITEMIDLIST pidlTestFile;
823 static WCHAR wszTestFile[] = {
824 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
825 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
827 LPITEMIDLIST pidlPrograms;
829 if(!pSHGetPathFromIDListW || !pSHGetSpecialFolderPathW)
831 skip("SHGetPathFromIDListW() or SHGetSpecialFolderPathW() is missing\n");
835 /* Calling SHGetPathFromIDListW with no pidl should return the empty string */
838 result = pSHGetPathFromIDListW(NULL, wszPath);
839 ok(!result, "Expected failure\n");
840 ok(!wszPath[0], "Expected empty string\n");
842 /* Calling SHGetPathFromIDListW with an empty pidl should return the desktop folder's path. */
843 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
844 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
847 result = pSHGetPathFromIDListW(pidlEmpty, wszPath);
848 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
850 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDListW didn't return desktop path for empty pidl!\n");
852 /* MyComputer does not map to a filesystem path. SHGetPathFromIDListW should fail. */
853 hr = SHGetDesktopFolder(&psfDesktop);
854 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
855 if (FAILED(hr)) return;
857 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
858 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
860 IShellFolder_Release(psfDesktop);
864 SetLastError(0xdeadbeef);
867 result = pSHGetPathFromIDListW(pidlMyComputer, wszPath);
868 ok (!result, "SHGetPathFromIDListW succeeded where it shouldn't!\n");
869 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDListW shouldn't set last error! Last error: %u\n", GetLastError());
870 ok (!wszPath[0], "Expected empty path\n");
872 IShellFolder_Release(psfDesktop);
876 IMalloc_Free(ppM, pidlMyComputer);
878 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
879 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
881 IShellFolder_Release(psfDesktop);
884 myPathAddBackslashW(wszFileName);
885 lstrcatW(wszFileName, wszTestFile);
886 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
887 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
888 if (hTestFile == INVALID_HANDLE_VALUE) {
889 IShellFolder_Release(psfDesktop);
892 CloseHandle(hTestFile);
894 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
895 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
897 IShellFolder_Release(psfDesktop);
898 DeleteFileW(wszFileName);
899 IMalloc_Free(ppM, pidlTestFile);
903 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
904 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
905 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
906 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
907 IShellFolder_Release(psfDesktop);
908 DeleteFileW(wszFileName);
910 IMalloc_Free(ppM, pidlTestFile);
915 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
916 ok(0 == lstrcmpW(wszFileName, wszPath),
917 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
918 "returned incorrect path for file placed on desktop\n");
921 result = pSHGetPathFromIDListW(pidlTestFile, wszPath);
922 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
923 IMalloc_Free(ppM, pidlTestFile);
925 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
928 /* Test if we can get the path from the start menu "program files" PIDL. */
929 hShell32 = GetModuleHandleA("shell32");
930 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
932 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
933 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
935 SetLastError(0xdeadbeef);
936 result = pSHGetPathFromIDListW(pidlPrograms, wszPath);
937 IMalloc_Free(ppM, pidlPrograms);
938 ok(result, "SHGetPathFromIDListW failed\n");
941 static void test_EnumObjects_and_CompareIDs(void)
944 IShellFolder *IDesktopFolder, *testIShellFolder;
945 char cCurrDirA [MAX_PATH] = {0};
946 WCHAR cCurrDirW [MAX_PATH];
947 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
951 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
952 len = lstrlenA(cCurrDirA);
955 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
958 if(cCurrDirA[len-1] == '\\')
959 cCurrDirA[len-1] = 0;
961 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
962 lstrcatW(cCurrDirW, cTestDirW);
964 hr = SHGetDesktopFolder(&IDesktopFolder);
965 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
967 CreateFilesFolders();
969 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
970 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
972 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
973 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
975 test_EnumObjects(testIShellFolder);
977 IShellFolder_Release(testIShellFolder);
981 IMalloc_Free(ppM, newPIDL);
983 IShellFolder_Release(IDesktopFolder);
986 /* A simple implementation of an IPropertyBag, which returns fixed values for
987 * 'Target' and 'Attributes' properties.
989 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
995 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
998 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
999 return E_NOINTERFACE;
1002 IPropertyBag_AddRef(iface);
1006 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
1010 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
1014 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
1015 VARIANT *pVar, IErrorLog *pErrorLog)
1017 static const WCHAR wszTargetSpecialFolder[] = {
1018 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
1019 static const WCHAR wszTarget[] = {
1020 'T','a','r','g','e','t',0 };
1021 static const WCHAR wszAttributes[] = {
1022 'A','t','t','r','i','b','u','t','e','s',0 };
1023 static const WCHAR wszResolveLinkFlags[] = {
1024 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
1026 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
1027 ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
1028 return E_INVALIDARG;
1031 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
1033 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
1034 return E_INVALIDARG;
1037 if (!lstrcmpW(pszPropName, wszTarget)) {
1038 WCHAR wszPath[MAX_PATH];
1041 ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
1042 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
1044 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1045 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1046 if (!result) return E_INVALIDARG;
1048 V_BSTR(pVar) = SysAllocString(wszPath);
1052 if (!lstrcmpW(pszPropName, wszAttributes)) {
1053 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
1054 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
1055 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
1056 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1060 ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
1061 return E_INVALIDARG;
1064 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1067 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1071 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1072 InitPropertyBag_IPropertyBag_QueryInterface,
1073 InitPropertyBag_IPropertyBag_AddRef,
1074 InitPropertyBag_IPropertyBag_Release,
1075 InitPropertyBag_IPropertyBag_Read,
1076 InitPropertyBag_IPropertyBag_Write
1079 static struct IPropertyBag InitPropertyBag = {
1080 &InitPropertyBag_IPropertyBagVtbl
1083 static void test_FolderShortcut(void) {
1084 IPersistPropertyBag *pPersistPropertyBag;
1085 IShellFolder *pShellFolder, *pDesktopFolder;
1086 IPersistFolder3 *pPersistFolder3;
1089 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1092 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1094 WCHAR wszWineTestFolder[] = {
1095 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1096 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1097 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1098 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1099 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1100 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1101 'N','a','m','e','S','p','a','c','e','\\',
1102 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1103 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1105 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1106 static const GUID CLSID_UnixDosFolder =
1107 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1109 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) {
1110 win_skip("SHGetSpecialFolderPathW and/or StrRetToBufW are not available\n");
1114 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1115 * via their IPersistPropertyBag interface. And that the target folder
1116 * is taken from the IPropertyBag's 'Target' property.
1118 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1119 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1120 if (hr == REGDB_E_CLASSNOTREG) {
1121 win_skip("CLSID_FolderShortcut is not implemented\n");
1124 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
1125 if (FAILED(hr)) return;
1127 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1128 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
1130 IPersistPropertyBag_Release(pPersistPropertyBag);
1134 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1135 (LPVOID*)&pShellFolder);
1136 IPersistPropertyBag_Release(pPersistPropertyBag);
1137 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1138 if (FAILED(hr)) return;
1140 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1141 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1143 IShellFolder_Release(pShellFolder);
1147 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1148 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1149 if (!result) return;
1151 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1152 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1154 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1155 IShellFolder_Release(pShellFolder);
1156 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
1157 if (FAILED(hr)) return;
1159 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1160 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1161 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1163 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1164 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1165 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1167 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1168 * shell namespace. The target folder, read from the property bag above, remains untouched.
1169 * The following tests show this: The itemidlist for some imaginary shellfolder object
1170 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1171 * itemidlist, but GetDisplayNameOf still returns the path from above.
1173 hr = SHGetDesktopFolder(&pDesktopFolder);
1174 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
1175 if (FAILED(hr)) return;
1177 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1178 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1179 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1180 RegCloseKey(hShellExtKey);
1181 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1182 &pidlWineTestFolder, NULL);
1183 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1184 IShellFolder_Release(pDesktopFolder);
1185 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1186 if (FAILED(hr)) return;
1188 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1189 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
1191 IPersistFolder3_Release(pPersistFolder3);
1192 pILFree(pidlWineTestFolder);
1196 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1197 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1198 ok(pILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1199 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1200 pILFree(pidlCurrentFolder);
1201 pILFree(pidlWineTestFolder);
1203 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1204 IPersistFolder3_Release(pPersistFolder3);
1205 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1206 if (FAILED(hr)) return;
1208 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1209 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1211 IShellFolder_Release(pShellFolder);
1215 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1216 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1218 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1219 * but ShellFSFolders. */
1220 myPathAddBackslashW(wszDesktopPath);
1221 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1222 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1223 IShellFolder_Release(pShellFolder);
1227 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1228 &pidlSubFolder, NULL);
1229 RemoveDirectoryW(wszDesktopPath);
1230 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1232 IShellFolder_Release(pShellFolder);
1236 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1237 (LPVOID*)&pPersistFolder3);
1238 IShellFolder_Release(pShellFolder);
1239 pILFree(pidlSubFolder);
1240 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
1244 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1245 * a little bit and also allow CLSID_UnixDosFolder. */
1246 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1247 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1248 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1249 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1251 IPersistFolder3_Release(pPersistFolder3);
1254 #include "pshpack1.h"
1255 struct FileStructA {
1259 WORD uFileDate; /* In our current implementation this is */
1260 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1265 struct FileStructW {
1266 WORD cbLen; /* Length of this element. */
1267 BYTE abFooBar1[6]; /* Beyond any recognition. */
1268 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1269 WORD uTime; /* (this is currently speculation) */
1270 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1271 WORD uTime2; /* (this is currently speculation) */
1272 BYTE abFooBar2[4]; /* Beyond any recognition. */
1273 WCHAR wszName[1]; /* The long filename in unicode. */
1274 /* Just for documentation: Right after the unicode string: */
1275 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1276 * SHITEMID->cb == uOffset + cbLen */
1278 #include "poppack.h"
1280 static void test_ITEMIDLIST_format(void) {
1281 WCHAR wszPersonal[MAX_PATH];
1282 LPSHELLFOLDER psfDesktop, psfPersonal;
1283 LPITEMIDLIST pidlPersonal, pidlFile;
1287 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1288 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1291 if(!pSHGetSpecialFolderPathW) return;
1293 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1294 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1295 if (!bResult) return;
1297 SetLastError(0xdeadbeef);
1298 bResult = SetCurrentDirectoryW(wszPersonal);
1299 if (!bResult && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
1300 win_skip("Most W-calls are not implemented\n");
1303 ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1304 if (!bResult) return;
1306 hr = SHGetDesktopFolder(&psfDesktop);
1307 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
1308 if (FAILED(hr)) return;
1310 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1311 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
1313 IShellFolder_Release(psfDesktop);
1317 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1318 (LPVOID*)&psfPersonal);
1319 IShellFolder_Release(psfDesktop);
1320 pILFree(pidlPersonal);
1321 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
1322 if (FAILED(hr)) return;
1324 for (i=0; i<3; i++) {
1325 CHAR szFile[MAX_PATH];
1326 struct FileStructA *pFileStructA;
1329 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1331 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1332 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
1333 if (hFile == INVALID_HANDLE_VALUE) {
1334 IShellFolder_Release(psfPersonal);
1339 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1340 DeleteFileW(wszFile[i]);
1341 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
1343 IShellFolder_Release(psfPersonal);
1347 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1348 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1349 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1350 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1352 if (i < 2) /* First two file names are already in valid 8.3 format */
1353 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1355 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1356 * can't implement this correctly, since unix filesystems don't support
1357 * this nasty short/long filename stuff. So we'll probably stay with our
1358 * current habbit of storing the long filename here, which seems to work
1360 todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
1362 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1363 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0',
1364 "Alignment byte, where there shouldn't be!\n");
1366 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1367 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1368 "There should be an alignment byte, but isn't!\n");
1370 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1371 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1372 ok (cbOffset >= sizeof(struct FileStructA) &&
1373 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
1374 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1376 if (cbOffset >= sizeof(struct FileStructA) &&
1377 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1379 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1381 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1382 "FileStructW's offset and length should add up to the PIDL's length!\n");
1384 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1385 /* Since we just created the file, time of creation,
1386 * time of last access and time of last write access just be the same.
1387 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1388 * after the first run. I do remember something with NTFS keeping the creation time
1389 * if a file is deleted and then created again within a couple of seconds or so.
1390 * Might be the reason. */
1391 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1392 pFileStructA->uFileTime == pFileStructW->uTime,
1393 "Last write time should match creation time!\n");
1395 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1396 pFileStructA->uFileTime == pFileStructW->uTime2,
1397 "Last write time should match last access time!\n");
1399 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
1400 "The filename should be stored in unicode at this position!\n");
1408 static void testSHGetFolderPathAndSubDirA(void)
1414 static char wine[] = "wine";
1415 static char winetemp[] = "wine\\temp";
1416 static char appdata[MAX_PATH];
1417 static char testpath[MAX_PATH];
1418 static char toolongpath[MAX_PATH+1];
1420 if(!pSHGetFolderPathA) {
1421 skip("SHGetFolderPathA not present!\n");
1424 if(FAILED(pSHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdata)))
1426 skip("SHGetFolderPathA failed for CSIDL_LOCAL_APPDATA!\n");
1430 sprintf(testpath, "%s\\%s", appdata, winetemp);
1431 delret = RemoveDirectoryA(testpath);
1432 if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) ) {
1433 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1437 sprintf(testpath, "%s\\%s", appdata, wine);
1438 delret = RemoveDirectoryA(testpath);
1439 if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) && (ERROR_FILE_NOT_FOUND != GetLastError())) {
1440 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1443 for(i=0; i< MAX_PATH; i++)
1444 toolongpath[i] = '0' + i % 10;
1445 toolongpath[MAX_PATH] = '\0';
1447 /* test invalid second parameter */
1448 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | 0xff, NULL, SHGFP_TYPE_CURRENT, wine, testpath);
1449 ok(E_INVALIDARG == ret, "expected E_INVALIDARG, got %x\n", ret);
1451 /* test invalid forth parameter */
1452 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, 2, wine, testpath);
1454 case S_OK: /* winvista */
1455 ok(!strncmp(appdata, testpath, strlen(appdata)),
1456 "expected %s to start with %s\n", testpath, appdata);
1457 ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1458 "expected %s to end with %s\n", testpath, winetemp);
1460 case E_INVALIDARG: /* winxp, win2k3 */
1463 ok(0, "expected S_OK or E_INVALIDARG, got %x\n", ret);
1466 /* test fifth parameter */
1468 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, NULL, testpath);
1469 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1470 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1473 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "", testpath);
1474 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1475 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1478 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "\\", testpath);
1479 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1480 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1482 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, toolongpath, testpath);
1483 ok(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE) == ret,
1484 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE), ret);
1487 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, wine, NULL);
1488 ok((S_OK == ret) || (E_INVALIDARG == ret), "expected S_OK or E_INVALIDARG, got %x\n", ret);
1490 /* test a not existing path */
1492 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1493 ok(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == ret,
1494 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), ret);
1496 /* create a directory inside a not existing directory */
1498 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_CREATE | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1499 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1500 ok(!strncmp(appdata, testpath, strlen(appdata)),
1501 "expected %s to start with %s\n", testpath, appdata);
1502 ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1503 "expected %s to end with %s\n", testpath, winetemp);
1504 dwret = GetFileAttributes(testpath);
1505 ok(FILE_ATTRIBUTE_DIRECTORY | dwret, "expected %x to contain FILE_ATTRIBUTE_DIRECTORY\n", dwret);
1508 sprintf(testpath, "%s\\%s", appdata, winetemp);
1509 RemoveDirectoryA(testpath);
1510 sprintf(testpath, "%s\\%s", appdata, wine);
1511 RemoveDirectoryA(testpath);
1514 static const char *wine_dbgstr_w(LPCWSTR str)
1516 static char buf[512];
1519 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
1523 static void test_LocalizedNames(void)
1525 static char cCurrDirA[MAX_PATH];
1526 WCHAR cCurrDirW[MAX_PATH], tempbufW[25];
1527 IShellFolder *IDesktopFolder, *testIShellFolder;
1528 ITEMIDLIST *newPIDL;
1531 static char resourcefile[MAX_PATH];
1536 static const char desktopini_contents1[] =
1537 "[.ShellClassInfo]\r\n"
1538 "LocalizedResourceName=@";
1539 static const char desktopini_contents2[] =
1541 static WCHAR foldernameW[] = {'t','e','s','t','f','o','l','d','e','r',0};
1542 static const WCHAR folderdisplayW[] = {'F','o','l','d','e','r',' ','N','a','m','e',' ','R','e','s','o','u','r','c','e',0};
1544 /* create folder with desktop.ini and localized name in GetModuleFileNameA(NULL) */
1545 CreateDirectoryA(".\\testfolder", NULL);
1547 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")|FILE_ATTRIBUTE_SYSTEM);
1549 GetModuleFileNameA(NULL, resourcefile, MAX_PATH);
1551 file = CreateFileA(".\\testfolder\\desktop.ini", GENERIC_WRITE, 0, NULL,
1552 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1553 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %i\n", GetLastError());
1554 ok(WriteFile(file, desktopini_contents1, strlen(desktopini_contents1), &res, NULL) &&
1555 WriteFile(file, resourcefile, strlen(resourcefile), &res, NULL) &&
1556 WriteFile(file, desktopini_contents2, strlen(desktopini_contents2), &res, NULL),
1557 "WriteFile failed %i\n", GetLastError());
1560 /* get IShellFolder for parent */
1561 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
1562 len = lstrlenA(cCurrDirA);
1565 trace("GetCurrentDirectoryA returned empty string. Skipping test_LocalizedNames\n");
1568 if(cCurrDirA[len-1] == '\\')
1569 cCurrDirA[len-1] = 0;
1571 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
1573 hr = SHGetDesktopFolder(&IDesktopFolder);
1574 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
1576 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
1577 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1579 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
1580 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
1582 IMalloc_Free(ppM, newPIDL);
1584 /* windows reads the display name from the resource */
1585 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, foldernameW, NULL, &newPIDL, 0);
1586 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1588 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER, &strret);
1589 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1591 if (SUCCEEDED(hr) && pStrRetToBufW)
1593 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1594 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1596 ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1597 broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1598 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1601 /* editing name is also read from the resource */
1602 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FOREDITING, &strret);
1603 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1605 if (SUCCEEDED(hr) && pStrRetToBufW)
1607 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1608 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1610 ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1611 broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1612 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1615 /* parsing name is unchanged */
1616 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FORPARSING, &strret);
1617 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1619 if (SUCCEEDED(hr) && pStrRetToBufW)
1621 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1622 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1623 ok (!lstrcmpiW(tempbufW, foldernameW), "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1626 IShellFolder_Release(IDesktopFolder);
1627 IShellFolder_Release(testIShellFolder);
1629 IMalloc_Free(ppM, newPIDL);
1632 DeleteFileA(".\\testfolder\\desktop.ini");
1633 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")&~FILE_ATTRIBUTE_SYSTEM);
1634 RemoveDirectoryA(".\\testfolder");
1638 START_TEST(shlfolder)
1640 init_function_pointers();
1641 /* if OleInitialize doesn't get called, ParseDisplayName returns
1642 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1643 OleInitialize(NULL);
1645 test_ParseDisplayName();
1646 test_BindToObject();
1647 test_EnumObjects_and_CompareIDs();
1648 test_GetDisplayName();
1649 test_GetAttributesOf();
1650 test_SHGetPathFromIDList();
1651 test_CallForAttributes();
1652 test_FolderShortcut();
1653 test_ITEMIDLIST_format();
1654 if(pSHGetFolderPathAndSubDirA)
1655 testSHGetFolderPathAndSubDirA();
1657 skip("SHGetFolderPathAndSubDirA not present\n");
1658 test_LocalizedNames();