2 * Unit tests to document InternetShortcut's behaviour
4 * Copyright 2008 Damjan Jovanovic
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
40 #include "wine/test.h"
42 static HRESULT WINAPI
Unknown_QueryInterface(IUnknown
*pUnknown
, REFIID riid
, void **ppvObject
)
44 if (IsEqualGUID(&IID_IUnknown
, riid
))
46 *ppvObject
= pUnknown
;
52 static ULONG WINAPI
Unknown_AddRef(IUnknown
*pUnknown
)
57 static ULONG WINAPI
Unknown_Release(IUnknown
*pUnknown
)
62 static IUnknownVtbl unknownVtbl
= {
63 Unknown_QueryInterface
,
68 static IUnknown unknown
= {
72 static void test_Aggregability(void)
75 IUnknown
*pUnknown
= NULL
;
77 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUnknown
, (void**)&pUnknown
);
78 ok(hr
== S_OK
, "could not create instance of CLSID_InternetShortcut with IID_IUnknown, hr = 0x%x\n", hr
);
80 IUnknown_Release(pUnknown
);
82 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&pUnknown
);
83 ok(hr
== S_OK
, "could not create instance of CLSID_InternetShortcut with IID_IUniformResourceLocatorA, hr = 0x%x\n", hr
);
85 IUnknown_Release(pUnknown
);
87 hr
= CoCreateInstance(&CLSID_InternetShortcut
, &unknown
, CLSCTX_ALL
, &IID_IUnknown
, (void**)&pUnknown
);
88 ok(hr
== CLASS_E_NOAGGREGATION
, "aggregation didn't fail like it should, hr = 0x%x\n", hr
);
90 IUnknown_Release(pUnknown
);
93 static void can_query_interface(IUnknown
*pUnknown
, REFIID riid
)
96 IUnknown
*newInterface
;
97 hr
= IUnknown_QueryInterface(pUnknown
, riid
, (void**)&newInterface
);
98 ok(hr
== S_OK
, "interface %s could not be queried\n", wine_dbgstr_guid(riid
));
100 IUnknown_Release(newInterface
);
103 static void test_QueryInterface(void)
108 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUnknown
, (void**)&pUnknown
);
109 ok(hr
== S_OK
, "Could not create InternetShortcut object: %08x\n", hr
);
111 can_query_interface(pUnknown
, &IID_IUniformResourceLocatorA
);
112 can_query_interface(pUnknown
, &IID_IUniformResourceLocatorW
);
113 can_query_interface(pUnknown
, &IID_IPersistFile
);
114 IUnknown_Release(pUnknown
);
117 #define test_shortcut_url(a,b) _test_shortcut_url(__LINE__,a,b)
118 static void _test_shortcut_url(unsigned line
, IUnknown
*unk
, const char *exurl
)
120 IUniformResourceLocatorA
*locator_a
;
124 hres
= IUnknown_QueryInterface(unk
, &IID_IUniformResourceLocatorA
, (void**)&locator_a
);
125 ok_(__FILE__
,line
)(hres
== S_OK
, "Could not get IUniformResourceLocatorA iface: %08x\n", hres
);
127 hres
= locator_a
->lpVtbl
->GetURL(locator_a
, &url_a
);
128 ok_(__FILE__
,line
)(hres
== S_OK
, "GetURL failed: %08x\n", hres
);
129 ok_(__FILE__
,line
)(!strcmp(url_a
, exurl
), "unexpected URL, got %s, expected %s\n", url_a
, exurl
);
130 CoTaskMemFree(url_a
);
132 IUnknown_Release((IUnknown
*)locator_a
);
135 #define check_string_transform(a,b,c,d,e) _check_string_transform(__LINE__,a,b,c,d,e)
136 static void _check_string_transform(unsigned line
, IUniformResourceLocatorA
*urlA
, LPCSTR input
, DWORD flags
,
137 LPCSTR expectedOutput
, BOOL is_todo
)
142 hr
= urlA
->lpVtbl
->SetURL(urlA
, input
, flags
);
143 ok_(__FILE__
,line
)(hr
== S_OK
, "SetUrl failed, hr=0x%x\n", hr
);
147 output
= (void*)0xdeadbeef;
148 hr
= urlA
->lpVtbl
->GetURL(urlA
, &output
);
150 todo_wine_if(is_todo
) {
151 ok_(__FILE__
,line
)(hr
== S_OK
, "GetUrl failed, hr=0x%x\n", hr
);
154 ok_(__FILE__
,line
)(!lstrcmpA(output
, expectedOutput
), "unexpected URL change %s -> %s (expected %s)\n",
155 input
, output
, expectedOutput
);
158 ok_(__FILE__
,line
)(hr
== S_FALSE
, "GetUrl failed, hr=0x%x\n", hr
);
160 ok_(__FILE__
,line
)(!output
, "GetUrl returned %s\n", output
);
163 CoTaskMemFree(output
);
166 static void test_ReadAndWriteProperties(void)
171 IUniformResourceLocatorA
*urlA
;
172 IUniformResourceLocatorA
*urlAFromFile
;
173 WCHAR fileNameW
[MAX_PATH
];
174 static WCHAR iconPath
[] = L
"file:///C:/arbitrary/icon/path";
175 char testurl
[] = "http://some/bogus/url.html";
177 ps
[0].ulKind
= PRSPEC_PROPID
;
178 U(ps
[0]).propid
= PID_IS_ICONFILE
;
179 ps
[1].ulKind
= PRSPEC_PROPID
;
180 U(ps
[1]).propid
= PID_IS_ICONINDEX
;
182 /* Make sure we have a valid temporary directory */
183 GetTempPathW(MAX_PATH
, fileNameW
);
184 lstrcatW(fileNameW
, L
"testshortcut.url");
186 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlA
);
187 ok(hr
== S_OK
, "Could not create CLSID_InternetShortcut instance: %08x\n", hr
);
191 IPropertyStorage
*pPropStgWrite
;
192 IPropertySetStorage
*pPropSetStg
;
195 /* We need to set a URL -- IPersistFile refuses to save without one. */
196 hr
= urlA
->lpVtbl
->SetURL(urlA
, testurl
, 0);
197 ok(hr
== S_OK
, "Failed to set a URL. hr=0x%x\n", hr
);
199 /* Write this shortcut out to a file so that we can test reading it in again. */
200 hr
= urlA
->lpVtbl
->QueryInterface(urlA
, &IID_IPersistFile
, (void **) &pf
);
201 ok(hr
== S_OK
, "Failed to get the IPersistFile for writing. hr=0x%x\n", hr
);
203 hr
= IPersistFile_Save(pf
, fileNameW
, TRUE
);
204 ok(hr
== S_OK
, "Failed to save via IPersistFile. hr=0x%x\n", hr
);
206 IPersistFile_Release(pf
);
208 pv
[0].vt
= VT_LPWSTR
;
209 U(pv
[0]).pwszVal
= iconPath
;
211 U(pv
[1]).lVal
= iconIndex
;
212 hr
= urlA
->lpVtbl
->QueryInterface(urlA
, &IID_IPropertySetStorage
, (void **) &pPropSetStg
);
213 ok(hr
== S_OK
, "Unable to get an IPropertySetStorage, hr=0x%x\n", hr
);
215 hr
= IPropertySetStorage_Open(pPropSetStg
, &FMTID_Intshcut
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, &pPropStgWrite
);
216 ok(hr
== S_OK
, "Unable to get an IPropertyStorage for writing, hr=0x%x\n", hr
);
218 hr
= IPropertyStorage_WriteMultiple(pPropStgWrite
, 2, ps
, pv
, 0);
219 ok(hr
== S_OK
, "Unable to set properties, hr=0x%x\n", hr
);
221 hr
= IPropertyStorage_Commit(pPropStgWrite
, STGC_DEFAULT
);
222 ok(hr
== S_OK
, "Failed to commit properties, hr=0x%x\n", hr
);
224 pPropStgWrite
->lpVtbl
->Release(pPropStgWrite
);
225 urlA
->lpVtbl
->Release(urlA
);
226 IPropertySetStorage_Release(pPropSetStg
);
229 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlAFromFile
);
230 ok(hr
== S_OK
, "Could not create CLSID_InternetShortcut instance: %08x\n", hr
);
233 IPropertySetStorage
*pPropSetStg
;
234 IPropertyStorage
*pPropStgRead
;
235 PROPVARIANT pvread
[2];
239 /* Now read that .url file back in. */
240 hr
= urlAFromFile
->lpVtbl
->QueryInterface(urlAFromFile
, &IID_IPersistFile
, (void **) &pf
);
241 ok(hr
== S_OK
, "Failed to get the IPersistFile for reading. hr=0x%x\n", hr
);
243 hr
= IPersistFile_Load(pf
, fileNameW
, 0);
244 ok(hr
== S_OK
, "Failed to load via IPersistFile. hr=0x%x\n", hr
);
245 IPersistFile_Release(pf
);
248 hr
= urlAFromFile
->lpVtbl
->GetURL(urlAFromFile
, &url
);
249 ok(hr
== S_OK
, "Unable to get url from file, hr=0x%x\n", hr
);
250 ok(lstrcmpA(url
, testurl
) == 0, "Wrong url read from file: %s\n",url
);
253 hr
= urlAFromFile
->lpVtbl
->QueryInterface(urlAFromFile
, &IID_IPropertySetStorage
, (void **) &pPropSetStg
);
254 ok(hr
== S_OK
, "Unable to get an IPropertySetStorage, hr=0x%x\n", hr
);
256 hr
= IPropertySetStorage_Open(pPropSetStg
, &FMTID_Intshcut
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, &pPropStgRead
);
257 ok(hr
== S_OK
, "Unable to get an IPropertyStorage for reading, hr=0x%x\n", hr
);
259 memset(pvread
, 0, sizeof(pvread
));
260 hr
= IPropertyStorage_ReadMultiple(pPropStgRead
, 2, ps
, pvread
);
261 todo_wine
/* Wine doesn't yet support setting properties after save */
263 ok(hr
== S_OK
, "Unable to read properties, hr=0x%x\n", hr
);
264 ok(pvread
[1].vt
== VT_I4
, "got %d\n", pvread
[1].vt
);
265 ok(U(pvread
[1]).lVal
== iconIndex
, "Read wrong icon index: %d\n", U(pvread
[1]).iVal
);
266 ok(pvread
[0].vt
== VT_LPWSTR
, "got %d\n", pvread
[0].vt
);
267 ok(lstrcmpW(U(pvread
[0]).pwszVal
, iconPath
) == 0, "Wrong icon path read: %s\n", wine_dbgstr_w(U(pvread
[0]).pwszVal
));
269 PropVariantClear(&pvread
[0]);
270 PropVariantClear(&pvread
[1]);
271 IPropertyStorage_Release(pPropStgRead
);
272 IPropertySetStorage_Release(pPropSetStg
);
273 urlAFromFile
->lpVtbl
->Release(urlAFromFile
);
274 DeleteFileW(fileNameW
);
278 static void test_NullURLs(void)
282 IUniformResourceLocatorA
*urlA
;
284 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlA
);
285 ok(hr
== S_OK
, "Could not create InternetShortcut object: %08x\n", hr
);
287 hr
= urlA
->lpVtbl
->GetURL(urlA
, &url
);
288 ok(hr
== S_FALSE
, "getting uninitialized URL unexpectedly failed, hr=0x%x\n", hr
);
289 ok(url
== NULL
, "uninitialized URL is not NULL but %s\n", url
);
291 hr
= urlA
->lpVtbl
->SetURL(urlA
, NULL
, 0);
292 ok(hr
== S_OK
, "setting NULL URL unexpectedly failed, hr=0x%x\n", hr
);
294 hr
= urlA
->lpVtbl
->GetURL(urlA
, &url
);
295 ok(hr
== S_FALSE
, "getting NULL URL unexpectedly failed, hr=0x%x\n", hr
);
296 ok(url
== NULL
, "URL unexpectedly not NULL but %s\n", url
);
298 urlA
->lpVtbl
->Release(urlA
);
306 static const load_test_t load_tests
[] = {
307 {"[InternetShortcut]\n"
308 "URL=http://www.winehq.org/\n"
311 "[{000214A0-0000-0000-C000-000000000046}]\n"
314 "http://www.winehq.org/"
318 static void test_Load(void)
320 IPersistFile
*persist_file
;
321 const load_test_t
*test
;
322 WCHAR file_path
[MAX_PATH
];
327 GetTempPathW(MAX_PATH
, file_path
);
328 lstrcatW(file_path
, L
"test.url");
330 for(test
= load_tests
; test
< load_tests
+ ARRAY_SIZE(load_tests
); test
++) {
331 IPropertySetStorage
*propsetstorage
;
332 IPropertyStorage
*propstorage
;
336 file
= CreateFileW(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
337 ok(file
!= INVALID_HANDLE_VALUE
, "could not create test file\n");
338 if(file
== INVALID_HANDLE_VALUE
)
341 WriteFile(file
, test
->data
, strlen(test
->data
), &size
, NULL
);
344 hres
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IPersistFile
, (void**)&persist_file
);
345 ok(hres
== S_OK
, "Could not create InternetShortcut instance: %08x\n", hres
);
347 hres
= IPersistFile_Load(persist_file
, file_path
, 0);
348 ok(hres
== S_OK
, "Load failed: %08x\n", hres
);
350 test_shortcut_url((IUnknown
*)persist_file
, test
->url
);
352 hres
= IPersistFile_QueryInterface(persist_file
, &IID_IPropertySetStorage
, (void **)&propsetstorage
);
353 ok(hres
== S_OK
, "Unable to get an IPropertySetStorage, hr=0x%x\n", hres
);
355 hres
= IPropertySetStorage_Open(propsetstorage
, &FMTID_Intshcut
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, &propstorage
);
356 ok(hres
== S_OK
, "Unable to get an IPropertyStorage for reading, hr=0x%x\n", hres
);
358 ps
.ulKind
= PRSPEC_PROPID
;
359 U(ps
).propid
= PID_IS_ICONFILE
;
361 hres
= IPropertyStorage_ReadMultiple(propstorage
, 1, &ps
, &v
);
362 ok(hres
== S_FALSE
, "got 0x%08x\n", hres
);
363 ok(v
.vt
== VT_EMPTY
, "got %d\n", v
.vt
);
365 ps
.ulKind
= PRSPEC_PROPID
;
366 U(ps
).propid
= PID_IS_ICONINDEX
;
368 hres
= IPropertyStorage_ReadMultiple(propstorage
, 1, &ps
, &v
);
369 ok(hres
== S_FALSE
, "got 0x%08x\n", hres
);
370 ok(v
.vt
== VT_EMPTY
, "got %d\n", v
.vt
);
372 IPropertyStorage_Release(propstorage
);
373 IPropertySetStorage_Release(propsetstorage
);
375 IPersistFile_Release(persist_file
);
376 DeleteFileW(file_path
);
380 static void test_SetURLFlags(void)
383 IUniformResourceLocatorA
*urlA
;
385 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlA
);
386 ok(hr
== S_OK
, "Could not create InternetShortcut object: %08x\n", hr
);
388 check_string_transform(urlA
, "somerandomstring", 0, NULL
, TRUE
);
389 check_string_transform(urlA
, "www.winehq.org", 0, NULL
, TRUE
);
391 check_string_transform(urlA
, "www.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL
, "http://www.winehq.org/", FALSE
);
392 check_string_transform(urlA
, "ftp.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL
, "ftp://ftp.winehq.org/", FALSE
);
394 urlA
->lpVtbl
->Release(urlA
);
397 static void test_InternetShortcut(void)
399 IUniformResourceLocatorA
*url
;
402 hres
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&url
);
403 ok(hres
== S_OK
, "Could not create CLSID_InternetShortcut instance: %08x\n", hres
);
406 url
->lpVtbl
->Release(url
);
408 test_Aggregability();
409 test_QueryInterface();
412 test_ReadAndWriteProperties();
420 test_InternetShortcut();