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>
24 #if ROSTESTS_81_IS_FIXED
29 struct location_test
{
43 static const struct location_test location_tests
[] = {
46 "http://www.winehq.org?search#hash",
47 "http://www.winehq.org/?search#hash",
58 "http://www.winehq.org/file?search#hash",
59 "http://www.winehq.org/file?search#hash",
70 "ftp://ftp.winehq.org/",
71 "ftp://ftp.winehq.org/",
82 "ftp://ftp.winehq.org/file",
83 "ftp://ftp.winehq.org/file",
94 "file://C:\\windows\\win.ini",
95 "file:///C:/windows/win.ini",
100 "C:\\windows\\win.ini",
106 static int str_eq_wa(LPCWSTR strw
, const char *stra
)
111 return (void*)strw
== (void*)stra
;
113 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
114 return !lstrcmpA(stra
, buf
);
117 static void test_href(IHTMLLocation
*loc
, const struct location_test
*test
)
122 hres
= IHTMLLocation_get_href(loc
, NULL
);
123 ok(hres
== E_POINTER
,
124 "%s: get_href should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
125 test
->name
, E_POINTER
, hres
);
127 hres
= IHTMLLocation_get_href(loc
, &str
);
128 ok(hres
== S_OK
, "%s: get_href failed: 0x%08x\n", test
->name
, hres
);
130 ok(str_eq_wa(str
, test
->href
),
131 "%s: expected retrieved href to be L\"%s\", was: %s\n",
132 test
->name
, test
->href
, wine_dbgstr_w(str
));
135 hres
= IHTMLLocation_toString(loc
, &str
);
136 ok(hres
== S_OK
, "%s: toString failed: 0x%08x\n", test
->name
, hres
);
137 ok(str_eq_wa(str
, test
->href
), "%s: toString returned %s, expected %s\n",
138 test
->name
, wine_dbgstr_w(str
), test
->href
);
142 static void test_protocol(IHTMLLocation
*loc
, const struct location_test
*test
)
147 hres
= IHTMLLocation_get_protocol(loc
, NULL
);
148 ok(hres
== E_POINTER
,
149 "%s: get_protocol should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
150 test
->name
, E_POINTER
, hres
);
152 hres
= IHTMLLocation_get_protocol(loc
, &str
);
153 ok(hres
== S_OK
, "%s: get_protocol failed: 0x%08x\n", test
->name
, hres
);
155 ok(str_eq_wa(str
, test
->protocol
),
156 "%s: expected retrieved protocol to be L\"%s\", was: %s\n",
157 test
->name
, test
->protocol
, wine_dbgstr_w(str
));
161 static void test_host(IHTMLLocation
*loc
, const struct location_test
*test
)
166 hres
= IHTMLLocation_get_host(loc
, NULL
);
167 ok(hres
== E_POINTER
,
168 "%s: get_host should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
169 test
->name
, E_POINTER
, hres
);
171 hres
= IHTMLLocation_get_host(loc
, &str
);
172 ok(hres
== S_OK
, "%s: get_host failed: 0x%08x\n", test
->name
, hres
);
174 ok(str_eq_wa(str
, test
->host
),
175 "%s: expected retrieved host to be L\"%s\", was: %s\n",
176 test
->name
, test
->host
, wine_dbgstr_w(str
));
180 static void test_hostname(IHTMLLocation
*loc
, IHTMLDocument2
*doc
, const struct location_test
*test
)
185 hres
= IHTMLLocation_get_hostname(loc
, NULL
);
186 ok(hres
== E_POINTER
,
187 "%s: get_hostname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
188 test
->name
, E_POINTER
, hres
);
190 hres
= IHTMLLocation_get_hostname(loc
, &str
);
191 ok(hres
== S_OK
, "%s: get_hostname failed: 0x%08x\n", test
->name
, hres
);
193 ok(str_eq_wa(str
, test
->hostname
),
194 "%s: expected retrieved hostname to be L\"%s\", was: %s\n",
195 test
->name
, test
->hostname
, wine_dbgstr_w(str
));
198 hres
= IHTMLDocument2_get_domain(doc
, &str
);
199 ok(hres
== S_OK
, "%s: get_domain failed: 0x%08x\n", test
->name
, hres
);
201 ok(str_eq_wa(str
, test
->hostname
? test
->hostname
: ""),
202 "%s: expected retrieved domain to be L\"%s\", was: %s\n",
203 test
->name
, test
->hostname
, wine_dbgstr_w(str
));
207 static void test_port(IHTMLLocation
*loc
, const struct location_test
*test
)
212 hres
= IHTMLLocation_get_port(loc
, NULL
);
213 ok(hres
== E_POINTER
,
214 "%s: get_port should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
215 test
->name
, E_POINTER
, hres
);
217 hres
= IHTMLLocation_get_port(loc
, &str
);
218 ok(hres
== S_OK
, "%s: get_port failed: 0x%08x\n", test
->name
, hres
);
220 ok(str_eq_wa(str
, test
->port
),
221 "%s: expected retrieved port to be L\"%s\", was: %s\n",
222 test
->name
, test
->port
, wine_dbgstr_w(str
));
226 static void test_pathname(IHTMLLocation
*loc
, const struct location_test
*test
)
231 hres
= IHTMLLocation_get_pathname(loc
, NULL
);
232 ok(hres
== E_POINTER
,
233 "%s: get_pathname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
234 test
->name
, E_POINTER
, hres
);
236 hres
= IHTMLLocation_get_pathname(loc
, &str
);
237 ok(hres
== S_OK
, "%s: get_pathname failed: 0x%08x\n", test
->name
, hres
);
239 ok(str_eq_wa(str
, test
->pathname
),
240 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
241 test
->name
, test
->pathname
, wine_dbgstr_w(str
));
245 static void test_search(IHTMLLocation
*loc
, const struct location_test
*test
)
250 hres
= IHTMLLocation_get_search(loc
, NULL
);
251 ok(hres
== E_POINTER
,
252 "%s: get_search should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
253 test
->name
, E_POINTER
, hres
);
255 hres
= IHTMLLocation_get_search(loc
, &str
);
256 ok(hres
== S_OK
, "%s: get_search failed: 0x%08x\n", test
->name
, hres
);
258 ok(str_eq_wa(str
, test
->search
),
259 "%s: expected retrieved search to be L\"%s\", was: %s\n",
260 test
->name
, test
->search
, wine_dbgstr_w(str
));
264 static void test_hash(IHTMLLocation
*loc
, const struct location_test
*test
)
269 hres
= IHTMLLocation_get_hash(loc
, NULL
);
270 ok(hres
== E_POINTER
,
271 "%s: get_hash should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
272 test
->name
, E_POINTER
, hres
);
274 hres
= IHTMLLocation_get_hash(loc
, &str
);
275 ok(hres
== S_OK
, "%s: get_hash failed: 0x%08x\n", test
->name
, hres
);
277 ok(str_eq_wa(str
, test
->hash
),
278 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
279 test
->name
, test
->hash
, wine_dbgstr_w(str
));
283 static void perform_test(const struct location_test
* test
)
285 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
289 IPersistMoniker
*persist_mon
;
291 IHTMLDocument6
*doc6
;
292 IHTMLLocation
*location
;
294 hres
= CreateBindCtx(0, &bc
);
295 ok(hres
== S_OK
, "%s: CreateBindCtx failed: 0x%08x\n", test
->name
, hres
);
299 MultiByteToWideChar(CP_ACP
, 0, test
->url
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
300 hres
= CreateURLMoniker(NULL
, url
, &url_mon
);
301 ok(hres
== S_OK
, "%s: CreateURLMoniker failed: 0x%08x\n", test
->name
, hres
);
303 IBindCtx_Release(bc
);
307 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
,
308 CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
, &IID_IHTMLDocument2
,
310 ok(hres
== S_OK
, "%s: CoCreateInstance failed: 0x%08x\n", test
->name
, hres
);
312 IMoniker_Release(url_mon
);
313 IBindCtx_Release(bc
);
317 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument6
, (void**)&doc6
);
319 IHTMLDocument6_Release(doc6
);
321 win_skip("%s: Could not get IHTMLDocument6, probably too old IE. Requires IE 8+\n", test
->name
);
322 IMoniker_Release(url_mon
);
323 IBindCtx_Release(bc
);
327 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IPersistMoniker
,
328 (void**)&persist_mon
);
329 ok(hres
== S_OK
, "%s: IHTMlDocument2_QueryInterface failed: 0x%08x\n", test
->name
, hres
);
331 IHTMLDocument2_Release(doc
);
332 IMoniker_Release(url_mon
);
333 IBindCtx_Release(bc
);
337 hres
= IPersistMoniker_Load(persist_mon
, FALSE
, url_mon
, bc
,
338 STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
);
339 ok(hres
== S_OK
, "%s: IPersistMoniker_Load failed: 0x%08x\n", test
->name
, hres
);
341 IPersistMoniker_Release(persist_mon
);
342 IHTMLDocument2_Release(doc
);
343 IMoniker_Release(url_mon
);
344 IBindCtx_Release(bc
);
348 hres
= IHTMLDocument2_get_location(doc
, &location
);
349 ok(hres
== S_OK
, "%s: IHTMLDocument2_get_location failed: 0x%08x\n", test
->name
, hres
);
351 IPersistMoniker_Release(persist_mon
);
352 IHTMLDocument2_Release(doc
);
353 IMoniker_Release(url_mon
);
354 IBindCtx_Release(bc
);
358 test_href(location
, test
);
359 test_protocol(location
, test
);
360 test_host(location
, test
);
361 test_hostname(location
, doc
, test
);
362 test_port(location
, test
);
363 test_pathname(location
, test
);
364 test_search(location
, test
);
365 test_hash(location
, test
);
367 IHTMLLocation_Release(location
);
368 IPersistMoniker_Release(persist_mon
);
369 IHTMLDocument2_Release(doc
);
370 IMoniker_Release(url_mon
);
371 IBindCtx_Release(bc
);
373 #endif /* ROSTESTS_81_IS_FIXED */
375 START_TEST(htmllocation
)
377 #if ROSTESTS_81_IS_FIXED
382 for(i
=0; i
< sizeof(location_tests
)/sizeof(*location_tests
); i
++)
383 perform_test(location_tests
+i
);
386 #endif /* ROSTESTS_81_IS_FIXED */