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 "Unexpected result : %08x\n", hr
);
83 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, invalid
, NULL
,
85 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
) ||
86 hr
== HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION
) || /* W2K/Vista/W2K8 */
87 hr
== E_FAIL
, /* Win9x/WinMe/NT4 */
88 "Unexpected result : %08x\n", hr
);
89 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, open
, NULL
,
91 ok(hr
== E_UNEXPECTED
||
92 hr
== E_INVALIDARG
, /* Win9x/WinMe/NT4/W2K/Vista/W2K8 */
93 "Unexpected result : %08x\n", hr
);
96 static void test_getstring_basic(void)
100 WCHAR
* executableName
;
101 DWORD len
, len2
, slen
;
103 if (!pAssocQueryStringW
)
105 win_skip("AssocQueryStringW() is missing\n");
109 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotHtml
, open
, NULL
, &len
);
110 expect_hr(S_FALSE
, hr
);
113 skip("failed to get initial len\n");
117 executableName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
118 len
* sizeof(WCHAR
));
121 skip("failed to allocate memory\n");
126 hr
= pAssocQueryStringW(0, ASSOCSTR_EXECUTABLE
, dotHtml
, open
,
127 executableName
, &len2
);
129 slen
= lstrlenW(executableName
) + 1;
133 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, open
, NULL
,
136 hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), /* Win9x/NT4 */
137 "Unexpected result : %08x\n", hr
);
140 HeapFree(GetProcessHeap(), 0, executableName
);
141 skip("failed to get initial len\n");
145 friendlyName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
146 len
* sizeof(WCHAR
));
149 HeapFree(GetProcessHeap(), 0, executableName
);
150 skip("failed to allocate memory\n");
155 hr
= pAssocQueryStringW(0, ASSOCSTR_FRIENDLYAPPNAME
, dotHtml
, open
,
156 friendlyName
, &len2
);
158 slen
= lstrlenW(friendlyName
) + 1;
162 HeapFree(GetProcessHeap(), 0, executableName
);
163 HeapFree(GetProcessHeap(), 0, friendlyName
);
166 static void test_getstring_no_extra(void)
171 static const CHAR dotWinetest
[] = {
172 '.','w','i','n','e','t','e','s','t',0
174 static const CHAR winetestfile
[] = {
175 'w','i','n','e','t','e','s','t', 'f','i','l','e',0
177 static const CHAR winetestfileAction
[] = {
178 'w','i','n','e','t','e','s','t','f','i','l','e',
179 '\\','s','h','e','l','l',
181 '\\','c','o','m','m','a','n','d',0
183 static const CHAR action
[] = {
184 'n','o','t','e','p','a','d','.','e','x','e',0
187 DWORD len
= MAX_PATH
;
189 if (!pAssocQueryStringA
)
191 win_skip("AssocQueryStringA() is missing\n");
196 ret
= RegCreateKeyA(HKEY_CLASSES_ROOT
, dotWinetest
, &hkey
);
197 if (ret
!= ERROR_SUCCESS
) {
198 skip("failed to create dotWinetest key\n");
202 ret
= RegSetValueA(hkey
, NULL
, REG_SZ
, winetestfile
, lstrlenA(winetestfile
));
204 if (ret
!= ERROR_SUCCESS
)
206 skip("failed to set dotWinetest key\n");
210 ret
= RegCreateKeyA(HKEY_CLASSES_ROOT
, winetestfileAction
, &hkey
);
211 if (ret
!= ERROR_SUCCESS
)
213 skip("failed to create winetestfileAction key\n");
217 ret
= RegSetValueA(hkey
, NULL
, REG_SZ
, action
, lstrlenA(action
));
219 if (ret
!= ERROR_SUCCESS
)
221 skip("failed to set winetestfileAction key\n");
225 hr
= pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE
, dotWinetest
, NULL
, buf
, &len
);
227 hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), /* XP and W2K3 */
228 "Unexpected result : %08x\n", hr
);
229 hr
= pAssocQueryStringA(0, ASSOCSTR_EXECUTABLE
, dotWinetest
, "foo", buf
, &len
);
231 ok(strstr(buf
, action
) != NULL
,
232 "got '%s' (Expected result to include 'notepad.exe')\n", buf
);
235 SHDeleteKeyA(HKEY_CLASSES_ROOT
, dotWinetest
);
236 SHDeleteKeyA(HKEY_CLASSES_ROOT
, winetestfile
);
240 static void test_assoc_create(void)
243 IQueryAssociations
*pqa
;
247 win_skip("AssocCreate() is missing\n");
251 hr
= pAssocCreate(IID_NULL
, &IID_NULL
, NULL
);
252 ok(hr
== E_INVALIDARG
, "Unexpected result : %08x\n", hr
);
254 hr
= pAssocCreate(CLSID_QueryAssociations
, &IID_NULL
, (LPVOID
*)&pqa
);
255 ok(hr
== CLASS_E_CLASSNOTAVAILABLE
|| hr
== E_NOTIMPL
|| hr
== E_NOINTERFACE
256 , "Unexpected result : %08x\n", hr
);
258 hr
= pAssocCreate(IID_NULL
, &IID_IQueryAssociations
, (LPVOID
*)&pqa
);
259 ok(hr
== CLASS_E_CLASSNOTAVAILABLE
|| hr
== E_NOTIMPL
|| hr
== E_INVALIDARG
260 , "Unexpected result : %08x\n", hr
);
262 hr
= pAssocCreate(CLSID_QueryAssociations
, &IID_IQueryAssociations
, (LPVOID
*)&pqa
);
263 ok(hr
== S_OK
|| hr
== E_NOTIMPL
/* win98 */
264 , "Unexpected result : %08x\n", hr
);
267 IQueryAssociations_Release(pqa
);
270 hr
= pAssocCreate(CLSID_QueryAssociations
, &IID_IUnknown
, (LPVOID
*)&pqa
);
271 ok(hr
== S_OK
|| hr
== E_NOTIMPL
/* win98 */
272 , "Unexpected result : %08x\n", hr
);
275 IQueryAssociations_Release(pqa
);
282 hshlwapi
= GetModuleHandleA("shlwapi.dll");
283 pAssocQueryStringA
= (void*)GetProcAddress(hshlwapi
, "AssocQueryStringA");
284 pAssocQueryStringW
= (void*)GetProcAddress(hshlwapi
, "AssocQueryStringW");
285 pAssocCreate
= (void*)GetProcAddress(hshlwapi
, "AssocCreate");
287 test_getstring_bad();
288 test_getstring_basic();
289 test_getstring_no_extra();