Spelling fixes.
[wine/multimedia.git] / dlls / wininet / tests / url.c
blobdd71edb485e3599f771d8b4c8f6c82af38459344
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");
243 /* Invalid Call: must set size of components structure (Windows only
244 * enforces this on the InternetCrackUrlA version of the call) */
245 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
246 SetLastError(0xdeadbeef);
247 urlComponents.dwStructSize = 0;
248 ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
249 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
250 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
252 /* Invalid Call: size of dwStructSize must be one of the "standard" sizes
253 * of the URL_COMPONENTS structure (Windows only enforces this on the
254 * InternetCrackUrlA version of the call) */
255 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
256 SetLastError(0xdeadbeef);
257 urlComponents.dwStructSize = sizeof(urlComponents) + 1;
258 ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
259 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
260 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
263 static void InternetCrackUrlW_test(void)
265 WCHAR url[] = {
266 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
267 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
268 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
269 'U','L','T', 0 };
270 static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
271 URL_COMPONENTSW comp;
272 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
273 DWORD error;
274 BOOL r;
276 urlpart[0]=0;
277 scheme[0]=0;
278 extra[0]=0;
279 host[0]=0;
280 user[0]=0;
281 pwd[0]=0;
282 memset(&comp, 0, sizeof comp);
283 comp.dwStructSize = sizeof comp;
284 comp.lpszScheme = scheme;
285 comp.dwSchemeLength = sizeof scheme;
286 comp.lpszHostName = host;
287 comp.dwHostNameLength = sizeof host;
288 comp.lpszUserName = user;
289 comp.dwUserNameLength = sizeof user;
290 comp.lpszPassword = pwd;
291 comp.dwPasswordLength = sizeof pwd;
292 comp.lpszUrlPath = urlpart;
293 comp.dwUrlPathLength = sizeof urlpart;
294 comp.lpszExtraInfo = extra;
295 comp.dwExtraInfoLength = sizeof extra;
297 SetLastError(0xdeadbeef);
298 r = InternetCrackUrlW(NULL, 0, 0, &comp );
299 error = GetLastError();
300 ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
301 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
303 SetLastError(0xdeadbeef);
304 r = InternetCrackUrlW(url, 0, 0, NULL );
305 error = GetLastError();
306 ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
307 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
309 r = InternetCrackUrlW(url, 0, 0, &comp );
310 ok( r, "failed to crack url\n");
311 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
312 ok( comp.dwHostNameLength == 12, "host length wrong\n");
313 ok( comp.dwUserNameLength == 0, "user length wrong\n");
314 ok( comp.dwPasswordLength == 0, "password length wrong\n");
315 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
316 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
318 urlpart[0]=0;
319 scheme[0]=0;
320 extra[0]=0;
321 host[0]=0;
322 user[0]=0;
323 pwd[0]=0;
324 memset(&comp, 0, sizeof comp);
325 comp.dwStructSize = sizeof comp;
326 comp.lpszHostName = host;
327 comp.dwHostNameLength = sizeof host;
328 comp.lpszUrlPath = urlpart;
329 comp.dwUrlPathLength = sizeof urlpart;
331 r = InternetCrackUrlW(url, 0, 0, &comp );
332 ok( r, "failed to crack url\n");
333 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
334 ok( comp.dwHostNameLength == 12, "host length wrong\n");
335 ok( comp.dwUserNameLength == 0, "user length wrong\n");
336 ok( comp.dwPasswordLength == 0, "password length wrong\n");
337 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
338 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
340 urlpart[0]=0;
341 scheme[0]=0;
342 extra[0]=0;
343 host[0]=0;
344 user[0]=0;
345 pwd[0]=0;
346 memset(&comp, 0, sizeof comp);
347 comp.dwStructSize = sizeof comp;
348 comp.lpszHostName = host;
349 comp.dwHostNameLength = sizeof host;
350 comp.lpszUrlPath = urlpart;
351 comp.dwUrlPathLength = sizeof urlpart;
352 comp.lpszExtraInfo = NULL;
353 comp.dwExtraInfoLength = sizeof extra;
355 r = InternetCrackUrlW(url, 0, 0, &comp );
356 ok( r, "failed to crack url\n");
357 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
358 ok( comp.dwHostNameLength == 12, "host length wrong\n");
359 ok( comp.dwUserNameLength == 0, "user length wrong\n");
360 ok( comp.dwPasswordLength == 0, "password length wrong\n");
361 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
362 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
364 urlpart[0]=0;
365 scheme[0]=0;
366 extra[0]=0;
367 host[0]=0;
368 user[0]=0;
369 pwd[0]=0;
370 memset(&comp, 0, sizeof(comp));
371 comp.dwStructSize = sizeof(comp);
372 comp.lpszScheme = scheme;
373 comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
374 comp.lpszHostName = host;
375 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
376 comp.lpszUserName = user;
377 comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
378 comp.lpszPassword = pwd;
379 comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
380 comp.lpszUrlPath = urlpart;
381 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
382 comp.lpszExtraInfo = extra;
383 comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
385 r = InternetCrackUrlW(url2, 0, 0, &comp);
386 todo_wine {
387 ok(!r, "InternetCrackUrl should have failed\n");
388 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
389 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
390 GetLastError());
394 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents)
396 static CHAR http[] = "http",
397 winehq[] = "www.winehq.org",
398 username[] = "username",
399 password[] = "password",
400 site_about[] = "/site/about",
401 empty[] = "";
403 lpUrlComponents->dwStructSize = sizeof(URL_COMPONENTS);
404 lpUrlComponents->lpszScheme = http;
405 lpUrlComponents->dwSchemeLength = strlen(lpUrlComponents->lpszScheme);
406 lpUrlComponents->nScheme = INTERNET_SCHEME_HTTP;
407 lpUrlComponents->lpszHostName = winehq;
408 lpUrlComponents->dwHostNameLength = strlen(lpUrlComponents->lpszHostName);
409 lpUrlComponents->nPort = 80;
410 lpUrlComponents->lpszUserName = username;
411 lpUrlComponents->dwUserNameLength = strlen(lpUrlComponents->lpszUserName);
412 lpUrlComponents->lpszPassword = password;
413 lpUrlComponents->dwPasswordLength = strlen(lpUrlComponents->lpszPassword);
414 lpUrlComponents->lpszUrlPath = site_about;
415 lpUrlComponents->dwUrlPathLength = strlen(lpUrlComponents->lpszUrlPath);
416 lpUrlComponents->lpszExtraInfo = empty;
417 lpUrlComponents->dwExtraInfoLength = strlen(lpUrlComponents->lpszExtraInfo);
420 static void InternetCreateUrlA_test(void)
422 URL_COMPONENTS urlComp;
423 LPSTR szUrl;
424 DWORD len = -1;
425 BOOL ret;
426 static CHAR empty[] = "",
427 nhttp[] = "nhttp",
428 http[] = "http",
429 https[] = "https",
430 winehq[] = "www.winehq.org",
431 username[] = "username",
432 password[] = "password",
433 site_about[] = "/site/about",
434 about[] = "about",
435 blank[] = "blank",
436 host[] = "host";
438 /* test NULL lpUrlComponents */
439 SetLastError(0xdeadbeef);
440 ret = InternetCreateUrlA(NULL, 0, NULL, &len);
441 ok(!ret, "Expected failure\n");
442 ok(GetLastError() == ERROR_INVALID_PARAMETER,
443 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
444 ok(len == -1, "Expected len -1, got %d\n", len);
446 /* test zero'ed lpUrlComponents */
447 ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
448 SetLastError(0xdeadbeef);
449 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
450 ok(!ret, "Expected failure\n");
451 ok(GetLastError() == ERROR_INVALID_PARAMETER,
452 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
453 ok(len == -1, "Expected len -1, got %d\n", len);
455 /* test valid lpUrlComponets, NULL lpdwUrlLength */
456 fill_url_components(&urlComp);
457 SetLastError(0xdeadbeef);
458 ret = InternetCreateUrlA(&urlComp, 0, NULL, NULL);
459 ok(!ret, "Expected failure\n");
460 ok(GetLastError() == ERROR_INVALID_PARAMETER,
461 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
462 ok(len == -1, "Expected len -1, got %d\n", len);
464 /* test valid lpUrlComponets, empty szUrl
465 * lpdwUrlLength is size of buffer required on exit, including
466 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
468 SetLastError(0xdeadbeef);
469 ret = InternetCreateUrlA(&urlComp, 0, NULL, &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 /* test correct size, NULL szUrl */
476 fill_url_components(&urlComp);
477 SetLastError(0xdeadbeef);
478 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
479 ok(!ret, "Expected failure\n");
480 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
481 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
482 ok(len == 51, "Expected len 51, got %d\n", len);
484 /* test valid lpUrlComponets, alloced szUrl, small size */
485 SetLastError(0xdeadbeef);
486 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
487 len -= 2;
488 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
489 ok(!ret, "Expected failure\n");
490 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
491 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
492 ok(len == 51, "Expected len 51, got %d\n", len);
494 /* alloced szUrl, NULL lpszScheme
495 * shows that it uses nScheme instead
497 SetLastError(0xdeadbeef);
498 urlComp.lpszScheme = NULL;
499 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
500 ok(ret, "Expected success\n");
501 ok(GetLastError() == 0xdeadbeef,
502 "Expected 0xdeadbeef, got %d\n", GetLastError());
503 ok(len == 50, "Expected len 50, got %d\n", len);
504 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
506 /* alloced szUrl, invalid nScheme
507 * any nScheme out of range seems ignored
509 fill_url_components(&urlComp);
510 SetLastError(0xdeadbeef);
511 urlComp.nScheme = -3;
512 len++;
513 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
514 ok(ret, "Expected success\n");
515 ok(GetLastError() == 0xdeadbeef,
516 "Expected 0xdeadbeef, got %d\n", GetLastError());
517 ok(len == 50, "Expected len 50, got %d\n", len);
519 /* test valid lpUrlComponets, alloced szUrl */
520 fill_url_components(&urlComp);
521 SetLastError(0xdeadbeef);
522 len = 51;
523 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
524 ok(ret, "Expected success\n");
525 ok(GetLastError() == 0xdeadbeef,
526 "Expected 0xdeadbeef, got %d\n", GetLastError());
527 ok(len == 50, "Expected len 50, got %d\n", len);
528 ok(strstr(szUrl, "80") == NULL, "Didn't expect to find 80 in szUrl\n");
529 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
531 /* valid username, NULL password */
532 fill_url_components(&urlComp);
533 SetLastError(0xdeadbeef);
534 urlComp.lpszPassword = NULL;
535 len = 42;
536 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
537 ok(ret, "Expected success\n");
538 ok(GetLastError() == 0xdeadbeef,
539 "Expected 0xdeadbeef, got %d\n", GetLastError());
540 ok(len == 41, "Expected len 41, got %d\n", len);
541 ok(!strcmp(szUrl, CREATE_URL2), "Expected %s, got %s\n", CREATE_URL2, szUrl);
543 /* valid username, empty password */
544 fill_url_components(&urlComp);
545 SetLastError(0xdeadbeef);
546 urlComp.lpszPassword = empty;
547 len = 51;
548 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
549 ok(ret, "Expected success\n");
550 ok(GetLastError() == 0xdeadbeef,
551 "Expected 0xdeadbeef, got %d\n", GetLastError());
552 ok(len == 50, "Expected len 50, got %d\n", len);
553 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
555 /* valid password, NULL username
556 * if password is provided, username has to exist
558 fill_url_components(&urlComp);
559 SetLastError(0xdeadbeef);
560 urlComp.lpszUserName = NULL;
561 len = 42;
562 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
563 ok(!ret, "Expected failure\n");
564 ok(GetLastError() == ERROR_INVALID_PARAMETER,
565 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
566 ok(len == 42, "Expected len 42, got %d\n", len);
567 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
569 /* valid password, empty username
570 * if password is provided, username has to exist
572 fill_url_components(&urlComp);
573 SetLastError(0xdeadbeef);
574 urlComp.lpszUserName = empty;
575 len = 51;
576 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
577 ok(ret, "Expected success\n");
578 ok(GetLastError() == 0xdeadbeef,
579 "Expected 0xdeadbeef, got %d\n", GetLastError());
580 ok(len == 50, "Expected len 50, got %d\n", len);
581 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
583 /* NULL username, NULL password */
584 fill_url_components(&urlComp);
585 SetLastError(0xdeadbeef);
586 urlComp.lpszUserName = NULL;
587 urlComp.lpszPassword = NULL;
588 len = 42;
589 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
590 ok(ret, "Expected success\n");
591 ok(GetLastError() == 0xdeadbeef,
592 "Expected 0xdeadbeef, got %d\n", GetLastError());
593 ok(len == 32, "Expected len 32, got %d\n", len);
594 ok(!strcmp(szUrl, CREATE_URL4), "Expected %s, got %s\n", CREATE_URL4, szUrl);
596 /* empty username, empty password */
597 fill_url_components(&urlComp);
598 SetLastError(0xdeadbeef);
599 urlComp.lpszUserName = empty;
600 urlComp.lpszPassword = empty;
601 len = 51;
602 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
603 ok(ret, "Expected success\n");
604 ok(GetLastError() == 0xdeadbeef,
605 "Expected 0xdeadbeef, got %d\n", GetLastError());
606 ok(len == 50, "Expected len 50, got %d\n", len);
607 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
609 /* shows that nScheme is ignored, as the appearance of the port number
610 * depends on lpszScheme and the string copied depends on lpszScheme.
612 fill_url_components(&urlComp);
613 HeapFree(GetProcessHeap(), 0, szUrl);
614 urlComp.lpszScheme = nhttp;
615 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
616 len = strlen(CREATE_URL6) + 1;
617 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
618 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
619 ok(ret, "Expected success\n");
620 ok(len == strlen(CREATE_URL6), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6) + 1, len);
621 ok(!strcmp(szUrl, CREATE_URL6), "Expected %s, got %s\n", CREATE_URL6, szUrl);
623 /* if lpszScheme != "http" or nPort != 80, display nPort */
624 HeapFree(GetProcessHeap(), 0, szUrl);
625 urlComp.lpszScheme = http;
626 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
627 urlComp.nPort = 42;
628 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
629 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
630 ok(ret, "Expected success\n");
631 ok(len == 53, "Expected len 53, got %d\n", len);
632 ok(strstr(szUrl, "42") != NULL, "Expected to find 42 in szUrl\n");
633 ok(!strcmp(szUrl, CREATE_URL7), "Expected %s, got %s\n", CREATE_URL7, szUrl);
635 HeapFree(GetProcessHeap(), 0, szUrl);
637 memset(&urlComp, 0, sizeof(urlComp));
638 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
639 urlComp.lpszScheme = http;
640 urlComp.dwSchemeLength = 0;
641 urlComp.nScheme = INTERNET_SCHEME_HTTP;
642 urlComp.lpszHostName = winehq;
643 urlComp.dwHostNameLength = 0;
644 urlComp.nPort = 80;
645 urlComp.lpszUserName = username;
646 urlComp.dwUserNameLength = 0;
647 urlComp.lpszPassword = password;
648 urlComp.dwPasswordLength = 0;
649 urlComp.lpszUrlPath = site_about;
650 urlComp.dwUrlPathLength = 0;
651 urlComp.lpszExtraInfo = empty;
652 urlComp.dwExtraInfoLength = 0;
653 len = strlen(CREATE_URL1);
654 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
655 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
656 ok(ret, "Expected success\n");
657 ok(len == strlen(CREATE_URL1), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1), len);
658 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
660 HeapFree(GetProcessHeap(), 0, szUrl);
662 memset(&urlComp, 0, sizeof(urlComp));
663 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
664 urlComp.lpszScheme = https;
665 urlComp.dwSchemeLength = 0;
666 urlComp.nScheme = INTERNET_SCHEME_HTTP;
667 urlComp.lpszHostName = winehq;
668 urlComp.dwHostNameLength = 0;
669 urlComp.nPort = 443;
670 urlComp.lpszUserName = username;
671 urlComp.dwUserNameLength = 0;
672 urlComp.lpszPassword = password;
673 urlComp.dwPasswordLength = 0;
674 urlComp.lpszUrlPath = site_about;
675 urlComp.dwUrlPathLength = 0;
676 urlComp.lpszExtraInfo = empty;
677 urlComp.dwExtraInfoLength = 0;
678 len = strlen(CREATE_URL8);
679 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
680 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
681 ok(ret, "Expected success\n");
682 ok(len == strlen(CREATE_URL8), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8), len);
683 ok(!strcmp(szUrl, CREATE_URL8), "Expected %s, got %s\n", CREATE_URL8, szUrl);
685 HeapFree(GetProcessHeap(), 0, szUrl);
687 memset(&urlComp, 0, sizeof(urlComp));
688 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
689 urlComp.lpszScheme = about;
690 urlComp.dwSchemeLength = 5;
691 urlComp.lpszUrlPath = blank;
692 urlComp.dwUrlPathLength = 5;
693 len = strlen(CREATE_URL9);
694 len++; /* work around bug in native wininet */
695 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
696 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
697 ok(ret, "Expected success\n");
698 ok(len == strlen(CREATE_URL9), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9), len);
699 ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
701 HeapFree(GetProcessHeap(), 0, szUrl);
703 memset(&urlComp, 0, sizeof(urlComp));
704 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
705 urlComp.lpszScheme = about;
706 urlComp.lpszHostName = host;
707 urlComp.lpszUrlPath = blank;
708 len = strlen(CREATE_URL10);
709 len++; /* work around bug in native wininet */
710 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
711 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
712 ok(ret, "Expected success\n");
713 ok(len == strlen(CREATE_URL10), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10), len);
714 ok(!strcmp(szUrl, CREATE_URL10), "Expected %s, got %s\n", CREATE_URL10, szUrl);
716 HeapFree(GetProcessHeap(), 0, szUrl);
718 memset(&urlComp, 0, sizeof(urlComp));
719 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
720 urlComp.nPort = 8080;
721 urlComp.lpszScheme = about;
722 len = strlen(CREATE_URL11);
723 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
724 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
725 ok(ret, "Expected success\n");
726 ok(len == strlen(CREATE_URL11), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11), len);
727 ok(!strcmp(szUrl, CREATE_URL11), "Expected %s, got %s\n", CREATE_URL11, szUrl);
729 HeapFree(GetProcessHeap(), 0, szUrl);
731 memset(&urlComp, 0, sizeof(urlComp));
732 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
733 urlComp.lpszScheme = http;
734 urlComp.dwSchemeLength = 0;
735 urlComp.nScheme = INTERNET_SCHEME_HTTP;
736 urlComp.lpszHostName = winehq;
737 urlComp.dwHostNameLength = 0;
738 urlComp.nPort = 65535;
739 len = strlen(CREATE_URL12);
740 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
741 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
742 ok(ret, "Expected success\n");
743 ok(len == strlen(CREATE_URL12), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12), len);
744 ok(!strcmp(szUrl, CREATE_URL12), "Expected %s, got %s\n", CREATE_URL12, szUrl);
746 HeapFree(GetProcessHeap(), 0, szUrl);
749 START_TEST(url)
751 InternetCrackUrl_test();
752 InternetCrackUrlW_test();
753 InternetCreateUrlA_test();