2 * Tests for special shell folders
4 * Copyright 2008 Robert Shearman for CodeWeavers
5 * Copyright 2008 Owen Rudge
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define WIN32_LEAN_AND_MEAN
32 #include "wine/test.h"
34 static inline BOOL
SHELL_OsIsUnicode(void)
36 return !(GetVersion() & 0x80000000);
39 /* Tests for My Computer */
40 static void test_parse_for_my_computer(void)
42 WCHAR path
[] = { '\\','\\','?','\\','C',':','\\',0 };
43 IShellFolder
*mycomp
, *sf
;
44 WCHAR
*drive
= path
+ 4;
49 hr
= SHGetDesktopFolder(&sf
);
50 ok(hr
== S_OK
, "SHGetDesktopFolder failed with error 0x%lx\n", hr
);
51 if (hr
!= S_OK
) return;
52 hr
= SHGetSpecialFolderLocation(NULL
, CSIDL_DRIVES
, &pidl
);
53 ok(hr
== S_OK
, "SHGetSpecialFolderLocation failed with error 0x%lx\n", hr
);
56 IShellFolder_Release(sf
);
59 hr
= IShellFolder_BindToObject(sf
, pidl
, NULL
, &IID_IShellFolder
, (void**)&mycomp
);
60 ok(hr
== S_OK
, "IShellFolder::BindToObject failed with error 0x%lx\n", hr
);
61 IShellFolder_Release(sf
);
63 if (hr
!= S_OK
) return;
65 while (drive
[0] <= 'Z' && GetDriveTypeW(drive
) == DRIVE_NO_ROOT_DIR
) drive
[0]++;
68 skip("No drive found, skipping My Computer tests...\n");
74 hr
= IShellFolder_ParseDisplayName(mycomp
, NULL
, NULL
, drive
, &eaten
, &pidl
, NULL
);
75 ok(hr
== S_OK
, "IShellFolder::ParseDisplayName failed with error 0x%lx\n", hr
);
77 ok(eaten
== 0xdeadbeef, "eaten should not have been set to %lu\n", eaten
);
78 ok(pidl
!= NULL
, "pidl is NULL\n");
81 /* \\?\ prefix is not valid */
84 hr
= IShellFolder_ParseDisplayName(mycomp
, NULL
, NULL
, path
, &eaten
, &pidl
, NULL
);
85 ok(hr
== E_INVALIDARG
, "IShellFolder::ParseDisplayName should have failed with E_INVALIDARG, got 0x%08lx\n", hr
);
87 ok(eaten
== 0xdeadbeef, "eaten should not have been set to %lu\n", eaten
);
88 ok(pidl
== NULL
, "pidl is not NULL\n");
91 /* Try without backslash */
95 hr
= IShellFolder_ParseDisplayName(mycomp
, NULL
, NULL
, drive
, &eaten
, &pidl
, NULL
);
96 ok(hr
== S_OK
|| broken(hr
== E_INVALIDARG
) /* WinXP */,
97 "IShellFolder::ParseDisplayName failed with error 0x%lx\n", hr
);
99 ok(eaten
== 0xdeadbeef, "eaten should not have been set to %lu\n", eaten
);
100 ok(pidl
!= NULL
|| broken(!pidl
) /* WinXP */, "pidl is NULL\n");
104 IShellFolder_Release(mycomp
);
107 /* Tests for My Network Places */
108 static void test_parse_for_entire_network(void)
110 static WCHAR my_network_places_path
[] = {
111 ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-',
112 '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 };
113 static WCHAR entire_network_path
[] = {
114 ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-',
115 '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D',
116 '}','\\','E','n','t','i','r','e','N','e','t','w','o','r','k',0 };
117 IShellFolder
*psfDesktop
;
119 DWORD eaten
= 0xdeadbeef;
124 hr
= SHGetDesktopFolder(&psfDesktop
);
125 ok(hr
== S_OK
, "SHGetDesktopFolder failed with error 0x%lx\n", hr
);
127 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, my_network_places_path
, &eaten
, &pidl
, &attr
);
128 ok(hr
== S_OK
, "IShellFolder_ParseDisplayName failed with error 0x%lx\n", hr
);
130 ok(eaten
== 0xdeadbeef, "eaten should not have been set to %lu\n", eaten
);
131 expected_attr
= SFGAO_HASSUBFOLDER
|SFGAO_FOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_DROPTARGET
|SFGAO_HASPROPSHEET
|SFGAO_CANRENAME
|SFGAO_CANLINK
;
133 ok((attr
== expected_attr
) || /* Win9x, NT4 */
134 (attr
== (expected_attr
| SFGAO_STREAM
)) || /* W2K */
135 (attr
== (expected_attr
| SFGAO_CANDELETE
)) || /* XP, W2K3 */
136 (attr
== (expected_attr
| SFGAO_CANDELETE
| SFGAO_NONENUMERATED
)), /* Vista */
137 "Unexpected attributes : %08lx\n", attr
);
141 /* Start clean again */
145 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, entire_network_path
, &eaten
, &pidl
, &attr
);
146 IShellFolder_Release(psfDesktop
);
147 if (hr
== HRESULT_FROM_WIN32(ERROR_BAD_NET_NAME
) ||
148 hr
== HRESULT_FROM_WIN32(ERROR_NO_NET_OR_BAD_PATH
) ||
149 hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
))
151 win_skip("'EntireNetwork' is not available on Win9x, NT4 and Vista\n");
154 ok(hr
== S_OK
, "IShellFolder_ParseDisplayName failed with error 0x%lx\n", hr
);
156 ok(eaten
== 0xdeadbeef, "eaten should not have been set to %lu\n", eaten
);
157 expected_attr
= SFGAO_HASSUBFOLDER
|SFGAO_FOLDER
|SFGAO_FILESYSANCESTOR
|SFGAO_HASPROPSHEET
|SFGAO_CANLINK
;
159 ok(attr
== expected_attr
|| /* winme, nt4 */
160 attr
== (expected_attr
| SFGAO_STREAM
) || /* win2k */
161 attr
== (expected_attr
| SFGAO_STORAGEANCESTOR
), /* others */
162 "attr should be 0x%lx, not 0x%lx\n", expected_attr
, attr
);
167 /* Tests for Control Panel */
168 static void test_parse_for_control_panel(void)
170 /* path of My Computer\Control Panel */
171 static WCHAR control_panel_path
[] = {
172 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}','\\',
173 ':',':','{','2','1','E','C','2','0','2','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','D','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 };
174 IShellFolder
*psfDesktop
;
176 DWORD eaten
= 0xdeadbeef;
180 hr
= SHGetDesktopFolder(&psfDesktop
);
181 ok(hr
== S_OK
, "SHGetDesktopFolder failed with error 0x%lx\n", hr
);
183 hr
= IShellFolder_ParseDisplayName(psfDesktop
, NULL
, NULL
, control_panel_path
, &eaten
, &pidl
, &attr
);
184 ok(hr
== S_OK
, "IShellFolder_ParseDisplayName failed with error 0x%lx\n", hr
);
185 todo_wine
ok(eaten
== 0xdeadbeef, "eaten should not have been set to %lu\n", eaten
);
187 ok((attr
== (SFGAO_CANLINK
| SFGAO_FOLDER
)) || /* Win9x, NT4 */
188 (attr
== (SFGAO_CANLINK
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
| SFGAO_STREAM
)) || /* W2K */
189 (attr
== (SFGAO_CANLINK
| SFGAO_FOLDER
| SFGAO_HASSUBFOLDER
)) || /* W2K, XP, W2K3 */
190 (attr
== (SFGAO_CANLINK
| SFGAO_NONENUMERATED
)) || /* Vista */
191 (attr
== SFGAO_CANLINK
), /* Vista, W2K8 */
192 "Unexpected attributes : %08lx\n", attr
);
195 IShellFolder_Release(psfDesktop
);
198 static void test_printers_folder(void)
200 IShellFolder2
*folder
;
202 SHELLDETAILS details
;
204 LPITEMIDLIST pidl1
, pidl2
;
208 CoInitialize( NULL
);
210 hr
= CoCreateInstance(&CLSID_Printers
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IShellFolder2
, (void**)&folder
);
213 win_skip("Failed to created IShellFolder2 for Printers folder\n");
221 IShellFolder2_GetDetailsOf(folder
, NULL
, 0, NULL
);
222 IShellFolder2_GetDefaultColumnState(folder
, 0, NULL
);
223 IPersistFolder2_GetCurFolder(pf
, NULL
);
226 /* 5 columns defined */
227 hr
= IShellFolder2_GetDetailsOf(folder
, NULL
, 6, &details
);
228 ok(hr
== E_NOTIMPL
, "got 0x%08lx\n", hr
);
230 hr
= IShellFolder2_GetDefaultColumnState(folder
, 6, &state
);
231 ok(broken(hr
== E_NOTIMPL
) || hr
== E_INVALIDARG
/* Win7 */, "got 0x%08lx\n", hr
);
233 details
.str
.pOleStr
= NULL
;
234 hr
= IShellFolder2_GetDetailsOf(folder
, NULL
, 0, &details
);
235 ok(hr
== S_OK
|| broken(hr
== E_NOTIMPL
) /* W2K */, "got 0x%08lx\n", hr
);
236 if (SHELL_OsIsUnicode()) SHFree(details
.str
.pOleStr
);
238 /* test every column if method is implemented */
241 ok(details
.str
.uType
== STRRET_WSTR
, "got %d\n", details
.str
.uType
);
243 for(i
= 0; i
< 6; i
++)
245 hr
= IShellFolder2_GetDetailsOf(folder
, NULL
, i
, &details
);
246 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
248 /* all columns are left-aligned */
249 ok(details
.fmt
== LVCFMT_LEFT
, "got 0x%x\n", details
.fmt
);
250 /* can't be on w9x at this point, IShellFolder2 unsupported there,
251 check present for running Wine with w9x setup */
252 if (SHELL_OsIsUnicode()) SHFree(details
.str
.pOleStr
);
254 hr
= IShellFolder2_GetDefaultColumnState(folder
, i
, &state
);
255 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
256 /* all columns are string except document count */
258 ok(state
== (SHCOLSTATE_TYPE_INT
| SHCOLSTATE_ONBYDEFAULT
), "got 0x%lx\n", state
);
260 ok(state
== (SHCOLSTATE_TYPE_STR
| SHCOLSTATE_ONBYDEFAULT
), "got 0x%lx\n", state
);
265 hr
= IShellFolder2_QueryInterface(folder
, &IID_IPersistFolder2
, (void**)&pf
);
266 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
268 /* not initialized */
269 pidl1
= (void*)0xdeadbeef;
270 hr
= IPersistFolder2_GetCurFolder(pf
, &pidl1
);
271 ok(hr
== S_FALSE
, "got 0x%08lx\n", hr
);
272 ok(pidl1
== NULL
, "got %p\n", pidl1
);
274 hr
= SHGetSpecialFolderLocation(NULL
, CSIDL_PRINTERS
, &pidl2
);
275 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
277 hr
= IPersistFolder2_Initialize(pf
, pidl2
);
278 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
280 hr
= IPersistFolder2_GetCurFolder(pf
, &pidl1
);
281 ok(hr
== S_OK
, "got 0x%08lx\n", hr
);
283 ok(ILIsEqual(pidl1
, pidl2
), "expected same PIDL\n");
284 IPersistFolder2_Release(pf
);
288 IShellFolder2_Release(folder
);
293 static void test_desktop_folder(void)
298 hr
= SHGetDesktopFolder(&psf
);
299 ok(hr
== S_OK
, "Got %lx\n", hr
);
301 hr
= IShellFolder_QueryInterface(psf
, &IID_IShellFolder
, NULL
);
302 ok(hr
== E_POINTER
, "Got %lx\n", hr
);
304 IShellFolder_Release(psf
);
307 static void test_desktop_displaynameof(void)
309 static WCHAR MyComputer
[] = { ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 };
310 static WCHAR MyDocuments
[] = { ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}', 0 };
311 static WCHAR RecycleBin
[] = { ':',':','{','6','4','5','F','F','0','4','0','-','5','0','8','1','-','1','0','1','B','-','9','F','0','8','-','0','0','A','A','0','0','2','F','9','5','4','E','}', 0 };
312 static WCHAR ControlPanel
[]= { ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}','\\',
313 ':',':','{','2','1','E','C','2','0','2','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','D','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 };
314 static WCHAR
*folders
[] = { MyComputer
, MyDocuments
, RecycleBin
, ControlPanel
};
315 IShellFolder
*desktop
;
322 hr
= SHGetDesktopFolder(&desktop
);
323 ok(hr
== S_OK
, "SHGetDesktopFolder failed with error 0x%08lx\n", hr
);
324 if (FAILED(hr
)) return;
326 for (i
= 0; i
< ARRAY_SIZE(folders
); i
++)
328 WCHAR name1
[MAX_PATH
], name2
[MAX_PATH
];
330 hr
= IShellFolder_ParseDisplayName(desktop
, NULL
, NULL
, folders
[i
], &eaten
, &pidl
, NULL
);
331 ok(hr
== S_OK
, "IShellFolder::ParseDisplayName failed with error 0x%08lx\n", hr
);
332 if (FAILED(hr
)) continue;
334 hr
= IShellFolder_GetDisplayNameOf(desktop
, pidl
, SHGDN_INFOLDER
, &strret
);
335 ok(hr
== S_OK
, "IShellFolder::GetDisplayNameOf failed with error 0x%08lx\n", hr
);
336 hr
= StrRetToBufW(&strret
, pidl
, name1
, ARRAY_SIZE(name1
));
337 ok(hr
== S_OK
, "StrRetToBuf failed with error 0x%08lx\n", hr
);
339 hr
= IShellFolder_GetDisplayNameOf(desktop
, pidl
, SHGDN_INFOLDER
| SHGDN_FORPARSING
| SHGDN_FORADDRESSBAR
, &strret
);
340 ok(hr
== S_OK
, "IShellFolder::GetDisplayNameOf failed with error 0x%08lx\n", hr
);
341 hr
= StrRetToBufW(&strret
, pidl
, name2
, ARRAY_SIZE(name2
));
342 ok(hr
== S_OK
, "StrRetToBuf failed with error 0x%08lx\n", hr
);
344 ok(!lstrcmpW(name1
, name2
), "the display names are not equal: %s vs %s\n", wine_dbgstr_w(name1
), wine_dbgstr_w(name2
));
345 ok(name1
[0] != ':' || name1
[1] != ':', "display name is a GUID: %s\n", wine_dbgstr_w(name1
));
347 hr
= IShellFolder_GetDisplayNameOf(desktop
, pidl
, SHGDN_INFOLDER
| SHGDN_FORPARSING
, &strret
);
348 ok(hr
== S_OK
, "IShellFolder::GetDisplayNameOf failed with error 0x%08lx\n", hr
);
349 hr
= StrRetToBufW(&strret
, pidl
, name1
, ARRAY_SIZE(name1
));
350 ok(hr
== S_OK
, "StrRetToBuf failed with error 0x%08lx\n", hr
);
352 ok(lstrcmpW(name1
, name2
), "the display names are equal: %s\n", wine_dbgstr_w(name1
));
353 ok(name1
[0] == ':' && name1
[1] == ':', "display name is not a GUID: %s\n", wine_dbgstr_w(name1
));
357 IShellFolder_Release(desktop
);
360 START_TEST(shfldr_special
)
362 test_parse_for_my_computer();
363 test_parse_for_entire_network();
364 test_parse_for_control_panel();
365 test_printers_folder();
366 test_desktop_folder();
367 test_desktop_displaynameof();