include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / mshtml / tests / htmllocation.c
blob222b9553816304f96d71c247fd780f200e85cb3b
1 /*
2 * Copyright 2009 Andrew Eikum for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
24 #include "mshtml.h"
25 #include "wininet.h"
27 struct location_test {
28 const char *name;
29 const char *url;
31 const char *href;
32 const char *protocol;
33 const char *host;
34 const char *hostname;
35 const char *port;
36 const char *pathname;
37 const char *search;
38 const char *hash;
41 static const struct location_test location_tests[] = {
43 "Empty",
44 NULL,
45 "about:blank",
46 "about:",
47 NULL,
48 NULL,
49 NULL,
50 "blank",
51 NULL,
52 NULL
55 "HTTP",
56 "http://www.winehq.org?search#hash",
57 "http://www.winehq.org/?search#hash",
58 "http:",
59 "www.winehq.org:80",
60 "www.winehq.org",
61 "80",
62 "/",
63 "?search",
64 "#hash"
67 "HTTP with file",
68 "http://www.winehq.org/file?search#hash",
69 "http://www.winehq.org/file?search#hash",
70 "http:",
71 "www.winehq.org:80",
72 "www.winehq.org",
73 "80",
74 "/file",
75 "?search",
76 "#hash"
79 "FTP",
80 "ftp://ftp.winehq.org/",
81 "ftp://ftp.winehq.org/",
82 "ftp:",
83 "ftp.winehq.org:21",
84 "ftp.winehq.org",
85 "21",
86 "/",
87 NULL,
88 NULL
91 "FTP with file",
92 "ftp://ftp.winehq.org/file",
93 "ftp://ftp.winehq.org/file",
94 "ftp:",
95 "ftp.winehq.org:21",
96 "ftp.winehq.org",
97 "21",
98 "/file",
99 NULL,
100 NULL
104 static int str_eq_wa(LPCWSTR strw, const char *stra)
106 CHAR buf[512];
108 if(!strw || !stra)
109 return (void*)strw == (void*)stra;
111 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
112 return !lstrcmpA(stra, buf);
115 static void test_href(IHTMLLocation *loc, const struct location_test *test)
117 HRESULT hres;
118 BSTR str;
120 hres = IHTMLLocation_get_href(loc, NULL);
121 ok(hres == E_POINTER,
122 "%s: get_href should have failed with E_POINTER (0x%08lx), was: 0x%08lx\n",
123 test->name, E_POINTER, hres);
125 hres = IHTMLLocation_get_href(loc, &str);
126 ok(hres == S_OK, "%s: get_href failed: 0x%08lx\n", test->name, hres);
127 if(hres == S_OK)
128 ok(str_eq_wa(str, test->href),
129 "%s: expected retrieved href to be L\"%s\", was: %s\n",
130 test->name, test->href, wine_dbgstr_w(str));
131 SysFreeString(str);
133 hres = IHTMLLocation_toString(loc, &str);
134 ok(hres == S_OK, "%s: toString failed: 0x%08lx\n", test->name, hres);
135 ok(str_eq_wa(str, test->href), "%s: toString returned %s, expected %s\n",
136 test->name, wine_dbgstr_w(str), test->href);
137 SysFreeString(str);
140 static void test_protocol(IHTMLLocation *loc, const struct location_test *test)
142 HRESULT hres;
143 BSTR str;
145 hres = IHTMLLocation_get_protocol(loc, NULL);
146 ok(hres == E_POINTER,
147 "%s: get_protocol should have failed with E_POINTER (0x%08lx), was: 0x%08lx\n",
148 test->name, E_POINTER, hres);
150 hres = IHTMLLocation_get_protocol(loc, &str);
151 ok(hres == S_OK, "%s: get_protocol failed: 0x%08lx\n", test->name, hres);
152 if(hres == S_OK)
153 ok(str_eq_wa(str, test->protocol),
154 "%s: expected retrieved protocol to be L\"%s\", was: %s\n",
155 test->name, test->protocol, wine_dbgstr_w(str));
156 SysFreeString(str);
159 static void test_host(IHTMLLocation *loc, const struct location_test *test)
161 HRESULT hres;
162 BSTR str;
164 hres = IHTMLLocation_get_host(loc, NULL);
165 ok(hres == E_POINTER,
166 "%s: get_host should have failed with E_POINTER (0x%08lx), was: 0x%08lx\n",
167 test->name, E_POINTER, hres);
169 hres = IHTMLLocation_get_host(loc, &str);
170 ok(hres == S_OK, "%s: get_host failed: 0x%08lx\n", test->name, hres);
171 if(hres == S_OK){
172 int len = test->host ? strlen(test->host) : 0;
173 ok(str_eq_wa(str, test->host),
174 "%s: expected retrieved host to be L\"%s\", was: %s\n",
175 test->name, test->host, wine_dbgstr_w(str));
176 ok(SysStringLen(str) == len, "%s: unexpected string length %u, expected %u\n",
177 test->name, SysStringLen(str), len);
180 SysFreeString(str);
183 static void test_hostname(IHTMLLocation *loc, IHTMLDocument2 *doc, const struct location_test *test)
185 HRESULT hres;
186 BSTR str;
188 hres = IHTMLLocation_get_hostname(loc, NULL);
189 ok(hres == E_POINTER,
190 "%s: get_hostname should have failed with E_POINTER (0x%08lx), was: 0x%08lx\n",
191 test->name, E_POINTER, hres);
193 hres = IHTMLLocation_get_hostname(loc, &str);
194 ok(hres == S_OK, "%s: get_hostname failed: 0x%08lx\n", test->name, hres);
195 if(hres == S_OK)
196 ok(str_eq_wa(str, test->hostname),
197 "%s: expected retrieved hostname to be L\"%s\", was: %s\n",
198 test->name, test->hostname, wine_dbgstr_w(str));
199 SysFreeString(str);
201 hres = IHTMLDocument2_get_domain(doc, &str);
202 ok(hres == (test->url ? S_OK : E_FAIL), "%s: get_domain failed: 0x%08lx\n", test->name, hres);
203 if(hres == S_OK)
204 ok(str_eq_wa(str, test->hostname ? test->hostname : ""),
205 "%s: expected retrieved domain to be L\"%s\", was: %s\n",
206 test->name, test->hostname, wine_dbgstr_w(str));
207 SysFreeString(str);
210 static void test_port(IHTMLLocation *loc, const struct location_test *test)
212 HRESULT hres;
213 BSTR str;
215 hres = IHTMLLocation_get_port(loc, NULL);
216 ok(hres == E_POINTER,
217 "%s: get_port should have failed with E_POINTER (0x%08lx), was: 0x%08lx\n",
218 test->name, E_POINTER, hres);
220 hres = IHTMLLocation_get_port(loc, &str);
221 ok(hres == S_OK, "%s: get_port failed: 0x%08lx\n", test->name, hres);
222 if(hres == S_OK)
223 ok(str_eq_wa(str, test->port)
224 || (!str && !*test->port), /* IE11 */
225 "%s: expected retrieved port to be L\"%s\", was: %s\n",
226 test->name, test->port, wine_dbgstr_w(str));
227 SysFreeString(str);
230 static void test_pathname(IHTMLLocation *loc, const struct location_test *test)
232 HRESULT hres;
233 BSTR str;
235 hres = IHTMLLocation_get_pathname(loc, NULL);
236 ok(hres == E_POINTER,
237 "%s: get_pathname should have failed with E_POINTER (0x%08lx), was: 0x%08lx\n",
238 test->name, E_POINTER, hres);
240 hres = IHTMLLocation_get_pathname(loc, &str);
241 ok(hres == S_OK, "%s: get_pathname failed: 0x%08lx\n", test->name, hres);
242 if(hres == S_OK)
243 /* FIXME: We seem to be testing location in a buggy state. Path names do not
244 * include leading slash, while other tests confirm that it should be there */
245 todo_wine_if(*test->pathname == '/')
246 ok(str_eq_wa(str, *test->pathname == '/' ? test->pathname + 1 : test->pathname),
247 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
248 test->name, test->pathname, wine_dbgstr_w(str));
249 SysFreeString(str);
252 static void test_search(IHTMLLocation *loc, const struct location_test *test)
254 HRESULT hres;
255 BSTR str;
257 hres = IHTMLLocation_get_search(loc, NULL);
258 ok(hres == E_POINTER,
259 "%s: get_search should have failed with E_POINTER (0x%08lx), was: 0x%08lx\n",
260 test->name, E_POINTER, hres);
262 hres = IHTMLLocation_get_search(loc, &str);
263 ok(hres == S_OK, "%s: get_search failed: 0x%08lx\n", test->name, hres);
264 if(hres == S_OK)
265 ok(str_eq_wa(str, test->search),
266 "%s: expected retrieved search to be L\"%s\", was: %s\n",
267 test->name, test->search, wine_dbgstr_w(str));
268 SysFreeString(str);
271 static void test_hash(IHTMLLocation *loc, const struct location_test *test)
273 HRESULT hres;
274 BSTR str;
276 hres = IHTMLLocation_get_hash(loc, NULL);
277 ok(hres == E_POINTER,
278 "%s: get_hash should have failed with E_POINTER (0x%08lx), was: 0x%08lx\n",
279 test->name, E_POINTER, hres);
281 hres = IHTMLLocation_get_hash(loc, &str);
282 ok(hres == S_OK, "%s: get_hash failed: 0x%08lx\n", test->name, hres);
283 if(hres == S_OK)
284 ok(str_eq_wa(str, test->hash),
285 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
286 test->name, test->hash, wine_dbgstr_w(str));
287 SysFreeString(str);
290 static void perform_test(const struct location_test* test)
292 WCHAR url[INTERNET_MAX_URL_LENGTH];
293 HRESULT hres;
294 IBindCtx *bc;
295 IMoniker *url_mon = NULL;
296 IPersistMoniker *persist_mon;
297 IHTMLDocument2 *doc;
298 IHTMLDocument6 *doc6;
299 IHTMLLocation *location;
301 hres = CreateBindCtx(0, &bc);
302 ok(hres == S_OK, "%s: CreateBindCtx failed: 0x%08lx\n", test->name, hres);
303 if(FAILED(hres))
304 return;
306 if(test->url) {
307 MultiByteToWideChar(CP_ACP, 0, test->url, -1, url, ARRAY_SIZE(url));
308 hres = CreateURLMoniker(NULL, url, &url_mon);
309 ok(hres == S_OK, "%s: CreateURLMoniker failed: 0x%08lx\n", test->name, hres);
310 if(FAILED(hres)){
311 IBindCtx_Release(bc);
312 return;
316 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
317 CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, &IID_IHTMLDocument2,
318 (void**)&doc);
319 #if !defined(__i386__) && !defined(__x86_64__)
320 todo_wine
321 #endif
322 ok(hres == S_OK, "%s: CoCreateInstance failed: 0x%08lx\n", test->name, hres);
323 if(FAILED(hres)){
324 if(url_mon) IMoniker_Release(url_mon);
325 IBindCtx_Release(bc);
326 return;
329 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument6, (void**)&doc6);
330 if(hres == S_OK){
331 IHTMLDocument6_Release(doc6);
332 }else{
333 win_skip("%s: Could not get IHTMLDocument6, probably too old IE. Requires IE 8+\n", test->name);
334 if(url_mon) IMoniker_Release(url_mon);
335 IBindCtx_Release(bc);
336 return;
339 if(url_mon) {
340 hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker,
341 (void**)&persist_mon);
342 ok(hres == S_OK, "%s: IHTMlDocument2_QueryInterface failed: 0x%08lx\n", test->name, hres);
343 if(FAILED(hres)){
344 IHTMLDocument2_Release(doc);
345 IMoniker_Release(url_mon);
346 IBindCtx_Release(bc);
347 return;
350 hres = IPersistMoniker_Load(persist_mon, FALSE, url_mon, bc,
351 STGM_SHARE_EXCLUSIVE | STGM_READWRITE);
352 ok(hres == S_OK, "%s: IPersistMoniker_Load failed: 0x%08lx\n", test->name, hres);
353 IPersistMoniker_Release(persist_mon);
354 IMoniker_Release(url_mon);
356 if(FAILED(hres)){
357 IHTMLDocument2_Release(doc);
358 IBindCtx_Release(bc);
359 return;
363 hres = IHTMLDocument2_get_location(doc, &location);
364 ok(hres == S_OK, "%s: IHTMLDocument2_get_location failed: 0x%08lx\n", test->name, hres);
365 if(FAILED(hres)){
366 IHTMLDocument2_Release(doc);
367 IBindCtx_Release(bc);
368 return;
371 test_href(location, test);
372 test_protocol(location, test);
373 test_host(location, test);
374 test_hostname(location, doc, test);
375 test_port(location, test);
376 test_pathname(location, test);
377 test_search(location, test);
378 test_hash(location, test);
380 IHTMLLocation_Release(location);
381 IHTMLDocument2_Release(doc);
382 IBindCtx_Release(bc);
385 START_TEST(htmllocation)
387 int i;
389 CoInitialize(NULL);
391 for(i=0; i < ARRAY_SIZE(location_tests); i++)
392 perform_test(location_tests+i);
394 CoUninitialize();