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