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 *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
50 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
51 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
52 static void (WINAPI *pILFree)(LPITEMIDLIST);
53 static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
55 static void init_function_pointers(void)
60 hmod = GetModuleHandleA("shell32.dll");
61 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
62 pSHGetFolderPathA = (void*)GetProcAddress(hmod, "SHGetFolderPathA");
63 pSHGetFolderPathAndSubDirA = (void*)GetProcAddress(hmod, "SHGetFolderPathAndSubDirA");
64 pSHGetPathFromIDListW = (void*)GetProcAddress(hmod, "SHGetPathFromIDListW");
65 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
66 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
67 pILFree = (void*)GetProcAddress(hmod, (LPSTR)155);
68 pILIsEqual = (void*)GetProcAddress(hmod, (LPSTR)21);
70 hmod = GetModuleHandleA("shlwapi.dll");
71 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 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
335 static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
339 if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
345 if (lpszPath[-1] != '\\')
354 static void test_GetDisplayName(void)
359 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
360 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
363 LPSHELLFOLDER psfDesktop, psfPersonal;
365 SHITEMID emptyitem = { 0, { 0 } };
366 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
367 LPCITEMIDLIST pidlLast;
368 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
369 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
371 /* I'm trying to figure if there is a functional difference between calling
372 * SHGetPathFromIDListW and calling GetDisplayNameOf(SHGDN_FORPARSING) after
373 * binding to the shellfolder. One thing I thought of was that perhaps
374 * SHGetPathFromIDListW would be able to get the path to a file, which does
375 * not exist anymore, while the other method wouldn't. It turns out there's
376 * no functional difference in this respect.
379 if(!pSHGetSpecialFolderPathW) return;
381 /* First creating a directory in MyDocuments and a file in this directory. */
382 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
383 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
386 myPathAddBackslashW(wszTestDir);
387 lstrcatW(wszTestDir, wszDirName);
388 /* Use ANSI file functions so this works on Windows 9x */
389 WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
390 CreateDirectoryA(szTestDir, NULL);
391 attr=GetFileAttributesA(szTestDir);
392 if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
394 ok(0, "unable to create the '%s' directory\n", szTestDir);
398 lstrcpyW(wszTestFile, wszTestDir);
399 myPathAddBackslashW(wszTestFile);
400 lstrcatW(wszTestFile, wszFileName);
401 WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
403 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
404 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
405 if (hTestFile == INVALID_HANDLE_VALUE) return;
406 CloseHandle(hTestFile);
408 /* Getting an itemidlist for the file. */
409 hr = SHGetDesktopFolder(&psfDesktop);
410 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
411 if (FAILED(hr)) return;
413 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
414 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
416 IShellFolder_Release(psfDesktop);
420 /* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
421 pidlLast = pILFindLastID(pidlTestFile);
422 ok(pidlLast->mkid.cb >=76, "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
423 if (pidlLast->mkid.cb >= 76) {
424 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
425 "WinXP stores the filename as a wchar-string at this position!\n");
428 /* It seems as if we cannot bind to regular files on windows, but only directories.
430 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
431 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08x\n", hr); }
433 IShellFolder_Release(psfFile);
438 skip("SHBindToParent is missing\n");
442 /* Some tests for IShellFolder::SetNameOf */
443 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
444 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
446 /* It's ok to use this fixed path. Call will fail anyway. */
447 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
448 LPITEMIDLIST pidlNew;
450 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
451 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
452 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
455 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
456 "pidl returned from SetNameOf should be simple!\n");
458 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
459 * is implemented on top of SHFileOperation in WinXP. */
460 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
461 SHGDN_FORPARSING, NULL);
462 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
464 /* Rename the file back to its original name. SetNameOf ignores the fact, that the
465 * SHGDN flags specify an absolute path. */
466 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
467 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
472 IShellFolder_Release(psfPersonal);
475 /* Deleting the file and the directory */
476 DeleteFileA(szTestFile);
477 RemoveDirectoryA(szTestDir);
479 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
480 if (pSHGetPathFromIDListW)
482 result = pSHGetPathFromIDListW(pidlTestFile, wszTestFile2);
483 ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
484 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
487 /* SHBindToParent fails, if called with a NULL PIDL. */
488 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
489 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
491 /* But it succeeds with an empty PIDL. */
492 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
493 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
494 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
496 IShellFolder_Release(psfPersonal);
498 /* Binding to the folder and querying the display name of the file also works. */
499 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
500 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
502 IShellFolder_Release(psfDesktop);
506 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
507 * pidlTestFile (In accordance with MSDN). */
508 ok (pILFindLastID(pidlTestFile) == pidlLast,
509 "SHBindToParent doesn't return the last id of the pidl param!\n");
511 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
512 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
514 IShellFolder_Release(psfDesktop);
515 IShellFolder_Release(psfPersonal);
521 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
522 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
523 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
526 IShellFolder_Release(psfDesktop);
527 IShellFolder_Release(psfPersonal);
530 static void test_CallForAttributes(void)
536 LPSHELLFOLDER psfDesktop;
537 LPITEMIDLIST pidlMyDocuments;
538 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
539 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
540 static const WCHAR wszCallForAttributes[] = {
541 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
542 static const WCHAR wszMyDocumentsKey[] = {
543 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
544 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
545 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
546 WCHAR wszMyDocuments[] = {
547 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
548 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
550 /* For the root of a namespace extension, the attributes are not queried by binding
551 * to the object and calling GetAttributesOf. Instead, the attributes are read from
552 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
554 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
555 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
556 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
557 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
559 hr = SHGetDesktopFolder(&psfDesktop);
560 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
561 if (FAILED(hr)) return;
563 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
564 &pidlMyDocuments, NULL);
566 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
568 IShellFolder_Release(psfDesktop);
572 dwAttributes = 0xffffffff;
573 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
574 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
575 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
577 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
578 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
579 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
580 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
582 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
583 * key. So the test will return at this point, if run on wine.
585 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
586 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
587 if (lResult != ERROR_SUCCESS) {
588 IMalloc_Free(ppM, pidlMyDocuments);
589 IShellFolder_Release(psfDesktop);
593 /* Query MyDocuments' Attributes value, to be able to restore it later. */
594 dwSize = sizeof(DWORD);
595 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
596 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
597 if (lResult != ERROR_SUCCESS) {
599 IMalloc_Free(ppM, pidlMyDocuments);
600 IShellFolder_Release(psfDesktop);
604 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
605 dwSize = sizeof(DWORD);
606 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
607 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
608 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
609 if (lResult != ERROR_SUCCESS) {
611 IMalloc_Free(ppM, pidlMyDocuments);
612 IShellFolder_Release(psfDesktop);
616 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
617 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
618 * SFGAO_FILESYSTEM attributes. */
619 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
620 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
621 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
622 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
623 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
625 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
626 * GetAttributesOf. It seems that once there is a single attribute queried, for which
627 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
628 * the flags in Attributes are ignored.
630 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
631 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
632 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
633 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
635 ok (dwAttributes == SFGAO_FILESYSTEM,
636 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n",
639 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
640 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
641 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
642 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
644 IMalloc_Free(ppM, pidlMyDocuments);
645 IShellFolder_Release(psfDesktop);
648 static void test_GetAttributesOf(void)
651 LPSHELLFOLDER psfDesktop, psfMyComputer;
652 SHITEMID emptyitem = { 0, { 0 } };
653 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
654 LPITEMIDLIST pidlMyComputer;
656 static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
657 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
658 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
659 static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
660 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
661 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
662 WCHAR wszMyComputer[] = {
663 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
664 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
665 char cCurrDirA [MAX_PATH] = {0};
666 WCHAR cCurrDirW [MAX_PATH];
667 static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
668 static const WCHAR cBackSlash[] = {'\\',0};
669 IShellFolder *IDesktopFolder, *testIShellFolder;
673 hr = SHGetDesktopFolder(&psfDesktop);
674 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
675 if (FAILED(hr)) return;
677 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
678 dwFlags = 0xffffffff;
679 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
680 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
681 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
682 dwFlags, dwDesktopFlags);
684 /* .. or with no itemidlist at all. */
685 dwFlags = 0xffffffff;
686 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
687 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
688 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08x, expected: %08x\n",
689 dwFlags, dwDesktopFlags);
691 /* Testing the attributes of the MyComputer shellfolder */
692 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
693 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
695 IShellFolder_Release(psfDesktop);
699 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
700 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
701 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
702 * should create a link to the original data". You can't create links on MyComputer on
703 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
704 * depends on this bug, we probably shouldn't imitate it.
706 dwFlags = 0xffffffff;
707 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
708 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
709 ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
710 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags);
712 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
713 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
714 IShellFolder_Release(psfDesktop);
715 IMalloc_Free(ppM, pidlMyComputer);
716 if (FAILED(hr)) return;
718 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
719 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr); }
721 dwFlags = 0xffffffff;
722 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
723 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
724 todo_wine { ok (dwFlags == dwMyComputerFlags,
725 "Wrong MyComputer attributes: %08x, expected: %08x\n", dwFlags, dwMyComputerFlags); }
727 IShellFolder_Release(psfMyComputer);
729 /* create test directory */
730 CreateFilesFolders();
732 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
733 len = lstrlenA(cCurrDirA);
736 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
739 if(cCurrDirA[len-1] == '\\')
740 cCurrDirA[len-1] = 0;
742 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
744 hr = SHGetDesktopFolder(&IDesktopFolder);
745 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
747 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
748 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
750 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
751 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
753 IMalloc_Free(ppM, newPIDL);
755 /* get relative PIDL */
756 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
757 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
759 /* test the shell attributes of the test directory using the relative PIDL */
760 dwFlags = SFGAO_FOLDER;
761 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
762 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
763 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
766 IMalloc_Free(ppM, newPIDL);
768 /* append testdirectory name to path */
769 lstrcatW(cCurrDirW, cBackSlash);
770 lstrcatW(cCurrDirW, cTestDirW);
772 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
773 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
775 /* test the shell attributes of the test directory using the absolute PIDL */
776 dwFlags = SFGAO_FOLDER;
777 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
778 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
779 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
782 IMalloc_Free(ppM, newPIDL);
784 IShellFolder_Release(testIShellFolder);
788 IShellFolder_Release(IDesktopFolder);
791 static void test_SHGetPathFromIDList(void)
793 SHITEMID emptyitem = { 0, { 0 } };
794 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
795 LPITEMIDLIST pidlMyComputer;
796 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
799 LPSHELLFOLDER psfDesktop;
800 WCHAR wszMyComputer[] = {
801 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
802 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
803 WCHAR wszFileName[MAX_PATH];
804 LPITEMIDLIST pidlTestFile;
807 static WCHAR wszTestFile[] = {
808 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
809 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
811 LPITEMIDLIST pidlPrograms;
813 if(!pSHGetPathFromIDListW || !pSHGetSpecialFolderPathW)
815 skip("SHGetPathFromIDListW() or SHGetSpecialFolderPathW() is missing\n");
819 /* Calling SHGetPathFromIDListW with no pidl should return the empty string */
822 result = pSHGetPathFromIDListW(NULL, wszPath);
823 ok(!result, "Expected failure\n");
824 ok(!wszPath[0], "Expected empty string\n");
826 /* Calling SHGetPathFromIDListW with an empty pidl should return the desktop folder's path. */
827 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
828 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
831 result = pSHGetPathFromIDListW(pidlEmpty, wszPath);
832 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
834 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDListW didn't return desktop path for empty pidl!\n");
836 /* MyComputer does not map to a filesystem path. SHGetPathFromIDListW should fail. */
837 hr = SHGetDesktopFolder(&psfDesktop);
838 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
839 if (FAILED(hr)) return;
841 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
842 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
844 IShellFolder_Release(psfDesktop);
848 SetLastError(0xdeadbeef);
851 result = pSHGetPathFromIDListW(pidlMyComputer, wszPath);
852 ok (!result, "SHGetPathFromIDListW succeeded where it shouldn't!\n");
853 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDListW shouldn't set last error! Last error: %u\n", GetLastError());
854 ok (!wszPath[0], "Expected empty path\n");
856 IShellFolder_Release(psfDesktop);
860 IMalloc_Free(ppM, pidlMyComputer);
862 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
863 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
865 IShellFolder_Release(psfDesktop);
868 myPathAddBackslashW(wszFileName);
869 lstrcatW(wszFileName, wszTestFile);
870 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
871 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
872 if (hTestFile == INVALID_HANDLE_VALUE) {
873 IShellFolder_Release(psfDesktop);
876 CloseHandle(hTestFile);
878 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
879 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
881 IShellFolder_Release(psfDesktop);
882 DeleteFileW(wszFileName);
883 IMalloc_Free(ppM, pidlTestFile);
887 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
888 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
889 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
890 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
891 IShellFolder_Release(psfDesktop);
892 DeleteFileW(wszFileName);
894 IMalloc_Free(ppM, pidlTestFile);
899 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
900 ok(0 == lstrcmpW(wszFileName, wszPath),
901 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
902 "returned incorrect path for file placed on desktop\n");
905 result = pSHGetPathFromIDListW(pidlTestFile, wszPath);
906 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
907 IMalloc_Free(ppM, pidlTestFile);
909 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
912 /* Test if we can get the path from the start menu "program files" PIDL. */
913 hShell32 = GetModuleHandleA("shell32");
914 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
916 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
917 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
919 SetLastError(0xdeadbeef);
920 result = pSHGetPathFromIDListW(pidlPrograms, wszPath);
921 IMalloc_Free(ppM, pidlPrograms);
922 ok(result, "SHGetPathFromIDListW failed\n");
925 static void test_EnumObjects_and_CompareIDs(void)
928 IShellFolder *IDesktopFolder, *testIShellFolder;
929 char cCurrDirA [MAX_PATH] = {0};
930 WCHAR cCurrDirW [MAX_PATH];
931 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
935 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
936 len = lstrlenA(cCurrDirA);
939 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
942 if(cCurrDirA[len-1] == '\\')
943 cCurrDirA[len-1] = 0;
945 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
946 lstrcatW(cCurrDirW, cTestDirW);
948 hr = SHGetDesktopFolder(&IDesktopFolder);
949 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
951 CreateFilesFolders();
953 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
954 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
956 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
957 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
959 test_EnumObjects(testIShellFolder);
961 IShellFolder_Release(testIShellFolder);
965 IMalloc_Free(ppM, newPIDL);
967 IShellFolder_Release(IDesktopFolder);
970 /* A simple implementation of an IPropertyBag, which returns fixed values for
971 * 'Target' and 'Attributes' properties.
973 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
979 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
982 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
983 return E_NOINTERFACE;
986 IPropertyBag_AddRef(iface);
990 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
994 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
998 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
999 VARIANT *pVar, IErrorLog *pErrorLog)
1001 static const WCHAR wszTargetSpecialFolder[] = {
1002 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
1003 static const WCHAR wszTarget[] = {
1004 'T','a','r','g','e','t',0 };
1005 static const WCHAR wszAttributes[] = {
1006 'A','t','t','r','i','b','u','t','e','s',0 };
1007 static const WCHAR wszResolveLinkFlags[] = {
1008 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
1010 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
1011 ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
1012 return E_INVALIDARG;
1015 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
1017 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
1018 return E_INVALIDARG;
1021 if (!lstrcmpW(pszPropName, wszTarget)) {
1022 WCHAR wszPath[MAX_PATH];
1025 ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
1026 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
1028 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1029 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1030 if (!result) return E_INVALIDARG;
1032 V_BSTR(pVar) = SysAllocString(wszPath);
1036 if (!lstrcmpW(pszPropName, wszAttributes)) {
1037 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
1038 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
1039 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
1040 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1044 ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
1045 return E_INVALIDARG;
1048 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1051 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1055 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1056 InitPropertyBag_IPropertyBag_QueryInterface,
1057 InitPropertyBag_IPropertyBag_AddRef,
1058 InitPropertyBag_IPropertyBag_Release,
1059 InitPropertyBag_IPropertyBag_Read,
1060 InitPropertyBag_IPropertyBag_Write
1063 static struct IPropertyBag InitPropertyBag = {
1064 &InitPropertyBag_IPropertyBagVtbl
1067 static void test_FolderShortcut(void) {
1068 IPersistPropertyBag *pPersistPropertyBag;
1069 IShellFolder *pShellFolder, *pDesktopFolder;
1070 IPersistFolder3 *pPersistFolder3;
1073 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1076 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1078 WCHAR wszWineTestFolder[] = {
1079 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1080 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1081 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1082 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1083 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1084 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1085 'N','a','m','e','S','p','a','c','e','\\',
1086 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1087 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1089 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1090 static const GUID CLSID_UnixDosFolder =
1091 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1093 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) {
1094 win_skip("SHGetSpecialFolderPathW and/or StrRetToBufW are not available\n");
1098 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1099 * via their IPersistPropertyBag interface. And that the target folder
1100 * is taken from the IPropertyBag's 'Target' property.
1102 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1103 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1104 if (hr == REGDB_E_CLASSNOTREG) {
1105 win_skip("CLSID_FolderShortcut is not implemented\n");
1108 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
1109 if (FAILED(hr)) return;
1111 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1112 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
1114 IPersistPropertyBag_Release(pPersistPropertyBag);
1118 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1119 (LPVOID*)&pShellFolder);
1120 IPersistPropertyBag_Release(pPersistPropertyBag);
1121 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1122 if (FAILED(hr)) return;
1124 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1125 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1127 IShellFolder_Release(pShellFolder);
1131 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1132 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1133 if (!result) return;
1135 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1136 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1138 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1139 IShellFolder_Release(pShellFolder);
1140 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
1141 if (FAILED(hr)) return;
1143 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1144 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1145 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1147 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1148 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1149 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1151 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1152 * shell namespace. The target folder, read from the property bag above, remains untouched.
1153 * The following tests show this: The itemidlist for some imaginary shellfolder object
1154 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1155 * itemidlist, but GetDisplayNameOf still returns the path from above.
1157 hr = SHGetDesktopFolder(&pDesktopFolder);
1158 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
1159 if (FAILED(hr)) return;
1161 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1162 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1163 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1164 RegCloseKey(hShellExtKey);
1165 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1166 &pidlWineTestFolder, NULL);
1167 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1168 IShellFolder_Release(pDesktopFolder);
1169 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1170 if (FAILED(hr)) return;
1172 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1173 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
1175 IPersistFolder3_Release(pPersistFolder3);
1176 pILFree(pidlWineTestFolder);
1180 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1181 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1182 ok(pILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1183 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1184 pILFree(pidlCurrentFolder);
1185 pILFree(pidlWineTestFolder);
1187 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1188 IPersistFolder3_Release(pPersistFolder3);
1189 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1190 if (FAILED(hr)) return;
1192 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1193 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1195 IShellFolder_Release(pShellFolder);
1199 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1200 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1202 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1203 * but ShellFSFolders. */
1204 myPathAddBackslashW(wszDesktopPath);
1205 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1206 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1207 IShellFolder_Release(pShellFolder);
1211 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1212 &pidlSubFolder, NULL);
1213 RemoveDirectoryW(wszDesktopPath);
1214 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1216 IShellFolder_Release(pShellFolder);
1220 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1221 (LPVOID*)&pPersistFolder3);
1222 IShellFolder_Release(pShellFolder);
1223 pILFree(pidlSubFolder);
1224 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
1228 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1229 * a little bit and also allow CLSID_UnixDosFolder. */
1230 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1231 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1232 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1233 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1235 IPersistFolder3_Release(pPersistFolder3);
1238 #include "pshpack1.h"
1239 struct FileStructA {
1243 WORD uFileDate; /* In our current implementation this is */
1244 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1249 struct FileStructW {
1250 WORD cbLen; /* Length of this element. */
1251 BYTE abFooBar1[6]; /* Beyond any recognition. */
1252 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1253 WORD uTime; /* (this is currently speculation) */
1254 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1255 WORD uTime2; /* (this is currently speculation) */
1256 BYTE abFooBar2[4]; /* Beyond any recognition. */
1257 WCHAR wszName[1]; /* The long filename in unicode. */
1258 /* Just for documentation: Right after the unicode string: */
1259 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1260 * SHITEMID->cb == uOffset + cbLen */
1262 #include "poppack.h"
1264 static void test_ITEMIDLIST_format(void) {
1265 WCHAR wszPersonal[MAX_PATH];
1266 LPSHELLFOLDER psfDesktop, psfPersonal;
1267 LPITEMIDLIST pidlPersonal, pidlFile;
1271 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1272 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1275 if(!pSHGetSpecialFolderPathW) return;
1277 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1278 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1279 if (!bResult) return;
1281 SetLastError(0xdeadbeef);
1282 bResult = SetCurrentDirectoryW(wszPersonal);
1283 if (!bResult && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
1284 win_skip("Most W-calls are not implemented\n");
1287 ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1288 if (!bResult) return;
1290 hr = SHGetDesktopFolder(&psfDesktop);
1291 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
1292 if (FAILED(hr)) return;
1294 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1295 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
1297 IShellFolder_Release(psfDesktop);
1301 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1302 (LPVOID*)&psfPersonal);
1303 IShellFolder_Release(psfDesktop);
1304 pILFree(pidlPersonal);
1305 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
1306 if (FAILED(hr)) return;
1308 for (i=0; i<3; i++) {
1309 CHAR szFile[MAX_PATH];
1310 struct FileStructA *pFileStructA;
1313 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1315 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1316 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
1317 if (hFile == INVALID_HANDLE_VALUE) {
1318 IShellFolder_Release(psfPersonal);
1323 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1324 DeleteFileW(wszFile[i]);
1325 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
1327 IShellFolder_Release(psfPersonal);
1331 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1332 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1333 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1334 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1336 if (i < 2) /* First two file names are already in valid 8.3 format */
1337 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1339 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1340 * can't implement this correctly, since unix filesystems don't support
1341 * this nasty short/long filename stuff. So we'll probably stay with our
1342 * current habbit of storing the long filename here, which seems to work
1344 todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
1346 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1347 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0',
1348 "Alignment byte, where there shouldn't be!\n");
1350 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1351 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1352 "There should be an alignment byte, but isn't!\n");
1354 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1355 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1356 ok (cbOffset >= sizeof(struct FileStructA) &&
1357 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
1358 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1360 if (cbOffset >= sizeof(struct FileStructA) &&
1361 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1363 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1365 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1366 "FileStructW's offset and length should add up to the PIDL's length!\n");
1368 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1369 /* Since we just created the file, time of creation,
1370 * time of last access and time of last write access just be the same.
1371 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1372 * after the first run. I do remember something with NTFS keeping the creation time
1373 * if a file is deleted and then created again within a couple of seconds or so.
1374 * Might be the reason. */
1375 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1376 pFileStructA->uFileTime == pFileStructW->uTime,
1377 "Last write time should match creation time!\n");
1379 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1380 pFileStructA->uFileTime == pFileStructW->uTime2,
1381 "Last write time should match last access time!\n");
1383 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
1384 "The filename should be stored in unicode at this position!\n");
1392 static void testSHGetFolderPathAndSubDirA(void)
1398 static char wine[] = "wine";
1399 static char winetemp[] = "wine\\temp";
1400 static char appdata[MAX_PATH];
1401 static char testpath[MAX_PATH];
1402 static char toolongpath[MAX_PATH+1];
1404 if(!pSHGetFolderPathA) {
1405 skip("SHGetFolderPathA not present!\n");
1408 if(FAILED(pSHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdata)))
1410 skip("SHGetFolderPathA failed for CSIDL_LOCAL_APPDATA!\n");
1414 sprintf(testpath, "%s\\%s", appdata, winetemp);
1415 delret = RemoveDirectoryA(testpath);
1416 if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) ) {
1417 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1421 sprintf(testpath, "%s\\%s", appdata, wine);
1422 delret = RemoveDirectoryA(testpath);
1423 if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) && (ERROR_FILE_NOT_FOUND != GetLastError())) {
1424 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1427 for(i=0; i< MAX_PATH; i++)
1428 toolongpath[i] = '0' + i % 10;
1429 toolongpath[MAX_PATH] = '\0';
1431 /* test invalid second parameter */
1432 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | 0xff, NULL, SHGFP_TYPE_CURRENT, wine, testpath);
1433 ok(E_INVALIDARG == ret, "expected E_INVALIDARG, got %x\n", ret);
1435 /* test invalid forth parameter */
1436 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, 2, wine, testpath);
1438 case S_OK: /* winvista */
1439 ok(!strncmp(appdata, testpath, strlen(appdata)),
1440 "expected %s to start with %s\n", testpath, appdata);
1441 ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1442 "expected %s to end with %s\n", testpath, winetemp);
1444 case E_INVALIDARG: /* winxp, win2k3 */
1447 ok(0, "expected S_OK or E_INVALIDARG, got %x\n", ret);
1450 /* test fifth parameter */
1452 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, NULL, testpath);
1453 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1454 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1457 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "", testpath);
1458 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1459 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1462 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "\\", testpath);
1463 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1464 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1466 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, toolongpath, testpath);
1467 ok(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE) == ret,
1468 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE), ret);
1471 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, wine, NULL);
1472 ok((S_OK == ret) || (E_INVALIDARG == ret), "expected S_OK or E_INVALIDARG, got %x\n", ret);
1474 /* test a not existing path */
1476 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1477 ok(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == ret,
1478 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), ret);
1480 /* create a directory inside a not existing directory */
1482 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_CREATE | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1483 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1484 ok(!strncmp(appdata, testpath, strlen(appdata)),
1485 "expected %s to start with %s\n", testpath, appdata);
1486 ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1487 "expected %s to end with %s\n", testpath, winetemp);
1488 dwret = GetFileAttributes(testpath);
1489 ok(FILE_ATTRIBUTE_DIRECTORY | dwret, "expected %x to contain FILE_ATTRIBUTE_DIRECTORY\n", dwret);
1492 sprintf(testpath, "%s\\%s", appdata, winetemp);
1493 RemoveDirectoryA(testpath);
1494 sprintf(testpath, "%s\\%s", appdata, wine);
1495 RemoveDirectoryA(testpath);
1498 static const char *wine_dbgstr_w(LPCWSTR str)
1500 static char buf[512];
1503 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
1507 static void test_LocalizedNames(void)
1509 static char cCurrDirA[MAX_PATH];
1510 WCHAR cCurrDirW[MAX_PATH], tempbufW[25];
1511 IShellFolder *IDesktopFolder, *testIShellFolder;
1512 ITEMIDLIST *newPIDL;
1515 static char resourcefile[MAX_PATH];
1520 static const char desktopini_contents1[] =
1521 "[.ShellClassInfo]\r\n"
1522 "LocalizedResourceName=@";
1523 static const char desktopini_contents2[] =
1525 static WCHAR foldernameW[] = {'t','e','s','t','f','o','l','d','e','r',0};
1526 static const WCHAR folderdisplayW[] = {'F','o','l','d','e','r',' ','N','a','m','e',' ','R','e','s','o','u','r','c','e',0};
1528 /* create folder with desktop.ini and localized name in GetModuleFileNameA(NULL) */
1529 CreateDirectoryA(".\\testfolder", NULL);
1531 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")|FILE_ATTRIBUTE_SYSTEM);
1533 GetModuleFileNameA(NULL, resourcefile, MAX_PATH);
1535 file = CreateFileA(".\\testfolder\\desktop.ini", GENERIC_WRITE, 0, NULL,
1536 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1537 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %i\n", GetLastError());
1538 ok(WriteFile(file, desktopini_contents1, strlen(desktopini_contents1), &res, NULL) &&
1539 WriteFile(file, resourcefile, strlen(resourcefile), &res, NULL) &&
1540 WriteFile(file, desktopini_contents2, strlen(desktopini_contents2), &res, NULL),
1541 "WriteFile failed %i\n", GetLastError());
1544 /* get IShellFolder for parent */
1545 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
1546 len = lstrlenA(cCurrDirA);
1549 trace("GetCurrentDirectoryA returned empty string. Skipping test_LocalizedNames\n");
1552 if(cCurrDirA[len-1] == '\\')
1553 cCurrDirA[len-1] = 0;
1555 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
1557 hr = SHGetDesktopFolder(&IDesktopFolder);
1558 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
1560 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
1561 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1563 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
1564 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
1566 IMalloc_Free(ppM, newPIDL);
1568 /* windows reads the display name from the resource */
1569 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, foldernameW, NULL, &newPIDL, 0);
1570 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1572 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER, &strret);
1573 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1575 if (SUCCEEDED(hr) && pStrRetToBufW)
1577 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1578 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1580 ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1581 broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1582 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1585 /* editing name is also read from the resource */
1586 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FOREDITING, &strret);
1587 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1589 if (SUCCEEDED(hr) && pStrRetToBufW)
1591 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1592 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1594 ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1595 broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1596 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1599 /* parsing name is unchanged */
1600 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FORPARSING, &strret);
1601 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1603 if (SUCCEEDED(hr) && pStrRetToBufW)
1605 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1606 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1607 ok (!lstrcmpiW(tempbufW, foldernameW), "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1610 IShellFolder_Release(IDesktopFolder);
1611 IShellFolder_Release(testIShellFolder);
1613 IMalloc_Free(ppM, newPIDL);
1616 DeleteFileA(".\\testfolder\\desktop.ini");
1617 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")&~FILE_ATTRIBUTE_SYSTEM);
1618 RemoveDirectoryA(".\\testfolder");
1622 START_TEST(shlfolder)
1624 init_function_pointers();
1625 /* if OleInitialize doesn't get called, ParseDisplayName returns
1626 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1627 OleInitialize(NULL);
1629 test_ParseDisplayName();
1630 test_BindToObject();
1631 test_EnumObjects_and_CompareIDs();
1632 test_GetDisplayName();
1633 test_GetAttributesOf();
1634 test_SHGetPathFromIDList();
1635 test_CallForAttributes();
1636 test_FolderShortcut();
1637 test_ITEMIDLIST_format();
1638 if(pSHGetFolderPathAndSubDirA)
1639 testSHGetFolderPathAndSubDirA();
1641 skip("SHGetFolderPathAndSubDirA not present\n");
1642 test_LocalizedNames();