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 {"http://www.winehq.org/myscript.php;test=123",
128 0, 4, INTERNET_SCHEME_HTTP
, 7, 14, 23, 80, -1, 0, -1, 0, 21, 22, -1, 0,
129 "http", "www.winehq.org", "", "", "/myscript.php;test=123", ""},
130 {"HtTp://www.winehq.org/scheme",
131 0, 4, INTERNET_SCHEME_HTTP
, 7, 14, 23, 80, -1, 0, -1, 0, 21, 7, -1, 0,
132 "HtTp", "www.winehq.org", "", "", "/scheme", ""},
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, 55, -1, 0,
135 "file", "", "", "", "C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", ""},
136 {"fide:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
137 0, 4, INTERNET_SCHEME_UNKNOWN
, 7, 0, -1, 0, -1, 0, -1, 0, 7, 55, -1, 0,
138 "fide", "", "", "", "/C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", ""},
139 {"file://C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
140 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 54, -1, 0,
141 "file", "", "", "", "C:\\Program%20Files\\Atmel\\AVR%20Tools\\STK500\\STK500.xml", ""},
142 {"file://C:/Program%20Files/Atmel/..",
143 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 27, -1, 0,
144 "file", "", "", "", "C:\\Program%20Files\\Atmel\\..\\", ""},
145 {"file://C:/Program%20Files/Atmel/../Asdf.xml",
146 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 36, -1, 0,
147 "file", "", "", "", "C:\\Program%20Files\\Atmel\\..\\Asdf.xml", ""},
148 {"file:///C:/Program%20Files/Atmel/..",
149 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 28, -1, 0,
150 "file", "", "", "", "C:\\Program Files\\Atmel\\..\\", ""},
151 {"file:///C:/Program%20Files/Atmel/../Asdf.xml",
152 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 37, -1, 0,
153 "file", "", "", "", "C:\\Program Files\\Atmel\\..\\Asdf.xml", ""},
154 {"file://C:/Program%20Files/Atmel/.",
155 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 26, -1, 0,
156 "file", "", "", "", "C:\\Program%20Files\\Atmel\\.\\", ""},
157 {"file://C:/Program%20Files/Atmel/./Asdf.xml",
158 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 35, -1, 0,
159 "file", "", "", "", "C:\\Program%20Files\\Atmel\\.\\Asdf.xml", ""},
160 {"file:///C:/Program%20Files/Atmel/.",
161 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 27, -1, 0,
162 "file", "", "", "", "C:\\Program Files\\Atmel\\.\\", ""},
163 {"file:///C:/Program%20Files/Atmel/./Asdf.xml",
164 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 36, -1, 0,
165 "file", "", "", "", "C:\\Program Files\\Atmel\\.\\Asdf.xml", ""},
167 0, 1, INTERNET_SCHEME_UNKNOWN
, -1, 0, -1, 0, -1, 0, -1, 0, 2, 9, -1, 0,
168 "C", "", "", "", "\\file.txt", ""}
171 static const WCHAR
*w_str_of(const char *str
)
173 static WCHAR buf
[512];
174 MultiByteToWideChar(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
)/sizeof(buf
[0]));
178 static void test_crack_url(const crack_url_test_t
*test
)
180 WCHAR buf
[INTERNET_MAX_URL_LENGTH
];
181 URL_COMPONENTSW urlw
;
183 char scheme
[32], hostname
[1024], username
[1024];
184 char password
[1024], extrainfo
[1024], urlpath
[1024];
187 /* test InternetCrackUrlA with NULL buffers */
188 zero_compsA(&url
, 1, 1, 1, 1, 1, 1);
190 b
= InternetCrackUrlA(test
->url
, strlen(test
->url
), 0, &url
);
191 ok(b
, "InternetCrackUrl failed with error %d\n", GetLastError());
193 if(test
->scheme_off
== -1)
194 ok(!url
.lpszScheme
, "[%s] url.lpszScheme = %p, expected NULL\n", test
->url
, url
.lpszScheme
);
196 ok(url
.lpszScheme
== test
->url
+test
->scheme_off
, "[%s] url.lpszScheme = %p, expected %p\n",
197 test
->url
, url
.lpszScheme
, test
->url
+test
->scheme_off
);
198 ok(url
.dwSchemeLength
== test
->scheme_len
, "[%s] url.lpszSchemeLength = %d, expected %d\n",
199 test
->url
, url
.dwSchemeLength
, test
->scheme_len
);
201 ok(url
.nScheme
== test
->scheme
, "[%s] url.nScheme = %d, expected %d\n", test
->url
, url
.nScheme
, test
->scheme
);
203 if(test
->host_off
== -1)
204 ok(!url
.lpszHostName
, "[%s] url.lpszHostName = %p, expected NULL\n", test
->url
, url
.lpszHostName
);
206 ok(url
.lpszHostName
== test
->url
+test
->host_off
, "[%s] url.lpszHostName = %p, expected %p\n",
207 test
->url
, url
.lpszHostName
, test
->url
+test
->host_off
);
208 if(test
->host_skip_broken
!= -1 && url
.dwHostNameLength
== test
->host_skip_broken
) {
209 win_skip("skipping broken dwHostNameLength result\n");
212 ok(url
.dwHostNameLength
== test
->host_len
, "[%s] url.lpszHostNameLength = %d, expected %d\n",
213 test
->url
, url
.dwHostNameLength
, test
->host_len
);
215 ok(url
.nPort
== test
->port
, "[%s] nPort = %d, expected %d\n", test
->url
, url
.nPort
, test
->port
);
217 if(test
->user_off
== -1)
218 ok(!url
.lpszUserName
, "[%s] url.lpszUserName = %p\n", test
->url
, url
.lpszUserName
);
220 ok(url
.lpszUserName
== test
->url
+test
->user_off
, "[%s] url.lpszUserName = %p, expected %p\n",
221 test
->url
, url
.lpszUserName
, test
->url
+test
->user_off
);
222 ok(url
.dwUserNameLength
== test
->user_len
, "[%s] url.lpszUserNameLength = %d, expected %d\n",
223 test
->url
, url
.dwUserNameLength
, test
->user_len
);
225 if(test
->pass_off
== -1)
226 ok(!url
.lpszPassword
, "[%s] url.lpszPassword = %p\n", test
->url
, url
.lpszPassword
);
228 ok(url
.lpszPassword
== test
->url
+test
->pass_off
, "[%s] url.lpszPassword = %p, expected %p\n",
229 test
->url
, url
.lpszPassword
, test
->url
+test
->pass_off
);
230 ok(url
.dwPasswordLength
== test
->pass_len
, "[%s] url.lpszPasswordLength = %d, expected %d\n",
231 test
->url
, url
.dwPasswordLength
, test
->pass_len
);
233 if(test
->path_off
== -1)
234 ok(!url
.lpszUrlPath
, "[%s] url.lpszPath = %p, expected NULL\n", test
->url
, url
.lpszUrlPath
);
236 ok(url
.lpszUrlPath
== test
->url
+test
->path_off
, "[%s] url.lpszPath = %p, expected %p\n",
237 test
->url
, url
.lpszUrlPath
, test
->url
+test
->path_off
);
238 ok(url
.dwUrlPathLength
== test
->path_len
, "[%s] url.lpszUrlPathLength = %d, expected %d\n",
239 test
->url
, url
.dwUrlPathLength
, test
->path_len
);
241 if(test
->extra_off
== -1)
242 ok(!url
.lpszExtraInfo
, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test
->url
, url
.lpszExtraInfo
);
244 ok(url
.lpszExtraInfo
== test
->url
+test
->extra_off
, "[%s] url.lpszExtraInfo = %p, expected %p\n",
245 test
->url
, url
.lpszExtraInfo
, test
->url
+test
->extra_off
);
246 ok(url
.dwExtraInfoLength
== test
->extra_len
, "[%s] url.lpszExtraInfoLength = %d, expected %d\n",
247 test
->url
, url
.dwExtraInfoLength
, test
->extra_len
);
249 /* test InternetCrackUrlW with NULL buffers */
250 memset(&urlw
, 0, sizeof(URL_COMPONENTSW
));
251 urlw
.dwStructSize
= sizeof(URL_COMPONENTSW
);
252 urlw
.dwSchemeLength
= 1;
253 urlw
.dwHostNameLength
= 1;
254 urlw
.dwUserNameLength
= 1;
255 urlw
.dwPasswordLength
= 1;
256 urlw
.dwUrlPathLength
= 1;
257 urlw
.dwExtraInfoLength
= 1;
259 MultiByteToWideChar(CP_ACP
, 0, test
->url
, -1, buf
, sizeof(buf
)/sizeof(buf
[0]));
260 b
= InternetCrackUrlW(buf
, lstrlenW(buf
), 0, &urlw
);
261 if(!b
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
) {
262 win_skip("InternetCrackUrlW is not implemented\n");
265 ok(b
, "InternetCrackUrl failed with error %d\n", GetLastError());
267 if(test
->scheme_off
== -1)
268 ok(!urlw
.lpszScheme
, "[%s] urlw.lpszScheme = %p, expected NULL\n", test
->url
, urlw
.lpszScheme
);
270 ok(urlw
.lpszScheme
== buf
+test
->scheme_off
, "[%s] urlw.lpszScheme = %p, expected %p\n",
271 test
->url
, urlw
.lpszScheme
, buf
+test
->scheme_off
);
272 ok(urlw
.dwSchemeLength
== test
->scheme_len
, "[%s] urlw.lpszSchemeLength = %d, expected %d\n",
273 test
->url
, urlw
.dwSchemeLength
, test
->scheme_len
);
275 ok(urlw
.nScheme
== test
->scheme
, "[%s] urlw.nScheme = %d, expected %d\n", test
->url
, urlw
.nScheme
, test
->scheme
);
277 if(test
->host_off
== -1) {
278 ok(!urlw
.lpszHostName
, "[%s] urlw.lpszHostName = %p, expected NULL\n", test
->url
, urlw
.lpszHostName
);
279 ok(urlw
.dwHostNameLength
== 0 || broken(urlw
.dwHostNameLength
== 1), "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
280 test
->url
, urlw
.dwHostNameLength
, test
->host_len
);
282 ok(urlw
.lpszHostName
== buf
+test
->host_off
, "[%s] urlw.lpszHostName = %p, expected %p\n",
283 test
->url
, urlw
.lpszHostName
, test
->url
+test
->host_off
);
284 ok(urlw
.dwHostNameLength
== test
->host_len
, "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
285 test
->url
, urlw
.dwHostNameLength
, test
->host_len
);
288 ok(urlw
.nPort
== test
->port
, "[%s] nPort = %d, expected %d\n", test
->url
, urlw
.nPort
, test
->port
);
290 if(test
->user_off
== -1) {
291 ok(!urlw
.lpszUserName
, "[%s] urlw.lpszUserName = %p\n", test
->url
, urlw
.lpszUserName
);
292 ok(urlw
.dwUserNameLength
== 0 || broken(urlw
.dwUserNameLength
== 1), "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
293 test
->url
, urlw
.dwUserNameLength
, test
->user_len
);
295 ok(urlw
.lpszUserName
== buf
+test
->user_off
, "[%s] urlw.lpszUserName = %p, expected %p\n",
296 test
->url
, urlw
.lpszUserName
, buf
+test
->user_off
);
297 ok(urlw
.dwUserNameLength
== test
->user_len
, "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
298 test
->url
, urlw
.dwUserNameLength
, test
->user_len
);
301 if(test
->pass_off
== -1) {
302 ok(!urlw
.lpszPassword
, "[%s] urlw.lpszPassword = %p\n", test
->url
, urlw
.lpszPassword
);
303 ok(urlw
.dwPasswordLength
== 0 || broken(urlw
.dwPasswordLength
), "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
304 test
->url
, urlw
.dwPasswordLength
, test
->pass_len
);
306 ok(urlw
.lpszPassword
== buf
+test
->pass_off
, "[%s] urlw.lpszPassword = %p, expected %p\n",
307 test
->url
, urlw
.lpszPassword
, buf
+test
->pass_off
);
308 ok(urlw
.dwPasswordLength
== test
->pass_len
, "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
309 test
->url
, urlw
.dwPasswordLength
, test
->pass_len
);
312 if(test
->path_off
== -1)
313 ok(!urlw
.lpszUrlPath
, "[%s] urlw.lpszPath = %p, expected NULL\n", test
->url
, urlw
.lpszUrlPath
);
315 ok(urlw
.lpszUrlPath
== buf
+test
->path_off
, "[%s] urlw.lpszPath = %p, expected %p\n",
316 test
->url
, urlw
.lpszUrlPath
, buf
+test
->path_off
);
317 ok(urlw
.dwUrlPathLength
== test
->path_len
, "[%s] urlw.lpszUrlPathLength = %d, expected %d\n",
318 test
->url
, urlw
.dwUrlPathLength
, test
->path_len
);
320 if(test
->extra_off
== -1) {
321 ok(!urlw
.lpszExtraInfo
, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test
->url
, urlw
.lpszExtraInfo
);
322 ok(urlw
.dwExtraInfoLength
== 0 || broken(urlw
.dwExtraInfoLength
== 1), "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
323 test
->url
, urlw
.dwExtraInfoLength
, test
->extra_len
);
325 ok(urlw
.lpszExtraInfo
== buf
+test
->extra_off
, "[%s] urlw.lpszExtraInfo = %p, expected %p\n",
326 test
->url
, urlw
.lpszExtraInfo
, buf
+test
->extra_off
);
327 ok(urlw
.dwExtraInfoLength
== test
->extra_len
, "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
328 test
->url
, urlw
.dwExtraInfoLength
, test
->extra_len
);
331 /* test InternetCrackUrlA with valid buffers */
332 memset(&url
, 0, sizeof(URL_COMPONENTSA
));
333 url
.dwStructSize
= sizeof(URL_COMPONENTSA
);
334 url
.lpszScheme
= scheme
;
335 url
.dwSchemeLength
= sizeof(scheme
);
336 url
.lpszHostName
= hostname
;
337 url
.dwHostNameLength
= sizeof(hostname
);
338 url
.lpszUserName
= username
;
339 url
.dwUserNameLength
= sizeof(username
);
340 url
.lpszPassword
= password
;
341 url
.dwPasswordLength
= sizeof(password
);
342 url
.lpszUrlPath
= urlpath
;
343 url
.dwUrlPathLength
= sizeof(urlpath
);
344 url
.lpszExtraInfo
= extrainfo
;
345 url
.dwExtraInfoLength
= sizeof(extrainfo
);
347 b
= InternetCrackUrlA(test
->url
, strlen(test
->url
), 0, &url
);
348 ok(b
, "InternetCrackUrlA failed with error %d\n", GetLastError());
350 ok(url
.dwSchemeLength
== strlen(test
->exp_scheme
), "[%s] Got wrong scheme length: %d\n",
351 test
->url
, url
.dwSchemeLength
);
352 ok(!strcmp(scheme
, test
->exp_scheme
), "[%s] Got wrong scheme, expected: %s, got: %s\n",
353 test
->url
, test
->exp_scheme
, scheme
);
355 ok(url
.nScheme
== test
->scheme
, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
356 test
->url
, test
->scheme
, url
.nScheme
);
358 ok(url
.dwHostNameLength
== strlen(test
->exp_hostname
), "[%s] Got wrong hostname length: %d\n",
359 test
->url
, url
.dwHostNameLength
);
360 ok(!strcmp(hostname
, test
->exp_hostname
), "[%s] Got wrong hostname, expected: %s, got: %s\n",
361 test
->url
, test
->exp_hostname
, hostname
);
363 ok(url
.nPort
== test
->port
, "[%s] Got wrong port, expected: %d, got: %d\n",
364 test
->url
, test
->port
, url
.nPort
);
366 ok(url
.dwUserNameLength
== strlen(test
->exp_username
), "[%s] Got wrong username length: %d\n",
367 test
->url
, url
.dwUserNameLength
);
368 ok(!strcmp(username
, test
->exp_username
), "[%s] Got wrong username, expected: %s, got: %s\n",
369 test
->url
, test
->exp_username
, username
);
371 ok(url
.dwPasswordLength
== strlen(test
->exp_password
), "[%s] Got wrong password length: %d\n",
372 test
->url
, url
.dwPasswordLength
);
373 ok(!strcmp(password
, test
->exp_password
), "[%s] Got wrong password, expected: %s, got: %s\n",
374 test
->url
, test
->exp_password
, password
);
376 ok(url
.dwUrlPathLength
== strlen(test
->exp_urlpath
), "[%s] Got wrong urlpath length: %d\n",
377 test
->url
, url
.dwUrlPathLength
);
378 ok(!strcmp(urlpath
, test
->exp_urlpath
), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
379 test
->url
, test
->exp_urlpath
, urlpath
);
381 ok(url
.dwExtraInfoLength
== strlen(test
->exp_extrainfo
), "[%s] Got wrong extrainfo length: %d\n",
382 test
->url
, url
.dwExtraInfoLength
);
383 ok(!strcmp(extrainfo
, test
->exp_extrainfo
), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
384 test
->url
, test
->exp_extrainfo
, extrainfo
);
386 /* test InternetCrackUrlW with valid buffers */
387 memset(&urlw
, 0, sizeof(URL_COMPONENTSW
));
388 urlw
.dwStructSize
= sizeof(URL_COMPONENTSW
);
389 urlw
.lpszScheme
= (WCHAR
*)scheme
;
390 urlw
.dwSchemeLength
= sizeof(scheme
) / sizeof(WCHAR
);
391 urlw
.lpszHostName
= (WCHAR
*)hostname
;
392 urlw
.dwHostNameLength
= sizeof(hostname
) / sizeof(WCHAR
);
393 urlw
.lpszUserName
= (WCHAR
*)username
;
394 urlw
.dwUserNameLength
= sizeof(username
) / sizeof(WCHAR
);
395 urlw
.lpszPassword
= (WCHAR
*)password
;
396 urlw
.dwPasswordLength
= sizeof(password
) / sizeof(WCHAR
);
397 urlw
.lpszUrlPath
= (WCHAR
*)urlpath
;
398 urlw
.dwUrlPathLength
= sizeof(urlpath
) / sizeof(WCHAR
);
399 urlw
.lpszExtraInfo
= (WCHAR
*)extrainfo
;
400 urlw
.dwExtraInfoLength
= sizeof(extrainfo
) / sizeof(WCHAR
);
402 b
= InternetCrackUrlW(buf
, lstrlenW(buf
), 0, &urlw
);
403 ok(b
, "InternetCrackUrlW failed with error %d\n", GetLastError());
405 ok(urlw
.dwSchemeLength
== strlen(test
->exp_scheme
), "[%s] Got wrong scheme length: %d\n",
406 test
->url
, urlw
.dwSchemeLength
);
407 ok(!lstrcmpW((WCHAR
*)scheme
, w_str_of(test
->exp_scheme
)), "[%s] Got wrong scheme, expected: %s, got: %s\n",
408 test
->url
, test
->exp_scheme
, wine_dbgstr_w((WCHAR
*)scheme
));
410 ok(urlw
.nScheme
== test
->scheme
, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
411 test
->url
, test
->scheme
, urlw
.nScheme
);
413 ok(urlw
.dwHostNameLength
== strlen(test
->exp_hostname
), "[%s] Got wrong hostname length: %d\n",
414 test
->url
, urlw
.dwHostNameLength
);
415 ok(!lstrcmpW((WCHAR
*)hostname
, w_str_of(test
->exp_hostname
)), "[%s] Got wrong hostname, expected: %s, got: %s\n",
416 test
->url
, test
->exp_hostname
, wine_dbgstr_w((WCHAR
*)hostname
));
418 ok(urlw
.nPort
== test
->port
, "[%s] Got wrong port, expected: %d, got: %d\n",
419 test
->url
, test
->port
, urlw
.nPort
);
421 ok(urlw
.dwUserNameLength
== strlen(test
->exp_username
), "[%s] Got wrong username length: %d\n",
422 test
->url
, urlw
.dwUserNameLength
);
423 ok(!lstrcmpW((WCHAR
*)username
, w_str_of(test
->exp_username
)), "[%s] Got wrong username, expected: %s, got: %s\n",
424 test
->url
, test
->exp_username
, wine_dbgstr_w((WCHAR
*)username
));
426 ok(urlw
.dwPasswordLength
== strlen(test
->exp_password
), "[%s] Got wrong password length: %d\n",
427 test
->url
, urlw
.dwPasswordLength
);
428 ok(!lstrcmpW((WCHAR
*)password
, w_str_of(test
->exp_password
)), "[%s] Got wrong password, expected: %s, got: %s\n",
429 test
->url
, test
->exp_password
, wine_dbgstr_w((WCHAR
*)password
));
431 ok(urlw
.dwUrlPathLength
== strlen(test
->exp_urlpath
), "[%s] Got wrong urlpath length: %d\n",
432 test
->url
, urlw
.dwUrlPathLength
);
433 ok(!lstrcmpW((WCHAR
*)urlpath
, w_str_of(test
->exp_urlpath
)), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
434 test
->url
, test
->exp_urlpath
, wine_dbgstr_w((WCHAR
*)urlpath
));
436 ok(urlw
.dwExtraInfoLength
== strlen(test
->exp_extrainfo
), "[%s] Got wrong extrainfo length: %d\n",
437 test
->url
, urlw
.dwExtraInfoLength
);
438 ok(!lstrcmpW((WCHAR
*)extrainfo
, w_str_of(test
->exp_extrainfo
)), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
439 test
->url
, test
->exp_extrainfo
, wine_dbgstr_w((WCHAR
*)extrainfo
));
442 static void InternetCrackUrl_test(void)
444 URL_COMPONENTSA urlSrc
, urlComponents
;
445 char protocol
[32], hostName
[1024], userName
[1024];
446 char password
[1024], extra
[1024], path
[1024];
450 ZeroMemory(&urlSrc
, sizeof(urlSrc
));
451 urlSrc
.dwStructSize
= sizeof(urlSrc
);
452 urlSrc
.lpszScheme
= protocol
;
453 urlSrc
.lpszHostName
= hostName
;
454 urlSrc
.lpszUserName
= userName
;
455 urlSrc
.lpszPassword
= password
;
456 urlSrc
.lpszUrlPath
= path
;
457 urlSrc
.lpszExtraInfo
= extra
;
459 /* Tests for lpsz* members pointing to real strings while
460 * some corresponding length members are set to zero.
461 * As of IE7 (wininet 7.0*?) all members are checked. So we
462 * run the first test and expect the outcome to be the same
463 * for the first four (scheme, hostname, username and password).
464 * The last two (path and extrainfo) are the same for all versions
465 * of the wininet.dll.
467 copy_compsA(&urlSrc
, &urlComponents
, 0, 1024, 1024, 1024, 2048, 1024);
468 SetLastError(0xdeadbeef);
469 firstret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
470 firstGLE
= GetLastError();
472 copy_compsA(&urlSrc
, &urlComponents
, 32, 0, 1024, 1024, 2048, 1024);
473 SetLastError(0xdeadbeef);
474 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
475 GLE
= GetLastError();
476 ok(ret
==firstret
&& (GLE
==firstGLE
), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
479 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 0, 1024, 2048, 1024);
480 SetLastError(0xdeadbeef);
481 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
482 GLE
= GetLastError();
483 ok(ret
==firstret
&& (GLE
==firstGLE
), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
486 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 0, 2048, 1024);
487 SetLastError(0xdeadbeef);
488 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
489 GLE
= GetLastError();
490 ok(ret
==firstret
&& (GLE
==firstGLE
), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
493 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 0, 1024);
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
, 32, 1024, 1024, 1024, 2048, 0);
503 SetLastError(0xdeadbeef);
504 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
505 GLE
= GetLastError();
507 ok(ret
==0 && (GLE
==ERROR_INVALID_HANDLE
|| GLE
==ERROR_INSUFFICIENT_BUFFER
),
508 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
511 copy_compsA(&urlSrc
, &urlComponents
, 0, 0, 0, 0, 0, 0);
512 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
513 GLE
= GetLastError();
515 ok(ret
==0 && GLE
==ERROR_INVALID_PARAMETER
,
516 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
519 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 2048, 1024);
520 ret
= InternetCrackUrlA("about://host/blank", 0,0,&urlComponents
);
521 ok(ret
, "InternetCrackUrl failed with %d\n", GetLastError());
522 ok(!strcmp(urlComponents
.lpszScheme
, "about"), "lpszScheme was \"%s\" instead of \"about\"\n", urlComponents
.lpszScheme
);
523 ok(!strcmp(urlComponents
.lpszHostName
, "host"), "lpszHostName was \"%s\" instead of \"host\"\n", urlComponents
.lpszHostName
);
524 ok(!strcmp(urlComponents
.lpszUrlPath
, "/blank"), "lpszUrlPath was \"%s\" instead of \"/blank\"\n", urlComponents
.lpszUrlPath
);
526 /* try a NULL lpszUrl */
527 SetLastError(0xdeadbeef);
528 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 2048, 1024);
529 ret
= InternetCrackUrlA(NULL
, 0, 0, &urlComponents
);
530 GLE
= GetLastError();
531 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
532 ok(GLE
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", GLE
);
534 /* try an empty lpszUrl, GetLastError returns 12006, whatever that means
535 * we just need to fail and not return success
537 SetLastError(0xdeadbeef);
538 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 2048, 1024);
539 ret
= InternetCrackUrlA("", 0, 0, &urlComponents
);
540 GLE
= GetLastError();
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: must set size of components structure (Windows only
545 * enforces this on the InternetCrackUrlA version of the call) */
546 copy_compsA(&urlSrc
, &urlComponents
, 0, 1024, 1024, 1024, 2048, 1024);
547 SetLastError(0xdeadbeef);
548 urlComponents
.dwStructSize
= 0;
549 ret
= InternetCrackUrlA(TEST_URL
, 0, 0, &urlComponents
);
550 GLE
= GetLastError();
551 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
552 ok(GLE
!= 0xdeadbeef && GLE
!= ERROR_SUCCESS
, "Expected GLE to represent a failure\n");
554 /* Invalid Call: size of dwStructSize must be one of the "standard" sizes
555 * of the URL_COMPONENTS structure (Windows only enforces this on the
556 * InternetCrackUrlA version of the call) */
557 copy_compsA(&urlSrc
, &urlComponents
, 0, 1024, 1024, 1024, 2048, 1024);
558 SetLastError(0xdeadbeef);
559 urlComponents
.dwStructSize
= sizeof(urlComponents
) + 1;
560 ret
= InternetCrackUrlA(TEST_URL
, 0, 0, &urlComponents
);
561 GLE
= GetLastError();
562 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
563 ok(GLE
!= 0xdeadbeef && GLE
!= ERROR_SUCCESS
, "Expected GLE to represent a failure\n");
565 SetLastError(0xdeadbeef);
566 memset(&urlComponents
, 0, sizeof(urlComponents
));
567 urlComponents
.dwStructSize
= sizeof(urlComponents
);
568 ret
= InternetCrackUrlA("file.txt", 0, 0, &urlComponents
);
569 GLE
= GetLastError();
570 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
571 ok(GLE
== ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "Expected GLE to represent a failure\n");
573 SetLastError(0xdeadbeef);
574 memset(&urlComponents
, 0, sizeof(urlComponents
));
575 urlComponents
.dwStructSize
= sizeof(urlComponents
);
576 ret
= InternetCrackUrlA("www.winehq.org", 0, 0, &urlComponents
);
577 GLE
= GetLastError();
578 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
579 ok(GLE
== ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "Expected GLE to represent a failure\n");
582 static void InternetCrackUrlW_test(void)
585 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
586 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
587 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
589 static const WCHAR url2
[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
590 static const WCHAR url3
[] = { 'h','t','t','p',':','/','/','x','.','o','r','g',0 };
591 URL_COMPONENTSW comp
;
592 WCHAR scheme
[20], host
[20], user
[20], pwd
[20], urlpart
[50], extra
[50];
602 memset(&comp
, 0, sizeof comp
);
603 comp
.dwStructSize
= sizeof(comp
);
604 comp
.lpszScheme
= scheme
;
605 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
606 comp
.lpszHostName
= host
;
607 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
608 comp
.lpszUserName
= user
;
609 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
610 comp
.lpszPassword
= pwd
;
611 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
612 comp
.lpszUrlPath
= urlpart
;
613 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
614 comp
.lpszExtraInfo
= extra
;
615 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
617 SetLastError(0xdeadbeef);
618 r
= InternetCrackUrlW(NULL
, 0, 0, &comp
);
619 error
= GetLastError();
620 if (!r
&& error
== ERROR_CALL_NOT_IMPLEMENTED
)
622 win_skip("InternetCrackUrlW is not implemented\n");
625 ok( !r
, "InternetCrackUrlW succeeded unexpectedly\n");
626 ok( error
== ERROR_INVALID_PARAMETER
||
627 broken(error
== ERROR_INTERNET_UNRECOGNIZED_SCHEME
), /* IE5 */
628 "expected ERROR_INVALID_PARAMETER got %u\n", error
);
630 if (error
== ERROR_INVALID_PARAMETER
)
633 SetLastError(0xdeadbeef);
634 r
= InternetCrackUrlW(url
, 0, 0, NULL
);
635 error
= GetLastError();
636 ok( !r
, "InternetCrackUrlW succeeded unexpectedly\n");
637 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
640 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
641 ok( r
, "failed to crack url\n");
642 ok( comp
.dwSchemeLength
== 4, "scheme length wrong\n");
643 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
644 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
645 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
646 ok( comp
.dwUrlPathLength
== 15, "url length wrong\n");
647 ok( comp
.dwExtraInfoLength
== 29, "extra length wrong\n");
655 memset(&comp
, 0, sizeof comp
);
656 comp
.dwStructSize
= sizeof comp
;
657 comp
.lpszHostName
= host
;
658 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
659 comp
.lpszUrlPath
= urlpart
;
660 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
662 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
663 ok( r
, "failed to crack url\n");
664 ok( comp
.dwSchemeLength
== 0, "scheme length wrong\n");
665 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
666 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
667 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
668 ok( comp
.dwUrlPathLength
== 44, "url length wrong\n");
669 ok( comp
.dwExtraInfoLength
== 0, "extra length wrong\n");
677 memset(&comp
, 0, sizeof comp
);
678 comp
.dwStructSize
= sizeof comp
;
679 comp
.lpszHostName
= host
;
680 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
681 comp
.lpszUrlPath
= urlpart
;
682 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
683 comp
.lpszExtraInfo
= NULL
;
684 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
686 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
687 ok( r
, "failed to crack url\n");
688 ok( comp
.dwSchemeLength
== 0, "scheme length wrong\n");
689 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
690 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
691 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
692 ok( comp
.dwUrlPathLength
== 15, "url length wrong\n");
693 ok( comp
.dwExtraInfoLength
== 29, "extra length wrong\n");
701 memset(&comp
, 0, sizeof(comp
));
702 comp
.dwStructSize
= sizeof(comp
);
703 comp
.lpszScheme
= scheme
;
704 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
705 comp
.lpszHostName
= host
;
706 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
707 comp
.lpszUserName
= user
;
708 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
709 comp
.lpszPassword
= pwd
;
710 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
711 comp
.lpszUrlPath
= urlpart
;
712 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
713 comp
.lpszExtraInfo
= extra
;
714 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
716 r
= InternetCrackUrlW(url2
, 0, 0, &comp
);
717 ok(!r
, "InternetCrackUrl should have failed\n");
718 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
,
719 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
722 /* Test to see whether cracking a URL without a filename initializes urlpart */
729 memset(&comp
, 0, sizeof comp
);
730 comp
.dwStructSize
= sizeof comp
;
731 comp
.lpszScheme
= scheme
;
732 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
733 comp
.lpszHostName
= host
;
734 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
735 comp
.lpszUserName
= user
;
736 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
737 comp
.lpszPassword
= pwd
;
738 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
739 comp
.lpszUrlPath
= urlpart
;
740 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
741 comp
.lpszExtraInfo
= extra
;
742 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
743 r
= InternetCrackUrlW(url3
, 0, 0, &comp
);
744 ok( r
, "InternetCrackUrlW failed unexpectedly\n");
745 ok( host
[0] == 'x', "host should be x.org\n");
746 ok( urlpart
[0] == 0, "urlpart should be empty\n");
749 static void fill_url_components(URL_COMPONENTSA
*lpUrlComponents
)
751 static CHAR http
[] = "http",
752 winehq
[] = "www.winehq.org",
753 username
[] = "username",
754 password
[] = "password",
755 site_about
[] = "/site/about",
758 lpUrlComponents
->dwStructSize
= sizeof(URL_COMPONENTSA
);
759 lpUrlComponents
->lpszScheme
= http
;
760 lpUrlComponents
->dwSchemeLength
= strlen(lpUrlComponents
->lpszScheme
);
761 lpUrlComponents
->nScheme
= INTERNET_SCHEME_HTTP
;
762 lpUrlComponents
->lpszHostName
= winehq
;
763 lpUrlComponents
->dwHostNameLength
= strlen(lpUrlComponents
->lpszHostName
);
764 lpUrlComponents
->nPort
= 80;
765 lpUrlComponents
->lpszUserName
= username
;
766 lpUrlComponents
->dwUserNameLength
= strlen(lpUrlComponents
->lpszUserName
);
767 lpUrlComponents
->lpszPassword
= password
;
768 lpUrlComponents
->dwPasswordLength
= strlen(lpUrlComponents
->lpszPassword
);
769 lpUrlComponents
->lpszUrlPath
= site_about
;
770 lpUrlComponents
->dwUrlPathLength
= strlen(lpUrlComponents
->lpszUrlPath
);
771 lpUrlComponents
->lpszExtraInfo
= empty
;
772 lpUrlComponents
->dwExtraInfoLength
= strlen(lpUrlComponents
->lpszExtraInfo
);
775 static void InternetCreateUrlA_test(void)
777 URL_COMPONENTSA urlComp
;
781 static CHAR empty
[] = "",
785 winehq
[] = "www.winehq.org",
786 localhost
[] = "localhost",
787 username
[] = "username",
788 password
[] = "password",
790 site_about
[] = "/site/about",
791 extra_info
[] = "?test=123",
796 /* test NULL lpUrlComponents */
797 SetLastError(0xdeadbeef);
798 ret
= InternetCreateUrlA(NULL
, 0, NULL
, &len
);
799 ok(!ret
, "Expected failure\n");
800 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
801 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
802 ok(len
== -1, "Expected len -1, got %d\n", len
);
804 /* test zero'ed lpUrlComponents */
805 ZeroMemory(&urlComp
, sizeof(urlComp
));
806 SetLastError(0xdeadbeef);
807 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
808 ok(!ret
, "Expected failure\n");
809 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
810 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
811 ok(len
== -1, "Expected len -1, got %d\n", len
);
813 /* test valid lpUrlComponents, NULL lpdwUrlLength */
814 fill_url_components(&urlComp
);
815 SetLastError(0xdeadbeef);
816 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, NULL
);
817 ok(!ret
, "Expected failure\n");
818 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
819 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
821 /* test valid lpUrlComponents, empty szUrl
822 * lpdwUrlLength is size of buffer required on exit, including
823 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
825 SetLastError(0xdeadbeef);
826 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
827 ok(!ret
, "Expected failure\n");
828 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
829 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
830 ok(len
== 51, "Expected len 51, got %d\n", len
);
832 /* test correct size, NULL szUrl */
833 fill_url_components(&urlComp
);
834 SetLastError(0xdeadbeef);
835 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
836 ok(!ret
, "Expected failure\n");
837 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
838 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
839 ok(len
== 51, "Expected len 51, got %d\n", len
);
841 /* test valid lpUrlComponents, alloc-ed szUrl, small size */
842 SetLastError(0xdeadbeef);
843 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
845 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
846 ok(!ret
, "Expected failure\n");
847 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
848 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
849 ok(len
== 51, "Expected len 51, got %d\n", len
);
851 /* alloc-ed szUrl, NULL lpszScheme
852 * shows that it uses nScheme instead
854 urlComp
.lpszScheme
= NULL
;
855 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
856 ok(ret
, "Expected success\n");
857 ok(len
== 50, "Expected len 50, got %d\n", len
);
858 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
860 /* alloc-ed szUrl, invalid nScheme
861 * any nScheme out of range seems ignored
863 fill_url_components(&urlComp
);
864 urlComp
.nScheme
= -3;
866 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
867 ok(ret
, "Expected success\n");
868 ok(len
== 50, "Expected len 50, got %d\n", len
);
870 /* test valid lpUrlComponents, alloc-ed szUrl */
871 fill_url_components(&urlComp
);
873 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
874 ok(ret
, "Expected success\n");
875 ok(len
== 50, "Expected len 50, got %d\n", len
);
876 ok(strstr(szUrl
, "80") == NULL
, "Didn't expect to find 80 in szUrl\n");
877 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
879 /* valid username, NULL password */
880 fill_url_components(&urlComp
);
881 urlComp
.lpszPassword
= NULL
;
883 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
884 ok(ret
, "Expected success\n");
885 ok(len
== 41, "Expected len 41, got %d\n", len
);
886 ok(!strcmp(szUrl
, CREATE_URL2
), "Expected %s, got %s\n", CREATE_URL2
, szUrl
);
888 /* valid username, empty password */
889 fill_url_components(&urlComp
);
890 urlComp
.lpszPassword
= empty
;
892 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
893 ok(ret
, "Expected success\n");
894 ok(len
== 50, "Expected len 50, got %d\n", len
);
895 ok(!strcmp(szUrl
, CREATE_URL3
), "Expected %s, got %s\n", CREATE_URL3
, szUrl
);
897 /* valid password, NULL username
898 * if password is provided, username has to exist
900 fill_url_components(&urlComp
);
901 SetLastError(0xdeadbeef);
902 urlComp
.lpszUserName
= NULL
;
904 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
905 ok(!ret
, "Expected failure\n");
906 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
907 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
908 ok(len
== 42, "Expected len 42, got %d\n", len
);
909 ok(!strcmp(szUrl
, CREATE_URL3
), "Expected %s, got %s\n", CREATE_URL3
, szUrl
);
911 /* valid password, empty username
912 * if password is provided, username has to exist
914 fill_url_components(&urlComp
);
915 urlComp
.lpszUserName
= empty
;
917 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
918 ok(ret
, "Expected success\n");
919 ok(len
== 50, "Expected len 50, got %d\n", len
);
920 ok(!strcmp(szUrl
, CREATE_URL5
), "Expected %s, got %s\n", CREATE_URL5
, szUrl
);
922 /* NULL username, NULL password */
923 fill_url_components(&urlComp
);
924 urlComp
.lpszUserName
= NULL
;
925 urlComp
.lpszPassword
= NULL
;
927 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
928 ok(ret
, "Expected success\n");
929 ok(len
== 32, "Expected len 32, got %d\n", len
);
930 ok(!strcmp(szUrl
, CREATE_URL4
), "Expected %s, got %s\n", CREATE_URL4
, szUrl
);
932 /* empty username, empty password */
933 fill_url_components(&urlComp
);
934 urlComp
.lpszUserName
= empty
;
935 urlComp
.lpszPassword
= empty
;
937 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
938 ok(ret
, "Expected success\n");
939 ok(len
== 50, "Expected len 50, got %d\n", len
);
940 ok(!strcmp(szUrl
, CREATE_URL5
), "Expected %s, got %s\n", CREATE_URL5
, szUrl
);
942 /* shows that nScheme is ignored, as the appearance of the port number
943 * depends on lpszScheme and the string copied depends on lpszScheme.
945 fill_url_components(&urlComp
);
946 HeapFree(GetProcessHeap(), 0, szUrl
);
947 urlComp
.lpszScheme
= nhttp
;
948 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
949 len
= strlen(CREATE_URL6
) + 1;
950 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
951 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
952 ok(ret
, "Expected success\n");
953 ok(len
== strlen(CREATE_URL6
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6
) + 1, len
);
954 ok(!strcmp(szUrl
, CREATE_URL6
), "Expected %s, got %s\n", CREATE_URL6
, szUrl
);
956 /* if lpszScheme != "http" or nPort != 80, display nPort */
957 HeapFree(GetProcessHeap(), 0, szUrl
);
958 urlComp
.lpszScheme
= http
;
959 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
961 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
962 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
963 ok(ret
, "Expected success\n");
964 ok(len
== 53, "Expected len 53, got %d\n", len
);
965 ok(strstr(szUrl
, "42") != NULL
, "Expected to find 42 in szUrl\n");
966 ok(!strcmp(szUrl
, CREATE_URL7
), "Expected %s, got %s\n", CREATE_URL7
, szUrl
);
968 HeapFree(GetProcessHeap(), 0, szUrl
);
970 memset(&urlComp
, 0, sizeof(urlComp
));
971 urlComp
.dwStructSize
= sizeof(urlComp
);
972 urlComp
.lpszScheme
= http
;
973 urlComp
.dwSchemeLength
= 0;
974 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
975 urlComp
.lpszHostName
= winehq
;
976 urlComp
.dwHostNameLength
= 0;
978 urlComp
.lpszUserName
= username
;
979 urlComp
.dwUserNameLength
= 0;
980 urlComp
.lpszPassword
= password
;
981 urlComp
.dwPasswordLength
= 0;
982 urlComp
.lpszUrlPath
= site_about
;
983 urlComp
.dwUrlPathLength
= 0;
984 urlComp
.lpszExtraInfo
= empty
;
985 urlComp
.dwExtraInfoLength
= 0;
986 len
= strlen(CREATE_URL1
);
987 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
988 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
989 ok(ret
, "Expected success\n");
990 ok(len
== strlen(CREATE_URL1
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1
), len
);
991 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
993 HeapFree(GetProcessHeap(), 0, szUrl
);
995 memset(&urlComp
, 0, sizeof(urlComp
));
996 urlComp
.dwStructSize
= sizeof(urlComp
);
997 urlComp
.lpszScheme
= https
;
998 urlComp
.dwSchemeLength
= 0;
999 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
1000 urlComp
.lpszHostName
= winehq
;
1001 urlComp
.dwHostNameLength
= 0;
1002 urlComp
.nPort
= 443;
1003 urlComp
.lpszUserName
= username
;
1004 urlComp
.dwUserNameLength
= 0;
1005 urlComp
.lpszPassword
= password
;
1006 urlComp
.dwPasswordLength
= 0;
1007 urlComp
.lpszUrlPath
= site_about
;
1008 urlComp
.dwUrlPathLength
= 0;
1009 urlComp
.lpszExtraInfo
= empty
;
1010 urlComp
.dwExtraInfoLength
= 0;
1011 len
= strlen(CREATE_URL8
);
1012 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1013 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1014 ok(ret
, "Expected success\n");
1015 ok(len
== strlen(CREATE_URL8
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8
), len
);
1016 ok(!strcmp(szUrl
, CREATE_URL8
), "Expected %s, got %s\n", CREATE_URL8
, szUrl
);
1018 HeapFree(GetProcessHeap(), 0, szUrl
);
1020 memset(&urlComp
, 0, sizeof(urlComp
));
1021 urlComp
.dwStructSize
= sizeof(urlComp
);
1022 urlComp
.lpszScheme
= about
;
1023 urlComp
.dwSchemeLength
= 5;
1024 urlComp
.lpszUrlPath
= blank
;
1025 urlComp
.dwUrlPathLength
= 5;
1026 len
= strlen(CREATE_URL9
);
1027 len
++; /* work around bug in native wininet */
1028 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1029 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1030 ok(ret
, "Expected success\n");
1031 ok(len
== strlen(CREATE_URL9
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9
), len
);
1032 ok(!strcmp(szUrl
, CREATE_URL9
), "Expected %s, got %s\n", CREATE_URL9
, szUrl
);
1034 HeapFree(GetProcessHeap(), 0, szUrl
);
1036 memset(&urlComp
, 0, sizeof(urlComp
));
1037 urlComp
.dwStructSize
= sizeof(urlComp
);
1038 urlComp
.lpszScheme
= about
;
1039 urlComp
.lpszHostName
= host
;
1040 urlComp
.lpszUrlPath
= blank
;
1041 len
= strlen(CREATE_URL10
);
1042 len
++; /* work around bug in native wininet */
1043 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1044 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1045 ok(ret
, "Expected success\n");
1046 ok(len
== strlen(CREATE_URL10
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10
), len
);
1047 ok(!strcmp(szUrl
, CREATE_URL10
), "Expected %s, got %s\n", CREATE_URL10
, szUrl
);
1049 HeapFree(GetProcessHeap(), 0, szUrl
);
1051 memset(&urlComp
, 0, sizeof(urlComp
));
1052 urlComp
.dwStructSize
= sizeof(urlComp
);
1053 urlComp
.nPort
= 8080;
1054 urlComp
.lpszScheme
= about
;
1055 len
= strlen(CREATE_URL11
);
1056 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1057 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1058 ok(ret
, "Expected success\n");
1059 ok(len
== strlen(CREATE_URL11
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11
), len
);
1060 ok(!strcmp(szUrl
, CREATE_URL11
), "Expected %s, got %s\n", CREATE_URL11
, szUrl
);
1062 HeapFree(GetProcessHeap(), 0, szUrl
);
1064 memset(&urlComp
, 0, sizeof(urlComp
));
1065 urlComp
.dwStructSize
= sizeof(urlComp
);
1066 urlComp
.lpszScheme
= http
;
1067 urlComp
.dwSchemeLength
= 0;
1068 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
1069 urlComp
.lpszHostName
= winehq
;
1070 urlComp
.dwHostNameLength
= 0;
1071 urlComp
.nPort
= 65535;
1072 len
= strlen(CREATE_URL12
);
1073 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1074 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1075 ok(ret
, "Expected success\n");
1076 ok(len
== strlen(CREATE_URL12
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12
), len
);
1077 ok(!strcmp(szUrl
, CREATE_URL12
), "Expected %s, got %s\n", CREATE_URL12
, szUrl
);
1079 HeapFree(GetProcessHeap(), 0, szUrl
);
1081 memset(&urlComp
, 0, sizeof(urlComp
));
1082 urlComp
.dwStructSize
= sizeof(urlComp
);
1083 urlComp
.lpszScheme
= http
;
1084 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
1085 urlComp
.lpszHostName
= localhost
;
1086 urlComp
.dwHostNameLength
= strlen(urlComp
.lpszHostName
);
1088 urlComp
.lpszUrlPath
= root
;
1089 urlComp
.dwUrlPathLength
= strlen(urlComp
.lpszUrlPath
);
1090 urlComp
.lpszExtraInfo
= extra_info
;
1091 urlComp
.dwExtraInfoLength
= strlen(urlComp
.lpszExtraInfo
);
1093 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
1094 InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1095 ok(ret
, "Expected success\n");
1096 ok(len
== strlen(CREATE_URL13
), "Got len %u\n", len
);
1097 ok(!strcmp(szUrl
, CREATE_URL13
), "Expected \"%s\", got \"%s\"\n", CREATE_URL13
, szUrl
);
1099 HeapFree(GetProcessHeap(), 0, szUrl
);
1102 static void InternetCanonicalizeUrl_test(void)
1104 char src
[] = "http://www.winehq.org/%27/ /./>/#> ";
1108 dstlen
= sizeof(dst
);
1109 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, 0);
1110 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1112 /* despite what MSDN says, ICU_BROWSER_MODE seems to be ignored */
1113 dstlen
= sizeof(dst
);
1114 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_BROWSER_MODE
);
1115 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1117 /* ICU_ESCAPE is supposed to be ignored */
1118 dstlen
= sizeof(dst
);
1119 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_ESCAPE
);
1120 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1122 dstlen
= sizeof(dst
);
1123 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_DECODE
);
1124 ok(strcmp(dst
, "http://www.winehq.org/'/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1126 dstlen
= sizeof(dst
);
1127 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_ENCODE_PERCENT
);
1128 ok(strcmp(dst
, "http://www.winehq.org/%2527/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1130 dstlen
= sizeof(dst
);
1131 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_ENCODE_SPACES_ONLY
);
1132 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/>/#>") == 0, "Got \"%s\"\n", dst
);
1134 dstlen
= sizeof(dst
);
1135 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_NO_ENCODE
);
1136 ok(strcmp(dst
, "http://www.winehq.org/%27/ />/#>") == 0, "Got \"%s\"\n", dst
);
1138 dstlen
= sizeof(dst
);
1139 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_NO_META
);
1140 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/./%3E/#>") == 0, "Got \"%s\"\n", dst
);
1147 if(!GetProcAddress(GetModuleHandleA("wininet.dll"), "InternetGetCookieExW")) {
1148 win_skip("Too old IE (older than 6.0)\n");
1152 for(i
=0; i
< sizeof(crack_url_tests
)/sizeof(*crack_url_tests
); i
++)
1153 test_crack_url(crack_url_tests
+i
);
1155 InternetCrackUrl_test();
1156 InternetCrackUrlW_test();
1157 InternetCreateUrlA_test();
1158 InternetCanonicalizeUrl_test();