shell32: Add test for SHCreateShellItem.
[wine/multimedia.git] / dlls / shell32 / tests / shlfolder.c
blob0b5d7b2226e941eb06178d9de7b5663ba7c7935f
1 /*
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
25 #define CONST_VTABLE
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wtypes.h"
30 #include "shellapi.h"
33 #include "shlguid.h"
34 #include "shlobj.h"
35 #include "shobjidl.h"
36 #include "shlwapi.h"
37 #include "ocidl.h"
38 #include "oleauto.h"
40 #include "wine/test.h"
43 static IMalloc *ppM;
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);
55 static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);
56 static LPITEMIDLIST (WINAPI *pILCombine)(LPCITEMIDLIST,LPCITEMIDLIST);
59 static void init_function_pointers(void)
61 HMODULE hmod;
62 HRESULT hr;
64 hmod = GetModuleHandleA("shell32.dll");
65 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
66 pSHGetFolderPathA = (void*)GetProcAddress(hmod, "SHGetFolderPathA");
67 pSHGetFolderPathAndSubDirA = (void*)GetProcAddress(hmod, "SHGetFolderPathAndSubDirA");
68 pSHGetPathFromIDListW = (void*)GetProcAddress(hmod, "SHGetPathFromIDListW");
69 pSHGetSpecialFolderPathA = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathA");
70 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
71 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
72 pILFree = (void*)GetProcAddress(hmod, (LPSTR)155);
73 pILIsEqual = (void*)GetProcAddress(hmod, (LPSTR)21);
74 pSHCreateShellItem = (void*)GetProcAddress(hmod, "SHCreateShellItem");
75 pILCombine = (void*)GetProcAddress(hmod, (LPSTR)25);
77 hmod = GetModuleHandleA("shlwapi.dll");
78 pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
80 hr = SHGetMalloc(&ppM);
81 ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
84 static void test_ParseDisplayName(void)
86 HRESULT hr;
87 IShellFolder *IDesktopFolder;
88 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
89 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
90 static const char *cInetTestA = "http:\\yyy";
91 static const char *cInetTest2A = "xx:yyy";
92 DWORD res;
93 WCHAR cTestDirW [MAX_PATH] = {0};
94 ITEMIDLIST *newPIDL;
95 BOOL bRes;
97 hr = SHGetDesktopFolder(&IDesktopFolder);
98 if(hr != S_OK) return;
100 MultiByteToWideChar(CP_ACP, 0, cInetTestA, -1, cTestDirW, MAX_PATH);
101 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
102 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
103 todo_wine ok((SUCCEEDED(hr) || broken(hr == E_FAIL) /* NT4 */),
104 "ParseDisplayName returned %08x, expected SUCCESS or E_FAIL\n", hr);
105 if (SUCCEEDED(hr))
107 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x61, "Last pidl should be of type "
108 "PT_IESPECIAL1, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
109 IMalloc_Free(ppM, newPIDL);
112 MultiByteToWideChar(CP_ACP, 0, cInetTest2A, -1, cTestDirW, MAX_PATH);
113 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
114 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
115 todo_wine ok((SUCCEEDED(hr) || broken(hr == E_FAIL) /* NT4 */),
116 "ParseDisplayName returned %08x, expected SUCCESS or E_FAIL\n", hr);
117 if (SUCCEEDED(hr))
119 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x61, "Last pidl should be of type "
120 "PT_IESPECIAL1, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
121 IMalloc_Free(ppM, newPIDL);
124 res = GetFileAttributesA(cNonExistDir1A);
125 if(res != INVALID_FILE_ATTRIBUTES) return;
127 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
128 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
129 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
130 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
131 "ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr);
133 res = GetFileAttributesA(cNonExistDir2A);
134 if(res != INVALID_FILE_ATTRIBUTES) return;
136 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
137 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
138 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
139 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
140 "ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
142 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
143 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
144 * out it doesn't. The magic seems to happen in the file dialogs, then. */
145 if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
147 bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
148 ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
149 if (!bRes) goto finished;
151 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
152 ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr);
153 if (FAILED(hr)) goto finished;
155 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31 ||
156 pILFindLastID(newPIDL)->mkid.abID[0] == 0xb1, /* Win98 */
157 "Last pidl should be of type PT_FOLDER or PT_IESPECIAL2, but is: %02x\n",
158 pILFindLastID(newPIDL)->mkid.abID[0]);
159 IMalloc_Free(ppM, newPIDL);
161 finished:
162 IShellFolder_Release(IDesktopFolder);
165 /* creates a file with the specified name for tests */
166 static void CreateTestFile(const CHAR *name)
168 HANDLE file;
169 DWORD written;
171 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
172 if (file != INVALID_HANDLE_VALUE)
174 WriteFile(file, name, strlen(name), &written, NULL);
175 WriteFile(file, "\n", strlen("\n"), &written, NULL);
176 CloseHandle(file);
181 /* initializes the tests */
182 static void CreateFilesFolders(void)
184 CreateDirectoryA(".\\testdir", NULL);
185 CreateDirectoryA(".\\testdir\\test.txt", NULL);
186 CreateTestFile (".\\testdir\\test1.txt ");
187 CreateTestFile (".\\testdir\\test2.txt ");
188 CreateTestFile (".\\testdir\\test3.txt ");
189 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
190 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
193 /* cleans after tests */
194 static void Cleanup(void)
196 DeleteFileA(".\\testdir\\test1.txt");
197 DeleteFileA(".\\testdir\\test2.txt");
198 DeleteFileA(".\\testdir\\test3.txt");
199 RemoveDirectoryA(".\\testdir\\test.txt");
200 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
201 RemoveDirectoryA(".\\testdir\\testdir2");
202 RemoveDirectoryA(".\\testdir");
206 /* perform test */
207 static void test_EnumObjects(IShellFolder *iFolder)
209 IEnumIDList *iEnumList;
210 LPITEMIDLIST newPIDL, idlArr[10];
211 ULONG NumPIDLs;
212 int i=0, j;
213 HRESULT hr;
215 static const WORD iResults [5][5] =
217 { 0,-1,-1,-1,-1},
218 { 1, 0,-1,-1,-1},
219 { 1, 1, 0,-1,-1},
220 { 1, 1, 1, 0,-1},
221 { 1, 1, 1, 1, 0}
224 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
225 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
226 static const ULONG attrs[5] =
228 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
229 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
230 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
231 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
232 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
235 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
236 ok(hr == S_OK, "EnumObjects failed %08x\n", hr);
238 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
239 * the filesystem shellfolders return S_OK even if less than 'celt' items are
240 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
241 * only ever returns a single entry per call. */
242 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
243 i += NumPIDLs;
244 ok (i == 5, "i: %d\n", i);
246 hr = IEnumIDList_Release(iEnumList);
247 ok(hr == S_OK, "IEnumIDList_Release failed %08x\n", hr);
249 /* Sort them first in case of wrong order from system */
250 for (i=0;i<5;i++) for (j=0;j<5;j++)
251 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
253 newPIDL = idlArr[i];
254 idlArr[i] = idlArr[j];
255 idlArr[j] = newPIDL;
258 for (i=0;i<5;i++) for (j=0;j<5;j++)
260 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
261 ok(hr == iResults[i][j], "Got %x expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
265 for (i = 0; i < 5; i++)
267 SFGAOF flags;
268 /* Native returns all flags no matter what we ask for */
269 flags = SFGAO_CANCOPY;
270 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
271 flags &= SFGAO_testfor;
272 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
273 ok(flags == (attrs[i]) ||
274 flags == (attrs[i] & ~SFGAO_FILESYSANCESTOR), /* Win9x, NT4 */
275 "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
277 flags = SFGAO_testfor;
278 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
279 flags &= SFGAO_testfor;
280 ok(hr == S_OK, "GetAttributesOf returns %08x\n", hr);
281 ok(flags == attrs[i] ||
282 flags == (attrs[i] & ~SFGAO_FILESYSANCESTOR), /* Win9x, NT4 */
283 "GetAttributesOf[%i] got %08x, expected %08x\n", i, flags, attrs[i]);
286 for (i=0;i<5;i++)
287 IMalloc_Free(ppM, idlArr[i]);
290 static void test_BindToObject(void)
292 HRESULT hr;
293 UINT cChars;
294 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
295 SHITEMID emptyitem = { 0, { 0 } };
296 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
297 WCHAR wszSystemDir[MAX_PATH];
298 char szSystemDir[MAX_PATH];
299 WCHAR wszMyComputer[] = {
300 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
301 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
303 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
304 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
306 hr = SHGetDesktopFolder(&psfDesktop);
307 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
308 if (FAILED(hr)) return;
310 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
311 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
313 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
314 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
316 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
317 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
318 if (FAILED(hr)) {
319 IShellFolder_Release(psfDesktop);
320 return;
323 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
324 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
325 IShellFolder_Release(psfDesktop);
326 IMalloc_Free(ppM, pidlMyComputer);
327 if (FAILED(hr)) return;
329 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
330 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
332 #if 0
333 /* this call segfaults on 98SE */
334 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
335 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
336 #endif
338 cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
339 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
340 if (cChars == 0 || cChars >= MAX_PATH) {
341 IShellFolder_Release(psfMyComputer);
342 return;
344 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
346 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
347 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr);
348 if (FAILED(hr)) {
349 IShellFolder_Release(psfMyComputer);
350 return;
353 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
354 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr);
355 IShellFolder_Release(psfMyComputer);
356 IMalloc_Free(ppM, pidlSystemDir);
357 if (FAILED(hr)) return;
359 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
360 ok (hr == E_INVALIDARG,
361 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr);
363 #if 0
364 /* this call segfaults on 98SE */
365 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
366 ok (hr == E_INVALIDARG,
367 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr);
368 #endif
370 IShellFolder_Release(psfSystemDir);
373 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
374 static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
376 size_t iLen;
378 if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
379 return NULL;
381 if (iLen)
383 lpszPath += iLen;
384 if (lpszPath[-1] != '\\')
386 *lpszPath++ = '\\';
387 *lpszPath = '\0';
390 return lpszPath;
393 static void test_GetDisplayName(void)
395 BOOL result;
396 HRESULT hr;
397 HANDLE hTestFile;
398 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH];
399 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
400 DWORD attr;
401 STRRET strret;
402 LPSHELLFOLDER psfDesktop, psfPersonal;
403 IUnknown *psfFile;
404 SHITEMID emptyitem = { 0, { 0 } };
405 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
406 LPCITEMIDLIST pidlLast;
407 static const CHAR szFileName[] = "winetest.foo";
408 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
409 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
411 /* I'm trying to figure if there is a functional difference between calling
412 * SHGetPathFromIDListW and calling GetDisplayNameOf(SHGDN_FORPARSING) after
413 * binding to the shellfolder. One thing I thought of was that perhaps
414 * SHGetPathFromIDListW would be able to get the path to a file, which does
415 * not exist anymore, while the other method wouldn't. It turns out there's
416 * no functional difference in this respect.
419 if(!pSHGetSpecialFolderPathA) {
420 win_skip("SHGetSpecialFolderPathA is not available\n");
421 return;
424 /* First creating a directory in MyDocuments and a file in this directory. */
425 result = pSHGetSpecialFolderPathA(NULL, szTestDir, CSIDL_PERSONAL, FALSE);
426 ok(result, "SHGetSpecialFolderPathA failed! Last error: %u\n", GetLastError());
427 if (!result) return;
429 /* Use ANSI file functions so this works on Windows 9x */
430 lstrcatA(szTestDir, "\\winetest");
431 CreateDirectoryA(szTestDir, NULL);
432 attr=GetFileAttributesA(szTestDir);
433 if (attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY))
435 ok(0, "unable to create the '%s' directory\n", szTestDir);
436 return;
439 lstrcpyA(szTestFile, szTestDir);
440 lstrcatA(szTestFile, "\\");
441 lstrcatA(szTestFile, szFileName);
442 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
443 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %u\n", GetLastError());
444 if (hTestFile == INVALID_HANDLE_VALUE) return;
445 CloseHandle(hTestFile);
447 /* Getting an itemidlist for the file. */
448 hr = SHGetDesktopFolder(&psfDesktop);
449 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
450 if (FAILED(hr)) return;
452 MultiByteToWideChar(CP_ACP, 0, szTestFile, -1, wszTestFile, MAX_PATH);
454 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
455 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08x\n", hr);
456 if (FAILED(hr)) {
457 IShellFolder_Release(psfDesktop);
458 return;
461 pidlLast = pILFindLastID(pidlTestFile);
462 ok(pidlLast->mkid.cb >=76 ||
463 broken(pidlLast->mkid.cb == 28) || /* W2K */
464 broken(pidlLast->mkid.cb == 40), /* Win9x, WinME */
465 "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
466 if (pidlLast->mkid.cb >= 28) {
467 ok(!lstrcmpA((CHAR*)&pidlLast->mkid.abID[12], szFileName),
468 "Filename should be stored as ansi-string at this position!\n");
470 /* WinXP and up store the filenames as both ANSI and UNICODE in the pidls */
471 if (pidlLast->mkid.cb >= 76) {
472 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
473 "Filename should be stored as wchar-string at this position!\n");
476 /* It seems as if we cannot bind to regular files on windows, but only directories.
478 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
479 todo_wine
480 ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
481 broken(SUCCEEDED(hr)), /* Win9x, W2K */
482 "hr = %08x\n", hr);
483 if (SUCCEEDED(hr)) {
484 IShellFolder_Release(psfFile);
487 if (!pSHBindToParent)
489 win_skip("SHBindToParent is missing\n");
490 DeleteFileA(szTestFile);
491 RemoveDirectoryA(szTestDir);
492 return;
495 /* Some tests for IShellFolder::SetNameOf */
496 if (pSHGetFolderPathAndSubDirA)
498 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
499 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
500 if (SUCCEEDED(hr)) {
501 /* It's ok to use this fixed path. Call will fail anyway. */
502 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
503 LPITEMIDLIST pidlNew;
505 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
506 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
507 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
508 if (hr == S_OK)
510 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
511 "pidl returned from SetNameOf should be simple!\n");
513 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
514 * is implemented on top of SHFileOperation in WinXP. */
515 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
516 SHGDN_FORPARSING, NULL);
517 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08x\n", hr);
519 /* Rename the file back to its original name. SetNameOf ignores the fact, that the
520 * SHGDN flags specify an absolute path. */
521 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
522 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08x\n", hr);
524 pILFree(pidlNew);
527 IShellFolder_Release(psfPersonal);
530 else
531 win_skip("Avoid needs of interaction on Win2k\n");
533 /* Deleting the file and the directory */
534 DeleteFileA(szTestFile);
535 RemoveDirectoryA(szTestDir);
537 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
538 if (pSHGetPathFromIDListW)
540 result = pSHGetPathFromIDListW(pidlTestFile, wszTestFile2);
541 ok (result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
542 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
545 /* SHBindToParent fails, if called with a NULL PIDL. */
546 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
547 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
549 /* But it succeeds with an empty PIDL. */
550 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
551 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr);
552 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
553 if (SUCCEEDED(hr))
554 IShellFolder_Release(psfPersonal);
556 /* Binding to the folder and querying the display name of the file also works. */
557 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
558 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08x\n", hr);
559 if (FAILED(hr)) {
560 IShellFolder_Release(psfDesktop);
561 return;
564 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
565 * pidlTestFile (In accordance with MSDN). */
566 ok (pILFindLastID(pidlTestFile) == pidlLast,
567 "SHBindToParent doesn't return the last id of the pidl param!\n");
569 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
570 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr);
571 if (FAILED(hr)) {
572 IShellFolder_Release(psfDesktop);
573 IShellFolder_Release(psfPersonal);
574 return;
577 if (pStrRetToBufW)
579 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
580 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
581 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
584 IShellFolder_Release(psfDesktop);
585 IShellFolder_Release(psfPersonal);
588 static void test_CallForAttributes(void)
590 HKEY hKey;
591 LONG lResult;
592 HRESULT hr;
593 DWORD dwSize;
594 LPSHELLFOLDER psfDesktop;
595 LPITEMIDLIST pidlMyDocuments;
596 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
597 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
598 static const WCHAR wszCallForAttributes[] = {
599 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
600 static const WCHAR wszMyDocumentsKey[] = {
601 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
602 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
603 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
604 WCHAR wszMyDocuments[] = {
605 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
606 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
608 /* For the root of a namespace extension, the attributes are not queried by binding
609 * to the object and calling GetAttributesOf. Instead, the attributes are read from
610 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
612 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
613 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
614 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
615 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
617 hr = SHGetDesktopFolder(&psfDesktop);
618 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
619 if (FAILED(hr)) return;
621 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
622 &pidlMyDocuments, NULL);
623 ok (SUCCEEDED(hr) ||
624 broken(hr == E_INVALIDARG), /* Win95, NT4 */
625 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr);
626 if (FAILED(hr)) {
627 IShellFolder_Release(psfDesktop);
628 return;
631 dwAttributes = 0xffffffff;
632 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
633 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
634 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
636 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
637 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
638 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
639 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
641 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
642 * key. So the test will return at this point, if run on wine.
644 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
645 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08x\n", lResult);
646 if (lResult != ERROR_SUCCESS) {
647 IMalloc_Free(ppM, pidlMyDocuments);
648 IShellFolder_Release(psfDesktop);
649 return;
652 /* Query MyDocuments' Attributes value, to be able to restore it later. */
653 dwSize = sizeof(DWORD);
654 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
655 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
656 if (lResult != ERROR_SUCCESS) {
657 RegCloseKey(hKey);
658 IMalloc_Free(ppM, pidlMyDocuments);
659 IShellFolder_Release(psfDesktop);
660 return;
663 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
664 dwSize = sizeof(DWORD);
665 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
666 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
667 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08x\n", lResult);
668 if (lResult != ERROR_SUCCESS) {
669 RegCloseKey(hKey);
670 IMalloc_Free(ppM, pidlMyDocuments);
671 IShellFolder_Release(psfDesktop);
672 return;
675 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
676 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
677 * SFGAO_FILESYSTEM attributes. */
678 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
679 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
680 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
681 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
682 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
684 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
685 * GetAttributesOf. It seems that once there is a single attribute queried, for which
686 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
687 * the flags in Attributes are ignored.
689 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
690 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
691 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
692 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr);
693 if (SUCCEEDED(hr))
694 ok (dwAttributes == SFGAO_FILESYSTEM,
695 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n",
696 dwAttributes);
698 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
699 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
700 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
701 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
702 RegCloseKey(hKey);
703 IMalloc_Free(ppM, pidlMyDocuments);
704 IShellFolder_Release(psfDesktop);
707 static void test_GetAttributesOf(void)
709 HRESULT hr;
710 LPSHELLFOLDER psfDesktop, psfMyComputer;
711 SHITEMID emptyitem = { 0, { 0 } };
712 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
713 LPITEMIDLIST pidlMyComputer;
714 DWORD dwFlags;
715 static const DWORD desktopFlags[] = {
716 /* WinXP */
717 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR | SFGAO_FILESYSANCESTOR |
718 SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER,
719 /* Win2k */
720 SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_STREAM | SFGAO_FILESYSANCESTOR |
721 SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER,
722 /* WinMe, Win9x, WinNT*/
723 SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_FILESYSANCESTOR |
724 SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER
726 static const DWORD myComputerFlags[] = {
727 /* WinXP */
728 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET |
729 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER,
730 /* Win2k */
731 SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET | SFGAO_STREAM |
732 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER,
733 /* WinMe, Win9x, WinNT */
734 SFGAO_CANRENAME | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR |
735 SFGAO_FOLDER | SFGAO_HASSUBFOLDER,
736 /* Win95, WinNT when queried directly */
737 SFGAO_CANLINK | SFGAO_HASPROPSHEET | SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR |
738 SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER
740 WCHAR wszMyComputer[] = {
741 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
742 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
743 char cCurrDirA [MAX_PATH] = {0};
744 WCHAR cCurrDirW [MAX_PATH];
745 static WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
746 IShellFolder *IDesktopFolder, *testIShellFolder;
747 ITEMIDLIST *newPIDL;
748 int len, i;
749 BOOL foundFlagsMatch;
751 hr = SHGetDesktopFolder(&psfDesktop);
752 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
753 if (FAILED(hr)) return;
755 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
756 dwFlags = 0xffffffff;
757 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
758 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr);
759 for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
760 i < sizeof(desktopFlags) / sizeof(desktopFlags[0]); i++)
762 if (desktopFlags[i] == dwFlags)
763 foundFlagsMatch = TRUE;
765 ok (foundFlagsMatch, "Wrong Desktop attributes: %08x\n", dwFlags);
767 /* .. or with no itemidlist at all. */
768 dwFlags = 0xffffffff;
769 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
770 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
771 for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
772 i < sizeof(desktopFlags) / sizeof(desktopFlags[0]); i++)
774 if (desktopFlags[i] == dwFlags)
775 foundFlagsMatch = TRUE;
777 ok (foundFlagsMatch, "Wrong Desktop attributes: %08x\n", dwFlags);
779 /* Testing the attributes of the MyComputer shellfolder */
780 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
781 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
782 if (FAILED(hr)) {
783 IShellFolder_Release(psfDesktop);
784 return;
787 /* Windows sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
788 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
790 dwFlags = 0xffffffff;
791 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
792 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr);
793 for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
794 i < sizeof(myComputerFlags) / sizeof(myComputerFlags[0]); i++)
796 if ((myComputerFlags[i] | SFGAO_CANLINK) == dwFlags)
797 foundFlagsMatch = TRUE;
799 todo_wine
800 ok (foundFlagsMatch, "Wrong MyComputer attributes: %08x\n", dwFlags);
802 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
803 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr);
804 IShellFolder_Release(psfDesktop);
805 IMalloc_Free(ppM, pidlMyComputer);
806 if (FAILED(hr)) return;
808 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
809 todo_wine
810 ok (hr == E_INVALIDARG ||
811 broken(SUCCEEDED(hr)), /* W2K and earlier */
812 "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr);
814 dwFlags = 0xffffffff;
815 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
816 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr);
817 for (i = 0, foundFlagsMatch = FALSE; !foundFlagsMatch &&
818 i < sizeof(myComputerFlags) / sizeof(myComputerFlags[0]); i++)
820 if (myComputerFlags[i] == dwFlags)
821 foundFlagsMatch = TRUE;
823 todo_wine
824 ok (foundFlagsMatch, "Wrong MyComputer attributes: %08x\n", dwFlags);
826 IShellFolder_Release(psfMyComputer);
828 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
829 len = lstrlenA(cCurrDirA);
831 if (len == 0) {
832 win_skip("GetCurrentDirectoryA returned empty string. Skipping test_GetAttributesOf\n");
833 return;
835 if (len > 3 && cCurrDirA[len-1] == '\\')
836 cCurrDirA[len-1] = 0;
838 /* create test directory */
839 CreateFilesFolders();
841 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
843 hr = SHGetDesktopFolder(&IDesktopFolder);
844 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
846 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
847 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
849 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
850 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
852 IMalloc_Free(ppM, newPIDL);
854 /* get relative PIDL */
855 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
856 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
858 /* test the shell attributes of the test directory using the relative PIDL */
859 dwFlags = SFGAO_FOLDER;
860 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
861 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
862 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags);
864 /* free memory */
865 IMalloc_Free(ppM, newPIDL);
867 /* append testdirectory name to path */
868 if (cCurrDirA[len-1] == '\\')
869 cCurrDirA[len-1] = 0;
870 lstrcatA(cCurrDirA, "\\testdir");
871 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
873 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
874 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
876 /* test the shell attributes of the test directory using the absolute PIDL */
877 dwFlags = SFGAO_FOLDER;
878 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
879 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr);
880 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags);
882 /* free memory */
883 IMalloc_Free(ppM, newPIDL);
885 IShellFolder_Release(testIShellFolder);
887 Cleanup();
889 IShellFolder_Release(IDesktopFolder);
892 static void test_SHGetPathFromIDList(void)
894 SHITEMID emptyitem = { 0, { 0 } };
895 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
896 LPITEMIDLIST pidlMyComputer;
897 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
898 BOOL result;
899 HRESULT hr;
900 LPSHELLFOLDER psfDesktop;
901 WCHAR wszMyComputer[] = {
902 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
903 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
904 WCHAR wszFileName[MAX_PATH];
905 LPITEMIDLIST pidlTestFile;
906 HANDLE hTestFile;
907 STRRET strret;
908 static WCHAR wszTestFile[] = {
909 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
910 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
911 HMODULE hShell32;
912 LPITEMIDLIST pidlPrograms;
914 if(!pSHGetPathFromIDListW || !pSHGetSpecialFolderPathW)
916 win_skip("SHGetPathFromIDListW() or SHGetSpecialFolderPathW() is missing\n");
917 return;
920 /* Calling SHGetPathFromIDListW with no pidl should return the empty string */
921 wszPath[0] = 'a';
922 wszPath[1] = '\0';
923 result = pSHGetPathFromIDListW(NULL, wszPath);
924 ok(!result, "Expected failure\n");
925 ok(!wszPath[0], "Expected empty string\n");
927 /* Calling SHGetPathFromIDListW with an empty pidl should return the desktop folder's path. */
928 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
929 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
930 if (!result) return;
932 /* Check if we are on Win9x */
933 SetLastError(0xdeadbeef);
934 lstrcmpiW(wszDesktop, wszDesktop);
935 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
937 win_skip("Most W-calls are not implemented\n");
938 return;
941 result = pSHGetPathFromIDListW(pidlEmpty, wszPath);
942 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
943 if (!result) return;
944 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDListW didn't return desktop path for empty pidl!\n");
946 /* MyComputer does not map to a filesystem path. SHGetPathFromIDListW should fail. */
947 hr = SHGetDesktopFolder(&psfDesktop);
948 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
949 if (FAILED(hr)) return;
951 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
952 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr);
953 if (FAILED(hr)) {
954 IShellFolder_Release(psfDesktop);
955 return;
958 SetLastError(0xdeadbeef);
959 wszPath[0] = 'a';
960 wszPath[1] = '\0';
961 result = pSHGetPathFromIDListW(pidlMyComputer, wszPath);
962 ok (!result, "SHGetPathFromIDListW succeeded where it shouldn't!\n");
963 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDListW shouldn't set last error! Last error: %u\n", GetLastError());
964 ok (!wszPath[0], "Expected empty path\n");
965 if (result) {
966 IShellFolder_Release(psfDesktop);
967 return;
970 IMalloc_Free(ppM, pidlMyComputer);
972 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
973 ok(result, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
974 if (!result) {
975 IShellFolder_Release(psfDesktop);
976 return;
978 myPathAddBackslashW(wszFileName);
979 lstrcatW(wszFileName, wszTestFile);
980 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
981 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %u\n", GetLastError());
982 if (hTestFile == INVALID_HANDLE_VALUE) {
983 IShellFolder_Release(psfDesktop);
984 return;
986 CloseHandle(hTestFile);
988 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
989 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr);
990 if (FAILED(hr)) {
991 IShellFolder_Release(psfDesktop);
992 DeleteFileW(wszFileName);
993 IMalloc_Free(ppM, pidlTestFile);
994 return;
997 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
998 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
999 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
1000 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr);
1001 IShellFolder_Release(psfDesktop);
1002 DeleteFileW(wszFileName);
1003 if (FAILED(hr)) {
1004 IMalloc_Free(ppM, pidlTestFile);
1005 return;
1007 if (pStrRetToBufW)
1009 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
1010 ok(0 == lstrcmpW(wszFileName, wszPath),
1011 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
1012 "returned incorrect path for file placed on desktop\n");
1015 result = pSHGetPathFromIDListW(pidlTestFile, wszPath);
1016 ok(result, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
1017 IMalloc_Free(ppM, pidlTestFile);
1018 if (!result) return;
1019 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
1022 /* Test if we can get the path from the start menu "program files" PIDL. */
1023 hShell32 = GetModuleHandleA("shell32");
1024 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
1026 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
1027 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08x\n", hr);
1029 SetLastError(0xdeadbeef);
1030 result = pSHGetPathFromIDListW(pidlPrograms, wszPath);
1031 IMalloc_Free(ppM, pidlPrograms);
1032 ok(result, "SHGetPathFromIDListW failed\n");
1035 static void test_EnumObjects_and_CompareIDs(void)
1037 ITEMIDLIST *newPIDL;
1038 IShellFolder *IDesktopFolder, *testIShellFolder;
1039 char cCurrDirA [MAX_PATH] = {0};
1040 static const CHAR cTestDirA[] = "\\testdir";
1041 WCHAR cTestDirW[MAX_PATH];
1042 int len;
1043 HRESULT hr;
1045 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
1046 len = lstrlenA(cCurrDirA);
1048 if(len == 0) {
1049 win_skip("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
1050 return;
1052 if(cCurrDirA[len-1] == '\\')
1053 cCurrDirA[len-1] = 0;
1055 lstrcatA(cCurrDirA, cTestDirA);
1056 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cTestDirW, MAX_PATH);
1058 hr = SHGetDesktopFolder(&IDesktopFolder);
1059 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
1061 CreateFilesFolders();
1063 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
1064 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1066 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
1067 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
1069 test_EnumObjects(testIShellFolder);
1071 IShellFolder_Release(testIShellFolder);
1073 Cleanup();
1075 IMalloc_Free(ppM, newPIDL);
1077 IShellFolder_Release(IDesktopFolder);
1080 /* A simple implementation of an IPropertyBag, which returns fixed values for
1081 * 'Target' and 'Attributes' properties.
1083 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
1084 void **ppvObject)
1086 if (!ppvObject)
1087 return E_INVALIDARG;
1089 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
1090 *ppvObject = iface;
1091 } else {
1092 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
1093 return E_NOINTERFACE;
1096 IPropertyBag_AddRef(iface);
1097 return S_OK;
1100 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
1101 return 2;
1104 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
1105 return 1;
1108 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
1109 VARIANT *pVar, IErrorLog *pErrorLog)
1111 static const WCHAR wszTargetSpecialFolder[] = {
1112 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
1113 static const WCHAR wszTarget[] = {
1114 'T','a','r','g','e','t',0 };
1115 static const WCHAR wszAttributes[] = {
1116 'A','t','t','r','i','b','u','t','e','s',0 };
1117 static const WCHAR wszResolveLinkFlags[] = {
1118 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
1120 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
1121 ok(V_VT(pVar) == VT_I4 ||
1122 broken(V_VT(pVar) == VT_BSTR), /* Win2k */
1123 "Wrong variant type for 'TargetSpecialFolder' property!\n");
1124 return E_INVALIDARG;
1127 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
1129 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
1130 return E_INVALIDARG;
1133 if (!lstrcmpW(pszPropName, wszTarget)) {
1134 WCHAR wszPath[MAX_PATH];
1135 BOOL result;
1137 ok(V_VT(pVar) == VT_BSTR ||
1138 broken(V_VT(pVar) == VT_EMPTY), /* Win2k */
1139 "Wrong variant type for 'Target' property!\n");
1140 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
1142 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1143 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1144 if (!result) return E_INVALIDARG;
1146 V_BSTR(pVar) = SysAllocString(wszPath);
1147 return S_OK;
1150 if (!lstrcmpW(pszPropName, wszAttributes)) {
1151 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
1152 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
1153 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
1154 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
1155 return S_OK;
1158 ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
1159 return E_INVALIDARG;
1162 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
1163 VARIANT *pVar)
1165 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
1166 return E_NOTIMPL;
1169 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1170 InitPropertyBag_IPropertyBag_QueryInterface,
1171 InitPropertyBag_IPropertyBag_AddRef,
1172 InitPropertyBag_IPropertyBag_Release,
1173 InitPropertyBag_IPropertyBag_Read,
1174 InitPropertyBag_IPropertyBag_Write
1177 static struct IPropertyBag InitPropertyBag = {
1178 &InitPropertyBag_IPropertyBagVtbl
1181 static void test_FolderShortcut(void) {
1182 IPersistPropertyBag *pPersistPropertyBag;
1183 IShellFolder *pShellFolder, *pDesktopFolder;
1184 IPersistFolder3 *pPersistFolder3;
1185 HRESULT hr;
1186 STRRET strret;
1187 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1188 BOOL result;
1189 CLSID clsid;
1190 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1191 HKEY hShellExtKey;
1192 WCHAR wszWineTestFolder[] = {
1193 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1194 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1195 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1196 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1197 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1198 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1199 'N','a','m','e','S','p','a','c','e','\\',
1200 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1201 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1203 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1204 static const GUID CLSID_UnixDosFolder =
1205 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1207 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) {
1208 win_skip("SHGetSpecialFolderPathW and/or StrRetToBufW are not available\n");
1209 return;
1212 if (!pSHGetFolderPathAndSubDirA)
1214 win_skip("FolderShortcut test doesn't work on Win2k\n");
1215 return;
1218 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1219 * via their IPersistPropertyBag interface. And that the target folder
1220 * is taken from the IPropertyBag's 'Target' property.
1222 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1223 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1224 if (hr == REGDB_E_CLASSNOTREG) {
1225 win_skip("CLSID_FolderShortcut is not implemented\n");
1226 return;
1228 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08x\n", hr);
1229 if (FAILED(hr)) return;
1231 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1232 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08x\n", hr);
1233 if (FAILED(hr)) {
1234 IPersistPropertyBag_Release(pPersistPropertyBag);
1235 return;
1238 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1239 (LPVOID*)&pShellFolder);
1240 IPersistPropertyBag_Release(pPersistPropertyBag);
1241 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1242 if (FAILED(hr)) return;
1244 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1245 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1246 if (FAILED(hr)) {
1247 IShellFolder_Release(pShellFolder);
1248 return;
1251 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1252 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1253 if (!result) return;
1255 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1256 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1258 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1259 IShellFolder_Release(pShellFolder);
1260 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr);
1261 if (FAILED(hr)) return;
1263 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1264 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1265 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1267 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1268 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1269 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1271 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1272 * shell namespace. The target folder, read from the property bag above, remains untouched.
1273 * The following tests show this: The itemidlist for some imaginary shellfolder object
1274 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1275 * itemidlist, but GetDisplayNameOf still returns the path from above.
1277 hr = SHGetDesktopFolder(&pDesktopFolder);
1278 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08x\n", hr);
1279 if (FAILED(hr)) return;
1281 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1282 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1283 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1284 RegCloseKey(hShellExtKey);
1285 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1286 &pidlWineTestFolder, NULL);
1287 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1288 IShellFolder_Release(pDesktopFolder);
1289 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1290 if (FAILED(hr)) return;
1292 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1293 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08x\n", hr);
1294 if (FAILED(hr)) {
1295 IPersistFolder3_Release(pPersistFolder3);
1296 pILFree(pidlWineTestFolder);
1297 return;
1300 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1301 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr);
1302 ok(pILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1303 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1304 pILFree(pidlCurrentFolder);
1305 pILFree(pidlWineTestFolder);
1307 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1308 IPersistFolder3_Release(pPersistFolder3);
1309 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr);
1310 if (FAILED(hr)) return;
1312 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1313 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr);
1314 if (FAILED(hr)) {
1315 IShellFolder_Release(pShellFolder);
1316 return;
1319 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1320 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1322 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1323 * but ShellFSFolders. */
1324 myPathAddBackslashW(wszDesktopPath);
1325 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1326 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1327 IShellFolder_Release(pShellFolder);
1328 return;
1331 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1332 &pidlSubFolder, NULL);
1333 RemoveDirectoryW(wszDesktopPath);
1334 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr);
1335 if (FAILED(hr)) {
1336 IShellFolder_Release(pShellFolder);
1337 return;
1340 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1341 (LPVOID*)&pPersistFolder3);
1342 IShellFolder_Release(pShellFolder);
1343 pILFree(pidlSubFolder);
1344 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08x\n", hr);
1345 if (FAILED(hr))
1346 return;
1348 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1349 * a little bit and also allow CLSID_UnixDosFolder. */
1350 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1351 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr);
1352 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1353 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1355 IPersistFolder3_Release(pPersistFolder3);
1358 #include "pshpack1.h"
1359 struct FileStructA {
1360 BYTE type;
1361 BYTE dummy;
1362 DWORD dwFileSize;
1363 WORD uFileDate; /* In our current implementation this is */
1364 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1365 WORD uFileAttribs;
1366 CHAR szName[1];
1369 struct FileStructW {
1370 WORD cbLen; /* Length of this element. */
1371 BYTE abFooBar1[6]; /* Beyond any recognition. */
1372 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1373 WORD uTime; /* (this is currently speculation) */
1374 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1375 WORD uTime2; /* (this is currently speculation) */
1376 BYTE abFooBar2[4]; /* Beyond any recognition. */
1377 WCHAR wszName[1]; /* The long filename in unicode. */
1378 /* Just for documentation: Right after the unicode string: */
1379 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1380 * SHITEMID->cb == uOffset + cbLen */
1382 #include "poppack.h"
1384 static void test_ITEMIDLIST_format(void) {
1385 WCHAR wszPersonal[MAX_PATH];
1386 LPSHELLFOLDER psfDesktop, psfPersonal;
1387 LPITEMIDLIST pidlPersonal, pidlFile;
1388 HANDLE hFile;
1389 HRESULT hr;
1390 BOOL bResult;
1391 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1392 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1393 int i;
1395 if (!pSHGetSpecialFolderPathW) return;
1397 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1398 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1399 if (!bResult) return;
1401 SetLastError(0xdeadbeef);
1402 bResult = SetCurrentDirectoryW(wszPersonal);
1403 if (!bResult && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
1404 win_skip("Most W-calls are not implemented\n");
1405 return;
1407 ok(bResult, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1408 if (!bResult) return;
1410 hr = SHGetDesktopFolder(&psfDesktop);
1411 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08x\n", hr);
1412 if (FAILED(hr)) return;
1414 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1415 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr);
1416 if (FAILED(hr)) {
1417 IShellFolder_Release(psfDesktop);
1418 return;
1421 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1422 (LPVOID*)&psfPersonal);
1423 IShellFolder_Release(psfDesktop);
1424 pILFree(pidlPersonal);
1425 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08x\n", hr);
1426 if (FAILED(hr)) return;
1428 for (i=0; i<3; i++) {
1429 CHAR szFile[MAX_PATH];
1430 struct FileStructA *pFileStructA;
1431 WORD cbOffset;
1433 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1435 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1436 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%u)\n", GetLastError());
1437 if (hFile == INVALID_HANDLE_VALUE) {
1438 IShellFolder_Release(psfPersonal);
1439 return;
1441 CloseHandle(hFile);
1443 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1444 DeleteFileW(wszFile[i]);
1445 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr);
1446 if (FAILED(hr)) {
1447 IShellFolder_Release(psfPersonal);
1448 return;
1451 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1452 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1453 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1454 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1456 if (i < 2) /* First two file names are already in valid 8.3 format */
1457 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1458 else
1459 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1460 * can't implement this correctly, since unix filesystems don't support
1461 * this nasty short/long filename stuff. So we'll probably stay with our
1462 * current habbit of storing the long filename here, which seems to work
1463 * just fine. */
1464 todo_wine
1465 ok(pidlFile->mkid.abID[18] == '~' ||
1466 broken(pidlFile->mkid.abID[34] == '~'), /* Win2k */
1467 "Should be derived 8.3 name!\n");
1469 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1470 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0' ||
1471 broken(pidlFile->mkid.cb == 2 + 12 + strlen(szFile) + 1 + 1), /* Win2k */
1472 "Alignment byte, where there shouldn't be!\n");
1474 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1475 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1476 "There should be an alignment byte, but isn't!\n");
1478 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1479 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1480 ok ((cbOffset >= sizeof(struct FileStructA) &&
1481 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW)) ||
1482 broken(pidlFile->mkid.cb == 2 + 12 + strlen(szFile) + 1 + 1) || /* Win2k on short names */
1483 broken(pidlFile->mkid.cb == 2 + 12 + strlen(szFile) + 1 + 12 + 1), /* Win2k on long names */
1484 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1486 if (cbOffset >= sizeof(struct FileStructA) &&
1487 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1489 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1491 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1492 "FileStructW's offset and length should add up to the PIDL's length!\n");
1494 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1495 /* Since we just created the file, time of creation,
1496 * time of last access and time of last write access just be the same.
1497 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1498 * after the first run. I do remember something with NTFS keeping the creation time
1499 * if a file is deleted and then created again within a couple of seconds or so.
1500 * Might be the reason. */
1501 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1502 pFileStructA->uFileTime == pFileStructW->uTime,
1503 "Last write time should match creation time!\n");
1505 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1506 pFileStructA->uFileTime == pFileStructW->uTime2,
1507 "Last write time should match last access time!\n");
1509 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName) ||
1510 !lstrcmpW(wszFile[i], (WCHAR *)(pFileStructW->abFooBar2 + 22)), /* Vista */
1511 "The filename should be stored in unicode at this position!\n");
1515 pILFree(pidlFile);
1519 static void testSHGetFolderPathAndSubDirA(void)
1521 HRESULT ret;
1522 BOOL delret;
1523 DWORD dwret;
1524 int i;
1525 static char wine[] = "wine";
1526 static char winetemp[] = "wine\\temp";
1527 static char appdata[MAX_PATH];
1528 static char testpath[MAX_PATH];
1529 static char toolongpath[MAX_PATH+1];
1531 if(!pSHGetFolderPathA) {
1532 skip("SHGetFolderPathA not present!\n");
1533 return;
1535 if(FAILED(pSHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdata)))
1537 skip("SHGetFolderPathA failed for CSIDL_LOCAL_APPDATA!\n");
1538 return;
1541 sprintf(testpath, "%s\\%s", appdata, winetemp);
1542 delret = RemoveDirectoryA(testpath);
1543 if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) ) {
1544 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1545 return;
1548 sprintf(testpath, "%s\\%s", appdata, wine);
1549 delret = RemoveDirectoryA(testpath);
1550 if(!delret && (ERROR_PATH_NOT_FOUND != GetLastError()) && (ERROR_FILE_NOT_FOUND != GetLastError())) {
1551 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath, GetLastError());
1552 return;
1554 for(i=0; i< MAX_PATH; i++)
1555 toolongpath[i] = '0' + i % 10;
1556 toolongpath[MAX_PATH] = '\0';
1558 /* test invalid second parameter */
1559 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | 0xff, NULL, SHGFP_TYPE_CURRENT, wine, testpath);
1560 ok(E_INVALIDARG == ret, "expected E_INVALIDARG, got %x\n", ret);
1562 /* test invalid forth parameter */
1563 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, 2, wine, testpath);
1564 switch(ret) {
1565 case S_OK: /* winvista */
1566 ok(!strncmp(appdata, testpath, strlen(appdata)),
1567 "expected %s to start with %s\n", testpath, appdata);
1568 ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1569 "expected %s to end with %s\n", testpath, winetemp);
1570 break;
1571 case E_INVALIDARG: /* winxp, win2k3 */
1572 break;
1573 default:
1574 ok(0, "expected S_OK or E_INVALIDARG, got %x\n", ret);
1577 /* test fifth parameter */
1578 testpath[0] = '\0';
1579 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, NULL, testpath);
1580 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1581 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1583 testpath[0] = '\0';
1584 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "", testpath);
1585 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1586 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1588 testpath[0] = '\0';
1589 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, "\\", testpath);
1590 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1591 ok(!lstrcmpA(appdata, testpath), "expected %s, got %s\n", appdata, testpath);
1593 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, toolongpath, testpath);
1594 ok(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE) == ret,
1595 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE), ret);
1597 testpath[0] = '\0';
1598 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, wine, NULL);
1599 ok((S_OK == ret) || (E_INVALIDARG == ret), "expected S_OK or E_INVALIDARG, got %x\n", ret);
1601 /* test a not existing path */
1602 testpath[0] = '\0';
1603 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1604 ok(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == ret,
1605 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), ret);
1607 /* create a directory inside a not existing directory */
1608 testpath[0] = '\0';
1609 ret = pSHGetFolderPathAndSubDirA(NULL, CSIDL_FLAG_CREATE | CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, winetemp, testpath);
1610 ok(S_OK == ret, "expected S_OK, got %x\n", ret);
1611 ok(!strncmp(appdata, testpath, strlen(appdata)),
1612 "expected %s to start with %s\n", testpath, appdata);
1613 ok(!lstrcmpA(&testpath[1 + strlen(appdata)], winetemp),
1614 "expected %s to end with %s\n", testpath, winetemp);
1615 dwret = GetFileAttributes(testpath);
1616 ok(FILE_ATTRIBUTE_DIRECTORY | dwret, "expected %x to contain FILE_ATTRIBUTE_DIRECTORY\n", dwret);
1618 /* cleanup */
1619 sprintf(testpath, "%s\\%s", appdata, winetemp);
1620 RemoveDirectoryA(testpath);
1621 sprintf(testpath, "%s\\%s", appdata, wine);
1622 RemoveDirectoryA(testpath);
1625 static const char *wine_dbgstr_w(LPCWSTR str)
1627 static char buf[512];
1628 if (!str)
1629 return "(null)";
1630 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
1631 return buf;
1634 static void test_LocalizedNames(void)
1636 static char cCurrDirA[MAX_PATH];
1637 WCHAR cCurrDirW[MAX_PATH], tempbufW[25];
1638 IShellFolder *IDesktopFolder, *testIShellFolder;
1639 ITEMIDLIST *newPIDL;
1640 int len;
1641 HRESULT hr;
1642 static char resourcefile[MAX_PATH];
1643 DWORD res;
1644 HANDLE file;
1645 STRRET strret;
1647 static const char desktopini_contents1[] =
1648 "[.ShellClassInfo]\r\n"
1649 "LocalizedResourceName=@";
1650 static const char desktopini_contents2[] =
1651 ",-1\r\n";
1652 static WCHAR foldernameW[] = {'t','e','s','t','f','o','l','d','e','r',0};
1653 static const WCHAR folderdisplayW[] = {'F','o','l','d','e','r',' ','N','a','m','e',' ','R','e','s','o','u','r','c','e',0};
1655 /* create folder with desktop.ini and localized name in GetModuleFileNameA(NULL) */
1656 CreateDirectoryA(".\\testfolder", NULL);
1658 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")|FILE_ATTRIBUTE_SYSTEM);
1660 GetModuleFileNameA(NULL, resourcefile, MAX_PATH);
1662 file = CreateFileA(".\\testfolder\\desktop.ini", GENERIC_WRITE, 0, NULL,
1663 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1664 ok(file != INVALID_HANDLE_VALUE, "CreateFileA failed %i\n", GetLastError());
1665 ok(WriteFile(file, desktopini_contents1, strlen(desktopini_contents1), &res, NULL) &&
1666 WriteFile(file, resourcefile, strlen(resourcefile), &res, NULL) &&
1667 WriteFile(file, desktopini_contents2, strlen(desktopini_contents2), &res, NULL),
1668 "WriteFile failed %i\n", GetLastError());
1669 CloseHandle(file);
1671 /* get IShellFolder for parent */
1672 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
1673 len = lstrlenA(cCurrDirA);
1675 if (len == 0) {
1676 trace("GetCurrentDirectoryA returned empty string. Skipping test_LocalizedNames\n");
1677 goto cleanup;
1679 if(cCurrDirA[len-1] == '\\')
1680 cCurrDirA[len-1] = 0;
1682 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
1684 hr = SHGetDesktopFolder(&IDesktopFolder);
1685 ok(hr == S_OK, "SHGetDesktopfolder failed %08x\n", hr);
1687 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
1688 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1690 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
1691 ok(hr == S_OK, "BindToObject failed %08x\n", hr);
1693 IMalloc_Free(ppM, newPIDL);
1695 /* windows reads the display name from the resource */
1696 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, foldernameW, NULL, &newPIDL, 0);
1697 ok(hr == S_OK, "ParseDisplayName failed %08x\n", hr);
1699 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER, &strret);
1700 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1702 if (SUCCEEDED(hr) && pStrRetToBufW)
1704 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1705 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1706 todo_wine
1707 ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1708 broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1709 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1712 /* editing name is also read from the resource */
1713 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FOREDITING, &strret);
1714 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1716 if (SUCCEEDED(hr) && pStrRetToBufW)
1718 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1719 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1720 todo_wine
1721 ok (!lstrcmpiW(tempbufW, folderdisplayW) ||
1722 broken(!lstrcmpiW(tempbufW, foldernameW)), /* W2K */
1723 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1726 /* parsing name is unchanged */
1727 hr = IShellFolder_GetDisplayNameOf(testIShellFolder, newPIDL, SHGDN_INFOLDER|SHGDN_FORPARSING, &strret);
1728 ok(hr == S_OK, "GetDisplayNameOf failed %08x\n", hr);
1730 if (SUCCEEDED(hr) && pStrRetToBufW)
1732 hr = pStrRetToBufW(&strret, newPIDL, tempbufW, sizeof(tempbufW)/sizeof(WCHAR));
1733 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08x\n", hr);
1734 ok (!lstrcmpiW(tempbufW, foldernameW), "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW));
1737 IShellFolder_Release(IDesktopFolder);
1738 IShellFolder_Release(testIShellFolder);
1740 IMalloc_Free(ppM, newPIDL);
1742 cleanup:
1743 DeleteFileA(".\\testfolder\\desktop.ini");
1744 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")&~FILE_ATTRIBUTE_SYSTEM);
1745 RemoveDirectoryA(".\\testfolder");
1748 static void test_SHCreateShellItem(void)
1750 IShellItem *shellitem;
1751 IPersistIDList *persistidl;
1752 LPITEMIDLIST pidl_cwd=NULL, pidl_testfile, pidl_abstestfile, pidl_test;
1753 HRESULT ret;
1754 char curdirA[MAX_PATH];
1755 WCHAR curdirW[MAX_PATH];
1756 IShellFolder *desktopfolder=NULL, *currentfolder=NULL;
1757 static WCHAR testfileW[] = {'t','e','s','t','f','i','l','e',0};
1759 GetCurrentDirectoryA(MAX_PATH, curdirA);
1761 if (!lstrlenA(curdirA))
1763 win_skip("GetCurrentDirectoryA returned empty string, skipping test_SHCreateShellItem\n");
1764 return;
1767 MultiByteToWideChar(CP_ACP, 0, curdirA, -1, curdirW, MAX_PATH);
1769 ret = SHGetDesktopFolder(&desktopfolder);
1770 ok(SUCCEEDED(ret), "SHGetShellFolder returned %x\n", ret);
1772 ret = IShellFolder_ParseDisplayName(desktopfolder, NULL, NULL, curdirW, NULL, &pidl_cwd, NULL);
1773 ok(SUCCEEDED(ret), "ParseDisplayName returned %x\n", ret);
1775 ret = IShellFolder_BindToObject(desktopfolder, pidl_cwd, NULL, &IID_IShellFolder, (void**)&currentfolder);
1776 ok(SUCCEEDED(ret), "BindToObject returned %x\n", ret);
1778 CreateTestFile(".\\testfile");
1780 ret = IShellFolder_ParseDisplayName(currentfolder, NULL, NULL, testfileW, NULL, &pidl_testfile, NULL);
1781 ok(SUCCEEDED(ret), "ParseDisplayName returned %x\n", ret);
1783 pidl_abstestfile = pILCombine(pidl_cwd, pidl_testfile);
1785 ret = pSHCreateShellItem(NULL, NULL, NULL, &shellitem);
1786 todo_wine ok(ret == E_INVALIDARG, "SHCreateShellItem returned %x\n", ret);
1788 if (0) /* crashes on Windows XP */
1790 pSHCreateShellItem(NULL, NULL, pidl_cwd, NULL);
1791 pSHCreateShellItem(pidl_cwd, NULL, NULL, &shellitem);
1792 pSHCreateShellItem(NULL, currentfolder, NULL, &shellitem);
1793 pSHCreateShellItem(pidl_cwd, currentfolder, NULL, &shellitem);
1796 ret = pSHCreateShellItem(NULL, NULL, pidl_cwd, &shellitem);
1797 ok(SUCCEEDED(ret), "SHCreateShellItem returned %x\n", ret);
1798 if (SUCCEEDED(ret))
1800 ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl);
1801 ok(SUCCEEDED(ret), "QueryInterface returned %x\n", ret);
1802 if (SUCCEEDED(ret))
1804 ret = IPersistIDList_GetIDList(persistidl, &pidl_test);
1805 ok(SUCCEEDED(ret), "GetIDList returned %x\n", ret);
1806 if (SUCCEEDED(ret))
1808 ok(ILIsEqual(pidl_cwd, pidl_test), "id lists are not equal\n");
1809 pILFree(pidl_test);
1811 IPersistIDList_Release(persistidl);
1813 IShellItem_Release(shellitem);
1816 ret = pSHCreateShellItem(pidl_cwd, NULL, pidl_testfile, &shellitem);
1817 todo_wine ok(SUCCEEDED(ret), "SHCreateShellItem returned %x\n", ret);
1818 if (SUCCEEDED(ret))
1820 ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl);
1821 ok(SUCCEEDED(ret), "QueryInterface returned %x\n", ret);
1822 if (SUCCEEDED(ret))
1824 ret = IPersistIDList_GetIDList(persistidl, &pidl_test);
1825 ok(SUCCEEDED(ret), "GetIDList returned %x\n", ret);
1826 if (SUCCEEDED(ret))
1828 ok(ILIsEqual(pidl_abstestfile, pidl_test), "id lists are not equal\n");
1829 pILFree(pidl_test);
1831 IPersistIDList_Release(persistidl);
1833 IShellItem_Release(shellitem);
1836 ret = pSHCreateShellItem(NULL, currentfolder, pidl_testfile, &shellitem);
1837 todo_wine ok(SUCCEEDED(ret), "SHCreateShellItem returned %x\n", ret);
1838 if (SUCCEEDED(ret))
1840 ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl);
1841 ok(SUCCEEDED(ret), "QueryInterface returned %x\n", ret);
1842 if (SUCCEEDED(ret))
1844 ret = IPersistIDList_GetIDList(persistidl, &pidl_test);
1845 ok(SUCCEEDED(ret), "GetIDList returned %x\n", ret);
1846 if (SUCCEEDED(ret))
1848 ok(ILIsEqual(pidl_abstestfile, pidl_test), "id lists are not equal\n");
1849 pILFree(pidl_test);
1851 IPersistIDList_Release(persistidl);
1853 IShellItem_Release(shellitem);
1856 /* if a parent pidl and shellfolder are specified, the shellfolder is ignored */
1857 ret = pSHCreateShellItem(pidl_cwd, desktopfolder, pidl_testfile, &shellitem);
1858 todo_wine ok(SUCCEEDED(ret), "SHCreateShellItem returned %x\n", ret);
1859 if (SUCCEEDED(ret))
1861 ret = IShellItem_QueryInterface(shellitem, &IID_IPersistIDList, (void**)&persistidl);
1862 ok(SUCCEEDED(ret), "QueryInterface returned %x\n", ret);
1863 if (SUCCEEDED(ret))
1865 ret = IPersistIDList_GetIDList(persistidl, &pidl_test);
1866 ok(SUCCEEDED(ret), "GetIDList returned %x\n", ret);
1867 if (SUCCEEDED(ret))
1869 ok(ILIsEqual(pidl_abstestfile, pidl_test), "id lists are not equal\n");
1870 pILFree(pidl_test);
1872 IPersistIDList_Release(persistidl);
1874 IShellItem_Release(shellitem);
1877 DeleteFileA(".\\testfile");
1878 pILFree(pidl_abstestfile);
1879 pILFree(pidl_testfile);
1880 pILFree(pidl_cwd);
1881 IShellFolder_Release(currentfolder);
1882 IShellFolder_Release(desktopfolder);
1885 START_TEST(shlfolder)
1887 init_function_pointers();
1888 /* if OleInitialize doesn't get called, ParseDisplayName returns
1889 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1890 OleInitialize(NULL);
1892 test_ParseDisplayName();
1893 test_BindToObject();
1894 test_EnumObjects_and_CompareIDs();
1895 test_GetDisplayName();
1896 test_GetAttributesOf();
1897 test_SHGetPathFromIDList();
1898 test_CallForAttributes();
1899 test_FolderShortcut();
1900 test_ITEMIDLIST_format();
1901 if(pSHGetFolderPathAndSubDirA)
1902 testSHGetFolderPathAndSubDirA();
1903 else
1904 skip("SHGetFolderPathAndSubDirA not present\n");
1905 test_LocalizedNames();
1906 if(pSHCreateShellItem)
1907 test_SHCreateShellItem();
1908 else
1909 win_skip("test_SHCreateShellItem not present\n");
1911 OleUninitialize();