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
31 #include "wine/test.h"
33 #define TEST_URL "http://www.winehq.org/site/about#hi"
34 #define TEST_URL_HOST "www.winehq.org"
35 #define TEST_URL_PATH "/site/about"
36 #define TEST_URL_HASH "#hi"
37 #define TEST_URL2 "http://www.myserver.com/myscript.php?arg=1"
38 #define TEST_URL2_SERVER "www.myserver.com"
39 #define TEST_URL2_PATH "/myscript.php"
40 #define TEST_URL2_PATHEXTRA "/myscript.php?arg=1"
41 #define TEST_URL2_EXTRA "?arg=1"
42 #define TEST_URL3 "file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml"
44 #define CREATE_URL1 "http://username:password@www.winehq.org/site/about"
45 #define CREATE_URL2 "http://username@www.winehq.org/site/about"
46 #define CREATE_URL3 "http://username:"
47 #define CREATE_URL4 "http://www.winehq.org/site/about"
48 #define CREATE_URL5 "http://"
49 #define CREATE_URL6 "nhttp://username:password@www.winehq.org:80/site/about"
50 #define CREATE_URL7 "http://username:password@www.winehq.org:42/site/about"
51 #define CREATE_URL8 "https://username:password@www.winehq.org/site/about"
52 #define CREATE_URL9 "about:blank"
53 #define CREATE_URL10 "about://host/blank"
54 #define CREATE_URL11 "about:"
55 #define CREATE_URL12 "http://www.winehq.org:65535"
56 #define CREATE_URL13 "http://localhost/?test=123"
58 static void copy_compsA(
69 dst->dwSchemeLength = scheLen;
70 dst->dwHostNameLength = hostLen;
71 dst->dwUserNameLength = userLen;
72 dst->dwPasswordLength = passLen;
73 dst->dwUrlPathLength = pathLen;
74 dst->dwExtraInfoLength = extrLen;
75 SetLastError(0xfaceabad);
78 static void zero_compsA(
87 ZeroMemory(dst, sizeof(URL_COMPONENTSA));
88 dst->dwStructSize = sizeof(URL_COMPONENTSA);
89 dst->dwSchemeLength = scheLen;
90 dst->dwHostNameLength = hostLen;
91 dst->dwUserNameLength = userLen;
92 dst->dwPasswordLength = passLen;
93 dst->dwUrlPathLength = pathLen;
94 dst->dwExtraInfoLength = extrLen;
95 SetLastError(0xfaceabad);
98 static void InternetCrackUrl_test(void)
100 URL_COMPONENTSA urlSrc, urlComponents;
101 char protocol[32], hostName[1024], userName[1024];
102 char password[1024], extra[1024], path[1024];
106 ZeroMemory(&urlSrc, sizeof(urlSrc));
107 urlSrc.dwStructSize = sizeof(urlSrc);
108 urlSrc.lpszScheme = protocol;
109 urlSrc.lpszHostName = hostName;
110 urlSrc.lpszUserName = userName;
111 urlSrc.lpszPassword = password;
112 urlSrc.lpszUrlPath = path;
113 urlSrc.lpszExtraInfo = extra;
115 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
116 ret = InternetCrackUrl(TEST_URL, 0,0,&urlComponents);
117 ok( ret, "InternetCrackUrl failed, error %d\n",GetLastError());
118 ok((strcmp(TEST_URL_PATH,path) == 0),"path cracked wrong\n");
120 /* Bug 1805: Confirm the returned lengths are correct: */
121 /* 1. When extra info split out explicitly */
122 zero_compsA(&urlComponents, 0, 1, 0, 0, 1, 1);
123 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed, error %d\n", GetLastError());
124 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATH),".dwUrlPathLength should be %d, but is %d\n", (DWORD)strlen(TEST_URL2_PATH), urlComponents.dwUrlPathLength);
125 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATH,strlen(TEST_URL2_PATH)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATH, urlComponents.lpszUrlPath);
126 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %d, but is %d\n", (DWORD)strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
127 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
128 ok(urlComponents.dwExtraInfoLength == strlen(TEST_URL2_EXTRA),".dwExtraInfoLength should be %d, but is %d\n", (DWORD)strlen(TEST_URL2_EXTRA), urlComponents.dwExtraInfoLength);
129 ok(!strncmp(urlComponents.lpszExtraInfo,TEST_URL2_EXTRA,strlen(TEST_URL2_EXTRA)),"lpszExtraInfo should be %s but is %s\n", TEST_URL2_EXTRA, urlComponents.lpszHostName);
131 /* 2. When extra info is not split out explicitly and is in url path */
132 zero_compsA(&urlComponents, 0, 1, 0, 0, 1, 0);
133 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed with GLE %d\n",GetLastError());
134 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATHEXTRA),".dwUrlPathLength should be %d, but is %d\n", (DWORD)strlen(TEST_URL2_PATHEXTRA), urlComponents.dwUrlPathLength);
135 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATHEXTRA,strlen(TEST_URL2_PATHEXTRA)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATHEXTRA, urlComponents.lpszUrlPath);
136 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %d, but is %d\n", (DWORD)strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
137 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
138 ok(urlComponents.nPort == INTERNET_DEFAULT_HTTP_PORT,"urlComponents->nPort should have been 80 instead of %d\n", urlComponents.nPort);
139 ok(urlComponents.nScheme == INTERNET_SCHEME_HTTP,"urlComponents->nScheme should have been INTERNET_SCHEME_HTTP instead of %d\n", urlComponents.nScheme);
141 zero_compsA(&urlComponents, 1, 1, 1, 1, 1, 1);
142 ok(InternetCrackUrlA(TEST_URL, strlen(TEST_URL), 0, &urlComponents),"InternetCrackUrl failed with GLE %d\n",GetLastError());
143 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL_PATH),".dwUrlPathLength should be %d, but is %d\n", lstrlenA(TEST_URL_PATH), urlComponents.dwUrlPathLength);
144 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL_PATH,strlen(TEST_URL_PATH)),"lpszUrlPath should be %s but is %s\n", TEST_URL_PATH, urlComponents.lpszUrlPath);
145 ok(urlComponents.dwHostNameLength == strlen(TEST_URL_HOST),".dwHostNameLength should be %d, but is %d\n", lstrlenA(TEST_URL_HOST), urlComponents.dwHostNameLength);
146 ok(!strncmp(urlComponents.lpszHostName,TEST_URL_HOST,strlen(TEST_URL_HOST)),"lpszHostName should be %s but is %s\n", TEST_URL_HOST, urlComponents.lpszHostName);
147 ok(urlComponents.nPort == INTERNET_DEFAULT_HTTP_PORT,"urlComponents->nPort should have been 80 instead of %d\n", urlComponents.nPort);
148 ok(urlComponents.nScheme == INTERNET_SCHEME_HTTP,"urlComponents->nScheme should have been INTERNET_SCHEME_HTTP instead of %d\n", urlComponents.nScheme);
149 ok(!urlComponents.lpszUserName, ".lpszUserName should have been set to NULL\n");
150 ok(!urlComponents.lpszPassword, ".lpszPassword should have been set to NULL\n");
151 ok(urlComponents.dwExtraInfoLength == strlen(TEST_URL_HASH),".dwExtraInfoLength should be %d, but is %d\n", lstrlenA(TEST_URL_HASH), urlComponents.dwExtraInfoLength);
152 ok(!strncmp(urlComponents.lpszExtraInfo,TEST_URL_HASH,strlen(TEST_URL_HASH)), ".lpszExtraInfo should be %s but is %s\n", TEST_URL_HASH, urlComponents.lpszExtraInfo);
153 ok(!urlComponents.dwUserNameLength,".dwUserNameLength should be 0, but is %d\n", urlComponents.dwUserNameLength);
154 ok(!urlComponents.dwPasswordLength,".dwPasswordLength should be 0, but is %d\n", urlComponents.dwPasswordLength);
156 /*3. Check for %20 */
157 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
158 ok(InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents),"InternetCrackUrl failed with GLE %d\n",GetLastError());
160 /* Tests for lpsz* members pointing to real strings while
161 * some corresponding length members are set to zero.
162 * As of IE7 (wininet 7.0*?) all members are checked. So we
163 * run the first test and expect the outcome to be the same
164 * for the first four (scheme, hostname, username and password).
165 * The last two (path and extrainfo) are the same for all versions
166 * of the wininet.dll.
168 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
169 SetLastError(0xdeadbeef);
170 firstret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
171 firstGLE = GetLastError();
173 copy_compsA(&urlSrc, &urlComponents, 32, 0, 1024, 1024, 2048, 1024);
174 SetLastError(0xdeadbeef);
175 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
176 GLE = GetLastError();
177 ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
178 ret, GetLastError(), firstret);
180 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 0, 1024, 2048, 1024);
181 SetLastError(0xdeadbeef);
182 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
183 GLE = GetLastError();
184 ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
185 ret, GetLastError(), firstret);
187 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 0, 2048, 1024);
188 SetLastError(0xdeadbeef);
189 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
190 GLE = GetLastError();
191 ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
192 ret, GetLastError(), firstret);
194 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 0, 1024);
195 SetLastError(0xdeadbeef);
196 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
197 GLE = GetLastError();
199 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
200 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
203 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 0);
204 SetLastError(0xdeadbeef);
205 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
206 GLE = GetLastError();
208 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
209 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
212 copy_compsA(&urlSrc, &urlComponents, 0, 0, 0, 0, 0, 0);
213 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
214 GLE = GetLastError();
216 ok(ret==0 && GLE==ERROR_INVALID_PARAMETER,
217 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
220 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
221 ret = InternetCrackUrl("about://host/blank", 0,0,&urlComponents);
222 ok(ret, "InternetCrackUrl failed with %d\n", GetLastError());
223 ok(!strcmp(urlComponents.lpszScheme, "about"), "lpszScheme was \"%s\" instead of \"about\"\n", urlComponents.lpszScheme);
224 ok(!strcmp(urlComponents.lpszHostName, "host"), "lpszHostName was \"%s\" instead of \"host\"\n", urlComponents.lpszHostName);
225 ok(!strcmp(urlComponents.lpszUrlPath, "/blank"), "lpszUrlPath was \"%s\" instead of \"/blank\"\n", urlComponents.lpszUrlPath);
227 /* try a NULL lpszUrl */
228 SetLastError(0xdeadbeef);
229 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
230 ret = InternetCrackUrl(NULL, 0, 0, &urlComponents);
231 GLE = GetLastError();
232 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
233 ok(GLE == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GLE);
235 /* try an empty lpszUrl, GetLastError returns 12006, whatever that means
236 * we just need to fail and not return success
238 SetLastError(0xdeadbeef);
239 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
240 ret = InternetCrackUrl("", 0, 0, &urlComponents);
241 GLE = GetLastError();
242 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
243 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
245 /* Invalid Call: must set size of components structure (Windows only
246 * enforces this on the InternetCrackUrlA version of the call) */
247 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
248 SetLastError(0xdeadbeef);
249 urlComponents.dwStructSize = 0;
250 ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
251 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
252 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
254 /* Invalid Call: size of dwStructSize must be one of the "standard" sizes
255 * of the URL_COMPONENTS structure (Windows only enforces this on the
256 * InternetCrackUrlA version of the call) */
257 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
258 SetLastError(0xdeadbeef);
259 urlComponents.dwStructSize = sizeof(urlComponents) + 1;
260 ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
261 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
262 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
265 static void InternetCrackUrlW_test(void)
268 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
269 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
270 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
272 static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
273 static const WCHAR url3[] = { 'h','t','t','p',':','/','/','x','.','o','r','g',0 };
274 URL_COMPONENTSW comp;
275 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
285 memset(&comp, 0, sizeof comp);
286 comp.dwStructSize = sizeof comp;
287 comp.lpszScheme = scheme;
288 comp.dwSchemeLength = sizeof scheme;
289 comp.lpszHostName = host;
290 comp.dwHostNameLength = sizeof host;
291 comp.lpszUserName = user;
292 comp.dwUserNameLength = sizeof user;
293 comp.lpszPassword = pwd;
294 comp.dwPasswordLength = sizeof pwd;
295 comp.lpszUrlPath = urlpart;
296 comp.dwUrlPathLength = sizeof urlpart;
297 comp.lpszExtraInfo = extra;
298 comp.dwExtraInfoLength = sizeof extra;
300 SetLastError(0xdeadbeef);
301 r = InternetCrackUrlW(NULL, 0, 0, &comp );
302 error = GetLastError();
303 if (!r && error == ERROR_CALL_NOT_IMPLEMENTED)
305 win_skip("InternetCrackUrlW is not implemented\n");
308 ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
309 ok( error == ERROR_INVALID_PARAMETER ||
310 broken(error == ERROR_INTERNET_UNRECOGNIZED_SCHEME), /* IE5 */
311 "expected ERROR_INVALID_PARAMETER got %u\n", error);
313 if (error == ERROR_INVALID_PARAMETER)
316 SetLastError(0xdeadbeef);
317 r = InternetCrackUrlW(url, 0, 0, NULL );
318 error = GetLastError();
319 ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
320 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
323 r = InternetCrackUrlW(url, 0, 0, &comp );
324 ok( r, "failed to crack url\n");
325 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
326 ok( comp.dwHostNameLength == 12, "host length wrong\n");
327 ok( comp.dwUserNameLength == 0, "user length wrong\n");
328 ok( comp.dwPasswordLength == 0, "password length wrong\n");
329 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
330 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
338 memset(&comp, 0, sizeof comp);
339 comp.dwStructSize = sizeof comp;
340 comp.lpszHostName = host;
341 comp.dwHostNameLength = sizeof host;
342 comp.lpszUrlPath = urlpart;
343 comp.dwUrlPathLength = sizeof urlpart;
345 r = InternetCrackUrlW(url, 0, 0, &comp );
346 ok( r, "failed to crack url\n");
347 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
348 ok( comp.dwHostNameLength == 12, "host length wrong\n");
349 ok( comp.dwUserNameLength == 0, "user length wrong\n");
350 ok( comp.dwPasswordLength == 0, "password length wrong\n");
351 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
352 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
360 memset(&comp, 0, sizeof comp);
361 comp.dwStructSize = sizeof comp;
362 comp.lpszHostName = host;
363 comp.dwHostNameLength = sizeof host;
364 comp.lpszUrlPath = urlpart;
365 comp.dwUrlPathLength = sizeof urlpart;
366 comp.lpszExtraInfo = NULL;
367 comp.dwExtraInfoLength = sizeof extra;
369 r = InternetCrackUrlW(url, 0, 0, &comp );
370 ok( r, "failed to crack url\n");
371 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
372 ok( comp.dwHostNameLength == 12, "host length wrong\n");
373 ok( comp.dwUserNameLength == 0, "user length wrong\n");
374 ok( comp.dwPasswordLength == 0, "password length wrong\n");
375 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
376 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
384 memset(&comp, 0, sizeof(comp));
385 comp.dwStructSize = sizeof(comp);
386 comp.lpszScheme = scheme;
387 comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
388 comp.lpszHostName = host;
389 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
390 comp.lpszUserName = user;
391 comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
392 comp.lpszPassword = pwd;
393 comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
394 comp.lpszUrlPath = urlpart;
395 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
396 comp.lpszExtraInfo = extra;
397 comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
399 r = InternetCrackUrlW(url2, 0, 0, &comp);
401 ok(!r, "InternetCrackUrl should have failed\n");
402 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
403 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
407 /* Test to see whether cracking a URL without a filename initializes urlpart */
414 memset(&comp, 0, sizeof comp);
415 comp.dwStructSize = sizeof comp;
416 comp.lpszScheme = scheme;
417 comp.dwSchemeLength = sizeof scheme;
418 comp.lpszHostName = host;
419 comp.dwHostNameLength = sizeof host;
420 comp.lpszUserName = user;
421 comp.dwUserNameLength = sizeof user;
422 comp.lpszPassword = pwd;
423 comp.dwPasswordLength = sizeof pwd;
424 comp.lpszUrlPath = urlpart;
425 comp.dwUrlPathLength = sizeof urlpart;
426 comp.lpszExtraInfo = extra;
427 comp.dwExtraInfoLength = sizeof extra;
428 r = InternetCrackUrlW(url3, 0, 0, &comp );
429 ok( r, "InternetCrackUrlW failed unexpectedly\n");
430 ok( host[0] == 'x', "host should be x.org\n");
431 ok( urlpart[0] == 0, "urlpart should be empty\n");
434 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents)
436 static CHAR http[] = "http",
437 winehq[] = "www.winehq.org",
438 username[] = "username",
439 password[] = "password",
440 site_about[] = "/site/about",
443 lpUrlComponents->dwStructSize = sizeof(URL_COMPONENTS);
444 lpUrlComponents->lpszScheme = http;
445 lpUrlComponents->dwSchemeLength = strlen(lpUrlComponents->lpszScheme);
446 lpUrlComponents->nScheme = INTERNET_SCHEME_HTTP;
447 lpUrlComponents->lpszHostName = winehq;
448 lpUrlComponents->dwHostNameLength = strlen(lpUrlComponents->lpszHostName);
449 lpUrlComponents->nPort = 80;
450 lpUrlComponents->lpszUserName = username;
451 lpUrlComponents->dwUserNameLength = strlen(lpUrlComponents->lpszUserName);
452 lpUrlComponents->lpszPassword = password;
453 lpUrlComponents->dwPasswordLength = strlen(lpUrlComponents->lpszPassword);
454 lpUrlComponents->lpszUrlPath = site_about;
455 lpUrlComponents->dwUrlPathLength = strlen(lpUrlComponents->lpszUrlPath);
456 lpUrlComponents->lpszExtraInfo = empty;
457 lpUrlComponents->dwExtraInfoLength = strlen(lpUrlComponents->lpszExtraInfo);
460 static void InternetCreateUrlA_test(void)
462 URL_COMPONENTS urlComp;
466 static CHAR empty[] = "",
470 winehq[] = "www.winehq.org",
471 localhost[] = "localhost",
472 username[] = "username",
473 password[] = "password",
475 site_about[] = "/site/about",
476 extra_info[] = "?test=123",
481 /* test NULL lpUrlComponents */
482 SetLastError(0xdeadbeef);
483 ret = InternetCreateUrlA(NULL, 0, NULL, &len);
484 ok(!ret, "Expected failure\n");
485 ok(GetLastError() == ERROR_INVALID_PARAMETER,
486 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
487 ok(len == -1, "Expected len -1, got %d\n", len);
489 /* test zero'ed lpUrlComponents */
490 ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
491 SetLastError(0xdeadbeef);
492 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
493 ok(!ret, "Expected failure\n");
494 ok(GetLastError() == ERROR_INVALID_PARAMETER,
495 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
496 ok(len == -1, "Expected len -1, got %d\n", len);
498 /* test valid lpUrlComponents, NULL lpdwUrlLength */
499 fill_url_components(&urlComp);
500 SetLastError(0xdeadbeef);
501 ret = InternetCreateUrlA(&urlComp, 0, NULL, NULL);
502 ok(!ret, "Expected failure\n");
503 ok(GetLastError() == ERROR_INVALID_PARAMETER,
504 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
505 ok(len == -1, "Expected len -1, got %d\n", len);
507 /* test valid lpUrlComponents, empty szUrl
508 * lpdwUrlLength is size of buffer required on exit, including
509 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
511 SetLastError(0xdeadbeef);
512 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
513 ok(!ret, "Expected failure\n");
514 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
515 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
516 ok(len == 51, "Expected len 51, got %d\n", len);
518 /* test correct size, NULL szUrl */
519 fill_url_components(&urlComp);
520 SetLastError(0xdeadbeef);
521 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
522 ok(!ret, "Expected failure\n");
523 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
524 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
525 ok(len == 51, "Expected len 51, got %d\n", len);
527 /* test valid lpUrlComponents, alloc-ed szUrl, small size */
528 SetLastError(0xdeadbeef);
529 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
531 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
532 ok(!ret, "Expected failure\n");
533 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
534 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
535 ok(len == 51, "Expected len 51, got %d\n", len);
537 /* alloc-ed szUrl, NULL lpszScheme
538 * shows that it uses nScheme instead
540 SetLastError(0xdeadbeef);
541 urlComp.lpszScheme = NULL;
542 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
543 ok(ret, "Expected success\n");
544 ok(GetLastError() == 0xdeadbeef,
545 "Expected 0xdeadbeef, got %d\n", GetLastError());
546 ok(len == 50, "Expected len 50, got %d\n", len);
547 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
549 /* alloc-ed szUrl, invalid nScheme
550 * any nScheme out of range seems ignored
552 fill_url_components(&urlComp);
553 SetLastError(0xdeadbeef);
554 urlComp.nScheme = -3;
556 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
557 ok(ret, "Expected success\n");
558 ok(GetLastError() == 0xdeadbeef,
559 "Expected 0xdeadbeef, got %d\n", GetLastError());
560 ok(len == 50, "Expected len 50, got %d\n", len);
562 /* test valid lpUrlComponents, alloc-ed szUrl */
563 fill_url_components(&urlComp);
564 SetLastError(0xdeadbeef);
566 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
567 ok(ret, "Expected success\n");
568 ok(GetLastError() == 0xdeadbeef,
569 "Expected 0xdeadbeef, got %d\n", GetLastError());
570 ok(len == 50, "Expected len 50, got %d\n", len);
571 ok(strstr(szUrl, "80") == NULL, "Didn't expect to find 80 in szUrl\n");
572 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
574 /* valid username, NULL password */
575 fill_url_components(&urlComp);
576 SetLastError(0xdeadbeef);
577 urlComp.lpszPassword = NULL;
579 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
580 ok(ret, "Expected success\n");
581 ok(GetLastError() == 0xdeadbeef,
582 "Expected 0xdeadbeef, got %d\n", GetLastError());
583 ok(len == 41, "Expected len 41, got %d\n", len);
584 ok(!strcmp(szUrl, CREATE_URL2), "Expected %s, got %s\n", CREATE_URL2, szUrl);
586 /* valid username, empty password */
587 fill_url_components(&urlComp);
588 SetLastError(0xdeadbeef);
589 urlComp.lpszPassword = empty;
591 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
592 ok(ret, "Expected success\n");
593 ok(GetLastError() == 0xdeadbeef,
594 "Expected 0xdeadbeef, got %d\n", GetLastError());
595 ok(len == 50, "Expected len 50, got %d\n", len);
596 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
598 /* valid password, NULL username
599 * if password is provided, username has to exist
601 fill_url_components(&urlComp);
602 SetLastError(0xdeadbeef);
603 urlComp.lpszUserName = NULL;
605 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
606 ok(!ret, "Expected failure\n");
607 ok(GetLastError() == ERROR_INVALID_PARAMETER,
608 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
609 ok(len == 42, "Expected len 42, got %d\n", len);
610 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
612 /* valid password, empty username
613 * if password is provided, username has to exist
615 fill_url_components(&urlComp);
616 SetLastError(0xdeadbeef);
617 urlComp.lpszUserName = empty;
619 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
620 ok(ret, "Expected success\n");
621 ok(GetLastError() == 0xdeadbeef,
622 "Expected 0xdeadbeef, got %d\n", GetLastError());
623 ok(len == 50, "Expected len 50, got %d\n", len);
624 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
626 /* NULL username, NULL password */
627 fill_url_components(&urlComp);
628 SetLastError(0xdeadbeef);
629 urlComp.lpszUserName = NULL;
630 urlComp.lpszPassword = NULL;
632 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
633 ok(ret, "Expected success\n");
634 ok(GetLastError() == 0xdeadbeef,
635 "Expected 0xdeadbeef, got %d\n", GetLastError());
636 ok(len == 32, "Expected len 32, got %d\n", len);
637 ok(!strcmp(szUrl, CREATE_URL4), "Expected %s, got %s\n", CREATE_URL4, szUrl);
639 /* empty username, empty password */
640 fill_url_components(&urlComp);
641 SetLastError(0xdeadbeef);
642 urlComp.lpszUserName = empty;
643 urlComp.lpszPassword = empty;
645 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
646 ok(ret, "Expected success\n");
647 ok(GetLastError() == 0xdeadbeef,
648 "Expected 0xdeadbeef, got %d\n", GetLastError());
649 ok(len == 50, "Expected len 50, got %d\n", len);
650 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
652 /* shows that nScheme is ignored, as the appearance of the port number
653 * depends on lpszScheme and the string copied depends on lpszScheme.
655 fill_url_components(&urlComp);
656 HeapFree(GetProcessHeap(), 0, szUrl);
657 urlComp.lpszScheme = nhttp;
658 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
659 len = strlen(CREATE_URL6) + 1;
660 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
661 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
662 ok(ret, "Expected success\n");
663 ok(len == strlen(CREATE_URL6), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6) + 1, len);
664 ok(!strcmp(szUrl, CREATE_URL6), "Expected %s, got %s\n", CREATE_URL6, szUrl);
666 /* if lpszScheme != "http" or nPort != 80, display nPort */
667 HeapFree(GetProcessHeap(), 0, szUrl);
668 urlComp.lpszScheme = http;
669 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
671 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
672 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
673 ok(ret, "Expected success\n");
674 ok(len == 53, "Expected len 53, got %d\n", len);
675 ok(strstr(szUrl, "42") != NULL, "Expected to find 42 in szUrl\n");
676 ok(!strcmp(szUrl, CREATE_URL7), "Expected %s, got %s\n", CREATE_URL7, szUrl);
678 HeapFree(GetProcessHeap(), 0, szUrl);
680 memset(&urlComp, 0, sizeof(urlComp));
681 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
682 urlComp.lpszScheme = http;
683 urlComp.dwSchemeLength = 0;
684 urlComp.nScheme = INTERNET_SCHEME_HTTP;
685 urlComp.lpszHostName = winehq;
686 urlComp.dwHostNameLength = 0;
688 urlComp.lpszUserName = username;
689 urlComp.dwUserNameLength = 0;
690 urlComp.lpszPassword = password;
691 urlComp.dwPasswordLength = 0;
692 urlComp.lpszUrlPath = site_about;
693 urlComp.dwUrlPathLength = 0;
694 urlComp.lpszExtraInfo = empty;
695 urlComp.dwExtraInfoLength = 0;
696 len = strlen(CREATE_URL1);
697 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
698 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
699 ok(ret, "Expected success\n");
700 ok(len == strlen(CREATE_URL1), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1), len);
701 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
703 HeapFree(GetProcessHeap(), 0, szUrl);
705 memset(&urlComp, 0, sizeof(urlComp));
706 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
707 urlComp.lpszScheme = https;
708 urlComp.dwSchemeLength = 0;
709 urlComp.nScheme = INTERNET_SCHEME_HTTP;
710 urlComp.lpszHostName = winehq;
711 urlComp.dwHostNameLength = 0;
713 urlComp.lpszUserName = username;
714 urlComp.dwUserNameLength = 0;
715 urlComp.lpszPassword = password;
716 urlComp.dwPasswordLength = 0;
717 urlComp.lpszUrlPath = site_about;
718 urlComp.dwUrlPathLength = 0;
719 urlComp.lpszExtraInfo = empty;
720 urlComp.dwExtraInfoLength = 0;
721 len = strlen(CREATE_URL8);
722 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
723 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
724 ok(ret, "Expected success\n");
725 ok(len == strlen(CREATE_URL8), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8), len);
726 ok(!strcmp(szUrl, CREATE_URL8), "Expected %s, got %s\n", CREATE_URL8, szUrl);
728 HeapFree(GetProcessHeap(), 0, szUrl);
730 memset(&urlComp, 0, sizeof(urlComp));
731 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
732 urlComp.lpszScheme = about;
733 urlComp.dwSchemeLength = 5;
734 urlComp.lpszUrlPath = blank;
735 urlComp.dwUrlPathLength = 5;
736 len = strlen(CREATE_URL9);
737 len++; /* work around bug in native wininet */
738 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
739 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
740 ok(ret, "Expected success\n");
741 ok(len == strlen(CREATE_URL9), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9), len);
742 ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
744 HeapFree(GetProcessHeap(), 0, szUrl);
746 memset(&urlComp, 0, sizeof(urlComp));
747 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
748 urlComp.lpszScheme = about;
749 urlComp.lpszHostName = host;
750 urlComp.lpszUrlPath = blank;
751 len = strlen(CREATE_URL10);
752 len++; /* work around bug in native wininet */
753 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
754 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
755 ok(ret, "Expected success\n");
756 ok(len == strlen(CREATE_URL10), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10), len);
757 ok(!strcmp(szUrl, CREATE_URL10), "Expected %s, got %s\n", CREATE_URL10, szUrl);
759 HeapFree(GetProcessHeap(), 0, szUrl);
761 memset(&urlComp, 0, sizeof(urlComp));
762 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
763 urlComp.nPort = 8080;
764 urlComp.lpszScheme = about;
765 len = strlen(CREATE_URL11);
766 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
767 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
768 ok(ret, "Expected success\n");
769 ok(len == strlen(CREATE_URL11), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11), len);
770 ok(!strcmp(szUrl, CREATE_URL11), "Expected %s, got %s\n", CREATE_URL11, szUrl);
772 HeapFree(GetProcessHeap(), 0, szUrl);
774 memset(&urlComp, 0, sizeof(urlComp));
775 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
776 urlComp.lpszScheme = http;
777 urlComp.dwSchemeLength = 0;
778 urlComp.nScheme = INTERNET_SCHEME_HTTP;
779 urlComp.lpszHostName = winehq;
780 urlComp.dwHostNameLength = 0;
781 urlComp.nPort = 65535;
782 len = strlen(CREATE_URL12);
783 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
784 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
785 ok(ret, "Expected success\n");
786 ok(len == strlen(CREATE_URL12), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12), len);
787 ok(!strcmp(szUrl, CREATE_URL12), "Expected %s, got %s\n", CREATE_URL12, szUrl);
789 HeapFree(GetProcessHeap(), 0, szUrl);
791 memset(&urlComp, 0, sizeof(urlComp));
792 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
793 urlComp.lpszScheme = http;
794 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
795 urlComp.lpszHostName = localhost;
796 urlComp.dwHostNameLength = strlen(urlComp.lpszHostName);
798 urlComp.lpszUrlPath = root;
799 urlComp.dwUrlPathLength = strlen(urlComp.lpszUrlPath);
800 urlComp.lpszExtraInfo = extra_info;
801 urlComp.dwExtraInfoLength = strlen(urlComp.lpszExtraInfo);
803 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
804 InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
805 ok(ret, "Expected success\n");
806 ok(len == strlen(CREATE_URL13), "Got len %u\n", len);
807 ok(!strcmp(szUrl, CREATE_URL13), "Expected \"%s\", got \"%s\"\n", CREATE_URL13, szUrl);
809 HeapFree(GetProcessHeap(), 0, szUrl);
814 InternetCrackUrl_test();
815 InternetCrackUrlW_test();
816 InternetCreateUrlA_test();