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"
34 #define TEST_URL_HOST "www.winehq.org"
35 #define TEST_URL_PATH "/site/about"
36 #define TEST_URL2 "http://www.myserver.com/myscript.php?arg=1"
37 #define TEST_URL2_SERVER "www.myserver.com"
38 #define TEST_URL2_PATH "/myscript.php"
39 #define TEST_URL2_PATHEXTRA "/myscript.php?arg=1"
40 #define TEST_URL2_EXTRA "?arg=1"
41 #define TEST_URL3 "file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml"
43 #define CREATE_URL1 "http://username:password@www.winehq.org/site/about"
44 #define CREATE_URL2 "http://username@www.winehq.org/site/about"
45 #define CREATE_URL3 "http://username:"
46 #define CREATE_URL4 "http://www.winehq.org/site/about"
47 #define CREATE_URL5 "http://"
48 #define CREATE_URL6 "nhttp://username:password@www.winehq.org:80/site/about"
49 #define CREATE_URL7 "http://username:password@www.winehq.org:42/site/about"
50 #define CREATE_URL8 "https://username:password@www.winehq.org/site/about"
51 #define CREATE_URL9 "about:blank"
52 #define CREATE_URL10 "about://host/blank"
53 #define CREATE_URL11 "about:"
54 #define CREATE_URL12 "http://www.winehq.org:65535"
56 static inline void copy_compsA(
67 dst->dwSchemeLength = scheLen;
68 dst->dwHostNameLength = hostLen;
69 dst->dwUserNameLength = userLen;
70 dst->dwPasswordLength = passLen;
71 dst->dwUrlPathLength = pathLen;
72 dst->dwExtraInfoLength = extrLen;
73 SetLastError(0xfaceabad);
76 static inline void zero_compsA(
85 ZeroMemory(dst, sizeof(URL_COMPONENTSA));
86 dst->dwStructSize = sizeof(URL_COMPONENTSA);
87 dst->dwSchemeLength = scheLen;
88 dst->dwHostNameLength = hostLen;
89 dst->dwUserNameLength = userLen;
90 dst->dwPasswordLength = passLen;
91 dst->dwUrlPathLength = pathLen;
92 dst->dwExtraInfoLength = extrLen;
93 SetLastError(0xfaceabad);
96 static void InternetCrackUrl_test(void)
98 URL_COMPONENTSA urlSrc, urlComponents;
99 char protocol[32], hostName[1024], userName[1024];
100 char password[1024], extra[1024], path[1024];
104 ZeroMemory(&urlSrc, sizeof(urlSrc));
105 urlSrc.dwStructSize = sizeof(urlSrc);
106 urlSrc.lpszScheme = protocol;
107 urlSrc.lpszHostName = hostName;
108 urlSrc.lpszUserName = userName;
109 urlSrc.lpszPassword = password;
110 urlSrc.lpszUrlPath = path;
111 urlSrc.lpszExtraInfo = extra;
113 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
114 ret = InternetCrackUrl(TEST_URL, 0,0,&urlComponents);
115 ok( ret, "InternetCrackUrl failed, error %lx\n",GetLastError());
116 ok((strcmp(TEST_URL_PATH,path) == 0),"path cracked wrong\n");
118 /* Bug 1805: Confirm the returned lengths are correct: */
119 /* 1. When extra info split out explicitly */
120 zero_compsA(&urlComponents, 0, 1, 0, 0, 1, 1);
121 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed, error 0x%lx\n", GetLastError());
122 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATH),".dwUrlPathLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_PATH), urlComponents.dwUrlPathLength);
123 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATH,strlen(TEST_URL2_PATH)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATH, urlComponents.lpszUrlPath);
124 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
125 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
126 ok(urlComponents.dwExtraInfoLength == strlen(TEST_URL2_EXTRA),".dwExtraInfoLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_EXTRA), urlComponents.dwExtraInfoLength);
127 ok(!strncmp(urlComponents.lpszExtraInfo,TEST_URL2_EXTRA,strlen(TEST_URL2_EXTRA)),"lpszExtraInfo should be %s but is %s\n", TEST_URL2_EXTRA, urlComponents.lpszHostName);
129 /* 2. When extra info is not split out explicitly and is in url path */
130 zero_compsA(&urlComponents, 0, 1, 0, 0, 1, 0);
131 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
132 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATHEXTRA),".dwUrlPathLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_PATHEXTRA), urlComponents.dwUrlPathLength);
133 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATHEXTRA,strlen(TEST_URL2_PATHEXTRA)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATHEXTRA, urlComponents.lpszUrlPath);
134 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
135 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
136 ok(urlComponents.nPort == INTERNET_DEFAULT_HTTP_PORT,"urlComponents->nPort should have been 80 instead of %d\n", urlComponents.nPort);
137 ok(urlComponents.nScheme == INTERNET_SCHEME_HTTP,"urlComponents->nScheme should have been INTERNET_SCHEME_HTTP instead of %d\n", urlComponents.nScheme);
139 zero_compsA(&urlComponents, 1, 1, 1, 1, 1, 1);
140 ok(InternetCrackUrlA(TEST_URL, strlen(TEST_URL), 0, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
141 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL_PATH),".dwUrlPathLength should be %d, but is %ld\n", lstrlenA(TEST_URL_PATH), urlComponents.dwUrlPathLength);
142 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL_PATH,strlen(TEST_URL_PATH)),"lpszUrlPath should be %s but is %s\n", TEST_URL_PATH, urlComponents.lpszUrlPath);
143 ok(urlComponents.dwHostNameLength == strlen(TEST_URL_HOST),".dwHostNameLength should be %d, but is %ld\n", lstrlenA(TEST_URL_HOST), urlComponents.dwHostNameLength);
144 ok(!strncmp(urlComponents.lpszHostName,TEST_URL_HOST,strlen(TEST_URL_HOST)),"lpszHostName should be %s but is %s\n", TEST_URL_HOST, urlComponents.lpszHostName);
145 ok(urlComponents.nPort == INTERNET_DEFAULT_HTTP_PORT,"urlComponents->nPort should have been 80 instead of %d\n", urlComponents.nPort);
146 ok(urlComponents.nScheme == INTERNET_SCHEME_HTTP,"urlComponents->nScheme should have been INTERNET_SCHEME_HTTP instead of %d\n", urlComponents.nScheme);
147 ok(!urlComponents.lpszUserName, ".lpszUserName should have been set to NULL\n");
148 ok(!urlComponents.lpszPassword, ".lpszPassword should have been set to NULL\n");
149 ok(!urlComponents.lpszExtraInfo, ".lpszExtraInfo should have been set to NULL\n");
150 ok(!urlComponents.dwUserNameLength,".dwUserNameLength should be 0, but is %ld\n", urlComponents.dwUserNameLength);
151 ok(!urlComponents.dwPasswordLength,".dwPasswordLength should be 0, but is %ld\n", urlComponents.dwPasswordLength);
152 ok(!urlComponents.dwExtraInfoLength,".dwExtraInfoLength should be 0, but is %ld\n", urlComponents.dwExtraInfoLength);
154 /*3. Check for %20 */
155 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
156 ok(InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
159 /* Tests for lpsz* members pointing to real strings while
160 * some corresponding length members are set to zero */
161 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
162 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
163 ok(ret==1, "InternetCrackUrl returned %d with GLE=%ld (expected to return 1)\n",
164 ret, GetLastError());
166 copy_compsA(&urlSrc, &urlComponents, 32, 0, 1024, 1024, 2048, 1024);
167 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
168 ok(ret==1, "InternetCrackUrl returned %d with GLE=%ld (expected to return 1)\n",
169 ret, GetLastError());
171 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 0, 1024, 2048, 1024);
172 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
173 ok(ret==1, "InternetCrackUrl returned %d with GLE=%ld (expected to return 1)\n",
174 ret, GetLastError());
176 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 0, 2048, 1024);
177 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
178 ok(ret==1, "InternetCrackUrl returned %d with GLE=%ld (expected to return 1)\n",
179 ret, GetLastError());
181 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 0, 1024);
182 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
183 GLE = GetLastError();
185 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
186 "InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
189 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 0);
190 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
191 GLE = GetLastError();
193 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
194 "InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
197 copy_compsA(&urlSrc, &urlComponents, 0, 0, 0, 0, 0, 0);
198 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
199 GLE = GetLastError();
201 ok(ret==0 && GLE==ERROR_INVALID_PARAMETER,
202 "InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
205 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
206 ret = InternetCrackUrl("about://host/blank", 0,0,&urlComponents);
207 ok(ret, "InternetCrackUrl failed with %ld\n", GetLastError());
208 ok(!strcmp(urlComponents.lpszScheme, "about"), "lpszScheme was \"%s\" instead of \"about\"\n", urlComponents.lpszScheme);
209 ok(!strcmp(urlComponents.lpszHostName, "host"), "lpszHostName was \"%s\" instead of \"host\"\n", urlComponents.lpszHostName);
210 ok(!strcmp(urlComponents.lpszUrlPath, "/blank"), "lpszUrlPath was \"%s\" instead of \"/blank\"\n", urlComponents.lpszUrlPath);
213 static void InternetCrackUrlW_test(void)
216 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
217 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
218 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
220 static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
221 URL_COMPONENTSW comp;
222 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
231 memset(&comp, 0, sizeof comp);
232 comp.dwStructSize = sizeof comp;
233 comp.lpszScheme = scheme;
234 comp.dwSchemeLength = sizeof scheme;
235 comp.lpszHostName = host;
236 comp.dwHostNameLength = sizeof host;
237 comp.lpszUserName = user;
238 comp.dwUserNameLength = sizeof user;
239 comp.lpszPassword = pwd;
240 comp.dwPasswordLength = sizeof pwd;
241 comp.lpszUrlPath = urlpart;
242 comp.dwUrlPathLength = sizeof urlpart;
243 comp.lpszExtraInfo = extra;
244 comp.dwExtraInfoLength = sizeof extra;
246 r = InternetCrackUrlW(url, 0, 0, &comp );
247 ok( r, "failed to crack url\n");
248 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
249 ok( comp.dwHostNameLength == 12, "host length wrong\n");
250 ok( comp.dwUserNameLength == 0, "user length wrong\n");
251 ok( comp.dwPasswordLength == 0, "password length wrong\n");
252 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
253 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
261 memset(&comp, 0, sizeof comp);
262 comp.dwStructSize = sizeof comp;
263 comp.lpszHostName = host;
264 comp.dwHostNameLength = sizeof host;
265 comp.lpszUrlPath = urlpart;
266 comp.dwUrlPathLength = sizeof urlpart;
268 r = InternetCrackUrlW(url, 0, 0, &comp );
269 ok( r, "failed to crack url\n");
270 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
271 ok( comp.dwHostNameLength == 12, "host length wrong\n");
272 ok( comp.dwUserNameLength == 0, "user length wrong\n");
273 ok( comp.dwPasswordLength == 0, "password length wrong\n");
274 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
275 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
283 memset(&comp, 0, sizeof comp);
284 comp.dwStructSize = sizeof comp;
285 comp.lpszHostName = host;
286 comp.dwHostNameLength = sizeof host;
287 comp.lpszUrlPath = urlpart;
288 comp.dwUrlPathLength = sizeof urlpart;
289 comp.lpszExtraInfo = NULL;
290 comp.dwExtraInfoLength = sizeof extra;
292 r = InternetCrackUrlW(url, 0, 0, &comp );
293 ok( r, "failed to crack url\n");
294 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
295 ok( comp.dwHostNameLength == 12, "host length wrong\n");
296 ok( comp.dwUserNameLength == 0, "user length wrong\n");
297 ok( comp.dwPasswordLength == 0, "password length wrong\n");
298 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
299 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
307 memset(&comp, 0, sizeof(comp));
308 comp.dwStructSize = sizeof(comp);
309 comp.lpszScheme = scheme;
310 comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
311 comp.lpszHostName = host;
312 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
313 comp.lpszUserName = user;
314 comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
315 comp.lpszPassword = pwd;
316 comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
317 comp.lpszUrlPath = urlpart;
318 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
319 comp.lpszExtraInfo = extra;
320 comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
322 r = InternetCrackUrlW(url2, 0, 0, &comp);
324 ok(!r, "InternetCrackUrl should have failed\n");
325 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
326 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %ld\n",
331 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents)
333 static CHAR http[] = "http",
334 winehq[] = "www.winehq.org",
335 username[] = "username",
336 password[] = "password",
337 site_about[] = "/site/about",
340 lpUrlComponents->dwStructSize = sizeof(URL_COMPONENTS);
341 lpUrlComponents->lpszScheme = http;
342 lpUrlComponents->dwSchemeLength = strlen(lpUrlComponents->lpszScheme);
343 lpUrlComponents->nScheme = INTERNET_SCHEME_HTTP;
344 lpUrlComponents->lpszHostName = winehq;
345 lpUrlComponents->dwHostNameLength = strlen(lpUrlComponents->lpszHostName);
346 lpUrlComponents->nPort = 80;
347 lpUrlComponents->lpszUserName = username;
348 lpUrlComponents->dwUserNameLength = strlen(lpUrlComponents->lpszUserName);
349 lpUrlComponents->lpszPassword = password;
350 lpUrlComponents->dwPasswordLength = strlen(lpUrlComponents->lpszPassword);
351 lpUrlComponents->lpszUrlPath = site_about;
352 lpUrlComponents->dwUrlPathLength = strlen(lpUrlComponents->lpszUrlPath);
353 lpUrlComponents->lpszExtraInfo = empty;
354 lpUrlComponents->dwExtraInfoLength = strlen(lpUrlComponents->lpszExtraInfo);
357 static void InternetCreateUrlA_test(void)
359 URL_COMPONENTS urlComp;
363 static CHAR empty[] = "",
367 winehq[] = "www.winehq.org",
368 username[] = "username",
369 password[] = "password",
370 site_about[] = "/site/about",
375 /* test NULL lpUrlComponents */
376 ret = InternetCreateUrlA(NULL, 0, NULL, &len);
377 SetLastError(0xdeadbeef);
378 ok(!ret, "Expected failure\n");
379 ok(GetLastError() == 0xdeadbeef,
380 "Expected 0xdeadbeef, got %ld\n", GetLastError());
381 ok(len == -1, "Expected len -1, got %ld\n", len);
383 /* test zero'ed lpUrlComponents */
384 ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
385 SetLastError(0xdeadbeef);
386 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
387 ok(!ret, "Expected failure\n");
388 ok(GetLastError() == ERROR_INVALID_PARAMETER,
389 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
390 ok(len == -1, "Expected len -1, got %ld\n", len);
392 /* test valid lpUrlComponets, NULL lpdwUrlLength */
393 fill_url_components(&urlComp);
394 SetLastError(0xdeadbeef);
395 ret = InternetCreateUrlA(&urlComp, 0, NULL, NULL);
396 ok(!ret, "Expected failure\n");
397 ok(GetLastError() == ERROR_INVALID_PARAMETER,
398 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
399 ok(len == -1, "Expected len -1, got %ld\n", len);
401 /* test valid lpUrlComponets, emptry szUrl
402 * lpdwUrlLength is size of buffer required on exit, including
403 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
405 SetLastError(0xdeadbeef);
406 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
407 ok(!ret, "Expected failure\n");
408 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
409 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
410 ok(len == 51, "Expected len 51, got %ld\n", len);
412 /* test correct size, NULL szUrl */
413 fill_url_components(&urlComp);
414 SetLastError(0xdeadbeef);
415 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
416 ok(!ret, "Expected failure\n");
417 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
418 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
419 ok(len == 51, "Expected len 51, got %ld\n", len);
421 /* test valid lpUrlComponets, alloced szUrl, small size */
422 SetLastError(0xdeadbeef);
423 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
425 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
426 ok(!ret, "Expected failure\n");
427 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
428 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
429 ok(len == 51, "Expected len 51, got %ld\n", len);
431 /* alloced szUrl, NULL lpszScheme
432 * shows that it uses nScheme instead
434 SetLastError(0xdeadbeef);
435 urlComp.lpszScheme = NULL;
436 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
437 ok(ret, "Expected success\n");
438 ok(GetLastError() == 0xdeadbeef,
439 "Expected 0xdeadbeef, got %ld\n", GetLastError());
440 ok(len == 50, "Expected len 50, got %ld\n", len);
441 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
443 /* alloced szUrl, invalid nScheme
444 * any nScheme out of range seems ignored
446 fill_url_components(&urlComp);
447 SetLastError(0xdeadbeef);
448 urlComp.nScheme = -3;
450 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
451 ok(ret, "Expected success\n");
452 ok(GetLastError() == 0xdeadbeef,
453 "Expected 0xdeadbeef, got %ld\n", GetLastError());
454 ok(len == 50, "Expected len 50, got %ld\n", len);
456 /* test valid lpUrlComponets, alloced szUrl */
457 fill_url_components(&urlComp);
458 SetLastError(0xdeadbeef);
460 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
461 ok(ret, "Expected success\n");
462 ok(GetLastError() == 0xdeadbeef,
463 "Expected 0xdeadbeef, got %ld\n", GetLastError());
464 ok(len == 50, "Expected len 50, got %ld\n", len);
465 ok(strstr(szUrl, "80") == NULL, "Didn't expect to find 80 in szUrl\n");
466 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
468 /* valid username, NULL password */
469 fill_url_components(&urlComp);
470 SetLastError(0xdeadbeef);
471 urlComp.lpszPassword = NULL;
473 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
474 ok(ret, "Expected success\n");
475 ok(GetLastError() == 0xdeadbeef,
476 "Expected 0xdeadbeef, got %ld\n", GetLastError());
477 ok(len == 41, "Expected len 41, got %ld\n", len);
478 ok(!strcmp(szUrl, CREATE_URL2), "Expected %s, got %s\n", CREATE_URL2, szUrl);
480 /* valid username, empty password */
481 fill_url_components(&urlComp);
482 SetLastError(0xdeadbeef);
483 urlComp.lpszPassword = empty;
485 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
486 ok(ret, "Expected success\n");
487 ok(GetLastError() == 0xdeadbeef,
488 "Expected 0xdeadbeef, got %ld\n", GetLastError());
489 ok(len == 50, "Expected len 50, got %ld\n", len);
490 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
492 /* valid password, NULL username
493 * if password is provided, username has to exist
495 fill_url_components(&urlComp);
496 SetLastError(0xdeadbeef);
497 urlComp.lpszUserName = NULL;
499 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
500 ok(!ret, "Expected failure\n");
501 ok(GetLastError() == ERROR_INVALID_PARAMETER,
502 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
503 ok(len == 42, "Expected len 42, got %ld\n", len);
504 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
506 /* valid password, empty username
507 * if password is provided, username has to exist
509 fill_url_components(&urlComp);
510 SetLastError(0xdeadbeef);
511 urlComp.lpszUserName = empty;
513 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
514 ok(ret, "Expected success\n");
515 ok(GetLastError() == 0xdeadbeef,
516 "Expected 0xdeadbeef, got %ld\n", GetLastError());
517 ok(len == 50, "Expected len 50, got %ld\n", len);
518 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
520 /* NULL username, NULL password */
521 fill_url_components(&urlComp);
522 SetLastError(0xdeadbeef);
523 urlComp.lpszUserName = NULL;
524 urlComp.lpszPassword = NULL;
526 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
527 ok(ret, "Expected success\n");
528 ok(GetLastError() == 0xdeadbeef,
529 "Expected 0xdeadbeef, got %ld\n", GetLastError());
530 ok(len == 32, "Expected len 32, got %ld\n", len);
531 ok(!strcmp(szUrl, CREATE_URL4), "Expected %s, got %s\n", CREATE_URL4, szUrl);
533 /* empty username, empty password */
534 fill_url_components(&urlComp);
535 SetLastError(0xdeadbeef);
536 urlComp.lpszUserName = empty;
537 urlComp.lpszPassword = empty;
539 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
540 ok(ret, "Expected success\n");
541 ok(GetLastError() == 0xdeadbeef,
542 "Expected 0xdeadbeef, got %ld\n", GetLastError());
543 ok(len == 50, "Expected len 50, got %ld\n", len);
544 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
546 /* shows that nScheme is ignored, as the appearance of the port number
547 * depends on lpszScheme and the string copied depends on lpszScheme.
549 fill_url_components(&urlComp);
550 HeapFree(GetProcessHeap(), 0, szUrl);
551 urlComp.lpszScheme = nhttp;
552 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
553 len = strlen(CREATE_URL6) + 1;
554 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, len);
555 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
556 ok(ret, "Expected success\n");
557 ok(len == strlen(CREATE_URL6), "Expected len %d, got %ld\n", lstrlenA(CREATE_URL6) + 1, len);
558 ok(!strcmp(szUrl, CREATE_URL6), "Expected %s, got %s\n", CREATE_URL6, szUrl);
560 /* if lpszScheme != "http" or nPort != 80, display nPort */
561 HeapFree(GetProcessHeap(), 0, szUrl);
562 urlComp.lpszScheme = http;
563 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
565 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
566 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
567 ok(ret, "Expected success\n");
568 ok(len == 53, "Expected len 53, got %ld\n", len);
569 ok(strstr(szUrl, "42") != NULL, "Expected to find 42 in szUrl\n");
570 ok(!strcmp(szUrl, CREATE_URL7), "Expected %s, got %s\n", CREATE_URL7, szUrl);
572 HeapFree(GetProcessHeap(), 0, szUrl);
574 memset(&urlComp, 0, sizeof(urlComp));
575 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
576 urlComp.lpszScheme = http;
577 urlComp.dwSchemeLength = 0;
578 urlComp.nScheme = INTERNET_SCHEME_HTTP;
579 urlComp.lpszHostName = winehq;
580 urlComp.dwHostNameLength = 0;
582 urlComp.lpszUserName = username;
583 urlComp.dwUserNameLength = 0;
584 urlComp.lpszPassword = password;
585 urlComp.dwPasswordLength = 0;
586 urlComp.lpszUrlPath = site_about;
587 urlComp.dwUrlPathLength = 0;
588 urlComp.lpszExtraInfo = empty;
589 urlComp.dwExtraInfoLength = 0;
590 len = strlen(CREATE_URL1);
591 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
592 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
593 ok(ret, "Expected success\n");
594 ok(len == strlen(CREATE_URL1), "Expected len %d, got %ld\n", lstrlenA(CREATE_URL1), len);
595 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
597 memset(&urlComp, 0, sizeof(urlComp));
598 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
599 urlComp.lpszScheme = https;
600 urlComp.dwSchemeLength = 0;
601 urlComp.nScheme = INTERNET_SCHEME_HTTP;
602 urlComp.lpszHostName = winehq;
603 urlComp.dwHostNameLength = 0;
605 urlComp.lpszUserName = username;
606 urlComp.dwUserNameLength = 0;
607 urlComp.lpszPassword = password;
608 urlComp.dwPasswordLength = 0;
609 urlComp.lpszUrlPath = site_about;
610 urlComp.dwUrlPathLength = 0;
611 urlComp.lpszExtraInfo = empty;
612 urlComp.dwExtraInfoLength = 0;
613 len = strlen(CREATE_URL8);
614 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
615 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
616 ok(ret, "Expected success\n");
617 ok(len == strlen(CREATE_URL8), "Expected len %d, got %ld\n", lstrlenA(CREATE_URL8), len);
618 ok(!strcmp(szUrl, CREATE_URL8), "Expected %s, got %s\n", CREATE_URL8, szUrl);
620 HeapFree(GetProcessHeap(), 0, szUrl);
622 memset(&urlComp, 0, sizeof(urlComp));
623 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
624 urlComp.lpszScheme = about;
625 urlComp.dwSchemeLength = 5;
626 urlComp.lpszUrlPath = blank;
627 urlComp.dwUrlPathLength = 5;
628 len = strlen(CREATE_URL9);
629 len++; /* work around bug in native wininet */
630 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
631 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
632 ok(ret, "Expected success\n");
633 ok(len == strlen(CREATE_URL9), "Expected len %d, got %ld\n", lstrlenA(CREATE_URL9), len);
634 ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
636 HeapFree(GetProcessHeap(), 0, szUrl);
638 memset(&urlComp, 0, sizeof(urlComp));
639 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
640 urlComp.lpszScheme = about;
641 urlComp.lpszHostName = host;
642 urlComp.lpszUrlPath = blank;
643 len = strlen(CREATE_URL10);
644 len++; /* work around bug in native wininet */
645 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
646 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
647 ok(ret, "Expected success\n");
648 ok(len == strlen(CREATE_URL10), "Expected len %d, got %ld\n", lstrlenA(CREATE_URL10), len);
649 ok(!strcmp(szUrl, CREATE_URL10), "Expected %s, got %s\n", CREATE_URL10, szUrl);
651 HeapFree(GetProcessHeap(), 0, szUrl);
653 memset(&urlComp, 0, sizeof(urlComp));
654 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
655 urlComp.nPort = 8080;
656 urlComp.lpszScheme = about;
657 len = strlen(CREATE_URL11);
658 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
659 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
660 ok(ret, "Expected success\n");
661 ok(len == strlen(CREATE_URL11), "Expected len %d, got %ld\n", lstrlenA(CREATE_URL11), len);
662 ok(!strcmp(szUrl, CREATE_URL11), "Expected %s, got %s\n", CREATE_URL11, szUrl);
664 HeapFree(GetProcessHeap(), 0, szUrl);
666 memset(&urlComp, 0, sizeof(urlComp));
667 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
668 urlComp.lpszScheme = http;
669 urlComp.dwSchemeLength = 0;
670 urlComp.nScheme = INTERNET_SCHEME_HTTP;
671 urlComp.lpszHostName = winehq;
672 urlComp.dwHostNameLength = 0;
673 urlComp.nPort = 65535;
674 len = strlen(CREATE_URL12);
675 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
676 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
677 ok(ret, "Expected success\n");
678 ok(len == strlen(CREATE_URL12), "Expected len %d, got %ld\n", lstrlenA(CREATE_URL12), len);
679 ok(!strcmp(szUrl, CREATE_URL12), "Expected %s, got %s\n", CREATE_URL12, szUrl);
681 HeapFree(GetProcessHeap(), 0, szUrl);
686 InternetCrackUrl_test();
687 InternetCrackUrlW_test();
688 InternetCreateUrlA_test();