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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
40 #include "wine/unicode.h"
41 #include "wine/test.h"
46 static HRESULT (WINAPI
*pSHBindToParent
)(LPCITEMIDLIST
, REFIID
, LPVOID
*, LPCITEMIDLIST
*);
47 static BOOL (WINAPI
*pSHGetSpecialFolderPathW
)(HWND
, LPWSTR
, int, BOOL
);
48 static HRESULT (WINAPI
*pStrRetToBufW
)(STRRET
*,LPCITEMIDLIST
,LPWSTR
,UINT
);
49 static LPITEMIDLIST (WINAPI
*pILFindLastID
)(LPCITEMIDLIST
);
51 static void init_function_pointers(void)
56 hmod
= GetModuleHandleA("shell32.dll");
59 pSHBindToParent
= (void*)GetProcAddress(hmod
, "SHBindToParent");
60 pSHGetSpecialFolderPathW
= (void*)GetProcAddress(hmod
, "SHGetSpecialFolderPathW");
61 pILFindLastID
= (void *)GetProcAddress(hmod
, (LPCSTR
)16);
65 hmod
= GetModuleHandleA("shlwapi.dll");
68 pStrRetToBufW
= (void*)GetProcAddress(hmod
, "StrRetToBufW");
71 hr
= SHGetMalloc(&ppM
);
72 ok(hr
== S_OK
, "SHGetMalloc failed %08lx\n", hr
);
75 static void test_ParseDisplayName(void)
78 IShellFolder
*IDesktopFolder
;
79 static const char *cNonExistDir1A
= "c:\\nonexist_subdir";
80 static const char *cNonExistDir2A
= "c:\\\\nonexist_subdir";
82 WCHAR cTestDirW
[MAX_PATH
] = {0};
85 hr
= SHGetDesktopFolder(&IDesktopFolder
);
86 if(hr
!= S_OK
) return;
88 res
= GetFileAttributesA(cNonExistDir1A
);
89 if(res
!= INVALID_FILE_ATTRIBUTES
) return;
91 MultiByteToWideChar(CP_ACP
, 0, cNonExistDir1A
, -1, cTestDirW
, MAX_PATH
);
92 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
,
93 NULL
, NULL
, cTestDirW
, NULL
, &newPIDL
, 0);
94 ok((hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)) || (hr
== E_FAIL
),
95 "ParseDisplayName returned %08lx, expected 80070002 or E_FAIL\n", hr
);
97 res
= GetFileAttributesA(cNonExistDir2A
);
98 if(res
!= INVALID_FILE_ATTRIBUTES
) return;
100 MultiByteToWideChar(CP_ACP
, 0, cNonExistDir2A
, -1, cTestDirW
, MAX_PATH
);
101 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
,
102 NULL
, NULL
, cTestDirW
, NULL
, &newPIDL
, 0);
103 ok((hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)) || (hr
== E_FAIL
) || (hr
== E_INVALIDARG
),
104 "ParseDisplayName returned %08lx, expected 80070002, E_FAIL or E_INVALIDARG\n", hr
);
107 /* creates a file with the specified name for tests */
108 static void CreateTestFile(const CHAR
*name
)
113 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
114 if (file
!= INVALID_HANDLE_VALUE
)
116 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
117 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
123 /* initializes the tests */
124 static void CreateFilesFolders(void)
126 CreateDirectoryA(".\\testdir", NULL
);
127 CreateDirectoryA(".\\testdir\\test.txt", NULL
);
128 CreateTestFile (".\\testdir\\test1.txt ");
129 CreateTestFile (".\\testdir\\test2.txt ");
130 CreateTestFile (".\\testdir\\test3.txt ");
131 CreateDirectoryA(".\\testdir\\testdir2 ", NULL
);
132 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL
);
135 /* cleans after tests */
136 static void Cleanup(void)
138 DeleteFileA(".\\testdir\\test1.txt");
139 DeleteFileA(".\\testdir\\test2.txt");
140 DeleteFileA(".\\testdir\\test3.txt");
141 RemoveDirectoryA(".\\testdir\\test.txt");
142 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
143 RemoveDirectoryA(".\\testdir\\testdir2");
144 RemoveDirectoryA(".\\testdir");
149 static void test_EnumObjects(IShellFolder
*iFolder
)
151 IEnumIDList
*iEnumList
;
152 LPITEMIDLIST newPIDL
, idlArr
[10];
157 static const WORD iResults
[5][5] =
166 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
167 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
168 static const ULONG attrs
[5] =
170 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
| SFGAO_FOLDER
| SFGAO_FILESYSANCESTOR
,
171 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
| SFGAO_FOLDER
| SFGAO_FILESYSANCESTOR
,
172 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
,
173 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
,
174 SFGAO_CAPABILITYMASK
| SFGAO_FILESYSTEM
,
177 hr
= IShellFolder_EnumObjects(iFolder
, NULL
, SHCONTF_FOLDERS
| SHCONTF_NONFOLDERS
| SHCONTF_INCLUDEHIDDEN
, &iEnumList
);
178 ok(hr
== S_OK
, "EnumObjects failed %08lx\n", hr
);
180 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
181 * the filesystem shellfolders return S_OK even if less than 'celt' items are
182 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
183 * only ever returns a single entry per call. */
184 while (IEnumIDList_Next(iEnumList
, 10-i
, &idlArr
[i
], &NumPIDLs
) == S_OK
)
186 ok (i
== 5, "i: %d\n", i
);
188 hr
= IEnumIDList_Release(iEnumList
);
189 ok(hr
== S_OK
, "IEnumIDList_Release failed %08lx\n", hr
);
191 /* Sort them first in case of wrong order from system */
192 for (i
=0;i
<5;i
++) for (j
=0;j
<5;j
++)
193 if ((SHORT
)IShellFolder_CompareIDs(iFolder
, 0, idlArr
[i
], idlArr
[j
]) < 0)
196 idlArr
[i
] = idlArr
[j
];
200 for (i
=0;i
<5;i
++) for (j
=0;j
<5;j
++)
202 hr
= IShellFolder_CompareIDs(iFolder
, 0, idlArr
[i
], idlArr
[j
]);
203 ok(hr
== iResults
[i
][j
], "Got %lx expected [%d]-[%d]=%x\n", hr
, i
, j
, iResults
[i
][j
]);
207 for (i
= 0; i
< 5; i
++)
210 /* Native returns all flags no matter what we ask for */
211 flags
= SFGAO_CANCOPY
;
212 hr
= IShellFolder_GetAttributesOf(iFolder
, 1, (LPCITEMIDLIST
*)(idlArr
+ i
), &flags
);
213 flags
&= SFGAO_testfor
;
214 ok(hr
== S_OK
, "GetAttributesOf returns %08lx\n", hr
);
215 ok(flags
== (attrs
[i
]), "GetAttributesOf[%i] got %08lx, expected %08lx\n", i
, flags
, attrs
[i
]);
217 flags
= SFGAO_testfor
;
218 hr
= IShellFolder_GetAttributesOf(iFolder
, 1, (LPCITEMIDLIST
*)(idlArr
+ i
), &flags
);
219 flags
&= SFGAO_testfor
;
220 ok(hr
== S_OK
, "GetAttributesOf returns %08lx\n", hr
);
221 ok(flags
== attrs
[i
], "GetAttributesOf[%i] got %08lx, expected %08lx\n", i
, flags
, attrs
[i
]);
225 IMalloc_Free(ppM
, idlArr
[i
]);
228 static void test_BindToObject(void)
232 IShellFolder
*psfDesktop
, *psfChild
, *psfMyComputer
, *psfSystemDir
;
233 SHITEMID emptyitem
= { 0, { 0 } };
234 LPITEMIDLIST pidlMyComputer
, pidlSystemDir
, pidlEmpty
= (LPITEMIDLIST
)&emptyitem
;
235 WCHAR wszSystemDir
[MAX_PATH
];
236 char szSystemDir
[MAX_PATH
];
237 WCHAR wszMyComputer
[] = {
238 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
239 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
241 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
242 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
244 hr
= SHGetDesktopFolder(&psfDesktop
);
245 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08lx\n", hr
);
246 if (FAILED(hr
)) return;
248 hr
= IShellFolder_BindToObject(psfDesktop
, pidlEmpty
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
249 ok (hr
== E_INVALIDARG
, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr
);
251 hr
= IShellFolder_BindToObject(psfDesktop
, NULL
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
252 ok (hr
== E_INVALIDARG
, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr
);
254 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszMyComputer
, NULL
, &pidlMyComputer
, NULL
);
255 ok (SUCCEEDED(hr
), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr
);
257 IShellFolder_Release(psfDesktop
);
261 hr
= IShellFolder_BindToObject(psfDesktop
, pidlMyComputer
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfMyComputer
);
262 ok (SUCCEEDED(hr
), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr
);
263 IShellFolder_Release(psfDesktop
);
264 IMalloc_Free(ppM
, pidlMyComputer
);
265 if (FAILED(hr
)) return;
267 hr
= IShellFolder_BindToObject(psfMyComputer
, pidlEmpty
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
268 ok (hr
== E_INVALIDARG
, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr
);
271 /* this call segfaults on 98SE */
272 hr
= IShellFolder_BindToObject(psfMyComputer
, NULL
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
273 ok (hr
== E_INVALIDARG
, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr
);
276 cChars
= GetSystemDirectoryA(szSystemDir
, MAX_PATH
);
277 ok (cChars
> 0 && cChars
< MAX_PATH
, "GetSystemDirectoryA failed! LastError: %08lx\n", GetLastError());
278 if (cChars
== 0 || cChars
>= MAX_PATH
) {
279 IShellFolder_Release(psfMyComputer
);
282 MultiByteToWideChar(CP_ACP
, 0, szSystemDir
, -1, wszSystemDir
, MAX_PATH
);
284 hr
= IShellFolder_ParseDisplayName(psfMyComputer
, NULL
, NULL
, wszSystemDir
, NULL
, &pidlSystemDir
, NULL
);
285 ok (SUCCEEDED(hr
), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08lx\n", hr
);
287 IShellFolder_Release(psfMyComputer
);
291 hr
= IShellFolder_BindToObject(psfMyComputer
, pidlSystemDir
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfSystemDir
);
292 ok (SUCCEEDED(hr
), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08lx\n", hr
);
293 IShellFolder_Release(psfMyComputer
);
294 IMalloc_Free(ppM
, pidlSystemDir
);
295 if (FAILED(hr
)) return;
297 hr
= IShellFolder_BindToObject(psfSystemDir
, pidlEmpty
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
298 ok (hr
== E_INVALIDARG
,
299 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr
);
302 /* this call segfaults on 98SE */
303 hr
= IShellFolder_BindToObject(psfSystemDir
, NULL
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfChild
);
304 ok (hr
== E_INVALIDARG
,
305 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr
);
308 IShellFolder_Release(psfSystemDir
);
311 static void test_GetDisplayName(void)
316 WCHAR wszTestFile
[MAX_PATH
], wszTestFile2
[MAX_PATH
], wszTestDir
[MAX_PATH
];
317 char szTestFile
[MAX_PATH
], szTestDir
[MAX_PATH
];
319 LPSHELLFOLDER psfDesktop
, psfPersonal
;
321 SHITEMID emptyitem
= { 0, { 0 } };
322 LPITEMIDLIST pidlTestFile
, pidlEmpty
= (LPITEMIDLIST
)&emptyitem
;
323 LPCITEMIDLIST pidlLast
;
324 static const WCHAR wszFileName
[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
325 static const WCHAR wszDirName
[] = { 'w','i','n','e','t','e','s','t',0 };
327 /* I'm trying to figure if there is a functional difference between calling
328 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
329 * binding to the shellfolder. One thing I thought of was that perhaps
330 * SHGetPathFromIDList would be able to get the path to a file, which does
331 * not exist anymore, while the other method would'nt. It turns out there's
332 * no functional difference in this respect.
335 if(!pSHGetSpecialFolderPathW
) return;
337 /* First creating a directory in MyDocuments and a file in this directory. */
338 result
= pSHGetSpecialFolderPathW(NULL
, wszTestDir
, CSIDL_PERSONAL
, FALSE
);
339 ok(result
, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
342 PathAddBackslashW(wszTestDir
);
343 lstrcatW(wszTestDir
, wszDirName
);
344 WideCharToMultiByte(CP_ACP
, 0, wszTestDir
, -1, szTestDir
, MAX_PATH
, 0, 0);
345 result
= CreateDirectoryA(szTestDir
, NULL
);
346 ok(result
, "CreateDirectoryA failed! Last error: %08lx\n", GetLastError());
349 lstrcpyW(wszTestFile
, wszTestDir
);
350 PathAddBackslashW(wszTestFile
);
351 lstrcatW(wszTestFile
, wszFileName
);
352 WideCharToMultiByte(CP_ACP
, 0, wszTestFile
, -1, szTestFile
, MAX_PATH
, 0, 0);
354 hTestFile
= CreateFileA(szTestFile
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
355 ok((hTestFile
!= INVALID_HANDLE_VALUE
), "CreateFileA failed! Last error: %08lx\n", GetLastError());
356 if (hTestFile
== INVALID_HANDLE_VALUE
) return;
357 CloseHandle(hTestFile
);
359 /* Getting an itemidlist for the file. */
360 hr
= SHGetDesktopFolder(&psfDesktop
);
361 ok(SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08lx\n", hr
);
362 if (FAILED(hr
)) return;
364 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszTestFile
, NULL
, &pidlTestFile
, NULL
);
365 ok(SUCCEEDED(hr
), "Desktop->ParseDisplayName failed! hr = %08lx\n", hr
);
367 IShellFolder_Release(psfDesktop
);
371 /* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
372 pidlLast
= pILFindLastID(pidlTestFile
);
373 ok(pidlLast
->mkid
.cb
>=76, "Expected pidl length of at least 76, got %d.\n", pidlLast
->mkid
.cb
);
374 if (pidlLast
->mkid
.cb
>= 76) {
375 ok(!lstrcmpW((WCHAR
*)&pidlLast
->mkid
.abID
[46], wszFileName
),
376 "WinXP stores the filename as a wchar-string at this position!\n");
379 /* It seems as if we cannot bind to regular files on windows, but only directories.
381 hr
= IShellFolder_BindToObject(psfDesktop
, pidlTestFile
, NULL
, &IID_IUnknown
, (VOID
**)&psfFile
);
382 todo_wine
{ ok (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "hr = %08lx\n", hr
); }
384 IShellFolder_Release(psfFile
);
387 /* Some tests for IShellFolder::SetNameOf */
388 hr
= pSHBindToParent(pidlTestFile
, &IID_IShellFolder
, (VOID
**)&psfPersonal
, &pidlLast
);
389 ok(SUCCEEDED(hr
), "SHBindToParent failed! hr = %08lx\n", hr
);
391 /* It's ok to use this fixed path. Call will fail anyway. */
392 WCHAR wszAbsoluteFilename
[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
393 LPITEMIDLIST pidlNew
;
395 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
396 hr
= IShellFolder_SetNameOf(psfPersonal
, NULL
, pidlLast
, wszDirName
, SHGDN_NORMAL
, &pidlNew
);
397 ok (SUCCEEDED(hr
), "SetNameOf failed! hr = %08lx\n", hr
);
398 ok (((LPITEMIDLIST
)((LPBYTE
)pidlNew
+pidlNew
->mkid
.cb
))->mkid
.cb
== 0,
399 "pidl returned from SetNameOf should be simple!\n");
401 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
402 * is implemented on top of SHFileOperation in WinXP. */
403 hr
= IShellFolder_SetNameOf(psfPersonal
, NULL
, pidlNew
, wszAbsoluteFilename
,
404 SHGDN_FORPARSING
, NULL
);
405 ok (hr
== HRESULT_FROM_WIN32(ERROR_CANCELLED
), "SetNameOf succeeded! hr = %08lx\n", hr
);
407 /* Rename the file back to it's original name. SetNameOf ignores the fact, that the
408 * SHGDN flags specify an absolute path. */
409 hr
= IShellFolder_SetNameOf(psfPersonal
, NULL
, pidlNew
, wszFileName
, SHGDN_FORPARSING
, NULL
);
410 ok (SUCCEEDED(hr
), "SetNameOf failed! hr = %08lx\n", hr
);
413 IShellFolder_Release(psfPersonal
);
416 /* Deleting the file and the directory */
417 DeleteFileA(szTestFile
);
418 RemoveDirectoryA(szTestDir
);
420 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
421 result
= SHGetPathFromIDListW(pidlTestFile
, wszTestFile2
);
422 ok (result
, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
423 ok (!lstrcmpiW(wszTestFile
, wszTestFile2
), "SHGetPathFromIDListW returns incorrect path!\n");
425 if(!pSHBindToParent
) return;
427 /* SHBindToParent fails, if called with a NULL PIDL. */
428 hr
= pSHBindToParent(NULL
, &IID_IShellFolder
, (VOID
**)&psfPersonal
, &pidlLast
);
429 ok (FAILED(hr
), "SHBindToParent(NULL) should fail!\n");
431 /* But it succeeds with an empty PIDL. */
432 hr
= pSHBindToParent(pidlEmpty
, &IID_IShellFolder
, (VOID
**)&psfPersonal
, &pidlLast
);
433 ok (SUCCEEDED(hr
), "SHBindToParent(empty PIDL) should succeed! hr = %08lx\n", hr
);
434 ok (pidlLast
== pidlEmpty
, "The last element of an empty PIDL should be the PIDL itself!\n");
436 IShellFolder_Release(psfPersonal
);
438 /* Binding to the folder and querying the display name of the file also works. */
439 hr
= pSHBindToParent(pidlTestFile
, &IID_IShellFolder
, (VOID
**)&psfPersonal
, &pidlLast
);
440 ok (SUCCEEDED(hr
), "SHBindToParent failed! hr = %08lx\n", hr
);
442 IShellFolder_Release(psfDesktop
);
446 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
447 * pidlTestFile (In accordance with MSDN). */
448 ok (pILFindLastID(pidlTestFile
) == pidlLast
,
449 "SHBindToParent doesn't return the last id of the pidl param!\n");
451 hr
= IShellFolder_GetDisplayNameOf(psfPersonal
, pidlLast
, SHGDN_FORPARSING
, &strret
);
452 ok (SUCCEEDED(hr
), "Personal->GetDisplayNameOf failed! hr = %08lx\n", hr
);
454 IShellFolder_Release(psfDesktop
);
455 IShellFolder_Release(psfPersonal
);
461 hr
= pStrRetToBufW(&strret
, pidlLast
, wszTestFile2
, MAX_PATH
);
462 ok (SUCCEEDED(hr
), "StrRetToBufW failed! hr = %08lx\n", hr
);
463 ok (!lstrcmpiW(wszTestFile
, wszTestFile2
), "GetDisplayNameOf returns incorrect path!\n");
466 IShellFolder_Release(psfDesktop
);
467 IShellFolder_Release(psfPersonal
);
470 static void test_CallForAttributes(void)
476 LPSHELLFOLDER psfDesktop
;
477 LPITEMIDLIST pidlMyDocuments
;
478 DWORD dwAttributes
, dwCallForAttributes
, dwOrigAttributes
, dwOrigCallForAttributes
;
479 static const WCHAR wszAttributes
[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
480 static const WCHAR wszCallForAttributes
[] = {
481 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
482 static const WCHAR wszMyDocumentsKey
[] = {
483 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
484 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
485 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
486 WCHAR wszMyDocuments
[] = {
487 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
488 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
490 /* For the root of a namespace extension, the attributes are not queried by binding
491 * to the object and calling GetAttributesOf. Instead, the attributes are read from
492 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
494 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
495 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
496 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
497 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
499 hr
= SHGetDesktopFolder(&psfDesktop
);
500 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08lx\n", hr
);
501 if (FAILED(hr
)) return;
503 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszMyDocuments
, NULL
,
504 &pidlMyDocuments
, NULL
);
506 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08lx\n", hr
);
508 IShellFolder_Release(psfDesktop
);
512 dwAttributes
= 0xffffffff;
513 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 1,
514 (LPCITEMIDLIST
*)&pidlMyDocuments
, &dwAttributes
);
515 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr
);
517 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
518 ok (dwAttributes
& SFGAO_FILESYSTEM
, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
519 ok (!(dwAttributes
& SFGAO_ISSLOW
), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
520 ok (!(dwAttributes
& SFGAO_GHOSTED
), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
522 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
523 * key. So the test will return at this point, if run on wine.
525 lResult
= RegOpenKeyExW(HKEY_CLASSES_ROOT
, wszMyDocumentsKey
, 0, KEY_WRITE
|KEY_READ
, &hKey
);
526 ok (lResult
== ERROR_SUCCESS
, "RegOpenKeyEx failed! result: %08lx\n", lResult
);
527 if (lResult
!= ERROR_SUCCESS
) {
528 IMalloc_Free(ppM
, pidlMyDocuments
);
529 IShellFolder_Release(psfDesktop
);
533 /* Query MyDocuments' Attributes value, to be able to restore it later. */
534 dwSize
= sizeof(DWORD
);
535 lResult
= RegQueryValueExW(hKey
, wszAttributes
, NULL
, NULL
, (LPBYTE
)&dwOrigAttributes
, &dwSize
);
536 ok (lResult
== ERROR_SUCCESS
, "RegQueryValueEx failed! result: %08lx\n", lResult
);
537 if (lResult
!= ERROR_SUCCESS
) {
539 IMalloc_Free(ppM
, pidlMyDocuments
);
540 IShellFolder_Release(psfDesktop
);
544 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
545 dwSize
= sizeof(DWORD
);
546 lResult
= RegQueryValueExW(hKey
, wszCallForAttributes
, NULL
, NULL
,
547 (LPBYTE
)&dwOrigCallForAttributes
, &dwSize
);
548 ok (lResult
== ERROR_SUCCESS
, "RegQueryValueEx failed! result: %08lx\n", lResult
);
549 if (lResult
!= ERROR_SUCCESS
) {
551 IMalloc_Free(ppM
, pidlMyDocuments
);
552 IShellFolder_Release(psfDesktop
);
556 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
557 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
558 * SFGAO_FILESYSTEM attributes. */
559 dwAttributes
= SFGAO_ISSLOW
|SFGAO_GHOSTED
;
560 RegSetValueExW(hKey
, wszAttributes
, 0, REG_DWORD
, (LPBYTE
)&dwAttributes
, sizeof(DWORD
));
561 dwCallForAttributes
= SFGAO_ISSLOW
|SFGAO_FILESYSTEM
;
562 RegSetValueExW(hKey
, wszCallForAttributes
, 0, REG_DWORD
,
563 (LPBYTE
)&dwCallForAttributes
, sizeof(DWORD
));
565 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
566 * GetAttributesOf. It seems that once there is a single attribute queried, for which
567 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
568 * the flags in Attributes are ignored.
570 dwAttributes
= SFGAO_ISSLOW
|SFGAO_GHOSTED
|SFGAO_FILESYSTEM
;
571 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 1,
572 (LPCITEMIDLIST
*)&pidlMyDocuments
, &dwAttributes
);
573 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr
);
575 ok (dwAttributes
== SFGAO_FILESYSTEM
,
576 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08lx\n",
579 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
580 RegSetValueExW(hKey
, wszAttributes
, 0, REG_DWORD
, (LPBYTE
)&dwOrigAttributes
, sizeof(DWORD
));
581 RegSetValueExW(hKey
, wszCallForAttributes
, 0, REG_DWORD
,
582 (LPBYTE
)&dwOrigCallForAttributes
, sizeof(DWORD
));
584 IMalloc_Free(ppM
, pidlMyDocuments
);
585 IShellFolder_Release(psfDesktop
);
588 static void test_GetAttributesOf(void)
591 LPSHELLFOLDER psfDesktop
, psfMyComputer
;
592 SHITEMID emptyitem
= { 0, { 0 } };
593 LPCITEMIDLIST pidlEmpty
= (LPCITEMIDLIST
)&emptyitem
;
594 LPITEMIDLIST pidlMyComputer
;
596 static const DWORD dwDesktopFlags
= /* As observed on WinXP SP2 */
597 SFGAO_STORAGE
| SFGAO_HASPROPSHEET
| SFGAO_STORAGEANCESTOR
|
598 SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_FILESYSTEM
| SFGAO_HASSUBFOLDER
;
599 static const DWORD dwMyComputerFlags
= /* As observed on WinXP SP2 */
600 SFGAO_CANRENAME
| SFGAO_CANDELETE
| SFGAO_HASPROPSHEET
|
601 SFGAO_DROPTARGET
| SFGAO_FILESYSANCESTOR
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
;
602 WCHAR wszMyComputer
[] = {
603 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
604 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
606 hr
= SHGetDesktopFolder(&psfDesktop
);
607 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08lx\n", hr
);
608 if (FAILED(hr
)) return;
610 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
611 dwFlags
= 0xffffffff;
612 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 1, &pidlEmpty
, &dwFlags
);
613 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08lx\n", hr
);
614 ok (dwFlags
== dwDesktopFlags
, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
615 dwFlags
, dwDesktopFlags
);
617 /* .. or with no itemidlist at all. */
618 dwFlags
= 0xffffffff;
619 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 0, NULL
, &dwFlags
);
620 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(NULL) failed! hr = %08lx\n", hr
);
621 ok (dwFlags
== dwDesktopFlags
, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
622 dwFlags
, dwDesktopFlags
);
624 /* Testing the attributes of the MyComputer shellfolder */
625 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszMyComputer
, NULL
, &pidlMyComputer
, NULL
);
626 ok (SUCCEEDED(hr
), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr
);
628 IShellFolder_Release(psfDesktop
);
632 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
633 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
634 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
635 * should create a link to the original data". You can't create links on MyComputer on
636 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
637 * depends on this bug, we probably shouldn't imitate it.
639 dwFlags
= 0xffffffff;
640 hr
= IShellFolder_GetAttributesOf(psfDesktop
, 1, (LPCITEMIDLIST
*)&pidlMyComputer
, &dwFlags
);
641 ok (SUCCEEDED(hr
), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08lx\n", hr
);
642 ok ((dwFlags
& ~(DWORD
)SFGAO_CANLINK
) == dwMyComputerFlags
,
643 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags
, dwMyComputerFlags
);
645 hr
= IShellFolder_BindToObject(psfDesktop
, pidlMyComputer
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfMyComputer
);
646 ok (SUCCEEDED(hr
), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr
);
647 IShellFolder_Release(psfDesktop
);
648 IMalloc_Free(ppM
, pidlMyComputer
);
649 if (FAILED(hr
)) return;
651 hr
= IShellFolder_GetAttributesOf(psfMyComputer
, 1, &pidlEmpty
, &dwFlags
);
652 todo_wine
{ok (hr
== E_INVALIDARG
, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08lx\n", hr
); }
654 dwFlags
= 0xffffffff;
655 hr
= IShellFolder_GetAttributesOf(psfMyComputer
, 0, NULL
, &dwFlags
);
656 ok (SUCCEEDED(hr
), "MyComputer->GetAttributesOf(NULL) failed! hr = %08lx\n", hr
);
657 todo_wine
{ ok (dwFlags
== dwMyComputerFlags
,
658 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags
, dwMyComputerFlags
); }
660 IShellFolder_Release(psfMyComputer
);
663 static void test_SHGetPathFromIDList(void)
665 SHITEMID emptyitem
= { 0, { 0 } };
666 LPCITEMIDLIST pidlEmpty
= (LPCITEMIDLIST
)&emptyitem
;
667 LPITEMIDLIST pidlMyComputer
;
668 WCHAR wszPath
[MAX_PATH
], wszDesktop
[MAX_PATH
];
671 LPSHELLFOLDER psfDesktop
;
672 WCHAR wszMyComputer
[] = {
673 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
674 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
675 WCHAR wszFileName
[MAX_PATH
];
676 LPITEMIDLIST pidlTestFile
;
679 static WCHAR wszTestFile
[] = {
680 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
681 HRESULT (WINAPI
*pSHGetSpecialFolderLocation
)(HWND
, int, LPITEMIDLIST
*);
683 LPITEMIDLIST pidlPrograms
;
685 if(!pSHGetSpecialFolderPathW
) return;
687 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
688 result
= pSHGetSpecialFolderPathW(NULL
, wszDesktop
, CSIDL_DESKTOP
, FALSE
);
689 ok(result
, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %08lx\n", GetLastError());
692 result
= SHGetPathFromIDListW(pidlEmpty
, wszPath
);
693 ok(result
, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
695 ok(!lstrcmpiW(wszDesktop
, wszPath
), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
697 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
698 hr
= SHGetDesktopFolder(&psfDesktop
);
699 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08lx\n", hr
);
700 if (FAILED(hr
)) return;
702 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszMyComputer
, NULL
, &pidlMyComputer
, NULL
);
703 ok (SUCCEEDED(hr
), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr
);
705 IShellFolder_Release(psfDesktop
);
709 SetLastError(0xdeadbeef);
710 result
= SHGetPathFromIDListW(pidlMyComputer
, wszPath
);
711 ok (!result
, "SHGetPathFromIDList succeeded where it shouldn't!\n");
712 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %08lx\n", GetLastError());
714 IShellFolder_Release(psfDesktop
);
718 IMalloc_Free(ppM
, pidlMyComputer
);
720 result
= pSHGetSpecialFolderPathW(NULL
, wszFileName
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
721 ok(result
, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
723 IShellFolder_Release(psfDesktop
);
726 PathAddBackslashW(wszFileName
);
727 lstrcatW(wszFileName
, wszTestFile
);
728 hTestFile
= CreateFileW(wszFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, NULL
);
729 ok(hTestFile
!= INVALID_HANDLE_VALUE
, "CreateFileW failed! Last error: %08lx\n", GetLastError());
730 if (hTestFile
== INVALID_HANDLE_VALUE
) {
731 IShellFolder_Release(psfDesktop
);
734 CloseHandle(hTestFile
);
736 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszTestFile
, NULL
, &pidlTestFile
, NULL
);
737 ok (SUCCEEDED(hr
), "Desktop's ParseDisplayName failed to parse filename hr = %08lx\n", hr
);
739 IShellFolder_Release(psfDesktop
);
740 DeleteFileW(wszFileName
);
741 IMalloc_Free(ppM
, pidlTestFile
);
745 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
746 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
747 hr
= IShellFolder_GetDisplayNameOf(psfDesktop
, pidlTestFile
, SHGDN_FORPARSING
, &strret
);
748 ok (SUCCEEDED(hr
), "Desktop's GetDisplayNamfOf failed! hr = %08lx\n", hr
);
749 IShellFolder_Release(psfDesktop
);
750 DeleteFileW(wszFileName
);
752 IMalloc_Free(ppM
, pidlTestFile
);
757 pStrRetToBufW(&strret
, pidlTestFile
, wszPath
, MAX_PATH
);
758 ok(0 == lstrcmpW(wszFileName
, wszPath
),
759 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
760 "returned incorrect path for file placed on desktop\n");
763 result
= SHGetPathFromIDListW(pidlTestFile
, wszPath
);
764 ok(result
, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
765 IMalloc_Free(ppM
, pidlTestFile
);
767 ok(0 == lstrcmpW(wszFileName
, wszPath
), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
770 /* Test if we can get the path from the start menu "program files" PIDL. */
771 hShell32
= GetModuleHandleA("shell32");
772 pSHGetSpecialFolderLocation
= (HRESULT(WINAPI
*)(HWND
,int,LPITEMIDLIST
*))GetProcAddress(hShell32
, "SHGetSpecialFolderLocation");
774 hr
= pSHGetSpecialFolderLocation(NULL
, CSIDL_PROGRAM_FILES
, &pidlPrograms
);
775 ok(SUCCEEDED(hr
), "SHGetFolderLocation failed: 0x%08lx\n", hr
);
777 SetLastError(0xdeadbeef);
778 result
= SHGetPathFromIDListW(pidlPrograms
, wszPath
);
779 IMalloc_Free(ppM
, pidlPrograms
);
780 ok(result
, "SHGetPathFromIDList failed\n");
783 static void test_EnumObjects_and_CompareIDs(void)
786 IShellFolder
*IDesktopFolder
, *testIShellFolder
;
787 char cCurrDirA
[MAX_PATH
] = {0};
788 WCHAR cCurrDirW
[MAX_PATH
];
789 static const WCHAR cTestDirW
[] = {'\\','t','e','s','t','d','i','r',0};
793 GetCurrentDirectoryA(MAX_PATH
, cCurrDirA
);
794 len
= lstrlenA(cCurrDirA
);
797 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
800 if(cCurrDirA
[len
-1] == '\\')
801 cCurrDirA
[len
-1] = 0;
803 MultiByteToWideChar(CP_ACP
, 0, cCurrDirA
, -1, cCurrDirW
, MAX_PATH
);
804 strcatW(cCurrDirW
, cTestDirW
);
806 hr
= SHGetDesktopFolder(&IDesktopFolder
);
807 ok(hr
== S_OK
, "SHGetDesktopfolder failed %08lx\n", hr
);
809 CreateFilesFolders();
811 hr
= IShellFolder_ParseDisplayName(IDesktopFolder
, NULL
, NULL
, cCurrDirW
, NULL
, &newPIDL
, 0);
812 ok(hr
== S_OK
, "ParseDisplayName failed %08lx\n", hr
);
814 hr
= IShellFolder_BindToObject(IDesktopFolder
, newPIDL
, NULL
, (REFIID
)&IID_IShellFolder
, (LPVOID
*)&testIShellFolder
);
815 ok(hr
== S_OK
, "BindToObject failed %08lx\n", hr
);
817 test_EnumObjects(testIShellFolder
);
819 hr
= IShellFolder_Release(testIShellFolder
);
820 ok(hr
== S_OK
, "IShellFolder_Release failed %08lx\n", hr
);
824 IMalloc_Free(ppM
, newPIDL
);
827 /* A simple implementation of an IPropertyBag, which returns fixed values for
828 * 'Target' and 'Attributes' properties.
830 static HRESULT WINAPI
InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag
*iface
, REFIID riid
,
836 if (IsEqualIID(&IID_IUnknown
, riid
) || IsEqualIID(&IID_IPropertyBag
, riid
)) {
839 ok (FALSE
, "InitPropertyBag asked for unknown interface!\n");
840 return E_NOINTERFACE
;
843 IPropertyBag_AddRef(iface
);
847 static ULONG WINAPI
InitPropertyBag_IPropertyBag_AddRef(IPropertyBag
*iface
) {
851 static ULONG WINAPI
InitPropertyBag_IPropertyBag_Release(IPropertyBag
*iface
) {
855 static HRESULT WINAPI
InitPropertyBag_IPropertyBag_Read(IPropertyBag
*iface
, LPCOLESTR pszPropName
,
856 VARIANT
*pVar
, IErrorLog
*pErrorLog
)
858 static const WCHAR wszTargetSpecialFolder
[] = {
859 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
860 static const WCHAR wszTarget
[] = {
861 'T','a','r','g','e','t',0 };
862 static const WCHAR wszAttributes
[] = {
863 'A','t','t','r','i','b','u','t','e','s',0 };
864 static const WCHAR wszResolveLinkFlags
[] = {
865 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
867 if (!lstrcmpW(pszPropName
, wszTargetSpecialFolder
)) {
868 ok(V_VT(pVar
) == VT_I4
, "Wrong variant type for 'TargetSpecialFolder' property!\n");
872 if (!lstrcmpW(pszPropName
, wszResolveLinkFlags
))
874 ok(V_VT(pVar
) == VT_UI4
, "Wrong variant type for 'ResolveLinkFlags' property!\n");
878 if (!lstrcmpW(pszPropName
, wszTarget
)) {
879 WCHAR wszPath
[MAX_PATH
];
882 ok(V_VT(pVar
) == VT_BSTR
, "Wrong variant type for 'Target' property!\n");
883 if (V_VT(pVar
) != VT_BSTR
) return E_INVALIDARG
;
885 result
= pSHGetSpecialFolderPathW(NULL
, wszPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
886 ok(result
, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! x%08lx\n", GetLastError());
887 if (!result
) return E_INVALIDARG
;
889 V_BSTR(pVar
) = SysAllocString(wszPath
);
893 if (!lstrcmpW(pszPropName
, wszAttributes
)) {
894 ok(V_VT(pVar
) == VT_UI4
, "Wrong variant type for 'Attributes' property!\n");
895 if (V_VT(pVar
) != VT_UI4
) return E_INVALIDARG
;
896 V_UI4(pVar
) = SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
|SFGAO_FILESYSANCESTOR
|
897 SFGAO_CANRENAME
|SFGAO_FILESYSTEM
;
901 ok(FALSE
, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar
));
905 static HRESULT WINAPI
InitPropertyBag_IPropertyBag_Write(IPropertyBag
*iface
, LPCOLESTR pszPropName
,
908 ok(FALSE
, "Unexpected call to IPropertyBag_Write\n");
912 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl
= {
913 InitPropertyBag_IPropertyBag_QueryInterface
,
914 InitPropertyBag_IPropertyBag_AddRef
,
915 InitPropertyBag_IPropertyBag_Release
,
916 InitPropertyBag_IPropertyBag_Read
,
917 InitPropertyBag_IPropertyBag_Write
920 struct IPropertyBag InitPropertyBag
= {
921 &InitPropertyBag_IPropertyBagVtbl
924 void test_FolderShortcut(void) {
925 IPersistPropertyBag
*pPersistPropertyBag
;
926 IShellFolder
*pShellFolder
, *pDesktopFolder
;
927 IPersistFolder3
*pPersistFolder3
;
930 WCHAR wszDesktopPath
[MAX_PATH
], wszBuffer
[MAX_PATH
];
933 LPITEMIDLIST pidlCurrentFolder
, pidlWineTestFolder
, pidlSubFolder
;
935 WCHAR wszWineTestFolder
[] = {
936 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
937 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
938 WCHAR wszShellExtKey
[] = { 'S','o','f','t','w','a','r','e','\\',
939 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
940 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
941 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
942 'N','a','m','e','S','p','a','c','e','\\',
943 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
944 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
946 WCHAR wszSomeSubFolder
[] = { 'S','u','b','F','o','l','d','e','r', 0};
947 static const GUID CLSID_UnixDosFolder
=
948 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
950 if (!pSHGetSpecialFolderPathW
|| !pStrRetToBufW
) return;
952 /* These tests basically show, that CLSID_FolderShortcuts are initialized
953 * via their IPersistPropertyBag interface. And that the target folder
954 * is taken from the IPropertyBag's 'Target' property.
956 hr
= CoCreateInstance(&CLSID_FolderShortcut
, NULL
, CLSCTX_INPROC_SERVER
,
957 &IID_IPersistPropertyBag
, (LPVOID
*)&pPersistPropertyBag
);
958 ok (SUCCEEDED(hr
), "CoCreateInstance failed! hr = 0x%08lx\n", hr
);
959 if (FAILED(hr
)) return;
961 hr
= IPersistPropertyBag_Load(pPersistPropertyBag
, &InitPropertyBag
, NULL
);
962 ok(SUCCEEDED(hr
), "IPersistPropertyBag_Load failed! hr = %08lx\n", hr
);
964 IPersistPropertyBag_Release(pPersistPropertyBag
);
968 hr
= IPersistPropertyBag_QueryInterface(pPersistPropertyBag
, &IID_IShellFolder
,
969 (LPVOID
*)&pShellFolder
);
970 IPersistPropertyBag_Release(pPersistPropertyBag
);
971 ok(SUCCEEDED(hr
), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08lx\n", hr
);
972 if (FAILED(hr
)) return;
974 hr
= IShellFolder_GetDisplayNameOf(pShellFolder
, NULL
, SHGDN_FORPARSING
, &strret
);
975 ok(SUCCEEDED(hr
), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08lx\n", hr
);
977 IShellFolder_Release(pShellFolder
);
981 result
= pSHGetSpecialFolderPathW(NULL
, wszDesktopPath
, CSIDL_DESKTOPDIRECTORY
, FALSE
);
982 ok(result
, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! 0x%08lx\n", GetLastError());
985 pStrRetToBufW(&strret
, NULL
, wszBuffer
, MAX_PATH
);
986 ok(!lstrcmpiW(wszDesktopPath
, wszBuffer
), "FolderShortcut returned incorrect folder!\n");
988 hr
= IShellFolder_QueryInterface(pShellFolder
, &IID_IPersistFolder3
, (LPVOID
*)&pPersistFolder3
);
989 IShellFolder_Release(pShellFolder
);
990 ok(SUCCEEDED(hr
), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08lx\n", hr
);
991 if (FAILED(hr
)) return;
993 hr
= IPersistFolder3_GetClassID(pPersistFolder3
, &clsid
);
994 ok(SUCCEEDED(hr
), "IPersistFolder3_GetClassID failed! hr=0x%08lx\n", hr
);
995 ok(IsEqualCLSID(&clsid
, &CLSID_FolderShortcut
), "Unexpected CLSID!\n");
997 hr
= IPersistFolder3_GetCurFolder(pPersistFolder3
, &pidlCurrentFolder
);
998 ok(SUCCEEDED(hr
), "IPersistFolder3_GetCurFolder failed! hr=0x%08lx\n", hr
);
999 ok(!pidlCurrentFolder
, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1001 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1002 * shell namespace. The target folder, read from the property bag above, remains untouched.
1003 * The following tests show this: The itemidlist for some imaginary shellfolder object
1004 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1005 * itemidlist, but GetDisplayNameOf still returns the path from above.
1007 hr
= SHGetDesktopFolder(&pDesktopFolder
);
1008 ok (SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr = %08lx\n", hr
);
1009 if (FAILED(hr
)) return;
1011 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1012 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1013 RegCreateKeyW(HKEY_CURRENT_USER
, wszShellExtKey
, &hShellExtKey
);
1014 RegCloseKey(hShellExtKey
);
1015 hr
= IShellFolder_ParseDisplayName(pDesktopFolder
, NULL
, NULL
, wszWineTestFolder
, NULL
,
1016 &pidlWineTestFolder
, NULL
);
1017 RegDeleteKeyW(HKEY_CURRENT_USER
, wszShellExtKey
);
1018 IShellFolder_Release(pDesktopFolder
);
1019 ok (SUCCEEDED(hr
), "IShellFolder::ParseDisplayName failed! hr = %08lx\n", hr
);
1020 if (FAILED(hr
)) return;
1022 hr
= IPersistFolder3_Initialize(pPersistFolder3
, pidlWineTestFolder
);
1023 ok (SUCCEEDED(hr
), "IPersistFolder3::Initialize failed! hr = %08lx\n", hr
);
1025 IPersistFolder3_Release(pPersistFolder3
);
1026 ILFree(pidlWineTestFolder
);
1030 hr
= IPersistFolder3_GetCurFolder(pPersistFolder3
, &pidlCurrentFolder
);
1031 ok(SUCCEEDED(hr
), "IPersistFolder3_GetCurFolder failed! hr=0x%08lx\n", hr
);
1032 ok(ILIsEqual(pidlCurrentFolder
, pidlWineTestFolder
),
1033 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1034 ILFree(pidlCurrentFolder
);
1035 ILFree(pidlWineTestFolder
);
1037 hr
= IPersistFolder3_QueryInterface(pPersistFolder3
, &IID_IShellFolder
, (LPVOID
*)&pShellFolder
);
1038 IPersistFolder3_Release(pPersistFolder3
);
1039 ok(SUCCEEDED(hr
), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08lx\n", hr
);
1040 if (FAILED(hr
)) return;
1042 hr
= IShellFolder_GetDisplayNameOf(pShellFolder
, NULL
, SHGDN_FORPARSING
, &strret
);
1043 ok(SUCCEEDED(hr
), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08lx\n", hr
);
1045 IShellFolder_Release(pShellFolder
);
1049 pStrRetToBufW(&strret
, NULL
, wszBuffer
, MAX_PATH
);
1050 ok(!lstrcmpiW(wszDesktopPath
, wszBuffer
), "FolderShortcut returned incorrect folder!\n");
1052 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1053 * but ShellFSFolders. */
1054 PathAddBackslashW(wszDesktopPath
);
1055 lstrcatW(wszDesktopPath
, wszSomeSubFolder
);
1056 if (!CreateDirectoryW(wszDesktopPath
, NULL
)) {
1057 IShellFolder_Release(pShellFolder
);
1061 hr
= IShellFolder_ParseDisplayName(pShellFolder
, NULL
, NULL
, wszSomeSubFolder
, NULL
,
1062 &pidlSubFolder
, NULL
);
1063 RemoveDirectoryW(wszDesktopPath
);
1064 ok (SUCCEEDED(hr
), "IShellFolder::ParseDisplayName failed! hr = %08lx\n", hr
);
1066 IShellFolder_Release(pShellFolder
);
1070 hr
= IShellFolder_BindToObject(pShellFolder
, pidlSubFolder
, NULL
, &IID_IPersistFolder3
,
1071 (LPVOID
*)&pPersistFolder3
);
1072 IShellFolder_Release(pShellFolder
);
1073 ILFree(pidlSubFolder
);
1074 ok (SUCCEEDED(hr
), "IShellFolder::BindToObject failed! hr = %08lx\n", hr
);
1078 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1079 * a little bit and also allow CLSID_UnixDosFolder. */
1080 hr
= IPersistFolder3_GetClassID(pPersistFolder3
, &clsid
);
1081 ok(SUCCEEDED(hr
), "IPersistFolder3_GetClassID failed! hr=0x%08lx\n", hr
);
1082 ok(IsEqualCLSID(&clsid
, &CLSID_ShellFSFolder
) || IsEqualCLSID(&clsid
, &CLSID_UnixDosFolder
),
1083 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1085 IPersistFolder3_Release(pPersistFolder3
);
1088 #include "pshpack1.h"
1089 struct FileStructA
{
1093 WORD uFileDate
; /* In our current implementation this is */
1094 WORD uFileTime
; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1099 struct FileStructW
{
1100 WORD cbLen
; /* Length of this element. */
1101 BYTE abFooBar1
[6]; /* Beyond any recognition. */
1102 WORD uDate
; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1103 WORD uTime
; /* (this is currently speculation) */
1104 WORD uDate2
; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1105 WORD uTime2
; /* (this is currently speculation) */
1106 BYTE abFooBar2
[4]; /* Beyond any recognition. */
1107 WCHAR wszName
[1]; /* The long filename in unicode. */
1108 /* Just for documentation: Right after the unicode string: */
1109 WORD cbOffset
; /* FileStructW's offset from the beginning of the SHITMEID.
1110 * SHITEMID->cb == uOffset + cbLen */
1112 #include "poppack.h"
1114 void test_ITEMIDLIST_format(void) {
1115 WCHAR wszPersonal
[MAX_PATH
];
1116 LPSHELLFOLDER psfDesktop
, psfPersonal
;
1117 LPITEMIDLIST pidlPersonal
, pidlFile
;
1121 WCHAR wszFile
[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1122 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1125 if(!pSHGetSpecialFolderPathW
) return;
1127 bResult
= pSHGetSpecialFolderPathW(NULL
, wszPersonal
, CSIDL_PERSONAL
, FALSE
);
1128 ok(bResult
, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
1129 if (!bResult
) return;
1131 bResult
= SetCurrentDirectoryW(wszPersonal
);
1132 ok(bResult
, "SetCurrentDirectory failed! Last error: %ld\n", GetLastError());
1133 if (!bResult
) return;
1135 hr
= SHGetDesktopFolder(&psfDesktop
);
1136 ok(SUCCEEDED(hr
), "SHGetDesktopFolder failed! hr: %08lx\n", hr
);
1137 if (FAILED(hr
)) return;
1139 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, wszPersonal
, NULL
, &pidlPersonal
, NULL
);
1140 ok(SUCCEEDED(hr
), "psfDesktop->ParseDisplayName failed! hr = %08lx\n", hr
);
1142 IShellFolder_Release(psfDesktop
);
1146 hr
= IShellFolder_BindToObject(psfDesktop
, pidlPersonal
, NULL
, &IID_IShellFolder
,
1147 (LPVOID
*)&psfPersonal
);
1148 IShellFolder_Release(psfDesktop
);
1149 ILFree(pidlPersonal
);
1150 ok(SUCCEEDED(hr
), "psfDesktop->BindToObject failed! hr = %08lx\n", hr
);
1151 if (FAILED(hr
)) return;
1153 for (i
=0; i
<3; i
++) {
1154 CHAR szFile
[MAX_PATH
];
1155 struct FileStructA
*pFileStructA
;
1158 WideCharToMultiByte(CP_ACP
, 0, wszFile
[i
], -1, szFile
, MAX_PATH
, NULL
, NULL
);
1160 hFile
= CreateFileW(wszFile
[i
], GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, FILE_FLAG_WRITE_THROUGH
, NULL
);
1161 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFile failed! (%ld)\n", GetLastError());
1162 if (hFile
== INVALID_HANDLE_VALUE
) {
1163 IShellFolder_Release(psfPersonal
);
1168 hr
= IShellFolder_ParseDisplayName(psfPersonal
, NULL
, NULL
, wszFile
[i
], NULL
, &pidlFile
, NULL
);
1169 DeleteFileW(wszFile
[i
]);
1170 ok(SUCCEEDED(hr
), "psfPersonal->ParseDisplayName failed! hr: %08lx\n", hr
);
1172 IShellFolder_Release(psfPersonal
);
1176 pFileStructA
= (struct FileStructA
*)pidlFile
->mkid
.abID
;
1177 ok(pFileStructA
->type
== 0x32, "PIDLTYPE should be 0x32!\n");
1178 ok(pFileStructA
->dummy
== 0x00, "Dummy Byte should be 0x00!\n");
1179 ok(pFileStructA
->dwFileSize
== 0, "Filesize should be zero!\n");
1181 if (i
< 2) /* First two file names are already in valid 8.3 format */
1182 ok(!strcmp(szFile
, (CHAR
*)&pidlFile
->mkid
.abID
[12]), "Wrong file name!\n");
1184 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1185 * can't implement this correctly, since unix filesystems don't support
1186 * this nasty short/long filename stuff. So we'll probably stay with our
1187 * current habbit of storing the long filename here, which seems to work
1189 todo_wine
{ ok(pidlFile
->mkid
.abID
[18] == '~', "Should be derived 8.3 name!\n"); }
1191 if (i
== 0) /* First file name has an even number of chars. No need for alignment. */
1192 ok(pidlFile
->mkid
.abID
[12 + strlen(szFile
) + 1] != '\0',
1193 "Alignment byte, where there shouldn't be!\n");
1195 if (i
== 1) /* Second file name has an uneven number of chars => alignment byte */
1196 ok(pidlFile
->mkid
.abID
[12 + strlen(szFile
) + 1] == '\0',
1197 "There should be an alignment byte, but isn't!\n");
1199 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1200 cbOffset
= *(WORD
*)(((LPBYTE
)pidlFile
)+pidlFile
->mkid
.cb
-sizeof(WORD
));
1201 ok (cbOffset
>= sizeof(struct FileStructA
) &&
1202 cbOffset
<= pidlFile
->mkid
.cb
- sizeof(struct FileStructW
),
1203 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset
);
1205 if (cbOffset
>= sizeof(struct FileStructA
) &&
1206 cbOffset
<= pidlFile
->mkid
.cb
- sizeof(struct FileStructW
))
1208 struct FileStructW
*pFileStructW
= (struct FileStructW
*)(((LPBYTE
)pidlFile
)+cbOffset
);
1210 ok(pidlFile
->mkid
.cb
== cbOffset
+ pFileStructW
->cbLen
,
1211 "FileStructW's offset and length should add up to the PIDL's length!\n");
1213 if (pidlFile
->mkid
.cb
== cbOffset
+ pFileStructW
->cbLen
) {
1214 /* Since we just created the file, time of creation,
1215 * time of last access and time of last write access just be the same.
1216 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1217 * after the first run. I do remember something with NTFS keeping the creation time
1218 * if a file is deleted and then created again within a couple of seconds or so.
1219 * Might be the reason. */
1220 ok (pFileStructA
->uFileDate
== pFileStructW
->uDate
&&
1221 pFileStructA
->uFileTime
== pFileStructW
->uTime
,
1222 "Last write time should match creation time!\n");
1224 ok (pFileStructA
->uFileDate
== pFileStructW
->uDate2
&&
1225 pFileStructA
->uFileTime
== pFileStructW
->uTime2
,
1226 "Last write time should match last access time!\n");
1228 ok (!lstrcmpW(wszFile
[i
], pFileStructW
->wszName
),
1229 "The filename should be stored in unicode at this position!\n");
1237 START_TEST(shlfolder
)
1239 init_function_pointers();
1240 /* if OleInitialize doesn't get called, ParseDisplayName returns
1241 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1242 OleInitialize(NULL
);
1244 test_ParseDisplayName();
1245 test_BindToObject();
1246 test_EnumObjects_and_CompareIDs();
1247 test_GetDisplayName();
1248 test_GetAttributesOf();
1249 test_SHGetPathFromIDList();
1250 test_CallForAttributes();
1251 test_FolderShortcut();
1252 test_ITEMIDLIST_format();