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
25 #define NONAMELESSUNION
42 #include "wine/test.h"
44 static HRESULT WINAPI
Unknown_QueryInterface(IUnknown
*pUnknown
, REFIID riid
, void **ppvObject
)
46 if (IsEqualGUID(&IID_IUnknown
, riid
))
48 *ppvObject
= pUnknown
;
54 static ULONG WINAPI
Unknown_AddRef(IUnknown
*pUnknown
)
59 static ULONG WINAPI
Unknown_Release(IUnknown
*pUnknown
)
64 static IUnknownVtbl unknownVtbl
= {
65 Unknown_QueryInterface
,
70 static IUnknown unknown
= {
74 static const char *printGUID(const GUID
*guid
)
76 static char guidSTR
[39];
78 if (!guid
) return NULL
;
80 sprintf(guidSTR
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
81 guid
->Data1
, guid
->Data2
, guid
->Data3
,
82 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
83 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7]);
87 static void test_Aggregability(void)
90 IUnknown
*pUnknown
= NULL
;
92 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUnknown
, (void**)&pUnknown
);
93 ok(hr
== S_OK
, "could not create instance of CLSID_InternetShortcut with IID_IUnknown, hr = 0x%x\n", hr
);
95 IUnknown_Release(pUnknown
);
97 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&pUnknown
);
98 ok(hr
== S_OK
, "could not create instance of CLSID_InternetShortcut with IID_IUniformResourceLocatorA, hr = 0x%x\n", hr
);
100 IUnknown_Release(pUnknown
);
102 hr
= CoCreateInstance(&CLSID_InternetShortcut
, &unknown
, CLSCTX_ALL
, &IID_IUnknown
, (void**)&pUnknown
);
103 ok(hr
== CLASS_E_NOAGGREGATION
, "aggregation didn't fail like it should, hr = 0x%x\n", hr
);
105 IUnknown_Release(pUnknown
);
108 static void can_query_interface(IUnknown
*pUnknown
, REFIID riid
)
111 IUnknown
*newInterface
;
112 hr
= IUnknown_QueryInterface(pUnknown
, riid
, (void**)&newInterface
);
113 ok(hr
== S_OK
, "interface %s could not be queried\n", printGUID(riid
));
115 IUnknown_Release(newInterface
);
118 static void test_QueryInterface(void)
123 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUnknown
, (void**)&pUnknown
);
124 ok(hr
== S_OK
, "Could not create InternetShortcut object: %08x\n", hr
);
126 can_query_interface(pUnknown
, &IID_IUniformResourceLocatorA
);
127 can_query_interface(pUnknown
, &IID_IUniformResourceLocatorW
);
128 can_query_interface(pUnknown
, &IID_IPersistFile
);
129 IUnknown_Release(pUnknown
);
132 #define test_shortcut_url(a,b) _test_shortcut_url(__LINE__,a,b)
133 static void _test_shortcut_url(unsigned line
, IUnknown
*unk
, const char *exurl
)
135 IUniformResourceLocatorA
*locator_a
;
139 hres
= IUnknown_QueryInterface(unk
, &IID_IUniformResourceLocatorA
, (void**)&locator_a
);
140 ok_(__FILE__
,line
)(hres
== S_OK
, "Could not get IUniformResourceLocatorA iface: %08x\n", hres
);
142 hres
= locator_a
->lpVtbl
->GetURL(locator_a
, &url_a
);
143 ok_(__FILE__
,line
)(hres
== S_OK
, "GetURL failed: %08x\n", hres
);
144 ok_(__FILE__
,line
)(!strcmp(url_a
, exurl
), "unexpected URL, got %s, expected %s\n", url_a
, exurl
);
145 CoTaskMemFree(url_a
);
147 IUnknown_Release(locator_a
);
150 #define check_string_transform(a,b,c,d,e) _check_string_transform(__LINE__,a,b,c,d,e)
151 static void _check_string_transform(unsigned line
, IUniformResourceLocatorA
*urlA
, LPCSTR input
, DWORD flags
,
152 LPCSTR expectedOutput
, BOOL is_todo
)
157 hr
= urlA
->lpVtbl
->SetURL(urlA
, input
, flags
);
158 ok_(__FILE__
,line
)(hr
== S_OK
, "SetUrl failed, hr=0x%x\n", hr
);
162 output
= (void*)0xdeadbeef;
163 hr
= urlA
->lpVtbl
->GetURL(urlA
, &output
);
167 ok_(__FILE__
,line
)(hr
== S_OK
, "GetUrl failed, hr=0x%x\n", hr
);
169 ok_(__FILE__
,line
)(hr
== S_OK
, "GetUrl failed, hr=0x%x\n", hr
);
172 ok_(__FILE__
,line
)(!lstrcmpA(output
, expectedOutput
), "unexpected URL change %s -> %s (expected %s)\n",
173 input
, output
, expectedOutput
);
174 CoTaskMemFree(output
);
177 ok_(__FILE__
,line
)(hr
== S_FALSE
, "GetUrl failed, hr=0x%x\n", hr
);
179 ok_(__FILE__
,line
)(!output
, "GetUrl returned %s\n", output
);
183 static BOOL
check_ie(void)
188 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
189 &IID_IHTMLDocument5
, (void**)&doc
);
193 IHTMLDocument5_Release(doc
);
197 static void test_ReadAndWriteProperties(void)
202 IUniformResourceLocatorA
*urlA
;
203 IUniformResourceLocatorA
*urlAFromFile
;
204 WCHAR fileNameW
[MAX_PATH
];
206 static const WCHAR shortcutW
[] = {'t','e','s','t','s','h','o','r','t','c','u','t','.','u','r','l',0};
207 WCHAR iconPath
[] = {'f','i','l','e',':','/','/','/','C',':','/','a','r','b','i','t','r','a','r','y','/','i','c','o','n','/','p','a','t','h',0};
208 char testurl
[] = "http://some/bogus/url.html";
210 ps
[0].ulKind
= PRSPEC_PROPID
;
211 U(ps
[0]).propid
= PID_IS_ICONFILE
;
212 ps
[1].ulKind
= PRSPEC_PROPID
;
213 U(ps
[1]).propid
= PID_IS_ICONINDEX
;
215 /* Make sure we have a valid temporary directory */
216 GetTempPathW(MAX_PATH
, fileNameW
);
217 lstrcatW(fileNameW
, shortcutW
);
219 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlA
);
223 IPropertyStorage
*pPropStgWrite
;
224 IPropertySetStorage
*pPropSetStg
;
227 /* We need to set a URL -- IPersistFile refuses to save without one. */
228 hr
= urlA
->lpVtbl
->SetURL(urlA
, testurl
, 0);
229 ok(hr
== S_OK
, "Failed to set a URL. hr=0x%x\n", hr
);
231 /* Write this shortcut out to a file so that we can test reading it in again. */
232 hr
= urlA
->lpVtbl
->QueryInterface(urlA
, &IID_IPersistFile
, (void **) &pf
);
233 ok(hr
== S_OK
, "Failed to get the IPersistFile for writing. hr=0x%x\n", hr
);
235 hr
= IPersistFile_Save(pf
, fileNameW
, TRUE
);
236 ok(hr
== S_OK
, "Failed to save via IPersistFile. hr=0x%x\n", hr
);
238 IPersistFile_Release(pf
);
240 pv
[0].vt
= VT_LPWSTR
;
241 U(pv
[0]).pwszVal
= (void *) iconPath
;
243 U(pv
[1]).iVal
= iconIndex
;
244 hr
= urlA
->lpVtbl
->QueryInterface(urlA
, &IID_IPropertySetStorage
, (void **) &pPropSetStg
);
245 ok(hr
== S_OK
, "Unable to get an IPropertySetStorage, hr=0x%x\n", hr
);
247 hr
= IPropertySetStorage_Open(pPropSetStg
, &FMTID_Intshcut
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, &pPropStgWrite
);
248 ok(hr
== S_OK
, "Unable to get an IPropertyStorage for writing, hr=0x%x\n", hr
);
250 hr
= IPropertyStorage_WriteMultiple(pPropStgWrite
, 2, ps
, pv
, 0);
251 ok(hr
== S_OK
, "Unable to set properties, hr=0x%x\n", hr
);
253 hr
= IPropertyStorage_Commit(pPropStgWrite
, STGC_DEFAULT
);
254 ok(hr
== S_OK
, "Failed to commit properties, hr=0x%x\n", hr
);
256 pPropStgWrite
->lpVtbl
->Release(pPropStgWrite
);
257 urlA
->lpVtbl
->Release(urlA
);
258 IPropertySetStorage_Release(pPropSetStg
);
261 skip("could not create a CLSID_InternetShortcut for property tests, hr=0x%x\n", hr
);
263 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlAFromFile
);
266 IPropertySetStorage
*pPropSetStg
;
267 IPropertyStorage
*pPropStgRead
;
268 PROPVARIANT pvread
[2];
272 /* Now read that .url file back in. */
273 hr
= urlAFromFile
->lpVtbl
->QueryInterface(urlAFromFile
, &IID_IPersistFile
, (void **) &pf
);
274 ok(hr
== S_OK
, "Failed to get the IPersistFile for reading. hr=0x%x\n", hr
);
276 hr
= IPersistFile_Load(pf
, fileNameW
, 0);
277 ok(hr
== S_OK
, "Failed to load via IPersistFile. hr=0x%x\n", hr
);
278 IPersistFile_Release(pf
);
281 hr
= urlAFromFile
->lpVtbl
->GetURL(urlAFromFile
, &url
);
282 ok(hr
== S_OK
, "Unable to get url from file, hr=0x%x\n", hr
);
283 ok(lstrcmp(url
, testurl
) == 0, "Wrong url read from file: %s\n",url
);
286 hr
= urlAFromFile
->lpVtbl
->QueryInterface(urlAFromFile
, &IID_IPropertySetStorage
, (void **) &pPropSetStg
);
287 ok(hr
== S_OK
, "Unable to get an IPropertySetStorage, hr=0x%x\n", hr
);
289 hr
= IPropertySetStorage_Open(pPropSetStg
, &FMTID_Intshcut
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, &pPropStgRead
);
290 ok(hr
== S_OK
, "Unable to get an IPropertyStorage for reading, hr=0x%x\n", hr
);
292 hr
= IPropertyStorage_ReadMultiple(pPropStgRead
, 2, ps
, pvread
);
293 ok(hr
== S_OK
, "Unable to read properties, hr=0x%x\n", hr
);
295 todo_wine
/* Wine doesn't yet support setting properties after save */
297 ok(U(pvread
[1]).iVal
== iconIndex
, "Read wrong icon index: %d\n", U(pvread
[1]).iVal
);
299 ok(lstrcmpW(U(pvread
[0]).pwszVal
, iconPath
) == 0, "Wrong icon path read: %s\n", wine_dbgstr_w(U(pvread
[0]).pwszVal
));
302 PropVariantClear(&pvread
[0]);
303 PropVariantClear(&pvread
[1]);
304 IPropertyStorage_Release(pPropStgRead
);
305 IPropertySetStorage_Release(pPropSetStg
);
306 urlAFromFile
->lpVtbl
->Release(urlAFromFile
);
307 DeleteFileW(fileNameW
);
310 skip("could not create a CLSID_InternetShortcut for property tests, hr=0x%x\n", hr
);
313 static void test_NullURLs(void)
317 IUniformResourceLocatorA
*urlA
;
319 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlA
);
320 ok(hr
== S_OK
, "Could not create InternetShortcut object: %08x\n", hr
);
322 hr
= urlA
->lpVtbl
->GetURL(urlA
, &url
);
323 ok(hr
== S_FALSE
, "getting uninitialized URL unexpectedly failed, hr=0x%x\n", hr
);
324 ok(url
== NULL
, "uninitialized URL is not NULL but %s\n", url
);
326 hr
= urlA
->lpVtbl
->SetURL(urlA
, NULL
, 0);
327 ok(hr
== S_OK
, "setting NULL URL unexpectedly failed, hr=0x%x\n", hr
);
329 hr
= urlA
->lpVtbl
->GetURL(urlA
, &url
);
330 ok(hr
== S_FALSE
, "getting NULL URL unexpectedly failed, hr=0x%x\n", hr
);
331 ok(url
== NULL
, "URL unexpectedly not NULL but %s\n", url
);
333 urlA
->lpVtbl
->Release(urlA
);
341 static const load_test_t load_tests
[] = {
342 {"[InternetShortcut]\n"
343 "URL=http://www.winehq.org/\n"
346 "[{000214A0-0000-0000-C000-000000000046}]\n"
349 "http://www.winehq.org/"
353 static void test_Load(void)
355 IPersistFile
*persist_file
;
356 const load_test_t
*test
;
357 WCHAR file_path
[MAX_PATH
];
362 static const WCHAR test_urlW
[] = {'t','e','s','t','.','u','r','l',0};
364 GetTempPathW(MAX_PATH
, file_path
);
365 lstrcatW(file_path
, test_urlW
);
367 for(test
= load_tests
; test
< load_tests
+ sizeof(load_tests
)/sizeof(*load_tests
); test
++) {
368 file
= CreateFileW(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
369 ok(file
!= INVALID_HANDLE_VALUE
, "could not create test file\n");
370 if(file
== INVALID_HANDLE_VALUE
)
373 WriteFile(file
, test
->data
, strlen(test
->data
), &size
, NULL
);
376 hres
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IPersistFile
, (void**)&persist_file
);
377 ok(hres
== S_OK
, "Could not create InternetShortcut instance: %08x\n", hres
);
379 hres
= IPersistFile_Load(persist_file
, file_path
, 0);
380 ok(hres
== S_OK
, "Load failed: %08x\n", hres
);
382 test_shortcut_url((IUnknown
*)persist_file
, test
->url
);
384 IPersistFile_Release(persist_file
);
385 DeleteFileW(file_path
);
389 static void test_SetURLFlags(void)
392 IUniformResourceLocatorA
*urlA
;
394 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlA
);
395 ok(hr
== S_OK
, "Could not create InternetShortcut object: %08x\n", hr
);
397 check_string_transform(urlA
, "somerandomstring", 0, NULL
, TRUE
);
398 check_string_transform(urlA
, "www.winehq.org", 0, NULL
, TRUE
);
400 check_string_transform(urlA
, "www.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL
, "http://www.winehq.org/", FALSE
);
401 check_string_transform(urlA
, "ftp.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL
, "ftp://ftp.winehq.org/", FALSE
);
403 urlA
->lpVtbl
->Release(urlA
);
406 static void test_InternetShortcut(void)
408 IUniformResourceLocatorA
*url
;
411 hres
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&url
);
413 win_skip("Could not create CLSID_InternetShortcut instance: %08x\n", hres
);
417 test_Aggregability();
418 test_QueryInterface();
421 test_ReadAndWriteProperties();
430 test_InternetShortcut();
432 win_skip("Too old IE\n");