wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / mshtml / tests / htmllocation.c
blobcec69e441420d1b08d036a7e2e51845e5a70f013
1 /*
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
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
24 #include "mshtml.h"
25 #include "wininet.h"
27 struct location_test {
28 const char *name;
29 const char *url;
31 const char *href;
32 const char *protocol;
33 const char *host;
34 const char *hostname;
35 const char *port;
36 const char *pathname;
37 const char *search;
38 const char *hash;
41 static const struct location_test location_tests[] = {
43 "HTTP",
44 "http://www.winehq.org?search#hash",
45 "http://www.winehq.org/?search#hash",
46 "http:",
47 "www.winehq.org:80",
48 "www.winehq.org",
49 "80",
50 "/",
51 "?search",
52 "#hash"
55 "HTTP with file",
56 "http://www.winehq.org/file?search#hash",
57 "http://www.winehq.org/file?search#hash",
58 "http:",
59 "www.winehq.org:80",
60 "www.winehq.org",
61 "80",
62 "/file",
63 "?search",
64 "#hash"
67 "FTP",
68 "ftp://ftp.winehq.org/",
69 "ftp://ftp.winehq.org/",
70 "ftp:",
71 "ftp.winehq.org:21",
72 "ftp.winehq.org",
73 "21",
74 "/",
75 NULL,
76 NULL
79 "FTP with file",
80 "ftp://ftp.winehq.org/file",
81 "ftp://ftp.winehq.org/file",
82 "ftp:",
83 "ftp.winehq.org:21",
84 "ftp.winehq.org",
85 "21",
86 "/file",
87 NULL,
88 NULL
92 static int str_eq_wa(LPCWSTR strw, const char *stra)
94 CHAR buf[512];
96 if(!strw || !stra)
97 return (void*)strw == (void*)stra;
99 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
100 return !lstrcmpA(stra, buf);
103 static void test_href(IHTMLLocation *loc, const struct location_test *test)
105 HRESULT hres;
106 BSTR str;
108 hres = IHTMLLocation_get_href(loc, NULL);
109 ok(hres == E_POINTER,
110 "%s: get_href should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
111 test->name, E_POINTER, hres);
113 hres = IHTMLLocation_get_href(loc, &str);
114 ok(hres == S_OK, "%s: get_href failed: 0x%08x\n", test->name, hres);
115 if(hres == S_OK)
116 ok(str_eq_wa(str, test->href),
117 "%s: expected retrieved href to be L\"%s\", was: %s\n",
118 test->name, test->href, wine_dbgstr_w(str));
119 SysFreeString(str);
121 hres = IHTMLLocation_toString(loc, &str);
122 ok(hres == S_OK, "%s: toString failed: 0x%08x\n", test->name, hres);
123 ok(str_eq_wa(str, test->href), "%s: toString returned %s, expected %s\n",
124 test->name, wine_dbgstr_w(str), test->href);
125 SysFreeString(str);
128 static void test_protocol(IHTMLLocation *loc, const struct location_test *test)
130 HRESULT hres;
131 BSTR str;
133 hres = IHTMLLocation_get_protocol(loc, NULL);
134 ok(hres == E_POINTER,
135 "%s: get_protocol should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
136 test->name, E_POINTER, hres);
138 hres = IHTMLLocation_get_protocol(loc, &str);
139 ok(hres == S_OK, "%s: get_protocol failed: 0x%08x\n", test->name, hres);
140 if(hres == S_OK)
141 ok(str_eq_wa(str, test->protocol),
142 "%s: expected retrieved protocol to be L\"%s\", was: %s\n",
143 test->name, test->protocol, wine_dbgstr_w(str));
144 SysFreeString(str);
147 static void test_host(IHTMLLocation *loc, const struct location_test *test)
149 HRESULT hres;
150 BSTR str;
152 hres = IHTMLLocation_get_host(loc, NULL);
153 ok(hres == E_POINTER,
154 "%s: get_host should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
155 test->name, E_POINTER, hres);
157 hres = IHTMLLocation_get_host(loc, &str);
158 ok(hres == S_OK, "%s: get_host failed: 0x%08x\n", test->name, hres);
159 if(hres == S_OK){
160 int len = test->host ? strlen(test->host) : 0;
161 ok(str_eq_wa(str, test->host),
162 "%s: expected retrieved host to be L\"%s\", was: %s\n",
163 test->name, test->host, wine_dbgstr_w(str));
164 ok(SysStringLen(str) == len, "%s: unexpected string length %u, expected %u\n",
165 test->name, SysStringLen(str), len);
168 SysFreeString(str);
171 static void test_hostname(IHTMLLocation *loc, IHTMLDocument2 *doc, const struct location_test *test)
173 HRESULT hres;
174 BSTR str;
176 hres = IHTMLLocation_get_hostname(loc, NULL);
177 ok(hres == E_POINTER,
178 "%s: get_hostname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
179 test->name, E_POINTER, hres);
181 hres = IHTMLLocation_get_hostname(loc, &str);
182 ok(hres == S_OK, "%s: get_hostname failed: 0x%08x\n", test->name, hres);
183 if(hres == S_OK)
184 ok(str_eq_wa(str, test->hostname),
185 "%s: expected retrieved hostname to be L\"%s\", was: %s\n",
186 test->name, test->hostname, wine_dbgstr_w(str));
187 SysFreeString(str);
189 hres = IHTMLDocument2_get_domain(doc, &str);
190 ok(hres == S_OK, "%s: get_domain failed: 0x%08x\n", test->name, hres);
191 if(hres == S_OK)
192 ok(str_eq_wa(str, test->hostname ? test->hostname : ""),
193 "%s: expected retrieved domain to be L\"%s\", was: %s\n",
194 test->name, test->hostname, wine_dbgstr_w(str));
195 SysFreeString(str);
198 static void test_port(IHTMLLocation *loc, const struct location_test *test)
200 HRESULT hres;
201 BSTR str;
203 hres = IHTMLLocation_get_port(loc, NULL);
204 ok(hres == E_POINTER,
205 "%s: get_port should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
206 test->name, E_POINTER, hres);
208 hres = IHTMLLocation_get_port(loc, &str);
209 ok(hres == S_OK, "%s: get_port failed: 0x%08x\n", test->name, hres);
210 if(hres == S_OK)
211 ok(str_eq_wa(str, test->port)
212 || (!str && !*test->port), /* IE11 */
213 "%s: expected retrieved port to be L\"%s\", was: %s\n",
214 test->name, test->port, wine_dbgstr_w(str));
215 SysFreeString(str);
218 static void test_pathname(IHTMLLocation *loc, const struct location_test *test)
220 HRESULT hres;
221 BSTR str;
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);
230 if(hres == S_OK)
231 /* FIXME: We seem to be testing location in a buggy state. Path names do not
232 * include leading slash, while other tests confirm that it should be there */
233 todo_wine_if(*test->pathname == '/')
234 ok(str_eq_wa(str, *test->pathname == '/' ? test->pathname + 1 : test->pathname),
235 "%s: expected retrieved pathname to be L\"%s\", was: %s\n",
236 test->name, test->pathname, wine_dbgstr_w(str));
237 SysFreeString(str);
240 static void test_search(IHTMLLocation *loc, const struct location_test *test)
242 HRESULT hres;
243 BSTR str;
245 hres = IHTMLLocation_get_search(loc, NULL);
246 ok(hres == E_POINTER,
247 "%s: get_search should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
248 test->name, E_POINTER, hres);
250 hres = IHTMLLocation_get_search(loc, &str);
251 ok(hres == S_OK, "%s: get_search failed: 0x%08x\n", test->name, hres);
252 if(hres == S_OK)
253 ok(str_eq_wa(str, test->search),
254 "%s: expected retrieved search to be L\"%s\", was: %s\n",
255 test->name, test->search, wine_dbgstr_w(str));
256 SysFreeString(str);
259 static void test_hash(IHTMLLocation *loc, const struct location_test *test)
261 HRESULT hres;
262 BSTR str;
264 hres = IHTMLLocation_get_hash(loc, NULL);
265 ok(hres == E_POINTER,
266 "%s: get_hash should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
267 test->name, E_POINTER, hres);
269 hres = IHTMLLocation_get_hash(loc, &str);
270 ok(hres == S_OK, "%s: get_hash failed: 0x%08x\n", test->name, hres);
271 if(hres == S_OK)
272 ok(str_eq_wa(str, test->hash),
273 "%s: expected retrieved hash to be L\"%s\", was: %s\n",
274 test->name, test->hash, wine_dbgstr_w(str));
275 SysFreeString(str);
278 static void perform_test(const struct location_test* test)
280 WCHAR url[INTERNET_MAX_URL_LENGTH];
281 HRESULT hres;
282 IBindCtx *bc;
283 IMoniker *url_mon;
284 IPersistMoniker *persist_mon;
285 IHTMLDocument2 *doc;
286 IHTMLDocument6 *doc6;
287 IHTMLLocation *location;
289 hres = CreateBindCtx(0, &bc);
290 ok(hres == S_OK, "%s: CreateBindCtx failed: 0x%08x\n", test->name, hres);
291 if(FAILED(hres))
292 return;
294 MultiByteToWideChar(CP_ACP, 0, test->url, -1, url, ARRAY_SIZE(url));
295 hres = CreateURLMoniker(NULL, url, &url_mon);
296 ok(hres == S_OK, "%s: CreateURLMoniker failed: 0x%08x\n", test->name, hres);
297 if(FAILED(hres)){
298 IBindCtx_Release(bc);
299 return;
302 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
303 CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, &IID_IHTMLDocument2,
304 (void**)&doc);
305 #if !defined(__i386__) && !defined(__x86_64__)
306 todo_wine
307 #endif
308 ok(hres == S_OK, "%s: CoCreateInstance failed: 0x%08x\n", test->name, hres);
309 if(FAILED(hres)){
310 IMoniker_Release(url_mon);
311 IBindCtx_Release(bc);
312 return;
315 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument6, (void**)&doc6);
316 if(hres == S_OK){
317 IHTMLDocument6_Release(doc6);
318 }else{
319 win_skip("%s: Could not get IHTMLDocument6, probably too old IE. Requires IE 8+\n", test->name);
320 IMoniker_Release(url_mon);
321 IBindCtx_Release(bc);
322 return;
325 hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker,
326 (void**)&persist_mon);
327 ok(hres == S_OK, "%s: IHTMlDocument2_QueryInterface failed: 0x%08x\n", test->name, hres);
328 if(FAILED(hres)){
329 IHTMLDocument2_Release(doc);
330 IMoniker_Release(url_mon);
331 IBindCtx_Release(bc);
332 return;
335 hres = IPersistMoniker_Load(persist_mon, FALSE, url_mon, bc,
336 STGM_SHARE_EXCLUSIVE | STGM_READWRITE);
337 ok(hres == S_OK, "%s: IPersistMoniker_Load failed: 0x%08x\n", test->name, hres);
338 if(FAILED(hres)){
339 IPersistMoniker_Release(persist_mon);
340 IHTMLDocument2_Release(doc);
341 IMoniker_Release(url_mon);
342 IBindCtx_Release(bc);
343 return;
346 hres = IHTMLDocument2_get_location(doc, &location);
347 ok(hres == S_OK, "%s: IHTMLDocument2_get_location failed: 0x%08x\n", test->name, hres);
348 if(FAILED(hres)){
349 IPersistMoniker_Release(persist_mon);
350 IHTMLDocument2_Release(doc);
351 IMoniker_Release(url_mon);
352 IBindCtx_Release(bc);
353 return;
356 test_href(location, test);
357 test_protocol(location, test);
358 test_host(location, test);
359 test_hostname(location, doc, test);
360 test_port(location, test);
361 test_pathname(location, test);
362 test_search(location, test);
363 test_hash(location, test);
365 IHTMLLocation_Release(location);
366 IPersistMoniker_Release(persist_mon);
367 IHTMLDocument2_Release(doc);
368 IMoniker_Release(url_mon);
369 IBindCtx_Release(bc);
372 START_TEST(htmllocation)
374 int i;
376 CoInitialize(NULL);
378 for(i=0; i < ARRAY_SIZE(location_tests); i++)
379 perform_test(location_tests+i);
381 CoUninitialize();