wininet: Removed inline from copy_compsA and zero_compsA to allow Windows testing.
[wine/wine64.git] / dlls / wininet / tests / url.c
blob84690723270def107df50fe0bffe8b1c52f167de
1 /*
2 * Wininet - URL tests
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
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wininet.h"
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 void copy_compsA(
57 URL_COMPONENTSA *src,
58 URL_COMPONENTSA *dst,
59 DWORD scheLen,
60 DWORD hostLen,
61 DWORD userLen,
62 DWORD passLen,
63 DWORD pathLen,
64 DWORD extrLen )
66 *dst = *src;
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 void zero_compsA(
77 URL_COMPONENTSA *dst,
78 DWORD scheLen,
79 DWORD hostLen,
80 DWORD userLen,
81 DWORD passLen,
82 DWORD pathLen,
83 DWORD extrLen )
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];
101 BOOL ret, firstret;
102 DWORD GLE, firstGLE;
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());
158 /* Tests for lpsz* members pointing to real strings while
159 * some corresponding length members are set to zero.
160 * As of IE7 (wininet 7.0*?) all members are checked. So we
161 * run the first test and expect the outcome to be the same
162 * for the first four (scheme, hostname, username and password).
163 * The last two (path and extrainfo) are the same for all versions
164 * of the wininet.dll.
166 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
167 SetLastError(0xdeadbeef);
168 firstret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
169 firstGLE = GetLastError();
171 copy_compsA(&urlSrc, &urlComponents, 32, 0, 1024, 1024, 2048, 1024);
172 SetLastError(0xdeadbeef);
173 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
174 GLE = GetLastError();
175 ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
176 ret, GetLastError(), firstret);
178 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 0, 1024, 2048, 1024);
179 SetLastError(0xdeadbeef);
180 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
181 GLE = GetLastError();
182 ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
183 ret, GetLastError(), firstret);
185 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 0, 2048, 1024);
186 SetLastError(0xdeadbeef);
187 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
188 GLE = GetLastError();
189 ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
190 ret, GetLastError(), firstret);
192 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 0, 1024);
193 SetLastError(0xdeadbeef);
194 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
195 GLE = GetLastError();
196 todo_wine
197 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
198 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
199 ret, GLE);
201 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 0);
202 SetLastError(0xdeadbeef);
203 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
204 GLE = GetLastError();
205 todo_wine
206 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
207 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
208 ret, GLE);
210 copy_compsA(&urlSrc, &urlComponents, 0, 0, 0, 0, 0, 0);
211 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
212 GLE = GetLastError();
213 todo_wine
214 ok(ret==0 && GLE==ERROR_INVALID_PARAMETER,
215 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
216 ret, GLE);
218 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
219 ret = InternetCrackUrl("about://host/blank", 0,0,&urlComponents);
220 ok(ret, "InternetCrackUrl failed with %d\n", GetLastError());
221 ok(!strcmp(urlComponents.lpszScheme, "about"), "lpszScheme was \"%s\" instead of \"about\"\n", urlComponents.lpszScheme);
222 ok(!strcmp(urlComponents.lpszHostName, "host"), "lpszHostName was \"%s\" instead of \"host\"\n", urlComponents.lpszHostName);
223 ok(!strcmp(urlComponents.lpszUrlPath, "/blank"), "lpszUrlPath was \"%s\" instead of \"/blank\"\n", urlComponents.lpszUrlPath);
225 /* try a NULL lpszUrl */
226 SetLastError(0xdeadbeef);
227 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
228 ret = InternetCrackUrl(NULL, 0, 0, &urlComponents);
229 GLE = GetLastError();
230 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
231 ok(GLE == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GLE);
233 /* try an empty lpszUrl, GetLastError returns 12006, whatever that means
234 * we just need to fail and not return success
236 SetLastError(0xdeadbeef);
237 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
238 ret = InternetCrackUrl("", 0, 0, &urlComponents);
239 GLE = GetLastError();
240 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
241 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
244 static void InternetCrackUrlW_test(void)
246 WCHAR url[] = {
247 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
248 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
249 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
250 'U','L','T', 0 };
251 static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
252 URL_COMPONENTSW comp;
253 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
254 DWORD error;
255 BOOL r;
257 urlpart[0]=0;
258 scheme[0]=0;
259 extra[0]=0;
260 host[0]=0;
261 user[0]=0;
262 pwd[0]=0;
263 memset(&comp, 0, sizeof comp);
264 comp.dwStructSize = sizeof comp;
265 comp.lpszScheme = scheme;
266 comp.dwSchemeLength = sizeof scheme;
267 comp.lpszHostName = host;
268 comp.dwHostNameLength = sizeof host;
269 comp.lpszUserName = user;
270 comp.dwUserNameLength = sizeof user;
271 comp.lpszPassword = pwd;
272 comp.dwPasswordLength = sizeof pwd;
273 comp.lpszUrlPath = urlpart;
274 comp.dwUrlPathLength = sizeof urlpart;
275 comp.lpszExtraInfo = extra;
276 comp.dwExtraInfoLength = sizeof extra;
278 SetLastError(0xdeadbeef);
279 r = InternetCrackUrlW(NULL, 0, 0, &comp );
280 error = GetLastError();
281 ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
282 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
284 SetLastError(0xdeadbeef);
285 r = InternetCrackUrlW(url, 0, 0, NULL );
286 error = GetLastError();
287 ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
288 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
290 r = InternetCrackUrlW(url, 0, 0, &comp );
291 ok( r, "failed to crack url\n");
292 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
293 ok( comp.dwHostNameLength == 12, "host length wrong\n");
294 ok( comp.dwUserNameLength == 0, "user length wrong\n");
295 ok( comp.dwPasswordLength == 0, "password length wrong\n");
296 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
297 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
299 urlpart[0]=0;
300 scheme[0]=0;
301 extra[0]=0;
302 host[0]=0;
303 user[0]=0;
304 pwd[0]=0;
305 memset(&comp, 0, sizeof comp);
306 comp.dwStructSize = sizeof comp;
307 comp.lpszHostName = host;
308 comp.dwHostNameLength = sizeof host;
309 comp.lpszUrlPath = urlpart;
310 comp.dwUrlPathLength = sizeof urlpart;
312 r = InternetCrackUrlW(url, 0, 0, &comp );
313 ok( r, "failed to crack url\n");
314 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
315 ok( comp.dwHostNameLength == 12, "host length wrong\n");
316 ok( comp.dwUserNameLength == 0, "user length wrong\n");
317 ok( comp.dwPasswordLength == 0, "password length wrong\n");
318 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
319 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
321 urlpart[0]=0;
322 scheme[0]=0;
323 extra[0]=0;
324 host[0]=0;
325 user[0]=0;
326 pwd[0]=0;
327 memset(&comp, 0, sizeof comp);
328 comp.dwStructSize = sizeof comp;
329 comp.lpszHostName = host;
330 comp.dwHostNameLength = sizeof host;
331 comp.lpszUrlPath = urlpart;
332 comp.dwUrlPathLength = sizeof urlpart;
333 comp.lpszExtraInfo = NULL;
334 comp.dwExtraInfoLength = sizeof extra;
336 r = InternetCrackUrlW(url, 0, 0, &comp );
337 ok( r, "failed to crack url\n");
338 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
339 ok( comp.dwHostNameLength == 12, "host length wrong\n");
340 ok( comp.dwUserNameLength == 0, "user length wrong\n");
341 ok( comp.dwPasswordLength == 0, "password length wrong\n");
342 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
343 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
345 urlpart[0]=0;
346 scheme[0]=0;
347 extra[0]=0;
348 host[0]=0;
349 user[0]=0;
350 pwd[0]=0;
351 memset(&comp, 0, sizeof(comp));
352 comp.dwStructSize = sizeof(comp);
353 comp.lpszScheme = scheme;
354 comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
355 comp.lpszHostName = host;
356 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
357 comp.lpszUserName = user;
358 comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
359 comp.lpszPassword = pwd;
360 comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
361 comp.lpszUrlPath = urlpart;
362 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
363 comp.lpszExtraInfo = extra;
364 comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
366 r = InternetCrackUrlW(url2, 0, 0, &comp);
367 todo_wine {
368 ok(!r, "InternetCrackUrl should have failed\n");
369 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
370 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
371 GetLastError());
375 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents)
377 static CHAR http[] = "http",
378 winehq[] = "www.winehq.org",
379 username[] = "username",
380 password[] = "password",
381 site_about[] = "/site/about",
382 empty[] = "";
384 lpUrlComponents->dwStructSize = sizeof(URL_COMPONENTS);
385 lpUrlComponents->lpszScheme = http;
386 lpUrlComponents->dwSchemeLength = strlen(lpUrlComponents->lpszScheme);
387 lpUrlComponents->nScheme = INTERNET_SCHEME_HTTP;
388 lpUrlComponents->lpszHostName = winehq;
389 lpUrlComponents->dwHostNameLength = strlen(lpUrlComponents->lpszHostName);
390 lpUrlComponents->nPort = 80;
391 lpUrlComponents->lpszUserName = username;
392 lpUrlComponents->dwUserNameLength = strlen(lpUrlComponents->lpszUserName);
393 lpUrlComponents->lpszPassword = password;
394 lpUrlComponents->dwPasswordLength = strlen(lpUrlComponents->lpszPassword);
395 lpUrlComponents->lpszUrlPath = site_about;
396 lpUrlComponents->dwUrlPathLength = strlen(lpUrlComponents->lpszUrlPath);
397 lpUrlComponents->lpszExtraInfo = empty;
398 lpUrlComponents->dwExtraInfoLength = strlen(lpUrlComponents->lpszExtraInfo);
401 static void InternetCreateUrlA_test(void)
403 URL_COMPONENTS urlComp;
404 LPSTR szUrl;
405 DWORD len = -1;
406 BOOL ret;
407 static CHAR empty[] = "",
408 nhttp[] = "nhttp",
409 http[] = "http",
410 https[] = "https",
411 winehq[] = "www.winehq.org",
412 username[] = "username",
413 password[] = "password",
414 site_about[] = "/site/about",
415 about[] = "about",
416 blank[] = "blank",
417 host[] = "host";
419 /* test NULL lpUrlComponents */
420 SetLastError(0xdeadbeef);
421 ret = InternetCreateUrlA(NULL, 0, NULL, &len);
422 ok(!ret, "Expected failure\n");
423 ok(GetLastError() == ERROR_INVALID_PARAMETER,
424 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
425 ok(len == -1, "Expected len -1, got %d\n", len);
427 /* test zero'ed lpUrlComponents */
428 ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
429 SetLastError(0xdeadbeef);
430 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
431 ok(!ret, "Expected failure\n");
432 ok(GetLastError() == ERROR_INVALID_PARAMETER,
433 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
434 ok(len == -1, "Expected len -1, got %d\n", len);
436 /* test valid lpUrlComponets, NULL lpdwUrlLength */
437 fill_url_components(&urlComp);
438 SetLastError(0xdeadbeef);
439 ret = InternetCreateUrlA(&urlComp, 0, NULL, NULL);
440 ok(!ret, "Expected failure\n");
441 ok(GetLastError() == ERROR_INVALID_PARAMETER,
442 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
443 ok(len == -1, "Expected len -1, got %d\n", len);
445 /* test valid lpUrlComponets, emptry szUrl
446 * lpdwUrlLength is size of buffer required on exit, including
447 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
449 SetLastError(0xdeadbeef);
450 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
451 ok(!ret, "Expected failure\n");
452 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
453 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
454 ok(len == 51, "Expected len 51, got %d\n", len);
456 /* test correct size, NULL szUrl */
457 fill_url_components(&urlComp);
458 SetLastError(0xdeadbeef);
459 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
460 ok(!ret, "Expected failure\n");
461 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
462 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
463 ok(len == 51, "Expected len 51, got %d\n", len);
465 /* test valid lpUrlComponets, alloced szUrl, small size */
466 SetLastError(0xdeadbeef);
467 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
468 len -= 2;
469 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
470 ok(!ret, "Expected failure\n");
471 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
472 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
473 ok(len == 51, "Expected len 51, got %d\n", len);
475 /* alloced szUrl, NULL lpszScheme
476 * shows that it uses nScheme instead
478 SetLastError(0xdeadbeef);
479 urlComp.lpszScheme = NULL;
480 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
481 ok(ret, "Expected success\n");
482 ok(GetLastError() == 0xdeadbeef,
483 "Expected 0xdeadbeef, got %d\n", GetLastError());
484 ok(len == 50, "Expected len 50, got %d\n", len);
485 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
487 /* alloced szUrl, invalid nScheme
488 * any nScheme out of range seems ignored
490 fill_url_components(&urlComp);
491 SetLastError(0xdeadbeef);
492 urlComp.nScheme = -3;
493 len++;
494 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
495 ok(ret, "Expected success\n");
496 ok(GetLastError() == 0xdeadbeef,
497 "Expected 0xdeadbeef, got %d\n", GetLastError());
498 ok(len == 50, "Expected len 50, got %d\n", len);
500 /* test valid lpUrlComponets, alloced szUrl */
501 fill_url_components(&urlComp);
502 SetLastError(0xdeadbeef);
503 len = 51;
504 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
505 ok(ret, "Expected success\n");
506 ok(GetLastError() == 0xdeadbeef,
507 "Expected 0xdeadbeef, got %d\n", GetLastError());
508 ok(len == 50, "Expected len 50, got %d\n", len);
509 ok(strstr(szUrl, "80") == NULL, "Didn't expect to find 80 in szUrl\n");
510 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
512 /* valid username, NULL password */
513 fill_url_components(&urlComp);
514 SetLastError(0xdeadbeef);
515 urlComp.lpszPassword = NULL;
516 len = 42;
517 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
518 ok(ret, "Expected success\n");
519 ok(GetLastError() == 0xdeadbeef,
520 "Expected 0xdeadbeef, got %d\n", GetLastError());
521 ok(len == 41, "Expected len 41, got %d\n", len);
522 ok(!strcmp(szUrl, CREATE_URL2), "Expected %s, got %s\n", CREATE_URL2, szUrl);
524 /* valid username, empty password */
525 fill_url_components(&urlComp);
526 SetLastError(0xdeadbeef);
527 urlComp.lpszPassword = empty;
528 len = 51;
529 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
530 ok(ret, "Expected success\n");
531 ok(GetLastError() == 0xdeadbeef,
532 "Expected 0xdeadbeef, got %d\n", GetLastError());
533 ok(len == 50, "Expected len 50, got %d\n", len);
534 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
536 /* valid password, NULL username
537 * if password is provided, username has to exist
539 fill_url_components(&urlComp);
540 SetLastError(0xdeadbeef);
541 urlComp.lpszUserName = NULL;
542 len = 42;
543 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
544 ok(!ret, "Expected failure\n");
545 ok(GetLastError() == ERROR_INVALID_PARAMETER,
546 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
547 ok(len == 42, "Expected len 42, got %d\n", len);
548 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
550 /* valid password, empty username
551 * if password is provided, username has to exist
553 fill_url_components(&urlComp);
554 SetLastError(0xdeadbeef);
555 urlComp.lpszUserName = empty;
556 len = 51;
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 /* NULL username, NULL password */
565 fill_url_components(&urlComp);
566 SetLastError(0xdeadbeef);
567 urlComp.lpszUserName = NULL;
568 urlComp.lpszPassword = NULL;
569 len = 42;
570 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
571 ok(ret, "Expected success\n");
572 ok(GetLastError() == 0xdeadbeef,
573 "Expected 0xdeadbeef, got %d\n", GetLastError());
574 ok(len == 32, "Expected len 32, got %d\n", len);
575 ok(!strcmp(szUrl, CREATE_URL4), "Expected %s, got %s\n", CREATE_URL4, szUrl);
577 /* empty username, empty password */
578 fill_url_components(&urlComp);
579 SetLastError(0xdeadbeef);
580 urlComp.lpszUserName = empty;
581 urlComp.lpszPassword = empty;
582 len = 51;
583 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
584 ok(ret, "Expected success\n");
585 ok(GetLastError() == 0xdeadbeef,
586 "Expected 0xdeadbeef, got %d\n", GetLastError());
587 ok(len == 50, "Expected len 50, got %d\n", len);
588 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
590 /* shows that nScheme is ignored, as the appearance of the port number
591 * depends on lpszScheme and the string copied depends on lpszScheme.
593 fill_url_components(&urlComp);
594 HeapFree(GetProcessHeap(), 0, szUrl);
595 urlComp.lpszScheme = nhttp;
596 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
597 len = strlen(CREATE_URL6) + 1;
598 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
599 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
600 ok(ret, "Expected success\n");
601 ok(len == strlen(CREATE_URL6), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6) + 1, len);
602 ok(!strcmp(szUrl, CREATE_URL6), "Expected %s, got %s\n", CREATE_URL6, szUrl);
604 /* if lpszScheme != "http" or nPort != 80, display nPort */
605 HeapFree(GetProcessHeap(), 0, szUrl);
606 urlComp.lpszScheme = http;
607 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
608 urlComp.nPort = 42;
609 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
610 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
611 ok(ret, "Expected success\n");
612 ok(len == 53, "Expected len 53, got %d\n", len);
613 ok(strstr(szUrl, "42") != NULL, "Expected to find 42 in szUrl\n");
614 ok(!strcmp(szUrl, CREATE_URL7), "Expected %s, got %s\n", CREATE_URL7, szUrl);
616 HeapFree(GetProcessHeap(), 0, szUrl);
618 memset(&urlComp, 0, sizeof(urlComp));
619 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
620 urlComp.lpszScheme = http;
621 urlComp.dwSchemeLength = 0;
622 urlComp.nScheme = INTERNET_SCHEME_HTTP;
623 urlComp.lpszHostName = winehq;
624 urlComp.dwHostNameLength = 0;
625 urlComp.nPort = 80;
626 urlComp.lpszUserName = username;
627 urlComp.dwUserNameLength = 0;
628 urlComp.lpszPassword = password;
629 urlComp.dwPasswordLength = 0;
630 urlComp.lpszUrlPath = site_about;
631 urlComp.dwUrlPathLength = 0;
632 urlComp.lpszExtraInfo = empty;
633 urlComp.dwExtraInfoLength = 0;
634 len = strlen(CREATE_URL1);
635 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
636 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
637 ok(ret, "Expected success\n");
638 ok(len == strlen(CREATE_URL1), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1), len);
639 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
641 HeapFree(GetProcessHeap(), 0, szUrl);
643 memset(&urlComp, 0, sizeof(urlComp));
644 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
645 urlComp.lpszScheme = https;
646 urlComp.dwSchemeLength = 0;
647 urlComp.nScheme = INTERNET_SCHEME_HTTP;
648 urlComp.lpszHostName = winehq;
649 urlComp.dwHostNameLength = 0;
650 urlComp.nPort = 443;
651 urlComp.lpszUserName = username;
652 urlComp.dwUserNameLength = 0;
653 urlComp.lpszPassword = password;
654 urlComp.dwPasswordLength = 0;
655 urlComp.lpszUrlPath = site_about;
656 urlComp.dwUrlPathLength = 0;
657 urlComp.lpszExtraInfo = empty;
658 urlComp.dwExtraInfoLength = 0;
659 len = strlen(CREATE_URL8);
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_URL8), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8), len);
664 ok(!strcmp(szUrl, CREATE_URL8), "Expected %s, got %s\n", CREATE_URL8, szUrl);
666 HeapFree(GetProcessHeap(), 0, szUrl);
668 memset(&urlComp, 0, sizeof(urlComp));
669 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
670 urlComp.lpszScheme = about;
671 urlComp.dwSchemeLength = 5;
672 urlComp.lpszUrlPath = blank;
673 urlComp.dwUrlPathLength = 5;
674 len = strlen(CREATE_URL9);
675 len++; /* work around bug in native wininet */
676 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
677 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
678 ok(ret, "Expected success\n");
679 ok(len == strlen(CREATE_URL9), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9), len);
680 ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
682 HeapFree(GetProcessHeap(), 0, szUrl);
684 memset(&urlComp, 0, sizeof(urlComp));
685 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
686 urlComp.lpszScheme = about;
687 urlComp.lpszHostName = host;
688 urlComp.lpszUrlPath = blank;
689 len = strlen(CREATE_URL10);
690 len++; /* work around bug in native wininet */
691 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
692 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
693 ok(ret, "Expected success\n");
694 ok(len == strlen(CREATE_URL10), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10), len);
695 ok(!strcmp(szUrl, CREATE_URL10), "Expected %s, got %s\n", CREATE_URL10, szUrl);
697 HeapFree(GetProcessHeap(), 0, szUrl);
699 memset(&urlComp, 0, sizeof(urlComp));
700 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
701 urlComp.nPort = 8080;
702 urlComp.lpszScheme = about;
703 len = strlen(CREATE_URL11);
704 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
705 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
706 ok(ret, "Expected success\n");
707 ok(len == strlen(CREATE_URL11), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11), len);
708 ok(!strcmp(szUrl, CREATE_URL11), "Expected %s, got %s\n", CREATE_URL11, szUrl);
710 HeapFree(GetProcessHeap(), 0, szUrl);
712 memset(&urlComp, 0, sizeof(urlComp));
713 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
714 urlComp.lpszScheme = http;
715 urlComp.dwSchemeLength = 0;
716 urlComp.nScheme = INTERNET_SCHEME_HTTP;
717 urlComp.lpszHostName = winehq;
718 urlComp.dwHostNameLength = 0;
719 urlComp.nPort = 65535;
720 len = strlen(CREATE_URL12);
721 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
722 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
723 ok(ret, "Expected success\n");
724 ok(len == strlen(CREATE_URL12), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12), len);
725 ok(!strcmp(szUrl, CREATE_URL12), "Expected %s, got %s\n", CREATE_URL12, szUrl);
727 HeapFree(GetProcessHeap(), 0, szUrl);
730 START_TEST(url)
732 InternetCrackUrl_test();
733 InternetCrackUrlW_test();
734 InternetCreateUrlA_test();