4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/test.h"
35 #define TEST_URL "http://www.winehq.org/site/about#hi"
36 #define TEST_URL3 "file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml"
38 #define CREATE_URL1 "http://username:password@www.winehq.org/site/about"
39 #define CREATE_URL2 "http://username@www.winehq.org/site/about"
40 #define CREATE_URL3 "http://username:"
41 #define CREATE_URL4 "http://www.winehq.org/site/about"
42 #define CREATE_URL5 "http://"
43 #define CREATE_URL6 "nhttp://username:password@www.winehq.org:80/site/about"
44 #define CREATE_URL7 "http://username:password@www.winehq.org:42/site/about"
45 #define CREATE_URL8 "https://username:password@www.winehq.org/site/about"
46 #define CREATE_URL9 "about:blank"
47 #define CREATE_URL10 "about://host/blank"
48 #define CREATE_URL11 "about:"
49 #define CREATE_URL12 "http://www.winehq.org:65535"
50 #define CREATE_URL13 "http://localhost/?test=123"
52 static void copy_compsA(
63 dst
->dwSchemeLength
= scheLen
;
64 dst
->dwHostNameLength
= hostLen
;
65 dst
->dwUserNameLength
= userLen
;
66 dst
->dwPasswordLength
= passLen
;
67 dst
->dwUrlPathLength
= pathLen
;
68 dst
->dwExtraInfoLength
= extrLen
;
69 SetLastError(0xfaceabad);
72 static void zero_compsA(
81 ZeroMemory(dst
, sizeof(URL_COMPONENTSA
));
82 dst
->dwStructSize
= sizeof(URL_COMPONENTSA
);
83 dst
->dwSchemeLength
= scheLen
;
84 dst
->dwHostNameLength
= hostLen
;
85 dst
->dwUserNameLength
= userLen
;
86 dst
->dwPasswordLength
= passLen
;
87 dst
->dwUrlPathLength
= pathLen
;
88 dst
->dwExtraInfoLength
= extrLen
;
89 SetLastError(0xfaceabad);
96 INTERNET_SCHEME scheme
;
109 const char *exp_scheme
;
110 const char *exp_hostname
;
111 const char *exp_username
;
112 const char *exp_password
;
113 const char *exp_urlpath
;
114 const char *exp_extrainfo
;
117 static const crack_url_test_t crack_url_tests
[] = {
118 {"http://www.winehq.org/site/about#hi",
119 0, 4, INTERNET_SCHEME_HTTP
, 7, 14, -1, 80, -1, 0, -1, 0, 21, 11, 32, 3,
120 "http", "www.winehq.org", "", "", "/site/about", "#hi"},
121 {"http://www.myserver.com/myscript.php?arg=1",
122 0, 4, INTERNET_SCHEME_HTTP
, 7, 16, -1, 80, -1, 0, -1, 0, 23, 13, 36, 6,
123 "http", "www.myserver.com", "", "", "/myscript.php", "?arg=1"},
124 {"http://www.winehq.org?test=123",
125 0, 4, INTERNET_SCHEME_HTTP
, 7, 14, 23, 80, -1, 0, -1, 0, 21, 0, 21, 9,
126 "http", "www.winehq.org", "", "", "", "?test=123"},
127 {"file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
128 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 55, -1, 0,
129 "file", "", "", "", "C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", ""},
130 {"fide:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
131 0, 4, INTERNET_SCHEME_UNKNOWN
, 7, 0, -1, 0, -1, 0, -1, 0, 7, 55, -1, 0,
132 "fide", "", "", "", "/C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", ""},
133 {"file://C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
134 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 54, -1, 0,
135 "file", "", "", "", "C:\\Program%20Files\\Atmel\\AVR%20Tools\\STK500\\STK500.xml", ""},
136 {"file://C:/Program%20Files/Atmel/..",
137 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 27, -1, 0,
138 "file", "", "", "", "C:\\Program%20Files\\Atmel\\..\\", ""},
139 {"file://C:/Program%20Files/Atmel/../Asdf.xml",
140 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 36, -1, 0,
141 "file", "", "", "", "C:\\Program%20Files\\Atmel\\..\\Asdf.xml", ""},
142 {"file:///C:/Program%20Files/Atmel/..",
143 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 28, -1, 0,
144 "file", "", "", "", "C:\\Program Files\\Atmel\\..\\", ""},
145 {"file:///C:/Program%20Files/Atmel/../Asdf.xml",
146 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 37, -1, 0,
147 "file", "", "", "", "C:\\Program Files\\Atmel\\..\\Asdf.xml", ""},
148 {"file://C:/Program%20Files/Atmel/.",
149 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 26, -1, 0,
150 "file", "", "", "", "C:\\Program%20Files\\Atmel\\.\\", ""},
151 {"file://C:/Program%20Files/Atmel/./Asdf.xml",
152 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 35, -1, 0,
153 "file", "", "", "", "C:\\Program%20Files\\Atmel\\.\\Asdf.xml", ""},
154 {"file:///C:/Program%20Files/Atmel/.",
155 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 27, -1, 0,
156 "file", "", "", "", "C:\\Program Files\\Atmel\\.\\", ""},
157 {"file:///C:/Program%20Files/Atmel/./Asdf.xml",
158 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 36, -1, 0,
159 "file", "", "", "", "C:\\Program Files\\Atmel\\.\\Asdf.xml", ""},
162 static const WCHAR
*w_str_of(const char *str
)
164 static WCHAR buf
[512];
165 MultiByteToWideChar(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
)/sizeof(buf
[0]));
169 static void test_crack_url(const crack_url_test_t
*test
)
171 WCHAR buf
[INTERNET_MAX_URL_LENGTH
];
172 URL_COMPONENTSW urlw
;
174 char scheme
[32], hostname
[1024], username
[1024];
175 char password
[1024], extrainfo
[1024], urlpath
[1024];
178 /* test InternetCrackUrlA with NULL buffers */
179 zero_compsA(&url
, 1, 1, 1, 1, 1, 1);
181 b
= InternetCrackUrlA(test
->url
, strlen(test
->url
), 0, &url
);
182 ok(b
, "InternetCrackUrl failed with error %d\n", GetLastError());
184 if(test
->scheme_off
== -1)
185 ok(!url
.lpszScheme
, "[%s] url.lpszScheme = %p, expected NULL\n", test
->url
, url
.lpszScheme
);
187 ok(url
.lpszScheme
== test
->url
+test
->scheme_off
, "[%s] url.lpszScheme = %p, expected %p\n",
188 test
->url
, url
.lpszScheme
, test
->url
+test
->scheme_off
);
189 ok(url
.dwSchemeLength
== test
->scheme_len
, "[%s] url.lpszSchemeLength = %d, expected %d\n",
190 test
->url
, url
.dwSchemeLength
, test
->scheme_len
);
192 ok(url
.nScheme
== test
->scheme
, "[%s] url.nScheme = %d, expected %d\n", test
->url
, url
.nScheme
, test
->scheme
);
194 if(test
->host_off
== -1)
195 ok(!url
.lpszHostName
, "[%s] url.lpszHostName = %p, expected NULL\n", test
->url
, url
.lpszHostName
);
197 ok(url
.lpszHostName
== test
->url
+test
->host_off
, "[%s] url.lpszHostName = %p, expected %p\n",
198 test
->url
, url
.lpszHostName
, test
->url
+test
->host_off
);
199 if(test
->host_skip_broken
!= -1 && url
.dwHostNameLength
== test
->host_skip_broken
) {
200 win_skip("skipping broken dwHostNameLength result\n");
203 ok(url
.dwHostNameLength
== test
->host_len
, "[%s] url.lpszHostNameLength = %d, expected %d\n",
204 test
->url
, url
.dwHostNameLength
, test
->host_len
);
206 ok(url
.nPort
== test
->port
, "[%s] nPort = %d, expected %d\n", test
->url
, url
.nPort
, test
->port
);
208 if(test
->user_off
== -1)
209 ok(!url
.lpszUserName
, "[%s] url.lpszUserName = %p\n", test
->url
, url
.lpszUserName
);
211 ok(url
.lpszUserName
== test
->url
+test
->user_off
, "[%s] url.lpszUserName = %p, expected %p\n",
212 test
->url
, url
.lpszUserName
, test
->url
+test
->user_off
);
213 ok(url
.dwUserNameLength
== test
->user_len
, "[%s] url.lpszUserNameLength = %d, expected %d\n",
214 test
->url
, url
.dwUserNameLength
, test
->user_len
);
216 if(test
->pass_off
== -1)
217 ok(!url
.lpszPassword
, "[%s] url.lpszPassword = %p\n", test
->url
, url
.lpszPassword
);
219 ok(url
.lpszPassword
== test
->url
+test
->pass_off
, "[%s] url.lpszPassword = %p, expected %p\n",
220 test
->url
, url
.lpszPassword
, test
->url
+test
->pass_off
);
221 ok(url
.dwPasswordLength
== test
->pass_len
, "[%s] url.lpszPasswordLength = %d, expected %d\n",
222 test
->url
, url
.dwPasswordLength
, test
->pass_len
);
224 if(test
->path_off
== -1)
225 ok(!url
.lpszUrlPath
, "[%s] url.lpszPath = %p, expected NULL\n", test
->url
, url
.lpszUrlPath
);
227 ok(url
.lpszUrlPath
== test
->url
+test
->path_off
, "[%s] url.lpszPath = %p, expected %p\n",
228 test
->url
, url
.lpszUrlPath
, test
->url
+test
->path_off
);
229 ok(url
.dwUrlPathLength
== test
->path_len
, "[%s] url.lpszUrlPathLength = %d, expected %d\n",
230 test
->url
, url
.dwUrlPathLength
, test
->path_len
);
232 if(test
->extra_off
== -1)
233 ok(!url
.lpszExtraInfo
, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test
->url
, url
.lpszExtraInfo
);
235 ok(url
.lpszExtraInfo
== test
->url
+test
->extra_off
, "[%s] url.lpszExtraInfo = %p, expected %p\n",
236 test
->url
, url
.lpszExtraInfo
, test
->url
+test
->extra_off
);
237 ok(url
.dwExtraInfoLength
== test
->extra_len
, "[%s] url.lpszExtraInfoLength = %d, expected %d\n",
238 test
->url
, url
.dwExtraInfoLength
, test
->extra_len
);
240 /* test InternetCrackUrlW with NULL buffers */
241 memset(&urlw
, 0, sizeof(URL_COMPONENTSW
));
242 urlw
.dwStructSize
= sizeof(URL_COMPONENTSW
);
243 urlw
.dwSchemeLength
= 1;
244 urlw
.dwHostNameLength
= 1;
245 urlw
.dwUserNameLength
= 1;
246 urlw
.dwPasswordLength
= 1;
247 urlw
.dwUrlPathLength
= 1;
248 urlw
.dwExtraInfoLength
= 1;
250 MultiByteToWideChar(CP_ACP
, 0, test
->url
, -1, buf
, sizeof(buf
)/sizeof(buf
[0]));
251 b
= InternetCrackUrlW(buf
, lstrlenW(buf
), 0, &urlw
);
252 if(!b
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
) {
253 win_skip("InternetCrackUrlW is not implemented\n");
256 ok(b
, "InternetCrackUrl failed with error %d\n", GetLastError());
258 if(test
->scheme_off
== -1)
259 ok(!urlw
.lpszScheme
, "[%s] urlw.lpszScheme = %p, expected NULL\n", test
->url
, urlw
.lpszScheme
);
261 ok(urlw
.lpszScheme
== buf
+test
->scheme_off
, "[%s] urlw.lpszScheme = %p, expected %p\n",
262 test
->url
, urlw
.lpszScheme
, buf
+test
->scheme_off
);
263 ok(urlw
.dwSchemeLength
== test
->scheme_len
, "[%s] urlw.lpszSchemeLength = %d, expected %d\n",
264 test
->url
, urlw
.dwSchemeLength
, test
->scheme_len
);
266 ok(urlw
.nScheme
== test
->scheme
, "[%s] urlw.nScheme = %d, expected %d\n", test
->url
, urlw
.nScheme
, test
->scheme
);
268 if(test
->host_off
== -1) {
269 ok(!urlw
.lpszHostName
, "[%s] urlw.lpszHostName = %p, expected NULL\n", test
->url
, urlw
.lpszHostName
);
270 ok(urlw
.dwHostNameLength
== 0 || broken(urlw
.dwHostNameLength
== 1), "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
271 test
->url
, urlw
.dwHostNameLength
, test
->host_len
);
273 ok(urlw
.lpszHostName
== buf
+test
->host_off
, "[%s] urlw.lpszHostName = %p, expected %p\n",
274 test
->url
, urlw
.lpszHostName
, test
->url
+test
->host_off
);
275 ok(urlw
.dwHostNameLength
== test
->host_len
, "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
276 test
->url
, urlw
.dwHostNameLength
, test
->host_len
);
279 ok(urlw
.nPort
== test
->port
, "[%s] nPort = %d, expected %d\n", test
->url
, urlw
.nPort
, test
->port
);
281 if(test
->user_off
== -1) {
282 ok(!urlw
.lpszUserName
, "[%s] urlw.lpszUserName = %p\n", test
->url
, urlw
.lpszUserName
);
283 ok(urlw
.dwUserNameLength
== 0 || broken(urlw
.dwUserNameLength
== 1), "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
284 test
->url
, urlw
.dwUserNameLength
, test
->user_len
);
286 ok(urlw
.lpszUserName
== buf
+test
->user_off
, "[%s] urlw.lpszUserName = %p, expected %p\n",
287 test
->url
, urlw
.lpszUserName
, buf
+test
->user_off
);
288 ok(urlw
.dwUserNameLength
== test
->user_len
, "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
289 test
->url
, urlw
.dwUserNameLength
, test
->user_len
);
292 if(test
->pass_off
== -1) {
293 ok(!urlw
.lpszPassword
, "[%s] urlw.lpszPassword = %p\n", test
->url
, urlw
.lpszPassword
);
294 ok(urlw
.dwPasswordLength
== 0 || broken(urlw
.dwPasswordLength
), "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
295 test
->url
, urlw
.dwPasswordLength
, test
->pass_len
);
297 ok(urlw
.lpszPassword
== buf
+test
->pass_off
, "[%s] urlw.lpszPassword = %p, expected %p\n",
298 test
->url
, urlw
.lpszPassword
, buf
+test
->pass_off
);
299 ok(urlw
.dwPasswordLength
== test
->pass_len
, "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
300 test
->url
, urlw
.dwPasswordLength
, test
->pass_len
);
303 if(test
->path_off
== -1)
304 ok(!urlw
.lpszUrlPath
, "[%s] urlw.lpszPath = %p, expected NULL\n", test
->url
, urlw
.lpszUrlPath
);
306 ok(urlw
.lpszUrlPath
== buf
+test
->path_off
, "[%s] urlw.lpszPath = %p, expected %p\n",
307 test
->url
, urlw
.lpszUrlPath
, buf
+test
->path_off
);
308 ok(urlw
.dwUrlPathLength
== test
->path_len
, "[%s] urlw.lpszUrlPathLength = %d, expected %d\n",
309 test
->url
, urlw
.dwUrlPathLength
, test
->path_len
);
311 if(test
->extra_off
== -1) {
312 ok(!urlw
.lpszExtraInfo
, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test
->url
, urlw
.lpszExtraInfo
);
313 ok(urlw
.dwExtraInfoLength
== 0 || broken(urlw
.dwExtraInfoLength
== 1), "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
314 test
->url
, urlw
.dwExtraInfoLength
, test
->extra_len
);
316 ok(urlw
.lpszExtraInfo
== buf
+test
->extra_off
, "[%s] urlw.lpszExtraInfo = %p, expected %p\n",
317 test
->url
, urlw
.lpszExtraInfo
, buf
+test
->extra_off
);
318 ok(urlw
.dwExtraInfoLength
== test
->extra_len
, "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
319 test
->url
, urlw
.dwExtraInfoLength
, test
->extra_len
);
322 /* test InternetCrackUrlA with valid buffers */
323 memset(&url
, 0, sizeof(URL_COMPONENTSA
));
324 url
.dwStructSize
= sizeof(URL_COMPONENTSA
);
325 url
.lpszScheme
= scheme
;
326 url
.dwSchemeLength
= sizeof(scheme
);
327 url
.lpszHostName
= hostname
;
328 url
.dwHostNameLength
= sizeof(hostname
);
329 url
.lpszUserName
= username
;
330 url
.dwUserNameLength
= sizeof(username
);
331 url
.lpszPassword
= password
;
332 url
.dwPasswordLength
= sizeof(password
);
333 url
.lpszUrlPath
= urlpath
;
334 url
.dwUrlPathLength
= sizeof(urlpath
);
335 url
.lpszExtraInfo
= extrainfo
;
336 url
.dwExtraInfoLength
= sizeof(extrainfo
);
338 b
= InternetCrackUrlA(test
->url
, strlen(test
->url
), 0, &url
);
339 ok(b
, "InternetCrackUrlA failed with error %d\n", GetLastError());
341 ok(url
.dwSchemeLength
== strlen(test
->exp_scheme
), "[%s] Got wrong scheme length: %d\n",
342 test
->url
, url
.dwSchemeLength
);
343 ok(!strcmp(scheme
, test
->exp_scheme
), "[%s] Got wrong scheme, expected: %s, got: %s\n",
344 test
->url
, test
->exp_scheme
, scheme
);
346 ok(url
.nScheme
== test
->scheme
, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
347 test
->url
, test
->scheme
, url
.nScheme
);
349 ok(url
.dwHostNameLength
== strlen(test
->exp_hostname
), "[%s] Got wrong hostname length: %d\n",
350 test
->url
, url
.dwHostNameLength
);
351 ok(!strcmp(hostname
, test
->exp_hostname
), "[%s] Got wrong hostname, expected: %s, got: %s\n",
352 test
->url
, test
->exp_hostname
, hostname
);
354 ok(url
.nPort
== test
->port
, "[%s] Got wrong port, expected: %d, got: %d\n",
355 test
->url
, test
->port
, url
.nPort
);
357 ok(url
.dwUserNameLength
== strlen(test
->exp_username
), "[%s] Got wrong username length: %d\n",
358 test
->url
, url
.dwUserNameLength
);
359 ok(!strcmp(username
, test
->exp_username
), "[%s] Got wrong username, expected: %s, got: %s\n",
360 test
->url
, test
->exp_username
, username
);
362 ok(url
.dwPasswordLength
== strlen(test
->exp_password
), "[%s] Got wrong password length: %d\n",
363 test
->url
, url
.dwPasswordLength
);
364 ok(!strcmp(password
, test
->exp_password
), "[%s] Got wrong password, expected: %s, got: %s\n",
365 test
->url
, test
->exp_password
, password
);
367 ok(url
.dwUrlPathLength
== strlen(test
->exp_urlpath
), "[%s] Got wrong urlpath length: %d\n",
368 test
->url
, url
.dwUrlPathLength
);
369 ok(!strcmp(urlpath
, test
->exp_urlpath
), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
370 test
->url
, test
->exp_urlpath
, urlpath
);
372 ok(url
.dwExtraInfoLength
== strlen(test
->exp_extrainfo
), "[%s] Got wrong extrainfo length: %d\n",
373 test
->url
, url
.dwExtraInfoLength
);
374 ok(!strcmp(extrainfo
, test
->exp_extrainfo
), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
375 test
->url
, test
->exp_extrainfo
, extrainfo
);
377 /* test InternetCrackUrlW with valid buffers */
378 memset(&urlw
, 0, sizeof(URL_COMPONENTSW
));
379 urlw
.dwStructSize
= sizeof(URL_COMPONENTSW
);
380 urlw
.lpszScheme
= (WCHAR
*)scheme
;
381 urlw
.dwSchemeLength
= sizeof(scheme
) / sizeof(WCHAR
);
382 urlw
.lpszHostName
= (WCHAR
*)hostname
;
383 urlw
.dwHostNameLength
= sizeof(hostname
) / sizeof(WCHAR
);
384 urlw
.lpszUserName
= (WCHAR
*)username
;
385 urlw
.dwUserNameLength
= sizeof(username
) / sizeof(WCHAR
);
386 urlw
.lpszPassword
= (WCHAR
*)password
;
387 urlw
.dwPasswordLength
= sizeof(password
) / sizeof(WCHAR
);
388 urlw
.lpszUrlPath
= (WCHAR
*)urlpath
;
389 urlw
.dwUrlPathLength
= sizeof(urlpath
) / sizeof(WCHAR
);
390 urlw
.lpszExtraInfo
= (WCHAR
*)extrainfo
;
391 urlw
.dwExtraInfoLength
= sizeof(extrainfo
) / sizeof(WCHAR
);
393 b
= InternetCrackUrlW(buf
, lstrlenW(buf
), 0, &urlw
);
394 ok(b
, "InternetCrackUrlW failed with error %d\n", GetLastError());
396 ok(urlw
.dwSchemeLength
== strlen(test
->exp_scheme
), "[%s] Got wrong scheme length: %d\n",
397 test
->url
, urlw
.dwSchemeLength
);
398 ok(!lstrcmpW((WCHAR
*)scheme
, w_str_of(test
->exp_scheme
)), "[%s] Got wrong scheme, expected: %s, got: %s\n",
399 test
->url
, test
->exp_scheme
, wine_dbgstr_w((WCHAR
*)scheme
));
401 ok(urlw
.nScheme
== test
->scheme
, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
402 test
->url
, test
->scheme
, urlw
.nScheme
);
404 ok(urlw
.dwHostNameLength
== strlen(test
->exp_hostname
), "[%s] Got wrong hostname length: %d\n",
405 test
->url
, urlw
.dwHostNameLength
);
406 ok(!lstrcmpW((WCHAR
*)hostname
, w_str_of(test
->exp_hostname
)), "[%s] Got wrong hostname, expected: %s, got: %s\n",
407 test
->url
, test
->exp_hostname
, wine_dbgstr_w((WCHAR
*)hostname
));
409 ok(urlw
.nPort
== test
->port
, "[%s] Got wrong port, expected: %d, got: %d\n",
410 test
->url
, test
->port
, urlw
.nPort
);
412 ok(urlw
.dwUserNameLength
== strlen(test
->exp_username
), "[%s] Got wrong username length: %d\n",
413 test
->url
, urlw
.dwUserNameLength
);
414 ok(!lstrcmpW((WCHAR
*)username
, w_str_of(test
->exp_username
)), "[%s] Got wrong username, expected: %s, got: %s\n",
415 test
->url
, test
->exp_username
, wine_dbgstr_w((WCHAR
*)username
));
417 ok(urlw
.dwPasswordLength
== strlen(test
->exp_password
), "[%s] Got wrong password length: %d\n",
418 test
->url
, urlw
.dwPasswordLength
);
419 ok(!lstrcmpW((WCHAR
*)password
, w_str_of(test
->exp_password
)), "[%s] Got wrong password, expected: %s, got: %s\n",
420 test
->url
, test
->exp_password
, wine_dbgstr_w((WCHAR
*)password
));
422 ok(urlw
.dwUrlPathLength
== strlen(test
->exp_urlpath
), "[%s] Got wrong urlpath length: %d\n",
423 test
->url
, urlw
.dwUrlPathLength
);
424 ok(!lstrcmpW((WCHAR
*)urlpath
, w_str_of(test
->exp_urlpath
)), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
425 test
->url
, test
->exp_urlpath
, wine_dbgstr_w((WCHAR
*)urlpath
));
427 ok(urlw
.dwExtraInfoLength
== strlen(test
->exp_extrainfo
), "[%s] Got wrong extrainfo length: %d\n",
428 test
->url
, urlw
.dwExtraInfoLength
);
429 ok(!lstrcmpW((WCHAR
*)extrainfo
, w_str_of(test
->exp_extrainfo
)), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
430 test
->url
, test
->exp_extrainfo
, wine_dbgstr_w((WCHAR
*)extrainfo
));
433 static void InternetCrackUrl_test(void)
435 URL_COMPONENTSA urlSrc
, urlComponents
;
436 char protocol
[32], hostName
[1024], userName
[1024];
437 char password
[1024], extra
[1024], path
[1024];
441 ZeroMemory(&urlSrc
, sizeof(urlSrc
));
442 urlSrc
.dwStructSize
= sizeof(urlSrc
);
443 urlSrc
.lpszScheme
= protocol
;
444 urlSrc
.lpszHostName
= hostName
;
445 urlSrc
.lpszUserName
= userName
;
446 urlSrc
.lpszPassword
= password
;
447 urlSrc
.lpszUrlPath
= path
;
448 urlSrc
.lpszExtraInfo
= extra
;
450 /* Tests for lpsz* members pointing to real strings while
451 * some corresponding length members are set to zero.
452 * As of IE7 (wininet 7.0*?) all members are checked. So we
453 * run the first test and expect the outcome to be the same
454 * for the first four (scheme, hostname, username and password).
455 * The last two (path and extrainfo) are the same for all versions
456 * of the wininet.dll.
458 copy_compsA(&urlSrc
, &urlComponents
, 0, 1024, 1024, 1024, 2048, 1024);
459 SetLastError(0xdeadbeef);
460 firstret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
461 firstGLE
= GetLastError();
463 copy_compsA(&urlSrc
, &urlComponents
, 32, 0, 1024, 1024, 2048, 1024);
464 SetLastError(0xdeadbeef);
465 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
466 GLE
= GetLastError();
467 ok(ret
==firstret
&& (GLE
==firstGLE
), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
470 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 0, 1024, 2048, 1024);
471 SetLastError(0xdeadbeef);
472 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
473 GLE
= GetLastError();
474 ok(ret
==firstret
&& (GLE
==firstGLE
), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
477 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 0, 2048, 1024);
478 SetLastError(0xdeadbeef);
479 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
480 GLE
= GetLastError();
481 ok(ret
==firstret
&& (GLE
==firstGLE
), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
484 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 0, 1024);
485 SetLastError(0xdeadbeef);
486 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
487 GLE
= GetLastError();
489 ok(ret
==0 && (GLE
==ERROR_INVALID_HANDLE
|| GLE
==ERROR_INSUFFICIENT_BUFFER
),
490 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
493 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 2048, 0);
494 SetLastError(0xdeadbeef);
495 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
496 GLE
= GetLastError();
498 ok(ret
==0 && (GLE
==ERROR_INVALID_HANDLE
|| GLE
==ERROR_INSUFFICIENT_BUFFER
),
499 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
502 copy_compsA(&urlSrc
, &urlComponents
, 0, 0, 0, 0, 0, 0);
503 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
504 GLE
= GetLastError();
506 ok(ret
==0 && GLE
==ERROR_INVALID_PARAMETER
,
507 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
510 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 2048, 1024);
511 ret
= InternetCrackUrl("about://host/blank", 0,0,&urlComponents
);
512 ok(ret
, "InternetCrackUrl failed with %d\n", GetLastError());
513 ok(!strcmp(urlComponents
.lpszScheme
, "about"), "lpszScheme was \"%s\" instead of \"about\"\n", urlComponents
.lpszScheme
);
514 ok(!strcmp(urlComponents
.lpszHostName
, "host"), "lpszHostName was \"%s\" instead of \"host\"\n", urlComponents
.lpszHostName
);
515 ok(!strcmp(urlComponents
.lpszUrlPath
, "/blank"), "lpszUrlPath was \"%s\" instead of \"/blank\"\n", urlComponents
.lpszUrlPath
);
517 /* try a NULL lpszUrl */
518 SetLastError(0xdeadbeef);
519 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 2048, 1024);
520 ret
= InternetCrackUrl(NULL
, 0, 0, &urlComponents
);
521 GLE
= GetLastError();
522 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
523 ok(GLE
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", GLE
);
525 /* try an empty lpszUrl, GetLastError returns 12006, whatever that means
526 * we just need to fail and not return success
528 SetLastError(0xdeadbeef);
529 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 2048, 1024);
530 ret
= InternetCrackUrl("", 0, 0, &urlComponents
);
531 GLE
= GetLastError();
532 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
533 ok(GLE
!= 0xdeadbeef && GLE
!= ERROR_SUCCESS
, "Expected GLE to represent a failure\n");
535 /* Invalid Call: must set size of components structure (Windows only
536 * enforces this on the InternetCrackUrlA version of the call) */
537 copy_compsA(&urlSrc
, &urlComponents
, 0, 1024, 1024, 1024, 2048, 1024);
538 SetLastError(0xdeadbeef);
539 urlComponents
.dwStructSize
= 0;
540 ret
= InternetCrackUrlA(TEST_URL
, 0, 0, &urlComponents
);
541 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
542 ok(GLE
!= 0xdeadbeef && GLE
!= ERROR_SUCCESS
, "Expected GLE to represent a failure\n");
544 /* Invalid Call: size of dwStructSize must be one of the "standard" sizes
545 * of the URL_COMPONENTS structure (Windows only enforces this on the
546 * InternetCrackUrlA version of the call) */
547 copy_compsA(&urlSrc
, &urlComponents
, 0, 1024, 1024, 1024, 2048, 1024);
548 SetLastError(0xdeadbeef);
549 urlComponents
.dwStructSize
= sizeof(urlComponents
) + 1;
550 ret
= InternetCrackUrlA(TEST_URL
, 0, 0, &urlComponents
);
551 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
552 ok(GLE
!= 0xdeadbeef && GLE
!= ERROR_SUCCESS
, "Expected GLE to represent a failure\n");
555 static void InternetCrackUrlW_test(void)
558 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
559 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
560 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
562 static const WCHAR url2
[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
563 static const WCHAR url3
[] = { 'h','t','t','p',':','/','/','x','.','o','r','g',0 };
564 URL_COMPONENTSW comp
;
565 WCHAR scheme
[20], host
[20], user
[20], pwd
[20], urlpart
[50], extra
[50];
575 memset(&comp
, 0, sizeof comp
);
576 comp
.dwStructSize
= sizeof(comp
);
577 comp
.lpszScheme
= scheme
;
578 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
579 comp
.lpszHostName
= host
;
580 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
581 comp
.lpszUserName
= user
;
582 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
583 comp
.lpszPassword
= pwd
;
584 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
585 comp
.lpszUrlPath
= urlpart
;
586 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
587 comp
.lpszExtraInfo
= extra
;
588 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
590 SetLastError(0xdeadbeef);
591 r
= InternetCrackUrlW(NULL
, 0, 0, &comp
);
592 error
= GetLastError();
593 if (!r
&& error
== ERROR_CALL_NOT_IMPLEMENTED
)
595 win_skip("InternetCrackUrlW is not implemented\n");
598 ok( !r
, "InternetCrackUrlW succeeded unexpectedly\n");
599 ok( error
== ERROR_INVALID_PARAMETER
||
600 broken(error
== ERROR_INTERNET_UNRECOGNIZED_SCHEME
), /* IE5 */
601 "expected ERROR_INVALID_PARAMETER got %u\n", error
);
603 if (error
== ERROR_INVALID_PARAMETER
)
606 SetLastError(0xdeadbeef);
607 r
= InternetCrackUrlW(url
, 0, 0, NULL
);
608 error
= GetLastError();
609 ok( !r
, "InternetCrackUrlW succeeded unexpectedly\n");
610 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
613 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
614 ok( r
, "failed to crack url\n");
615 ok( comp
.dwSchemeLength
== 4, "scheme length wrong\n");
616 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
617 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
618 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
619 ok( comp
.dwUrlPathLength
== 15, "url length wrong\n");
620 ok( comp
.dwExtraInfoLength
== 29, "extra length wrong\n");
628 memset(&comp
, 0, sizeof comp
);
629 comp
.dwStructSize
= sizeof comp
;
630 comp
.lpszHostName
= host
;
631 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
632 comp
.lpszUrlPath
= urlpart
;
633 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
635 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
636 ok( r
, "failed to crack url\n");
637 ok( comp
.dwSchemeLength
== 0, "scheme length wrong\n");
638 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
639 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
640 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
641 ok( comp
.dwUrlPathLength
== 44, "url length wrong\n");
642 ok( comp
.dwExtraInfoLength
== 0, "extra length wrong\n");
650 memset(&comp
, 0, sizeof comp
);
651 comp
.dwStructSize
= sizeof comp
;
652 comp
.lpszHostName
= host
;
653 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
654 comp
.lpszUrlPath
= urlpart
;
655 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
656 comp
.lpszExtraInfo
= NULL
;
657 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
659 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
660 ok( r
, "failed to crack url\n");
661 ok( comp
.dwSchemeLength
== 0, "scheme length wrong\n");
662 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
663 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
664 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
665 ok( comp
.dwUrlPathLength
== 15, "url length wrong\n");
666 ok( comp
.dwExtraInfoLength
== 29, "extra length wrong\n");
674 memset(&comp
, 0, sizeof(comp
));
675 comp
.dwStructSize
= sizeof(comp
);
676 comp
.lpszScheme
= scheme
;
677 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
678 comp
.lpszHostName
= host
;
679 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
680 comp
.lpszUserName
= user
;
681 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
682 comp
.lpszPassword
= pwd
;
683 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
684 comp
.lpszUrlPath
= urlpart
;
685 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
686 comp
.lpszExtraInfo
= extra
;
687 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
689 r
= InternetCrackUrlW(url2
, 0, 0, &comp
);
691 ok(!r
, "InternetCrackUrl should have failed\n");
692 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
,
693 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
697 /* Test to see whether cracking a URL without a filename initializes urlpart */
704 memset(&comp
, 0, sizeof comp
);
705 comp
.dwStructSize
= sizeof comp
;
706 comp
.lpszScheme
= scheme
;
707 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
708 comp
.lpszHostName
= host
;
709 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
710 comp
.lpszUserName
= user
;
711 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
712 comp
.lpszPassword
= pwd
;
713 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
714 comp
.lpszUrlPath
= urlpart
;
715 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
716 comp
.lpszExtraInfo
= extra
;
717 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
718 r
= InternetCrackUrlW(url3
, 0, 0, &comp
);
719 ok( r
, "InternetCrackUrlW failed unexpectedly\n");
720 ok( host
[0] == 'x', "host should be x.org\n");
721 ok( urlpart
[0] == 0, "urlpart should be empty\n");
724 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents
)
726 static CHAR http
[] = "http",
727 winehq
[] = "www.winehq.org",
728 username
[] = "username",
729 password
[] = "password",
730 site_about
[] = "/site/about",
733 lpUrlComponents
->dwStructSize
= sizeof(URL_COMPONENTS
);
734 lpUrlComponents
->lpszScheme
= http
;
735 lpUrlComponents
->dwSchemeLength
= strlen(lpUrlComponents
->lpszScheme
);
736 lpUrlComponents
->nScheme
= INTERNET_SCHEME_HTTP
;
737 lpUrlComponents
->lpszHostName
= winehq
;
738 lpUrlComponents
->dwHostNameLength
= strlen(lpUrlComponents
->lpszHostName
);
739 lpUrlComponents
->nPort
= 80;
740 lpUrlComponents
->lpszUserName
= username
;
741 lpUrlComponents
->dwUserNameLength
= strlen(lpUrlComponents
->lpszUserName
);
742 lpUrlComponents
->lpszPassword
= password
;
743 lpUrlComponents
->dwPasswordLength
= strlen(lpUrlComponents
->lpszPassword
);
744 lpUrlComponents
->lpszUrlPath
= site_about
;
745 lpUrlComponents
->dwUrlPathLength
= strlen(lpUrlComponents
->lpszUrlPath
);
746 lpUrlComponents
->lpszExtraInfo
= empty
;
747 lpUrlComponents
->dwExtraInfoLength
= strlen(lpUrlComponents
->lpszExtraInfo
);
750 static void InternetCreateUrlA_test(void)
752 URL_COMPONENTS urlComp
;
756 static CHAR empty
[] = "",
760 winehq
[] = "www.winehq.org",
761 localhost
[] = "localhost",
762 username
[] = "username",
763 password
[] = "password",
765 site_about
[] = "/site/about",
766 extra_info
[] = "?test=123",
771 /* test NULL lpUrlComponents */
772 SetLastError(0xdeadbeef);
773 ret
= InternetCreateUrlA(NULL
, 0, NULL
, &len
);
774 ok(!ret
, "Expected failure\n");
775 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
776 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
777 ok(len
== -1, "Expected len -1, got %d\n", len
);
779 /* test zero'ed lpUrlComponents */
780 ZeroMemory(&urlComp
, sizeof(URL_COMPONENTS
));
781 SetLastError(0xdeadbeef);
782 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
783 ok(!ret
, "Expected failure\n");
784 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
785 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
786 ok(len
== -1, "Expected len -1, got %d\n", len
);
788 /* test valid lpUrlComponents, NULL lpdwUrlLength */
789 fill_url_components(&urlComp
);
790 SetLastError(0xdeadbeef);
791 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, NULL
);
792 ok(!ret
, "Expected failure\n");
793 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
794 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
796 /* test valid lpUrlComponents, empty szUrl
797 * lpdwUrlLength is size of buffer required on exit, including
798 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
800 SetLastError(0xdeadbeef);
801 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
802 ok(!ret
, "Expected failure\n");
803 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
804 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
805 ok(len
== 51, "Expected len 51, got %d\n", len
);
807 /* test correct size, NULL szUrl */
808 fill_url_components(&urlComp
);
809 SetLastError(0xdeadbeef);
810 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
811 ok(!ret
, "Expected failure\n");
812 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
813 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
814 ok(len
== 51, "Expected len 51, got %d\n", len
);
816 /* test valid lpUrlComponents, alloc-ed szUrl, small size */
817 SetLastError(0xdeadbeef);
818 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
820 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
821 ok(!ret
, "Expected failure\n");
822 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
823 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
824 ok(len
== 51, "Expected len 51, got %d\n", len
);
826 /* alloc-ed szUrl, NULL lpszScheme
827 * shows that it uses nScheme instead
829 SetLastError(0xdeadbeef);
830 urlComp
.lpszScheme
= NULL
;
831 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
832 ok(ret
, "Expected success\n");
833 ok(GetLastError() == 0xdeadbeef,
834 "Expected 0xdeadbeef, got %d\n", GetLastError());
835 ok(len
== 50, "Expected len 50, got %d\n", len
);
836 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
838 /* alloc-ed szUrl, invalid nScheme
839 * any nScheme out of range seems ignored
841 fill_url_components(&urlComp
);
842 SetLastError(0xdeadbeef);
843 urlComp
.nScheme
= -3;
845 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
846 ok(ret
, "Expected success\n");
847 ok(GetLastError() == 0xdeadbeef,
848 "Expected 0xdeadbeef, got %d\n", GetLastError());
849 ok(len
== 50, "Expected len 50, got %d\n", len
);
851 /* test valid lpUrlComponents, alloc-ed szUrl */
852 fill_url_components(&urlComp
);
853 SetLastError(0xdeadbeef);
855 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
856 ok(ret
, "Expected success\n");
857 ok(GetLastError() == 0xdeadbeef,
858 "Expected 0xdeadbeef, got %d\n", GetLastError());
859 ok(len
== 50, "Expected len 50, got %d\n", len
);
860 ok(strstr(szUrl
, "80") == NULL
, "Didn't expect to find 80 in szUrl\n");
861 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
863 /* valid username, NULL password */
864 fill_url_components(&urlComp
);
865 SetLastError(0xdeadbeef);
866 urlComp
.lpszPassword
= NULL
;
868 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
869 ok(ret
, "Expected success\n");
870 ok(GetLastError() == 0xdeadbeef,
871 "Expected 0xdeadbeef, got %d\n", GetLastError());
872 ok(len
== 41, "Expected len 41, got %d\n", len
);
873 ok(!strcmp(szUrl
, CREATE_URL2
), "Expected %s, got %s\n", CREATE_URL2
, szUrl
);
875 /* valid username, empty password */
876 fill_url_components(&urlComp
);
877 SetLastError(0xdeadbeef);
878 urlComp
.lpszPassword
= empty
;
880 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
881 ok(ret
, "Expected success\n");
882 ok(GetLastError() == 0xdeadbeef,
883 "Expected 0xdeadbeef, got %d\n", GetLastError());
884 ok(len
== 50, "Expected len 50, got %d\n", len
);
885 ok(!strcmp(szUrl
, CREATE_URL3
), "Expected %s, got %s\n", CREATE_URL3
, szUrl
);
887 /* valid password, NULL username
888 * if password is provided, username has to exist
890 fill_url_components(&urlComp
);
891 SetLastError(0xdeadbeef);
892 urlComp
.lpszUserName
= NULL
;
894 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
895 ok(!ret
, "Expected failure\n");
896 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
897 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
898 ok(len
== 42, "Expected len 42, got %d\n", len
);
899 ok(!strcmp(szUrl
, CREATE_URL3
), "Expected %s, got %s\n", CREATE_URL3
, szUrl
);
901 /* valid password, empty username
902 * if password is provided, username has to exist
904 fill_url_components(&urlComp
);
905 SetLastError(0xdeadbeef);
906 urlComp
.lpszUserName
= empty
;
908 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
909 ok(ret
, "Expected success\n");
910 ok(GetLastError() == 0xdeadbeef,
911 "Expected 0xdeadbeef, got %d\n", GetLastError());
912 ok(len
== 50, "Expected len 50, got %d\n", len
);
913 ok(!strcmp(szUrl
, CREATE_URL5
), "Expected %s, got %s\n", CREATE_URL5
, szUrl
);
915 /* NULL username, NULL password */
916 fill_url_components(&urlComp
);
917 SetLastError(0xdeadbeef);
918 urlComp
.lpszUserName
= NULL
;
919 urlComp
.lpszPassword
= NULL
;
921 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
922 ok(ret
, "Expected success\n");
923 ok(GetLastError() == 0xdeadbeef,
924 "Expected 0xdeadbeef, got %d\n", GetLastError());
925 ok(len
== 32, "Expected len 32, got %d\n", len
);
926 ok(!strcmp(szUrl
, CREATE_URL4
), "Expected %s, got %s\n", CREATE_URL4
, szUrl
);
928 /* empty username, empty password */
929 fill_url_components(&urlComp
);
930 SetLastError(0xdeadbeef);
931 urlComp
.lpszUserName
= empty
;
932 urlComp
.lpszPassword
= empty
;
934 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
935 ok(ret
, "Expected success\n");
936 ok(GetLastError() == 0xdeadbeef,
937 "Expected 0xdeadbeef, got %d\n", GetLastError());
938 ok(len
== 50, "Expected len 50, got %d\n", len
);
939 ok(!strcmp(szUrl
, CREATE_URL5
), "Expected %s, got %s\n", CREATE_URL5
, szUrl
);
941 /* shows that nScheme is ignored, as the appearance of the port number
942 * depends on lpszScheme and the string copied depends on lpszScheme.
944 fill_url_components(&urlComp
);
945 HeapFree(GetProcessHeap(), 0, szUrl
);
946 urlComp
.lpszScheme
= nhttp
;
947 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
948 len
= strlen(CREATE_URL6
) + 1;
949 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
950 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
951 ok(ret
, "Expected success\n");
952 ok(len
== strlen(CREATE_URL6
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6
) + 1, len
);
953 ok(!strcmp(szUrl
, CREATE_URL6
), "Expected %s, got %s\n", CREATE_URL6
, szUrl
);
955 /* if lpszScheme != "http" or nPort != 80, display nPort */
956 HeapFree(GetProcessHeap(), 0, szUrl
);
957 urlComp
.lpszScheme
= http
;
958 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
960 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
961 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
962 ok(ret
, "Expected success\n");
963 ok(len
== 53, "Expected len 53, got %d\n", len
);
964 ok(strstr(szUrl
, "42") != NULL
, "Expected to find 42 in szUrl\n");
965 ok(!strcmp(szUrl
, CREATE_URL7
), "Expected %s, got %s\n", CREATE_URL7
, szUrl
);
967 HeapFree(GetProcessHeap(), 0, szUrl
);
969 memset(&urlComp
, 0, sizeof(urlComp
));
970 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
971 urlComp
.lpszScheme
= http
;
972 urlComp
.dwSchemeLength
= 0;
973 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
974 urlComp
.lpszHostName
= winehq
;
975 urlComp
.dwHostNameLength
= 0;
977 urlComp
.lpszUserName
= username
;
978 urlComp
.dwUserNameLength
= 0;
979 urlComp
.lpszPassword
= password
;
980 urlComp
.dwPasswordLength
= 0;
981 urlComp
.lpszUrlPath
= site_about
;
982 urlComp
.dwUrlPathLength
= 0;
983 urlComp
.lpszExtraInfo
= empty
;
984 urlComp
.dwExtraInfoLength
= 0;
985 len
= strlen(CREATE_URL1
);
986 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
987 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
988 ok(ret
, "Expected success\n");
989 ok(len
== strlen(CREATE_URL1
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1
), len
);
990 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
992 HeapFree(GetProcessHeap(), 0, szUrl
);
994 memset(&urlComp
, 0, sizeof(urlComp
));
995 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
996 urlComp
.lpszScheme
= https
;
997 urlComp
.dwSchemeLength
= 0;
998 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
999 urlComp
.lpszHostName
= winehq
;
1000 urlComp
.dwHostNameLength
= 0;
1001 urlComp
.nPort
= 443;
1002 urlComp
.lpszUserName
= username
;
1003 urlComp
.dwUserNameLength
= 0;
1004 urlComp
.lpszPassword
= password
;
1005 urlComp
.dwPasswordLength
= 0;
1006 urlComp
.lpszUrlPath
= site_about
;
1007 urlComp
.dwUrlPathLength
= 0;
1008 urlComp
.lpszExtraInfo
= empty
;
1009 urlComp
.dwExtraInfoLength
= 0;
1010 len
= strlen(CREATE_URL8
);
1011 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1012 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1013 ok(ret
, "Expected success\n");
1014 ok(len
== strlen(CREATE_URL8
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8
), len
);
1015 ok(!strcmp(szUrl
, CREATE_URL8
), "Expected %s, got %s\n", CREATE_URL8
, szUrl
);
1017 HeapFree(GetProcessHeap(), 0, szUrl
);
1019 memset(&urlComp
, 0, sizeof(urlComp
));
1020 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
1021 urlComp
.lpszScheme
= about
;
1022 urlComp
.dwSchemeLength
= 5;
1023 urlComp
.lpszUrlPath
= blank
;
1024 urlComp
.dwUrlPathLength
= 5;
1025 len
= strlen(CREATE_URL9
);
1026 len
++; /* work around bug in native wininet */
1027 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1028 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1029 ok(ret
, "Expected success\n");
1030 ok(len
== strlen(CREATE_URL9
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9
), len
);
1031 ok(!strcmp(szUrl
, CREATE_URL9
), "Expected %s, got %s\n", CREATE_URL9
, szUrl
);
1033 HeapFree(GetProcessHeap(), 0, szUrl
);
1035 memset(&urlComp
, 0, sizeof(urlComp
));
1036 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
1037 urlComp
.lpszScheme
= about
;
1038 urlComp
.lpszHostName
= host
;
1039 urlComp
.lpszUrlPath
= blank
;
1040 len
= strlen(CREATE_URL10
);
1041 len
++; /* work around bug in native wininet */
1042 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1043 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1044 ok(ret
, "Expected success\n");
1045 ok(len
== strlen(CREATE_URL10
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10
), len
);
1046 ok(!strcmp(szUrl
, CREATE_URL10
), "Expected %s, got %s\n", CREATE_URL10
, szUrl
);
1048 HeapFree(GetProcessHeap(), 0, szUrl
);
1050 memset(&urlComp
, 0, sizeof(urlComp
));
1051 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
1052 urlComp
.nPort
= 8080;
1053 urlComp
.lpszScheme
= about
;
1054 len
= strlen(CREATE_URL11
);
1055 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1056 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1057 ok(ret
, "Expected success\n");
1058 ok(len
== strlen(CREATE_URL11
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11
), len
);
1059 ok(!strcmp(szUrl
, CREATE_URL11
), "Expected %s, got %s\n", CREATE_URL11
, szUrl
);
1061 HeapFree(GetProcessHeap(), 0, szUrl
);
1063 memset(&urlComp
, 0, sizeof(urlComp
));
1064 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
1065 urlComp
.lpszScheme
= http
;
1066 urlComp
.dwSchemeLength
= 0;
1067 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
1068 urlComp
.lpszHostName
= winehq
;
1069 urlComp
.dwHostNameLength
= 0;
1070 urlComp
.nPort
= 65535;
1071 len
= strlen(CREATE_URL12
);
1072 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1073 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1074 ok(ret
, "Expected success\n");
1075 ok(len
== strlen(CREATE_URL12
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12
), len
);
1076 ok(!strcmp(szUrl
, CREATE_URL12
), "Expected %s, got %s\n", CREATE_URL12
, szUrl
);
1078 HeapFree(GetProcessHeap(), 0, szUrl
);
1080 memset(&urlComp
, 0, sizeof(urlComp
));
1081 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
1082 urlComp
.lpszScheme
= http
;
1083 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
1084 urlComp
.lpszHostName
= localhost
;
1085 urlComp
.dwHostNameLength
= strlen(urlComp
.lpszHostName
);
1087 urlComp
.lpszUrlPath
= root
;
1088 urlComp
.dwUrlPathLength
= strlen(urlComp
.lpszUrlPath
);
1089 urlComp
.lpszExtraInfo
= extra_info
;
1090 urlComp
.dwExtraInfoLength
= strlen(urlComp
.lpszExtraInfo
);
1092 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
1093 InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1094 ok(ret
, "Expected success\n");
1095 ok(len
== strlen(CREATE_URL13
), "Got len %u\n", len
);
1096 ok(!strcmp(szUrl
, CREATE_URL13
), "Expected \"%s\", got \"%s\"\n", CREATE_URL13
, szUrl
);
1098 HeapFree(GetProcessHeap(), 0, szUrl
);
1105 if(!GetProcAddress(GetModuleHandleA("wininet.dll"), "InternetGetCookieExW")) {
1106 win_skip("Too old IE (older than 6.0)\n");
1110 for(i
=0; i
< sizeof(crack_url_tests
)/sizeof(*crack_url_tests
); i
++)
1111 test_crack_url(crack_url_tests
+i
);
1113 InternetCrackUrl_test();
1114 InternetCrackUrlW_test();
1115 InternetCreateUrlA_test();