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
);
152 ok_(__FILE__
,line
)(hr
== S_OK
, "GetUrl failed, hr=0x%x\n", hr
);
154 ok_(__FILE__
,line
)(hr
== S_OK
, "GetUrl failed, hr=0x%x\n", hr
);
157 ok_(__FILE__
,line
)(!lstrcmpA(output
, expectedOutput
), "unexpected URL change %s -> %s (expected %s)\n",
158 input
, output
, expectedOutput
);
161 ok_(__FILE__
,line
)(hr
== S_FALSE
, "GetUrl failed, hr=0x%x\n", hr
);
163 ok_(__FILE__
,line
)(!output
, "GetUrl returned %s\n", output
);
166 CoTaskMemFree(output
);
169 static void test_ReadAndWriteProperties(void)
174 IUniformResourceLocatorA
*urlA
;
175 IUniformResourceLocatorA
*urlAFromFile
;
176 WCHAR fileNameW
[MAX_PATH
];
178 static const WCHAR shortcutW
[] = {'t','e','s','t','s','h','o','r','t','c','u','t','.','u','r','l',0};
179 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};
180 char testurl
[] = "http://some/bogus/url.html";
182 ps
[0].ulKind
= PRSPEC_PROPID
;
183 U(ps
[0]).propid
= PID_IS_ICONFILE
;
184 ps
[1].ulKind
= PRSPEC_PROPID
;
185 U(ps
[1]).propid
= PID_IS_ICONINDEX
;
187 /* Make sure we have a valid temporary directory */
188 GetTempPathW(MAX_PATH
, fileNameW
);
189 lstrcatW(fileNameW
, shortcutW
);
191 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlA
);
192 ok(hr
== S_OK
, "Could not create CLSID_InternetShortcut instance: %08x\n", hr
);
196 IPropertyStorage
*pPropStgWrite
;
197 IPropertySetStorage
*pPropSetStg
;
200 /* We need to set a URL -- IPersistFile refuses to save without one. */
201 hr
= urlA
->lpVtbl
->SetURL(urlA
, testurl
, 0);
202 ok(hr
== S_OK
, "Failed to set a URL. hr=0x%x\n", hr
);
204 /* Write this shortcut out to a file so that we can test reading it in again. */
205 hr
= urlA
->lpVtbl
->QueryInterface(urlA
, &IID_IPersistFile
, (void **) &pf
);
206 ok(hr
== S_OK
, "Failed to get the IPersistFile for writing. hr=0x%x\n", hr
);
208 hr
= IPersistFile_Save(pf
, fileNameW
, TRUE
);
209 ok(hr
== S_OK
, "Failed to save via IPersistFile. hr=0x%x\n", hr
);
211 IPersistFile_Release(pf
);
213 pv
[0].vt
= VT_LPWSTR
;
214 U(pv
[0]).pwszVal
= (void *) iconPath
;
216 U(pv
[1]).iVal
= iconIndex
;
217 hr
= urlA
->lpVtbl
->QueryInterface(urlA
, &IID_IPropertySetStorage
, (void **) &pPropSetStg
);
218 ok(hr
== S_OK
, "Unable to get an IPropertySetStorage, hr=0x%x\n", hr
);
220 hr
= IPropertySetStorage_Open(pPropSetStg
, &FMTID_Intshcut
, STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
, &pPropStgWrite
);
221 ok(hr
== S_OK
, "Unable to get an IPropertyStorage for writing, hr=0x%x\n", hr
);
223 hr
= IPropertyStorage_WriteMultiple(pPropStgWrite
, 2, ps
, pv
, 0);
224 ok(hr
== S_OK
, "Unable to set properties, hr=0x%x\n", hr
);
226 hr
= IPropertyStorage_Commit(pPropStgWrite
, STGC_DEFAULT
);
227 ok(hr
== S_OK
, "Failed to commit properties, hr=0x%x\n", hr
);
229 pPropStgWrite
->lpVtbl
->Release(pPropStgWrite
);
230 urlA
->lpVtbl
->Release(urlA
);
231 IPropertySetStorage_Release(pPropSetStg
);
234 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlAFromFile
);
235 ok(hr
== S_OK
, "Could not create CLSID_InternetShortcut instance: %08x\n", hr
);
238 IPropertySetStorage
*pPropSetStg
;
239 IPropertyStorage
*pPropStgRead
;
240 PROPVARIANT pvread
[2];
244 /* Now read that .url file back in. */
245 hr
= urlAFromFile
->lpVtbl
->QueryInterface(urlAFromFile
, &IID_IPersistFile
, (void **) &pf
);
246 ok(hr
== S_OK
, "Failed to get the IPersistFile for reading. hr=0x%x\n", hr
);
248 hr
= IPersistFile_Load(pf
, fileNameW
, 0);
249 ok(hr
== S_OK
, "Failed to load via IPersistFile. hr=0x%x\n", hr
);
250 IPersistFile_Release(pf
);
253 hr
= urlAFromFile
->lpVtbl
->GetURL(urlAFromFile
, &url
);
254 ok(hr
== S_OK
, "Unable to get url from file, hr=0x%x\n", hr
);
255 ok(lstrcmpA(url
, testurl
) == 0, "Wrong url read from file: %s\n",url
);
258 hr
= urlAFromFile
->lpVtbl
->QueryInterface(urlAFromFile
, &IID_IPropertySetStorage
, (void **) &pPropSetStg
);
259 ok(hr
== S_OK
, "Unable to get an IPropertySetStorage, hr=0x%x\n", hr
);
261 hr
= IPropertySetStorage_Open(pPropSetStg
, &FMTID_Intshcut
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, &pPropStgRead
);
262 ok(hr
== S_OK
, "Unable to get an IPropertyStorage for reading, hr=0x%x\n", hr
);
264 hr
= IPropertyStorage_ReadMultiple(pPropStgRead
, 2, ps
, pvread
);
265 ok(hr
== S_OK
, "Unable to read properties, hr=0x%x\n", hr
);
267 todo_wine
/* Wine doesn't yet support setting properties after save */
269 ok(U(pvread
[1]).iVal
== iconIndex
, "Read wrong icon index: %d\n", U(pvread
[1]).iVal
);
271 ok(lstrcmpW(U(pvread
[0]).pwszVal
, iconPath
) == 0, "Wrong icon path read: %s\n", wine_dbgstr_w(U(pvread
[0]).pwszVal
));
274 PropVariantClear(&pvread
[0]);
275 PropVariantClear(&pvread
[1]);
276 IPropertyStorage_Release(pPropStgRead
);
277 IPropertySetStorage_Release(pPropSetStg
);
278 urlAFromFile
->lpVtbl
->Release(urlAFromFile
);
279 DeleteFileW(fileNameW
);
283 static void test_NullURLs(void)
287 IUniformResourceLocatorA
*urlA
;
289 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlA
);
290 ok(hr
== S_OK
, "Could not create InternetShortcut object: %08x\n", hr
);
292 hr
= urlA
->lpVtbl
->GetURL(urlA
, &url
);
293 ok(hr
== S_FALSE
, "getting uninitialized URL unexpectedly failed, hr=0x%x\n", hr
);
294 ok(url
== NULL
, "uninitialized URL is not NULL but %s\n", url
);
296 hr
= urlA
->lpVtbl
->SetURL(urlA
, NULL
, 0);
297 ok(hr
== S_OK
, "setting NULL URL unexpectedly failed, hr=0x%x\n", hr
);
299 hr
= urlA
->lpVtbl
->GetURL(urlA
, &url
);
300 ok(hr
== S_FALSE
, "getting NULL URL unexpectedly failed, hr=0x%x\n", hr
);
301 ok(url
== NULL
, "URL unexpectedly not NULL but %s\n", url
);
303 urlA
->lpVtbl
->Release(urlA
);
311 static const load_test_t load_tests
[] = {
312 {"[InternetShortcut]\n"
313 "URL=http://www.winehq.org/\n"
316 "[{000214A0-0000-0000-C000-000000000046}]\n"
319 "http://www.winehq.org/"
323 static void test_Load(void)
325 IPersistFile
*persist_file
;
326 const load_test_t
*test
;
327 WCHAR file_path
[MAX_PATH
];
332 static const WCHAR test_urlW
[] = {'t','e','s','t','.','u','r','l',0};
334 GetTempPathW(MAX_PATH
, file_path
);
335 lstrcatW(file_path
, test_urlW
);
337 for(test
= load_tests
; test
< load_tests
+ sizeof(load_tests
)/sizeof(*load_tests
); test
++) {
338 file
= CreateFileW(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
339 ok(file
!= INVALID_HANDLE_VALUE
, "could not create test file\n");
340 if(file
== INVALID_HANDLE_VALUE
)
343 WriteFile(file
, test
->data
, strlen(test
->data
), &size
, NULL
);
346 hres
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IPersistFile
, (void**)&persist_file
);
347 ok(hres
== S_OK
, "Could not create InternetShortcut instance: %08x\n", hres
);
349 hres
= IPersistFile_Load(persist_file
, file_path
, 0);
350 ok(hres
== S_OK
, "Load failed: %08x\n", hres
);
352 test_shortcut_url((IUnknown
*)persist_file
, test
->url
);
354 IPersistFile_Release(persist_file
);
355 DeleteFileW(file_path
);
359 static void test_SetURLFlags(void)
362 IUniformResourceLocatorA
*urlA
;
364 hr
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&urlA
);
365 ok(hr
== S_OK
, "Could not create InternetShortcut object: %08x\n", hr
);
367 check_string_transform(urlA
, "somerandomstring", 0, NULL
, TRUE
);
368 check_string_transform(urlA
, "www.winehq.org", 0, NULL
, TRUE
);
370 check_string_transform(urlA
, "www.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL
, "http://www.winehq.org/", FALSE
);
371 check_string_transform(urlA
, "ftp.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL
, "ftp://ftp.winehq.org/", FALSE
);
373 urlA
->lpVtbl
->Release(urlA
);
376 static void test_InternetShortcut(void)
378 IUniformResourceLocatorA
*url
;
381 hres
= CoCreateInstance(&CLSID_InternetShortcut
, NULL
, CLSCTX_ALL
, &IID_IUniformResourceLocatorA
, (void**)&url
);
382 ok(hres
== S_OK
, "Could not create CLSID_InternetShortcut instance: %08x\n", hres
);
385 url
->lpVtbl
->Release(url
);
387 test_Aggregability();
388 test_QueryInterface();
391 test_ReadAndWriteProperties();
399 test_InternetShortcut();