1 /* 2 * Wininet - URL tests 3 * 4 * Copyright 2002 Aric Stewart 5 * Copyright 2004 Mike McCormack 6 * Copyright 2005 Hans Leidekker 7 * 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. 12 * 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. 17 * 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 21 */ 22 23 #include <stdarg.h> 24 #include <stdio.h> 25 #include <stdlib.h> 26 #include <string.h> 27 28 #include "windef.h" 29 #include "winbase.h" 30 #include "winnls.h" 31 #include "wininet.h" 32 33 #include "wine/test.h" 34 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" 37 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" 51 52 static void copy_compsA( 53 URL_COMPONENTSA *src, 54 URL_COMPONENTSA *dst, 55 DWORD scheLen, 56 DWORD hostLen, 57 DWORD userLen, 58 DWORD passLen, 59 DWORD pathLen, 60 DWORD extrLen ) 61 { 62 *dst = *src; 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); 70 } 71 72 static void zero_compsA( 73 URL_COMPONENTSA *dst, 74 DWORD scheLen, 75 DWORD hostLen, 76 DWORD userLen, 77 DWORD passLen, 78 DWORD pathLen, 79 DWORD extrLen ) 80 { 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); 90 } 91 92 typedef struct { 93 const char *url; 94 int scheme_off; 95 int scheme_len; 96 INTERNET_SCHEME scheme; 97 int host_off; 98 int host_len; 99 int host_skip_broken; 100 INTERNET_PORT port; 101 int user_off; 102 int user_len; 103 int pass_off; 104 int pass_len; 105 int path_off; 106 int path_len; 107 int extra_off; 108 int extra_len; 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; 115 } crack_url_test_t; 116 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", ""}, 169 {"C:\\file.txt", 170 0, 1, INTERNET_SCHEME_UNKNOWN, -1, 0, -1, 0, -1, 0, -1, 0, 2, 9, -1, 0, 171 "C", "", "", "", "\\file.txt", ""} 172 }; 173 174 static WCHAR *a2w(const char *str) 175 { 176 WCHAR *ret; 177 int len; 178 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); 182 return ret; 183 } 184 185 static int strcmp_wa(const WCHAR *str1, const char *str2) 186 { 187 WCHAR *str2w = a2w(str2); 188 int ret = lstrcmpW(str1, str2w); 189 HeapFree(GetProcessHeap(), 0, str2w); 190 return ret; 191 } 192 193 static void test_crack_url(const crack_url_test_t *test) 194 { 195 URL_COMPONENTSW urlw; 196 URL_COMPONENTSA url; 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); 202 WCHAR *buf; 203 BOOL b; 204 205 /* test InternetCrackUrlA with NULL buffers */ 206 zero_compsA(&url, 1, 1, 1, 1, 1, 1); 207 208 b = InternetCrackUrlA(test->url, strlen(test->url), 0, &url); 209 ok(b, "InternetCrackUrl failed with error %d\n", GetLastError()); 210 211 if(test->scheme_off == -1) 212 ok(!url.lpszScheme, "[%s] url.lpszScheme = %p, expected NULL\n", test->url, url.lpszScheme); 213 else 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); 218 219 ok(url.nScheme == test->scheme, "[%s] url.nScheme = %d, expected %d\n", test->url, url.nScheme, test->scheme); 220 221 if(test->host_off == -1) 222 ok(!url.lpszHostName, "[%s] url.lpszHostName = %p, expected NULL\n", test->url, url.lpszHostName); 223 else 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"); 228 return; 229 } 230 ok(url.dwHostNameLength == test->host_len, "[%s] url.lpszHostNameLength = %d, expected %d\n", 231 test->url, url.dwHostNameLength, test->host_len); 232 233 ok(url.nPort == test->port, "[%s] nPort = %d, expected %d\n", test->url, url.nPort, test->port); 234 235 if(test->user_off == -1) 236 ok(!url.lpszUserName, "[%s] url.lpszUserName = %p\n", test->url, url.lpszUserName); 237 else 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); 242 243 if(test->pass_off == -1) 244 ok(!url.lpszPassword, "[%s] url.lpszPassword = %p\n", test->url, url.lpszPassword); 245 else 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); 250 251 if(test->path_off == -1) 252 ok(!url.lpszUrlPath, "[%s] url.lpszUrlPath = %p, expected NULL\n", test->url, url.lpszUrlPath); 253 else 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); 258 259 if(test->extra_off == -1) 260 ok(!url.lpszExtraInfo, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test->url, url.lpszExtraInfo); 261 else 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); 266 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; 276 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); 282 return; 283 } 284 ok(b, "InternetCrackUrl failed with error %d\n", GetLastError()); 285 286 if(test->scheme_off == -1) 287 ok(!urlw.lpszScheme, "[%s] urlw.lpszScheme = %p, expected NULL\n", test->url, urlw.lpszScheme); 288 else 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); 293 294 ok(urlw.nScheme == test->scheme, "[%s] urlw.nScheme = %d, expected %d\n", test->url, urlw.nScheme, test->scheme); 295 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); 300 }else { 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); 305 } 306 307 ok(urlw.nPort == test->port, "[%s] nPort = %d, expected %d\n", test->url, urlw.nPort, test->port); 308 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); 313 }else { 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); 318 } 319 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); 324 }else { 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); 329 } 330 331 if(test->path_off == -1) 332 ok(!urlw.lpszUrlPath, "[%s] urlw.lpszUrlPath = %p, expected NULL\n", test->url, urlw.lpszUrlPath); 333 else 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); 338 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); 343 }else { 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); 348 } 349 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; 371 372 b = InternetCrackUrlA(test->url, strlen(test->url), 0, &url); 373 ok(b, "InternetCrackUrlA failed with error %d\n", GetLastError()); 374 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); 379 380 ok(url.nScheme == test->scheme, "[%s] Got wrong nScheme, expected: %d, got: %d\n", 381 test->url, test->scheme, url.nScheme); 382 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); 387 388 ok(url.nPort == test->port, "[%s] Got wrong port, expected: %d, got: %d\n", 389 test->url, test->port, url.nPort); 390 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); 395 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); 400 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); 405 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); 410 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; 426 427 b = InternetCrackUrlW(buf, lstrlenW(buf), 0, &urlw); 428 ok(b, "InternetCrackUrlW failed with error %d\n", GetLastError()); 429 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)); 434 435 ok(urlw.nScheme == test->scheme, "[%s] Got wrong nScheme, expected: %d, got: %d\n", 436 test->url, test->scheme, urlw.nScheme); 437 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)); 442 443 ok(urlw.nPort == test->port, "[%s] Got wrong port, expected: %d, got: %d\n", 444 test->url, test->port, urlw.nPort); 445 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)); 450 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)); 455 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)); 460 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)); 465 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); 473 } 474 475 static void test_long_url(void) 476 { 477 char long_buf[6000]; 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; 486 BOOL b; 487 488 memset(long_buf, 'x', sizeof(long_buf)); 489 long_buf[0] = '/'; 490 long_buf[sizeof(long_buf)-1] = 0; 491 492 strcpy(long_url, "http://www.winehq.org"); 493 strcat(long_url, long_buf); 494 test_crack_url(&test_long_path); 495 496 strcpy(long_url, "http://www.winehq.org/path/"); 497 long_buf[0] = '#'; 498 strcat(long_url, long_buf); 499 test_crack_url(&test_long_extra); 500 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()); 505 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()); 510 } 511 512 static void InternetCrackUrl_test(void) 513 { 514 URL_COMPONENTSA urlSrc, urlComponents; 515 char protocol[32], hostName[1024], userName[1024]; 516 char password[1024], extra[1024], path[1024]; 517 BOOL ret, firstret; 518 DWORD GLE, firstGLE; 519 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; 528 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. 536 */ 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(); 541 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", 547 ret, GLE, firstret); 548 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", 554 ret, GLE, firstret); 555 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", 561 ret, GLE, firstret); 562 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(); 567 todo_wine 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", 570 ret, GLE); 571 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(); 576 todo_wine 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", 579 ret, GLE); 580 581 copy_compsA(&urlSrc, &urlComponents, 0, 0, 0, 0, 0, 0); 582 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents); 583 GLE = GetLastError(); 584 todo_wine 585 ok(ret==0 && GLE==ERROR_INVALID_PARAMETER, 586 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_PARAMETER)\n", 587 ret, GLE); 588 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); 595 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); 603 604 /* try an empty lpszUrl, GetLastError returns 12006, whatever that means 605 * we just need to fail and not return success 606 */ 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"); 613 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"); 623 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"); 634 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"); 642 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"); 650 } 651 652 static void InternetCrackUrlW_test(void) 653 { 654 WCHAR url[] = { 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', 658 'U','L','T', 0 }; 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]; 663 DWORD error; 664 BOOL r; 665 666 urlpart[0]=0; 667 scheme[0]=0; 668 extra[0]=0; 669 host[0]=0; 670 user[0]=0; 671 pwd[0]=0; 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]); 686 687 SetLastError(0xdeadbeef); 688 r = InternetCrackUrlW(NULL, 0, 0, &comp ); 689 error = GetLastError(); 690 if (!r && error == ERROR_CALL_NOT_IMPLEMENTED) 691 { 692 win_skip("InternetCrackUrlW is not implemented\n"); 693 return; 694 } 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); 699 700 if (error == ERROR_INVALID_PARAMETER) 701 { 702 /* Crashes on IE5 */ 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); 708 } 709 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"); 718 719 urlpart[0]=0; 720 host[0]=0; 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]); 727 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"); 736 737 urlpart[0]=0; 738 host[0]=0; 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]); 747 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"); 756 757 urlpart[0]=0; 758 scheme[0]=0; 759 extra[0]=0; 760 host[0]=0; 761 user[0]=0; 762 pwd[0]=0; 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]); 777 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", 782 GetLastError()); 783 784 /* Test to see whether cracking a URL without a filename initializes urlpart */ 785 urlpart[0]=0xba; 786 scheme[0]=0; 787 extra[0]=0; 788 host[0]=0; 789 user[0]=0; 790 pwd[0]=0; 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"); 809 810 urlpart[0] = 0; 811 host[0] = 0; 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 ok(r, "InternetCrackUrlW failed unexpectedly\n"); 820 ok(!strcmp_wa(host, "x.org"), "host is %s, should be x.org\n", wine_dbgstr_w(host)); 821 todo_wine ok(urlpart[0] == 0, "urlpart should be empty\n"); 822 } 823 824 static void fill_url_components(URL_COMPONENTSA *lpUrlComponents) 825 { 826 static CHAR http[] = "http", 827 winehq[] = "www.winehq.org", 828 username[] = "username", 829 password[] = "password", 830 site_about[] = "/site/about", 831 empty[] = ""; 832 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); 848 } 849 850 static void InternetCreateUrlA_test(void) 851 { 852 URL_COMPONENTSA urlComp; 853 LPSTR szUrl; 854 DWORD len = -1; 855 BOOL ret; 856 static CHAR empty[] = "", 857 nhttp[] = "nhttp", 858 http[] = "http", 859 https[] = "https", 860 winehq[] = "www.winehq.org", 861 localhost[] = "localhost", 862 username[] = "username", 863 password[] = "password", 864 root[] = "/", 865 site_about[] = "/site/about", 866 extra_info[] = "?test=123", 867 about[] = "about", 868 blank[] = "blank", 869 host[] = "host"; 870 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); 878 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); 887 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()); 895 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 899 */ 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); 906 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); 915 916 /* test valid lpUrlComponents, alloc-ed szUrl, small size */ 917 SetLastError(0xdeadbeef); 918 szUrl = HeapAlloc(GetProcessHeap(), 0, len); 919 len -= 2; 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); 925 926 /* alloc-ed szUrl, NULL lpszScheme 927 * shows that it uses nScheme instead 928 */ 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); 934 935 /* alloc-ed szUrl, invalid nScheme 936 * any nScheme out of range seems ignored 937 */ 938 fill_url_components(&urlComp); 939 urlComp.nScheme = -3; 940 len++; 941 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len); 942 ok(ret, "Expected success\n"); 943 ok(len == 50, "Expected len 50, got %d\n", len); 944 945 /* test valid lpUrlComponents, alloc-ed szUrl */ 946 fill_url_components(&urlComp); 947 len = 51; 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); 953 954 /* valid username, NULL password */ 955 fill_url_components(&urlComp); 956 urlComp.lpszPassword = NULL; 957 len = 42; 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); 962 963 /* valid username, empty password */ 964 fill_url_components(&urlComp); 965 urlComp.lpszPassword = empty; 966 len = 51; 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); 971 972 /* valid password, NULL username 973 * if password is provided, username has to exist 974 */ 975 fill_url_components(&urlComp); 976 SetLastError(0xdeadbeef); 977 urlComp.lpszUserName = NULL; 978 len = 42; 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); 985 986 /* valid password, empty username 987 * if password is provided, username has to exist 988 */ 989 fill_url_components(&urlComp); 990 urlComp.lpszUserName = empty; 991 len = 51; 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); 996 997 /* NULL username, NULL password */ 998 fill_url_components(&urlComp); 999 urlComp.lpszUserName = NULL; 1000 urlComp.lpszPassword = NULL; 1001 len = 42; 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); 1006 1007 /* empty username, empty password */ 1008 fill_url_components(&urlComp); 1009 urlComp.lpszUserName = empty; 1010 urlComp.lpszPassword = empty; 1011 len = 51; 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); 1016 1017 /* shows that nScheme is ignored, as the appearance of the port number 1018 * depends on lpszScheme and the string copied depends on lpszScheme. 1019 */ 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); 1030 1031 /* if lpszScheme != "http" or nPort != 80, display nPort */ 1032 HeapFree(GetProcessHeap(), 0, szUrl); 1033 urlComp.lpszScheme = http; 1034 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme); 1035 urlComp.nPort = 42; 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); 1042 1043 HeapFree(GetProcessHeap(), 0, szUrl); 1044 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; 1052 urlComp.nPort = 80; 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); 1067 1068 HeapFree(GetProcessHeap(), 0, szUrl); 1069 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); 1092 1093 HeapFree(GetProcessHeap(), 0, szUrl); 1094 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); 1108 1109 HeapFree(GetProcessHeap(), 0, szUrl); 1110 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); 1123 1124 HeapFree(GetProcessHeap(), 0, szUrl); 1125 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); 1136 1137 HeapFree(GetProcessHeap(), 0, szUrl); 1138 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); 1153 1154 HeapFree(GetProcessHeap(), 0, szUrl); 1155 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); 1162 urlComp.nPort = 80; 1163 urlComp.lpszUrlPath = root; 1164 urlComp.dwUrlPathLength = strlen(urlComp.lpszUrlPath); 1165 urlComp.lpszExtraInfo = extra_info; 1166 urlComp.dwExtraInfoLength = strlen(urlComp.lpszExtraInfo); 1167 len = 256; 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); 1173 1174 HeapFree(GetProcessHeap(), 0, szUrl); 1175 } 1176 1177 static void InternetCanonicalizeUrl_test(void) 1178 { 1179 char src[] = "http://www.winehq.org/%27/ /./>/#> "; 1180 char dst[64]; 1181 DWORD dstlen; 1182 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); 1186 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); 1191 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); 1196 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); 1200 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); 1204 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); 1208 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); 1212 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); 1216 } 1217 1218 START_TEST(url) 1219 { 1220 int i; 1221 1222 if(!GetProcAddress(GetModuleHandleA("wininet.dll"), "InternetGetCookieExW")) { 1223 win_skip("Too old IE (older than 6.0)\n"); 1224 return; 1225 } 1226 1227 for(i=0; i < sizeof(crack_url_tests)/sizeof(*crack_url_tests); i++) 1228 test_crack_url(crack_url_tests+i); 1229 1230 test_long_url(); 1231 1232 InternetCrackUrl_test(); 1233 InternetCrackUrlW_test(); 1234 InternetCreateUrlA_test(); 1235 InternetCanonicalizeUrl_test(); 1236 } 1237