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
22 #include "wine/test.h"
26 #define expect(expected, got) ok ( expected == got, "Expected %d, got %d\n", expected, got)
27 #define expect_hr(expected, got) ok ( expected == got, "Expected %08x, got %08x\n", expected, got)
29 static HRESULT (WINAPI
*pAssocQueryStringA
)(ASSOCF
,ASSOCSTR
,LPCSTR
,LPCSTR
,LPSTR
,LPDWORD
) = NULL
;
30 static HRESULT (WINAPI
*pAssocQueryStringW
)(ASSOCF
,ASSOCSTR
,LPCWSTR
,LPCWSTR
,LPWSTR
,LPDWORD
) = NULL
;
31 static HRESULT (WINAPI
*pAssocCreate
)(CLSID
, REFIID
, void **) = NULL
;
33 /* Every version of Windows with IE should have this association? */
34 static const WCHAR dotHtml
[] = { '.','h','t','m','l',0 };
35 static const WCHAR badBad
[] = { 'b','a','d','b','a','d',0 };
36 static const WCHAR dotBad
[] = { '.','b','a','d',0 };
37 static const WCHAR open
[] = { 'o','p','e','n',0 };
38 static const WCHAR invalid
[] = { 'i','n','v','a','l','i','d',0 };
40 static void test_getstring_bad(void)
45 if (!pAssocQueryStringW
)
47 win_skip("AssocQueryStringW() is missing\n");
51 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, NULL
, open
, NULL
, &len
);
52 expect_hr(E_INVALIDARG
, hr
);
53 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, badBad
, open
, NULL
, &len
);
55 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
56 "Unexpected result : %08x\n", hr
);
57 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotBad
, open
, NULL
, &len
);
59 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
60 "Unexpected result : %08x\n", hr
);
61 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotHtml
, invalid
, NULL
,
63 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
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
, open
, NULL
, NULL
);
67 ok(hr
== E_UNEXPECTED
||
68 hr
== E_INVALIDARG
, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
69 "Unexpected result : %08x\n", hr
);
71 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, NULL
, open
, NULL
, &len
);
72 expect_hr(E_INVALIDARG
, hr
);
73 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, badBad
, open
, NULL
,
76 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
), /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
77 "Unexpected result : %08x\n", hr
);
78 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotBad
, open
, NULL
,
81 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
) /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */ ||
82 hr
== HRESULT_FROM_WIN32(ERROR_NOT_FOUND
), /* Win8 */
83 "Unexpected result : %08x\n", hr
);
84 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, invalid
, NULL
,
86 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
87 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
) || /* W2K/Vista/W2K8 */
88 hr
== E_FAIL
, /* Win9x/WinMe/NT4 */
89 "Unexpected result : %08x\n", hr
);
90 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, open
, NULL
,
92 ok(hr
== E_UNEXPECTED
||
93 hr
== E_INVALIDARG
, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
94 "Unexpected result : %08x\n", hr
);
97 static void test_getstring_basic(void)
100 WCHAR
* friendlyName
;
101 WCHAR
* executableName
;
102 DWORD len
, len2
, slen
;
104 if (!pAssocQueryStringW
)
106 win_skip("AssocQueryStringW() is missing\n");
110 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotHtml
, open
, NULL
, &len
);
111 expect_hr(S_FALSE
, hr
);
114 skip("failed to get initial len\n");
118 executableName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
119 len
* sizeof(WCHAR
));
122 skip("failed to allocate memory\n");
127 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotHtml
, open
,
128 executableName
, &len2
);
130 slen
= lstrlenW(executableName
) + 1;
134 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, open
, NULL
,
137 hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) /* Win9x/NT4 */ ||
138 hr
== HRESULT_FROM_WIN32(ERROR_NOT_FOUND
), /* Win8 */
139 "Unexpected result : %08x\n", hr
);
142 HeapFree(GetProcessHeap(), 0, executableName
);
143 skip("failed to get initial len\n");
147 friendlyName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
148 len
* sizeof(WCHAR
));
151 HeapFree(GetProcessHeap(), 0, executableName
);
152 skip("failed to allocate memory\n");
157 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, open
,
158 friendlyName
, &len2
);
160 slen
= lstrlenW(friendlyName
) + 1;
164 HeapFree(GetProcessHeap(), 0, executableName
);
165 HeapFree(GetProcessHeap(), 0, friendlyName
);
168 static void test_getstring_no_extra(void)
173 static const CHAR dotWinetest
[] = {
174 '.','w','i','n','e','t','e','s','t',0
176 static const CHAR winetestfile
[] = {
177 'w','i','n','e','t','e','s','t', 'f','i','l','e',0
179 static const CHAR winetestfileAction
[] = {
180 'w','i','n','e','t','e','s','t','f','i','l','e',
181 '\\','s','h','e','l','l',
183 '\\','c','o','m','m','a','n','d',0
185 static const CHAR action
[] = {
186 'n','o','t','e','p','a','d','.','e','x','e',0
189 DWORD len
= MAX_PATH
;
191 if (!pAssocQueryStringA
)
193 win_skip("AssocQueryStringA() is missing\n");
198 ret
= RegCreateKeyA(HKEY_CLASSES_ROOT
, dotWinetest
, &hkey
);
199 if (ret
!= ERROR_SUCCESS
) {
200 skip("failed to create dotWinetest key\n");
204 ret
= RegSetValueA(hkey
, NULL
, REG_SZ
, winetestfile
, lstrlenA(winetestfile
));
206 if (ret
!= ERROR_SUCCESS
)
208 skip("failed to set dotWinetest key\n");
212 ret
= RegCreateKeyA(HKEY_CLASSES_ROOT
, winetestfileAction
, &hkey
);
213 if (ret
!= ERROR_SUCCESS
)
215 skip("failed to create winetestfileAction key\n");
219 ret
= RegSetValueA(hkey
, NULL
, REG_SZ
, action
, lstrlenA(action
));
221 if (ret
!= ERROR_SUCCESS
)
223 skip("failed to set winetestfileAction key\n");
227 hr
= pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE
, dotWinetest
, NULL
, buf
, &len
);
229 hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), /* XP and W2K3 */
230 "Unexpected result : %08x\n", hr
);
231 hr
= pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE
, dotWinetest
, "foo", buf
, &len
);
233 ok(strstr(buf
, action
) != NULL
,
234 "got '%s' (Expected result to include 'notepad.exe')\n", buf
);
237 SHDeleteKeyA(HKEY_CLASSES_ROOT
, dotWinetest
);
238 SHDeleteKeyA(HKEY_CLASSES_ROOT
, winetestfile
);
242 static void test_assoc_create(void)
245 IQueryAssociations
*pqa
;
249 win_skip("AssocCreate() is missing\n");
253 hr
= pAssocCreate(IID_NULL
, &IID_NULL
, NULL
);
254 ok(hr
== E_INVALIDARG
, "Unexpected result : %08x\n", hr
);
256 hr
= pAssocCreate(CLSID_QueryAssociations
, &IID_NULL
, (LPVOID
*)&pqa
);
257 ok(hr
== CLASS_E_CLASSNOTAVAILABLE
|| hr
== E_NOTIMPL
|| hr
== E_NOINTERFACE
258 , "Unexpected result : %08x\n", hr
);
260 hr
= pAssocCreate(IID_NULL
, &IID_IQueryAssociations
, (LPVOID
*)&pqa
);
261 ok(hr
== CLASS_E_CLASSNOTAVAILABLE
|| hr
== E_NOTIMPL
|| hr
== E_INVALIDARG
262 , "Unexpected result : %08x\n", hr
);
264 hr
= pAssocCreate(CLSID_QueryAssociations
, &IID_IQueryAssociations
, (LPVOID
*)&pqa
);
265 ok(hr
== S_OK
|| hr
== E_NOTIMPL
/* win98 */
266 , "Unexpected result : %08x\n", hr
);
269 IQueryAssociations_Release(pqa
);
272 hr
= pAssocCreate(CLSID_QueryAssociations
, &IID_IUnknown
, (LPVOID
*)&pqa
);
273 ok(hr
== S_OK
|| hr
== E_NOTIMPL
/* win98 */
274 , "Unexpected result : %08x\n", hr
);
277 IQueryAssociations_Release(pqa
);
284 hshlwapi
= GetModuleHandleA("shlwapi.dll");
285 pAssocQueryStringA
= (void*)GetProcAddress(hshlwapi
, "AssocQueryStringA");
286 pAssocQueryStringW
= (void*)GetProcAddress(hshlwapi
, "AssocQueryStringW");
287 pAssocCreate
= (void*)GetProcAddress(hshlwapi
, "AssocCreate");
289 test_getstring_bad();
290 test_getstring_basic();
291 test_getstring_no_extra();