advapi32: Make rpcrt4 a delayed import to work around circular dependencies with...
[wine/testsucceed.git] / dlls / shdocvw / tests / intshcut.c
blobcf0b2251b933c3fbe5a73600224f46813856eb22
1 /*
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winerror.h"
31 #include "shlobj.h"
32 #include "shobjidl.h"
33 #include "shlguid.h"
34 #include "ole2.h"
35 #include "initguid.h"
36 #include "isguids.h"
37 #include "intshcut.h"
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;
46 return S_OK;
48 return E_NOINTERFACE;
51 static ULONG WINAPI Unknown_AddRef(IUnknown *pUnknown)
53 return 2;
56 static ULONG WINAPI Unknown_Release(IUnknown *pUnknown)
58 return 1;
61 static IUnknownVtbl unknownVtbl = {
62 Unknown_QueryInterface,
63 Unknown_AddRef,
64 Unknown_Release
67 static IUnknown unknown = {
68 &unknownVtbl
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]);
81 return guidSTR;
84 static void test_Aggregability(void)
86 HRESULT hr;
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);
91 if (pUnknown)
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);
96 if (pUnknown)
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);
101 if (pUnknown)
102 IUnknown_Release(pUnknown);
105 static void can_query_interface(IUnknown *pUnknown, REFIID riid)
107 HRESULT hr;
108 IUnknown *newInterface;
109 hr = IUnknown_QueryInterface(pUnknown, riid, (void**)&newInterface);
110 ok(SUCCEEDED(hr), "interface %s could not be queried\n", printGUID(riid));
111 if (SUCCEEDED(hr))
112 IUnknown_Release(newInterface);
115 static void test_QueryInterface(void)
117 HRESULT hr;
118 IUnknown *pUnknown;
120 hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUnknown, (void**)&pUnknown);
121 if (SUCCEEDED(hr))
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);
128 else
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)
134 HRESULT hr;
135 hr = urlA->lpVtbl->SetURL(urlA, input, flags);
136 if (SUCCEEDED(hr))
138 CHAR *output;
139 hr = urlA->lpVtbl->GetURL(urlA, &output);
140 if (SUCCEEDED(hr))
141 return output;
142 else
143 skip("GetUrl failed, hr=0x%x\n", hr);
145 else
146 skip("SetUrl (%s, 0x%x) failed, hr=0x%x\n", input, flags, hr);
147 return NULL;
150 static void check_string_transform(IUniformResourceLocatorA *urlA, LPCSTR input, DWORD flags, LPCSTR expectedOutput)
152 CHAR *output = set_and_get_url(urlA, input, flags);
153 if (output != NULL)
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)
163 HRESULT hr;
164 IUniformResourceLocatorA *urlA;
166 hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&urlA);
167 if (SUCCEEDED(hr))
169 LPSTR url = NULL;
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);
184 else
185 skip("could not create a CLSID_InternetShortcut for NullURL tests, hr=0x%x\n", hr);
188 static void test_SetURLFlags(void)
190 HRESULT hr;
191 IUniformResourceLocatorA *urlA;
193 hr = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_ALL, &IID_IUniformResourceLocatorA, (void**)&urlA);
194 if (SUCCEEDED(hr))
196 check_string_transform(urlA, "somerandomstring", 0, "somerandomstring");
197 check_string_transform(urlA, "www.winehq.org", 0, "www.winehq.org");
199 todo_wine
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);
207 else
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();
215 test_NullURLs();
216 test_SetURLFlags();
219 START_TEST(intshcut)
221 OleInitialize(NULL);
222 test_InternetShortcut();
223 OleUninitialize();