[SHLWAPI_WINETEST] Add tests for AssocGetPerceivedType. By Mark Jansen. CORE-9754
[reactos.git] / rostests / winetests / shlwapi / assoc.c
1 /* Unit test suite for SHLWAPI IQueryAssociations functions
2 *
3 * Copyright 2008 Google (Lei Zhang)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #define WIN32_NO_STATUS
21 #define _INC_WINDOWS
22 #define COM_NO_WINDOWS_H
23
24 //#include <stdarg.h>
25
26 #include <wine/test.h>
27 #include <winreg.h>
28 #include <shlwapi.h>
29 #include <shlguid.h>
30
31 #define expect(expected, got) ok( (expected) == (got), "Expected %d, got %d\n", (expected), (got))
32 #define expect_hr(expected, got) ok( (expected) == (got), "Expected %08x, got %08x\n", (expected), (got))
33
34 static HRESULT (WINAPI *pAssocQueryStringA)(ASSOCF,ASSOCSTR,LPCSTR,LPCSTR,LPSTR,LPDWORD) = NULL;
35 static HRESULT (WINAPI *pAssocQueryStringW)(ASSOCF,ASSOCSTR,LPCWSTR,LPCWSTR,LPWSTR,LPDWORD) = NULL;
36 static HRESULT (WINAPI *pAssocCreate)(CLSID, REFIID, void **) = NULL;
37 static HRESULT (WINAPI *pAssocGetPerceivedType)(LPCWSTR, PERCEIVED *, INT *, LPWSTR *) = NULL;
38
39 /* Every version of Windows with IE should have this association? */
40 static const WCHAR dotHtml[] = { '.','h','t','m','l',0 };
41 static const WCHAR badBad[] = { 'b','a','d','b','a','d',0 };
42 static const WCHAR dotBad[] = { '.','b','a','d',0 };
43 static const WCHAR open[] = { 'o','p','e','n',0 };
44 static const WCHAR invalid[] = { 'i','n','v','a','l','i','d',0 };
45
46 static void test_getstring_bad(void)
47 {
48 static const WCHAR openwith[] = {'O','p','e','n','W','i','t','h','.','e','x','e',0};
49 WCHAR buf[MAX_PATH];
50 HRESULT hr;
51 DWORD len;
52
53 if (!pAssocQueryStringW)
54 {
55 win_skip("AssocQueryStringW() is missing\n");
56 return;
57 }
58
59 len = 0xdeadbeef;
60 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, NULL, open, NULL, &len);
61 expect_hr(E_INVALIDARG, hr);
62 ok(len == 0xdeadbeef, "got %u\n", len);
63
64 len = 0xdeadbeef;
65 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, badBad, open, NULL, &len);
66 ok(hr == E_FAIL ||
67 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
68 "Unexpected result : %08x\n", hr);
69 ok(len == 0xdeadbeef, "got %u\n", len);
70
71 len = sizeof(buf)/sizeof(buf[0]);
72 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotBad, open, buf, &len);
73 ok(hr == E_FAIL ||
74 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */ ||
75 hr == S_OK /* Win8 */,
76 "Unexpected result : %08x\n", hr);
77 if (hr == S_OK)
78 {
79 ok(len < sizeof(buf)/sizeof(buf[0]), "got %u\n", len);
80 ok(!lstrcmpiW(buf + len - sizeof(openwith)/sizeof(openwith[0]), openwith), "wrong data\n");
81 }
82
83 len = 0xdeadbeef;
84 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, invalid, NULL, &len);
85 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
86 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
87 "Unexpected result : %08x\n", hr);
88 ok(len == 0xdeadbeef, "got %u\n", len);
89
90 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, NULL);
91 ok(hr == E_UNEXPECTED ||
92 hr == E_INVALIDARG, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
93 "Unexpected result : %08x\n", hr);
94
95 len = 0xdeadbeef;
96 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, NULL, open, NULL, &len);
97 expect_hr(E_INVALIDARG, hr);
98 ok(len == 0xdeadbeef, "got %u\n", len);
99
100 len = 0xdeadbeef;
101 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, badBad, open, NULL, &len);
102 ok(hr == E_FAIL ||
103 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
104 "Unexpected result : %08x\n", hr);
105 ok(len == 0xdeadbeef, "got %u\n", len);
106
107 len = 0xdeadbeef;
108 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotBad, open, NULL, &len);
109 ok(hr == E_FAIL ||
110 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */ ||
111 hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), /* Win8 */
112 "Unexpected result : %08x\n", hr);
113 ok(len == 0xdeadbeef, "got %u\n", len);
114
115 len = 0xdeadbeef;
116 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, invalid, NULL, &len);
117 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
118 hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION) || /* W2K/Vista/W2K8 */
119 hr == E_FAIL, /* Win9x/WinMe/NT4 */
120 "Unexpected result : %08x\n", hr);
121 ok(len == 0xdeadbeef, "got %u\n", len);
122
123 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL, NULL);
124 ok(hr == E_UNEXPECTED ||
125 hr == E_INVALIDARG, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
126 "Unexpected result : %08x\n", hr);
127 }
128
129 static void test_getstring_basic(void)
130 {
131 HRESULT hr;
132 WCHAR * friendlyName;
133 WCHAR * executableName;
134 DWORD len, len2, slen;
135
136 if (!pAssocQueryStringW)
137 {
138 win_skip("AssocQueryStringW() is missing\n");
139 return;
140 }
141
142 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open, NULL, &len);
143 expect_hr(S_FALSE, hr);
144 if (hr != S_FALSE)
145 {
146 skip("failed to get initial len\n");
147 return;
148 }
149
150 executableName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
151 len * sizeof(WCHAR));
152 if (!executableName)
153 {
154 skip("failed to allocate memory\n");
155 return;
156 }
157
158 len2 = len;
159 hr = pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE, dotHtml, open,
160 executableName, &len2);
161 expect_hr(S_OK, hr);
162 slen = lstrlenW(executableName) + 1;
163 expect(len, len2);
164 expect(len, slen);
165
166 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open, NULL,
167 &len);
168 ok(hr == S_FALSE ||
169 hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* Win9x/NT4 */ ||
170 hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), /* Win8 */
171 "Unexpected result : %08x\n", hr);
172 if (hr != S_FALSE)
173 {
174 HeapFree(GetProcessHeap(), 0, executableName);
175 skip("failed to get initial len\n");
176 return;
177 }
178
179 friendlyName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
180 len * sizeof(WCHAR));
181 if (!friendlyName)
182 {
183 HeapFree(GetProcessHeap(), 0, executableName);
184 skip("failed to allocate memory\n");
185 return;
186 }
187
188 len2 = len;
189 hr = pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME, dotHtml, open,
190 friendlyName, &len2);
191 expect_hr(S_OK, hr);
192 slen = lstrlenW(friendlyName) + 1;
193 expect(len, len2);
194 expect(len, slen);
195
196 HeapFree(GetProcessHeap(), 0, executableName);
197 HeapFree(GetProcessHeap(), 0, friendlyName);
198 }
199
200 static void test_getstring_no_extra(void)
201 {
202 LONG ret;
203 HKEY hkey;
204 HRESULT hr;
205 static const CHAR dotWinetest[] = {
206 '.','w','i','n','e','t','e','s','t',0
207 };
208 static const CHAR winetestfile[] = {
209 'w','i','n','e','t','e','s','t', 'f','i','l','e',0
210 };
211 static const CHAR winetestfileAction[] = {
212 'w','i','n','e','t','e','s','t','f','i','l','e',
213 '\\','s','h','e','l','l',
214 '\\','f','o','o',
215 '\\','c','o','m','m','a','n','d',0
216 };
217 static const CHAR action[] = {
218 'n','o','t','e','p','a','d','.','e','x','e',0
219 };
220 CHAR buf[MAX_PATH];
221 DWORD len = MAX_PATH;
222
223 if (!pAssocQueryStringA)
224 {
225 win_skip("AssocQueryStringA() is missing\n");
226 return;
227 }
228
229 buf[0] = '\0';
230 ret = RegCreateKeyA(HKEY_CLASSES_ROOT, dotWinetest, &hkey);
231 if (ret != ERROR_SUCCESS) {
232 skip("failed to create dotWinetest key\n");
233 return;
234 }
235
236 ret = RegSetValueA(hkey, NULL, REG_SZ, winetestfile, lstrlenA(winetestfile));
237 RegCloseKey(hkey);
238 if (ret != ERROR_SUCCESS)
239 {
240 skip("failed to set dotWinetest key\n");
241 goto cleanup;
242 }
243
244 ret = RegCreateKeyA(HKEY_CLASSES_ROOT, winetestfileAction, &hkey);
245 if (ret != ERROR_SUCCESS)
246 {
247 skip("failed to create winetestfileAction key\n");
248 goto cleanup;
249 }
250
251 ret = RegSetValueA(hkey, NULL, REG_SZ, action, lstrlenA(action));
252 RegCloseKey(hkey);
253 if (ret != ERROR_SUCCESS)
254 {
255 skip("failed to set winetestfileAction key\n");
256 goto cleanup;
257 }
258
259 hr = pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE, dotWinetest, NULL, buf, &len);
260 ok(hr == S_OK ||
261 hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), /* XP and W2K3 */
262 "Unexpected result : %08x\n", hr);
263 hr = pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE, dotWinetest, "foo", buf, &len);
264 expect_hr(S_OK, hr);
265 ok(strstr(buf, action) != NULL,
266 "got '%s' (Expected result to include 'notepad.exe')\n", buf);
267
268 cleanup:
269 SHDeleteKeyA(HKEY_CLASSES_ROOT, dotWinetest);
270 SHDeleteKeyA(HKEY_CLASSES_ROOT, winetestfile);
271
272 }
273
274 static void test_assoc_create(void)
275 {
276 HRESULT hr;
277 IQueryAssociations *pqa;
278
279 if (!pAssocCreate)
280 {
281 win_skip("AssocCreate() is missing\n");
282 return;
283 }
284
285 hr = pAssocCreate(IID_NULL, &IID_NULL, NULL);
286 ok(hr == E_INVALIDARG, "Unexpected result : %08x\n", hr);
287
288 hr = pAssocCreate(CLSID_QueryAssociations, &IID_NULL, (LPVOID*)&pqa);
289 ok(hr == CLASS_E_CLASSNOTAVAILABLE || hr == E_NOTIMPL || hr == E_NOINTERFACE
290 , "Unexpected result : %08x\n", hr);
291
292 hr = pAssocCreate(IID_NULL, &IID_IQueryAssociations, (LPVOID*)&pqa);
293 ok(hr == CLASS_E_CLASSNOTAVAILABLE || hr == E_NOTIMPL || hr == E_INVALIDARG
294 , "Unexpected result : %08x\n", hr);
295
296 hr = pAssocCreate(CLSID_QueryAssociations, &IID_IQueryAssociations, (LPVOID*)&pqa);
297 ok(hr == S_OK || hr == E_NOTIMPL /* win98 */
298 , "Unexpected result : %08x\n", hr);
299 if(hr == S_OK)
300 {
301 IQueryAssociations_Release(pqa);
302 }
303
304 hr = pAssocCreate(CLSID_QueryAssociations, &IID_IUnknown, (LPVOID*)&pqa);
305 ok(hr == S_OK || hr == E_NOTIMPL /* win98 */
306 , "Unexpected result : %08x\n", hr);
307 if(hr == S_OK)
308 {
309 IQueryAssociations_Release(pqa);
310 }
311 }
312
313 /* Based on http://www.geoffchappell.com/studies/windows/shell/shlwapi/api/assocapi/getperceivedtype.htm */
314 struct assoc_test_struct
315 {
316 PCSTR extension;
317 PERCEIVED perceived;
318 INT flags;
319 PCSTR type;
320 DWORD minversion;
321 HRESULT hr;
322 };
323
324 #define HARDCODED_NATIVE_WMSDK (PERCEIVEDFLAG_HARDCODED | PERCEIVEDFLAG_NATIVESUPPORT | PERCEIVEDFLAG_WMSDK)
325 #define HARDCODED_NATIVE_GDIPLUS (PERCEIVEDFLAG_HARDCODED | PERCEIVEDFLAG_NATIVESUPPORT | PERCEIVEDFLAG_GDIPLUS)
326 #define HARDCODED_NATIVE_ZIPFLDR (PERCEIVEDFLAG_HARDCODED | PERCEIVEDFLAG_NATIVESUPPORT | PERCEIVEDFLAG_ZIPFOLDER)
327 #define SOFTCODED_NATIVESUPPORT (PERCEIVEDFLAG_SOFTCODED | PERCEIVEDFLAG_NATIVESUPPORT)
328
329 static const struct assoc_test_struct assoc_perceived_types[] =
330 {
331 /* builtins */
332 { ".aif", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
333 { ".aifc", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
334 { ".aiff", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
335 { ".asf", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
336 { ".asx", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
337 { ".au", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
338 { ".avi", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
339 { ".bas", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
340 { ".bat", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
341 { ".bmp", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
342 { ".cmd", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
343 { ".com", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
344 { ".cpl", PERCEIVED_TYPE_SYSTEM, PERCEIVEDFLAG_HARDCODED, "system", 0x600 },
345 { ".dib", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
346 { ".dvr-ms", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
347 { ".emf", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
348 { ".exe", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
349 { ".gif", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
350 { ".hta", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
351 /* htm & html are PERCEIVED_TYPE_TEXT, PERCEIVEDFLAG_NATIVESUPPORT | PERCEIVEDFLAG_SOFTCODED in w2k3 */
352 { ".htm", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_HARDCODED, "document", 0x600 },
353 { ".html", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_HARDCODED, "document", 0x600 },
354 { ".ico", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
355 { ".IVF", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
356 { ".jfif", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
357 { ".jpe", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
358 { ".jpeg", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
359 { ".jpg", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
360 { ".lnk", PERCEIVED_TYPE_UNSPECIFIED, PERCEIVEDFLAG_HARDCODED, NULL, 0x600, E_FAIL },
361 { ".m1v", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
362 { ".m3u", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
363 { ".mht", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_HARDCODED, "document", 0x600 },
364 { ".mid", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
365 { ".midi", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
366 { ".msi", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
367 /* below win8 this is defined to be video */
368 { ".mp2", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio", 0x602 },
369 { ".mp2v", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
370 { ".mp3", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
371 { ".mpa", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
372 { ".mpe", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
373 { ".mpeg", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
374 { ".mpg", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
375 { ".mpv2", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
376 { ".pif", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
377 { ".png", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
378 { ".reg", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
379 { ".rle", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
380 { ".rmi", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
381 { ".scr", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
382 { ".search-ms", PERCEIVED_TYPE_UNSPECIFIED, PERCEIVEDFLAG_HARDCODED, NULL, 0x600, E_FAIL },
383 { ".snd", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
384 { ".tif", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
385 { ".tiff", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
386 { ".vb", PERCEIVED_TYPE_APPLICATION, PERCEIVEDFLAG_HARDCODED, "application" },
387 { ".wav", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
388 { ".wax", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
389 { ".wm", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
390 { ".wma", PERCEIVED_TYPE_AUDIO, HARDCODED_NATIVE_WMSDK, "audio" },
391 { ".wmf", PERCEIVED_TYPE_IMAGE, HARDCODED_NATIVE_GDIPLUS, "image" },
392 { ".wmv", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
393 { ".wmx", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
394 { ".wvx", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" },
395 { ".zip", PERCEIVED_TYPE_COMPRESSED, HARDCODED_NATIVE_ZIPFLDR, "compressed" },
396 /* found in the registry under HKEY_CLASSES_ROOT on a new Win7 VM */
397 { ".386", PERCEIVED_TYPE_SYSTEM, PERCEIVEDFLAG_SOFTCODED, "system" },
398 { ".3g2", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
399 { ".3gp", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
400 { ".3gp2", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
401 { ".3gpp", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
402 { ".AAC", PERCEIVED_TYPE_AUDIO, PERCEIVEDFLAG_SOFTCODED, "audio", 0x601 },
403 { ".ADT", PERCEIVED_TYPE_AUDIO, PERCEIVEDFLAG_SOFTCODED, "audio", 0x601 },
404 { ".ADTS", PERCEIVED_TYPE_AUDIO, PERCEIVEDFLAG_SOFTCODED, "audio", 0x601 },
405 { ".asm", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
406 { ".asmx", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
407 { ".aspx", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
408 { ".c", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
409 { ".cab", PERCEIVED_TYPE_COMPRESSED, PERCEIVEDFLAG_SOFTCODED, "compressed", 0x600 },
410 { ".chk", PERCEIVED_TYPE_SYSTEM, PERCEIVEDFLAG_SOFTCODED, "system" },
411 { ".cpp", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
412 { ".css", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
413 { ".cxx", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
414 { ".def", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
415 { ".diz", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
416 { ".docx", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x601 },
417 { ".drv", PERCEIVED_TYPE_SYSTEM, PERCEIVEDFLAG_SOFTCODED, "system", 0x600 },
418 { ".gz", PERCEIVED_TYPE_COMPRESSED, PERCEIVEDFLAG_SOFTCODED, "compressed" },
419 { ".h", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
420 { ".hpp", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
421 { ".hxx", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
422 { ".inc", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
423 { ".ini", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text", 0x600 },
424 { ".java", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
425 { ".local", PERCEIVED_TYPE_SYSTEM, PERCEIVEDFLAG_SOFTCODED, "system" },
426 { ".M2T", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
427 { ".M2TS", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
428 { ".M2V", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
429 { ".m4a", PERCEIVED_TYPE_AUDIO, PERCEIVEDFLAG_SOFTCODED, "audio", 0x601 },
430 { ".m4b", PERCEIVED_TYPE_AUDIO, PERCEIVEDFLAG_SOFTCODED, "audio", 0x601 },
431 { ".m4p", PERCEIVED_TYPE_AUDIO, PERCEIVEDFLAG_SOFTCODED, "audio", 0x601 },
432 { ".m4v", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
433 { ".manifest", PERCEIVED_TYPE_SYSTEM, PERCEIVEDFLAG_SOFTCODED, "system" },
434 { ".MOD", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
435 { ".mov", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
436 { ".mp4", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
437 { ".mp4v", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
438 { ".MTS", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
439 { ".nvr", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
440 { ".ocx", PERCEIVED_TYPE_SYSTEM, PERCEIVEDFLAG_SOFTCODED, "system" },
441 { ".odt", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x601 },
442 { ".php3", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
443 { ".pl", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
444 { ".plg", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
445 { ".ps1xml", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "Text" },
446 { ".rtf", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
447 { ".sed", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
448 { ".shtml", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
449 { ".sql", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
450 { ".sys", PERCEIVED_TYPE_SYSTEM, PERCEIVEDFLAG_SOFTCODED, "system", 0x600 },
451 { ".tar", PERCEIVED_TYPE_COMPRESSED, PERCEIVEDFLAG_SOFTCODED, "compressed" },
452 { ".text", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
453 { ".tgz", PERCEIVED_TYPE_COMPRESSED, PERCEIVEDFLAG_SOFTCODED, "compressed" },
454 { ".TS", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
455 { ".tsv", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
456 { ".TTS", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
457 { ".txt", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
458 { ".vob", PERCEIVED_TYPE_VIDEO, PERCEIVEDFLAG_SOFTCODED, "video", 0x601 },
459 { ".vxd", PERCEIVED_TYPE_SYSTEM, PERCEIVEDFLAG_SOFTCODED, "system" },
460 { ".wdp", PERCEIVED_TYPE_IMAGE, PERCEIVEDFLAG_SOFTCODED, "image" },
461 { ".wmz", PERCEIVED_TYPE_COMPRESSED, PERCEIVEDFLAG_SOFTCODED, "compressed" },
462 { ".wpl", PERCEIVED_TYPE_AUDIO, PERCEIVEDFLAG_SOFTCODED, "audio", 0x601 },
463 { ".wsz", PERCEIVED_TYPE_COMPRESSED, PERCEIVEDFLAG_SOFTCODED, "compressed" },
464 { ".x", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text" },
465 { ".xml", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text", 0x601 },
466 { ".xsl", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text", 0x601 },
467 { ".z", PERCEIVED_TYPE_COMPRESSED, PERCEIVEDFLAG_SOFTCODED, "compressed" },
468 /* found in the registry under HKEY_CLASSES_ROOT\PerceivedType */
469 { ".doc", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
470 { ".dot", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
471 { ".mhtml", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
472 { ".pot", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
473 { ".ppt", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
474 { ".rtf", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
475 { ".wri", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
476 { ".xls", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
477 { ".xlt", PERCEIVED_TYPE_DOCUMENT, PERCEIVEDFLAG_SOFTCODED, "document", 0x600 },
478
479 };
480
481 static void test_assoc_one(const struct assoc_test_struct* test)
482 {
483 LPWSTR extension, type_expected, type_returned;
484 PERCEIVED perceived;
485 HRESULT hr;
486 INT flags;
487
488 /* if SHStrDupA receives a nullptr as input, it will null the output */
489 SHStrDupA(test->extension, &extension);
490 SHStrDupA(test->type, &type_expected);
491
492 perceived = 0xdeadbeef;
493 flags = 0xdeadbeef;
494
495 hr = pAssocGetPerceivedType(extension, &perceived, &flags, NULL);
496 expect_hr(type_expected ? S_OK : test->hr, hr);
497 ok(perceived == test->perceived, "%s: got perceived 0x%x, expected 0x%x\n",
498 test->extension, perceived, test->perceived);
499 ok(flags == test->flags, "%s: got flags 0x%x, expected 0x%x\n",
500 test->extension, flags, test->flags);
501
502 type_returned = (void *)0xdeadbeef;
503 perceived = 0xdeadbeef;
504 flags = 0xdeadbeef;
505
506 hr = pAssocGetPerceivedType(extension, &perceived, &flags, &type_returned);
507 expect_hr(type_expected ? S_OK : test->hr, hr);
508 ok(perceived == test->perceived, "%s: got perceived 0x%x, expected 0x%x\n",
509 test->extension, perceived, test->perceived);
510 ok(flags == test->flags, "%s: got flags 0x%x, expected 0x%x\n",
511 test->extension, flags, test->flags);
512
513 if (!type_expected)
514 {
515 ok(type_returned == (void *)0xdeadbeef || broken(type_returned == NULL) /* Win 8 */,
516 "%s: got type %p, expected 0xdeadbeef\n", test->extension, type_returned);
517 }
518 else if (type_returned == (void *)0xdeadbeef)
519 {
520 ok(type_returned != (void *)0xdeadbeef, "%s: got type %p, expected '%s'\n",
521 test->extension, type_returned, test->type);
522 }
523 else
524 {
525 ok(StrCmpIW(type_expected, type_returned) == 0, "%s: got type %s, expected '%s'\n",
526 test->extension, wine_dbgstr_w(type_returned), test->type);
527 }
528
529 CoTaskMemFree(type_returned);
530 CoTaskMemFree(extension);
531 CoTaskMemFree(type_expected);
532 }
533
534 static void test_assoc_perceived(void)
535 {
536 static const struct assoc_test_struct should_not_exist =
537 { ".should_not_exist", PERCEIVED_TYPE_UNSPECIFIED, PERCEIVEDFLAG_UNDEFINED, NULL, 0, 0x80070002 };
538 static const struct assoc_test_struct htm[] =
539 {
540 { ".htm", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text", 0x600 },
541 { ".html", PERCEIVED_TYPE_TEXT, SOFTCODED_NATIVESUPPORT, "text", 0x600 },
542 };
543 static const struct assoc_test_struct mp2 =
544 { ".mp2", PERCEIVED_TYPE_VIDEO, HARDCODED_NATIVE_WMSDK, "video" };
545
546 OSVERSIONINFOEXW osvi;
547 DWORD version;
548 size_t i;
549
550 if (!pAssocGetPerceivedType)
551 {
552 win_skip("AssocGetPerceivedType() is missing\n");
553 return;
554 }
555
556 memset(&osvi, 0, sizeof(osvi));
557 osvi.dwOSVersionInfoSize = sizeof(osvi);
558 GetVersionExW((LPOSVERSIONINFOW)&osvi);
559 version = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
560
561 /* invalid entry results in HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) */
562 test_assoc_one(&should_not_exist);
563
564 for (i = 0; i < sizeof(assoc_perceived_types) / sizeof(assoc_perceived_types[0]); ++i)
565 {
566 if (assoc_perceived_types[i].minversion && assoc_perceived_types[i].minversion > version)
567 continue;
568 if (!(assoc_perceived_types[i].flags & PERCEIVEDFLAG_HARDCODED))
569 todo_wine test_assoc_one(&assoc_perceived_types[i]);
570 else
571 test_assoc_one(&assoc_perceived_types[i]);
572 }
573
574 /* below Vista */
575 if (version < 0x600)
576 {
577 todo_wine
578 test_assoc_one(&htm[0]);
579 todo_wine
580 test_assoc_one(&htm[1]);
581 }
582
583 /* below Win8 */
584 if (version < 0x602)
585 {
586 test_assoc_one(&mp2);
587 }
588 }
589
590 START_TEST(assoc)
591 {
592 HMODULE hshlwapi;
593 hshlwapi = GetModuleHandleA("shlwapi.dll");
594 pAssocQueryStringA = (void*)GetProcAddress(hshlwapi, "AssocQueryStringA");
595 pAssocQueryStringW = (void*)GetProcAddress(hshlwapi, "AssocQueryStringW");
596 pAssocCreate = (void*)GetProcAddress(hshlwapi, "AssocCreate");
597 pAssocGetPerceivedType = (void*)GetProcAddress(hshlwapi, "AssocGetPerceivedType");
598
599 test_getstring_bad();
600 test_getstring_basic();
601 test_getstring_no_extra();
602 test_assoc_create();
603 test_assoc_perceived();
604 }