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
{
40 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};
41 static const struct location_test http_test
= {
44 "http://www.winehq.org/?search#hash",
54 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};
55 static const struct location_test http_file_test
= {
58 "http://www.winehq.org/file?search#hash",
68 static const WCHAR ftp_url
[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g','/',0};
69 static const struct location_test ftp_test
= {
72 "ftp://ftp.winehq.org/",
82 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};
83 static const struct location_test ftp_file_test
= {
86 "ftp://ftp.winehq.org/file",
96 static const WCHAR file_url
[] = {'f','i','l','e',':','/','/','C',':','\\','w','i','n','d','o','w','s','\\','w','i','n','.','i','n','i',0};
97 static const struct location_test file_test
= {
100 "file:///C:/windows/win.ini",
105 "C:\\windows\\win.ini",
110 static int str_eq_wa(LPCWSTR strw
, const char *stra
)
114 if(strw
== NULL
|| stra
== NULL
){
115 if((void*)strw
== (void*)stra
)
120 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
121 return !lstrcmpA(stra
, buf
);
124 static void test_href(IHTMLLocation
*loc
, const struct location_test
*test
)
129 hres
= IHTMLLocation_get_href(loc
, NULL
);
130 ok(hres
== E_POINTER
,
131 "%s: get_href should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
132 test
->name
, E_POINTER
, hres
);
134 hres
= IHTMLLocation_get_href(loc
, &str
);
135 ok(hres
== S_OK
, "%s: get_href failed: 0x%08x\n", test
->name
, hres
);
137 ok(str_eq_wa(str
, test
->href
),
138 "%s: expected retrieved href to be L\"%s\", was: %s\n",
139 test
->name
, test
->href
, wine_dbgstr_w(str
));
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
));
160 static void test_host(IHTMLLocation
*loc
, const struct location_test
*test
)
165 hres
= IHTMLLocation_get_host(loc
, NULL
);
166 ok(hres
== E_POINTER
,
167 "%s: get_host should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
168 test
->name
, E_POINTER
, hres
);
170 hres
= IHTMLLocation_get_host(loc
, &str
);
171 ok(hres
== S_OK
, "%s: get_host failed: 0x%08x\n", test
->name
, hres
);
173 ok(str_eq_wa(str
, test
->host
),
174 "%s: expected retrieved host to be L\"%s\", was: %s\n",
175 test
->name
, test
->host
, wine_dbgstr_w(str
));
178 static void test_hostname(IHTMLLocation
*loc
, 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 static void test_port(IHTMLLocation
*loc
, const struct location_test
*test
)
201 hres
= IHTMLLocation_get_port(loc
, NULL
);
202 ok(hres
== E_POINTER
,
203 "%s: get_port should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
204 test
->name
, E_POINTER
, hres
);
206 hres
= IHTMLLocation_get_port(loc
, &str
);
207 ok(hres
== S_OK
, "%s: get_port failed: 0x%08x\n", test
->name
, hres
);
209 ok(str_eq_wa(str
, test
->port
),
210 "%s: expected retrieved port to be L\"%s\", was: %s\n",
211 test
->name
, test
->port
, wine_dbgstr_w(str
));
214 static void test_pathname(IHTMLLocation
*loc
, const struct location_test
*test
)
219 hres
= IHTMLLocation_get_pathname(loc
, NULL
);
220 ok(hres
== E_POINTER
,
221 "%s: get_pathname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
222 test
->name
, E_POINTER
, hres
);
224 hres
= IHTMLLocation_get_pathname(loc
, &str
);
225 ok(hres
== S_OK
, "%s: get_pathname failed: 0x%08x\n", test
->name
, hres
);
227 ok(str_eq_wa(str
, test
->pathname
),
228 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
229 test
->name
, test
->pathname
, wine_dbgstr_w(str
));
232 static void test_search(IHTMLLocation
*loc
, const struct location_test
*test
)
237 hres
= IHTMLLocation_get_search(loc
, NULL
);
238 ok(hres
== E_POINTER
,
239 "%s: get_search should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
240 test
->name
, E_POINTER
, hres
);
242 hres
= IHTMLLocation_get_search(loc
, &str
);
243 ok(hres
== S_OK
, "%s: get_search failed: 0x%08x\n", test
->name
, hres
);
245 ok(str_eq_wa(str
, test
->search
),
246 "%s: expected retrieved search to be L\"%s\", was: %s\n",
247 test
->name
, test
->search
, wine_dbgstr_w(str
));
250 static void test_hash(IHTMLLocation
*loc
, const struct location_test
*test
)
255 hres
= IHTMLLocation_get_hash(loc
, NULL
);
256 ok(hres
== E_POINTER
,
257 "%s: get_hash should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
258 test
->name
, E_POINTER
, hres
);
260 hres
= IHTMLLocation_get_hash(loc
, &str
);
261 ok(hres
== S_OK
, "%s: get_hash failed: 0x%08x\n", test
->name
, hres
);
263 ok(str_eq_wa(str
, test
->hash
),
264 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
265 test
->name
, test
->hash
, wine_dbgstr_w(str
));
268 static void perform_test(const struct location_test
* test
)
273 IPersistMoniker
*persist_mon
;
275 IHTMLDocument6
*doc6
;
276 IHTMLLocation
*location
;
278 hres
= CreateBindCtx(0, &bc
);
279 ok(hres
== S_OK
, "%s: CreateBindCtx failed: 0x%08x\n", test
->name
, hres
);
283 hres
= CreateURLMoniker(NULL
, test
->url
, &url_mon
);
284 ok(hres
== S_OK
, "%s: CreateURLMoniker failed: 0x%08x\n", test
->name
, hres
);
286 IBindCtx_Release(bc
);
290 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
,
291 CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
, &IID_IHTMLDocument2
,
293 ok(hres
== S_OK
, "%s: CoCreateInstance failed: 0x%08x\n", test
->name
, hres
);
295 IMoniker_Release(url_mon
);
296 IBindCtx_Release(bc
);
300 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument6
, (void**)&doc6
);
302 IHTMLDocument6_Release(doc6
);
304 win_skip("%s: Could not get IHTMLDocument6, probably too old IE. Requires IE 8+\n", test
->name
);
305 IMoniker_Release(url_mon
);
306 IBindCtx_Release(bc
);
310 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IPersistMoniker
,
311 (void**)&persist_mon
);
312 ok(hres
== S_OK
, "%s: IHTMlDocument2_QueryInterface failed: 0x%08x\n", test
->name
, hres
);
314 IHTMLDocument2_Release(doc
);
315 IMoniker_Release(url_mon
);
316 IBindCtx_Release(bc
);
320 hres
= IPersistMoniker_Load(persist_mon
, FALSE
, url_mon
, bc
,
321 STGM_SHARE_EXCLUSIVE
| STGM_READWRITE
);
322 ok(hres
== S_OK
, "%s: IPersistMoniker_Load failed: 0x%08x\n", test
->name
, hres
);
324 IPersistMoniker_Release(persist_mon
);
325 IHTMLDocument2_Release(doc
);
326 IMoniker_Release(url_mon
);
327 IBindCtx_Release(bc
);
331 hres
= IHTMLDocument2_get_location(doc
, &location
);
332 ok(hres
== S_OK
, "%s: IHTMLDocument2_get_location failed: 0x%08x\n", test
->name
, hres
);
334 IPersistMoniker_Release(persist_mon
);
335 IHTMLDocument2_Release(doc
);
336 IMoniker_Release(url_mon
);
337 IBindCtx_Release(bc
);
341 test_href(location
, test
);
342 test_protocol(location
, test
);
343 test_host(location
, test
);
344 test_hostname(location
, test
);
345 test_port(location
, test
);
346 test_pathname(location
, test
);
347 test_search(location
, test
);
348 test_hash(location
, test
);
350 IHTMLLocation_Release(location
);
351 IPersistMoniker_Release(persist_mon
);
352 IHTMLDocument2_Release(doc
);
353 IMoniker_Release(url_mon
);
354 IBindCtx_Release(bc
);
357 START_TEST(htmllocation
)
361 perform_test(&http_test
);
362 perform_test(&http_file_test
);
363 perform_test(&ftp_test
);
364 perform_test(&ftp_file_test
);
365 perform_test(&file_test
);