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
[] = {
44 "http://www.winehq.org?search#hash",
45 "http://www.winehq.org/?search#hash",
56 "http://www.winehq.org/file?search#hash",
57 "http://www.winehq.org/file?search#hash",
68 "ftp://ftp.winehq.org/",
69 "ftp://ftp.winehq.org/",
80 "ftp://ftp.winehq.org/file",
81 "ftp://ftp.winehq.org/file",
92 static int str_eq_wa(LPCWSTR strw
, const char *stra
)
97 return (void*)strw
== (void*)stra
;
99 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
100 return !lstrcmpA(stra
, buf
);
103 static void test_href(IHTMLLocation
*loc
, const struct location_test
*test
)
108 hres
= IHTMLLocation_get_href(loc
, NULL
);
109 ok(hres
== E_POINTER
,
110 "%s: get_href should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
111 test
->name
, E_POINTER
, hres
);
113 hres
= IHTMLLocation_get_href(loc
, &str
);
114 ok(hres
== S_OK
, "%s: get_href failed: 0x%08x\n", test
->name
, hres
);
116 ok(str_eq_wa(str
, test
->href
),
117 "%s: expected retrieved href to be L\"%s\", was: %s\n",
118 test
->name
, test
->href
, wine_dbgstr_w(str
));
121 hres
= IHTMLLocation_toString(loc
, &str
);
122 ok(hres
== S_OK
, "%s: toString failed: 0x%08x\n", test
->name
, hres
);
123 ok(str_eq_wa(str
, test
->href
), "%s: toString returned %s, expected %s\n",
124 test
->name
, wine_dbgstr_w(str
), test
->href
);
128 static void test_protocol(IHTMLLocation
*loc
, const struct location_test
*test
)
133 hres
= IHTMLLocation_get_protocol(loc
, NULL
);
134 ok(hres
== E_POINTER
,
135 "%s: get_protocol should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
136 test
->name
, E_POINTER
, hres
);
138 hres
= IHTMLLocation_get_protocol(loc
, &str
);
139 ok(hres
== S_OK
, "%s: get_protocol failed: 0x%08x\n", test
->name
, hres
);
141 ok(str_eq_wa(str
, test
->protocol
),
142 "%s: expected retrieved protocol to be L\"%s\", was: %s\n",
143 test
->name
, test
->protocol
, wine_dbgstr_w(str
));
147 static void test_host(IHTMLLocation
*loc
, const struct location_test
*test
)
152 hres
= IHTMLLocation_get_host(loc
, NULL
);
153 ok(hres
== E_POINTER
,
154 "%s: get_host should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
155 test
->name
, E_POINTER
, hres
);
157 hres
= IHTMLLocation_get_host(loc
, &str
);
158 ok(hres
== S_OK
, "%s: get_host failed: 0x%08x\n", test
->name
, hres
);
160 int len
= test
->host
? strlen(test
->host
) : 0;
161 ok(str_eq_wa(str
, test
->host
),
162 "%s: expected retrieved host to be L\"%s\", was: %s\n",
163 test
->name
, test
->host
, wine_dbgstr_w(str
));
164 ok(SysStringLen(str
) == len
, "%s: unexpected string length %u, expected %u\n",
165 test
->name
, SysStringLen(str
), len
);
171 static void test_hostname(IHTMLLocation
*loc
, IHTMLDocument2
*doc
, const struct location_test
*test
)
176 hres
= IHTMLLocation_get_hostname(loc
, NULL
);
177 ok(hres
== E_POINTER
,
178 "%s: get_hostname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
179 test
->name
, E_POINTER
, hres
);
181 hres
= IHTMLLocation_get_hostname(loc
, &str
);
182 ok(hres
== S_OK
, "%s: get_hostname failed: 0x%08x\n", test
->name
, hres
);
184 ok(str_eq_wa(str
, test
->hostname
),
185 "%s: expected retrieved hostname to be L\"%s\", was: %s\n",
186 test
->name
, test
->hostname
, wine_dbgstr_w(str
));
189 hres
= IHTMLDocument2_get_domain(doc
, &str
);
190 ok(hres
== S_OK
, "%s: get_domain failed: 0x%08x\n", test
->name
, hres
);
192 ok(str_eq_wa(str
, test
->hostname
? test
->hostname
: ""),
193 "%s: expected retrieved domain to be L\"%s\", was: %s\n",
194 test
->name
, test
->hostname
, wine_dbgstr_w(str
));
198 static void test_port(IHTMLLocation
*loc
, const struct location_test
*test
)
203 hres
= IHTMLLocation_get_port(loc
, NULL
);
204 ok(hres
== E_POINTER
,
205 "%s: get_port should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
206 test
->name
, E_POINTER
, hres
);
208 hres
= IHTMLLocation_get_port(loc
, &str
);
209 ok(hres
== S_OK
, "%s: get_port failed: 0x%08x\n", test
->name
, hres
);
211 ok(str_eq_wa(str
, test
->port
)
212 || (!str
&& !*test
->port
), /* IE11 */
213 "%s: expected retrieved port to be L\"%s\", was: %s\n",
214 test
->name
, test
->port
, wine_dbgstr_w(str
));
218 static void test_pathname(IHTMLLocation
*loc
, const struct location_test
*test
)
223 hres
= IHTMLLocation_get_pathname(loc
, NULL
);
224 ok(hres
== E_POINTER
,
225 "%s: get_pathname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
226 test
->name
, E_POINTER
, hres
);
228 hres
= IHTMLLocation_get_pathname(loc
, &str
);
229 ok(hres
== S_OK
, "%s: get_pathname failed: 0x%08x\n", test
->name
, hres
);
231 /* FIXME: We seem to be testing location in a buggy state. Path names do not
232 * include leading slash, while other tests confirm that it should be there */
233 todo_wine_if(*test
->pathname
== '/')
234 ok(str_eq_wa(str
, *test
->pathname
== '/' ? test
->pathname
+ 1 : test
->pathname
),
235 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
236 test
->name
, test
->pathname
, wine_dbgstr_w(str
));
240 static void test_search(IHTMLLocation
*loc
, const struct location_test
*test
)
245 hres
= IHTMLLocation_get_search(loc
, NULL
);
246 ok(hres
== E_POINTER
,
247 "%s: get_search should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
248 test
->name
, E_POINTER
, hres
);
250 hres
= IHTMLLocation_get_search(loc
, &str
);
251 ok(hres
== S_OK
, "%s: get_search failed: 0x%08x\n", test
->name
, hres
);
253 ok(str_eq_wa(str
, test
->search
),
254 "%s: expected retrieved search to be L\"%s\", was: %s\n",
255 test
->name
, test
->search
, wine_dbgstr_w(str
));
259 static void test_hash(IHTMLLocation
*loc
, const struct location_test
*test
)
264 hres
= IHTMLLocation_get_hash(loc
, NULL
);
265 ok(hres
== E_POINTER
,
266 "%s: get_hash should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
267 test
->name
, E_POINTER
, hres
);
269 hres
= IHTMLLocation_get_hash(loc
, &str
);
270 ok(hres
== S_OK
, "%s: get_hash failed: 0x%08x\n", test
->name
, hres
);
272 ok(str_eq_wa(str
, test
->hash
),
273 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
274 test
->name
, test
->hash
, wine_dbgstr_w(str
));
278 static void perform_test(const struct location_test
* test
)
280 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
284 IPersistMoniker
*persist_mon
;
286 IHTMLDocument6
*doc6
;
287 IHTMLLocation
*location
;
289 hres
= CreateBindCtx(0, &bc
);
290 ok(hres
== S_OK
, "%s: CreateBindCtx failed: 0x%08x\n", test
->name
, hres
);
294 MultiByteToWideChar(CP_ACP
, 0, test
->url
, -1, url
, ARRAY_SIZE(url
));
295 hres
= CreateURLMoniker(NULL
, url
, &url_mon
);
296 ok(hres
== S_OK
, "%s: CreateURLMoniker failed: 0x%08x\n", test
->name
, hres
);
298 IBindCtx_Release(bc
);
302 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
,
303 CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
, &IID_IHTMLDocument2
,
305 #if !defined(__i386__) && !defined(__x86_64__)
308 ok(hres
== S_OK
, "%s: CoCreateInstance failed: 0x%08x\n", test
->name
, hres
);
310 IMoniker_Release(url_mon
);
311 IBindCtx_Release(bc
);
315 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument6
, (void**)&doc6
);
317 IHTMLDocument6_Release(doc6
);
319 win_skip("%s: Could not get IHTMLDocument6, probably too old IE. Requires IE 8+\n", test
->name
);
320 IMoniker_Release(url_mon
);
321 IBindCtx_Release(bc
);
325 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IPersistMoniker
,
326 (void**)&persist_mon
);
327 ok(hres
== S_OK
, "%s: IHTMlDocument2_QueryInterface failed: 0x%08x\n", test
->name
, hres
);
329 IHTMLDocument2_Release(doc
);
330 IMoniker_Release(url_mon
);
331 IBindCtx_Release(bc
);
335 hres
= IPersistMoniker_Load(persist_mon
, FALSE
, url_mon
, bc
,
336 STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
);
337 ok(hres
== S_OK
, "%s: IPersistMoniker_Load failed: 0x%08x\n", test
->name
, hres
);
339 IPersistMoniker_Release(persist_mon
);
340 IHTMLDocument2_Release(doc
);
341 IMoniker_Release(url_mon
);
342 IBindCtx_Release(bc
);
346 hres
= IHTMLDocument2_get_location(doc
, &location
);
347 ok(hres
== S_OK
, "%s: IHTMLDocument2_get_location failed: 0x%08x\n", test
->name
, hres
);
349 IPersistMoniker_Release(persist_mon
);
350 IHTMLDocument2_Release(doc
);
351 IMoniker_Release(url_mon
);
352 IBindCtx_Release(bc
);
356 test_href(location
, test
);
357 test_protocol(location
, test
);
358 test_host(location
, test
);
359 test_hostname(location
, doc
, test
);
360 test_port(location
, test
);
361 test_pathname(location
, test
);
362 test_search(location
, test
);
363 test_hash(location
, test
);
365 IHTMLLocation_Release(location
);
366 IPersistMoniker_Release(persist_mon
);
367 IHTMLDocument2_Release(doc
);
368 IMoniker_Release(url_mon
);
369 IBindCtx_Release(bc
);
372 START_TEST(htmllocation
)
378 for(i
=0; i
< ARRAY_SIZE(location_tests
); i
++)
379 perform_test(location_tests
+i
);