1 /* Unit test suite for SHLWAPI IQueryAssociations functions
3 * Copyright 2008 Google (Lei Zhang)
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.
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.
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
20 #define WIN32_NO_STATUS
22 #define COM_NO_WINDOWS_H
26 #include <wine/test.h>
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)
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
;
38 /* Every version of Windows with IE should have this association? */
39 static const WCHAR dotHtml
[] = { '.','h','t','m','l',0 };
40 static const WCHAR badBad
[] = { 'b','a','d','b','a','d',0 };
41 static const WCHAR dotBad
[] = { '.','b','a','d',0 };
42 static const WCHAR open
[] = { 'o','p','e','n',0 };
43 static const WCHAR invalid
[] = { 'i','n','v','a','l','i','d',0 };
45 static void test_getstring_bad(void)
50 if (!pAssocQueryStringW
)
52 win_skip("AssocQueryStringW() is missing\n");
56 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, NULL
, open
, NULL
, &len
);
57 expect_hr(E_INVALIDARG
, hr
);
58 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, badBad
, open
, NULL
, &len
);
60 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
61 "Unexpected result : %08x\n", hr
);
62 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotBad
, open
, NULL
, &len
);
64 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
65 "Unexpected result : %08x\n", hr
);
66 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotHtml
, invalid
, NULL
,
68 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
69 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
70 "Unexpected result : %08x\n", hr
);
71 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotHtml
, open
, NULL
, NULL
);
72 ok(hr
== E_UNEXPECTED
||
73 hr
== E_INVALIDARG
, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
74 "Unexpected result : %08x\n", hr
);
76 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, NULL
, open
, NULL
, &len
);
77 expect_hr(E_INVALIDARG
, hr
);
78 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, badBad
, open
, NULL
,
81 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
82 "Unexpected result : %08x\n", hr
);
83 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotBad
, open
, NULL
,
86 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
) /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */ ||
87 hr
== HRESULT_FROM_WIN32(ERROR_NOT_FOUND
), /* Win8 */
88 "Unexpected result : %08x\n", hr
);
89 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, invalid
, NULL
,
91 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
92 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
) || /* W2K/Vista/W2K8 */
93 hr
== E_FAIL
, /* Win9x/WinMe/NT4 */
94 "Unexpected result : %08x\n", hr
);
95 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, open
, NULL
,
97 ok(hr
== E_UNEXPECTED
||
98 hr
== E_INVALIDARG
, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
99 "Unexpected result : %08x\n", hr
);
102 static void test_getstring_basic(void)
105 WCHAR
* friendlyName
;
106 WCHAR
* executableName
;
107 DWORD len
, len2
, slen
;
109 if (!pAssocQueryStringW
)
111 win_skip("AssocQueryStringW() is missing\n");
115 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotHtml
, open
, NULL
, &len
);
116 expect_hr(S_FALSE
, hr
);
119 skip("failed to get initial len\n");
123 executableName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
124 len
* sizeof(WCHAR
));
127 skip("failed to allocate memory\n");
132 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotHtml
, open
,
133 executableName
, &len2
);
135 slen
= lstrlenW(executableName
) + 1;
139 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, open
, NULL
,
142 hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) /* Win9x/NT4 */ ||
143 hr
== HRESULT_FROM_WIN32(ERROR_NOT_FOUND
), /* Win8 */
144 "Unexpected result : %08x\n", hr
);
147 HeapFree(GetProcessHeap(), 0, executableName
);
148 skip("failed to get initial len\n");
152 friendlyName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
153 len
* sizeof(WCHAR
));
156 HeapFree(GetProcessHeap(), 0, executableName
);
157 skip("failed to allocate memory\n");
162 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, open
,
163 friendlyName
, &len2
);
165 slen
= lstrlenW(friendlyName
) + 1;
169 HeapFree(GetProcessHeap(), 0, executableName
);
170 HeapFree(GetProcessHeap(), 0, friendlyName
);
173 static void test_getstring_no_extra(void)
178 static const CHAR dotWinetest
[] = {
179 '.','w','i','n','e','t','e','s','t',0
181 static const CHAR winetestfile
[] = {
182 'w','i','n','e','t','e','s','t', 'f','i','l','e',0
184 static const CHAR winetestfileAction
[] = {
185 'w','i','n','e','t','e','s','t','f','i','l','e',
186 '\\','s','h','e','l','l',
188 '\\','c','o','m','m','a','n','d',0
190 static const CHAR action
[] = {
191 'n','o','t','e','p','a','d','.','e','x','e',0
194 DWORD len
= MAX_PATH
;
196 if (!pAssocQueryStringA
)
198 win_skip("AssocQueryStringA() is missing\n");
203 ret
= RegCreateKeyA(HKEY_CLASSES_ROOT
, dotWinetest
, &hkey
);
204 if (ret
!= ERROR_SUCCESS
) {
205 skip("failed to create dotWinetest key\n");
209 ret
= RegSetValueA(hkey
, NULL
, REG_SZ
, winetestfile
, lstrlenA(winetestfile
));
211 if (ret
!= ERROR_SUCCESS
)
213 skip("failed to set dotWinetest key\n");
217 ret
= RegCreateKeyA(HKEY_CLASSES_ROOT
, winetestfileAction
, &hkey
);
218 if (ret
!= ERROR_SUCCESS
)
220 skip("failed to create winetestfileAction key\n");
224 ret
= RegSetValueA(hkey
, NULL
, REG_SZ
, action
, lstrlenA(action
));
226 if (ret
!= ERROR_SUCCESS
)
228 skip("failed to set winetestfileAction key\n");
232 hr
= pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE
, dotWinetest
, NULL
, buf
, &len
);
234 hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), /* XP and W2K3 */
235 "Unexpected result : %08x\n", hr
);
236 hr
= pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE
, dotWinetest
, "foo", buf
, &len
);
238 ok(strstr(buf
, action
) != NULL
,
239 "got '%s' (Expected result to include 'notepad.exe')\n", buf
);
242 SHDeleteKeyA(HKEY_CLASSES_ROOT
, dotWinetest
);
243 SHDeleteKeyA(HKEY_CLASSES_ROOT
, winetestfile
);
247 static void test_assoc_create(void)
250 IQueryAssociations
*pqa
;
254 win_skip("AssocCreate() is missing\n");
258 hr
= pAssocCreate(IID_NULL
, &IID_NULL
, NULL
);
259 ok(hr
== E_INVALIDARG
, "Unexpected result : %08x\n", hr
);
261 hr
= pAssocCreate(CLSID_QueryAssociations
, &IID_NULL
, (LPVOID
*)&pqa
);
262 ok(hr
== CLASS_E_CLASSNOTAVAILABLE
|| hr
== E_NOTIMPL
|| hr
== E_NOINTERFACE
263 , "Unexpected result : %08x\n", hr
);
265 hr
= pAssocCreate(IID_NULL
, &IID_IQueryAssociations
, (LPVOID
*)&pqa
);
266 ok(hr
== CLASS_E_CLASSNOTAVAILABLE
|| hr
== E_NOTIMPL
|| hr
== E_INVALIDARG
267 , "Unexpected result : %08x\n", hr
);
269 hr
= pAssocCreate(CLSID_QueryAssociations
, &IID_IQueryAssociations
, (LPVOID
*)&pqa
);
270 ok(hr
== S_OK
|| hr
== E_NOTIMPL
/* win98 */
271 , "Unexpected result : %08x\n", hr
);
274 IQueryAssociations_Release(pqa
);
277 hr
= pAssocCreate(CLSID_QueryAssociations
, &IID_IUnknown
, (LPVOID
*)&pqa
);
278 ok(hr
== S_OK
|| hr
== E_NOTIMPL
/* win98 */
279 , "Unexpected result : %08x\n", hr
);
282 IQueryAssociations_Release(pqa
);
289 hshlwapi
= GetModuleHandleA("shlwapi.dll");
290 pAssocQueryStringA
= (void*)GetProcAddress(hshlwapi
, "AssocQueryStringA");
291 pAssocQueryStringW
= (void*)GetProcAddress(hshlwapi
, "AssocQueryStringW");
292 pAssocCreate
= (void*)GetProcAddress(hshlwapi
, "AssocCreate");
294 test_getstring_bad();
295 test_getstring_basic();
296 test_getstring_no_extra();