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 {"http://www.winehq.org",
134 0, 4, INTERNET_SCHEME_HTTP
, 7, 14, 23, 80, -1, 0, -1, 0, 21, 0, -1, 0,
135 "http", "www.winehq.org", "", "", "", ""},
136 {"file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
137 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 55, -1, 0,
138 "file", "", "", "", "C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", ""},
139 {"fide:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
140 0, 4, INTERNET_SCHEME_UNKNOWN
, 7, 0, -1, 0, -1, 0, -1, 0, 7, 55, -1, 0,
141 "fide", "", "", "", "/C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", ""},
142 {"file://C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
143 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 54, -1, 0,
144 "file", "", "", "", "C:\\Program%20Files\\Atmel\\AVR%20Tools\\STK500\\STK500.xml", ""},
145 {"file://C:/Program%20Files/Atmel/..",
146 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 27, -1, 0,
147 "file", "", "", "", "C:\\Program%20Files\\Atmel\\..\\", ""},
148 {"file://C:/Program%20Files/Atmel/../Asdf.xml",
149 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 36, -1, 0,
150 "file", "", "", "", "C:\\Program%20Files\\Atmel\\..\\Asdf.xml", ""},
151 {"file:///C:/Program%20Files/Atmel/..",
152 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 28, -1, 0,
153 "file", "", "", "", "C:\\Program Files\\Atmel\\..\\", ""},
154 {"file:///C:/Program%20Files/Atmel/../Asdf.xml",
155 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 37, -1, 0,
156 "file", "", "", "", "C:\\Program Files\\Atmel\\..\\Asdf.xml", ""},
157 {"file://C:/Program%20Files/Atmel/.",
158 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 26, -1, 0,
159 "file", "", "", "", "C:\\Program%20Files\\Atmel\\.\\", ""},
160 {"file://C:/Program%20Files/Atmel/./Asdf.xml",
161 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 35, -1, 0,
162 "file", "", "", "", "C:\\Program%20Files\\Atmel\\.\\Asdf.xml", ""},
163 {"file:///C:/Program%20Files/Atmel/.",
164 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 27, -1, 0,
165 "file", "", "", "", "C:\\Program Files\\Atmel\\.\\", ""},
166 {"file:///C:/Program%20Files/Atmel/./Asdf.xml",
167 0, 4, INTERNET_SCHEME_FILE
, -1, 0, -1, 0, -1, 0, -1, 0, 7, 36, -1, 0,
168 "file", "", "", "", "C:\\Program Files\\Atmel\\.\\Asdf.xml", ""},
170 0, 1, INTERNET_SCHEME_UNKNOWN
, -1, 0, -1, 0, -1, 0, -1, 0, 2, 9, -1, 0,
171 "C", "", "", "", "\\file.txt", ""}
174 static WCHAR
*a2w(const char *str
)
179 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
180 ret
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
181 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
185 static int strcmp_wa(const WCHAR
*str1
, const char *str2
)
187 WCHAR
*str2w
= a2w(str2
);
188 int ret
= lstrcmpW(str1
, str2w
);
189 HeapFree(GetProcessHeap(), 0, str2w
);
193 static void test_crack_url(const crack_url_test_t
*test
)
195 URL_COMPONENTSW urlw
;
197 char *scheme_a
, *hostname_a
, *username_a
;
198 char *password_a
, *extrainfo_a
, *urlpath_a
;
199 WCHAR
*scheme_w
, *hostname_w
, *username_w
;
200 WCHAR
*password_w
, *extrainfo_w
, *urlpath_w
;
201 size_t buf_len
= strlen(test
->url
);
205 /* test InternetCrackUrlA with NULL buffers */
206 zero_compsA(&url
, 1, 1, 1, 1, 1, 1);
208 b
= InternetCrackUrlA(test
->url
, strlen(test
->url
), 0, &url
);
209 ok(b
, "InternetCrackUrl failed with error %d\n", GetLastError());
211 if(test
->scheme_off
== -1)
212 ok(!url
.lpszScheme
, "[%s] url.lpszScheme = %p, expected NULL\n", test
->url
, url
.lpszScheme
);
214 ok(url
.lpszScheme
== test
->url
+test
->scheme_off
, "[%s] url.lpszScheme = %p, expected %p\n",
215 test
->url
, url
.lpszScheme
, test
->url
+test
->scheme_off
);
216 ok(url
.dwSchemeLength
== test
->scheme_len
, "[%s] url.lpszSchemeLength = %d, expected %d\n",
217 test
->url
, url
.dwSchemeLength
, test
->scheme_len
);
219 ok(url
.nScheme
== test
->scheme
, "[%s] url.nScheme = %d, expected %d\n", test
->url
, url
.nScheme
, test
->scheme
);
221 if(test
->host_off
== -1)
222 ok(!url
.lpszHostName
, "[%s] url.lpszHostName = %p, expected NULL\n", test
->url
, url
.lpszHostName
);
224 ok(url
.lpszHostName
== test
->url
+test
->host_off
, "[%s] url.lpszHostName = %p, expected %p\n",
225 test
->url
, url
.lpszHostName
, test
->url
+test
->host_off
);
226 if(test
->host_skip_broken
!= -1 && url
.dwHostNameLength
== test
->host_skip_broken
) {
227 win_skip("skipping broken dwHostNameLength result\n");
230 ok(url
.dwHostNameLength
== test
->host_len
, "[%s] url.lpszHostNameLength = %d, expected %d\n",
231 test
->url
, url
.dwHostNameLength
, test
->host_len
);
233 ok(url
.nPort
== test
->port
, "[%s] nPort = %d, expected %d\n", test
->url
, url
.nPort
, test
->port
);
235 if(test
->user_off
== -1)
236 ok(!url
.lpszUserName
, "[%s] url.lpszUserName = %p\n", test
->url
, url
.lpszUserName
);
238 ok(url
.lpszUserName
== test
->url
+test
->user_off
, "[%s] url.lpszUserName = %p, expected %p\n",
239 test
->url
, url
.lpszUserName
, test
->url
+test
->user_off
);
240 ok(url
.dwUserNameLength
== test
->user_len
, "[%s] url.lpszUserNameLength = %d, expected %d\n",
241 test
->url
, url
.dwUserNameLength
, test
->user_len
);
243 if(test
->pass_off
== -1)
244 ok(!url
.lpszPassword
, "[%s] url.lpszPassword = %p\n", test
->url
, url
.lpszPassword
);
246 ok(url
.lpszPassword
== test
->url
+test
->pass_off
, "[%s] url.lpszPassword = %p, expected %p\n",
247 test
->url
, url
.lpszPassword
, test
->url
+test
->pass_off
);
248 ok(url
.dwPasswordLength
== test
->pass_len
, "[%s] url.lpszPasswordLength = %d, expected %d\n",
249 test
->url
, url
.dwPasswordLength
, test
->pass_len
);
251 if(test
->path_off
== -1)
252 ok(!url
.lpszUrlPath
, "[%s] url.lpszUrlPath = %p, expected NULL\n", test
->url
, url
.lpszUrlPath
);
254 ok(url
.lpszUrlPath
== test
->url
+test
->path_off
, "[%s] url.lpszUrlPath = %p, expected %p\n",
255 test
->url
, url
.lpszUrlPath
, test
->url
+test
->path_off
);
256 ok(url
.dwUrlPathLength
== test
->path_len
, "[%s] url.lpszUrlPathLength = %d, expected %d\n",
257 test
->url
, url
.dwUrlPathLength
, test
->path_len
);
259 if(test
->extra_off
== -1)
260 ok(!url
.lpszExtraInfo
, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test
->url
, url
.lpszExtraInfo
);
262 ok(url
.lpszExtraInfo
== test
->url
+test
->extra_off
, "[%s] url.lpszExtraInfo = %p, expected %p\n",
263 test
->url
, url
.lpszExtraInfo
, test
->url
+test
->extra_off
);
264 ok(url
.dwExtraInfoLength
== test
->extra_len
, "[%s] url.lpszExtraInfoLength = %d, expected %d\n",
265 test
->url
, url
.dwExtraInfoLength
, test
->extra_len
);
267 /* test InternetCrackUrlW with NULL buffers */
268 memset(&urlw
, 0, sizeof(URL_COMPONENTSW
));
269 urlw
.dwStructSize
= sizeof(URL_COMPONENTSW
);
270 urlw
.dwSchemeLength
= 1;
271 urlw
.dwHostNameLength
= 1;
272 urlw
.dwUserNameLength
= 1;
273 urlw
.dwPasswordLength
= 1;
274 urlw
.dwUrlPathLength
= 1;
275 urlw
.dwExtraInfoLength
= 1;
277 buf
= a2w(test
->url
);
278 b
= InternetCrackUrlW(buf
, lstrlenW(buf
), 0, &urlw
);
279 if(!b
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
) {
280 win_skip("InternetCrackUrlW is not implemented\n");
281 HeapFree(GetProcessHeap(), 0, buf
);
284 ok(b
, "InternetCrackUrl failed with error %d\n", GetLastError());
286 if(test
->scheme_off
== -1)
287 ok(!urlw
.lpszScheme
, "[%s] urlw.lpszScheme = %p, expected NULL\n", test
->url
, urlw
.lpszScheme
);
289 ok(urlw
.lpszScheme
== buf
+test
->scheme_off
, "[%s] urlw.lpszScheme = %p, expected %p\n",
290 test
->url
, urlw
.lpszScheme
, buf
+test
->scheme_off
);
291 ok(urlw
.dwSchemeLength
== test
->scheme_len
, "[%s] urlw.lpszSchemeLength = %d, expected %d\n",
292 test
->url
, urlw
.dwSchemeLength
, test
->scheme_len
);
294 ok(urlw
.nScheme
== test
->scheme
, "[%s] urlw.nScheme = %d, expected %d\n", test
->url
, urlw
.nScheme
, test
->scheme
);
296 if(test
->host_off
== -1) {
297 ok(!urlw
.lpszHostName
, "[%s] urlw.lpszHostName = %p, expected NULL\n", test
->url
, urlw
.lpszHostName
);
298 ok(urlw
.dwHostNameLength
== 0 || broken(urlw
.dwHostNameLength
== 1), "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
299 test
->url
, urlw
.dwHostNameLength
, test
->host_len
);
301 ok(urlw
.lpszHostName
== buf
+test
->host_off
, "[%s] urlw.lpszHostName = %p, expected %p\n",
302 test
->url
, urlw
.lpszHostName
, test
->url
+test
->host_off
);
303 ok(urlw
.dwHostNameLength
== test
->host_len
, "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
304 test
->url
, urlw
.dwHostNameLength
, test
->host_len
);
307 ok(urlw
.nPort
== test
->port
, "[%s] nPort = %d, expected %d\n", test
->url
, urlw
.nPort
, test
->port
);
309 if(test
->user_off
== -1) {
310 ok(!urlw
.lpszUserName
, "[%s] urlw.lpszUserName = %p\n", test
->url
, urlw
.lpszUserName
);
311 ok(urlw
.dwUserNameLength
== 0 || broken(urlw
.dwUserNameLength
== 1), "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
312 test
->url
, urlw
.dwUserNameLength
, test
->user_len
);
314 ok(urlw
.lpszUserName
== buf
+test
->user_off
, "[%s] urlw.lpszUserName = %p, expected %p\n",
315 test
->url
, urlw
.lpszUserName
, buf
+test
->user_off
);
316 ok(urlw
.dwUserNameLength
== test
->user_len
, "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
317 test
->url
, urlw
.dwUserNameLength
, test
->user_len
);
320 if(test
->pass_off
== -1) {
321 ok(!urlw
.lpszPassword
, "[%s] urlw.lpszPassword = %p\n", test
->url
, urlw
.lpszPassword
);
322 ok(urlw
.dwPasswordLength
== 0 || broken(urlw
.dwPasswordLength
), "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
323 test
->url
, urlw
.dwPasswordLength
, test
->pass_len
);
325 ok(urlw
.lpszPassword
== buf
+test
->pass_off
, "[%s] urlw.lpszPassword = %p, expected %p\n",
326 test
->url
, urlw
.lpszPassword
, buf
+test
->pass_off
);
327 ok(urlw
.dwPasswordLength
== test
->pass_len
, "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
328 test
->url
, urlw
.dwPasswordLength
, test
->pass_len
);
331 if(test
->path_off
== -1)
332 ok(!urlw
.lpszUrlPath
, "[%s] urlw.lpszUrlPath = %p, expected NULL\n", test
->url
, urlw
.lpszUrlPath
);
334 ok(urlw
.lpszUrlPath
== buf
+test
->path_off
, "[%s] urlw.lpszUrlPath = %p, expected %p\n",
335 test
->url
, urlw
.lpszUrlPath
, buf
+test
->path_off
);
336 ok(urlw
.dwUrlPathLength
== test
->path_len
, "[%s] urlw.lpszUrlPathLength = %d, expected %d\n",
337 test
->url
, urlw
.dwUrlPathLength
, test
->path_len
);
339 if(test
->extra_off
== -1) {
340 ok(!urlw
.lpszExtraInfo
, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test
->url
, urlw
.lpszExtraInfo
);
341 ok(urlw
.dwExtraInfoLength
== 0 || broken(urlw
.dwExtraInfoLength
== 1), "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
342 test
->url
, urlw
.dwExtraInfoLength
, test
->extra_len
);
344 ok(urlw
.lpszExtraInfo
== buf
+test
->extra_off
, "[%s] urlw.lpszExtraInfo = %p, expected %p\n",
345 test
->url
, urlw
.lpszExtraInfo
, buf
+test
->extra_off
);
346 ok(urlw
.dwExtraInfoLength
== test
->extra_len
, "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
347 test
->url
, urlw
.dwExtraInfoLength
, test
->extra_len
);
350 /* test InternetCrackUrlA with valid buffers */
351 scheme_a
= (char*)(scheme_w
= HeapAlloc(GetProcessHeap(), 0, buf_len
*sizeof(WCHAR
)));
352 hostname_a
= (char*)(hostname_w
= HeapAlloc(GetProcessHeap(), 0, buf_len
*sizeof(WCHAR
)));
353 username_a
= (char*)(username_w
= HeapAlloc(GetProcessHeap(), 0, buf_len
*sizeof(WCHAR
)));
354 password_a
= (char*)(password_w
= HeapAlloc(GetProcessHeap(), 0, buf_len
*sizeof(WCHAR
)));
355 urlpath_a
= (char*)(urlpath_w
= HeapAlloc(GetProcessHeap(), 0, buf_len
*sizeof(WCHAR
)));
356 extrainfo_a
= (char*)(extrainfo_w
= HeapAlloc(GetProcessHeap(), 0, buf_len
*sizeof(WCHAR
)));
357 memset(&url
, 0, sizeof(URL_COMPONENTSA
));
358 url
.dwStructSize
= sizeof(URL_COMPONENTSA
);
359 url
.lpszScheme
= scheme_a
;
360 url
.dwSchemeLength
= buf_len
;
361 url
.lpszHostName
= hostname_a
;
362 url
.dwHostNameLength
= buf_len
;
363 url
.lpszUserName
= username_a
;
364 url
.dwUserNameLength
= buf_len
;
365 url
.lpszPassword
= password_a
;
366 url
.dwPasswordLength
= buf_len
;
367 url
.lpszUrlPath
= urlpath_a
;
368 url
.dwUrlPathLength
= buf_len
;
369 url
.lpszExtraInfo
= extrainfo_a
;
370 url
.dwExtraInfoLength
= buf_len
;
372 b
= InternetCrackUrlA(test
->url
, strlen(test
->url
), 0, &url
);
373 ok(b
, "InternetCrackUrlA failed with error %d\n", GetLastError());
375 ok(url
.dwSchemeLength
== strlen(test
->exp_scheme
), "[%s] Got wrong scheme length: %d\n",
376 test
->url
, url
.dwSchemeLength
);
377 ok(!strcmp(scheme_a
, test
->exp_scheme
), "[%s] Got wrong scheme, expected: %s, got: %s\n",
378 test
->url
, test
->exp_scheme
, scheme_a
);
380 ok(url
.nScheme
== test
->scheme
, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
381 test
->url
, test
->scheme
, url
.nScheme
);
383 ok(url
.dwHostNameLength
== strlen(test
->exp_hostname
), "[%s] Got wrong hostname length: %d\n",
384 test
->url
, url
.dwHostNameLength
);
385 ok(!strcmp(hostname_a
, test
->exp_hostname
), "[%s] Got wrong hostname, expected: %s, got: %s\n",
386 test
->url
, test
->exp_hostname
, hostname_a
);
388 ok(url
.nPort
== test
->port
, "[%s] Got wrong port, expected: %d, got: %d\n",
389 test
->url
, test
->port
, url
.nPort
);
391 ok(url
.dwUserNameLength
== strlen(test
->exp_username
), "[%s] Got wrong username length: %d\n",
392 test
->url
, url
.dwUserNameLength
);
393 ok(!strcmp(username_a
, test
->exp_username
), "[%s] Got wrong username, expected: %s, got: %s\n",
394 test
->url
, test
->exp_username
, username_a
);
396 ok(url
.dwPasswordLength
== strlen(test
->exp_password
), "[%s] Got wrong password length: %d\n",
397 test
->url
, url
.dwPasswordLength
);
398 ok(!strcmp(password_a
, test
->exp_password
), "[%s] Got wrong password, expected: %s, got: %s\n",
399 test
->url
, test
->exp_password
, password_a
);
401 ok(url
.dwUrlPathLength
== strlen(test
->exp_urlpath
), "[%s] Got wrong urlpath length: %d\n",
402 test
->url
, url
.dwUrlPathLength
);
403 ok(!strcmp(urlpath_a
, test
->exp_urlpath
), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
404 test
->url
, test
->exp_urlpath
, urlpath_a
);
406 ok(url
.dwExtraInfoLength
== strlen(test
->exp_extrainfo
), "[%s] Got wrong extrainfo length: %d\n",
407 test
->url
, url
.dwExtraInfoLength
);
408 ok(!strcmp(extrainfo_a
, test
->exp_extrainfo
), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
409 test
->url
, test
->exp_extrainfo
, extrainfo_a
);
411 /* test InternetCrackUrlW with valid buffers */
412 memset(&urlw
, 0, sizeof(URL_COMPONENTSW
));
413 urlw
.dwStructSize
= sizeof(URL_COMPONENTSW
);
414 urlw
.lpszScheme
= scheme_w
;
415 urlw
.dwSchemeLength
= buf_len
;
416 urlw
.lpszHostName
= hostname_w
;
417 urlw
.dwHostNameLength
= buf_len
;
418 urlw
.lpszUserName
= username_w
;
419 urlw
.dwUserNameLength
= buf_len
;
420 urlw
.lpszPassword
= password_w
;
421 urlw
.dwPasswordLength
= buf_len
;
422 urlw
.lpszUrlPath
= urlpath_w
;
423 urlw
.dwUrlPathLength
= buf_len
;
424 urlw
.lpszExtraInfo
= extrainfo_w
;
425 urlw
.dwExtraInfoLength
= buf_len
;
427 b
= InternetCrackUrlW(buf
, lstrlenW(buf
), 0, &urlw
);
428 ok(b
, "InternetCrackUrlW failed with error %d\n", GetLastError());
430 ok(urlw
.dwSchemeLength
== strlen(test
->exp_scheme
), "[%s] Got wrong scheme length: %d\n",
431 test
->url
, urlw
.dwSchemeLength
);
432 ok(!strcmp_wa(scheme_w
, test
->exp_scheme
), "[%s] Got wrong scheme, expected: %s, got: %s\n",
433 test
->url
, test
->exp_scheme
, wine_dbgstr_w(scheme_w
));
435 ok(urlw
.nScheme
== test
->scheme
, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
436 test
->url
, test
->scheme
, urlw
.nScheme
);
438 ok(urlw
.dwHostNameLength
== strlen(test
->exp_hostname
), "[%s] Got wrong hostname length: %d\n",
439 test
->url
, urlw
.dwHostNameLength
);
440 ok(!strcmp_wa(hostname_w
, test
->exp_hostname
), "[%s] Got wrong hostname, expected: %s, got: %s\n",
441 test
->url
, test
->exp_hostname
, wine_dbgstr_w(hostname_w
));
443 ok(urlw
.nPort
== test
->port
, "[%s] Got wrong port, expected: %d, got: %d\n",
444 test
->url
, test
->port
, urlw
.nPort
);
446 ok(urlw
.dwUserNameLength
== strlen(test
->exp_username
), "[%s] Got wrong username length: %d\n",
447 test
->url
, urlw
.dwUserNameLength
);
448 ok(!strcmp_wa(username_w
, test
->exp_username
), "[%s] Got wrong username, expected: %s, got: %s\n",
449 test
->url
, test
->exp_username
, wine_dbgstr_w(username_w
));
451 ok(urlw
.dwPasswordLength
== strlen(test
->exp_password
), "[%s] Got wrong password length: %d\n",
452 test
->url
, urlw
.dwPasswordLength
);
453 ok(!strcmp_wa(password_w
, test
->exp_password
), "[%s] Got wrong password, expected: %s, got: %s\n",
454 test
->url
, test
->exp_password
, wine_dbgstr_w(password_w
));
456 ok(urlw
.dwUrlPathLength
== strlen(test
->exp_urlpath
), "[%s] Got wrong urlpath length: %d\n",
457 test
->url
, urlw
.dwUrlPathLength
);
458 ok(!strcmp_wa(urlpath_w
, test
->exp_urlpath
), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
459 test
->url
, test
->exp_urlpath
, wine_dbgstr_w(urlpath_w
));
461 ok(urlw
.dwExtraInfoLength
== strlen(test
->exp_extrainfo
), "[%s] Got wrong extrainfo length: %d\n",
462 test
->url
, urlw
.dwExtraInfoLength
);
463 ok(!strcmp_wa(extrainfo_w
, test
->exp_extrainfo
), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
464 test
->url
, test
->exp_extrainfo
, wine_dbgstr_w(extrainfo_w
));
466 HeapFree(GetProcessHeap(), 0, scheme_w
);
467 HeapFree(GetProcessHeap(), 0, hostname_w
);
468 HeapFree(GetProcessHeap(), 0, username_w
);
469 HeapFree(GetProcessHeap(), 0, password_w
);
470 HeapFree(GetProcessHeap(), 0, urlpath_w
);
471 HeapFree(GetProcessHeap(), 0, extrainfo_w
);
472 HeapFree(GetProcessHeap(), 0, buf
);
475 static void test_long_url(void)
478 char long_url
[sizeof(long_buf
) + 1000];
479 crack_url_test_t test_long_path
=
480 {long_url
, 0, 4, INTERNET_SCHEME_HTTP
, 7, 14, -1, 80, -1, 0, -1, 0, 21, sizeof(long_buf
)-1, -1, 0,
481 "http", "www.winehq.org", "", "", long_buf
, ""};
482 crack_url_test_t test_long_extra
=
483 {long_url
, 0, 4, INTERNET_SCHEME_HTTP
, 7, 14, -1, 80, -1, 0, -1, 0, 21, 6, 27, sizeof(long_buf
)-1,
484 "http", "www.winehq.org", "", "", "/path/", long_buf
};
485 URL_COMPONENTSA url_comp
;
488 memset(long_buf
, 'x', sizeof(long_buf
));
490 long_buf
[sizeof(long_buf
)-1] = 0;
492 strcpy(long_url
, "http://www.winehq.org");
493 strcat(long_url
, long_buf
);
494 test_crack_url(&test_long_path
);
496 strcpy(long_url
, "http://www.winehq.org/path/");
498 strcat(long_url
, long_buf
);
499 test_crack_url(&test_long_extra
);
501 zero_compsA(&url_comp
, 0, 0, 0, 0, 0, 100);
502 url_comp
.lpszExtraInfo
= long_buf
;
503 b
= InternetCrackUrlA(long_url
, strlen(long_url
), 0, &url_comp
);
504 ok(!b
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetCrackUrlA returned %x with error %d\n", b
, GetLastError());
506 zero_compsA(&url_comp
, 4, 0, 0, 0, 0, 0);
507 url_comp
.lpszScheme
= long_buf
;
508 b
= InternetCrackUrlA(long_url
, strlen(long_url
), 0, &url_comp
);
509 ok(!b
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetCrackUrlA returned %x with error %d\n", b
, GetLastError());
512 static void InternetCrackUrl_test(void)
514 URL_COMPONENTSA urlSrc
, urlComponents
;
515 char protocol
[32], hostName
[1024], userName
[1024];
516 char password
[1024], extra
[1024], path
[1024];
520 ZeroMemory(&urlSrc
, sizeof(urlSrc
));
521 urlSrc
.dwStructSize
= sizeof(urlSrc
);
522 urlSrc
.lpszScheme
= protocol
;
523 urlSrc
.lpszHostName
= hostName
;
524 urlSrc
.lpszUserName
= userName
;
525 urlSrc
.lpszPassword
= password
;
526 urlSrc
.lpszUrlPath
= path
;
527 urlSrc
.lpszExtraInfo
= extra
;
529 /* Tests for lpsz* members pointing to real strings while
530 * some corresponding length members are set to zero.
531 * As of IE7 (wininet 7.0*?) all members are checked. So we
532 * run the first test and expect the outcome to be the same
533 * for the first four (scheme, hostname, username and password).
534 * The last two (path and extrainfo) are the same for all versions
535 * of the wininet.dll.
537 copy_compsA(&urlSrc
, &urlComponents
, 0, 1024, 1024, 1024, 1024, 1024);
538 SetLastError(0xdeadbeef);
539 firstret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
540 firstGLE
= GetLastError();
542 copy_compsA(&urlSrc
, &urlComponents
, 32, 0, 1024, 1024, 1024, 1024);
543 SetLastError(0xdeadbeef);
544 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
545 GLE
= GetLastError();
546 ok(ret
==firstret
&& (GLE
==firstGLE
), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
549 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 0, 1024, 1024, 1024);
550 SetLastError(0xdeadbeef);
551 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
552 GLE
= GetLastError();
553 ok(ret
==firstret
&& (GLE
==firstGLE
), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
556 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 0, 1024, 1024);
557 SetLastError(0xdeadbeef);
558 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
559 GLE
= GetLastError();
560 ok(ret
==firstret
&& (GLE
==firstGLE
), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
563 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 0, 1024);
564 SetLastError(0xdeadbeef);
565 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
566 GLE
= GetLastError();
568 ok(ret
==0 && (GLE
==ERROR_INVALID_HANDLE
|| GLE
==ERROR_INSUFFICIENT_BUFFER
),
569 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
572 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 1024, 0);
573 SetLastError(0xdeadbeef);
574 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
575 GLE
= GetLastError();
577 ok(ret
==0 && (GLE
==ERROR_INVALID_HANDLE
|| GLE
==ERROR_INSUFFICIENT_BUFFER
),
578 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
581 copy_compsA(&urlSrc
, &urlComponents
, 0, 0, 0, 0, 0, 0);
582 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
583 GLE
= GetLastError();
585 ok(ret
==0 && GLE
==ERROR_INVALID_PARAMETER
,
586 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
589 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 1024, 1024);
590 ret
= InternetCrackUrlA("about://host/blank", 0,0,&urlComponents
);
591 ok(ret
, "InternetCrackUrl failed with %d\n", GetLastError());
592 ok(!strcmp(urlComponents
.lpszScheme
, "about"), "lpszScheme was \"%s\" instead of \"about\"\n", urlComponents
.lpszScheme
);
593 ok(!strcmp(urlComponents
.lpszHostName
, "host"), "lpszHostName was \"%s\" instead of \"host\"\n", urlComponents
.lpszHostName
);
594 ok(!strcmp(urlComponents
.lpszUrlPath
, "/blank"), "lpszUrlPath was \"%s\" instead of \"/blank\"\n", urlComponents
.lpszUrlPath
);
596 /* try a NULL lpszUrl */
597 SetLastError(0xdeadbeef);
598 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 1024, 1024);
599 ret
= InternetCrackUrlA(NULL
, 0, 0, &urlComponents
);
600 GLE
= GetLastError();
601 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
602 ok(GLE
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", GLE
);
604 /* try an empty lpszUrl, GetLastError returns 12006, whatever that means
605 * we just need to fail and not return success
607 SetLastError(0xdeadbeef);
608 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 1024, 1024);
609 ret
= InternetCrackUrlA("", 0, 0, &urlComponents
);
610 GLE
= GetLastError();
611 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
612 ok(GLE
!= 0xdeadbeef && GLE
!= ERROR_SUCCESS
, "Expected GLE to represent a failure\n");
614 /* Invalid Call: must set size of components structure (Windows only
615 * enforces this on the InternetCrackUrlA version of the call) */
616 copy_compsA(&urlSrc
, &urlComponents
, 0, 1024, 1024, 1024, 1024, 1024);
617 SetLastError(0xdeadbeef);
618 urlComponents
.dwStructSize
= 0;
619 ret
= InternetCrackUrlA(TEST_URL
, 0, 0, &urlComponents
);
620 GLE
= GetLastError();
621 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
622 ok(GLE
!= 0xdeadbeef && GLE
!= ERROR_SUCCESS
, "Expected GLE to represent a failure\n");
624 /* Invalid Call: size of dwStructSize must be one of the "standard" sizes
625 * of the URL_COMPONENTS structure (Windows only enforces this on the
626 * InternetCrackUrlA version of the call) */
627 copy_compsA(&urlSrc
, &urlComponents
, 0, 1024, 1024, 1024, 1024, 1024);
628 SetLastError(0xdeadbeef);
629 urlComponents
.dwStructSize
= sizeof(urlComponents
) + 1;
630 ret
= InternetCrackUrlA(TEST_URL
, 0, 0, &urlComponents
);
631 GLE
= GetLastError();
632 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
633 ok(GLE
!= 0xdeadbeef && GLE
!= ERROR_SUCCESS
, "Expected GLE to represent a failure\n");
635 SetLastError(0xdeadbeef);
636 memset(&urlComponents
, 0, sizeof(urlComponents
));
637 urlComponents
.dwStructSize
= sizeof(urlComponents
);
638 ret
= InternetCrackUrlA("file.txt", 0, 0, &urlComponents
);
639 GLE
= GetLastError();
640 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
641 ok(GLE
== ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "Expected GLE to represent a failure\n");
643 SetLastError(0xdeadbeef);
644 memset(&urlComponents
, 0, sizeof(urlComponents
));
645 urlComponents
.dwStructSize
= sizeof(urlComponents
);
646 ret
= InternetCrackUrlA("www.winehq.org", 0, 0, &urlComponents
);
647 GLE
= GetLastError();
648 ok(ret
== FALSE
, "Expected InternetCrackUrl to fail\n");
649 ok(GLE
== ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "Expected GLE to represent a failure\n");
652 static void InternetCrackUrlW_test(void)
655 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
656 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
657 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
659 static const WCHAR url2
[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
660 static const WCHAR url3
[] = { 'h','t','t','p',':','/','/','x','.','o','r','g',0 };
661 URL_COMPONENTSW comp
;
662 WCHAR scheme
[20], host
[20], user
[20], pwd
[20], urlpart
[50], extra
[50];
672 memset(&comp
, 0, sizeof comp
);
673 comp
.dwStructSize
= sizeof(comp
);
674 comp
.lpszScheme
= scheme
;
675 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
676 comp
.lpszHostName
= host
;
677 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
678 comp
.lpszUserName
= user
;
679 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
680 comp
.lpszPassword
= pwd
;
681 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
682 comp
.lpszUrlPath
= urlpart
;
683 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
684 comp
.lpszExtraInfo
= extra
;
685 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
687 SetLastError(0xdeadbeef);
688 r
= InternetCrackUrlW(NULL
, 0, 0, &comp
);
689 error
= GetLastError();
690 if (!r
&& error
== ERROR_CALL_NOT_IMPLEMENTED
)
692 win_skip("InternetCrackUrlW is not implemented\n");
695 ok( !r
, "InternetCrackUrlW succeeded unexpectedly\n");
696 ok( error
== ERROR_INVALID_PARAMETER
||
697 broken(error
== ERROR_INTERNET_UNRECOGNIZED_SCHEME
), /* IE5 */
698 "expected ERROR_INVALID_PARAMETER got %u\n", error
);
700 if (error
== ERROR_INVALID_PARAMETER
)
703 SetLastError(0xdeadbeef);
704 r
= InternetCrackUrlW(url
, 0, 0, NULL
);
705 error
= GetLastError();
706 ok( !r
, "InternetCrackUrlW succeeded unexpectedly\n");
707 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
710 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
711 ok( r
, "failed to crack url\n");
712 ok( comp
.dwSchemeLength
== 4, "scheme length wrong\n");
713 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
714 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
715 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
716 ok( comp
.dwUrlPathLength
== 15, "url length wrong\n");
717 ok( comp
.dwExtraInfoLength
== 29, "extra length wrong\n");
721 memset(&comp
, 0, sizeof comp
);
722 comp
.dwStructSize
= sizeof comp
;
723 comp
.lpszHostName
= host
;
724 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
725 comp
.lpszUrlPath
= urlpart
;
726 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
728 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
729 ok( r
, "failed to crack url\n");
730 ok( comp
.dwSchemeLength
== 0, "scheme length wrong\n");
731 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
732 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
733 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
734 ok( comp
.dwUrlPathLength
== 44, "url length wrong\n");
735 ok( comp
.dwExtraInfoLength
== 0, "extra length wrong\n");
739 memset(&comp
, 0, sizeof comp
);
740 comp
.dwStructSize
= sizeof comp
;
741 comp
.lpszHostName
= host
;
742 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
743 comp
.lpszUrlPath
= urlpart
;
744 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
745 comp
.lpszExtraInfo
= NULL
;
746 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
748 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
749 ok( r
, "failed to crack url\n");
750 ok( comp
.dwSchemeLength
== 0, "scheme length wrong\n");
751 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
752 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
753 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
754 ok( comp
.dwUrlPathLength
== 15, "url length wrong\n");
755 ok( comp
.dwExtraInfoLength
== 29, "extra length wrong\n");
763 memset(&comp
, 0, sizeof(comp
));
764 comp
.dwStructSize
= sizeof(comp
);
765 comp
.lpszScheme
= scheme
;
766 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
767 comp
.lpszHostName
= host
;
768 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
769 comp
.lpszUserName
= user
;
770 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
771 comp
.lpszPassword
= pwd
;
772 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
773 comp
.lpszUrlPath
= urlpart
;
774 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
775 comp
.lpszExtraInfo
= extra
;
776 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
778 r
= InternetCrackUrlW(url2
, 0, 0, &comp
);
779 ok(!r
, "InternetCrackUrl should have failed\n");
780 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
,
781 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
784 /* Test to see whether cracking a URL without a filename initializes urlpart */
791 memset(&comp
, 0, sizeof comp
);
792 comp
.dwStructSize
= sizeof comp
;
793 comp
.lpszScheme
= scheme
;
794 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
795 comp
.lpszHostName
= host
;
796 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
797 comp
.lpszUserName
= user
;
798 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
799 comp
.lpszPassword
= pwd
;
800 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
801 comp
.lpszUrlPath
= urlpart
;
802 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
803 comp
.lpszExtraInfo
= extra
;
804 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
805 r
= InternetCrackUrlW(url3
, 0, 0, &comp
);
806 ok( r
, "InternetCrackUrlW failed unexpectedly\n");
807 ok( host
[0] == 'x', "host should be x.org\n");
808 ok( urlpart
[0] == 0, "urlpart should be empty\n");
812 memset(&comp
, 0, sizeof(comp
));
813 comp
.dwStructSize
= sizeof(comp
);
814 comp
.lpszHostName
= host
;
815 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
816 comp
.lpszUrlPath
= urlpart
;
817 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
818 r
= InternetCrackUrlW(url3
, 0, ICU_DECODE
, &comp
);
819 todo_wine
ok(r
, "InternetCrackUrlW failed unexpectedly\n");
820 todo_wine
ok(!strcmp_wa(host
, "x.org"), "host is %s, should be x.org\n", wine_dbgstr_w(host
));
821 ok(urlpart
[0] == 0, "urlpart should be empty\n");
824 static void fill_url_components(URL_COMPONENTSA
*lpUrlComponents
)
826 static CHAR http
[] = "http",
827 winehq
[] = "www.winehq.org",
828 username
[] = "username",
829 password
[] = "password",
830 site_about
[] = "/site/about",
833 lpUrlComponents
->dwStructSize
= sizeof(URL_COMPONENTSA
);
834 lpUrlComponents
->lpszScheme
= http
;
835 lpUrlComponents
->dwSchemeLength
= strlen(lpUrlComponents
->lpszScheme
);
836 lpUrlComponents
->nScheme
= INTERNET_SCHEME_HTTP
;
837 lpUrlComponents
->lpszHostName
= winehq
;
838 lpUrlComponents
->dwHostNameLength
= strlen(lpUrlComponents
->lpszHostName
);
839 lpUrlComponents
->nPort
= 80;
840 lpUrlComponents
->lpszUserName
= username
;
841 lpUrlComponents
->dwUserNameLength
= strlen(lpUrlComponents
->lpszUserName
);
842 lpUrlComponents
->lpszPassword
= password
;
843 lpUrlComponents
->dwPasswordLength
= strlen(lpUrlComponents
->lpszPassword
);
844 lpUrlComponents
->lpszUrlPath
= site_about
;
845 lpUrlComponents
->dwUrlPathLength
= strlen(lpUrlComponents
->lpszUrlPath
);
846 lpUrlComponents
->lpszExtraInfo
= empty
;
847 lpUrlComponents
->dwExtraInfoLength
= strlen(lpUrlComponents
->lpszExtraInfo
);
850 static void InternetCreateUrlA_test(void)
852 URL_COMPONENTSA urlComp
;
856 static CHAR empty
[] = "",
860 winehq
[] = "www.winehq.org",
861 localhost
[] = "localhost",
862 username
[] = "username",
863 password
[] = "password",
865 site_about
[] = "/site/about",
866 extra_info
[] = "?test=123",
871 /* test NULL lpUrlComponents */
872 SetLastError(0xdeadbeef);
873 ret
= InternetCreateUrlA(NULL
, 0, NULL
, &len
);
874 ok(!ret
, "Expected failure\n");
875 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
876 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
877 ok(len
== -1, "Expected len -1, got %d\n", len
);
879 /* test zero'ed lpUrlComponents */
880 ZeroMemory(&urlComp
, sizeof(urlComp
));
881 SetLastError(0xdeadbeef);
882 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
883 ok(!ret
, "Expected failure\n");
884 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
885 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
886 ok(len
== -1, "Expected len -1, got %d\n", len
);
888 /* test valid lpUrlComponents, NULL lpdwUrlLength */
889 fill_url_components(&urlComp
);
890 SetLastError(0xdeadbeef);
891 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, NULL
);
892 ok(!ret
, "Expected failure\n");
893 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
894 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
896 /* test valid lpUrlComponents, empty szUrl
897 * lpdwUrlLength is size of buffer required on exit, including
898 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
900 SetLastError(0xdeadbeef);
901 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
902 ok(!ret
, "Expected failure\n");
903 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
904 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
905 ok(len
== 51, "Expected len 51, got %d\n", len
);
907 /* test correct size, NULL szUrl */
908 fill_url_components(&urlComp
);
909 SetLastError(0xdeadbeef);
910 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
911 ok(!ret
, "Expected failure\n");
912 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
913 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
914 ok(len
== 51, "Expected len 51, got %d\n", len
);
916 /* test valid lpUrlComponents, alloc-ed szUrl, small size */
917 SetLastError(0xdeadbeef);
918 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
920 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
921 ok(!ret
, "Expected failure\n");
922 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
923 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
924 ok(len
== 51, "Expected len 51, got %d\n", len
);
926 /* alloc-ed szUrl, NULL lpszScheme
927 * shows that it uses nScheme instead
929 urlComp
.lpszScheme
= NULL
;
930 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
931 ok(ret
, "Expected success\n");
932 ok(len
== 50, "Expected len 50, got %d\n", len
);
933 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
935 /* alloc-ed szUrl, invalid nScheme
936 * any nScheme out of range seems ignored
938 fill_url_components(&urlComp
);
939 urlComp
.nScheme
= -3;
941 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
942 ok(ret
, "Expected success\n");
943 ok(len
== 50, "Expected len 50, got %d\n", len
);
945 /* test valid lpUrlComponents, alloc-ed szUrl */
946 fill_url_components(&urlComp
);
948 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
949 ok(ret
, "Expected success\n");
950 ok(len
== 50, "Expected len 50, got %d\n", len
);
951 ok(strstr(szUrl
, "80") == NULL
, "Didn't expect to find 80 in szUrl\n");
952 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
954 /* valid username, NULL password */
955 fill_url_components(&urlComp
);
956 urlComp
.lpszPassword
= NULL
;
958 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
959 ok(ret
, "Expected success\n");
960 ok(len
== 41, "Expected len 41, got %d\n", len
);
961 ok(!strcmp(szUrl
, CREATE_URL2
), "Expected %s, got %s\n", CREATE_URL2
, szUrl
);
963 /* valid username, empty password */
964 fill_url_components(&urlComp
);
965 urlComp
.lpszPassword
= empty
;
967 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
968 ok(ret
, "Expected success\n");
969 ok(len
== 50, "Expected len 50, got %d\n", len
);
970 ok(!strcmp(szUrl
, CREATE_URL3
), "Expected %s, got %s\n", CREATE_URL3
, szUrl
);
972 /* valid password, NULL username
973 * if password is provided, username has to exist
975 fill_url_components(&urlComp
);
976 SetLastError(0xdeadbeef);
977 urlComp
.lpszUserName
= NULL
;
979 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
980 ok(!ret
, "Expected failure\n");
981 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
982 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
983 ok(len
== 42, "Expected len 42, got %d\n", len
);
984 ok(!strcmp(szUrl
, CREATE_URL3
), "Expected %s, got %s\n", CREATE_URL3
, szUrl
);
986 /* valid password, empty username
987 * if password is provided, username has to exist
989 fill_url_components(&urlComp
);
990 urlComp
.lpszUserName
= empty
;
992 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
993 ok(ret
, "Expected success\n");
994 ok(len
== 50, "Expected len 50, got %d\n", len
);
995 ok(!strcmp(szUrl
, CREATE_URL5
), "Expected %s, got %s\n", CREATE_URL5
, szUrl
);
997 /* NULL username, NULL password */
998 fill_url_components(&urlComp
);
999 urlComp
.lpszUserName
= NULL
;
1000 urlComp
.lpszPassword
= NULL
;
1002 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
1003 ok(ret
, "Expected success\n");
1004 ok(len
== 32, "Expected len 32, got %d\n", len
);
1005 ok(!strcmp(szUrl
, CREATE_URL4
), "Expected %s, got %s\n", CREATE_URL4
, szUrl
);
1007 /* empty username, empty password */
1008 fill_url_components(&urlComp
);
1009 urlComp
.lpszUserName
= empty
;
1010 urlComp
.lpszPassword
= empty
;
1012 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
1013 ok(ret
, "Expected success\n");
1014 ok(len
== 50, "Expected len 50, got %d\n", len
);
1015 ok(!strcmp(szUrl
, CREATE_URL5
), "Expected %s, got %s\n", CREATE_URL5
, szUrl
);
1017 /* shows that nScheme is ignored, as the appearance of the port number
1018 * depends on lpszScheme and the string copied depends on lpszScheme.
1020 fill_url_components(&urlComp
);
1021 HeapFree(GetProcessHeap(), 0, szUrl
);
1022 urlComp
.lpszScheme
= nhttp
;
1023 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
1024 len
= strlen(CREATE_URL6
) + 1;
1025 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
1026 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1027 ok(ret
, "Expected success\n");
1028 ok(len
== strlen(CREATE_URL6
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6
) + 1, len
);
1029 ok(!strcmp(szUrl
, CREATE_URL6
), "Expected %s, got %s\n", CREATE_URL6
, szUrl
);
1031 /* if lpszScheme != "http" or nPort != 80, display nPort */
1032 HeapFree(GetProcessHeap(), 0, szUrl
);
1033 urlComp
.lpszScheme
= http
;
1034 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
1036 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1037 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1038 ok(ret
, "Expected success\n");
1039 ok(len
== 53, "Expected len 53, got %d\n", len
);
1040 ok(strstr(szUrl
, "42") != NULL
, "Expected to find 42 in szUrl\n");
1041 ok(!strcmp(szUrl
, CREATE_URL7
), "Expected %s, got %s\n", CREATE_URL7
, szUrl
);
1043 HeapFree(GetProcessHeap(), 0, szUrl
);
1045 memset(&urlComp
, 0, sizeof(urlComp
));
1046 urlComp
.dwStructSize
= sizeof(urlComp
);
1047 urlComp
.lpszScheme
= http
;
1048 urlComp
.dwSchemeLength
= 0;
1049 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
1050 urlComp
.lpszHostName
= winehq
;
1051 urlComp
.dwHostNameLength
= 0;
1053 urlComp
.lpszUserName
= username
;
1054 urlComp
.dwUserNameLength
= 0;
1055 urlComp
.lpszPassword
= password
;
1056 urlComp
.dwPasswordLength
= 0;
1057 urlComp
.lpszUrlPath
= site_about
;
1058 urlComp
.dwUrlPathLength
= 0;
1059 urlComp
.lpszExtraInfo
= empty
;
1060 urlComp
.dwExtraInfoLength
= 0;
1061 len
= strlen(CREATE_URL1
);
1062 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1063 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1064 ok(ret
, "Expected success\n");
1065 ok(len
== strlen(CREATE_URL1
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1
), len
);
1066 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
1068 HeapFree(GetProcessHeap(), 0, szUrl
);
1070 memset(&urlComp
, 0, sizeof(urlComp
));
1071 urlComp
.dwStructSize
= sizeof(urlComp
);
1072 urlComp
.lpszScheme
= https
;
1073 urlComp
.dwSchemeLength
= 0;
1074 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
1075 urlComp
.lpszHostName
= winehq
;
1076 urlComp
.dwHostNameLength
= 0;
1077 urlComp
.nPort
= 443;
1078 urlComp
.lpszUserName
= username
;
1079 urlComp
.dwUserNameLength
= 0;
1080 urlComp
.lpszPassword
= password
;
1081 urlComp
.dwPasswordLength
= 0;
1082 urlComp
.lpszUrlPath
= site_about
;
1083 urlComp
.dwUrlPathLength
= 0;
1084 urlComp
.lpszExtraInfo
= empty
;
1085 urlComp
.dwExtraInfoLength
= 0;
1086 len
= strlen(CREATE_URL8
);
1087 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1088 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1089 ok(ret
, "Expected success\n");
1090 ok(len
== strlen(CREATE_URL8
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8
), len
);
1091 ok(!strcmp(szUrl
, CREATE_URL8
), "Expected %s, got %s\n", CREATE_URL8
, szUrl
);
1093 HeapFree(GetProcessHeap(), 0, szUrl
);
1095 memset(&urlComp
, 0, sizeof(urlComp
));
1096 urlComp
.dwStructSize
= sizeof(urlComp
);
1097 urlComp
.lpszScheme
= about
;
1098 urlComp
.dwSchemeLength
= 5;
1099 urlComp
.lpszUrlPath
= blank
;
1100 urlComp
.dwUrlPathLength
= 5;
1101 len
= strlen(CREATE_URL9
);
1102 len
++; /* work around bug in native wininet */
1103 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1104 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1105 ok(ret
, "Expected success\n");
1106 ok(len
== strlen(CREATE_URL9
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9
), len
);
1107 ok(!strcmp(szUrl
, CREATE_URL9
), "Expected %s, got %s\n", CREATE_URL9
, szUrl
);
1109 HeapFree(GetProcessHeap(), 0, szUrl
);
1111 memset(&urlComp
, 0, sizeof(urlComp
));
1112 urlComp
.dwStructSize
= sizeof(urlComp
);
1113 urlComp
.lpszScheme
= about
;
1114 urlComp
.lpszHostName
= host
;
1115 urlComp
.lpszUrlPath
= blank
;
1116 len
= strlen(CREATE_URL10
);
1117 len
++; /* work around bug in native wininet */
1118 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1119 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1120 ok(ret
, "Expected success\n");
1121 ok(len
== strlen(CREATE_URL10
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10
), len
);
1122 ok(!strcmp(szUrl
, CREATE_URL10
), "Expected %s, got %s\n", CREATE_URL10
, szUrl
);
1124 HeapFree(GetProcessHeap(), 0, szUrl
);
1126 memset(&urlComp
, 0, sizeof(urlComp
));
1127 urlComp
.dwStructSize
= sizeof(urlComp
);
1128 urlComp
.nPort
= 8080;
1129 urlComp
.lpszScheme
= about
;
1130 len
= strlen(CREATE_URL11
);
1131 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1132 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1133 ok(ret
, "Expected success\n");
1134 ok(len
== strlen(CREATE_URL11
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11
), len
);
1135 ok(!strcmp(szUrl
, CREATE_URL11
), "Expected %s, got %s\n", CREATE_URL11
, szUrl
);
1137 HeapFree(GetProcessHeap(), 0, szUrl
);
1139 memset(&urlComp
, 0, sizeof(urlComp
));
1140 urlComp
.dwStructSize
= sizeof(urlComp
);
1141 urlComp
.lpszScheme
= http
;
1142 urlComp
.dwSchemeLength
= 0;
1143 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
1144 urlComp
.lpszHostName
= winehq
;
1145 urlComp
.dwHostNameLength
= 0;
1146 urlComp
.nPort
= 65535;
1147 len
= strlen(CREATE_URL12
);
1148 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
1149 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1150 ok(ret
, "Expected success\n");
1151 ok(len
== strlen(CREATE_URL12
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12
), len
);
1152 ok(!strcmp(szUrl
, CREATE_URL12
), "Expected %s, got %s\n", CREATE_URL12
, szUrl
);
1154 HeapFree(GetProcessHeap(), 0, szUrl
);
1156 memset(&urlComp
, 0, sizeof(urlComp
));
1157 urlComp
.dwStructSize
= sizeof(urlComp
);
1158 urlComp
.lpszScheme
= http
;
1159 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
1160 urlComp
.lpszHostName
= localhost
;
1161 urlComp
.dwHostNameLength
= strlen(urlComp
.lpszHostName
);
1163 urlComp
.lpszUrlPath
= root
;
1164 urlComp
.dwUrlPathLength
= strlen(urlComp
.lpszUrlPath
);
1165 urlComp
.lpszExtraInfo
= extra_info
;
1166 urlComp
.dwExtraInfoLength
= strlen(urlComp
.lpszExtraInfo
);
1168 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
1169 InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
1170 ok(ret
, "Expected success\n");
1171 ok(len
== strlen(CREATE_URL13
), "Got len %u\n", len
);
1172 ok(!strcmp(szUrl
, CREATE_URL13
), "Expected \"%s\", got \"%s\"\n", CREATE_URL13
, szUrl
);
1174 HeapFree(GetProcessHeap(), 0, szUrl
);
1177 static void InternetCanonicalizeUrl_test(void)
1179 char src
[] = "http://www.winehq.org/%27/ /./>/#> ";
1183 dstlen
= sizeof(dst
);
1184 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, 0);
1185 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1187 /* despite what MSDN says, ICU_BROWSER_MODE seems to be ignored */
1188 dstlen
= sizeof(dst
);
1189 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_BROWSER_MODE
);
1190 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1192 /* ICU_ESCAPE is supposed to be ignored */
1193 dstlen
= sizeof(dst
);
1194 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_ESCAPE
);
1195 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1197 dstlen
= sizeof(dst
);
1198 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_DECODE
);
1199 ok(strcmp(dst
, "http://www.winehq.org/'/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1201 dstlen
= sizeof(dst
);
1202 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_ENCODE_PERCENT
);
1203 ok(strcmp(dst
, "http://www.winehq.org/%2527/%20/%3E/#>") == 0, "Got \"%s\"\n", dst
);
1205 dstlen
= sizeof(dst
);
1206 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_ENCODE_SPACES_ONLY
);
1207 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/>/#>") == 0, "Got \"%s\"\n", dst
);
1209 dstlen
= sizeof(dst
);
1210 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_NO_ENCODE
);
1211 ok(strcmp(dst
, "http://www.winehq.org/%27/ />/#>") == 0, "Got \"%s\"\n", dst
);
1213 dstlen
= sizeof(dst
);
1214 InternetCanonicalizeUrlA(src
, dst
, &dstlen
, ICU_NO_META
);
1215 ok(strcmp(dst
, "http://www.winehq.org/%27/%20/./%3E/#>") == 0, "Got \"%s\"\n", dst
);
1222 if(!GetProcAddress(GetModuleHandleA("wininet.dll"), "InternetGetCookieExW")) {
1223 win_skip("Too old IE (older than 6.0)\n");
1227 for(i
=0; i
< sizeof(crack_url_tests
)/sizeof(*crack_url_tests
); i
++)
1228 test_crack_url(crack_url_tests
+i
);
1232 InternetCrackUrl_test();
1233 InternetCrackUrlW_test();
1234 InternetCreateUrlA_test();
1235 InternetCanonicalizeUrl_test();