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
)
110 if(strw
== NULL
|| stra
== NULL
){
111 if((void*)strw
== (void*)stra
)
116 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
117 return !lstrcmpA(stra
, buf
);
120 static void test_href(IHTMLLocation
*loc
, const struct location_test
*test
)
125 hres
= IHTMLLocation_get_href(loc
, NULL
);
126 ok(hres
== E_POINTER
,
127 "%s: get_href should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
128 test
->name
, E_POINTER
, hres
);
130 hres
= IHTMLLocation_get_href(loc
, &str
);
131 ok(hres
== S_OK
, "%s: get_href failed: 0x%08x\n", test
->name
, hres
);
133 ok(str_eq_wa(str
, test
->href
),
134 "%s: expected retrieved href to be L\"%s\", was: %s\n",
135 test
->name
, test
->href
, wine_dbgstr_w(str
));
138 static void test_protocol(IHTMLLocation
*loc
, const struct location_test
*test
)
143 hres
= IHTMLLocation_get_protocol(loc
, NULL
);
144 ok(hres
== E_POINTER
,
145 "%s: get_protocol should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
146 test
->name
, E_POINTER
, hres
);
148 hres
= IHTMLLocation_get_protocol(loc
, &str
);
149 ok(hres
== S_OK
, "%s: get_protocol failed: 0x%08x\n", test
->name
, hres
);
151 ok(str_eq_wa(str
, test
->protocol
),
152 "%s: expected retrieved protocol to be L\"%s\", was: %s\n",
153 test
->name
, test
->protocol
, wine_dbgstr_w(str
));
156 static void test_host(IHTMLLocation
*loc
, const struct location_test
*test
)
161 hres
= IHTMLLocation_get_host(loc
, NULL
);
162 ok(hres
== E_POINTER
,
163 "%s: get_host should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
164 test
->name
, E_POINTER
, hres
);
166 hres
= IHTMLLocation_get_host(loc
, &str
);
167 ok(hres
== S_OK
, "%s: get_host failed: 0x%08x\n", test
->name
, hres
);
169 ok(str_eq_wa(str
, test
->host
),
170 "%s: expected retrieved host to be L\"%s\", was: %s\n",
171 test
->name
, test
->host
, wine_dbgstr_w(str
));
174 static void test_hostname(IHTMLLocation
*loc
, const struct location_test
*test
)
179 hres
= IHTMLLocation_get_hostname(loc
, NULL
);
180 ok(hres
== E_POINTER
,
181 "%s: get_hostname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
182 test
->name
, E_POINTER
, hres
);
184 hres
= IHTMLLocation_get_hostname(loc
, &str
);
185 ok(hres
== S_OK
, "%s: get_hostname failed: 0x%08x\n", test
->name
, hres
);
187 ok(str_eq_wa(str
, test
->hostname
),
188 "%s: expected retrieved hostname to be L\"%s\", was: %s\n",
189 test
->name
, test
->hostname
, wine_dbgstr_w(str
));
192 static void test_port(IHTMLLocation
*loc
, const struct location_test
*test
)
197 hres
= IHTMLLocation_get_port(loc
, NULL
);
198 ok(hres
== E_POINTER
,
199 "%s: get_port should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
200 test
->name
, E_POINTER
, hres
);
202 hres
= IHTMLLocation_get_port(loc
, &str
);
203 ok(hres
== S_OK
, "%s: get_port failed: 0x%08x\n", test
->name
, hres
);
205 ok(str_eq_wa(str
, test
->port
),
206 "%s: expected retrieved port to be L\"%s\", was: %s\n",
207 test
->name
, test
->port
, wine_dbgstr_w(str
));
210 static void test_pathname(IHTMLLocation
*loc
, const struct location_test
*test
)
215 hres
= IHTMLLocation_get_pathname(loc
, NULL
);
216 ok(hres
== E_POINTER
,
217 "%s: get_pathname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
218 test
->name
, E_POINTER
, hres
);
220 hres
= IHTMLLocation_get_pathname(loc
, &str
);
221 ok(hres
== S_OK
, "%s: get_pathname failed: 0x%08x\n", test
->name
, hres
);
223 ok(str_eq_wa(str
, test
->pathname
),
224 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
225 test
->name
, test
->pathname
, wine_dbgstr_w(str
));
228 static void test_search(IHTMLLocation
*loc
, const struct location_test
*test
)
233 hres
= IHTMLLocation_get_search(loc
, NULL
);
234 ok(hres
== E_POINTER
,
235 "%s: get_search should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
236 test
->name
, E_POINTER
, hres
);
238 hres
= IHTMLLocation_get_search(loc
, &str
);
239 ok(hres
== S_OK
, "%s: get_search failed: 0x%08x\n", test
->name
, hres
);
241 ok(str_eq_wa(str
, test
->search
),
242 "%s: expected retrieved search to be L\"%s\", was: %s\n",
243 test
->name
, test
->search
, wine_dbgstr_w(str
));
246 static void test_hash(IHTMLLocation
*loc
, const struct location_test
*test
)
251 hres
= IHTMLLocation_get_hash(loc
, NULL
);
252 ok(hres
== E_POINTER
,
253 "%s: get_hash should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
254 test
->name
, E_POINTER
, hres
);
256 hres
= IHTMLLocation_get_hash(loc
, &str
);
257 ok(hres
== S_OK
, "%s: get_hash failed: 0x%08x\n", test
->name
, hres
);
259 ok(str_eq_wa(str
, test
->hash
),
260 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
261 test
->name
, test
->hash
, wine_dbgstr_w(str
));
264 static void perform_test(const struct location_test
* test
)
266 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
270 IPersistMoniker
*persist_mon
;
272 IHTMLDocument6
*doc6
;
273 IHTMLLocation
*location
;
275 hres
= CreateBindCtx(0, &bc
);
276 ok(hres
== S_OK
, "%s: CreateBindCtx failed: 0x%08x\n", test
->name
, hres
);
280 MultiByteToWideChar(CP_ACP
, 0, test
->url
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
281 hres
= CreateURLMoniker(NULL
, url
, &url_mon
);
282 ok(hres
== S_OK
, "%s: CreateURLMoniker failed: 0x%08x\n", test
->name
, hres
);
284 IBindCtx_Release(bc
);
288 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
,
289 CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
, &IID_IHTMLDocument2
,
291 ok(hres
== S_OK
, "%s: CoCreateInstance failed: 0x%08x\n", test
->name
, hres
);
293 IMoniker_Release(url_mon
);
294 IBindCtx_Release(bc
);
298 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument6
, (void**)&doc6
);
300 IHTMLDocument6_Release(doc6
);
302 win_skip("%s: Could not get IHTMLDocument6, probably too old IE. Requires IE 8+\n", test
->name
);
303 IMoniker_Release(url_mon
);
304 IBindCtx_Release(bc
);
308 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IPersistMoniker
,
309 (void**)&persist_mon
);
310 ok(hres
== S_OK
, "%s: IHTMlDocument2_QueryInterface failed: 0x%08x\n", test
->name
, hres
);
312 IHTMLDocument2_Release(doc
);
313 IMoniker_Release(url_mon
);
314 IBindCtx_Release(bc
);
318 hres
= IPersistMoniker_Load(persist_mon
, FALSE
, url_mon
, bc
,
319 STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
);
320 ok(hres
== S_OK
, "%s: IPersistMoniker_Load failed: 0x%08x\n", test
->name
, hres
);
322 IPersistMoniker_Release(persist_mon
);
323 IHTMLDocument2_Release(doc
);
324 IMoniker_Release(url_mon
);
325 IBindCtx_Release(bc
);
329 hres
= IHTMLDocument2_get_location(doc
, &location
);
330 ok(hres
== S_OK
, "%s: IHTMLDocument2_get_location failed: 0x%08x\n", test
->name
, hres
);
332 IPersistMoniker_Release(persist_mon
);
333 IHTMLDocument2_Release(doc
);
334 IMoniker_Release(url_mon
);
335 IBindCtx_Release(bc
);
339 test_href(location
, test
);
340 test_protocol(location
, test
);
341 test_host(location
, test
);
342 test_hostname(location
, test
);
343 test_port(location
, test
);
344 test_pathname(location
, test
);
345 test_search(location
, test
);
346 test_hash(location
, test
);
348 IHTMLLocation_Release(location
);
349 IPersistMoniker_Release(persist_mon
);
350 IHTMLDocument2_Release(doc
);
351 IMoniker_Release(url_mon
);
352 IBindCtx_Release(bc
);
354 #endif /* ROSTESTS_81_IS_FIXED */
356 START_TEST(htmllocation
)
358 #if ROSTESTS_81_IS_FIXED
363 for(i
=0; i
< sizeof(location_tests
)/sizeof(*location_tests
); i
++)
364 perform_test(location_tests
+i
);
367 #endif /* ROSTESTS_81_IS_FIXED */