2 * Unit test of the IShellFolder functions.
4 * Copyright 2004 Vitaliy Margolen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
40 #include "wine/test.h"
45 static HRESULT (WINAPI
*pSHBindToParent
)(LPCITEMIDLIST
, REFIID
, LPVOID
*, LPCITEMIDLIST
*);
46 static HRESULT (WINAPI
*pSHGetFolderPathA
)(HWND
, int, HANDLE
, DWORD
, LPSTR
);
47 static HRESULT (WINAPI
*pSHGetFolderPathAndSubDirA
)(HWND
, int, HANDLE
, DWORD
, LPCSTR
, LPSTR
);
48 static BOOL (WINAPI
*pSHGetPathFromIDListW
)(LPCITEMIDLIST
,LPWSTR
);
49 static BOOL (WINAPI
*pSHGetSpecialFolderPathA
)(HWND
, LPSTR
, int, BOOL
);
50 static BOOL (WINAPI
*pSHGetSpecialFolderPathW
)(HWND
, LPWSTR
, int, BOOL
);
51 static HRESULT (WINAPI
*pStrRetToBufW
)(STRRET
*,LPCITEMIDLIST
,LPWSTR
,UINT
);
52 static LPITEMIDLIST (WINAPI
*pILFindLastID
)(LPCITEMIDLIST
);
53 static void (WINAPI
*pILFree
)(LPITEMIDLIST
);
54 static BOOL (WINAPI
*pILIsEqual
)(LPCITEMIDLIST
, LPCITEMIDLIST
);
55 static HRESULT (WINAPI
*pSHCreateShellItem
)(LPCITEMIDLIST
,IShellFolder
*,LPCITEMIDLIST
,IShellItem
**);
56 static LPITEMIDLIST (WINAPI
*pILCombine
)(LPCITEMIDLIST
,LPCITEMIDLIST
);
59 static void init_function_pointers(void)
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 const char *wine_dbgstr_w(LPCWSTR str
)
89 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
93 static void test_ParseDisplayName(void)
96 IShellFolder
*IDesktopFolder
;
97 static const char *cNonExistDir1A
= "c:\\nonexist_subdir";
98 static const char *cNonExistDir2A
= "c:\\\\nonexist_subdir";
99 static const char *cInetTestA
= "http:\\yyy";
100 static const char *cInetTest2A
= "xx:yyy";
102 WCHAR cTestDirW
[MAX_PATH
] = {0};
106 hr
= SHGetDesktopFolder(&IDesktopFolder
);
107 if(hr
!= S_OK
) return;
109 MultiByteToWideChar(CP_ACP
, 0, cInetTestA
, -1, cTestDirW
, MAX_PATH
);
110 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
,
111 NULL
, NULL
, cTestDirW
, NULL
, &newPIDL
, 0);
112 todo_wine
ok((SUCCEEDED(hr
) || broken(hr
== E_FAIL
) /* NT4 */),
113 "ParseDisplayName returned %08x, expected SUCCESS or E_FAIL\n", hr
);
116 ok(pILFindLastID(newPIDL
)->mkid
.abID
[0] == 0x61, "Last pidl should be of type "
117 "PT_IESPECIAL1, but is: %02x\n", pILFindLastID(newPIDL
)->mkid
.abID
[0]);
118 IMalloc_Free(ppM
, newPIDL
);
121 MultiByteToWideChar(CP_ACP
, 0, cInetTest2A
, -1, cTestDirW
, MAX_PATH
);
122 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
,
123 NULL
, NULL
, cTestDirW
, NULL
, &newPIDL
, 0);
124 todo_wine
ok((SUCCEEDED(hr
) || broken(hr
== E_FAIL
) /* NT4 */),
125 "ParseDisplayName returned %08x, expected SUCCESS or E_FAIL\n", hr
);
128 ok(pILFindLastID(newPIDL
)->mkid
.abID
[0] == 0x61, "Last pidl should be of type "
129 "PT_IESPECIAL1, but is: %02x\n", pILFindLastID(newPIDL
)->mkid
.abID
[0]);
130 IMalloc_Free(ppM
, newPIDL
);
133 res
= GetFileAttributesA(cNonExistDir1A
);
134 if(res
!= INVALID_FILE_ATTRIBUTES
) return;
136 MultiByteToWideChar(CP_ACP
, 0, cNonExistDir1A
, -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
),
140 "ParseDisplayName returned %08x, expected 80070002 or E_FAIL\n", hr
);
142 res
= GetFileAttributesA(cNonExistDir2A
);
143 if(res
!= INVALID_FILE_ATTRIBUTES
) return;
145 MultiByteToWideChar(CP_ACP
, 0, cNonExistDir2A
, -1, cTestDirW
, MAX_PATH
);
146 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
,
147 NULL
, NULL
, cTestDirW
, NULL
, &newPIDL
, 0);
148 ok((hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)) || (hr
== E_FAIL
) || (hr
== E_INVALIDARG
),
149 "ParseDisplayName returned %08x, expected 80070002, E_FAIL or E_INVALIDARG\n", hr
);
151 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
152 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
153 * out it doesn't. The magic seems to happen in the file dialogs, then. */
154 if (!pSHGetSpecialFolderPathW
|| !pILFindLastID
) goto finished
;
156 bRes
= pSHGetSpecialFolderPathW(NULL
, cTestDirW
, CSIDL_PERSONAL
, FALSE
);
157 ok(bRes
, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %u\n", GetLastError());
158 if (!bRes
) goto finished
;
160 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
, NULL
, NULL
, cTestDirW
, NULL
, &newPIDL
, 0);
161 ok(SUCCEEDED(hr
), "DesktopFolder->ParseDisplayName failed. hr = %08x.\n", hr
);
162 if (FAILED(hr
)) goto finished
;
164 ok(pILFindLastID(newPIDL
)->mkid
.abID
[0] == 0x31 ||
165 pILFindLastID(newPIDL
)->mkid
.abID
[0] == 0xb1, /* Win98 */
166 "Last pidl should be of type PT_FOLDER or PT_IESPECIAL2, but is: %02x\n",
167 pILFindLastID(newPIDL
)->mkid
.abID
[0]);
168 IMalloc_Free(ppM
, newPIDL
);
171 IShellFolder_Release(IDesktopFolder
);
174 /* creates a file with the specified name for tests */
175 static void CreateTestFile(const CHAR
*name
)
180 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
181 if (file
!= INVALID_HANDLE_VALUE
)
183 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
184 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
190 /* initializes the tests */
191 static void CreateFilesFolders(void)
193 CreateDirectoryA(".\\testdir", NULL
);
194 CreateDirectoryA(".\\testdir\\test.txt", NULL
);
195 CreateTestFile (".\\testdir\\test1.txt ");
196 CreateTestFile (".\\testdir\\test2.txt ");
197 CreateTestFile (".\\testdir\\test3.txt ");
198 CreateDirectoryA(".\\testdir\\testdir2 ", NULL
);
199 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL
);
202 /* cleans after tests */
203 static void Cleanup(void)
205 DeleteFileA(".\\testdir\\test1.txt");
206 DeleteFileA(".\\testdir\\test2.txt");
207 DeleteFileA(".\\testdir\\test3.txt");
208 RemoveDirectoryA(".\\testdir\\test.txt");
209 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
210 RemoveDirectoryA(".\\testdir\\testdir2");
211 RemoveDirectoryA(".\\testdir");
216 static void test_EnumObjects(IShellFolder
*iFolder
)
218 IEnumIDList
*iEnumList
;
219 LPITEMIDLIST newPIDL
, idlArr
[10];
224 static const WORD iResults
[5][5] =
233 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
234 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
235 static const ULONG attrs
[5] =
237 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
| SFGAO_FOLDER
| SFGAO_FILESYSANCESTOR
,
238 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
| SFGAO_FOLDER
| SFGAO_FILESYSANCESTOR
,
239 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
,
240 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
,
241 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
,
244 hr
= IShellFolder_EnumObjects(iFolder
, NULL
, SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &iEnumList
);
245 ok(hr
== S_OK
, "EnumObjects failed %08x\n", hr
);
247 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
248 * the filesystem shellfolders return S_OK even if less than 'celt' items are
249 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
250 * only ever returns a single entry per call. */
251 while (IEnumIDList_Next(iEnumList
, 10-i
, &idlArr
[i
], &NumPIDLs
) == S_OK
)
253 ok (i
== 5, "i: %d\n", i
);
255 hr
= IEnumIDList_Release(iEnumList
);
256 ok(hr
== S_OK
, "IEnumIDList_Release failed %08x\n", hr
);
258 /* Sort them first in case of wrong order from system */
259 for (i
=0;i
<5;i
++) for (j
=0;j
<5;j
++)
260 if ((SHORT
)IShellFolder_CompareIDs(iFolder
, 0, idlArr
[i
], idlArr
[j
]) < 0)
263 idlArr
[i
] = idlArr
[j
];
267 for (i
=0;i
<5;i
++) for (j
=0;j
<5;j
++)
269 hr
= IShellFolder_CompareIDs(iFolder
, 0, idlArr
[i
], idlArr
[j
]);
270 ok(hr
== iResults
[i
][j
], "Got %x expected [%d]-[%d]=%x\n", hr
, i
, j
, iResults
[i
][j
]);
274 for (i
= 0; i
< 5; i
++)
277 #define SFGAO_VISTA SFGAO_DROPTARGET | SFGAO_CANLINK | SFGAO_CANCOPY
278 /* Native returns all flags no matter what we ask for */
279 flags
= SFGAO_CANCOPY
;
280 hr
= IShellFolder_GetAttributesOf(iFolder
, 1, (LPCITEMIDLIST
*)(idlArr
+ i
), &flags
);
281 flags
&= SFGAO_testfor
;
282 ok(hr
== S_OK
, "GetAttributesOf returns %08x\n", hr
);
283 ok(flags
== (attrs
[i
]) ||
284 flags
== (attrs
[i
] & ~SFGAO_FILESYSANCESTOR
) || /* Win9x, NT4 */
285 flags
== ((attrs
[i
] & ~SFGAO_CAPABILITYMASK
) | SFGAO_VISTA
), /* Vista and higher */
286 "GetAttributesOf[%i] got %08x, expected %08x\n", i
, flags
, attrs
[i
]);
288 flags
= SFGAO_testfor
;
289 hr
= IShellFolder_GetAttributesOf(iFolder
, 1, (LPCITEMIDLIST
*)(idlArr
+ i
), &flags
);
290 flags
&= SFGAO_testfor
;
291 ok(hr
== S_OK
, "GetAttributesOf returns %08x\n", hr
);
292 ok(flags
== attrs
[i
] ||
293 flags
== (attrs
[i
] & ~SFGAO_FILESYSANCESTOR
), /* Win9x, NT4 */
294 "GetAttributesOf[%i] got %08x, expected %08x\n", i
, flags
, attrs
[i
]);
298 IMalloc_Free(ppM
, idlArr
[i
]);
301 static void test_BindToObject(void)
305 IShellFolder
*psfDesktop
, *psfChild
, *psfMyComputer
, *psfSystemDir
;
306 SHITEMID emptyitem
= { 0, { 0 } };
307 LPITEMIDLIST pidlMyComputer
, pidlSystemDir
, pidlEmpty
= (LPITEMIDLIST
)&emptyitem
;
308 WCHAR wszSystemDir
[MAX_PATH
];
309 char szSystemDir
[MAX_PATH
];
310 WCHAR wszMyComputer
[] = {
311 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
312 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
314 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
315 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
317 hr
= SHGetDesktopFolder(&psfDesktop
);
318 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08x\n", hr
);
319 if (FAILED(hr
)) return;
321 hr
= IShellFolder_BindToObject(psfDesktop
, pidlEmpty
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
322 ok (hr
== E_INVALIDARG
, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr
);
324 hr
= IShellFolder_BindToObject(psfDesktop
, NULL
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
325 ok (hr
== E_INVALIDARG
, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr
);
327 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszMyComputer
, NULL
, &pidlMyComputer
, NULL
);
328 ok (SUCCEEDED(hr
), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr
);
330 IShellFolder_Release(psfDesktop
);
334 hr
= IShellFolder_BindToObject(psfDesktop
, pidlMyComputer
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfMyComputer
);
335 ok (SUCCEEDED(hr
), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr
);
336 IShellFolder_Release(psfDesktop
);
337 IMalloc_Free(ppM
, pidlMyComputer
);
338 if (FAILED(hr
)) return;
340 hr
= IShellFolder_BindToObject(psfMyComputer
, pidlEmpty
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
341 ok (hr
== E_INVALIDARG
, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr
);
344 /* this call segfaults on 98SE */
345 hr
= IShellFolder_BindToObject(psfMyComputer
, NULL
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
346 ok (hr
== E_INVALIDARG
, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr
);
349 cChars
= GetSystemDirectoryA(szSystemDir
, MAX_PATH
);
350 ok (cChars
> 0 && cChars
< MAX_PATH
, "GetSystemDirectoryA failed! LastError: %u\n", GetLastError());
351 if (cChars
== 0 || cChars
>= MAX_PATH
) {
352 IShellFolder_Release(psfMyComputer
);
355 MultiByteToWideChar(CP_ACP
, 0, szSystemDir
, -1, wszSystemDir
, MAX_PATH
);
357 hr
= IShellFolder_ParseDisplayName(psfMyComputer
, NULL
, NULL
, wszSystemDir
, NULL
, &pidlSystemDir
, NULL
);
358 ok (SUCCEEDED(hr
), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08x\n", hr
);
360 IShellFolder_Release(psfMyComputer
);
364 hr
= IShellFolder_BindToObject(psfMyComputer
, pidlSystemDir
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfSystemDir
);
365 ok (SUCCEEDED(hr
), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08x\n", hr
);
366 IShellFolder_Release(psfMyComputer
);
367 IMalloc_Free(ppM
, pidlSystemDir
);
368 if (FAILED(hr
)) return;
370 hr
= IShellFolder_BindToObject(psfSystemDir
, pidlEmpty
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
371 ok (hr
== E_INVALIDARG
,
372 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08x\n", hr
);
375 /* this call segfaults on 98SE */
376 hr
= IShellFolder_BindToObject(psfSystemDir
, NULL
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
377 ok (hr
== E_INVALIDARG
,
378 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08x\n", hr
);
381 IShellFolder_Release(psfSystemDir
);
384 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
385 static LPWSTR
myPathAddBackslashW( LPWSTR lpszPath
)
389 if (!lpszPath
|| (iLen
= lstrlenW(lpszPath
)) >= MAX_PATH
)
395 if (lpszPath
[-1] != '\\')
404 static void test_GetDisplayName(void)
409 WCHAR wszTestFile
[MAX_PATH
], wszTestFile2
[MAX_PATH
];
410 char szTestFile
[MAX_PATH
], szTestDir
[MAX_PATH
];
413 LPSHELLFOLDER psfDesktop
, psfPersonal
;
415 SHITEMID emptyitem
= { 0, { 0 } };
416 LPITEMIDLIST pidlTestFile
, pidlEmpty
= (LPITEMIDLIST
)&emptyitem
;
417 LPCITEMIDLIST pidlLast
;
418 static const CHAR szFileName
[] = "winetest.foo";
419 static const WCHAR wszFileName
[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
420 static const WCHAR wszDirName
[] = { 'w','i','n','e','t','e','s','t',0 };
422 /* I'm trying to figure if there is a functional difference between calling
423 * SHGetPathFromIDListW and calling GetDisplayNameOf(SHGDN_FORPARSING) after
424 * binding to the shellfolder. One thing I thought of was that perhaps
425 * SHGetPathFromIDListW would be able to get the path to a file, which does
426 * not exist anymore, while the other method wouldn't. It turns out there's
427 * no functional difference in this respect.
430 if(!pSHGetSpecialFolderPathA
) {
431 win_skip("SHGetSpecialFolderPathA is not available\n");
435 /* First creating a directory in MyDocuments and a file in this directory. */
436 result
= pSHGetSpecialFolderPathA(NULL
, szTestDir
, CSIDL_PERSONAL
, FALSE
);
437 ok(result
, "SHGetSpecialFolderPathA failed! Last error: %u\n", GetLastError());
440 /* Use ANSI file functions so this works on Windows 9x */
441 lstrcatA(szTestDir
, "\\winetest");
442 CreateDirectoryA(szTestDir
, NULL
);
443 attr
=GetFileAttributesA(szTestDir
);
444 if (attr
== INVALID_FILE_ATTRIBUTES
|| !(attr
& FILE_ATTRIBUTE_DIRECTORY
))
446 ok(0, "unable to create the '%s' directory\n", szTestDir
);
450 lstrcpyA(szTestFile
, szTestDir
);
451 lstrcatA(szTestFile
, "\\");
452 lstrcatA(szTestFile
, szFileName
);
453 hTestFile
= CreateFileA(szTestFile
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
454 ok((hTestFile
!= INVALID_HANDLE_VALUE
), "CreateFileA failed! Last error: %u\n", GetLastError());
455 if (hTestFile
== INVALID_HANDLE_VALUE
) return;
456 CloseHandle(hTestFile
);
458 /* Getting an itemidlist for the file. */
459 hr
= SHGetDesktopFolder(&psfDesktop
);
460 ok(SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08x\n", hr
);
461 if (FAILED(hr
)) return;
463 MultiByteToWideChar(CP_ACP
, 0, szTestFile
, -1, wszTestFile
, MAX_PATH
);
465 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszTestFile
, NULL
, &pidlTestFile
, NULL
);
466 ok(SUCCEEDED(hr
), "Desktop->ParseDisplayName failed! hr = %08x\n", hr
);
468 IShellFolder_Release(psfDesktop
);
472 pidlLast
= pILFindLastID(pidlTestFile
);
473 ok(pidlLast
->mkid
.cb
>=76 ||
474 broken(pidlLast
->mkid
.cb
== 28) || /* W2K */
475 broken(pidlLast
->mkid
.cb
== 40), /* Win9x, WinME */
476 "Expected pidl length of at least 76, got %d.\n", pidlLast
->mkid
.cb
);
477 if (pidlLast
->mkid
.cb
>= 28) {
478 ok(!lstrcmpA((CHAR
*)&pidlLast
->mkid
.abID
[12], szFileName
),
479 "Filename should be stored as ansi-string at this position!\n");
481 /* WinXP and up store the filenames as both ANSI and UNICODE in the pidls */
482 if (pidlLast
->mkid
.cb
>= 76) {
483 ok(!lstrcmpW((WCHAR
*)&pidlLast
->mkid
.abID
[46], wszFileName
) ||
484 (pidlLast
->mkid
.cb
>= 94 && !lstrcmpW((WCHAR
*)&pidlLast
->mkid
.abID
[64], wszFileName
)), /* Vista */
485 "Filename should be stored as wchar-string at this position!\n");
488 /* It seems as if we cannot bind to regular files on windows, but only directories.
490 hr
= IShellFolder_BindToObject(psfDesktop
, pidlTestFile
, NULL
, &IID_IUnknown
, (VOID
**)&psfFile
);
492 ok (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
493 hr
== E_NOTIMPL
|| /* Vista */
494 broken(SUCCEEDED(hr
)), /* Win9x, W2K */
497 IShellFolder_Release(psfFile
);
500 if (!pSHBindToParent
)
502 win_skip("SHBindToParent is missing\n");
503 DeleteFileA(szTestFile
);
504 RemoveDirectoryA(szTestDir
);
508 /* Some tests for IShellFolder::SetNameOf */
509 if (pSHGetFolderPathAndSubDirA
)
511 hr
= pSHBindToParent(pidlTestFile
, &IID_IShellFolder
, (VOID
**)&psfPersonal
, &pidlLast
);
512 ok(SUCCEEDED(hr
), "SHBindToParent failed! hr = %08x\n", hr
);
514 /* It's ok to use this fixed path. Call will fail anyway. */
515 WCHAR wszAbsoluteFilename
[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
516 LPITEMIDLIST pidlNew
;
518 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
519 hr
= IShellFolder_SetNameOf(psfPersonal
, NULL
, pidlLast
, wszDirName
, SHGDN_NORMAL
, &pidlNew
);
520 ok (SUCCEEDED(hr
), "SetNameOf failed! hr = %08x\n", hr
);
523 ok (((LPITEMIDLIST
)((LPBYTE
)pidlNew
+pidlNew
->mkid
.cb
))->mkid
.cb
== 0,
524 "pidl returned from SetNameOf should be simple!\n");
526 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
527 * is implemented on top of SHFileOperation in WinXP. */
528 hr
= IShellFolder_SetNameOf(psfPersonal
, NULL
, pidlNew
, wszAbsoluteFilename
,
529 SHGDN_FORPARSING
, NULL
);
530 ok (hr
== HRESULT_FROM_WIN32(ERROR_CANCELLED
), "SetNameOf succeeded! hr = %08x\n", hr
);
532 /* Rename the file back to its original name. SetNameOf ignores the fact, that the
533 * SHGDN flags specify an absolute path. */
534 hr
= IShellFolder_SetNameOf(psfPersonal
, NULL
, pidlNew
, wszFileName
, SHGDN_FORPARSING
, NULL
);
535 ok (SUCCEEDED(hr
), "SetNameOf failed! hr = %08x\n", hr
);
540 IShellFolder_Release(psfPersonal
);
544 win_skip("Avoid needs of interaction on Win2k\n");
546 /* Deleting the file and the directory */
547 DeleteFileA(szTestFile
);
548 RemoveDirectoryA(szTestDir
);
550 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
551 if (pSHGetPathFromIDListW
)
553 result
= pSHGetPathFromIDListW(pidlTestFile
, wszTestFile2
);
554 ok (result
, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
555 ok (!lstrcmpiW(wszTestFile
, wszTestFile2
), "SHGetPathFromIDListW returns incorrect path!\n");
558 /* SHBindToParent fails, if called with a NULL PIDL. */
559 hr
= pSHBindToParent(NULL
, &IID_IShellFolder
, (VOID
**)&psfPersonal
, &pidlLast
);
560 ok (FAILED(hr
), "SHBindToParent(NULL) should fail!\n");
562 /* But it succeeds with an empty PIDL. */
563 hr
= pSHBindToParent(pidlEmpty
, &IID_IShellFolder
, (VOID
**)&psfPersonal
, &pidlLast
);
564 ok (SUCCEEDED(hr
), "SHBindToParent(empty PIDL) should succeed! hr = %08x\n", hr
);
565 ok (pidlLast
== pidlEmpty
, "The last element of an empty PIDL should be the PIDL itself!\n");
567 IShellFolder_Release(psfPersonal
);
569 /* Binding to the folder and querying the display name of the file also works. */
570 hr
= pSHBindToParent(pidlTestFile
, &IID_IShellFolder
, (VOID
**)&psfPersonal
, &pidlLast
);
571 ok (SUCCEEDED(hr
), "SHBindToParent failed! hr = %08x\n", hr
);
573 IShellFolder_Release(psfDesktop
);
577 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
578 * pidlTestFile (In accordance with MSDN). */
579 ok (pILFindLastID(pidlTestFile
) == pidlLast
,
580 "SHBindToParent doesn't return the last id of the pidl param!\n");
582 hr
= IShellFolder_GetDisplayNameOf(psfPersonal
, pidlLast
, SHGDN_FORPARSING
, &strret
);
583 ok (SUCCEEDED(hr
), "Personal->GetDisplayNameOf failed! hr = %08x\n", hr
);
585 IShellFolder_Release(psfDesktop
);
586 IShellFolder_Release(psfPersonal
);
592 hr
= pStrRetToBufW(&strret
, pidlLast
, wszTestFile2
, MAX_PATH
);
593 ok (SUCCEEDED(hr
), "StrRetToBufW failed! hr = %08x\n", hr
);
594 ok (!lstrcmpiW(wszTestFile
, wszTestFile2
), "GetDisplayNameOf returns incorrect path!\n");
597 IShellFolder_Release(psfDesktop
);
598 IShellFolder_Release(psfPersonal
);
601 static void test_CallForAttributes(void)
607 LPSHELLFOLDER psfDesktop
;
608 LPITEMIDLIST pidlMyDocuments
;
609 DWORD dwAttributes
, dwCallForAttributes
, dwOrigAttributes
, dwOrigCallForAttributes
;
610 static const WCHAR wszAttributes
[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
611 static const WCHAR wszCallForAttributes
[] = {
612 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
613 static const WCHAR wszMyDocumentsKey
[] = {
614 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
615 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
616 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
617 WCHAR wszMyDocuments
[] = {
618 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
619 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
621 /* For the root of a namespace extension, the attributes are not queried by binding
622 * to the object and calling GetAttributesOf. Instead, the attributes are read from
623 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
625 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
626 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
627 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
628 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
630 hr
= SHGetDesktopFolder(&psfDesktop
);
631 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08x\n", hr
);
632 if (FAILED(hr
)) return;
634 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszMyDocuments
, NULL
,
635 &pidlMyDocuments
, NULL
);
637 broken(hr
== E_INVALIDARG
), /* Win95, NT4 */
638 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08x\n", hr
);
640 IShellFolder_Release(psfDesktop
);
644 dwAttributes
= 0xffffffff;
645 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 1,
646 (LPCITEMIDLIST
*)&pidlMyDocuments
, &dwAttributes
);
647 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr
);
649 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
650 ok (dwAttributes
& SFGAO_FILESYSTEM
, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
651 ok (!(dwAttributes
& SFGAO_ISSLOW
), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
652 ok (!(dwAttributes
& SFGAO_GHOSTED
), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
654 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
655 * key. So the test will return at this point, if run on wine.
657 lResult
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszMyDocumentsKey
, 0, KEY_WRITE
|KEY_READ
, &hKey
);
658 ok (lResult
== ERROR_SUCCESS
, "RegOpenKeyEx failed! result: %08x\n", lResult
);
659 if (lResult
!= ERROR_SUCCESS
) {
660 IMalloc_Free(ppM
, pidlMyDocuments
);
661 IShellFolder_Release(psfDesktop
);
665 /* Query MyDocuments' Attributes value, to be able to restore it later. */
666 dwSize
= sizeof(DWORD
);
667 lResult
= RegQueryValueExW(hKey
, wszAttributes
, NULL
, NULL
, (LPBYTE
)&dwOrigAttributes
, &dwSize
);
668 ok (lResult
== ERROR_SUCCESS
, "RegQueryValueEx failed! result: %08x\n", lResult
);
669 if (lResult
!= ERROR_SUCCESS
) {
671 IMalloc_Free(ppM
, pidlMyDocuments
);
672 IShellFolder_Release(psfDesktop
);
676 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
677 dwSize
= sizeof(DWORD
);
678 lResult
= RegQueryValueExW(hKey
, wszCallForAttributes
, NULL
, NULL
,
679 (LPBYTE
)&dwOrigCallForAttributes
, &dwSize
);
680 ok (lResult
== ERROR_SUCCESS
, "RegQueryValueEx failed! result: %08x\n", lResult
);
681 if (lResult
!= ERROR_SUCCESS
) {
683 IMalloc_Free(ppM
, pidlMyDocuments
);
684 IShellFolder_Release(psfDesktop
);
688 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
689 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
690 * SFGAO_FILESYSTEM attributes. */
691 dwAttributes
= SFGAO_ISSLOW
|SFGAO_GHOSTED
;
692 RegSetValueExW(hKey
, wszAttributes
, 0, REG_DWORD
, (LPBYTE
)&dwAttributes
, sizeof(DWORD
));
693 dwCallForAttributes
= SFGAO_ISSLOW
|SFGAO_FILESYSTEM
;
694 RegSetValueExW(hKey
, wszCallForAttributes
, 0, REG_DWORD
,
695 (LPBYTE
)&dwCallForAttributes
, sizeof(DWORD
));
697 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
698 * GetAttributesOf. It seems that once there is a single attribute queried, for which
699 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
700 * the flags in Attributes are ignored.
702 dwAttributes
= SFGAO_ISSLOW
|SFGAO_GHOSTED
|SFGAO_FILESYSTEM
;
703 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 1,
704 (LPCITEMIDLIST
*)&pidlMyDocuments
, &dwAttributes
);
705 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08x\n", hr
);
707 ok (dwAttributes
== SFGAO_FILESYSTEM
,
708 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08x\n",
711 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
712 RegSetValueExW(hKey
, wszAttributes
, 0, REG_DWORD
, (LPBYTE
)&dwOrigAttributes
, sizeof(DWORD
));
713 RegSetValueExW(hKey
, wszCallForAttributes
, 0, REG_DWORD
,
714 (LPBYTE
)&dwOrigCallForAttributes
, sizeof(DWORD
));
716 IMalloc_Free(ppM
, pidlMyDocuments
);
717 IShellFolder_Release(psfDesktop
);
720 static void test_GetAttributesOf(void)
723 LPSHELLFOLDER psfDesktop
, psfMyComputer
;
724 SHITEMID emptyitem
= { 0, { 0 } };
725 LPCITEMIDLIST pidlEmpty
= (LPCITEMIDLIST
)&emptyitem
;
726 LPITEMIDLIST pidlMyComputer
;
728 static const DWORD desktopFlags
[] = {
730 SFGAO_STORAGE
| SFGAO_HASPROPSHEET
| SFGAO_STORAGEANCESTOR
| SFGAO_FILESYSANCESTOR
|
731 SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
,
733 SFGAO_CANRENAME
| SFGAO_HASPROPSHEET
| SFGAO_STREAM
| SFGAO_FILESYSANCESTOR
|
734 SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
,
735 /* WinMe, Win9x, WinNT*/
736 SFGAO_CANRENAME
| SFGAO_HASPROPSHEET
| SFGAO_FILESYSANCESTOR
|
737 SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
739 static const DWORD myComputerFlags
[] = {
741 SFGAO_CANRENAME
| SFGAO_CANDELETE
| SFGAO_HASPROPSHEET
| SFGAO_DROPTARGET
|
742 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
,
744 SFGAO_CANRENAME
| SFGAO_HASPROPSHEET
| SFGAO_DROPTARGET
| SFGAO_STREAM
|
745 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
,
746 /* WinMe, Win9x, WinNT */
747 SFGAO_CANRENAME
| SFGAO_HASPROPSHEET
| SFGAO_DROPTARGET
| SFGAO_FILESYSANCESTOR
|
748 SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
,
749 /* Win95, WinNT when queried directly */
750 SFGAO_CANLINK
| SFGAO_HASPROPSHEET
| SFGAO_DROPTARGET
| SFGAO_FILESYSANCESTOR
|
751 SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
753 WCHAR wszMyComputer
[] = {
754 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
755 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
756 char cCurrDirA
[MAX_PATH
] = {0};
757 WCHAR cCurrDirW
[MAX_PATH
];
758 static WCHAR cTestDirW
[] = {'t','e','s','t','d','i','r',0};
759 IShellFolder
*IDesktopFolder
, *testIShellFolder
;
762 BOOL foundFlagsMatch
;
764 hr
= SHGetDesktopFolder(&psfDesktop
);
765 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08x\n", hr
);
766 if (FAILED(hr
)) return;
768 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
769 dwFlags
= 0xffffffff;
770 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 1, &pidlEmpty
, &dwFlags
);
771 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08x\n", hr
);
772 for (i
= 0, foundFlagsMatch
= FALSE
; !foundFlagsMatch
&&
773 i
< sizeof(desktopFlags
) / sizeof(desktopFlags
[0]); i
++)
775 if (desktopFlags
[i
] == dwFlags
)
776 foundFlagsMatch
= TRUE
;
778 ok (foundFlagsMatch
, "Wrong Desktop attributes: %08x\n", dwFlags
);
780 /* .. or with no itemidlist at all. */
781 dwFlags
= 0xffffffff;
782 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 0, NULL
, &dwFlags
);
783 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(NULL) failed! hr = %08x\n", hr
);
784 for (i
= 0, foundFlagsMatch
= FALSE
; !foundFlagsMatch
&&
785 i
< sizeof(desktopFlags
) / sizeof(desktopFlags
[0]); i
++)
787 if (desktopFlags
[i
] == dwFlags
)
788 foundFlagsMatch
= TRUE
;
790 ok (foundFlagsMatch
, "Wrong Desktop attributes: %08x\n", dwFlags
);
792 /* Testing the attributes of the MyComputer shellfolder */
793 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszMyComputer
, NULL
, &pidlMyComputer
, NULL
);
794 ok (SUCCEEDED(hr
), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr
);
796 IShellFolder_Release(psfDesktop
);
800 /* Windows sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
801 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
803 dwFlags
= 0xffffffff;
804 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 1, (LPCITEMIDLIST
*)&pidlMyComputer
, &dwFlags
);
805 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08x\n", hr
);
806 for (i
= 0, foundFlagsMatch
= FALSE
; !foundFlagsMatch
&&
807 i
< sizeof(myComputerFlags
) / sizeof(myComputerFlags
[0]); i
++)
809 if ((myComputerFlags
[i
] | SFGAO_CANLINK
) == dwFlags
)
810 foundFlagsMatch
= TRUE
;
813 ok (foundFlagsMatch
, "Wrong MyComputer attributes: %08x\n", dwFlags
);
815 hr
= IShellFolder_BindToObject(psfDesktop
, pidlMyComputer
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfMyComputer
);
816 ok (SUCCEEDED(hr
), "Desktop failed to bind to MyComputer object! hr = %08x\n", hr
);
817 IShellFolder_Release(psfDesktop
);
818 IMalloc_Free(ppM
, pidlMyComputer
);
819 if (FAILED(hr
)) return;
821 hr
= IShellFolder_GetAttributesOf(psfMyComputer
, 1, &pidlEmpty
, &dwFlags
);
823 ok (hr
== E_INVALIDARG
||
824 broken(SUCCEEDED(hr
)), /* W2K and earlier */
825 "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08x\n", hr
);
827 dwFlags
= 0xffffffff;
828 hr
= IShellFolder_GetAttributesOf(psfMyComputer
, 0, NULL
, &dwFlags
);
829 ok (SUCCEEDED(hr
), "MyComputer->GetAttributesOf(NULL) failed! hr = %08x\n", hr
);
830 for (i
= 0, foundFlagsMatch
= FALSE
; !foundFlagsMatch
&&
831 i
< sizeof(myComputerFlags
) / sizeof(myComputerFlags
[0]); i
++)
833 if (myComputerFlags
[i
] == dwFlags
)
834 foundFlagsMatch
= TRUE
;
837 ok (foundFlagsMatch
, "Wrong MyComputer attributes: %08x\n", dwFlags
);
839 IShellFolder_Release(psfMyComputer
);
841 GetCurrentDirectoryA(MAX_PATH
, cCurrDirA
);
842 len
= lstrlenA(cCurrDirA
);
845 win_skip("GetCurrentDirectoryA returned empty string. Skipping test_GetAttributesOf\n");
848 if (len
> 3 && cCurrDirA
[len
-1] == '\\')
849 cCurrDirA
[len
-1] = 0;
851 /* create test directory */
852 CreateFilesFolders();
854 MultiByteToWideChar(CP_ACP
, 0, cCurrDirA
, -1, cCurrDirW
, MAX_PATH
);
856 hr
= SHGetDesktopFolder(&IDesktopFolder
);
857 ok(hr
== S_OK
, "SHGetDesktopfolder failed %08x\n", hr
);
859 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
, NULL
, NULL
, cCurrDirW
, NULL
, &newPIDL
, 0);
860 ok(hr
== S_OK
, "ParseDisplayName failed %08x\n", hr
);
862 hr
= IShellFolder_BindToObject(IDesktopFolder
, newPIDL
, NULL
, (REFIID
)&IID_IShellFolder
, (LPVOID
*)&testIShellFolder
);
863 ok(hr
== S_OK
, "BindToObject failed %08x\n", hr
);
865 IMalloc_Free(ppM
, newPIDL
);
867 /* get relative PIDL */
868 hr
= IShellFolder_ParseDisplayName(testIShellFolder
, NULL
, NULL
, cTestDirW
, NULL
, &newPIDL
, 0);
869 ok(hr
== S_OK
, "ParseDisplayName failed %08x\n", hr
);
871 /* test the shell attributes of the test directory using the relative PIDL */
872 dwFlags
= SFGAO_FOLDER
;
873 hr
= IShellFolder_GetAttributesOf(testIShellFolder
, 1, (LPCITEMIDLIST
*)&newPIDL
, &dwFlags
);
874 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr
);
875 ok ((dwFlags
&SFGAO_FOLDER
), "Wrong directory attribute for relative PIDL: %08x\n", dwFlags
);
878 IMalloc_Free(ppM
, newPIDL
);
880 /* append testdirectory name to path */
881 if (cCurrDirA
[len
-1] == '\\')
882 cCurrDirA
[len
-1] = 0;
883 lstrcatA(cCurrDirA
, "\\testdir");
884 MultiByteToWideChar(CP_ACP
, 0, cCurrDirA
, -1, cCurrDirW
, MAX_PATH
);
886 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
, NULL
, NULL
, cCurrDirW
, NULL
, &newPIDL
, 0);
887 ok(hr
== S_OK
, "ParseDisplayName failed %08x\n", hr
);
889 /* test the shell attributes of the test directory using the absolute PIDL */
890 dwFlags
= SFGAO_FOLDER
;
891 hr
= IShellFolder_GetAttributesOf(IDesktopFolder
, 1, (LPCITEMIDLIST
*)&newPIDL
, &dwFlags
);
892 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf() failed! hr = %08x\n", hr
);
893 ok ((dwFlags
&SFGAO_FOLDER
), "Wrong directory attribute for absolute PIDL: %08x\n", dwFlags
);
896 IMalloc_Free(ppM
, newPIDL
);
898 IShellFolder_Release(testIShellFolder
);
902 IShellFolder_Release(IDesktopFolder
);
905 static void test_SHGetPathFromIDList(void)
907 SHITEMID emptyitem
= { 0, { 0 } };
908 LPCITEMIDLIST pidlEmpty
= (LPCITEMIDLIST
)&emptyitem
;
909 LPITEMIDLIST pidlMyComputer
;
910 WCHAR wszPath
[MAX_PATH
], wszDesktop
[MAX_PATH
];
913 LPSHELLFOLDER psfDesktop
;
914 WCHAR wszMyComputer
[] = {
915 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
916 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
917 WCHAR wszFileName
[MAX_PATH
];
918 LPITEMIDLIST pidlTestFile
;
921 static WCHAR wszTestFile
[] = {
922 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
923 HRESULT (WINAPI
*pSHGetSpecialFolderLocation
)(HWND
, int, LPITEMIDLIST
*);
925 LPITEMIDLIST pidlPrograms
;
927 if(!pSHGetPathFromIDListW
|| !pSHGetSpecialFolderPathW
)
929 win_skip("SHGetPathFromIDListW() or SHGetSpecialFolderPathW() is missing\n");
933 /* Calling SHGetPathFromIDListW with no pidl should return the empty string */
936 result
= pSHGetPathFromIDListW(NULL
, wszPath
);
937 ok(!result
, "Expected failure\n");
938 ok(!wszPath
[0], "Expected empty string\n");
940 /* Calling SHGetPathFromIDListW with an empty pidl should return the desktop folder's path. */
941 result
= pSHGetSpecialFolderPathW(NULL
, wszDesktop
, CSIDL_DESKTOP
, FALSE
);
942 ok(result
, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %u\n", GetLastError());
945 /* Check if we are on Win9x */
946 SetLastError(0xdeadbeef);
947 lstrcmpiW(wszDesktop
, wszDesktop
);
948 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
950 win_skip("Most W-calls are not implemented\n");
954 result
= pSHGetPathFromIDListW(pidlEmpty
, wszPath
);
955 ok(result
, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
957 ok(!lstrcmpiW(wszDesktop
, wszPath
), "SHGetPathFromIDListW didn't return desktop path for empty pidl!\n");
959 /* MyComputer does not map to a filesystem path. SHGetPathFromIDListW should fail. */
960 hr
= SHGetDesktopFolder(&psfDesktop
);
961 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08x\n", hr
);
962 if (FAILED(hr
)) return;
964 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszMyComputer
, NULL
, &pidlMyComputer
, NULL
);
965 ok (SUCCEEDED(hr
), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08x\n", hr
);
967 IShellFolder_Release(psfDesktop
);
971 SetLastError(0xdeadbeef);
974 result
= pSHGetPathFromIDListW(pidlMyComputer
, wszPath
);
975 ok (!result
, "SHGetPathFromIDListW succeeded where it shouldn't!\n");
976 ok (GetLastError()==0xdeadbeef ||
977 GetLastError()==ERROR_SUCCESS
, /* Vista and higher */
978 "Unexpected last error from SHGetPathFromIDListW: %u\n", GetLastError());
979 ok (!wszPath
[0], "Expected empty path\n");
981 IShellFolder_Release(psfDesktop
);
985 IMalloc_Free(ppM
, pidlMyComputer
);
987 result
= pSHGetSpecialFolderPathW(NULL
, wszFileName
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
988 ok(result
, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
990 IShellFolder_Release(psfDesktop
);
993 myPathAddBackslashW(wszFileName
);
994 lstrcatW(wszFileName
, wszTestFile
);
995 hTestFile
= CreateFileW(wszFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, NULL
);
996 ok(hTestFile
!= INVALID_HANDLE_VALUE
, "CreateFileW failed! Last error: %u\n", GetLastError());
997 if (hTestFile
== INVALID_HANDLE_VALUE
) {
998 IShellFolder_Release(psfDesktop
);
1001 CloseHandle(hTestFile
);
1003 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszTestFile
, NULL
, &pidlTestFile
, NULL
);
1004 ok (SUCCEEDED(hr
), "Desktop's ParseDisplayName failed to parse filename hr = %08x\n", hr
);
1006 IShellFolder_Release(psfDesktop
);
1007 DeleteFileW(wszFileName
);
1008 IMalloc_Free(ppM
, pidlTestFile
);
1012 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
1013 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
1014 hr
= IShellFolder_GetDisplayNameOf(psfDesktop
, pidlTestFile
, SHGDN_FORPARSING
, &strret
);
1015 ok (SUCCEEDED(hr
), "Desktop's GetDisplayNamfOf failed! hr = %08x\n", hr
);
1016 IShellFolder_Release(psfDesktop
);
1017 DeleteFileW(wszFileName
);
1019 IMalloc_Free(ppM
, pidlTestFile
);
1024 pStrRetToBufW(&strret
, pidlTestFile
, wszPath
, MAX_PATH
);
1025 ok(0 == lstrcmpW(wszFileName
, wszPath
),
1026 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
1027 "returned incorrect path for file placed on desktop\n");
1030 result
= pSHGetPathFromIDListW(pidlTestFile
, wszPath
);
1031 ok(result
, "SHGetPathFromIDListW failed! Last error: %u\n", GetLastError());
1032 IMalloc_Free(ppM
, pidlTestFile
);
1033 if (!result
) return;
1034 ok(0 == lstrcmpW(wszFileName
, wszPath
), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
1037 /* Test if we can get the path from the start menu "program files" PIDL. */
1038 hShell32
= GetModuleHandleA("shell32");
1039 pSHGetSpecialFolderLocation
= (void *)GetProcAddress(hShell32
, "SHGetSpecialFolderLocation");
1041 hr
= pSHGetSpecialFolderLocation(NULL
, CSIDL_PROGRAM_FILES
, &pidlPrograms
);
1042 ok(SUCCEEDED(hr
), "SHGetFolderLocation failed: 0x%08x\n", hr
);
1044 SetLastError(0xdeadbeef);
1045 result
= pSHGetPathFromIDListW(pidlPrograms
, wszPath
);
1046 IMalloc_Free(ppM
, pidlPrograms
);
1047 ok(result
, "SHGetPathFromIDListW failed\n");
1050 static void test_EnumObjects_and_CompareIDs(void)
1052 ITEMIDLIST
*newPIDL
;
1053 IShellFolder
*IDesktopFolder
, *testIShellFolder
;
1054 char cCurrDirA
[MAX_PATH
] = {0};
1055 static const CHAR cTestDirA
[] = "\\testdir";
1056 WCHAR cTestDirW
[MAX_PATH
];
1060 GetCurrentDirectoryA(MAX_PATH
, cCurrDirA
);
1061 len
= lstrlenA(cCurrDirA
);
1064 win_skip("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
1067 if(cCurrDirA
[len
-1] == '\\')
1068 cCurrDirA
[len
-1] = 0;
1070 lstrcatA(cCurrDirA
, cTestDirA
);
1071 MultiByteToWideChar(CP_ACP
, 0, cCurrDirA
, -1, cTestDirW
, MAX_PATH
);
1073 hr
= SHGetDesktopFolder(&IDesktopFolder
);
1074 ok(hr
== S_OK
, "SHGetDesktopfolder failed %08x\n", hr
);
1076 CreateFilesFolders();
1078 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
, NULL
, NULL
, cTestDirW
, NULL
, &newPIDL
, 0);
1079 ok(hr
== S_OK
, "ParseDisplayName failed %08x\n", hr
);
1081 hr
= IShellFolder_BindToObject(IDesktopFolder
, newPIDL
, NULL
, (REFIID
)&IID_IShellFolder
, (LPVOID
*)&testIShellFolder
);
1082 ok(hr
== S_OK
, "BindToObject failed %08x\n", hr
);
1084 test_EnumObjects(testIShellFolder
);
1086 IShellFolder_Release(testIShellFolder
);
1090 IMalloc_Free(ppM
, newPIDL
);
1092 IShellFolder_Release(IDesktopFolder
);
1095 /* A simple implementation of an IPropertyBag, which returns fixed values for
1096 * 'Target' and 'Attributes' properties.
1098 static HRESULT WINAPI
InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag
*iface
, REFIID riid
,
1102 return E_INVALIDARG
;
1104 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IPropertyBag
, riid
)) {
1107 ok (FALSE
, "InitPropertyBag asked for unknown interface!\n");
1108 return E_NOINTERFACE
;
1111 IPropertyBag_AddRef(iface
);
1115 static ULONG WINAPI
InitPropertyBag_IPropertyBag_AddRef(IPropertyBag
*iface
) {
1119 static ULONG WINAPI
InitPropertyBag_IPropertyBag_Release(IPropertyBag
*iface
) {
1123 static HRESULT WINAPI
InitPropertyBag_IPropertyBag_Read(IPropertyBag
*iface
, LPCOLESTR pszPropName
,
1124 VARIANT
*pVar
, IErrorLog
*pErrorLog
)
1126 static const WCHAR wszTargetSpecialFolder
[] = {
1127 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
1128 static const WCHAR wszTarget
[] = {
1129 'T','a','r','g','e','t',0 };
1130 static const WCHAR wszAttributes
[] = {
1131 'A','t','t','r','i','b','u','t','e','s',0 };
1132 static const WCHAR wszResolveLinkFlags
[] = {
1133 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
1134 static const WCHAR wszTargetKnownFolder
[] = {
1135 'T','a','r','g','e','t','K','n','o','w','n','F','o','l','d','e','r',0 };
1136 static const WCHAR wszCLSID
[] = {
1137 'C','L','S','I','D',0 };
1139 if (!lstrcmpW(pszPropName
, wszTargetSpecialFolder
)) {
1140 ok(V_VT(pVar
) == VT_I4
||
1141 broken(V_VT(pVar
) == VT_BSTR
), /* Win2k */
1142 "Wrong variant type for 'TargetSpecialFolder' property!\n");
1143 return E_INVALIDARG
;
1146 if (!lstrcmpW(pszPropName
, wszResolveLinkFlags
))
1148 ok(V_VT(pVar
) == VT_UI4
, "Wrong variant type for 'ResolveLinkFlags' property!\n");
1149 return E_INVALIDARG
;
1152 if (!lstrcmpW(pszPropName
, wszTarget
)) {
1153 WCHAR wszPath
[MAX_PATH
];
1156 ok(V_VT(pVar
) == VT_BSTR
||
1157 broken(V_VT(pVar
) == VT_EMPTY
), /* Win2k */
1158 "Wrong variant type for 'Target' property!\n");
1159 if (V_VT(pVar
) != VT_BSTR
) return E_INVALIDARG
;
1161 result
= pSHGetSpecialFolderPathW(NULL
, wszPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
1162 ok(result
, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1163 if (!result
) return E_INVALIDARG
;
1165 V_BSTR(pVar
) = SysAllocString(wszPath
);
1169 if (!lstrcmpW(pszPropName
, wszAttributes
)) {
1170 ok(V_VT(pVar
) == VT_UI4
, "Wrong variant type for 'Attributes' property!\n");
1171 if (V_VT(pVar
) != VT_UI4
) return E_INVALIDARG
;
1172 V_UI4(pVar
) = SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|
1173 SFGAO_CANRENAME
|SFGAO_FILESYSTEM
;
1177 if (!lstrcmpW(pszPropName
, wszTargetKnownFolder
)) {
1178 ok(V_VT(pVar
) == VT_BSTR
, "Wrong variant type for 'TargetKnownFolder' property!\n");
1180 return E_INVALIDARG
;
1183 if (!lstrcmpW(pszPropName
, wszCLSID
)) {
1184 ok(V_VT(pVar
) == VT_EMPTY
, "Wrong variant type for 'CLSID' property!\n");
1186 return E_INVALIDARG
;
1189 ok(FALSE
, "PropertyBag was asked for unknown property %s (vt=%d)!\n", wine_dbgstr_w(pszPropName
), V_VT(pVar
));
1190 return E_INVALIDARG
;
1193 static HRESULT WINAPI
InitPropertyBag_IPropertyBag_Write(IPropertyBag
*iface
, LPCOLESTR pszPropName
,
1196 ok(FALSE
, "Unexpected call to IPropertyBag_Write\n");
1200 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl
= {
1201 InitPropertyBag_IPropertyBag_QueryInterface
,
1202 InitPropertyBag_IPropertyBag_AddRef
,
1203 InitPropertyBag_IPropertyBag_Release
,
1204 InitPropertyBag_IPropertyBag_Read
,
1205 InitPropertyBag_IPropertyBag_Write
1208 static struct IPropertyBag InitPropertyBag
= {
1209 &InitPropertyBag_IPropertyBagVtbl
1212 static void test_FolderShortcut(void) {
1213 IPersistPropertyBag
*pPersistPropertyBag
;
1214 IShellFolder
*pShellFolder
, *pDesktopFolder
;
1215 IPersistFolder3
*pPersistFolder3
;
1218 WCHAR wszDesktopPath
[MAX_PATH
], wszBuffer
[MAX_PATH
];
1221 LPITEMIDLIST pidlCurrentFolder
, pidlWineTestFolder
, pidlSubFolder
;
1223 WCHAR wszWineTestFolder
[] = {
1224 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1225 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1226 WCHAR wszShellExtKey
[] = { 'S','o','f','t','w','a','r','e','\\',
1227 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1228 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1229 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1230 'N','a','m','e','S','p','a','c','e','\\',
1231 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1232 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1234 WCHAR wszSomeSubFolder
[] = { 'S','u','b','F','o','l','d','e','r', 0};
1235 static const GUID CLSID_UnixDosFolder
=
1236 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1238 if (!pSHGetSpecialFolderPathW
|| !pStrRetToBufW
) {
1239 win_skip("SHGetSpecialFolderPathW and/or StrRetToBufW are not available\n");
1243 if (!pSHGetFolderPathAndSubDirA
)
1245 win_skip("FolderShortcut test doesn't work on Win2k\n");
1249 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1250 * via their IPersistPropertyBag interface. And that the target folder
1251 * is taken from the IPropertyBag's 'Target' property.
1253 hr
= CoCreateInstance(&CLSID_FolderShortcut
, NULL
, CLSCTX_INPROC_SERVER
,
1254 &IID_IPersistPropertyBag
, (LPVOID
*)&pPersistPropertyBag
);
1255 if (hr
== REGDB_E_CLASSNOTREG
) {
1256 win_skip("CLSID_FolderShortcut is not implemented\n");
1259 ok (SUCCEEDED(hr
), "CoCreateInstance failed! hr = 0x%08x\n", hr
);
1260 if (FAILED(hr
)) return;
1262 hr
= IPersistPropertyBag_Load(pPersistPropertyBag
, &InitPropertyBag
, NULL
);
1263 ok(SUCCEEDED(hr
), "IPersistPropertyBag_Load failed! hr = %08x\n", hr
);
1265 IPersistPropertyBag_Release(pPersistPropertyBag
);
1269 hr
= IPersistPropertyBag_QueryInterface(pPersistPropertyBag
, &IID_IShellFolder
,
1270 (LPVOID
*)&pShellFolder
);
1271 IPersistPropertyBag_Release(pPersistPropertyBag
);
1272 ok(SUCCEEDED(hr
), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08x\n", hr
);
1273 if (FAILED(hr
)) return;
1275 hr
= IShellFolder_GetDisplayNameOf(pShellFolder
, NULL
, SHGDN_FORPARSING
, &strret
);
1276 ok(SUCCEEDED(hr
), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr
);
1278 IShellFolder_Release(pShellFolder
);
1282 result
= pSHGetSpecialFolderPathW(NULL
, wszDesktopPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
1283 ok(result
, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! %u\n", GetLastError());
1284 if (!result
) return;
1286 pStrRetToBufW(&strret
, NULL
, wszBuffer
, MAX_PATH
);
1287 ok(!lstrcmpiW(wszDesktopPath
, wszBuffer
), "FolderShortcut returned incorrect folder!\n");
1289 hr
= IShellFolder_QueryInterface(pShellFolder
, &IID_IPersistFolder3
, (LPVOID
*)&pPersistFolder3
);
1290 IShellFolder_Release(pShellFolder
);
1291 ok(SUCCEEDED(hr
), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08x\n", hr
);
1292 if (FAILED(hr
)) return;
1294 hr
= IPersistFolder3_GetClassID(pPersistFolder3
, &clsid
);
1295 ok(SUCCEEDED(hr
), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr
);
1296 ok(IsEqualCLSID(&clsid
, &CLSID_FolderShortcut
), "Unexpected CLSID!\n");
1298 hr
= IPersistFolder3_GetCurFolder(pPersistFolder3
, &pidlCurrentFolder
);
1299 ok(SUCCEEDED(hr
), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr
);
1300 ok(!pidlCurrentFolder
, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1302 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1303 * shell namespace. The target folder, read from the property bag above, remains untouched.
1304 * The following tests show this: The itemidlist for some imaginary shellfolder object
1305 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1306 * itemidlist, but GetDisplayNameOf still returns the path from above.
1308 hr
= SHGetDesktopFolder(&pDesktopFolder
);
1309 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08x\n", hr
);
1310 if (FAILED(hr
)) return;
1312 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1313 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1314 RegCreateKeyW(HKEY_CURRENT_USER
, wszShellExtKey
, &hShellExtKey
);
1315 RegCloseKey(hShellExtKey
);
1316 hr
= IShellFolder_ParseDisplayName(pDesktopFolder
, NULL
, NULL
, wszWineTestFolder
, NULL
,
1317 &pidlWineTestFolder
, NULL
);
1318 RegDeleteKeyW(HKEY_CURRENT_USER
, wszShellExtKey
);
1319 IShellFolder_Release(pDesktopFolder
);
1320 ok (SUCCEEDED(hr
), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr
);
1321 if (FAILED(hr
)) return;
1323 hr
= IPersistFolder3_Initialize(pPersistFolder3
, pidlWineTestFolder
);
1324 ok (SUCCEEDED(hr
), "IPersistFolder3::Initialize failed! hr = %08x\n", hr
);
1326 IPersistFolder3_Release(pPersistFolder3
);
1327 pILFree(pidlWineTestFolder
);
1331 hr
= IPersistFolder3_GetCurFolder(pPersistFolder3
, &pidlCurrentFolder
);
1332 ok(SUCCEEDED(hr
), "IPersistFolder3_GetCurFolder failed! hr=0x%08x\n", hr
);
1333 ok(pILIsEqual(pidlCurrentFolder
, pidlWineTestFolder
),
1334 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1335 pILFree(pidlCurrentFolder
);
1336 pILFree(pidlWineTestFolder
);
1338 hr
= IPersistFolder3_QueryInterface(pPersistFolder3
, &IID_IShellFolder
, (LPVOID
*)&pShellFolder
);
1339 IPersistFolder3_Release(pPersistFolder3
);
1340 ok(SUCCEEDED(hr
), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08x\n", hr
);
1341 if (FAILED(hr
)) return;
1343 hr
= IShellFolder_GetDisplayNameOf(pShellFolder
, NULL
, SHGDN_FORPARSING
, &strret
);
1344 ok(SUCCEEDED(hr
), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08x\n", hr
);
1346 IShellFolder_Release(pShellFolder
);
1350 pStrRetToBufW(&strret
, NULL
, wszBuffer
, MAX_PATH
);
1351 ok(!lstrcmpiW(wszDesktopPath
, wszBuffer
), "FolderShortcut returned incorrect folder!\n");
1353 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1354 * but ShellFSFolders. */
1355 myPathAddBackslashW(wszDesktopPath
);
1356 lstrcatW(wszDesktopPath
, wszSomeSubFolder
);
1357 if (!CreateDirectoryW(wszDesktopPath
, NULL
)) {
1358 IShellFolder_Release(pShellFolder
);
1362 hr
= IShellFolder_ParseDisplayName(pShellFolder
, NULL
, NULL
, wszSomeSubFolder
, NULL
,
1363 &pidlSubFolder
, NULL
);
1364 RemoveDirectoryW(wszDesktopPath
);
1365 ok (SUCCEEDED(hr
), "IShellFolder::ParseDisplayName failed! hr = %08x\n", hr
);
1367 IShellFolder_Release(pShellFolder
);
1371 hr
= IShellFolder_BindToObject(pShellFolder
, pidlSubFolder
, NULL
, &IID_IPersistFolder3
,
1372 (LPVOID
*)&pPersistFolder3
);
1373 IShellFolder_Release(pShellFolder
);
1374 pILFree(pidlSubFolder
);
1375 ok (SUCCEEDED(hr
), "IShellFolder::BindToObject failed! hr = %08x\n", hr
);
1379 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1380 * a little bit and also allow CLSID_UnixDosFolder. */
1381 hr
= IPersistFolder3_GetClassID(pPersistFolder3
, &clsid
);
1382 ok(SUCCEEDED(hr
), "IPersistFolder3_GetClassID failed! hr=0x%08x\n", hr
);
1383 ok(IsEqualCLSID(&clsid
, &CLSID_ShellFSFolder
) || IsEqualCLSID(&clsid
, &CLSID_UnixDosFolder
),
1384 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1386 IPersistFolder3_Release(pPersistFolder3
);
1389 #include "pshpack1.h"
1390 struct FileStructA
{
1394 WORD uFileDate
; /* In our current implementation this is */
1395 WORD uFileTime
; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1400 struct FileStructW
{
1401 WORD cbLen
; /* Length of this element. */
1402 BYTE abFooBar1
[6]; /* Beyond any recognition. */
1403 WORD uDate
; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1404 WORD uTime
; /* (this is currently speculation) */
1405 WORD uDate2
; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1406 WORD uTime2
; /* (this is currently speculation) */
1407 BYTE abFooBar2
[4]; /* Beyond any recognition. */
1408 WCHAR wszName
[1]; /* The long filename in unicode. */
1409 /* Just for documentation: Right after the unicode string: */
1410 WORD cbOffset
; /* FileStructW's offset from the beginning of the SHITMEID.
1411 * SHITEMID->cb == uOffset + cbLen */
1413 #include "poppack.h"
1415 static void test_ITEMIDLIST_format(void) {
1416 WCHAR wszPersonal
[MAX_PATH
];
1417 LPSHELLFOLDER psfDesktop
, psfPersonal
;
1418 LPITEMIDLIST pidlPersonal
, pidlFile
;
1422 WCHAR wszFile
[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1423 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1426 if (!pSHGetSpecialFolderPathW
) return;
1428 bResult
= pSHGetSpecialFolderPathW(NULL
, wszPersonal
, CSIDL_PERSONAL
, FALSE
);
1429 ok(bResult
, "SHGetSpecialFolderPathW failed! Last error: %u\n", GetLastError());
1430 if (!bResult
) return;
1432 SetLastError(0xdeadbeef);
1433 bResult
= SetCurrentDirectoryW(wszPersonal
);
1434 if (!bResult
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
) {
1435 win_skip("Most W-calls are not implemented\n");
1438 ok(bResult
, "SetCurrentDirectory failed! Last error: %u\n", GetLastError());
1439 if (!bResult
) return;
1441 hr
= SHGetDesktopFolder(&psfDesktop
);
1442 ok(SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr: %08x\n", hr
);
1443 if (FAILED(hr
)) return;
1445 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszPersonal
, NULL
, &pidlPersonal
, NULL
);
1446 ok(SUCCEEDED(hr
), "psfDesktop->ParseDisplayName failed! hr = %08x\n", hr
);
1448 IShellFolder_Release(psfDesktop
);
1452 hr
= IShellFolder_BindToObject(psfDesktop
, pidlPersonal
, NULL
, &IID_IShellFolder
,
1453 (LPVOID
*)&psfPersonal
);
1454 IShellFolder_Release(psfDesktop
);
1455 pILFree(pidlPersonal
);
1456 ok(SUCCEEDED(hr
), "psfDesktop->BindToObject failed! hr = %08x\n", hr
);
1457 if (FAILED(hr
)) return;
1459 for (i
=0; i
<3; i
++) {
1460 CHAR szFile
[MAX_PATH
];
1461 struct FileStructA
*pFileStructA
;
1464 WideCharToMultiByte(CP_ACP
, 0, wszFile
[i
], -1, szFile
, MAX_PATH
, NULL
, NULL
);
1466 hFile
= CreateFileW(wszFile
[i
], GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, FILE_FLAG_WRITE_THROUGH
, NULL
);
1467 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFile failed! (%u)\n", GetLastError());
1468 if (hFile
== INVALID_HANDLE_VALUE
) {
1469 IShellFolder_Release(psfPersonal
);
1474 hr
= IShellFolder_ParseDisplayName(psfPersonal
, NULL
, NULL
, wszFile
[i
], NULL
, &pidlFile
, NULL
);
1475 DeleteFileW(wszFile
[i
]);
1476 ok(SUCCEEDED(hr
), "psfPersonal->ParseDisplayName failed! hr: %08x\n", hr
);
1478 IShellFolder_Release(psfPersonal
);
1482 pFileStructA
= (struct FileStructA
*)pidlFile
->mkid
.abID
;
1483 ok(pFileStructA
->type
== 0x32, "PIDLTYPE should be 0x32!\n");
1484 ok(pFileStructA
->dummy
== 0x00, "Dummy Byte should be 0x00!\n");
1485 ok(pFileStructA
->dwFileSize
== 0, "Filesize should be zero!\n");
1487 if (i
< 2) /* First two file names are already in valid 8.3 format */
1488 ok(!strcmp(szFile
, (CHAR
*)&pidlFile
->mkid
.abID
[12]), "Wrong file name!\n");
1490 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1491 * can't implement this correctly, since unix filesystems don't support
1492 * this nasty short/long filename stuff. So we'll probably stay with our
1493 * current habbit of storing the long filename here, which seems to work
1496 ok(pidlFile
->mkid
.abID
[18] == '~' ||
1497 broken(pidlFile
->mkid
.abID
[34] == '~'), /* Win2k */
1498 "Should be derived 8.3 name!\n");
1500 if (i
== 0) /* First file name has an even number of chars. No need for alignment. */
1501 ok(pidlFile
->mkid
.abID
[12 + strlen(szFile
) + 1] != '\0' ||
1502 broken(pidlFile
->mkid
.cb
== 2 + 12 + strlen(szFile
) + 1 + 1), /* Win2k */
1503 "Alignment byte, where there shouldn't be!\n");
1505 if (i
== 1) /* Second file name has an uneven number of chars => alignment byte */
1506 ok(pidlFile
->mkid
.abID
[12 + strlen(szFile
) + 1] == '\0',
1507 "There should be an alignment byte, but isn't!\n");
1509 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1510 cbOffset
= *(WORD
*)(((LPBYTE
)pidlFile
)+pidlFile
->mkid
.cb
-sizeof(WORD
));
1511 ok ((cbOffset
>= sizeof(struct FileStructA
) &&
1512 cbOffset
<= pidlFile
->mkid
.cb
- sizeof(struct FileStructW
)) ||
1513 broken(pidlFile
->mkid
.cb
== 2 + 12 + strlen(szFile
) + 1 + 1) || /* Win2k on short names */
1514 broken(pidlFile
->mkid
.cb
== 2 + 12 + strlen(szFile
) + 1 + 12 + 1), /* Win2k on long names */
1515 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset
);
1517 if (cbOffset
>= sizeof(struct FileStructA
) &&
1518 cbOffset
<= pidlFile
->mkid
.cb
- sizeof(struct FileStructW
))
1520 struct FileStructW
*pFileStructW
= (struct FileStructW
*)(((LPBYTE
)pidlFile
)+cbOffset
);
1522 ok(pidlFile
->mkid
.cb
== cbOffset
+ pFileStructW
->cbLen
,
1523 "FileStructW's offset and length should add up to the PIDL's length!\n");
1525 if (pidlFile
->mkid
.cb
== cbOffset
+ pFileStructW
->cbLen
) {
1526 /* Since we just created the file, time of creation,
1527 * time of last access and time of last write access just be the same.
1528 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1529 * after the first run. I do remember something with NTFS keeping the creation time
1530 * if a file is deleted and then created again within a couple of seconds or so.
1531 * Might be the reason. */
1532 ok (pFileStructA
->uFileDate
== pFileStructW
->uDate
&&
1533 pFileStructA
->uFileTime
== pFileStructW
->uTime
,
1534 "Last write time should match creation time!\n");
1536 ok (pFileStructA
->uFileDate
== pFileStructW
->uDate2
&&
1537 pFileStructA
->uFileTime
== pFileStructW
->uTime2
,
1538 "Last write time should match last access time!\n");
1540 ok (!lstrcmpW(wszFile
[i
], pFileStructW
->wszName
) ||
1541 !lstrcmpW(wszFile
[i
], (WCHAR
*)(pFileStructW
->abFooBar2
+ 22)), /* Vista */
1542 "The filename should be stored in unicode at this position!\n");
1550 static void testSHGetFolderPathAndSubDirA(void)
1556 static char wine
[] = "wine";
1557 static char winetemp
[] = "wine\\temp";
1558 static char appdata
[MAX_PATH
];
1559 static char testpath
[MAX_PATH
];
1560 static char toolongpath
[MAX_PATH
+1];
1562 if(!pSHGetFolderPathA
) {
1563 win_skip("SHGetFolderPathA not present!\n");
1566 if(FAILED(pSHGetFolderPathA(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, appdata
)))
1568 skip("SHGetFolderPathA failed for CSIDL_LOCAL_APPDATA!\n");
1572 sprintf(testpath
, "%s\\%s", appdata
, winetemp
);
1573 delret
= RemoveDirectoryA(testpath
);
1574 if(!delret
&& (ERROR_PATH_NOT_FOUND
!= GetLastError()) ) {
1575 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath
, GetLastError());
1579 sprintf(testpath
, "%s\\%s", appdata
, wine
);
1580 delret
= RemoveDirectoryA(testpath
);
1581 if(!delret
&& (ERROR_PATH_NOT_FOUND
!= GetLastError()) && (ERROR_FILE_NOT_FOUND
!= GetLastError())) {
1582 skip("RemoveDirectoryA(%s) failed with error %u\n", testpath
, GetLastError());
1586 /* test invalid second parameter */
1587 ret
= pSHGetFolderPathAndSubDirA(NULL
, CSIDL_FLAG_DONT_VERIFY
| 0xff, NULL
, SHGFP_TYPE_CURRENT
, wine
, testpath
);
1588 ok(E_INVALIDARG
== ret
, "expected E_INVALIDARG, got %x\n", ret
);
1590 /* test fourth parameter */
1591 ret
= pSHGetFolderPathAndSubDirA(NULL
, CSIDL_FLAG_DONT_VERIFY
| CSIDL_LOCAL_APPDATA
, NULL
, 2, winetemp
, testpath
);
1593 case S_OK
: /* winvista */
1594 ok(!strncmp(appdata
, testpath
, strlen(appdata
)),
1595 "expected %s to start with %s\n", testpath
, appdata
);
1596 ok(!lstrcmpA(&testpath
[1 + strlen(appdata
)], winetemp
),
1597 "expected %s to end with %s\n", testpath
, winetemp
);
1599 case E_INVALIDARG
: /* winxp, win2k3 */
1602 ok(0, "expected S_OK or E_INVALIDARG, got %x\n", ret
);
1605 /* test fifth parameter */
1607 ret
= pSHGetFolderPathAndSubDirA(NULL
, CSIDL_FLAG_DONT_VERIFY
| CSIDL_LOCAL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, NULL
, testpath
);
1608 ok(S_OK
== ret
, "expected S_OK, got %x\n", ret
);
1609 ok(!lstrcmpA(appdata
, testpath
), "expected %s, got %s\n", appdata
, testpath
);
1612 ret
= pSHGetFolderPathAndSubDirA(NULL
, CSIDL_FLAG_DONT_VERIFY
| CSIDL_LOCAL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, "", testpath
);
1613 ok(S_OK
== ret
, "expected S_OK, got %x\n", ret
);
1614 ok(!lstrcmpA(appdata
, testpath
), "expected %s, got %s\n", appdata
, testpath
);
1617 ret
= pSHGetFolderPathAndSubDirA(NULL
, CSIDL_FLAG_DONT_VERIFY
| CSIDL_LOCAL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, "\\", testpath
);
1618 ok(S_OK
== ret
, "expected S_OK, got %x\n", ret
);
1619 ok(!lstrcmpA(appdata
, testpath
), "expected %s, got %s\n", appdata
, testpath
);
1621 for(i
=0; i
< MAX_PATH
; i
++)
1622 toolongpath
[i
] = '0' + i
% 10;
1623 toolongpath
[MAX_PATH
] = '\0';
1624 ret
= pSHGetFolderPathAndSubDirA(NULL
, CSIDL_FLAG_DONT_VERIFY
| CSIDL_LOCAL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, toolongpath
, testpath
);
1625 ok(HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
) == ret
,
1626 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
), ret
);
1629 ret
= pSHGetFolderPathAndSubDirA(NULL
, CSIDL_FLAG_DONT_VERIFY
| CSIDL_LOCAL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, wine
, NULL
);
1630 ok((S_OK
== ret
) || (E_INVALIDARG
== ret
), "expected S_OK or E_INVALIDARG, got %x\n", ret
);
1632 /* test a not existing path */
1634 ret
= pSHGetFolderPathAndSubDirA(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, winetemp
, testpath
);
1635 ok(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == ret
,
1636 "expected %x, got %x\n", HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), ret
);
1638 /* create a directory inside a not existing directory */
1640 ret
= pSHGetFolderPathAndSubDirA(NULL
, CSIDL_FLAG_CREATE
| CSIDL_LOCAL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, winetemp
, testpath
);
1641 ok(S_OK
== ret
, "expected S_OK, got %x\n", ret
);
1642 ok(!strncmp(appdata
, testpath
, strlen(appdata
)),
1643 "expected %s to start with %s\n", testpath
, appdata
);
1644 ok(!lstrcmpA(&testpath
[1 + strlen(appdata
)], winetemp
),
1645 "expected %s to end with %s\n", testpath
, winetemp
);
1646 dwret
= GetFileAttributes(testpath
);
1647 ok(FILE_ATTRIBUTE_DIRECTORY
| dwret
, "expected %x to contain FILE_ATTRIBUTE_DIRECTORY\n", dwret
);
1650 sprintf(testpath
, "%s\\%s", appdata
, winetemp
);
1651 RemoveDirectoryA(testpath
);
1652 sprintf(testpath
, "%s\\%s", appdata
, wine
);
1653 RemoveDirectoryA(testpath
);
1656 static void test_LocalizedNames(void)
1658 static char cCurrDirA
[MAX_PATH
];
1659 WCHAR cCurrDirW
[MAX_PATH
], tempbufW
[25];
1660 IShellFolder
*IDesktopFolder
, *testIShellFolder
;
1661 ITEMIDLIST
*newPIDL
;
1664 static char resourcefile
[MAX_PATH
];
1669 static const char desktopini_contents1
[] =
1670 "[.ShellClassInfo]\r\n"
1671 "LocalizedResourceName=@";
1672 static const char desktopini_contents2
[] =
1674 static WCHAR foldernameW
[] = {'t','e','s','t','f','o','l','d','e','r',0};
1675 static const WCHAR folderdisplayW
[] = {'F','o','l','d','e','r',' ','N','a','m','e',' ','R','e','s','o','u','r','c','e',0};
1677 /* create folder with desktop.ini and localized name in GetModuleFileNameA(NULL) */
1678 CreateDirectoryA(".\\testfolder", NULL
);
1680 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")|FILE_ATTRIBUTE_SYSTEM
);
1682 GetModuleFileNameA(NULL
, resourcefile
, MAX_PATH
);
1684 file
= CreateFileA(".\\testfolder\\desktop.ini", GENERIC_WRITE
, 0, NULL
,
1685 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1686 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFileA failed %i\n", GetLastError());
1687 ok(WriteFile(file
, desktopini_contents1
, strlen(desktopini_contents1
), &res
, NULL
) &&
1688 WriteFile(file
, resourcefile
, strlen(resourcefile
), &res
, NULL
) &&
1689 WriteFile(file
, desktopini_contents2
, strlen(desktopini_contents2
), &res
, NULL
),
1690 "WriteFile failed %i\n", GetLastError());
1693 /* get IShellFolder for parent */
1694 GetCurrentDirectoryA(MAX_PATH
, cCurrDirA
);
1695 len
= lstrlenA(cCurrDirA
);
1698 trace("GetCurrentDirectoryA returned empty string. Skipping test_LocalizedNames\n");
1701 if(cCurrDirA
[len
-1] == '\\')
1702 cCurrDirA
[len
-1] = 0;
1704 MultiByteToWideChar(CP_ACP
, 0, cCurrDirA
, -1, cCurrDirW
, MAX_PATH
);
1706 hr
= SHGetDesktopFolder(&IDesktopFolder
);
1707 ok(hr
== S_OK
, "SHGetDesktopfolder failed %08x\n", hr
);
1709 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
, NULL
, NULL
, cCurrDirW
, NULL
, &newPIDL
, 0);
1710 ok(hr
== S_OK
, "ParseDisplayName failed %08x\n", hr
);
1712 hr
= IShellFolder_BindToObject(IDesktopFolder
, newPIDL
, NULL
, (REFIID
)&IID_IShellFolder
, (LPVOID
*)&testIShellFolder
);
1713 ok(hr
== S_OK
, "BindToObject failed %08x\n", hr
);
1715 IMalloc_Free(ppM
, newPIDL
);
1717 /* windows reads the display name from the resource */
1718 hr
= IShellFolder_ParseDisplayName(testIShellFolder
, NULL
, NULL
, foldernameW
, NULL
, &newPIDL
, 0);
1719 ok(hr
== S_OK
, "ParseDisplayName failed %08x\n", hr
);
1721 hr
= IShellFolder_GetDisplayNameOf(testIShellFolder
, newPIDL
, SHGDN_INFOLDER
, &strret
);
1722 ok(hr
== S_OK
, "GetDisplayNameOf failed %08x\n", hr
);
1724 if (SUCCEEDED(hr
) && pStrRetToBufW
)
1726 hr
= pStrRetToBufW(&strret
, newPIDL
, tempbufW
, sizeof(tempbufW
)/sizeof(WCHAR
));
1727 ok (SUCCEEDED(hr
), "StrRetToBufW failed! hr = %08x\n", hr
);
1729 ok (!lstrcmpiW(tempbufW
, folderdisplayW
) ||
1730 broken(!lstrcmpiW(tempbufW
, foldernameW
)), /* W2K */
1731 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW
));
1734 /* editing name is also read from the resource */
1735 hr
= IShellFolder_GetDisplayNameOf(testIShellFolder
, newPIDL
, SHGDN_INFOLDER
|SHGDN_FOREDITING
, &strret
);
1736 ok(hr
== S_OK
, "GetDisplayNameOf failed %08x\n", hr
);
1738 if (SUCCEEDED(hr
) && pStrRetToBufW
)
1740 hr
= pStrRetToBufW(&strret
, newPIDL
, tempbufW
, sizeof(tempbufW
)/sizeof(WCHAR
));
1741 ok (SUCCEEDED(hr
), "StrRetToBufW failed! hr = %08x\n", hr
);
1743 ok (!lstrcmpiW(tempbufW
, folderdisplayW
) ||
1744 broken(!lstrcmpiW(tempbufW
, foldernameW
)), /* W2K */
1745 "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW
));
1748 /* parsing name is unchanged */
1749 hr
= IShellFolder_GetDisplayNameOf(testIShellFolder
, newPIDL
, SHGDN_INFOLDER
|SHGDN_FORPARSING
, &strret
);
1750 ok(hr
== S_OK
, "GetDisplayNameOf failed %08x\n", hr
);
1752 if (SUCCEEDED(hr
) && pStrRetToBufW
)
1754 hr
= pStrRetToBufW(&strret
, newPIDL
, tempbufW
, sizeof(tempbufW
)/sizeof(WCHAR
));
1755 ok (SUCCEEDED(hr
), "StrRetToBufW failed! hr = %08x\n", hr
);
1756 ok (!lstrcmpiW(tempbufW
, foldernameW
), "GetDisplayNameOf returned %s\n", wine_dbgstr_w(tempbufW
));
1759 IShellFolder_Release(IDesktopFolder
);
1760 IShellFolder_Release(testIShellFolder
);
1762 IMalloc_Free(ppM
, newPIDL
);
1765 DeleteFileA(".\\testfolder\\desktop.ini");
1766 SetFileAttributesA(".\\testfolder", GetFileAttributesA(".\\testfolder")&~FILE_ATTRIBUTE_SYSTEM
);
1767 RemoveDirectoryA(".\\testfolder");
1770 static void test_SHCreateShellItem(void)
1772 IShellItem
*shellitem
, *shellitem2
;
1773 IPersistIDList
*persistidl
;
1774 LPITEMIDLIST pidl_cwd
=NULL
, pidl_testfile
, pidl_abstestfile
, pidl_test
;
1776 char curdirA
[MAX_PATH
];
1777 WCHAR curdirW
[MAX_PATH
];
1778 IShellFolder
*desktopfolder
=NULL
, *currentfolder
=NULL
;
1779 static WCHAR testfileW
[] = {'t','e','s','t','f','i','l','e',0};
1781 GetCurrentDirectoryA(MAX_PATH
, curdirA
);
1783 if (!lstrlenA(curdirA
))
1785 win_skip("GetCurrentDirectoryA returned empty string, skipping test_SHCreateShellItem\n");
1789 MultiByteToWideChar(CP_ACP
, 0, curdirA
, -1, curdirW
, MAX_PATH
);
1791 ret
= SHGetDesktopFolder(&desktopfolder
);
1792 ok(SUCCEEDED(ret
), "SHGetShellFolder returned %x\n", ret
);
1794 ret
= IShellFolder_ParseDisplayName(desktopfolder
, NULL
, NULL
, curdirW
, NULL
, &pidl_cwd
, NULL
);
1795 ok(SUCCEEDED(ret
), "ParseDisplayName returned %x\n", ret
);
1797 ret
= IShellFolder_BindToObject(desktopfolder
, pidl_cwd
, NULL
, &IID_IShellFolder
, (void**)¤tfolder
);
1798 ok(SUCCEEDED(ret
), "BindToObject returned %x\n", ret
);
1800 CreateTestFile(".\\testfile");
1802 ret
= IShellFolder_ParseDisplayName(currentfolder
, NULL
, NULL
, testfileW
, NULL
, &pidl_testfile
, NULL
);
1803 ok(SUCCEEDED(ret
), "ParseDisplayName returned %x\n", ret
);
1805 pidl_abstestfile
= pILCombine(pidl_cwd
, pidl_testfile
);
1807 ret
= pSHCreateShellItem(NULL
, NULL
, NULL
, &shellitem
);
1808 ok(ret
== E_INVALIDARG
, "SHCreateShellItem returned %x\n", ret
);
1810 if (0) /* crashes on Windows XP */
1812 pSHCreateShellItem(NULL
, NULL
, pidl_cwd
, NULL
);
1813 pSHCreateShellItem(pidl_cwd
, NULL
, NULL
, &shellitem
);
1814 pSHCreateShellItem(NULL
, currentfolder
, NULL
, &shellitem
);
1815 pSHCreateShellItem(pidl_cwd
, currentfolder
, NULL
, &shellitem
);
1818 ret
= pSHCreateShellItem(NULL
, NULL
, pidl_cwd
, &shellitem
);
1819 ok(SUCCEEDED(ret
), "SHCreateShellItem returned %x\n", ret
);
1822 ret
= IShellItem_QueryInterface(shellitem
, &IID_IPersistIDList
, (void**)&persistidl
);
1823 ok(SUCCEEDED(ret
), "QueryInterface returned %x\n", ret
);
1826 ret
= IPersistIDList_GetIDList(persistidl
, &pidl_test
);
1827 ok(SUCCEEDED(ret
), "GetIDList returned %x\n", ret
);
1830 ok(ILIsEqual(pidl_cwd
, pidl_test
), "id lists are not equal\n");
1833 IPersistIDList_Release(persistidl
);
1835 IShellItem_Release(shellitem
);
1838 ret
= pSHCreateShellItem(pidl_cwd
, NULL
, pidl_testfile
, &shellitem
);
1839 ok(SUCCEEDED(ret
), "SHCreateShellItem returned %x\n", ret
);
1842 ret
= IShellItem_QueryInterface(shellitem
, &IID_IPersistIDList
, (void**)&persistidl
);
1843 ok(SUCCEEDED(ret
), "QueryInterface returned %x\n", ret
);
1846 ret
= IPersistIDList_GetIDList(persistidl
, &pidl_test
);
1847 ok(SUCCEEDED(ret
), "GetIDList returned %x\n", ret
);
1850 ok(ILIsEqual(pidl_abstestfile
, pidl_test
), "id lists are not equal\n");
1853 IPersistIDList_Release(persistidl
);
1856 ret
= IShellItem_GetParent(shellitem
, &shellitem2
);
1857 ok(SUCCEEDED(ret
), "GetParent returned %x\n", ret
);
1860 ret
= IShellItem_QueryInterface(shellitem2
, &IID_IPersistIDList
, (void**)&persistidl
);
1861 ok(SUCCEEDED(ret
), "QueryInterface returned %x\n", ret
);
1864 ret
= IPersistIDList_GetIDList(persistidl
, &pidl_test
);
1865 ok(SUCCEEDED(ret
), "GetIDList returned %x\n", ret
);
1868 ok(ILIsEqual(pidl_cwd
, pidl_test
), "id lists are not equal\n");
1871 IPersistIDList_Release(persistidl
);
1873 IShellItem_Release(shellitem2
);
1876 IShellItem_Release(shellitem
);
1879 ret
= pSHCreateShellItem(NULL
, currentfolder
, pidl_testfile
, &shellitem
);
1880 ok(SUCCEEDED(ret
), "SHCreateShellItem returned %x\n", ret
);
1883 ret
= IShellItem_QueryInterface(shellitem
, &IID_IPersistIDList
, (void**)&persistidl
);
1884 ok(SUCCEEDED(ret
), "QueryInterface returned %x\n", ret
);
1887 ret
= IPersistIDList_GetIDList(persistidl
, &pidl_test
);
1888 ok(SUCCEEDED(ret
), "GetIDList returned %x\n", ret
);
1891 ok(ILIsEqual(pidl_abstestfile
, pidl_test
), "id lists are not equal\n");
1894 IPersistIDList_Release(persistidl
);
1896 IShellItem_Release(shellitem
);
1899 /* if a parent pidl and shellfolder are specified, the shellfolder is ignored */
1900 ret
= pSHCreateShellItem(pidl_cwd
, desktopfolder
, pidl_testfile
, &shellitem
);
1901 ok(SUCCEEDED(ret
), "SHCreateShellItem returned %x\n", ret
);
1904 ret
= IShellItem_QueryInterface(shellitem
, &IID_IPersistIDList
, (void**)&persistidl
);
1905 ok(SUCCEEDED(ret
), "QueryInterface returned %x\n", ret
);
1908 ret
= IPersistIDList_GetIDList(persistidl
, &pidl_test
);
1909 ok(SUCCEEDED(ret
), "GetIDList returned %x\n", ret
);
1912 ok(ILIsEqual(pidl_abstestfile
, pidl_test
), "id lists are not equal\n");
1915 IPersistIDList_Release(persistidl
);
1917 IShellItem_Release(shellitem
);
1920 DeleteFileA(".\\testfile");
1921 pILFree(pidl_abstestfile
);
1922 pILFree(pidl_testfile
);
1924 IShellFolder_Release(currentfolder
);
1925 IShellFolder_Release(desktopfolder
);
1928 START_TEST(shlfolder
)
1930 init_function_pointers();
1931 /* if OleInitialize doesn't get called, ParseDisplayName returns
1932 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1933 OleInitialize(NULL
);
1935 test_ParseDisplayName();
1936 test_BindToObject();
1937 test_EnumObjects_and_CompareIDs();
1938 test_GetDisplayName();
1939 test_GetAttributesOf();
1940 test_SHGetPathFromIDList();
1941 test_CallForAttributes();
1942 test_FolderShortcut();
1943 test_ITEMIDLIST_format();
1944 if(pSHGetFolderPathAndSubDirA
)
1945 testSHGetFolderPathAndSubDirA();
1947 skip("SHGetFolderPathAndSubDirA not present\n");
1948 test_LocalizedNames();
1949 if(pSHCreateShellItem
)
1950 test_SHCreateShellItem();
1952 win_skip("test_SHCreateShellItem not present\n");