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", strlen(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", strlen(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 lpUrlComponents->dwStructSize = sizeof(URL_COMPONENTS);
334 lpUrlComponents->lpszScheme = "http";
335 lpUrlComponents->dwSchemeLength = strlen(lpUrlComponents->lpszScheme);
336 lpUrlComponents->nScheme = INTERNET_SCHEME_HTTP;
337 lpUrlComponents->lpszHostName = "www.winehq.org";
338 lpUrlComponents->dwHostNameLength = strlen(lpUrlComponents->lpszHostName);
339 lpUrlComponents->nPort = 80;
340 lpUrlComponents->lpszUserName = "username";
341 lpUrlComponents->dwUserNameLength = strlen(lpUrlComponents->lpszUserName);
342 lpUrlComponents->lpszPassword = "password";
343 lpUrlComponents->dwPasswordLength = strlen(lpUrlComponents->lpszPassword);
344 lpUrlComponents->lpszUrlPath = "/site/about";
345 lpUrlComponents->dwUrlPathLength = strlen(lpUrlComponents->lpszUrlPath);
346 lpUrlComponents->lpszExtraInfo = "";
347 lpUrlComponents->dwExtraInfoLength = strlen(lpUrlComponents->lpszExtraInfo);
350 static void InternetCreateUrlA_test(void)
352 URL_COMPONENTS urlComp;
357 /* test NULL lpUrlComponents */
358 ret = InternetCreateUrlA(NULL, 0, NULL, &len);
359 SetLastError(0xdeadbeef);
360 ok(!ret, "Expected failure\n");
361 ok(GetLastError() == 0xdeadbeef,
362 "Expected 0xdeadbeef, got %ld\n", GetLastError());
363 ok(len == -1, "Expected len -1, got %ld\n", len);
365 /* test zero'ed lpUrlComponents */
366 ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
367 SetLastError(0xdeadbeef);
368 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
369 ok(!ret, "Expected failure\n");
370 ok(GetLastError() == ERROR_INVALID_PARAMETER,
371 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
372 ok(len == -1, "Expected len -1, got %ld\n", len);
374 /* test valid lpUrlComponets, NULL lpdwUrlLength */
375 fill_url_components(&urlComp);
376 SetLastError(0xdeadbeef);
377 ret = InternetCreateUrlA(&urlComp, 0, NULL, NULL);
378 ok(!ret, "Expected failure\n");
379 ok(GetLastError() == ERROR_INVALID_PARAMETER,
380 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
381 ok(len == -1, "Expected len -1, got %ld\n", len);
383 /* test valid lpUrlComponets, emptry szUrl
384 * lpdwUrlLength is size of buffer required on exit, including
385 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
387 SetLastError(0xdeadbeef);
388 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
389 ok(!ret, "Expected failure\n");
390 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
391 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
392 ok(len == 51, "Expected len 51, got %ld\n", len);
394 /* test correct size, NULL szUrl */
395 fill_url_components(&urlComp);
396 SetLastError(0xdeadbeef);
397 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
398 ok(!ret, "Expected failure\n");
399 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
400 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
401 ok(len == 51, "Expected len 51, got %ld\n", len);
403 /* test valid lpUrlComponets, alloced szUrl, small size */
404 SetLastError(0xdeadbeef);
405 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
407 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
408 ok(!ret, "Expected failure\n");
409 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
410 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
411 ok(len == 51, "Expected len 51, got %ld\n", len);
413 /* alloced szUrl, NULL lpszScheme
414 * shows that it uses nScheme instead
416 SetLastError(0xdeadbeef);
417 urlComp.lpszScheme = NULL;
418 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
419 ok(ret, "Expected success\n");
420 ok(GetLastError() == 0xdeadbeef,
421 "Expected 0xdeadbeef, got %ld\n", GetLastError());
422 ok(len == 50, "Expected len 50, got %ld\n", len);
423 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
425 /* alloced szUrl, invalid nScheme
426 * any nScheme out of range seems ignored
428 fill_url_components(&urlComp);
429 SetLastError(0xdeadbeef);
430 urlComp.nScheme = -3;
432 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
433 ok(ret, "Expected success\n");
434 ok(GetLastError() == 0xdeadbeef,
435 "Expected 0xdeadbeef, got %ld\n", GetLastError());
436 ok(len == 50, "Expected len 50, got %ld\n", len);
438 /* test valid lpUrlComponets, alloced szUrl */
439 fill_url_components(&urlComp);
440 SetLastError(0xdeadbeef);
442 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
443 ok(ret, "Expected success\n");
444 ok(GetLastError() == 0xdeadbeef,
445 "Expected 0xdeadbeef, got %ld\n", GetLastError());
446 ok(len == 50, "Expected len 50, got %ld\n", len);
447 ok(strstr(szUrl, "80") == NULL, "Didn't expect to find 80 in szUrl\n");
448 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
450 /* valid username, NULL password */
451 fill_url_components(&urlComp);
452 SetLastError(0xdeadbeef);
453 urlComp.lpszPassword = NULL;
455 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
456 ok(ret, "Expected success\n");
457 ok(GetLastError() == 0xdeadbeef,
458 "Expected 0xdeadbeef, got %ld\n", GetLastError());
459 ok(len == 41, "Expected len 41, got %ld\n", len);
460 ok(!strcmp(szUrl, CREATE_URL2), "Expected %s, got %s\n", CREATE_URL2, szUrl);
462 /* valid username, empty password */
463 fill_url_components(&urlComp);
464 SetLastError(0xdeadbeef);
465 urlComp.lpszPassword = "";
467 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
468 ok(ret, "Expected success\n");
469 ok(GetLastError() == 0xdeadbeef,
470 "Expected 0xdeadbeef, got %ld\n", GetLastError());
471 ok(len == 50, "Expected len 50, got %ld\n", len);
472 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
474 /* valid password, NULL username
475 * if password is provided, username has to exist
477 fill_url_components(&urlComp);
478 SetLastError(0xdeadbeef);
479 urlComp.lpszUserName = NULL;
481 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
482 ok(!ret, "Expected failure\n");
483 ok(GetLastError() == ERROR_INVALID_PARAMETER,
484 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
485 ok(len == 42, "Expected len 42, got %ld\n", len);
486 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
488 /* valid password, empty username
489 * if password is provided, username has to exist
491 fill_url_components(&urlComp);
492 SetLastError(0xdeadbeef);
493 urlComp.lpszUserName = "";
495 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
496 ok(ret, "Expected success\n");
497 ok(GetLastError() == 0xdeadbeef,
498 "Expected 0xdeadbeef, got %ld\n", GetLastError());
499 ok(len == 50, "Expected len 50, got %ld\n", len);
500 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
502 /* NULL username, NULL password */
503 fill_url_components(&urlComp);
504 SetLastError(0xdeadbeef);
505 urlComp.lpszUserName = NULL;
506 urlComp.lpszPassword = NULL;
508 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
509 ok(ret, "Expected success\n");
510 ok(GetLastError() == 0xdeadbeef,
511 "Expected 0xdeadbeef, got %ld\n", GetLastError());
512 ok(len == 32, "Expected len 32, got %ld\n", len);
513 ok(!strcmp(szUrl, CREATE_URL4), "Expected %s, got %s\n", CREATE_URL4, szUrl);
515 /* empty username, empty password */
516 fill_url_components(&urlComp);
517 SetLastError(0xdeadbeef);
518 urlComp.lpszUserName = "";
519 urlComp.lpszPassword = "";
521 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
522 ok(ret, "Expected success\n");
523 ok(GetLastError() == 0xdeadbeef,
524 "Expected 0xdeadbeef, got %ld\n", GetLastError());
525 ok(len == 50, "Expected len 50, got %ld\n", len);
526 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
528 /* shows that nScheme is ignored, as the appearance of the port number
529 * depends on lpszScheme and the string copied depends on lpszScheme.
531 fill_url_components(&urlComp);
532 HeapFree(GetProcessHeap(), 0, szUrl);
533 urlComp.lpszScheme = "nhttp";
534 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
535 len = strlen(CREATE_URL6) + 1;
536 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, len);
537 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
538 ok(ret, "Expected success\n");
539 ok(len == strlen(CREATE_URL6), "Expected len %d, got %ld\n", strlen(CREATE_URL6) + 1, len);
540 ok(!strcmp(szUrl, CREATE_URL6), "Expected %s, got %s\n", CREATE_URL6, szUrl);
542 /* if lpszScheme != "http" or nPort != 80, display nPort */
543 HeapFree(GetProcessHeap(), 0, szUrl);
544 urlComp.lpszScheme = "http";
545 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
547 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
548 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
549 ok(ret, "Expected success\n");
550 ok(len == 53, "Expected len 53, got %ld\n", len);
551 ok(strstr(szUrl, "42") != NULL, "Expected to find 42 in szUrl\n");
552 ok(!strcmp(szUrl, CREATE_URL7), "Expected %s, got %s\n", CREATE_URL7, szUrl);
554 HeapFree(GetProcessHeap(), 0, szUrl);
556 memset(&urlComp, 0, sizeof(urlComp));
557 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
558 urlComp.lpszScheme = "http";
559 urlComp.dwSchemeLength = 0;
560 urlComp.nScheme = INTERNET_SCHEME_HTTP;
561 urlComp.lpszHostName = "www.winehq.org";
562 urlComp.dwHostNameLength = 0;
564 urlComp.lpszUserName = "username";
565 urlComp.dwUserNameLength = 0;
566 urlComp.lpszPassword = "password";
567 urlComp.dwPasswordLength = 0;
568 urlComp.lpszUrlPath = "/site/about";
569 urlComp.dwUrlPathLength = 0;
570 urlComp.lpszExtraInfo = "";
571 urlComp.dwExtraInfoLength = 0;
572 len = strlen(CREATE_URL1);
573 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
574 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
575 ok(ret, "Expected success\n");
576 ok(len == strlen(CREATE_URL1), "Expected len %d, got %ld\n", strlen(CREATE_URL1), len);
577 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
579 memset(&urlComp, 0, sizeof(urlComp));
580 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
581 urlComp.lpszScheme = "https";
582 urlComp.dwSchemeLength = 0;
583 urlComp.nScheme = INTERNET_SCHEME_HTTP;
584 urlComp.lpszHostName = "www.winehq.org";
585 urlComp.dwHostNameLength = 0;
587 urlComp.lpszUserName = "username";
588 urlComp.dwUserNameLength = 0;
589 urlComp.lpszPassword = "password";
590 urlComp.dwPasswordLength = 0;
591 urlComp.lpszUrlPath = "/site/about";
592 urlComp.dwUrlPathLength = 0;
593 urlComp.lpszExtraInfo = "";
594 urlComp.dwExtraInfoLength = 0;
595 len = strlen(CREATE_URL8);
596 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
597 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
598 ok(ret, "Expected success\n");
599 ok(len == strlen(CREATE_URL8), "Expected len %d, got %ld\n", strlen(CREATE_URL8), len);
600 ok(!strcmp(szUrl, CREATE_URL8), "Expected %s, got %s\n", CREATE_URL8, szUrl);
602 HeapFree(GetProcessHeap(), 0, szUrl);
604 memset(&urlComp, 0, sizeof(urlComp));
605 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
606 urlComp.lpszScheme = "about";
607 urlComp.dwSchemeLength = 5;
608 urlComp.lpszUrlPath = "blank";
609 urlComp.dwUrlPathLength = 5;
610 len = strlen(CREATE_URL9);
611 len++; /* work around bug in native wininet */
612 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
613 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
614 ok(ret, "Expected success\n");
615 ok(len == strlen(CREATE_URL9), "Expected len %d, got %ld\n", strlen(CREATE_URL9), len);
616 ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
618 HeapFree(GetProcessHeap(), 0, szUrl);
620 memset(&urlComp, 0, sizeof(urlComp));
621 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
622 urlComp.lpszScheme = "about";
623 urlComp.lpszHostName = "host";
624 urlComp.lpszUrlPath = "blank";
625 len = strlen(CREATE_URL10);
626 len++; /* work around bug in native wininet */
627 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
628 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
629 ok(ret, "Expected success\n");
630 ok(len == strlen(CREATE_URL10), "Expected len %d, got %ld\n", strlen(CREATE_URL10), len);
631 ok(!strcmp(szUrl, CREATE_URL10), "Expected %s, got %s\n", CREATE_URL10, szUrl);
633 HeapFree(GetProcessHeap(), 0, szUrl);
635 memset(&urlComp, 0, sizeof(urlComp));
636 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
637 urlComp.nPort = 8080;
638 urlComp.lpszScheme = "about";
639 len = strlen(CREATE_URL11);
640 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
641 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
642 ok(ret, "Expected success\n");
643 ok(len == strlen(CREATE_URL11), "Expected len %d, got %ld\n", strlen(CREATE_URL11), len);
644 ok(!strcmp(szUrl, CREATE_URL11), "Expected %s, got %s\n", CREATE_URL11, szUrl);
646 HeapFree(GetProcessHeap(), 0, szUrl);
648 memset(&urlComp, 0, sizeof(urlComp));
649 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
650 urlComp.lpszScheme = "http";
651 urlComp.dwSchemeLength = 0;
652 urlComp.nScheme = INTERNET_SCHEME_HTTP;
653 urlComp.lpszHostName = "www.winehq.org";
654 urlComp.dwHostNameLength = 0;
655 urlComp.nPort = 65535;
656 len = strlen(CREATE_URL12);
657 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
658 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
659 ok(ret, "Expected success\n");
660 ok(len == strlen(CREATE_URL12), "Expected len %d, got %ld\n", strlen(CREATE_URL12), len);
661 ok(!strcmp(szUrl, CREATE_URL12), "Expected %s, got %s\n", CREATE_URL12, szUrl);
663 HeapFree(GetProcessHeap(), 0, szUrl);
668 InternetCrackUrl_test();
669 InternetCrackUrlW_test();
670 InternetCreateUrlA_test();