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
22 #include <wine/test.h>
27 struct location_test
{
41 static const struct location_test location_tests
[] = {
56 "http://www.winehq.org?search#hash",
57 "http://www.winehq.org/?search#hash",
68 "http://www.winehq.org/file?search#hash",
69 "http://www.winehq.org/file?search#hash",
80 "ftp://ftp.winehq.org/",
81 "ftp://ftp.winehq.org/",
92 "ftp://ftp.winehq.org/file",
93 "ftp://ftp.winehq.org/file",
104 static int str_eq_wa(LPCWSTR strw
, const char *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
)
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
);
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
));
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
);
140 static void test_protocol(IHTMLLocation
*loc
, const struct location_test
*test
)
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
);
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
));
159 static void test_host(IHTMLLocation
*loc
, const struct location_test
*test
)
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
);
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
);
183 static void test_hostname(IHTMLLocation
*loc
, IHTMLDocument2
*doc
, const struct location_test
*test
)
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
);
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
));
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
);
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
));
210 static void test_port(IHTMLLocation
*loc
, const struct location_test
*test
)
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
);
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
));
230 static void test_pathname(IHTMLLocation
*loc
, const struct location_test
*test
)
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
);
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
));
252 static void test_search(IHTMLLocation
*loc
, const struct location_test
*test
)
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
);
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
));
271 static void test_hash(IHTMLLocation
*loc
, const struct location_test
*test
)
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
);
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
));
290 static void perform_test(const struct location_test
* test
)
292 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
295 IMoniker
*url_mon
= NULL
;
296 IPersistMoniker
*persist_mon
;
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
);
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
);
311 IBindCtx_Release(bc
);
316 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
,
317 CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
, &IID_IHTMLDocument2
,
319 #if !defined(__i386__) && !defined(__x86_64__)
322 ok(hres
== S_OK
, "%s: CoCreateInstance failed: 0x%08lx\n", test
->name
, hres
);
324 if(url_mon
) IMoniker_Release(url_mon
);
325 IBindCtx_Release(bc
);
329 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument6
, (void**)&doc6
);
331 IHTMLDocument6_Release(doc6
);
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
);
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
);
344 IHTMLDocument2_Release(doc
);
345 IMoniker_Release(url_mon
);
346 IBindCtx_Release(bc
);
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
);
357 IHTMLDocument2_Release(doc
);
358 IBindCtx_Release(bc
);
363 hres
= IHTMLDocument2_get_location(doc
, &location
);
364 ok(hres
== S_OK
, "%s: IHTMLDocument2_get_location failed: 0x%08lx\n", test
->name
, hres
);
366 IHTMLDocument2_Release(doc
);
367 IBindCtx_Release(bc
);
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
)
391 for(i
=0; i
< ARRAY_SIZE(location_tests
); i
++)
392 perform_test(location_tests
+i
);