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 "file://C:\\windows\\win.ini",
93 "file:///C:/windows/win.ini",
98 "C:\\windows\\win.ini",
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%08x), was: 0x%08x\n",
123 test->name, E_POINTER, hres);
125 hres = IHTMLLocation_get_href(loc, &str);
126 ok(hres == S_OK, "%s: get_href failed: 0x%08x\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%08x\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%08x), was: 0x%08x\n",
148 test->name, E_POINTER, hres);
150 hres = IHTMLLocation_get_protocol(loc, &str);
151 ok(hres == S_OK, "%s: get_protocol failed: 0x%08x\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%08x), was: 0x%08x\n",
167 test->name, E_POINTER, hres);
169 hres = IHTMLLocation_get_host(loc, &str);
170 ok(hres == S_OK, "%s: get_host failed: 0x%08x\n", test->name, hres);
172 ok(str_eq_wa(str, test->host),
173 "%s: expected retrieved host to be L\"%s\", was: %s\n",
174 test->name, test->host, wine_dbgstr_w(str));
178 static void test_hostname(IHTMLLocation *loc, IHTMLDocument2 *doc, const struct location_test *test)
183 hres = IHTMLLocation_get_hostname(loc, NULL);
184 ok(hres == E_POINTER,
185 "%s: get_hostname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
186 test->name, E_POINTER, hres);
188 hres = IHTMLLocation_get_hostname(loc, &str);
189 ok(hres == S_OK, "%s: get_hostname failed: 0x%08x\n", test->name, hres);
191 ok(str_eq_wa(str, test->hostname),
192 "%s: expected retrieved hostname to be L\"%s\", was: %s\n",
193 test->name, test->hostname, wine_dbgstr_w(str));
196 hres = IHTMLDocument2_get_domain(doc, &str);
197 ok(hres == S_OK, "%s: get_domain failed: 0x%08x\n", test->name, hres);
199 ok(str_eq_wa(str, test->hostname ? test->hostname : ""),
200 "%s: expected retrieved domain to be L\"%s\", was: %s\n",
201 test->name, test->hostname, wine_dbgstr_w(str));
205 static void test_port(IHTMLLocation *loc, const struct location_test *test)
210 hres = IHTMLLocation_get_port(loc, NULL);
211 ok(hres == E_POINTER,
212 "%s: get_port should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
213 test->name, E_POINTER, hres);
215 hres = IHTMLLocation_get_port(loc, &str);
216 ok(hres == S_OK, "%s: get_port failed: 0x%08x\n", test->name, hres);
218 ok(str_eq_wa(str, test->port),
219 "%s: expected retrieved port to be L\"%s\", was: %s\n",
220 test->name, test->port, wine_dbgstr_w(str));
224 static void test_pathname(IHTMLLocation *loc, const struct location_test *test)
229 hres = IHTMLLocation_get_pathname(loc, NULL);
230 ok(hres == E_POINTER,
231 "%s: get_pathname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
232 test->name, E_POINTER, hres);
234 hres = IHTMLLocation_get_pathname(loc, &str);
235 ok(hres == S_OK, "%s: get_pathname failed: 0x%08x\n", test->name, hres);
237 ok(str_eq_wa(str, test->pathname),
238 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
239 test->name, test->pathname, wine_dbgstr_w(str));
243 static void test_search(IHTMLLocation *loc, const struct location_test *test)
248 hres = IHTMLLocation_get_search(loc, NULL);
249 ok(hres == E_POINTER,
250 "%s: get_search should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
251 test->name, E_POINTER, hres);
253 hres = IHTMLLocation_get_search(loc, &str);
254 ok(hres == S_OK, "%s: get_search failed: 0x%08x\n", test->name, hres);
256 ok(str_eq_wa(str, test->search),
257 "%s: expected retrieved search to be L\"%s\", was: %s\n",
258 test->name, test->search, wine_dbgstr_w(str));
262 static void test_hash(IHTMLLocation *loc, const struct location_test *test)
267 hres = IHTMLLocation_get_hash(loc, NULL);
268 ok(hres == E_POINTER,
269 "%s: get_hash should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
270 test->name, E_POINTER, hres);
272 hres = IHTMLLocation_get_hash(loc, &str);
273 ok(hres == S_OK, "%s: get_hash failed: 0x%08x\n", test->name, hres);
275 ok(str_eq_wa(str, test->hash),
276 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
277 test->name, test->hash, wine_dbgstr_w(str));
281 static void perform_test(const struct location_test* test)
283 WCHAR url[INTERNET_MAX_URL_LENGTH];
287 IPersistMoniker *persist_mon;
289 IHTMLDocument6 *doc6;
290 IHTMLLocation *location;
292 hres = CreateBindCtx(0, &bc);
293 ok(hres == S_OK, "%s: CreateBindCtx failed: 0x%08x\n", test->name, hres);
297 MultiByteToWideChar(CP_ACP, 0, test->url, -1, url, sizeof(url)/sizeof(WCHAR));
298 hres = CreateURLMoniker(NULL, url, &url_mon);
299 ok(hres == S_OK, "%s: CreateURLMoniker failed: 0x%08x\n", test->name, hres);
301 IBindCtx_Release(bc);
305 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
306 CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, &IID_IHTMLDocument2,
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 < sizeof(location_tests)/sizeof(*location_tests); i++)
379 perform_test(location_tests+i);