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
));
134 static void test_protocol(IHTMLLocation
*loc
, const struct location_test
*test
)
139 hres
= IHTMLLocation_get_protocol(loc
, NULL
);
140 ok(hres
== E_POINTER
,
141 "%s: get_protocol should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
142 test
->name
, E_POINTER
, hres
);
144 hres
= IHTMLLocation_get_protocol(loc
, &str
);
145 ok(hres
== S_OK
, "%s: get_protocol failed: 0x%08x\n", test
->name
, hres
);
147 ok(str_eq_wa(str
, test
->protocol
),
148 "%s: expected retrieved protocol to be L\"%s\", was: %s\n",
149 test
->name
, test
->protocol
, wine_dbgstr_w(str
));
153 static void test_host(IHTMLLocation
*loc
, const struct location_test
*test
)
158 hres
= IHTMLLocation_get_host(loc
, NULL
);
159 ok(hres
== E_POINTER
,
160 "%s: get_host should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
161 test
->name
, E_POINTER
, hres
);
163 hres
= IHTMLLocation_get_host(loc
, &str
);
164 ok(hres
== S_OK
, "%s: get_host failed: 0x%08x\n", test
->name
, hres
);
166 ok(str_eq_wa(str
, test
->host
),
167 "%s: expected retrieved host to be L\"%s\", was: %s\n",
168 test
->name
, test
->host
, wine_dbgstr_w(str
));
172 static void test_hostname(IHTMLLocation
*loc
, IHTMLDocument2
*doc
, const struct location_test
*test
)
177 hres
= IHTMLLocation_get_hostname(loc
, NULL
);
178 ok(hres
== E_POINTER
,
179 "%s: get_hostname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
180 test
->name
, E_POINTER
, hres
);
182 hres
= IHTMLLocation_get_hostname(loc
, &str
);
183 ok(hres
== S_OK
, "%s: get_hostname failed: 0x%08x\n", test
->name
, hres
);
185 ok(str_eq_wa(str
, test
->hostname
),
186 "%s: expected retrieved hostname to be L\"%s\", was: %s\n",
187 test
->name
, test
->hostname
, wine_dbgstr_w(str
));
190 hres
= IHTMLDocument2_get_domain(doc
, &str
);
191 ok(hres
== S_OK
, "%s: get_domain failed: 0x%08x\n", test
->name
, hres
);
193 ok(str_eq_wa(str
, test
->hostname
? test
->hostname
: ""),
194 "%s: expected retrieved domain to be L\"%s\", was: %s\n",
195 test
->name
, test
->hostname
, wine_dbgstr_w(str
));
199 static void test_port(IHTMLLocation
*loc
, const struct location_test
*test
)
204 hres
= IHTMLLocation_get_port(loc
, NULL
);
205 ok(hres
== E_POINTER
,
206 "%s: get_port should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
207 test
->name
, E_POINTER
, hres
);
209 hres
= IHTMLLocation_get_port(loc
, &str
);
210 ok(hres
== S_OK
, "%s: get_port failed: 0x%08x\n", test
->name
, hres
);
212 ok(str_eq_wa(str
, test
->port
),
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 ok(str_eq_wa(str
, test
->pathname
),
232 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
233 test
->name
, test
->pathname
, wine_dbgstr_w(str
));
237 static void test_search(IHTMLLocation
*loc
, const struct location_test
*test
)
242 hres
= IHTMLLocation_get_search(loc
, NULL
);
243 ok(hres
== E_POINTER
,
244 "%s: get_search should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
245 test
->name
, E_POINTER
, hres
);
247 hres
= IHTMLLocation_get_search(loc
, &str
);
248 ok(hres
== S_OK
, "%s: get_search failed: 0x%08x\n", test
->name
, hres
);
250 ok(str_eq_wa(str
, test
->search
),
251 "%s: expected retrieved search to be L\"%s\", was: %s\n",
252 test
->name
, test
->search
, wine_dbgstr_w(str
));
256 static void test_hash(IHTMLLocation
*loc
, const struct location_test
*test
)
261 hres
= IHTMLLocation_get_hash(loc
, NULL
);
262 ok(hres
== E_POINTER
,
263 "%s: get_hash should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
264 test
->name
, E_POINTER
, hres
);
266 hres
= IHTMLLocation_get_hash(loc
, &str
);
267 ok(hres
== S_OK
, "%s: get_hash failed: 0x%08x\n", test
->name
, hres
);
269 ok(str_eq_wa(str
, test
->hash
),
270 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
271 test
->name
, test
->hash
, wine_dbgstr_w(str
));
275 static void perform_test(const struct location_test
* test
)
277 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
281 IPersistMoniker
*persist_mon
;
283 IHTMLDocument6
*doc6
;
284 IHTMLLocation
*location
;
286 hres
= CreateBindCtx(0, &bc
);
287 ok(hres
== S_OK
, "%s: CreateBindCtx failed: 0x%08x\n", test
->name
, hres
);
291 MultiByteToWideChar(CP_ACP
, 0, test
->url
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
292 hres
= CreateURLMoniker(NULL
, url
, &url_mon
);
293 ok(hres
== S_OK
, "%s: CreateURLMoniker failed: 0x%08x\n", test
->name
, hres
);
295 IBindCtx_Release(bc
);
299 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
,
300 CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
, &IID_IHTMLDocument2
,
302 ok(hres
== S_OK
, "%s: CoCreateInstance failed: 0x%08x\n", test
->name
, hres
);
304 IMoniker_Release(url_mon
);
305 IBindCtx_Release(bc
);
309 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument6
, (void**)&doc6
);
311 IHTMLDocument6_Release(doc6
);
313 win_skip("%s: Could not get IHTMLDocument6, probably too old IE. Requires IE 8+\n", test
->name
);
314 IMoniker_Release(url_mon
);
315 IBindCtx_Release(bc
);
319 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IPersistMoniker
,
320 (void**)&persist_mon
);
321 ok(hres
== S_OK
, "%s: IHTMlDocument2_QueryInterface failed: 0x%08x\n", test
->name
, hres
);
323 IHTMLDocument2_Release(doc
);
324 IMoniker_Release(url_mon
);
325 IBindCtx_Release(bc
);
329 hres
= IPersistMoniker_Load(persist_mon
, FALSE
, url_mon
, bc
,
330 STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
);
331 ok(hres
== S_OK
, "%s: IPersistMoniker_Load failed: 0x%08x\n", test
->name
, hres
);
333 IPersistMoniker_Release(persist_mon
);
334 IHTMLDocument2_Release(doc
);
335 IMoniker_Release(url_mon
);
336 IBindCtx_Release(bc
);
340 hres
= IHTMLDocument2_get_location(doc
, &location
);
341 ok(hres
== S_OK
, "%s: IHTMLDocument2_get_location failed: 0x%08x\n", test
->name
, hres
);
343 IPersistMoniker_Release(persist_mon
);
344 IHTMLDocument2_Release(doc
);
345 IMoniker_Release(url_mon
);
346 IBindCtx_Release(bc
);
350 test_href(location
, test
);
351 test_protocol(location
, test
);
352 test_host(location
, test
);
353 test_hostname(location
, doc
, test
);
354 test_port(location
, test
);
355 test_pathname(location
, test
);
356 test_search(location
, test
);
357 test_hash(location
, test
);
359 IHTMLLocation_Release(location
);
360 IPersistMoniker_Release(persist_mon
);
361 IHTMLDocument2_Release(doc
);
362 IMoniker_Release(url_mon
);
363 IBindCtx_Release(bc
);
366 START_TEST(htmllocation
)
372 for(i
=0; i
< sizeof(location_tests
)/sizeof(*location_tests
); i
++)
373 perform_test(location_tests
+i
);