mshtml: Implement IHTMLLocation::get_search.
[wine/multimedia.git] / dlls / mshtml / tests / htmllocation.c
blobb66fe62a1c3d153675f93ee933746f88bd333b7d
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"
26 struct location_test {
27 const char *name;
28 const WCHAR *url;
30 const char *href;
31 const BOOL href_ok;
33 const char *protocol;
34 const BOOL protocol_ok;
36 const char *host;
37 const BOOL host_ok;
39 const char *hostname;
40 const BOOL hostname_ok;
42 const char *port;
43 const BOOL port_ok;
45 const char *pathname;
46 const BOOL pathname_ok;
48 const char *search;
49 const BOOL search_ok;
51 const char *hash;
52 const BOOL hash_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 = {
57 "HTTP",
58 http_url,
59 "http://www.winehq.org/?search#hash", TRUE,
60 "http:", TRUE,
61 "www.winehq.org:80", TRUE,
62 "www.winehq.org", TRUE,
63 "80", TRUE,
64 "", TRUE,
65 "?search", TRUE,
66 "#hash", 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 = {
71 "HTTP with file",
72 http_file_url,
73 "http://www.winehq.org/file?search#hash", TRUE,
74 "http:", TRUE,
75 "www.winehq.org:80", TRUE,
76 "www.winehq.org", TRUE,
77 "80", TRUE,
78 "file", TRUE,
79 "?search", TRUE,
80 "#hash", 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 = {
85 "FTP",
86 ftp_url,
87 "ftp://ftp.winehq.org/", TRUE,
88 "ftp:", TRUE,
89 "ftp.winehq.org:21", TRUE,
90 "ftp.winehq.org", TRUE,
91 "21", TRUE,
92 "", TRUE,
93 NULL, TRUE,
94 NULL, 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 = {
99 "FTP with file",
100 ftp_file_url,
101 "ftp://ftp.winehq.org/file", TRUE,
102 "ftp:", TRUE,
103 "ftp.winehq.org:21", TRUE,
104 "ftp.winehq.org", TRUE,
105 "21", TRUE,
106 "file", TRUE,
107 NULL, TRUE,
108 NULL, 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 = {
113 "FILE",
114 file_url,
115 "file:///C:/windows/win.ini", TRUE,
116 "file:", TRUE,
117 NULL, TRUE,
118 NULL, TRUE,
119 "", TRUE,
120 "C:\\windows\\win.ini", TRUE,
121 NULL, TRUE,
122 NULL, TRUE
125 static int str_eq_wa(LPCWSTR strw, const char *stra)
127 CHAR buf[512];
129 if(strw == NULL || stra == NULL){
130 if((void*)strw == (void*)stra)
131 return 1;
132 return 0;
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)
141 HRESULT hres;
142 BSTR str;
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);
151 if(hres == S_OK){
152 if(test->href_ok)
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));
156 else
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)
165 HRESULT hres;
166 BSTR str;
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);
175 if(hres == S_OK){
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));
180 else
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)
189 HRESULT hres;
190 BSTR str;
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);
199 if(hres == S_OK){
200 if(test->host_ok)
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));
204 else
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)
213 HRESULT hres;
214 BSTR str;
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);
223 if(hres == S_OK){
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));
228 else
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)
237 HRESULT hres;
238 BSTR str;
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);
247 if(hres == S_OK){
248 if(test->port_ok)
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));
252 else
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)
261 HRESULT hres;
262 BSTR str;
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);
271 if(hres == S_OK){
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));
276 else
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)
285 HRESULT hres;
286 BSTR str;
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 ok(hres == S_OK, "%s: get_search failed: 0x%08x\n", test->name, hres);
295 if(hres == S_OK){
296 if(test->search_ok)
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));
300 else
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)
309 HRESULT hres;
310 BSTR str;
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 ok(hres == S_OK, "%s: get_hash failed: 0x%08x\n", test->name, hres);
319 if(hres == S_OK){
320 if(test->hash_ok)
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));
324 else
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)
333 HRESULT hres;
334 IBindCtx *bc;
335 IMoniker *url_mon;
336 IPersistMoniker *persist_mon;
337 IHTMLDocument2 *doc;
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);
343 if(FAILED(hres))
344 return;
346 hres = CreateURLMoniker(NULL, test->url, &url_mon);
347 ok(hres == S_OK, "%s: CreateURLMoniker failed: 0x%08x\n", test->name, hres);
348 if(FAILED(hres)){
349 IBindCtx_Release(bc);
350 return;
353 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
354 CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, &IID_IHTMLDocument2,
355 (void**)&doc);
356 ok(hres == S_OK, "%s: CoCreateInstance failed: 0x%08x\n", test->name, hres);
357 if(FAILED(hres)){
358 IMoniker_Release(url_mon);
359 IBindCtx_Release(bc);
360 return;
363 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument6, (void**)&doc6);
364 if(hres == S_OK){
365 IHTMLDocument6_Release(doc6);
366 }else{
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);
370 return;
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);
376 if(FAILED(hres)){
377 IHTMLDocument2_Release(doc);
378 IMoniker_Release(url_mon);
379 IBindCtx_Release(bc);
380 return;
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);
386 if(FAILED(hres)){
387 IPersistMoniker_Release(persist_mon);
388 IHTMLDocument2_Release(doc);
389 IMoniker_Release(url_mon);
390 IBindCtx_Release(bc);
391 return;
394 hres = IHTMLDocument2_get_location(doc, &location);
395 ok(hres == S_OK, "%s: IHTMLDocument2_get_location failed: 0x%08x\n", test->name, hres);
396 if(FAILED(hres)){
397 IPersistMoniker_Release(persist_mon);
398 IHTMLDocument2_Release(doc);
399 IMoniker_Release(url_mon);
400 IBindCtx_Release(bc);
401 return;
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)
422 CoInitialize(NULL);
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);
430 CoUninitialize();