urlmon/tests: Added tests for IUri_HasProperty.
[wine.git] / dlls / urlmon / tests / uri.c
blob9e8b32ebeaa6741f4539f301a2dcc690ae4c8df8
1 /*
2 * UrlMon IUri tests
4 * Copyright 2010 Thomas Mullaly
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * IUri testing framework goals:
23 * - Test invalid args
24 * - invalid flags
25 * - invalid args (IUri, uri string)
26 * - Test parsing for components when no canonicalization occurs
27 * - Test parsing for components when canonicalization occurs.
28 * - More tests...
31 #include <wine/test.h>
32 #include <stdarg.h>
33 #include <stddef.h>
35 #define COBJMACROS
37 #include "windef.h"
38 #include "winbase.h"
39 #include "urlmon.h"
40 #include "shlwapi.h"
42 #define URI_STR_PROPERTY_COUNT Uri_PROPERTY_STRING_LAST+1
43 #define URI_DWORD_PROPERTY_COUNT (Uri_PROPERTY_DWORD_LAST - Uri_PROPERTY_DWORD_START)+1
45 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
47 static const WCHAR http_urlW[] = { 'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
48 '.','o','r','g','/',0};
50 typedef struct _uri_create_flag_test {
51 DWORD flags;
52 HRESULT expected;
53 } uri_create_flag_test;
55 static const uri_create_flag_test invalid_flag_tests[] = {
56 /* Set of invalid flag combinations to test for. */
57 {Uri_CREATE_DECODE_EXTRA_INFO | Uri_CREATE_NO_DECODE_EXTRA_INFO, E_INVALIDARG},
58 {Uri_CREATE_CANONICALIZE | Uri_CREATE_NO_CANONICALIZE, E_INVALIDARG},
59 {Uri_CREATE_CRACK_UNKNOWN_SCHEMES | Uri_CREATE_NO_CRACK_UNKNOWN_SCHEMES, E_INVALIDARG},
60 {Uri_CREATE_PRE_PROCESS_HTML_URI | Uri_CREATE_NO_PRE_PROCESS_HTML_URI, E_INVALIDARG},
61 {Uri_CREATE_IE_SETTINGS | Uri_CREATE_NO_IE_SETTINGS, E_INVALIDARG}
64 typedef struct _uri_str_property {
65 const char* value;
66 HRESULT expected;
67 BOOL todo;
68 } uri_str_property;
70 typedef struct _uri_dword_property {
71 DWORD value;
72 HRESULT expected;
73 BOOL todo;
74 } uri_dword_property;
76 typedef struct _uri_properties {
77 const char* uri;
78 DWORD create_flags;
79 HRESULT create_expected;
80 BOOL create_todo;
81 DWORD props;
82 BOOL props_todo;
84 uri_str_property str_props[URI_STR_PROPERTY_COUNT];
85 uri_dword_property dword_props[URI_DWORD_PROPERTY_COUNT];
86 } uri_properties;
88 static const uri_properties uri_tests[] = {
89 { "http://www.winehq.org/tests/../tests/../..", 0, S_OK, FALSE,
90 /* A flag bitmap containing all the Uri_HAS_* flags that correspond to this uri. */
91 Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|Uri_HAS_HOST|
92 Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|
93 Uri_HAS_PORT|Uri_HAS_SCHEME,
94 TRUE,
96 {"http://www.winehq.org/",S_OK,TRUE}, /* ABSOLUTE_URI */
97 {"www.winehq.org",S_OK,TRUE}, /* AUTHORITY */
98 {"http://www.winehq.org/",S_OK,TRUE}, /* DISPLAY_URI */
99 {"winehq.org",S_OK,TRUE}, /* DOMAIN */
100 {"",S_FALSE,TRUE}, /* EXTENSION */
101 {"",S_FALSE,TRUE}, /* FRAGMENT */
102 {"www.winehq.org",S_OK,TRUE}, /* HOST */
103 {"",S_FALSE,TRUE}, /* PASSWORD */
104 {"/",S_OK,TRUE}, /* PATH */
105 {"/",S_OK,TRUE}, /* PATH_AND_QUERY */
106 {"",S_FALSE,TRUE}, /* QUERY */
107 {"http://www.winehq.org/tests/../tests/../..",S_OK,TRUE}, /* RAW_URI */
108 {"http",S_OK,TRUE}, /* SCHEME_NAME */
109 {"",S_FALSE,TRUE}, /* USER_INFO */
110 {"",S_FALSE,TRUE} /* USER_NAME */
113 {Uri_HOST_DNS,S_OK,TRUE}, /* HOST_TYPE */
114 {80,S_OK,TRUE}, /* PORT */
115 {URL_SCHEME_HTTP,S_OK,TRUE}, /* SCHEME */
116 {URLZONE_INVALID,E_NOTIMPL,FALSE} /* ZONE */
119 { "http://winehq.org/tests/.././tests", 0, S_OK, FALSE,
120 Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|Uri_HAS_HOST|
121 Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|
122 Uri_HAS_PORT|Uri_HAS_SCHEME,
123 TRUE,
125 {"http://winehq.org/tests",S_OK,TRUE},
126 {"winehq.org",S_OK,TRUE},
127 {"http://winehq.org/tests",S_OK,TRUE},
128 {"winehq.org",S_OK,TRUE},
129 {"",S_FALSE,TRUE},
130 {"",S_FALSE,TRUE},
131 {"winehq.org",S_OK,TRUE},
132 {"",S_FALSE,TRUE},
133 {"/tests",S_OK,TRUE},
134 {"/tests",S_OK,TRUE},
135 {"",S_FALSE,TRUE},
136 {"http://winehq.org/tests/.././tests",S_OK,TRUE},
137 {"http",S_OK,TRUE},
138 {"",S_FALSE,TRUE},
139 {"",S_FALSE,TRUE}
142 {Uri_HOST_DNS,S_OK,TRUE},
143 {80,S_OK,TRUE},
144 {URL_SCHEME_HTTP,S_OK,TRUE},
145 {URLZONE_INVALID,E_NOTIMPL,FALSE}
148 { "HtTp://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, FALSE,
149 Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|Uri_HAS_HOST|
150 Uri_HAS_DOMAIN|Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_QUERY|Uri_HAS_RAW_URI|
151 Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
152 TRUE,
154 {"http://www.winehq.org/?query=x&return=y",S_OK,TRUE},
155 {"www.winehq.org",S_OK,TRUE},
156 {"http://www.winehq.org/?query=x&return=y",S_OK,TRUE},
157 {"winehq.org",S_OK,TRUE},
158 {"",S_FALSE,TRUE},
159 {"",S_FALSE,TRUE},
160 {"www.winehq.org",S_OK,TRUE},
161 {"",S_FALSE,TRUE},
162 {"/",S_OK,TRUE},
163 {"/?query=x&return=y",S_OK,TRUE},
164 {"?query=x&return=y",S_OK,TRUE},
165 {"HtTp://www.winehq.org/tests/..?query=x&return=y",S_OK,TRUE},
166 {"http",S_OK,TRUE},
167 {"",S_FALSE,TRUE},
168 {"",S_FALSE,TRUE}
171 {Uri_HOST_DNS,S_OK,TRUE},
172 {80,S_OK,TRUE},
173 {URL_SCHEME_HTTP,S_OK,TRUE},
174 {URLZONE_INVALID,E_NOTIMPL,FALSE},
177 { "hTTp://us%45r%3Ainfo@examp%4CE.com:80/path/a/b/./c/../%2E%2E/Forbidden'<|> Characters", 0, S_OK, FALSE,
178 Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|Uri_HAS_HOST|Uri_HAS_PATH|
179 Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|Uri_HAS_USER_INFO|Uri_HAS_USER_NAME|
180 Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
181 TRUE,
183 {"http://usEr%3Ainfo@example.com/path/a/Forbidden'%3C%7C%3E%20Characters",S_OK,TRUE},
184 {"usEr%3Ainfo@example.com",S_OK,TRUE},
185 {"http://example.com/path/a/Forbidden'%3C%7C%3E%20Characters",S_OK,TRUE},
186 {"example.com",S_OK,TRUE},
187 {"",S_FALSE,TRUE},
188 {"",S_FALSE,TRUE},
189 {"example.com",S_OK,TRUE},
190 {"",S_FALSE,TRUE},
191 {"/path/a/Forbidden'%3C%7C%3E%20Characters",S_OK,TRUE},
192 {"/path/a/Forbidden'%3C%7C%3E%20Characters",S_OK,TRUE},
193 {"",S_FALSE,TRUE},
194 {"hTTp://us%45r%3Ainfo@examp%4CE.com:80/path/a/b/./c/../%2E%2E/Forbidden'<|> Characters",S_OK,TRUE},
195 {"http",S_OK,TRUE},
196 {"usEr%3Ainfo",S_OK,TRUE},
197 {"usEr%3Ainfo",S_OK,TRUE}
200 {Uri_HOST_DNS,S_OK,TRUE},
201 {80,S_OK,TRUE},
202 {URL_SCHEME_HTTP,S_OK,TRUE},
203 {URLZONE_INVALID,E_NOTIMPL,FALSE},
206 { "ftp://winepass:wine@ftp.winehq.org:9999/dir/foo bar.txt", 0, S_OK, FALSE,
207 Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_DOMAIN|Uri_HAS_EXTENSION|
208 Uri_HAS_HOST|Uri_HAS_PASSWORD|Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|
209 Uri_HAS_SCHEME_NAME|Uri_HAS_USER_INFO|Uri_HAS_USER_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_PORT|
210 Uri_HAS_SCHEME,
211 TRUE,
213 {"ftp://winepass:wine@ftp.winehq.org:9999/dir/foo%20bar.txt",S_OK,TRUE},
214 {"winepass:wine@ftp.winehq.org:9999",S_OK,TRUE},
215 {"ftp://ftp.winehq.org:9999/dir/foo%20bar.txt",S_OK,TRUE},
216 {"winehq.org",S_OK,TRUE},
217 {".txt",S_OK,TRUE},
218 {"",S_FALSE,TRUE},
219 {"ftp.winehq.org",S_OK,TRUE},
220 {"wine",S_OK,TRUE},
221 {"/dir/foo%20bar.txt",S_OK,TRUE},
222 {"/dir/foo%20bar.txt",S_OK,TRUE},
223 {"",S_FALSE,TRUE},
224 {"ftp://winepass:wine@ftp.winehq.org:9999/dir/foo bar.txt",S_OK,TRUE},
225 {"ftp",S_OK,TRUE},
226 {"winepass:wine",S_OK,TRUE},
227 {"winepass",S_OK,TRUE}
230 {Uri_HOST_DNS,S_OK,TRUE},
231 {9999,S_OK,TRUE},
232 {URL_SCHEME_FTP,S_OK,TRUE},
233 {URLZONE_INVALID,E_NOTIMPL,FALSE}
236 { "file://c:\\tests\\../tests/foo%20bar.mp3", 0, S_OK, FALSE,
237 Uri_HAS_ABSOLUTE_URI|Uri_HAS_DISPLAY_URI|Uri_HAS_EXTENSION|Uri_HAS_PATH|
238 Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_SCHEME,
239 TRUE,
241 {"file:///c:/tests/foo%2520bar.mp3",S_OK,TRUE},
242 {"",S_FALSE,TRUE},
243 {"file:///c:/tests/foo%2520bar.mp3",S_OK,TRUE},
244 {"",S_FALSE,TRUE},
245 {".mp3",S_OK,TRUE},
246 {"",S_FALSE,TRUE},
247 {"",S_FALSE,TRUE},
248 {"",S_FALSE,TRUE},
249 {"/c:/tests/foo%2520bar.mp3",S_OK,TRUE},
250 {"/c:/tests/foo%2520bar.mp3",S_OK,TRUE},
251 {"",S_FALSE,TRUE},
252 {"file://c:\\tests\\../tests/foo%20bar.mp3",S_OK,TRUE},
253 {"file",S_OK,TRUE},
254 {"",S_FALSE,TRUE},
255 {"",S_FALSE,TRUE}
258 {Uri_HOST_UNKNOWN,S_OK,TRUE},
259 {0,S_FALSE,TRUE},
260 {URL_SCHEME_FILE,S_OK,TRUE},
261 {URLZONE_INVALID,E_NOTIMPL,FALSE}
264 { "FILE://localhost/test dir\\../tests/test%20file.README.txt", 0, S_OK, FALSE,
265 Uri_HAS_ABSOLUTE_URI|Uri_HAS_DISPLAY_URI|Uri_HAS_EXTENSION|Uri_HAS_PATH|
266 Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_SCHEME,
267 TRUE,
269 {"file:///tests/test%20file.README.txt",S_OK,TRUE},
270 {"",S_FALSE,TRUE},
271 {"file:///tests/test%20file.README.txt",S_OK,TRUE},
272 {"",S_FALSE,TRUE},
273 {".txt",S_OK,TRUE},
274 {"",S_FALSE,TRUE},
275 {"",S_FALSE,TRUE},
276 {"",S_FALSE,TRUE},
277 {"/tests/test%20file.README.txt",S_OK,TRUE},
278 {"/tests/test%20file.README.txt",S_OK,TRUE},
279 {"",S_FALSE,TRUE},
280 {"FILE://localhost/test dir\\../tests/test%20file.README.txt",S_OK,TRUE},
281 {"file",S_OK,TRUE},
282 {"",S_FALSE,TRUE},
283 {"",S_FALSE,TRUE}
286 {Uri_HOST_UNKNOWN,S_OK,TRUE},
287 {0,S_FALSE,TRUE},
288 {URL_SCHEME_FILE,S_OK,TRUE},
289 {URLZONE_INVALID,E_NOTIMPL,FALSE}
292 { "urn:nothing:should:happen here", 0, S_OK, FALSE,
293 Uri_HAS_ABSOLUTE_URI|Uri_HAS_DISPLAY_URI|Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|
294 Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|Uri_HAS_HOST_TYPE|Uri_HAS_SCHEME,
295 TRUE,
297 {"urn:nothing:should:happen here",S_OK,TRUE},
298 {"",S_FALSE,TRUE},
299 {"urn:nothing:should:happen here",S_OK,TRUE},
300 {"",S_FALSE,TRUE},
301 {"",S_FALSE,TRUE},
302 {"",S_FALSE,TRUE},
303 {"",S_FALSE,TRUE},
304 {"",S_FALSE,TRUE},
305 {"nothing:should:happen here",S_OK,TRUE},
306 {"nothing:should:happen here",S_OK,TRUE},
307 {"",S_FALSE,TRUE},
308 {"urn:nothing:should:happen here",S_OK,TRUE},
309 {"urn",S_OK,TRUE},
310 {"",S_FALSE,TRUE},
311 {"",S_FALSE,TRUE}
314 {Uri_HOST_UNKNOWN,S_OK,TRUE},
315 {0,S_FALSE,TRUE},
316 {URL_SCHEME_UNKNOWN,S_OK,TRUE},
317 {URLZONE_INVALID,E_NOTIMPL,FALSE}
320 { "http://127.0.0.1/tests/../test dir/./test.txt", 0, S_OK, FALSE,
321 Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_EXTENSION|
322 Uri_HAS_HOST|Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|
323 Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
324 TRUE,
326 {"http://127.0.0.1/test%20dir/test.txt",S_OK,TRUE},
327 {"127.0.0.1",S_OK,TRUE},
328 {"http://127.0.0.1/test%20dir/test.txt",S_OK,TRUE},
329 {"",S_FALSE,TRUE},
330 {".txt",S_OK,TRUE},
331 {"",S_FALSE,TRUE},
332 {"127.0.0.1",S_OK,TRUE},
333 {"",S_FALSE,TRUE},
334 {"/test%20dir/test.txt",S_OK,TRUE},
335 {"/test%20dir/test.txt",S_OK,TRUE},
336 {"",S_FALSE,TRUE},
337 {"http://127.0.0.1/tests/../test dir/./test.txt",S_OK,TRUE},
338 {"http",S_OK,TRUE},
339 {"",S_FALSE,TRUE},
340 {"",S_FALSE,TRUE}
343 {Uri_HOST_IPV4,S_OK,TRUE},
344 {80,S_OK,TRUE},
345 {URL_SCHEME_HTTP,S_OK,TRUE},
346 {URLZONE_INVALID,E_NOTIMPL,FALSE}
349 { "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]", 0, S_OK, FALSE,
350 Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_HOST|
351 Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|
352 Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
353 TRUE,
355 {"http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/",S_OK,TRUE},
356 {"[fedc:ba98:7654:3210:fedc:ba98:7654:3210]",S_OK,TRUE},
357 {"http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/",S_OK,TRUE},
358 {"",S_FALSE,TRUE},
359 {"",S_FALSE,TRUE},
360 {"",S_FALSE,TRUE},
361 {"fedc:ba98:7654:3210:fedc:ba98:7654:3210",S_OK,TRUE},
362 {"",S_FALSE,TRUE},
363 {"/",S_OK,TRUE},
364 {"/",S_OK,TRUE},
365 {"",S_FALSE,TRUE},
366 {"http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]",S_OK,TRUE},
367 {"http",S_OK,TRUE},
368 {"",S_FALSE,TRUE},
369 {"",S_FALSE,TRUE}
372 {Uri_HOST_IPV6,S_OK,TRUE},
373 {80,S_OK,TRUE},
374 {URL_SCHEME_HTTP,S_OK,TRUE},
375 {URLZONE_INVALID,E_NOTIMPL,FALSE}
378 { "ftp://[::13.1.68.3]", 0, S_OK, FALSE,
379 Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_HOST|
380 Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|
381 Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
382 TRUE,
384 {"ftp://[::13.1.68.3]/",S_OK,TRUE},
385 {"[::13.1.68.3]",S_OK,TRUE},
386 {"ftp://[::13.1.68.3]/",S_OK,TRUE},
387 {"",S_FALSE,TRUE},
388 {"",S_FALSE,TRUE},
389 {"",S_FALSE,TRUE},
390 {"::13.1.68.3",S_OK,TRUE},
391 {"",S_FALSE,TRUE},
392 {"/",S_OK,TRUE},
393 {"/",S_OK,TRUE},
394 {"",S_FALSE,TRUE},
395 {"ftp://[::13.1.68.3]",S_OK,TRUE},
396 {"ftp",S_OK,TRUE},
397 {"",S_FALSE,TRUE},
398 {"",S_FALSE,TRUE}
401 {Uri_HOST_IPV6,S_OK,TRUE},
402 {21,S_OK,TRUE},
403 {URL_SCHEME_FTP,S_OK,TRUE},
404 {URLZONE_INVALID,E_NOTIMPL,FALSE}
407 { "http://[FEDC:BA98:0:0:0:0:0:3210]", 0, S_OK, FALSE,
408 Uri_HAS_ABSOLUTE_URI|Uri_HAS_AUTHORITY|Uri_HAS_DISPLAY_URI|Uri_HAS_HOST|
409 Uri_HAS_PATH|Uri_HAS_PATH_AND_QUERY|Uri_HAS_RAW_URI|Uri_HAS_SCHEME_NAME|
410 Uri_HAS_HOST_TYPE|Uri_HAS_PORT|Uri_HAS_SCHEME,
411 TRUE,
413 {"http://[fedc:ba98::3210]/",S_OK,TRUE},
414 {"[fedc:ba98::3210]",S_OK,TRUE},
415 {"http://[fedc:ba98::3210]/",S_OK,TRUE},
416 {"",S_FALSE,TRUE},
417 {"",S_FALSE,TRUE},
418 {"",S_FALSE,TRUE},
419 {"fedc:ba98::3210",S_OK,TRUE},
420 {"",S_FALSE,TRUE},
421 {"/",S_OK,TRUE},
422 {"/",S_OK,TRUE},
423 {"",S_FALSE,TRUE},
424 {"http://[FEDC:BA98:0:0:0:0:0:3210]",S_OK,TRUE},
425 {"http",S_OK,TRUE},
426 {"",S_FALSE,TRUE},
427 {"",S_FALSE,TRUE},
430 {Uri_HOST_IPV6,S_OK,TRUE},
431 {80,S_OK,TRUE},
432 {URL_SCHEME_HTTP,S_OK,TRUE},
433 {URLZONE_INVALID,E_NOTIMPL,FALSE}
438 static inline LPWSTR a2w(LPCSTR str) {
439 LPWSTR ret = NULL;
441 if(str) {
442 DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
443 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
444 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
447 return ret;
450 static inline BOOL heap_free(void* mem) {
451 return HeapFree(GetProcessHeap(), 0, mem);
454 static inline DWORD strcmp_aw(LPCSTR strA, LPCWSTR strB) {
455 LPWSTR strAW = a2w(strA);
456 DWORD ret = lstrcmpW(strAW, strB);
457 heap_free(strAW);
458 return ret;
462 * Simple tests to make sure the CreateUri function handles invalid flag combinations
463 * correctly.
465 static void test_CreateUri_InvalidFlags(void) {
466 DWORD i;
468 for(i = 0; i < sizeof(invalid_flag_tests)/sizeof(invalid_flag_tests[0]); ++i) {
469 HRESULT hr;
470 IUri *uri = (void*) 0xdeadbeef;
472 hr = pCreateUri(http_urlW, invalid_flag_tests[i].flags, 0, &uri);
473 todo_wine {
474 ok(hr == invalid_flag_tests[i].expected, "Error: CreateUri returned 0x%08x, expected 0x%08x, flags=0x%08x\n",
475 hr, invalid_flag_tests[i].expected, invalid_flag_tests[i].flags);
477 todo_wine { ok(uri == NULL, "Error: expected the IUri to be NULL, but it was %p instead\n", uri); }
481 static void test_CreateUri_InvalidArgs(void) {
482 HRESULT hr;
483 IUri *uri = (void*) 0xdeadbeef;
485 hr = pCreateUri(http_urlW, 0, 0, NULL);
486 ok(hr == E_INVALIDARG, "Error: CreateUri returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
488 hr = pCreateUri(NULL, 0, 0, &uri);
489 ok(hr == E_INVALIDARG, "Error: CreateUri returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
490 ok(uri == NULL, "Error: Expected the IUri to be NULL, but it was %p instead\n", uri);
493 static void test_IUri_GetPropertyBSTR(void) {
494 IUri *uri = NULL;
495 HRESULT hr;
496 DWORD i;
498 /* Make sure GetPropertyBSTR handles invalid args correctly. */
499 hr = pCreateUri(http_urlW, 0, 0, &uri);
500 ok(hr == S_OK, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
501 if(SUCCEEDED(hr)) {
502 BSTR received = NULL;
504 hr = IUri_GetPropertyBSTR(uri, Uri_PROPERTY_RAW_URI, NULL, 0);
505 ok(hr == E_POINTER, "Error: GetPropertyBSTR returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
507 /* Make sure it handles a invalid Uri_PROPERTY's correctly. */
508 hr = IUri_GetPropertyBSTR(uri, Uri_PROPERTY_PORT, &received, 0);
509 ok(hr == S_OK, "Error: GetPropertyBSTR returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
510 ok(received != NULL, "Error: Expected the string not to be NULL.\n");
511 ok(!SysStringLen(received), "Error: Expected the string to be of len=0 but it was %d instead.\n", SysStringLen(received));
512 SysFreeString(received);
514 /* Make sure it handles the ZONE property correctly. */
515 received = NULL;
516 hr = IUri_GetPropertyBSTR(uri, Uri_PROPERTY_ZONE, &received, 0);
517 ok(hr == S_FALSE, "Error: GetPropertyBSTR returned 0x%08x, expected 0x%08x.\n", hr, S_FALSE);
518 ok(received != NULL, "Error: Expected the string not to be NULL.\n");
519 ok(!SysStringLen(received), "Error: Expected the string to be of len=0 but it was %d instead.\n", SysStringLen(received));
520 SysFreeString(received);
522 if(uri) IUri_Release(uri);
524 for(i = 0; i < sizeof(uri_tests)/sizeof(uri_tests[0]); ++i) {
525 uri_properties test = uri_tests[i];
526 LPWSTR uriW;
527 uri = NULL;
529 uriW = a2w(test.uri);
530 hr = pCreateUri(uriW, test.create_flags, 0, &uri);
531 if(test.create_todo) {
532 todo_wine {
533 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x. Failed on uri_tests[%d].\n",
534 hr, test.create_expected, i);
536 } else {
537 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x. Failed on uri_tests[%d].\n",
538 hr, test.create_expected, i);
541 if(SUCCEEDED(hr)) {
542 DWORD j;
544 /* Checks all the string properties of the uri. */
545 for(j = Uri_PROPERTY_STRING_START; j <= Uri_PROPERTY_STRING_LAST; ++j) {
546 BSTR received = NULL;
547 uri_str_property prop = test.str_props[j];
549 hr = IUri_GetPropertyBSTR(uri, j, &received, 0);
550 if(prop.todo) {
551 todo_wine {
552 ok(hr == prop.expected, "GetPropertyBSTR returned 0x%08x, expected 0x%08x. On uri_tests[%d].str_props[%d].\n",
553 hr, prop.expected, i, j);
555 todo_wine {
556 ok(!strcmp_aw(prop.value, received), "Expected %s but got %s on uri_tests[%d].str_props[%d].\n",
557 prop.value, wine_dbgstr_w(received), i, j);
559 } else {
560 ok(hr == prop.expected, "GetPropertyBSTR returned 0x%08x, expected 0x%08x. On uri_tests[%d].str_props[%d].\n",
561 hr, prop.expected, i, j);
562 ok(!strcmp_aw(prop.value, received), "Expected %s but got %s on uri_tests[%d].str_props[%d].\n",
563 prop.value, wine_dbgstr_w(received), i, j);
566 SysFreeString(received);
570 if(uri) IUri_Release(uri);
572 heap_free(uriW);
576 static void test_IUri_GetPropertyDWORD(void) {
577 IUri *uri = NULL;
578 HRESULT hr;
579 DWORD i;
581 hr = pCreateUri(http_urlW, 0, 0, &uri);
582 ok(hr == S_OK, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
583 if(SUCCEEDED(hr)) {
584 DWORD received = 0xdeadbeef;
586 hr = IUri_GetPropertyDWORD(uri, Uri_PROPERTY_DWORD_START, NULL, 0);
587 ok(hr == E_INVALIDARG, "Error: GetPropertyDWORD returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
589 hr = IUri_GetPropertyDWORD(uri, Uri_PROPERTY_ABSOLUTE_URI, &received, 0);
590 ok(hr == E_INVALIDARG, "Error: GetPropertyDWORD returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
591 ok(received == 0, "Error: Expected received=%d but instead received=%d.\n", 0, received);
593 if(uri) IUri_Release(uri);
595 for(i = 0; i < sizeof(uri_tests)/sizeof(uri_tests[0]); ++i) {
596 uri_properties test = uri_tests[i];
597 LPWSTR uriW;
598 uri = NULL;
600 uriW = a2w(test.uri);
601 hr = pCreateUri(uriW, test.create_flags, 0, &uri);
602 if(test.create_todo) {
603 todo_wine {
604 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x. Failed on uri_tests[%d].\n",
605 hr, test.create_expected, i);
607 } else {
608 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x. Failed on uri_tests[%d].\n",
609 hr, test.create_expected, i);
612 if(SUCCEEDED(hr)) {
613 DWORD j;
615 /* Checks all the DWORD properties of the uri. */
616 for(j = 0; j < sizeof(test.dword_props)/sizeof(test.dword_props[0]); ++j) {
617 DWORD received;
618 uri_dword_property prop = test.dword_props[j];
620 hr = IUri_GetPropertyDWORD(uri, j+Uri_PROPERTY_DWORD_START, &received, 0);
621 if(prop.todo) {
622 todo_wine {
623 ok(hr == prop.expected, "GetPropertyDWORD returned 0x%08x, expected 0x%08x. On uri_tests[%d].dword_props[%d].\n",
624 hr, prop.expected, i, j);
626 todo_wine {
627 ok(prop.value == received, "Expected %d but got %d on uri_tests[%d].dword_props[%d].\n",
628 prop.value, received, i, j);
630 } else {
631 ok(hr == prop.expected, "GetPropertyDWORD returned 0x%08x, expected 0x%08x. On uri_tests[%d].dword_props[%d].\n",
632 hr, prop.expected, i, j);
633 ok(prop.value == received, "Expected %d but got %d on uri_tests[%d].dword_props[%d].\n",
634 prop.value, received, i, j);
639 if(uri) IUri_Release(uri);
641 heap_free(uriW);
645 /* Tests all the 'Get*' property functions which deal with strings. */
646 static void test_IUri_GetStrProperties(void) {
647 IUri *uri = NULL;
648 HRESULT hr;
649 DWORD i;
651 /* Make sure all the 'Get*' string property functions handle invalid args correctly. */
652 hr = pCreateUri(http_urlW, 0, 0, &uri);
653 ok(hr == S_OK, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
654 if(SUCCEEDED(hr)) {
655 hr = IUri_GetAbsoluteUri(uri, NULL);
656 ok(hr == E_POINTER, "Error: GetAbsoluteUri returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
658 hr = IUri_GetAuthority(uri, NULL);
659 ok(hr == E_POINTER, "Error: GetAuthority returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
661 hr = IUri_GetDisplayUri(uri, NULL);
662 ok(hr == E_POINTER, "Error: GetDisplayUri returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
664 hr = IUri_GetDomain(uri, NULL);
665 ok(hr == E_POINTER, "Error: GetDomain returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
667 hr = IUri_GetExtension(uri, NULL);
668 ok(hr == E_POINTER, "Error: GetExtension returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
670 hr = IUri_GetFragment(uri, NULL);
671 ok(hr == E_POINTER, "Error: GetFragment returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
673 hr = IUri_GetPassword(uri, NULL);
674 ok(hr == E_POINTER, "Error: GetPassword returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
676 hr = IUri_GetPath(uri, NULL);
677 ok(hr == E_POINTER, "Error: GetPath returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
679 hr = IUri_GetPathAndQuery(uri, NULL);
680 ok(hr == E_POINTER, "Error: GetPathAndQuery returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
682 hr = IUri_GetQuery(uri, NULL);
683 ok(hr == E_POINTER, "Error: GetQuery returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
685 hr = IUri_GetRawUri(uri, NULL);
686 ok(hr == E_POINTER, "Error: GetRawUri returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
688 hr = IUri_GetSchemeName(uri, NULL);
689 ok(hr == E_POINTER, "Error: GetSchemeName returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
691 hr = IUri_GetUserInfo(uri, NULL);
692 ok(hr == E_POINTER, "Error: GetUserInfo returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
694 hr = IUri_GetUserName(uri, NULL);
695 ok(hr == E_POINTER, "Error: GetUserName returned 0x%08x, expected 0x%08x.\n", hr, E_POINTER);
697 if(uri) IUri_Release(uri);
699 for(i = 0; i < sizeof(uri_tests)/sizeof(uri_tests[0]); ++i) {
700 uri_properties test = uri_tests[i];
701 LPWSTR uriW;
702 uri = NULL;
704 uriW = a2w(test.uri);
705 hr = pCreateUri(uriW, test.create_flags, 0, &uri);
706 if(test.create_todo) {
707 todo_wine {
708 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
709 hr, test.create_expected, i);
711 } else {
712 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
713 hr, test.create_expected, i);
716 if(SUCCEEDED(hr)) {
717 uri_str_property prop;
718 BSTR received = NULL;
720 /* GetAbsoluteUri() tests. */
721 prop = test.str_props[Uri_PROPERTY_ABSOLUTE_URI];
722 hr = IUri_GetAbsoluteUri(uri, &received);
723 if(prop.todo) {
724 todo_wine {
725 ok(hr == prop.expected, "Error: GetAbsoluteUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
726 hr, prop.expected, i);
728 todo_wine {
729 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
730 prop.value, wine_dbgstr_w(received), i);
732 } else {
733 ok(hr == prop.expected, "Error: GetAbsoluteUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
734 hr, prop.expected, i);
735 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
736 prop.value, wine_dbgstr_w(received), i);
738 SysFreeString(received);
739 received = NULL;
741 /* GetAuthority() tests. */
742 prop = test.str_props[Uri_PROPERTY_AUTHORITY];
743 hr = IUri_GetAuthority(uri, &received);
744 if(prop.todo) {
745 todo_wine {
746 ok(hr == prop.expected, "Error: GetAuthority returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
747 hr, prop.expected, i);
749 todo_wine {
750 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
751 prop.value, wine_dbgstr_w(received), i);
753 } else {
754 ok(hr == prop.expected, "Error: GetAuthority returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
755 hr, prop.expected, i);
756 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
757 prop.value, wine_dbgstr_w(received), i);
759 SysFreeString(received);
760 received = NULL;
762 /* GetDisplayUri() tests. */
763 prop = test.str_props[Uri_PROPERTY_DISPLAY_URI];
764 hr = IUri_GetDisplayUri(uri, &received);
765 if(prop.todo) {
766 todo_wine {
767 ok(hr == prop.expected, "Error: GetDisplayUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
768 hr, prop.expected, i);
770 todo_wine {
771 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_test[%d].\n",
772 prop.value, wine_dbgstr_w(received), i);
774 } else {
775 ok(hr == prop.expected, "Error: GetDisplayUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
776 hr, prop.expected, i);
777 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
778 prop.value, wine_dbgstr_w(received), i);
780 SysFreeString(received);
781 received = NULL;
783 /* GetDomain() tests. */
784 prop = test.str_props[Uri_PROPERTY_DOMAIN];
785 hr = IUri_GetDomain(uri, &received);
786 if(prop.todo) {
787 todo_wine {
788 ok(hr == prop.expected, "Error: GetDomain returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
789 hr, prop.expected, i);
791 todo_wine {
792 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
793 prop.value, wine_dbgstr_w(received), i);
795 } else {
796 ok(hr == prop.expected, "Error: GetDomain returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
797 hr, prop.expected, i);
798 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
799 prop.value, wine_dbgstr_w(received), i);
801 SysFreeString(received);
802 received = NULL;
804 /* GetExtension() tests. */
805 prop = test.str_props[Uri_PROPERTY_EXTENSION];
806 hr = IUri_GetExtension(uri, &received);
807 if(prop.todo) {
808 todo_wine {
809 ok(hr == prop.expected, "Error: GetExtension returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
810 hr, prop.expected, i);
812 todo_wine {
813 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
814 prop.value, wine_dbgstr_w(received), i);
816 } else {
817 ok(hr == prop.expected, "Error: GetExtension returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
818 hr, prop.expected, i);
819 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
820 prop.value, wine_dbgstr_w(received), i);
822 SysFreeString(received);
823 received = NULL;
825 /* GetFragment() tests. */
826 prop = test.str_props[Uri_PROPERTY_FRAGMENT];
827 hr = IUri_GetFragment(uri, &received);
828 if(prop.todo) {
829 todo_wine {
830 ok(hr == prop.expected, "Error: GetFragment returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
831 hr, prop.expected, i);
833 todo_wine {
834 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
835 prop.value, wine_dbgstr_w(received), i);
837 } else {
838 ok(hr == prop.expected, "Error: GetFragment returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
839 hr, prop.expected, i);
840 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
841 prop.value, wine_dbgstr_w(received), i);
843 SysFreeString(received);
844 received = NULL;
846 /* GetPassword() tests. */
847 prop = test.str_props[Uri_PROPERTY_PASSWORD];
848 hr = IUri_GetPassword(uri, &received);
849 if(prop.todo) {
850 todo_wine {
851 ok(hr == prop.expected, "Error: GetPassword returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
852 hr, prop.expected, i);
854 todo_wine {
855 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
856 prop.value, wine_dbgstr_w(received), i);
858 } else {
859 ok(hr == prop.expected, "Error: GetPassword returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
860 hr, prop.expected, i);
861 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
862 prop.value, wine_dbgstr_w(received), i);
864 SysFreeString(received);
865 received = NULL;
867 /* GetPath() tests. */
868 prop = test.str_props[Uri_PROPERTY_PATH];
869 hr = IUri_GetPath(uri, &received);
870 if(prop.todo) {
871 todo_wine {
872 ok(hr == prop.expected, "Error: GetPath returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
873 hr, prop.expected, i);
875 todo_wine {
876 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
877 prop.value, wine_dbgstr_w(received), i);
879 } else {
880 ok(hr == prop.expected, "Error: GetPath returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
881 hr, prop.expected, i);
882 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
883 prop.value, wine_dbgstr_w(received), i);
885 SysFreeString(received);
886 received = NULL;
888 /* GetPathAndQuery() tests. */
889 prop = test.str_props[Uri_PROPERTY_PATH_AND_QUERY];
890 hr = IUri_GetPathAndQuery(uri, &received);
891 if(prop.todo) {
892 todo_wine {
893 ok(hr == prop.expected, "Error: GetPathAndQuery returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
894 hr, prop.expected, i);
896 todo_wine {
897 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
898 prop.value, wine_dbgstr_w(received), i);
900 } else {
901 ok(hr == prop.expected, "Error: GetPathAndQuery returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
902 hr, prop.expected, i);
903 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
904 prop.value, wine_dbgstr_w(received), i);
906 SysFreeString(received);
907 received = NULL;
909 /* GetQuery() tests. */
910 prop = test.str_props[Uri_PROPERTY_QUERY];
911 hr = IUri_GetQuery(uri, &received);
912 if(prop.todo) {
913 todo_wine {
914 ok(hr == prop.expected, "Error: GetQuery returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
915 hr, prop.expected, i);
917 todo_wine {
918 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
919 prop.value, wine_dbgstr_w(received), i);
921 } else {
922 ok(hr == prop.expected, "Error: GetQuery returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
923 hr, prop.expected, i);
924 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
925 prop.value, wine_dbgstr_w(received), i);
927 SysFreeString(received);
928 received = NULL;
930 /* GetRawUri() tests. */
931 prop = test.str_props[Uri_PROPERTY_RAW_URI];
932 hr = IUri_GetRawUri(uri, &received);
933 if(prop.todo) {
934 todo_wine {
935 ok(hr == prop.expected, "Error: GetRawUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
936 hr, prop.expected, i);
938 todo_wine {
939 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
940 prop.value, wine_dbgstr_w(received), i);
942 } else {
943 ok(hr == prop.expected, "Error: GetRawUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
944 hr, prop.expected, i);
945 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
946 prop.value, wine_dbgstr_w(received), i);
948 SysFreeString(received);
949 received = NULL;
951 /* GetSchemeName() tests. */
952 prop = test.str_props[Uri_PROPERTY_SCHEME_NAME];
953 hr = IUri_GetSchemeName(uri, &received);
954 if(prop.todo) {
955 todo_wine {
956 ok(hr == prop.expected, "Error: GetSchemeName returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
957 hr, prop.expected, i);
959 todo_wine {
960 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
961 prop.value, wine_dbgstr_w(received), i);
963 } else {
964 ok(hr == prop.expected, "Error: GetSchemeName returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
965 hr, prop.expected, i);
966 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
967 prop.value, wine_dbgstr_w(received), i);
969 SysFreeString(received);
970 received = NULL;
972 /* GetUserInfo() tests. */
973 prop = test.str_props[Uri_PROPERTY_USER_INFO];
974 hr = IUri_GetUserInfo(uri, &received);
975 if(prop.todo) {
976 todo_wine {
977 ok(hr == prop.expected, "Error: GetUserInfo returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
978 hr, prop.expected, i);
980 todo_wine {
981 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
982 prop.value, wine_dbgstr_w(received), i);
984 } else {
985 ok(hr == prop.expected, "Error: GetUserInfo returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
986 hr, prop.expected, i);
987 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
988 prop.value, wine_dbgstr_w(received), i);
990 SysFreeString(received);
991 received = NULL;
993 /* GetUserName() tests. */
994 prop = test.str_props[Uri_PROPERTY_USER_NAME];
995 hr = IUri_GetUserName(uri, &received);
996 if(prop.todo) {
997 todo_wine {
998 ok(hr == prop.expected, "Error: GetUserName returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
999 hr, prop.expected, i);
1001 todo_wine {
1002 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
1003 prop.value, wine_dbgstr_w(received), i);
1005 } else {
1006 ok(hr == prop.expected, "Error: GetUserName returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1007 hr, prop.expected, i);
1008 ok(!strcmp_aw(prop.value, received), "Error: Expected %s but got %s on uri_tests[%d].\n",
1009 prop.value, wine_dbgstr_w(received), i);
1011 SysFreeString(received);
1014 if(uri) IUri_Release(uri);
1016 heap_free(uriW);
1020 static void test_IUri_GetDwordProperties(void) {
1021 IUri *uri = NULL;
1022 HRESULT hr;
1023 DWORD i;
1025 /* Make sure all the 'Get*' dword property functions handle invalid args correctly. */
1026 hr = pCreateUri(http_urlW, 0, 0, &uri);
1027 ok(hr == S_OK, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
1028 if(SUCCEEDED(hr)) {
1029 hr = IUri_GetHostType(uri, NULL);
1030 ok(hr == E_INVALIDARG, "Error: GetHostType returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
1032 hr = IUri_GetPort(uri, NULL);
1033 ok(hr == E_INVALIDARG, "Error: GetPort returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
1035 hr = IUri_GetScheme(uri, NULL);
1036 ok(hr == E_INVALIDARG, "Error: GetScheme returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
1038 hr = IUri_GetZone(uri, NULL);
1039 ok(hr == E_INVALIDARG, "Error: GetZone returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
1041 if(uri) IUri_Release(uri);
1043 for(i = 0; i < sizeof(uri_tests)/sizeof(uri_tests[0]); ++i) {
1044 uri_properties test = uri_tests[i];
1045 LPWSTR uriW;
1046 uri = NULL;
1048 uriW = a2w(test.uri);
1049 hr = pCreateUri(uriW, test.create_flags, 0, &uri);
1050 if(test.create_todo) {
1051 todo_wine {
1052 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1053 hr, test.create_expected, i);
1055 } else {
1056 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1057 hr, test.create_expected, i);
1060 if(SUCCEEDED(hr)) {
1061 uri_dword_property prop;
1062 DWORD received;
1064 /* Assign an insane value so tests don't accidentally pass when
1065 * they shouldn't!
1067 received = -9999999;
1069 /* GetHostType() tests. */
1070 prop = test.dword_props[Uri_PROPERTY_HOST_TYPE-Uri_PROPERTY_DWORD_START];
1071 hr = IUri_GetHostType(uri, &received);
1072 if(prop.todo) {
1073 todo_wine {
1074 ok(hr == prop.expected, "Error: GetHostType returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1075 hr, prop.expected, i);
1077 todo_wine {
1078 ok(received == prop.value, "Error: Expected %d but got %d on uri_tests[%d].\n", prop.value, received, i);
1080 } else {
1081 ok(hr == prop.expected, "Error: GetHostType returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1082 hr, prop.expected, i);
1083 ok(received == prop.value, "Error: Expected %d but got %d on uri_tests[%d].\n", prop.value, received, i);
1085 received = -9999999;
1087 /* GetPort() tests. */
1088 prop = test.dword_props[Uri_PROPERTY_PORT-Uri_PROPERTY_DWORD_START];
1089 hr = IUri_GetPort(uri, &received);
1090 if(prop.todo) {
1091 todo_wine {
1092 ok(hr == prop.expected, "Error: GetPort returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1093 hr, prop.expected, i);
1095 todo_wine {
1096 ok(received == prop.value, "Error: Expected %d but got %d on uri_tests[%d].\n", prop.value, received, i);
1098 } else {
1099 ok(hr == prop.expected, "Error: GetPort returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1100 hr, prop.expected, i);
1101 ok(received == prop.value, "Error: Expected %d but got %d on uri_tests[%d].\n", prop.value, received, i);
1103 received = -9999999;
1105 /* GetScheme() tests. */
1106 prop = test.dword_props[Uri_PROPERTY_SCHEME-Uri_PROPERTY_DWORD_START];
1107 hr = IUri_GetScheme(uri, &received);
1108 if(prop.todo) {
1109 todo_wine {
1110 ok(hr == prop.expected, "Error: GetScheme returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1111 hr, prop.expected, i);
1113 todo_wine {
1114 ok(received == prop.value, "Error: Expected %d but got %d on uri_tests[%d].\n", prop.value, received, i);
1116 } else {
1117 ok(hr == prop.expected, "Error: GetScheme returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1118 hr, prop.expected, i);
1119 ok(received == prop.value, "Error: Expected %d but got %d on uri_tests[%d].\n", prop.value, received, i);
1121 received = -9999999;
1123 /* GetZone() tests. */
1124 prop = test.dword_props[Uri_PROPERTY_ZONE-Uri_PROPERTY_DWORD_START];
1125 hr = IUri_GetZone(uri, &received);
1126 if(prop.todo) {
1127 todo_wine {
1128 ok(hr == prop.expected, "Error: GetZone returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1129 hr, prop.expected, i);
1131 todo_wine {
1132 ok(received == prop.value, "Error: Expected %d but got %d on uri_tests[%d].\n", prop.value, received, i);
1134 } else {
1135 ok(hr == prop.expected, "Error: GetZone returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1136 hr, prop.expected, i);
1137 ok(received == prop.value, "Error: Expected %d but got %d on uri_tests[%d].\n", prop.value, received, i);
1141 if(uri) IUri_Release(uri);
1143 heap_free(uriW);
1147 static void test_IUri_GetPropertyLength(void) {
1148 IUri *uri = NULL;
1149 HRESULT hr;
1150 DWORD i;
1152 /* Make sure it handles invalid args correctly. */
1153 hr = pCreateUri(http_urlW, 0, 0, &uri);
1154 ok(hr == S_OK, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
1155 if(SUCCEEDED(hr)) {
1156 DWORD received = 0xdeadbeef;
1158 hr = IUri_GetPropertyLength(uri, Uri_PROPERTY_STRING_START, NULL, 0);
1159 ok(hr == E_INVALIDARG, "Error: GetPropertyLength returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
1161 hr = IUri_GetPropertyLength(uri, Uri_PROPERTY_DWORD_START, &received, 0);
1162 ok(hr == E_INVALIDARG, "Error: GetPropertyLength return 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
1163 ok(received == 0xdeadbeef, "Error: Expected 0xdeadbeef but got 0x%08x.\n", received);
1165 if(uri) IUri_Release(uri);
1167 for(i = 0; i < sizeof(uri_tests)/sizeof(uri_tests[0]); ++i) {
1168 uri_properties test = uri_tests[i];
1169 LPWSTR uriW;
1170 uri = NULL;
1172 uriW = a2w(test.uri);
1173 hr = pCreateUri(uriW, test.create_flags, 0, &uri);
1174 if(test.create_todo) {
1175 todo_wine {
1176 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x on uri_tests[%d].\n",
1177 hr, test.create_expected, i);
1179 } else {
1180 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x on uri_test[%d].\n",
1181 hr, test.create_expected, i);
1184 if(SUCCEEDED(hr)) {
1185 DWORD j;
1187 for(j = Uri_PROPERTY_STRING_START; j <= Uri_PROPERTY_STRING_LAST; ++j) {
1188 DWORD expectedLen, receivedLen;
1189 uri_str_property prop = test.str_props[j];
1191 expectedLen = lstrlen(prop.value);
1193 /* This won't be neccessary once GetPropertyLength is implemented. */
1194 receivedLen = -1;
1196 hr = IUri_GetPropertyLength(uri, j, &receivedLen, 0);
1197 if(prop.todo) {
1198 todo_wine {
1199 ok(hr == prop.expected, "Error: GetPropertyLength returned 0x%08x, expected 0x%08x on uri_tests[%d].str_props[%d].\n",
1200 hr, prop.expected, i, j);
1202 todo_wine {
1203 ok(receivedLen == expectedLen, "Error: Expected a length of %d but got %d on uri_tests[%d].str_props[%d].\n",
1204 expectedLen, receivedLen, i, j);
1206 } else {
1207 ok(hr == prop.expected, "Error: GetPropertyLength returned 0x%08x, expected 0x%08x on uri_tests[%d].str_props[%d].\n",
1208 hr, prop.expected, i, j);
1209 ok(receivedLen == expectedLen, "Error: Expected a length of %d but got %d on uri_tests[%d].str_props[%d].\n",
1210 expectedLen, receivedLen, i, j);
1215 if(uri) IUri_Release(uri);
1217 heap_free(uriW);
1221 static void test_IUri_GetProperties(void) {
1222 IUri *uri = NULL;
1223 HRESULT hr;
1224 DWORD i;
1226 hr = pCreateUri(http_urlW, 0, 0, &uri);
1227 ok(hr == S_OK, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
1228 if(SUCCEEDED(hr)) {
1229 hr = IUri_GetProperties(uri, NULL);
1230 ok(hr == E_INVALIDARG, "Error: GetProperties returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
1232 if(uri) IUri_Release(uri);
1234 for(i = 0; i < sizeof(uri_tests)/sizeof(uri_tests[0]); ++i) {
1235 uri_properties test = uri_tests[i];
1236 LPWSTR uriW;
1237 uri = NULL;
1239 uriW = a2w(test.uri);
1240 hr = pCreateUri(uriW, test.create_flags, 0, &uri);
1241 if(test.create_todo) {
1242 todo_wine {
1243 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, test.create_expected);
1245 } else {
1246 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, test.create_expected);
1249 if(SUCCEEDED(hr)) {
1250 DWORD received = 0;
1251 DWORD j;
1253 hr = IUri_GetProperties(uri, &received);
1254 if(test.props_todo) {
1255 todo_wine {
1256 ok(hr == S_OK, "Error: GetProperties returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
1258 } else {
1259 ok(hr == S_OK, "Error: GetProperties returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
1262 for(j = 0; j <= Uri_PROPERTY_DWORD_LAST; ++j) {
1263 /* (1 << j) converts a Uri_PROPERTY to its corresponding Uri_HAS_* flag mask. */
1264 if(test.props & (1 << j)) {
1265 if(test.props_todo) {
1266 todo_wine {
1267 ok(received & (1 << j), "Error: Expected flag for property %d on uri_tests[%d].\n", j, i);
1269 } else {
1270 ok(received & (1 << j), "Error: Expected flag for property %d on uri_tests[%d].\n", j, i);
1272 } else {
1273 /* NOTE: Since received is initialized to 0, this test will always pass while
1274 * GetProperties is unimplemented.
1276 ok(!(received & (1 << j)), "Error: Received flag for property %d when not expected on uri_tests[%d].\n", j, i);
1281 if(uri) IUri_Release(uri);
1283 heap_free(uriW);
1287 static void test_IUri_HasProperty(void) {
1288 IUri *uri = NULL;
1289 HRESULT hr;
1290 DWORD i;
1292 hr = pCreateUri(http_urlW, 0, 0, &uri);
1293 ok(hr == S_OK, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, S_OK);
1294 if(SUCCEEDED(hr)) {
1295 hr = IUri_HasProperty(uri, Uri_PROPERTY_RAW_URI, NULL);
1296 ok(hr == E_INVALIDARG, "Error: HasProperty returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
1298 if(uri) IUri_Release(uri);
1300 for(i = 0; i < sizeof(uri_tests)/sizeof(uri_tests[0]); ++i) {
1301 uri_properties test = uri_tests[i];
1302 LPWSTR uriW;
1303 uri = NULL;
1305 uriW = a2w(test.uri);
1307 hr = pCreateUri(uriW, test.create_flags, 0, &uri);
1308 if(test.create_todo) {
1309 todo_wine {
1310 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, test.create_expected);
1312 } else {
1313 ok(hr == test.create_expected, "Error: CreateUri returned 0x%08x, expected 0x%08x.\n", hr, test.create_expected);
1316 if(SUCCEEDED(hr)) {
1317 DWORD j;
1319 for(j = 0; j <= Uri_PROPERTY_DWORD_LAST; ++j) {
1320 /* Assign -1, then explicitly test for TRUE or FALSE later. */
1321 BOOL received = -1;
1323 hr = IUri_HasProperty(uri, j, &received);
1324 if(test.props_todo) {
1325 todo_wine {
1326 ok(hr == S_OK, "Error: HasProperty returned 0x%08x, expected 0x%08x for property %d on uri_tests[%d].\n",
1327 hr, S_OK, j, i);
1330 /* Check if the property should be true. */
1331 if(test.props & (1 << j)) {
1332 todo_wine {
1333 ok(received == TRUE, "Error: Expected to have property %d on uri_tests[%d].\n", j, i);
1335 } else {
1336 todo_wine {
1337 ok(received == FALSE, "Error: Wasn't expecting to have property %d on uri_tests[%d].\n", j, i);
1340 } else {
1341 ok(hr == S_OK, "Error: HasProperty returned 0x%08x, expected 0x%08x for property %d on uri_tests[%d].\n",
1342 hr, S_OK, j, i);
1344 if(test.props & (1 << j)) {
1345 ok(received == TRUE, "Error: Expected to have property %d on uri_tests[%d].\n", j, i);
1346 } else {
1347 ok(received == FALSE, "Error: Wasn't expecting to have property %d on uri_tests[%d].\n", j, i);
1353 if(uri) IUri_Release(uri);
1355 heap_free(uriW);
1359 START_TEST(uri) {
1360 HMODULE hurlmon;
1362 hurlmon = GetModuleHandle("urlmon.dll");
1363 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
1365 if(!pCreateUri) {
1366 win_skip("CreateUri is not present, skipping tests.\n");
1367 return;
1370 trace("test CreateUri invalid flags...\n");
1371 test_CreateUri_InvalidFlags();
1373 trace("test CreateUri invalid args...\n");
1374 test_CreateUri_InvalidArgs();
1376 trace("test IUri_GetPropertyBSTR...\n");
1377 test_IUri_GetPropertyBSTR();
1379 trace("test IUri_GetPropertyDWORD...\n");
1380 test_IUri_GetPropertyDWORD();
1382 trace("test IUri_GetStrProperties...\n");
1383 test_IUri_GetStrProperties();
1385 trace("test IUri_GetDwordProperties...\n");
1386 test_IUri_GetDwordProperties();
1388 trace("test IUri_GetPropertyLength...\n");
1389 test_IUri_GetPropertyLength();
1391 trace("test IUri_GetProperties...\n");
1392 test_IUri_GetProperties();
1394 trace("test IUri_HasProperty...\n");
1395 test_IUri_HasProperty();