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 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 void zero_compsA(
85 ZeroMemory(dst
, sizeof(URL_COMPONENTSA
));
86 dst
->dwStructSize
= sizeof(URL_COMPONENTSA
);
87 dst
->dwSchemeLength
= scheLen
;
88 dst
->dwHostNameLength
= hostLen
;
89 dst
->dwUserNameLength
= userLen
;
90 dst
->dwPasswordLength
= passLen
;
91 dst
->dwUrlPathLength
= pathLen
;
92 dst
->dwExtraInfoLength
= extrLen
;
93 SetLastError(0xfaceabad);
96 static void InternetCrackUrl_test(void)
98 URL_COMPONENTSA urlSrc
, urlComponents
;
99 char protocol
[32], hostName
[1024], userName
[1024];
100 char password
[1024], extra
[1024], path
[1024];
104 ZeroMemory(&urlSrc
, sizeof(urlSrc
));
105 urlSrc
.dwStructSize
= sizeof(urlSrc
);
106 urlSrc
.lpszScheme
= protocol
;
107 urlSrc
.lpszHostName
= hostName
;
108 urlSrc
.lpszUserName
= userName
;
109 urlSrc
.lpszPassword
= password
;
110 urlSrc
.lpszUrlPath
= path
;
111 urlSrc
.lpszExtraInfo
= extra
;
113 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 2048, 1024);
114 ret
= InternetCrackUrl(TEST_URL
, 0,0,&urlComponents
);
115 ok( ret
, "InternetCrackUrl failed, error %d\n",GetLastError());
116 ok((strcmp(TEST_URL_PATH
,path
) == 0),"path cracked wrong\n");
118 /* Bug 1805: Confirm the returned lengths are correct: */
119 /* 1. When extra info split out explicitly */
120 zero_compsA(&urlComponents
, 0, 1, 0, 0, 1, 1);
121 ok(InternetCrackUrlA(TEST_URL2
, 0, 0, &urlComponents
),"InternetCrackUrl failed, error %d\n", GetLastError());
122 ok(urlComponents
.dwUrlPathLength
== strlen(TEST_URL2_PATH
),".dwUrlPathLength should be %d, but is %d\n", (DWORD
)strlen(TEST_URL2_PATH
), urlComponents
.dwUrlPathLength
);
123 ok(!strncmp(urlComponents
.lpszUrlPath
,TEST_URL2_PATH
,strlen(TEST_URL2_PATH
)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATH
, urlComponents
.lpszUrlPath
);
124 ok(urlComponents
.dwHostNameLength
== strlen(TEST_URL2_SERVER
),".dwHostNameLength should be %d, but is %d\n", (DWORD
)strlen(TEST_URL2_SERVER
), urlComponents
.dwHostNameLength
);
125 ok(!strncmp(urlComponents
.lpszHostName
,TEST_URL2_SERVER
,strlen(TEST_URL2_SERVER
)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER
, urlComponents
.lpszHostName
);
126 ok(urlComponents
.dwExtraInfoLength
== strlen(TEST_URL2_EXTRA
),".dwExtraInfoLength should be %d, but is %d\n", (DWORD
)strlen(TEST_URL2_EXTRA
), urlComponents
.dwExtraInfoLength
);
127 ok(!strncmp(urlComponents
.lpszExtraInfo
,TEST_URL2_EXTRA
,strlen(TEST_URL2_EXTRA
)),"lpszExtraInfo should be %s but is %s\n", TEST_URL2_EXTRA
, urlComponents
.lpszHostName
);
129 /* 2. When extra info is not split out explicitly and is in url path */
130 zero_compsA(&urlComponents
, 0, 1, 0, 0, 1, 0);
131 ok(InternetCrackUrlA(TEST_URL2
, 0, 0, &urlComponents
),"InternetCrackUrl failed with GLE %d\n",GetLastError());
132 ok(urlComponents
.dwUrlPathLength
== strlen(TEST_URL2_PATHEXTRA
),".dwUrlPathLength should be %d, but is %d\n", (DWORD
)strlen(TEST_URL2_PATHEXTRA
), urlComponents
.dwUrlPathLength
);
133 ok(!strncmp(urlComponents
.lpszUrlPath
,TEST_URL2_PATHEXTRA
,strlen(TEST_URL2_PATHEXTRA
)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATHEXTRA
, urlComponents
.lpszUrlPath
);
134 ok(urlComponents
.dwHostNameLength
== strlen(TEST_URL2_SERVER
),".dwHostNameLength should be %d, but is %d\n", (DWORD
)strlen(TEST_URL2_SERVER
), urlComponents
.dwHostNameLength
);
135 ok(!strncmp(urlComponents
.lpszHostName
,TEST_URL2_SERVER
,strlen(TEST_URL2_SERVER
)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER
, urlComponents
.lpszHostName
);
136 ok(urlComponents
.nPort
== INTERNET_DEFAULT_HTTP_PORT
,"urlComponents->nPort should have been 80 instead of %d\n", urlComponents
.nPort
);
137 ok(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
,"urlComponents->nScheme should have been INTERNET_SCHEME_HTTP instead of %d\n", urlComponents
.nScheme
);
139 zero_compsA(&urlComponents
, 1, 1, 1, 1, 1, 1);
140 ok(InternetCrackUrlA(TEST_URL
, strlen(TEST_URL
), 0, &urlComponents
),"InternetCrackUrl failed with GLE %d\n",GetLastError());
141 ok(urlComponents
.dwUrlPathLength
== strlen(TEST_URL_PATH
),".dwUrlPathLength should be %d, but is %d\n", lstrlenA(TEST_URL_PATH
), urlComponents
.dwUrlPathLength
);
142 ok(!strncmp(urlComponents
.lpszUrlPath
,TEST_URL_PATH
,strlen(TEST_URL_PATH
)),"lpszUrlPath should be %s but is %s\n", TEST_URL_PATH
, urlComponents
.lpszUrlPath
);
143 ok(urlComponents
.dwHostNameLength
== strlen(TEST_URL_HOST
),".dwHostNameLength should be %d, but is %d\n", lstrlenA(TEST_URL_HOST
), urlComponents
.dwHostNameLength
);
144 ok(!strncmp(urlComponents
.lpszHostName
,TEST_URL_HOST
,strlen(TEST_URL_HOST
)),"lpszHostName should be %s but is %s\n", TEST_URL_HOST
, urlComponents
.lpszHostName
);
145 ok(urlComponents
.nPort
== INTERNET_DEFAULT_HTTP_PORT
,"urlComponents->nPort should have been 80 instead of %d\n", urlComponents
.nPort
);
146 ok(urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
,"urlComponents->nScheme should have been INTERNET_SCHEME_HTTP instead of %d\n", urlComponents
.nScheme
);
147 ok(!urlComponents
.lpszUserName
, ".lpszUserName should have been set to NULL\n");
148 ok(!urlComponents
.lpszPassword
, ".lpszPassword should have been set to NULL\n");
149 ok(!urlComponents
.lpszExtraInfo
, ".lpszExtraInfo should have been set to NULL\n");
150 ok(!urlComponents
.dwUserNameLength
,".dwUserNameLength should be 0, but is %d\n", urlComponents
.dwUserNameLength
);
151 ok(!urlComponents
.dwPasswordLength
,".dwPasswordLength should be 0, but is %d\n", urlComponents
.dwPasswordLength
);
152 ok(!urlComponents
.dwExtraInfoLength
,".dwExtraInfoLength should be 0, but is %d\n", urlComponents
.dwExtraInfoLength
);
154 /*3. Check for %20 */
155 copy_compsA(&urlSrc
, &urlComponents
, 32, 1024, 1024, 1024, 2048, 1024);
156 ok(InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
),"InternetCrackUrl failed with GLE %d\n",GetLastError());
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();
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",
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();
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",
210 copy_compsA(&urlSrc
, &urlComponents
, 0, 0, 0, 0, 0, 0);
211 ret
= InternetCrackUrlA(TEST_URL3
, 0, ICU_DECODE
, &urlComponents
);
212 GLE
= GetLastError();
214 ok(ret
==0 && GLE
==ERROR_INVALID_PARAMETER
,
215 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
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)
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',
270 static const WCHAR url2
[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
271 static const WCHAR url3
[] = { 'h','t','t','p',':','/','/','x','.','o','r','g',0 };
272 URL_COMPONENTSW comp
;
273 WCHAR scheme
[20], host
[20], user
[20], pwd
[20], urlpart
[50], extra
[50];
283 memset(&comp
, 0, sizeof comp
);
284 comp
.dwStructSize
= sizeof comp
;
285 comp
.lpszScheme
= scheme
;
286 comp
.dwSchemeLength
= sizeof scheme
;
287 comp
.lpszHostName
= host
;
288 comp
.dwHostNameLength
= sizeof host
;
289 comp
.lpszUserName
= user
;
290 comp
.dwUserNameLength
= sizeof user
;
291 comp
.lpszPassword
= pwd
;
292 comp
.dwPasswordLength
= sizeof pwd
;
293 comp
.lpszUrlPath
= urlpart
;
294 comp
.dwUrlPathLength
= sizeof urlpart
;
295 comp
.lpszExtraInfo
= extra
;
296 comp
.dwExtraInfoLength
= sizeof extra
;
298 SetLastError(0xdeadbeef);
299 r
= InternetCrackUrlW(NULL
, 0, 0, &comp
);
300 error
= GetLastError();
301 ok( !r
, "InternetCrackUrlW succeeded unexpectedly\n");
302 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
304 SetLastError(0xdeadbeef);
305 r
= InternetCrackUrlW(url
, 0, 0, NULL
);
306 error
= GetLastError();
307 ok( !r
, "InternetCrackUrlW succeeded unexpectedly\n");
308 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
310 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
311 ok( r
, "failed to crack url\n");
312 ok( comp
.dwSchemeLength
== 4, "scheme length wrong\n");
313 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
314 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
315 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
316 ok( comp
.dwUrlPathLength
== 15, "url length wrong\n");
317 ok( comp
.dwExtraInfoLength
== 29, "extra length wrong\n");
325 memset(&comp
, 0, sizeof comp
);
326 comp
.dwStructSize
= sizeof comp
;
327 comp
.lpszHostName
= host
;
328 comp
.dwHostNameLength
= sizeof host
;
329 comp
.lpszUrlPath
= urlpart
;
330 comp
.dwUrlPathLength
= sizeof urlpart
;
332 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
333 ok( r
, "failed to crack url\n");
334 ok( comp
.dwSchemeLength
== 0, "scheme length wrong\n");
335 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
336 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
337 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
338 ok( comp
.dwUrlPathLength
== 44, "url length wrong\n");
339 ok( comp
.dwExtraInfoLength
== 0, "extra length wrong\n");
347 memset(&comp
, 0, sizeof comp
);
348 comp
.dwStructSize
= sizeof comp
;
349 comp
.lpszHostName
= host
;
350 comp
.dwHostNameLength
= sizeof host
;
351 comp
.lpszUrlPath
= urlpart
;
352 comp
.dwUrlPathLength
= sizeof urlpart
;
353 comp
.lpszExtraInfo
= NULL
;
354 comp
.dwExtraInfoLength
= sizeof extra
;
356 r
= InternetCrackUrlW(url
, 0, 0, &comp
);
357 ok( r
, "failed to crack url\n");
358 ok( comp
.dwSchemeLength
== 0, "scheme length wrong\n");
359 ok( comp
.dwHostNameLength
== 12, "host length wrong\n");
360 ok( comp
.dwUserNameLength
== 0, "user length wrong\n");
361 ok( comp
.dwPasswordLength
== 0, "password length wrong\n");
362 ok( comp
.dwUrlPathLength
== 15, "url length wrong\n");
363 ok( comp
.dwExtraInfoLength
== 29, "extra length wrong\n");
371 memset(&comp
, 0, sizeof(comp
));
372 comp
.dwStructSize
= sizeof(comp
);
373 comp
.lpszScheme
= scheme
;
374 comp
.dwSchemeLength
= sizeof(scheme
)/sizeof(scheme
[0]);
375 comp
.lpszHostName
= host
;
376 comp
.dwHostNameLength
= sizeof(host
)/sizeof(host
[0]);
377 comp
.lpszUserName
= user
;
378 comp
.dwUserNameLength
= sizeof(user
)/sizeof(user
[0]);
379 comp
.lpszPassword
= pwd
;
380 comp
.dwPasswordLength
= sizeof(pwd
)/sizeof(pwd
[0]);
381 comp
.lpszUrlPath
= urlpart
;
382 comp
.dwUrlPathLength
= sizeof(urlpart
)/sizeof(urlpart
[0]);
383 comp
.lpszExtraInfo
= extra
;
384 comp
.dwExtraInfoLength
= sizeof(extra
)/sizeof(extra
[0]);
386 r
= InternetCrackUrlW(url2
, 0, 0, &comp
);
388 ok(!r
, "InternetCrackUrl should have failed\n");
389 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
,
390 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
394 /* Test to see whether cracking a URL without a filename initializes urlpart */
401 memset(&comp
, 0, sizeof comp
);
402 comp
.dwStructSize
= sizeof comp
;
403 comp
.lpszScheme
= scheme
;
404 comp
.dwSchemeLength
= sizeof scheme
;
405 comp
.lpszHostName
= host
;
406 comp
.dwHostNameLength
= sizeof host
;
407 comp
.lpszUserName
= user
;
408 comp
.dwUserNameLength
= sizeof user
;
409 comp
.lpszPassword
= pwd
;
410 comp
.dwPasswordLength
= sizeof pwd
;
411 comp
.lpszUrlPath
= urlpart
;
412 comp
.dwUrlPathLength
= sizeof urlpart
;
413 comp
.lpszExtraInfo
= extra
;
414 comp
.dwExtraInfoLength
= sizeof extra
;
415 r
= InternetCrackUrlW(url3
, 0, 0, &comp
);
416 ok( r
, "InternetCrackUrlW failed unexpectedly\n");
417 ok( host
[0] == 'x', "host should be x.org\n");
418 ok( urlpart
[0] == 0, "urlpart should be empty\n");
421 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents
)
423 static CHAR http
[] = "http",
424 winehq
[] = "www.winehq.org",
425 username
[] = "username",
426 password
[] = "password",
427 site_about
[] = "/site/about",
430 lpUrlComponents
->dwStructSize
= sizeof(URL_COMPONENTS
);
431 lpUrlComponents
->lpszScheme
= http
;
432 lpUrlComponents
->dwSchemeLength
= strlen(lpUrlComponents
->lpszScheme
);
433 lpUrlComponents
->nScheme
= INTERNET_SCHEME_HTTP
;
434 lpUrlComponents
->lpszHostName
= winehq
;
435 lpUrlComponents
->dwHostNameLength
= strlen(lpUrlComponents
->lpszHostName
);
436 lpUrlComponents
->nPort
= 80;
437 lpUrlComponents
->lpszUserName
= username
;
438 lpUrlComponents
->dwUserNameLength
= strlen(lpUrlComponents
->lpszUserName
);
439 lpUrlComponents
->lpszPassword
= password
;
440 lpUrlComponents
->dwPasswordLength
= strlen(lpUrlComponents
->lpszPassword
);
441 lpUrlComponents
->lpszUrlPath
= site_about
;
442 lpUrlComponents
->dwUrlPathLength
= strlen(lpUrlComponents
->lpszUrlPath
);
443 lpUrlComponents
->lpszExtraInfo
= empty
;
444 lpUrlComponents
->dwExtraInfoLength
= strlen(lpUrlComponents
->lpszExtraInfo
);
447 static void InternetCreateUrlA_test(void)
449 URL_COMPONENTS urlComp
;
453 static CHAR empty
[] = "",
457 winehq
[] = "www.winehq.org",
458 username
[] = "username",
459 password
[] = "password",
460 site_about
[] = "/site/about",
465 /* test NULL lpUrlComponents */
466 SetLastError(0xdeadbeef);
467 ret
= InternetCreateUrlA(NULL
, 0, NULL
, &len
);
468 ok(!ret
, "Expected failure\n");
469 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
470 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
471 ok(len
== -1, "Expected len -1, got %d\n", len
);
473 /* test zero'ed lpUrlComponents */
474 ZeroMemory(&urlComp
, sizeof(URL_COMPONENTS
));
475 SetLastError(0xdeadbeef);
476 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
477 ok(!ret
, "Expected failure\n");
478 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
479 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
480 ok(len
== -1, "Expected len -1, got %d\n", len
);
482 /* test valid lpUrlComponents, NULL lpdwUrlLength */
483 fill_url_components(&urlComp
);
484 SetLastError(0xdeadbeef);
485 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, NULL
);
486 ok(!ret
, "Expected failure\n");
487 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
488 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
489 ok(len
== -1, "Expected len -1, got %d\n", len
);
491 /* test valid lpUrlComponents, empty szUrl
492 * lpdwUrlLength is size of buffer required on exit, including
493 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
495 SetLastError(0xdeadbeef);
496 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
497 ok(!ret
, "Expected failure\n");
498 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
499 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
500 ok(len
== 51, "Expected len 51, got %d\n", len
);
502 /* test correct size, NULL szUrl */
503 fill_url_components(&urlComp
);
504 SetLastError(0xdeadbeef);
505 ret
= InternetCreateUrlA(&urlComp
, 0, NULL
, &len
);
506 ok(!ret
, "Expected failure\n");
507 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
508 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
509 ok(len
== 51, "Expected len 51, got %d\n", len
);
511 /* test valid lpUrlComponents, alloc-ed szUrl, small size */
512 SetLastError(0xdeadbeef);
513 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
515 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
516 ok(!ret
, "Expected failure\n");
517 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
518 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
519 ok(len
== 51, "Expected len 51, got %d\n", len
);
521 /* alloc-ed szUrl, NULL lpszScheme
522 * shows that it uses nScheme instead
524 SetLastError(0xdeadbeef);
525 urlComp
.lpszScheme
= NULL
;
526 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
527 ok(ret
, "Expected success\n");
528 ok(GetLastError() == 0xdeadbeef,
529 "Expected 0xdeadbeef, got %d\n", GetLastError());
530 ok(len
== 50, "Expected len 50, got %d\n", len
);
531 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
533 /* alloc-ed szUrl, invalid nScheme
534 * any nScheme out of range seems ignored
536 fill_url_components(&urlComp
);
537 SetLastError(0xdeadbeef);
538 urlComp
.nScheme
= -3;
540 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
541 ok(ret
, "Expected success\n");
542 ok(GetLastError() == 0xdeadbeef,
543 "Expected 0xdeadbeef, got %d\n", GetLastError());
544 ok(len
== 50, "Expected len 50, got %d\n", len
);
546 /* test valid lpUrlComponents, alloc-ed szUrl */
547 fill_url_components(&urlComp
);
548 SetLastError(0xdeadbeef);
550 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
551 ok(ret
, "Expected success\n");
552 ok(GetLastError() == 0xdeadbeef,
553 "Expected 0xdeadbeef, got %d\n", GetLastError());
554 ok(len
== 50, "Expected len 50, got %d\n", len
);
555 ok(strstr(szUrl
, "80") == NULL
, "Didn't expect to find 80 in szUrl\n");
556 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
558 /* valid username, NULL password */
559 fill_url_components(&urlComp
);
560 SetLastError(0xdeadbeef);
561 urlComp
.lpszPassword
= NULL
;
563 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
564 ok(ret
, "Expected success\n");
565 ok(GetLastError() == 0xdeadbeef,
566 "Expected 0xdeadbeef, got %d\n", GetLastError());
567 ok(len
== 41, "Expected len 41, got %d\n", len
);
568 ok(!strcmp(szUrl
, CREATE_URL2
), "Expected %s, got %s\n", CREATE_URL2
, szUrl
);
570 /* valid username, empty password */
571 fill_url_components(&urlComp
);
572 SetLastError(0xdeadbeef);
573 urlComp
.lpszPassword
= empty
;
575 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
576 ok(ret
, "Expected success\n");
577 ok(GetLastError() == 0xdeadbeef,
578 "Expected 0xdeadbeef, got %d\n", GetLastError());
579 ok(len
== 50, "Expected len 50, got %d\n", len
);
580 ok(!strcmp(szUrl
, CREATE_URL3
), "Expected %s, got %s\n", CREATE_URL3
, szUrl
);
582 /* valid password, NULL username
583 * if password is provided, username has to exist
585 fill_url_components(&urlComp
);
586 SetLastError(0xdeadbeef);
587 urlComp
.lpszUserName
= NULL
;
589 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
590 ok(!ret
, "Expected failure\n");
591 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
592 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
593 ok(len
== 42, "Expected len 42, got %d\n", len
);
594 ok(!strcmp(szUrl
, CREATE_URL3
), "Expected %s, got %s\n", CREATE_URL3
, szUrl
);
596 /* valid password, empty username
597 * if password is provided, username has to exist
599 fill_url_components(&urlComp
);
600 SetLastError(0xdeadbeef);
601 urlComp
.lpszUserName
= empty
;
603 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
604 ok(ret
, "Expected success\n");
605 ok(GetLastError() == 0xdeadbeef,
606 "Expected 0xdeadbeef, got %d\n", GetLastError());
607 ok(len
== 50, "Expected len 50, got %d\n", len
);
608 ok(!strcmp(szUrl
, CREATE_URL5
), "Expected %s, got %s\n", CREATE_URL5
, szUrl
);
610 /* NULL username, NULL password */
611 fill_url_components(&urlComp
);
612 SetLastError(0xdeadbeef);
613 urlComp
.lpszUserName
= NULL
;
614 urlComp
.lpszPassword
= NULL
;
616 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
617 ok(ret
, "Expected success\n");
618 ok(GetLastError() == 0xdeadbeef,
619 "Expected 0xdeadbeef, got %d\n", GetLastError());
620 ok(len
== 32, "Expected len 32, got %d\n", len
);
621 ok(!strcmp(szUrl
, CREATE_URL4
), "Expected %s, got %s\n", CREATE_URL4
, szUrl
);
623 /* empty username, empty password */
624 fill_url_components(&urlComp
);
625 SetLastError(0xdeadbeef);
626 urlComp
.lpszUserName
= empty
;
627 urlComp
.lpszPassword
= empty
;
629 ret
= InternetCreateUrlA(&urlComp
, 0, szUrl
, &len
);
630 ok(ret
, "Expected success\n");
631 ok(GetLastError() == 0xdeadbeef,
632 "Expected 0xdeadbeef, got %d\n", GetLastError());
633 ok(len
== 50, "Expected len 50, got %d\n", len
);
634 ok(!strcmp(szUrl
, CREATE_URL5
), "Expected %s, got %s\n", CREATE_URL5
, szUrl
);
636 /* shows that nScheme is ignored, as the appearance of the port number
637 * depends on lpszScheme and the string copied depends on lpszScheme.
639 fill_url_components(&urlComp
);
640 HeapFree(GetProcessHeap(), 0, szUrl
);
641 urlComp
.lpszScheme
= nhttp
;
642 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
643 len
= strlen(CREATE_URL6
) + 1;
644 szUrl
= HeapAlloc(GetProcessHeap(), 0, len
);
645 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
646 ok(ret
, "Expected success\n");
647 ok(len
== strlen(CREATE_URL6
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6
) + 1, len
);
648 ok(!strcmp(szUrl
, CREATE_URL6
), "Expected %s, got %s\n", CREATE_URL6
, szUrl
);
650 /* if lpszScheme != "http" or nPort != 80, display nPort */
651 HeapFree(GetProcessHeap(), 0, szUrl
);
652 urlComp
.lpszScheme
= http
;
653 urlComp
.dwSchemeLength
= strlen(urlComp
.lpszScheme
);
655 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
656 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
657 ok(ret
, "Expected success\n");
658 ok(len
== 53, "Expected len 53, got %d\n", len
);
659 ok(strstr(szUrl
, "42") != NULL
, "Expected to find 42 in szUrl\n");
660 ok(!strcmp(szUrl
, CREATE_URL7
), "Expected %s, got %s\n", CREATE_URL7
, szUrl
);
662 HeapFree(GetProcessHeap(), 0, szUrl
);
664 memset(&urlComp
, 0, sizeof(urlComp
));
665 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
666 urlComp
.lpszScheme
= http
;
667 urlComp
.dwSchemeLength
= 0;
668 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
669 urlComp
.lpszHostName
= winehq
;
670 urlComp
.dwHostNameLength
= 0;
672 urlComp
.lpszUserName
= username
;
673 urlComp
.dwUserNameLength
= 0;
674 urlComp
.lpszPassword
= password
;
675 urlComp
.dwPasswordLength
= 0;
676 urlComp
.lpszUrlPath
= site_about
;
677 urlComp
.dwUrlPathLength
= 0;
678 urlComp
.lpszExtraInfo
= empty
;
679 urlComp
.dwExtraInfoLength
= 0;
680 len
= strlen(CREATE_URL1
);
681 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
682 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
683 ok(ret
, "Expected success\n");
684 ok(len
== strlen(CREATE_URL1
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1
), len
);
685 ok(!strcmp(szUrl
, CREATE_URL1
), "Expected %s, got %s\n", CREATE_URL1
, szUrl
);
687 HeapFree(GetProcessHeap(), 0, szUrl
);
689 memset(&urlComp
, 0, sizeof(urlComp
));
690 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
691 urlComp
.lpszScheme
= https
;
692 urlComp
.dwSchemeLength
= 0;
693 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
694 urlComp
.lpszHostName
= winehq
;
695 urlComp
.dwHostNameLength
= 0;
697 urlComp
.lpszUserName
= username
;
698 urlComp
.dwUserNameLength
= 0;
699 urlComp
.lpszPassword
= password
;
700 urlComp
.dwPasswordLength
= 0;
701 urlComp
.lpszUrlPath
= site_about
;
702 urlComp
.dwUrlPathLength
= 0;
703 urlComp
.lpszExtraInfo
= empty
;
704 urlComp
.dwExtraInfoLength
= 0;
705 len
= strlen(CREATE_URL8
);
706 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
707 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
708 ok(ret
, "Expected success\n");
709 ok(len
== strlen(CREATE_URL8
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8
), len
);
710 ok(!strcmp(szUrl
, CREATE_URL8
), "Expected %s, got %s\n", CREATE_URL8
, szUrl
);
712 HeapFree(GetProcessHeap(), 0, szUrl
);
714 memset(&urlComp
, 0, sizeof(urlComp
));
715 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
716 urlComp
.lpszScheme
= about
;
717 urlComp
.dwSchemeLength
= 5;
718 urlComp
.lpszUrlPath
= blank
;
719 urlComp
.dwUrlPathLength
= 5;
720 len
= strlen(CREATE_URL9
);
721 len
++; /* work around bug in native wininet */
722 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
723 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
724 ok(ret
, "Expected success\n");
725 ok(len
== strlen(CREATE_URL9
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9
), len
);
726 ok(!strcmp(szUrl
, CREATE_URL9
), "Expected %s, got %s\n", CREATE_URL9
, szUrl
);
728 HeapFree(GetProcessHeap(), 0, szUrl
);
730 memset(&urlComp
, 0, sizeof(urlComp
));
731 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
732 urlComp
.lpszScheme
= about
;
733 urlComp
.lpszHostName
= host
;
734 urlComp
.lpszUrlPath
= blank
;
735 len
= strlen(CREATE_URL10
);
736 len
++; /* work around bug in native wininet */
737 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
738 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
739 ok(ret
, "Expected success\n");
740 ok(len
== strlen(CREATE_URL10
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10
), len
);
741 ok(!strcmp(szUrl
, CREATE_URL10
), "Expected %s, got %s\n", CREATE_URL10
, szUrl
);
743 HeapFree(GetProcessHeap(), 0, szUrl
);
745 memset(&urlComp
, 0, sizeof(urlComp
));
746 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
747 urlComp
.nPort
= 8080;
748 urlComp
.lpszScheme
= about
;
749 len
= strlen(CREATE_URL11
);
750 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
751 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
752 ok(ret
, "Expected success\n");
753 ok(len
== strlen(CREATE_URL11
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11
), len
);
754 ok(!strcmp(szUrl
, CREATE_URL11
), "Expected %s, got %s\n", CREATE_URL11
, szUrl
);
756 HeapFree(GetProcessHeap(), 0, szUrl
);
758 memset(&urlComp
, 0, sizeof(urlComp
));
759 urlComp
.dwStructSize
= sizeof(URL_COMPONENTS
);
760 urlComp
.lpszScheme
= http
;
761 urlComp
.dwSchemeLength
= 0;
762 urlComp
.nScheme
= INTERNET_SCHEME_HTTP
;
763 urlComp
.lpszHostName
= winehq
;
764 urlComp
.dwHostNameLength
= 0;
765 urlComp
.nPort
= 65535;
766 len
= strlen(CREATE_URL12
);
767 szUrl
= HeapAlloc(GetProcessHeap(), 0, ++len
);
768 ret
= InternetCreateUrlA(&urlComp
, ICU_ESCAPE
, szUrl
, &len
);
769 ok(ret
, "Expected success\n");
770 ok(len
== strlen(CREATE_URL12
), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12
), len
);
771 ok(!strcmp(szUrl
, CREATE_URL12
), "Expected %s, got %s\n", CREATE_URL12
, szUrl
);
773 HeapFree(GetProcessHeap(), 0, szUrl
);
778 InternetCrackUrl_test();
779 InternetCrackUrlW_test();
780 InternetCreateUrlA_test();