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
39 #include "wine/test.h"
41 static HRESULT WINAPI Unknown_QueryInterface(IUnknown *pUnknown, REFIID riid, void **ppvObject)
43 if (IsEqualGUID(&IID_IUnknown, riid))
45 *ppvObject = pUnknown;
51 static ULONG WINAPI Unknown_AddRef(IUnknown *pUnknown)
56 static ULONG WINAPI Unknown_Release(IUnknown *pUnknown)
61 static IUnknownVtbl unknownVtbl = {
62 Unknown_QueryInterface,
67 static IUnknown unknown = {
71 static const char *printGUID(const GUID *guid)
73 static char guidSTR[39];
75 if (!guid) return NULL;
77 sprintf(guidSTR, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
78 guid->Data1, guid->Data2, guid->Data3,
79 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
80 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
84 static void test_Aggregability(void)
87 IUnknown *pUnknown = NULL;
89 hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
90 ok(SUCCEEDED(hr), "could not create instance of CLSID_InternetShortcut with IID_IUnknown, hr = 0x%x\n", hr);
92 IUnknown_Release(pUnknown);
94 hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&pUnknown);
95 ok(SUCCEEDED(hr), "could not create instance of CLSID_InternetShortcut with IID_IUniformResourceLocatorA, hr = 0x%x\n", hr);
97 IUnknown_Release(pUnknown);
99 hr = CoCreateInstance(&CLSID_InternetShortcut, &unknown, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
100 ok(FAILED(hr), "aggregation didn't fail like it should, hr = 0x%x\n", hr);
102 IUnknown_Release(pUnknown);
105 static void can_query_interface(IUnknown *pUnknown, REFIID riid)
108 IUnknown *newInterface;
109 hr = IUnknown_QueryInterface(pUnknown, riid, (void**)&newInterface);
110 ok(SUCCEEDED(hr), "interface %s could not be queried\n", printGUID(riid));
112 IUnknown_Release(newInterface);
115 static void test_QueryInterface(void)
120 hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
123 can_query_interface(pUnknown, &IID_IUniformResourceLocatorA);
124 can_query_interface(pUnknown, &IID_IUniformResourceLocatorW);
125 can_query_interface(pUnknown, &IID_IPersistFile);
126 IUnknown_Release(pUnknown);
129 skip("could not create a CLSID_InternetShortcut for QueryInterface tests, hr=0x%x\n", hr);
132 static CHAR *set_and_get_url(IUniformResourceLocatorA *urlA, LPCSTR input, DWORD flags)
135 hr = urlA->lpVtbl->SetURL(urlA, input, flags);
139 hr = urlA->lpVtbl->GetURL(urlA, &output);
143 skip("GetUrl failed, hr=0x%x\n", hr);
146 skip("SetUrl (%s, 0x%x) failed, hr=0x%x\n", input, flags, hr);
150 static void check_string_transform(IUniformResourceLocatorA *urlA, LPCSTR input, DWORD flags, LPCSTR expectedOutput)
152 CHAR *output = set_and_get_url(urlA, input, flags);
155 ok(lstrcmpA(output, expectedOutput) == 0, "unexpected URL change %s -> %s (expected %s)\n",
156 input, output, expectedOutput);
157 CoTaskMemFree(output);
161 static void test_NullURLs(void)
164 IUniformResourceLocatorA *urlA;
166 hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&urlA);
171 hr = urlA->lpVtbl->GetURL(urlA, &url);
172 ok(SUCCEEDED(hr), "getting uninitialized URL unexpectedly failed, hr=0x%x\n", hr);
173 ok(url == NULL, "uninitialized URL is not NULL but %s\n", url);
175 hr = urlA->lpVtbl->SetURL(urlA, NULL, 0);
176 ok(SUCCEEDED(hr), "setting NULL URL unexpectedly failed, hr=0x%x\n", hr);
178 hr = urlA->lpVtbl->GetURL(urlA, &url);
179 ok(SUCCEEDED(hr), "getting NULL URL unexpectedly failed, hr=0x%x\n", hr);
180 ok(url == NULL, "URL unexpectedly not NULL but %s\n", url);
182 urlA->lpVtbl->Release(urlA);
185 skip("could not create a CLSID_InternetShortcut for NullURL tests, hr=0x%x\n", hr);
188 static void test_SetURLFlags(void)
191 IUniformResourceLocatorA *urlA;
193 hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&urlA);
196 check_string_transform(urlA, "somerandomstring", 0, "somerandomstring");
197 check_string_transform(urlA, "www.winehq.org", 0, "www.winehq.org");
201 check_string_transform(urlA, "www.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL, "http://www.winehq.org/");
202 check_string_transform(urlA, "ftp.winehq.org", IURL_SETURL_FL_GUESS_PROTOCOL, "ftp://ftp.winehq.org/");
205 urlA->lpVtbl->Release(urlA);
208 skip("could not create a CLSID_InternetShortcut for SetUrl tests, hr=0x%x\n", hr);
211 static void test_InternetShortcut(void)
213 test_Aggregability();
214 test_QueryInterface();
222 test_InternetShortcut();