6d6122090d6720ca1c15d4fee8e8fa4609c332fa
[reactos.git] / rostests / winetests / shell32 / shfldr_special.c
1 /*
2 * Tests for special shell folders
3 *
4 * Copyright 2008 Robert Shearman for CodeWeavers
5 * Copyright 2008 Owen Rudge
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24
25 #define COBJMACROS
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28
29 #define WIN32_LEAN_AND_MEAN
30 #include <windows.h>
31 #include "shellapi.h"
32 #include "shlobj.h"
33
34 #include "wine/test.h"
35
36 static inline BOOL SHELL_OsIsUnicode(void)
37 {
38 return !(GetVersion() & 0x80000000);
39 }
40
41 /* Tests for My Network Places */
42 static void test_parse_for_entire_network(void)
43 {
44 static WCHAR my_network_places_path[] = {
45 ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-',
46 '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D','}', 0 };
47 static WCHAR entire_network_path[] = {
48 ':',':','{','2','0','8','D','2','C','6','0','-','3','A','E','A','-',
49 '1','0','6','9','-','A','2','D','7','-','0','8','0','0','2','B','3','0','3','0','9','D',
50 '}','\\','E','n','t','i','r','e','N','e','t','w','o','r','k',0 };
51 IShellFolder *psfDesktop;
52 HRESULT hr;
53 DWORD eaten = 0xdeadbeef;
54 LPITEMIDLIST pidl;
55 DWORD attr = ~0;
56 DWORD expected_attr;
57
58 hr = SHGetDesktopFolder(&psfDesktop);
59 ok(hr == S_OK, "SHGetDesktopFolder failed with error 0x%x\n", hr);
60
61 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, my_network_places_path, &eaten, &pidl, &attr);
62 ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr);
63 todo_wine
64 ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten);
65 expected_attr = SFGAO_HASSUBFOLDER|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET|SFGAO_CANRENAME|SFGAO_CANLINK;
66 todo_wine
67 ok((attr == expected_attr) || /* Win9x, NT4 */
68 (attr == (expected_attr | SFGAO_STREAM)) || /* W2K */
69 (attr == (expected_attr | SFGAO_CANDELETE)) || /* XP, W2K3 */
70 (attr == (expected_attr | SFGAO_CANDELETE | SFGAO_NONENUMERATED)), /* Vista */
71 "Unexpected attributes : %08x\n", attr);
72
73 ILFree(pidl);
74
75 /* Start clean again */
76 eaten = 0xdeadbeef;
77 attr = ~0;
78
79 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, entire_network_path, &eaten, &pidl, &attr);
80 IShellFolder_Release(psfDesktop);
81 if (hr == HRESULT_FROM_WIN32(ERROR_BAD_NET_NAME) ||
82 hr == HRESULT_FROM_WIN32(ERROR_NO_NET_OR_BAD_PATH) ||
83 hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER))
84 {
85 win_skip("'EntireNetwork' is not available on Win9x, NT4 and Vista\n");
86 return;
87 }
88 ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr);
89 todo_wine
90 ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten);
91 expected_attr = SFGAO_HASSUBFOLDER|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR|SFGAO_HASPROPSHEET|SFGAO_CANLINK;
92 todo_wine
93 ok(attr == expected_attr || /* winme, nt4 */
94 attr == (expected_attr | SFGAO_STREAM) || /* win2k */
95 attr == (expected_attr | SFGAO_STORAGEANCESTOR), /* others */
96 "attr should be 0x%x, not 0x%x\n", expected_attr, attr);
97
98 ILFree(pidl);
99 }
100
101 /* Tests for Control Panel */
102 static void test_parse_for_control_panel(void)
103 {
104 /* path of My Computer\Control Panel */
105 static WCHAR control_panel_path[] = {
106 ':',':','{','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','}','\\',
107 ':',':','{','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 };
108 IShellFolder *psfDesktop;
109 HRESULT hr;
110 DWORD eaten = 0xdeadbeef;
111 LPITEMIDLIST pidl;
112 DWORD attr = ~0;
113
114 hr = SHGetDesktopFolder(&psfDesktop);
115 ok(hr == S_OK, "SHGetDesktopFolder failed with error 0x%x\n", hr);
116
117 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, control_panel_path, &eaten, &pidl, &attr);
118 ok(hr == S_OK, "IShellFolder_ParseDisplayName failed with error 0x%x\n", hr);
119 todo_wine ok(eaten == 0xdeadbeef, "eaten should not have been set to %u\n", eaten);
120 todo_wine
121 ok((attr == (SFGAO_CANLINK | SFGAO_FOLDER)) || /* Win9x, NT4 */
122 (attr == (SFGAO_CANLINK | SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_STREAM)) || /* W2K */
123 (attr == (SFGAO_CANLINK | SFGAO_FOLDER | SFGAO_HASSUBFOLDER)) || /* W2K, XP, W2K3 */
124 (attr == (SFGAO_CANLINK | SFGAO_NONENUMERATED)) || /* Vista */
125 (attr == SFGAO_CANLINK), /* Vista, W2K8 */
126 "Unexpected attributes : %08x\n", attr);
127
128 ILFree(pidl);
129 IShellFolder_Release(psfDesktop);
130 }
131
132 static void test_printers_folder(void)
133 {
134 IShellFolder2 *folder;
135 IPersistFolder2 *pf;
136 SHELLDETAILS details;
137 SHCOLSTATEF state;
138 LPITEMIDLIST pidl1, pidl2;
139 HRESULT hr;
140 INT i;
141
142 CoInitialize( NULL );
143
144 hr = CoCreateInstance(&CLSID_Printers, NULL, CLSCTX_INPROC_SERVER, &IID_IShellFolder2, (void**)&folder);
145 if (hr != S_OK)
146 {
147 win_skip("Failed to created IShellFolder2 for Printers folder\n");
148 CoUninitialize();
149 return;
150 }
151
152 if (0)
153 {
154 /* crashes on XP */
155 IShellFolder2_GetDetailsOf(folder, NULL, 0, NULL);
156 IShellFolder2_GetDefaultColumnState(folder, 0, NULL);
157 IPersistFolder2_GetCurFolder(pf, NULL);
158 }
159
160 /* 5 columns defined */
161 hr = IShellFolder2_GetDetailsOf(folder, NULL, 6, &details);
162 ok(hr == E_NOTIMPL, "got 0x%08x\n", hr);
163
164 hr = IShellFolder2_GetDefaultColumnState(folder, 6, &state);
165 ok(broken(hr == E_NOTIMPL) || hr == E_INVALIDARG /* Win7 */, "got 0x%08x\n", hr);
166
167 details.str.u.pOleStr = NULL;
168 hr = IShellFolder2_GetDetailsOf(folder, NULL, 0, &details);
169 ok(hr == S_OK || broken(E_NOTIMPL) /* W2K */, "got 0x%08x\n", hr);
170 if (SHELL_OsIsUnicode()) SHFree(details.str.u.pOleStr);
171
172 /* test every column if method is implemented */
173 if (hr == S_OK)
174 {
175 ok(details.str.uType == STRRET_WSTR, "got %d\n", details.str.uType);
176
177 for(i = 0; i < 6; i++)
178 {
179 hr = IShellFolder2_GetDetailsOf(folder, NULL, i, &details);
180 ok(hr == S_OK, "got 0x%08x\n", hr);
181
182 /* all columns are left-aligned */
183 ok(details.fmt == LVCFMT_LEFT, "got 0x%x\n", details.fmt);
184 /* can't be on w9x at this point, IShellFolder2 unsupported there,
185 check present for running Wine with w9x setup */
186 if (SHELL_OsIsUnicode()) SHFree(details.str.u.pOleStr);
187
188 hr = IShellFolder2_GetDefaultColumnState(folder, i, &state);
189 ok(hr == S_OK, "got 0x%08x\n", hr);
190 /* all columns are string except document count */
191 if (i == 1)
192 ok(state == (SHCOLSTATE_TYPE_INT | SHCOLSTATE_ONBYDEFAULT), "got 0x%x\n", state);
193 else
194 ok(state == (SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT), "got 0x%x\n", state);
195 }
196 }
197
198 /* default pidl */
199 hr = IShellFolder2_QueryInterface(folder, &IID_IPersistFolder2, (void**)&pf);
200 ok(hr == S_OK, "got 0x%08x\n", hr);
201
202 /* not initialized */
203 pidl1 = (void*)0xdeadbeef;
204 hr = IPersistFolder2_GetCurFolder(pf, &pidl1);
205 ok(hr == S_FALSE, "got 0x%08x\n", hr);
206 ok(pidl1 == NULL, "got %p\n", pidl1);
207
208 hr = SHGetSpecialFolderLocation(NULL, CSIDL_PRINTERS, &pidl2);
209 ok(hr == S_OK, "got 0x%08x\n", hr);
210
211 hr = IPersistFolder2_Initialize(pf, pidl2);
212 ok(hr == S_OK, "got 0x%08x\n", hr);
213
214 hr = IPersistFolder2_GetCurFolder(pf, &pidl1);
215 ok(hr == S_OK, "got 0x%08x\n", hr);
216
217 ok(ILIsEqual(pidl1, pidl2), "expected same PIDL\n");
218 IPersistFolder2_Release(pf);
219
220 ILFree(pidl1);
221 ILFree(pidl2);
222 IShellFolder2_Release(folder);
223
224 CoUninitialize();
225 }
226
227 static void test_desktop_folder(void)
228 {
229 IShellFolder *psf;
230 HRESULT hr;
231
232 hr = SHGetDesktopFolder(&psf);
233 ok(hr == S_OK, "Got %x\n", hr);
234
235 hr = IShellFolder_QueryInterface(psf, &IID_IShellFolder, NULL);
236 ok(hr == E_POINTER, "Got %x\n", hr);
237
238 IShellFolder_Release(psf);
239 }
240
241 START_TEST(shfldr_special)
242 {
243 test_parse_for_entire_network();
244 test_parse_for_control_panel();
245 test_printers_folder();
246 test_desktop_folder();
247 }