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>
26 struct location_test
{
34 const BOOL protocol_ok
;
40 const BOOL hostname_ok
;
46 const BOOL pathname_ok
;
55 static const WCHAR http_url
[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','?','s','e','a','r','c','h','#','h','a','s','h',0};
56 static const struct location_test http_test
= {
59 "http://www.winehq.org/?search#hash", FALSE
,
61 "www.winehq.org:80", TRUE
,
62 "www.winehq.org", TRUE
,
69 static const WCHAR http_file_url
[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','f','i','l','e','?','s','e','a','r','c','h','#','h','a','s','h',0};
70 static const struct location_test http_file_test
= {
73 "http://www.winehq.org/file?search#hash", TRUE
,
75 "www.winehq.org:80", TRUE
,
76 "www.winehq.org", TRUE
,
83 static const WCHAR ftp_url
[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g','/',0};
84 static const struct location_test ftp_test
= {
87 "ftp://ftp.winehq.org/", TRUE
,
89 "ftp.winehq.org:21", TRUE
,
90 "ftp.winehq.org", TRUE
,
97 static const WCHAR ftp_file_url
[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g','/','f','i','l','e',0};
98 static const struct location_test ftp_file_test
= {
101 "ftp://ftp.winehq.org/file", TRUE
,
103 "ftp.winehq.org:21", TRUE
,
104 "ftp.winehq.org", TRUE
,
111 static const WCHAR file_url
[] = {'f','i','l','e',':','/','/','C',':','\\','w','i','n','d','o','w','s','\\','w','i','n','.','i','n','i',0};
112 static const struct location_test file_test
= {
115 "file:///C:/windows/win.ini", FALSE
,
120 "C:\\windows\\win.ini", TRUE
,
125 static int str_eq_wa(LPCWSTR strw
, const char *stra
)
129 if(strw
== NULL
|| stra
== NULL
){
130 if((void*)strw
== (void*)stra
)
135 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
136 return !lstrcmpA(stra
, buf
);
139 static void test_href(IHTMLLocation
*loc
, const struct location_test
*test
)
144 hres
= IHTMLLocation_get_href(loc
, NULL
);
145 ok(hres
== E_POINTER
,
146 "%s: get_href should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
147 test
->name
, E_POINTER
, hres
);
149 hres
= IHTMLLocation_get_href(loc
, &str
);
150 ok(hres
== S_OK
, "%s: get_href failed: 0x%08x\n", test
->name
, hres
);
153 ok(str_eq_wa(str
, test
->href
),
154 "%s: expected retrieved href to be L\"%s\", was: %s\n",
155 test
->name
, test
->href
, wine_dbgstr_w(str
));
157 todo_wine
ok(str_eq_wa(str
, test
->href
),
158 "%s: expected retrieved href to be L\"%s\", was: %s\n",
159 test
->name
, test
->href
, wine_dbgstr_w(str
));
163 static void test_protocol(IHTMLLocation
*loc
, const struct location_test
*test
)
168 hres
= IHTMLLocation_get_protocol(loc
, NULL
);
169 ok(hres
== E_POINTER
,
170 "%s: get_protocol should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
171 test
->name
, E_POINTER
, hres
);
173 hres
= IHTMLLocation_get_protocol(loc
, &str
);
174 ok(hres
== S_OK
, "%s: get_protocol failed: 0x%08x\n", test
->name
, hres
);
176 if(test
->protocol_ok
)
177 ok(str_eq_wa(str
, test
->protocol
),
178 "%s: expected retrieved protocol to be L\"%s\", was: %s\n",
179 test
->name
, test
->protocol
, wine_dbgstr_w(str
));
181 todo_wine
ok(str_eq_wa(str
, test
->protocol
),
182 "%s: expected retrieved protocol to be L\"%s\", was: %s\n",
183 test
->name
, test
->protocol
, wine_dbgstr_w(str
));
187 static void test_host(IHTMLLocation
*loc
, const struct location_test
*test
)
192 hres
= IHTMLLocation_get_host(loc
, NULL
);
193 ok(hres
== E_POINTER
,
194 "%s: get_host should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
195 test
->name
, E_POINTER
, hres
);
197 hres
= IHTMLLocation_get_host(loc
, &str
);
198 ok(hres
== S_OK
, "%s: get_host failed: 0x%08x\n", test
->name
, hres
);
201 ok(str_eq_wa(str
, test
->host
),
202 "%s: expected retrieved host to be L\"%s\", was: %s\n",
203 test
->name
, test
->host
, wine_dbgstr_w(str
));
205 todo_wine
ok(str_eq_wa(str
, test
->host
),
206 "%s: expected retrieved host to be L\"%s\", was: %s\n",
207 test
->name
, test
->host
, wine_dbgstr_w(str
));
211 static void test_hostname(IHTMLLocation
*loc
, const struct location_test
*test
)
216 hres
= IHTMLLocation_get_hostname(loc
, NULL
);
217 ok(hres
== E_POINTER
,
218 "%s: get_hostname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
219 test
->name
, E_POINTER
, hres
);
221 hres
= IHTMLLocation_get_hostname(loc
, &str
);
222 ok(hres
== S_OK
, "%s: get_hostname failed: 0x%08x\n", test
->name
, hres
);
224 if(test
->hostname_ok
)
225 ok(str_eq_wa(str
, test
->hostname
),
226 "%s: expected retrieved hostname to be L\"%s\", was: %s\n",
227 test
->name
, test
->hostname
, wine_dbgstr_w(str
));
229 todo_wine
ok(str_eq_wa(str
, test
->hostname
),
230 "%s: expected retrieved hostname to be L\"%s\", was: %s\n",
231 test
->name
, test
->hostname
, wine_dbgstr_w(str
));
235 static void test_port(IHTMLLocation
*loc
, const struct location_test
*test
)
240 hres
= IHTMLLocation_get_port(loc
, NULL
);
241 ok(hres
== E_POINTER
,
242 "%s: get_port should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
243 test
->name
, E_POINTER
, hres
);
245 hres
= IHTMLLocation_get_port(loc
, &str
);
246 ok(hres
== S_OK
, "%s: get_port failed: 0x%08x\n", test
->name
, hres
);
249 ok(str_eq_wa(str
, test
->port
),
250 "%s: expected retrieved port to be L\"%s\", was: %s\n",
251 test
->name
, test
->port
, wine_dbgstr_w(str
));
253 todo_wine
ok(str_eq_wa(str
, test
->port
),
254 "%s: expected retrieved port to be L\"%s\", was: %s\n",
255 test
->name
, test
->port
, wine_dbgstr_w(str
));
259 static void test_pathname(IHTMLLocation
*loc
, const struct location_test
*test
)
264 hres
= IHTMLLocation_get_pathname(loc
, NULL
);
265 ok(hres
== E_POINTER
,
266 "%s: get_pathname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
267 test
->name
, E_POINTER
, hres
);
269 hres
= IHTMLLocation_get_pathname(loc
, &str
);
270 ok(hres
== S_OK
, "%s: get_pathname failed: 0x%08x\n", test
->name
, hres
);
272 if(test
->pathname_ok
)
273 ok(str_eq_wa(str
, test
->pathname
),
274 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
275 test
->name
, test
->pathname
, wine_dbgstr_w(str
));
277 todo_wine
ok(str_eq_wa(str
, test
->pathname
),
278 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
279 test
->name
, test
->pathname
, wine_dbgstr_w(str
));
283 static void test_search(IHTMLLocation
*loc
, const struct location_test
*test
)
288 hres
= IHTMLLocation_get_search(loc
, NULL
);
289 ok(hres
== E_POINTER
,
290 "%s: get_search should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
291 test
->name
, E_POINTER
, hres
);
293 hres
= IHTMLLocation_get_search(loc
, &str
);
294 todo_wine
ok(hres
== S_OK
, "%s: get_search failed: 0x%08x\n", test
->name
, hres
);
297 ok(str_eq_wa(str
, test
->search
),
298 "%s: expected retrieved search to be L\"%s\", was: %s\n",
299 test
->name
, test
->search
, wine_dbgstr_w(str
));
301 todo_wine
ok(str_eq_wa(str
, test
->search
),
302 "%s: expected retrieved search to be L\"%s\", was: %s\n",
303 test
->name
, test
->search
, wine_dbgstr_w(str
));
307 static void test_hash(IHTMLLocation
*loc
, const struct location_test
*test
)
312 hres
= IHTMLLocation_get_hash(loc
, NULL
);
313 ok(hres
== E_POINTER
,
314 "%s: get_hash should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
315 test
->name
, E_POINTER
, hres
);
317 hres
= IHTMLLocation_get_hash(loc
, &str
);
318 todo_wine
ok(hres
== S_OK
, "%s: get_hash failed: 0x%08x\n", test
->name
, hres
);
321 ok(str_eq_wa(str
, test
->hash
),
322 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
323 test
->name
, test
->hash
, wine_dbgstr_w(str
));
325 todo_wine
ok(str_eq_wa(str
, test
->hash
),
326 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
327 test
->name
, test
->hash
, wine_dbgstr_w(str
));
331 static void perform_test(const struct location_test
* test
)
336 IPersistMoniker
*persist_mon
;
338 IHTMLDocument6
*doc6
;
339 IHTMLLocation
*location
;
341 hres
= CreateBindCtx(0, &bc
);
342 ok(hres
== S_OK
, "%s: CreateBindCtx failed: 0x%08x\n", test
->name
, hres
);
346 hres
= CreateURLMoniker(NULL
, test
->url
, &url_mon
);
347 ok(hres
== S_OK
, "%s: CreateURLMoniker failed: 0x%08x\n", test
->name
, hres
);
349 IBindCtx_Release(bc
);
353 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
,
354 CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
, &IID_IHTMLDocument2
,
356 ok(hres
== S_OK
, "%s: CoCreateInstance failed: 0x%08x\n", test
->name
, hres
);
358 IMoniker_Release(url_mon
);
359 IBindCtx_Release(bc
);
363 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument6
, (void**)&doc6
);
365 IHTMLDocument6_Release(doc6
);
367 win_skip("%s: Could not get IHTMLDocument6, probably too old IE. Requires IE 8+\n", test
->name
);
368 IMoniker_Release(url_mon
);
369 IBindCtx_Release(bc
);
373 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IPersistMoniker
,
374 (void**)&persist_mon
);
375 ok(hres
== S_OK
, "%s: IHTMlDocument2_QueryInterface failed: 0x%08x\n", test
->name
, hres
);
377 IHTMLDocument2_Release(doc
);
378 IMoniker_Release(url_mon
);
379 IBindCtx_Release(bc
);
383 hres
= IPersistMoniker_Load(persist_mon
, FALSE
, url_mon
, bc
,
384 STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
);
385 ok(hres
== S_OK
, "%s: IPersistMoniker_Load failed: 0x%08x\n", test
->name
, hres
);
387 IPersistMoniker_Release(persist_mon
);
388 IHTMLDocument2_Release(doc
);
389 IMoniker_Release(url_mon
);
390 IBindCtx_Release(bc
);
394 hres
= IHTMLDocument2_get_location(doc
, &location
);
395 ok(hres
== S_OK
, "%s: IHTMLDocument2_get_location failed: 0x%08x\n", test
->name
, hres
);
397 IPersistMoniker_Release(persist_mon
);
398 IHTMLDocument2_Release(doc
);
399 IMoniker_Release(url_mon
);
400 IBindCtx_Release(bc
);
404 test_href(location
, test
);
405 test_protocol(location
, test
);
406 test_host(location
, test
);
407 test_hostname(location
, test
);
408 test_port(location
, test
);
409 test_pathname(location
, test
);
410 test_search(location
, test
);
411 test_hash(location
, test
);
413 IHTMLLocation_Release(location
);
414 IPersistMoniker_Release(persist_mon
);
415 IHTMLDocument2_Release(doc
);
416 IMoniker_Release(url_mon
);
417 IBindCtx_Release(bc
);
420 START_TEST(htmllocation
)
424 perform_test(&http_test
);
425 perform_test(&http_file_test
);
426 perform_test(&ftp_test
);
427 perform_test(&ftp_file_test
);
428 perform_test(&file_test
);