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 %d\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 %d\n", GetLastError());
122 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATH),".dwUrlPathLength should be %d, but is %d\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 %d, but is %d\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 %d, but is %d\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 %d\n",GetLastError());
132 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATHEXTRA),".dwUrlPathLength should be %d, but is %d\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 %d, but is %d\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 %d\n",GetLastError());
141 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL_PATH),".dwUrlPathLength should be %d, but is %d\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 %d\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 %d\n", urlComponents.dwUserNameLength);
151 ok(!urlComponents.dwPasswordLength,".dwPasswordLength should be 0, but is %d\n", urlComponents.dwPasswordLength);
152 ok(!urlComponents.dwExtraInfoLength,".dwExtraInfoLength should be 0, but is %d\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 %d\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=%d (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=%d (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=%d (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=%d (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=%d (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=%d (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=%d (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 %d\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);
212 /* try a NULL lpszUrl */
213 SetLastError(0xdeadbeef);
214 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
215 ret = InternetCrackUrl(NULL, 0, 0, &urlComponents);
216 GLE = GetLastError();
217 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
218 ok(GLE == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GLE);
220 /* try an empty lpszUrl, GetLastError returns 12006, whatever that means
221 * we just need to fail and not return success
223 SetLastError(0xdeadbeef);
224 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
225 ret = InternetCrackUrl("", 0, 0, &urlComponents);
226 GLE = GetLastError();
227 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
228 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
231 static void InternetCrackUrlW_test(void)
234 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
235 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
236 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
238 static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
239 URL_COMPONENTSW comp;
240 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
249 memset(&comp, 0, sizeof comp);
250 comp.dwStructSize = sizeof comp;
251 comp.lpszScheme = scheme;
252 comp.dwSchemeLength = sizeof scheme;
253 comp.lpszHostName = host;
254 comp.dwHostNameLength = sizeof host;
255 comp.lpszUserName = user;
256 comp.dwUserNameLength = sizeof user;
257 comp.lpszPassword = pwd;
258 comp.dwPasswordLength = sizeof pwd;
259 comp.lpszUrlPath = urlpart;
260 comp.dwUrlPathLength = sizeof urlpart;
261 comp.lpszExtraInfo = extra;
262 comp.dwExtraInfoLength = sizeof extra;
264 r = InternetCrackUrlW(url, 0, 0, &comp );
265 ok( r, "failed to crack url\n");
266 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
267 ok( comp.dwHostNameLength == 12, "host length wrong\n");
268 ok( comp.dwUserNameLength == 0, "user length wrong\n");
269 ok( comp.dwPasswordLength == 0, "password length wrong\n");
270 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
271 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
279 memset(&comp, 0, sizeof comp);
280 comp.dwStructSize = sizeof comp;
281 comp.lpszHostName = host;
282 comp.dwHostNameLength = sizeof host;
283 comp.lpszUrlPath = urlpart;
284 comp.dwUrlPathLength = sizeof urlpart;
286 r = InternetCrackUrlW(url, 0, 0, &comp );
287 ok( r, "failed to crack url\n");
288 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
289 ok( comp.dwHostNameLength == 12, "host length wrong\n");
290 ok( comp.dwUserNameLength == 0, "user length wrong\n");
291 ok( comp.dwPasswordLength == 0, "password length wrong\n");
292 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
293 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
301 memset(&comp, 0, sizeof comp);
302 comp.dwStructSize = sizeof comp;
303 comp.lpszHostName = host;
304 comp.dwHostNameLength = sizeof host;
305 comp.lpszUrlPath = urlpart;
306 comp.dwUrlPathLength = sizeof urlpart;
307 comp.lpszExtraInfo = NULL;
308 comp.dwExtraInfoLength = sizeof extra;
310 r = InternetCrackUrlW(url, 0, 0, &comp );
311 ok( r, "failed to crack url\n");
312 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
313 ok( comp.dwHostNameLength == 12, "host length wrong\n");
314 ok( comp.dwUserNameLength == 0, "user length wrong\n");
315 ok( comp.dwPasswordLength == 0, "password length wrong\n");
316 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
317 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
325 memset(&comp, 0, sizeof(comp));
326 comp.dwStructSize = sizeof(comp);
327 comp.lpszScheme = scheme;
328 comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
329 comp.lpszHostName = host;
330 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
331 comp.lpszUserName = user;
332 comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
333 comp.lpszPassword = pwd;
334 comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
335 comp.lpszUrlPath = urlpart;
336 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
337 comp.lpszExtraInfo = extra;
338 comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
340 r = InternetCrackUrlW(url2, 0, 0, &comp);
342 ok(!r, "InternetCrackUrl should have failed\n");
343 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
344 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
349 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents)
351 static CHAR http[] = "http",
352 winehq[] = "www.winehq.org",
353 username[] = "username",
354 password[] = "password",
355 site_about[] = "/site/about",
358 lpUrlComponents->dwStructSize = sizeof(URL_COMPONENTS);
359 lpUrlComponents->lpszScheme = http;
360 lpUrlComponents->dwSchemeLength = strlen(lpUrlComponents->lpszScheme);
361 lpUrlComponents->nScheme = INTERNET_SCHEME_HTTP;
362 lpUrlComponents->lpszHostName = winehq;
363 lpUrlComponents->dwHostNameLength = strlen(lpUrlComponents->lpszHostName);
364 lpUrlComponents->nPort = 80;
365 lpUrlComponents->lpszUserName = username;
366 lpUrlComponents->dwUserNameLength = strlen(lpUrlComponents->lpszUserName);
367 lpUrlComponents->lpszPassword = password;
368 lpUrlComponents->dwPasswordLength = strlen(lpUrlComponents->lpszPassword);
369 lpUrlComponents->lpszUrlPath = site_about;
370 lpUrlComponents->dwUrlPathLength = strlen(lpUrlComponents->lpszUrlPath);
371 lpUrlComponents->lpszExtraInfo = empty;
372 lpUrlComponents->dwExtraInfoLength = strlen(lpUrlComponents->lpszExtraInfo);
375 static void InternetCreateUrlA_test(void)
377 URL_COMPONENTS urlComp;
381 static CHAR empty[] = "",
385 winehq[] = "www.winehq.org",
386 username[] = "username",
387 password[] = "password",
388 site_about[] = "/site/about",
393 /* test NULL lpUrlComponents */
394 ret = InternetCreateUrlA(NULL, 0, NULL, &len);
395 SetLastError(0xdeadbeef);
396 ok(!ret, "Expected failure\n");
397 ok(GetLastError() == 0xdeadbeef,
398 "Expected 0xdeadbeef, got %d\n", GetLastError());
399 ok(len == -1, "Expected len -1, got %d\n", len);
401 /* test zero'ed lpUrlComponents */
402 ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
403 SetLastError(0xdeadbeef);
404 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
405 ok(!ret, "Expected failure\n");
406 ok(GetLastError() == ERROR_INVALID_PARAMETER,
407 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
408 ok(len == -1, "Expected len -1, got %d\n", len);
410 /* test valid lpUrlComponets, NULL lpdwUrlLength */
411 fill_url_components(&urlComp);
412 SetLastError(0xdeadbeef);
413 ret = InternetCreateUrlA(&urlComp, 0, NULL, NULL);
414 ok(!ret, "Expected failure\n");
415 ok(GetLastError() == ERROR_INVALID_PARAMETER,
416 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
417 ok(len == -1, "Expected len -1, got %d\n", len);
419 /* test valid lpUrlComponets, emptry szUrl
420 * lpdwUrlLength is size of buffer required on exit, including
421 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
423 SetLastError(0xdeadbeef);
424 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
425 ok(!ret, "Expected failure\n");
426 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
427 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
428 ok(len == 51, "Expected len 51, got %d\n", len);
430 /* test correct size, NULL szUrl */
431 fill_url_components(&urlComp);
432 SetLastError(0xdeadbeef);
433 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
434 ok(!ret, "Expected failure\n");
435 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
436 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
437 ok(len == 51, "Expected len 51, got %d\n", len);
439 /* test valid lpUrlComponets, alloced szUrl, small size */
440 SetLastError(0xdeadbeef);
441 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
443 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
444 ok(!ret, "Expected failure\n");
445 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
446 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
447 ok(len == 51, "Expected len 51, got %d\n", len);
449 /* alloced szUrl, NULL lpszScheme
450 * shows that it uses nScheme instead
452 SetLastError(0xdeadbeef);
453 urlComp.lpszScheme = NULL;
454 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
455 ok(ret, "Expected success\n");
456 ok(GetLastError() == 0xdeadbeef,
457 "Expected 0xdeadbeef, got %d\n", GetLastError());
458 ok(len == 50, "Expected len 50, got %d\n", len);
459 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
461 /* alloced szUrl, invalid nScheme
462 * any nScheme out of range seems ignored
464 fill_url_components(&urlComp);
465 SetLastError(0xdeadbeef);
466 urlComp.nScheme = -3;
468 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
469 ok(ret, "Expected success\n");
470 ok(GetLastError() == 0xdeadbeef,
471 "Expected 0xdeadbeef, got %d\n", GetLastError());
472 ok(len == 50, "Expected len 50, got %d\n", len);
474 /* test valid lpUrlComponets, alloced szUrl */
475 fill_url_components(&urlComp);
476 SetLastError(0xdeadbeef);
478 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
479 ok(ret, "Expected success\n");
480 ok(GetLastError() == 0xdeadbeef,
481 "Expected 0xdeadbeef, got %d\n", GetLastError());
482 ok(len == 50, "Expected len 50, got %d\n", len);
483 ok(strstr(szUrl, "80") == NULL, "Didn't expect to find 80 in szUrl\n");
484 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
486 /* valid username, NULL password */
487 fill_url_components(&urlComp);
488 SetLastError(0xdeadbeef);
489 urlComp.lpszPassword = NULL;
491 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
492 ok(ret, "Expected success\n");
493 ok(GetLastError() == 0xdeadbeef,
494 "Expected 0xdeadbeef, got %d\n", GetLastError());
495 ok(len == 41, "Expected len 41, got %d\n", len);
496 ok(!strcmp(szUrl, CREATE_URL2), "Expected %s, got %s\n", CREATE_URL2, szUrl);
498 /* valid username, empty password */
499 fill_url_components(&urlComp);
500 SetLastError(0xdeadbeef);
501 urlComp.lpszPassword = empty;
503 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
504 ok(ret, "Expected success\n");
505 ok(GetLastError() == 0xdeadbeef,
506 "Expected 0xdeadbeef, got %d\n", GetLastError());
507 ok(len == 50, "Expected len 50, got %d\n", len);
508 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
510 /* valid password, NULL username
511 * if password is provided, username has to exist
513 fill_url_components(&urlComp);
514 SetLastError(0xdeadbeef);
515 urlComp.lpszUserName = NULL;
517 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
518 ok(!ret, "Expected failure\n");
519 ok(GetLastError() == ERROR_INVALID_PARAMETER,
520 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
521 ok(len == 42, "Expected len 42, got %d\n", len);
522 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
524 /* valid password, empty username
525 * if password is provided, username has to exist
527 fill_url_components(&urlComp);
528 SetLastError(0xdeadbeef);
529 urlComp.lpszUserName = empty;
531 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
532 ok(ret, "Expected success\n");
533 ok(GetLastError() == 0xdeadbeef,
534 "Expected 0xdeadbeef, got %d\n", GetLastError());
535 ok(len == 50, "Expected len 50, got %d\n", len);
536 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
538 /* NULL username, NULL password */
539 fill_url_components(&urlComp);
540 SetLastError(0xdeadbeef);
541 urlComp.lpszUserName = NULL;
542 urlComp.lpszPassword = NULL;
544 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
545 ok(ret, "Expected success\n");
546 ok(GetLastError() == 0xdeadbeef,
547 "Expected 0xdeadbeef, got %d\n", GetLastError());
548 ok(len == 32, "Expected len 32, got %d\n", len);
549 ok(!strcmp(szUrl, CREATE_URL4), "Expected %s, got %s\n", CREATE_URL4, szUrl);
551 /* empty username, empty password */
552 fill_url_components(&urlComp);
553 SetLastError(0xdeadbeef);
554 urlComp.lpszUserName = empty;
555 urlComp.lpszPassword = empty;
557 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
558 ok(ret, "Expected success\n");
559 ok(GetLastError() == 0xdeadbeef,
560 "Expected 0xdeadbeef, got %d\n", GetLastError());
561 ok(len == 50, "Expected len 50, got %d\n", len);
562 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
564 /* shows that nScheme is ignored, as the appearance of the port number
565 * depends on lpszScheme and the string copied depends on lpszScheme.
567 fill_url_components(&urlComp);
568 HeapFree(GetProcessHeap(), 0, szUrl);
569 urlComp.lpszScheme = nhttp;
570 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
571 len = strlen(CREATE_URL6) + 1;
572 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, len);
573 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
574 ok(ret, "Expected success\n");
575 ok(len == strlen(CREATE_URL6), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6) + 1, len);
576 ok(!strcmp(szUrl, CREATE_URL6), "Expected %s, got %s\n", CREATE_URL6, szUrl);
578 /* if lpszScheme != "http" or nPort != 80, display nPort */
579 HeapFree(GetProcessHeap(), 0, szUrl);
580 urlComp.lpszScheme = http;
581 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
583 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
584 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
585 ok(ret, "Expected success\n");
586 ok(len == 53, "Expected len 53, got %d\n", len);
587 ok(strstr(szUrl, "42") != NULL, "Expected to find 42 in szUrl\n");
588 ok(!strcmp(szUrl, CREATE_URL7), "Expected %s, got %s\n", CREATE_URL7, szUrl);
590 HeapFree(GetProcessHeap(), 0, szUrl);
592 memset(&urlComp, 0, sizeof(urlComp));
593 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
594 urlComp.lpszScheme = http;
595 urlComp.dwSchemeLength = 0;
596 urlComp.nScheme = INTERNET_SCHEME_HTTP;
597 urlComp.lpszHostName = winehq;
598 urlComp.dwHostNameLength = 0;
600 urlComp.lpszUserName = username;
601 urlComp.dwUserNameLength = 0;
602 urlComp.lpszPassword = password;
603 urlComp.dwPasswordLength = 0;
604 urlComp.lpszUrlPath = site_about;
605 urlComp.dwUrlPathLength = 0;
606 urlComp.lpszExtraInfo = empty;
607 urlComp.dwExtraInfoLength = 0;
608 len = strlen(CREATE_URL1);
609 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
610 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
611 ok(ret, "Expected success\n");
612 ok(len == strlen(CREATE_URL1), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1), len);
613 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
615 HeapFree(GetProcessHeap(), 0, szUrl);
617 memset(&urlComp, 0, sizeof(urlComp));
618 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
619 urlComp.lpszScheme = https;
620 urlComp.dwSchemeLength = 0;
621 urlComp.nScheme = INTERNET_SCHEME_HTTP;
622 urlComp.lpszHostName = winehq;
623 urlComp.dwHostNameLength = 0;
625 urlComp.lpszUserName = username;
626 urlComp.dwUserNameLength = 0;
627 urlComp.lpszPassword = password;
628 urlComp.dwPasswordLength = 0;
629 urlComp.lpszUrlPath = site_about;
630 urlComp.dwUrlPathLength = 0;
631 urlComp.lpszExtraInfo = empty;
632 urlComp.dwExtraInfoLength = 0;
633 len = strlen(CREATE_URL8);
634 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
635 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
636 ok(ret, "Expected success\n");
637 ok(len == strlen(CREATE_URL8), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8), len);
638 ok(!strcmp(szUrl, CREATE_URL8), "Expected %s, got %s\n", CREATE_URL8, szUrl);
640 HeapFree(GetProcessHeap(), 0, szUrl);
642 memset(&urlComp, 0, sizeof(urlComp));
643 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
644 urlComp.lpszScheme = about;
645 urlComp.dwSchemeLength = 5;
646 urlComp.lpszUrlPath = blank;
647 urlComp.dwUrlPathLength = 5;
648 len = strlen(CREATE_URL9);
649 len++; /* work around bug in native wininet */
650 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
651 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
652 ok(ret, "Expected success\n");
653 ok(len == strlen(CREATE_URL9), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9), len);
654 ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
656 HeapFree(GetProcessHeap(), 0, szUrl);
658 memset(&urlComp, 0, sizeof(urlComp));
659 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
660 urlComp.lpszScheme = about;
661 urlComp.lpszHostName = host;
662 urlComp.lpszUrlPath = blank;
663 len = strlen(CREATE_URL10);
664 len++; /* work around bug in native wininet */
665 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
666 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
667 ok(ret, "Expected success\n");
668 ok(len == strlen(CREATE_URL10), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10), len);
669 ok(!strcmp(szUrl, CREATE_URL10), "Expected %s, got %s\n", CREATE_URL10, szUrl);
671 HeapFree(GetProcessHeap(), 0, szUrl);
673 memset(&urlComp, 0, sizeof(urlComp));
674 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
675 urlComp.nPort = 8080;
676 urlComp.lpszScheme = about;
677 len = strlen(CREATE_URL11);
678 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
679 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
680 ok(ret, "Expected success\n");
681 ok(len == strlen(CREATE_URL11), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11), len);
682 ok(!strcmp(szUrl, CREATE_URL11), "Expected %s, got %s\n", CREATE_URL11, szUrl);
684 HeapFree(GetProcessHeap(), 0, szUrl);
686 memset(&urlComp, 0, sizeof(urlComp));
687 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
688 urlComp.lpszScheme = http;
689 urlComp.dwSchemeLength = 0;
690 urlComp.nScheme = INTERNET_SCHEME_HTTP;
691 urlComp.lpszHostName = winehq;
692 urlComp.dwHostNameLength = 0;
693 urlComp.nPort = 65535;
694 len = strlen(CREATE_URL12);
695 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
696 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
697 ok(ret, "Expected success\n");
698 ok(len == strlen(CREATE_URL12), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12), len);
699 ok(!strcmp(szUrl, CREATE_URL12), "Expected %s, got %s\n", CREATE_URL12, szUrl);
701 HeapFree(GetProcessHeap(), 0, szUrl);
706 InternetCrackUrl_test();
707 InternetCrackUrlW_test();
708 InternetCreateUrlA_test();