2 * Copyright 2008 Hans Leidekker
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 static WCHAR empty
[] = {0};
29 static WCHAR ftp
[] = {'f','t','p',0};
30 static WCHAR http
[] = {'h','t','t','p',0};
31 static WCHAR winehq
[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
32 static WCHAR username
[] = {'u','s','e','r','n','a','m','e',0};
33 static WCHAR password
[] = {'p','a','s','s','w','o','r','d',0};
34 static WCHAR about
[] = {'/','s','i','t','e','/','a','b','o','u','t',0};
35 static WCHAR query
[] = {'?','q','u','e','r','y',0};
36 static WCHAR escape
[] = {' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>',
37 '?','@','[','\\',']','^','_','`','{','|','}','~',0};
38 static WCHAR escape2
[] = {'\r',0x1f,' ','\n',0x7f,'\r','\n',0};
39 static WCHAR escape3
[] = {'?','t','e','x','t','=',0xfb00,0};
40 static WCHAR escape4
[] = {'/','t','e','x','t','=',0xfb00,0};
42 static const WCHAR url1
[] = L
"http://username:password@www.winehq.org/site/about?query";
43 static const WCHAR url2
[] = L
"http://username:";
44 static const WCHAR url3
[] = L
"http://www.winehq.org/site/about?query";
45 static const WCHAR url4
[] = L
"http://";
46 static const WCHAR url5
[] = L
"ftp://username:password@www.winehq.org:80/site/about?query";
47 static const WCHAR url6
[] = L
"http://username:password@www.winehq.org:42/site/about?query";
48 static const WCHAR url7
[] = L
"http://username:password@www.winehq.org/site/about%20!%22%23$%25&'()"
49 "*+,-./:;%3C=%3E?@%5B%5C%5D%5E_%60%7B%7C%7D%7E";
50 static const WCHAR url8
[] = L
"http://username:password@www.winehq.org:0/site/about?query";
51 static const WCHAR url9
[] = L
"http://username:password@www.winehq.org:80/site/about?query";
52 static const WCHAR url10
[] = L
"https://username:password@www.winehq.org:443/site/about?query";
53 static const WCHAR url11
[] = L
"http://example.net/path?var1=example@example.com&var2=x&var3=y";
54 static const WCHAR url12
[] = L
"https://tools.google.com/service/update2?w=3:BxDHoWy8ezM";
55 static const WCHAR url13
[] = L
"http://winehq.o g/path with spaces";
56 static const WCHAR url14
[] = L
"http://www.winehq.org/test";
57 static const WCHAR url15
[] = L
"http://winehq.org:65536";
58 static const WCHAR url16
[] = L
"http://winehq.org:0";
59 static const WCHAR url17
[] = L
"http://winehq.org:";
60 static const WCHAR url18
[] = L
"http://%0D%1F%20%0A%7F%0D%0A";
61 static const WCHAR url19
[] = L
"http://?text=\xfb00";
62 static const WCHAR url20
[] = L
"http:///text=\xfb00";
63 static const WCHAR url21
[] = L
"https://nba2k19-ws.2ksports.com:19133/nba/v4/Accounts/get_account?x=3789526775265663876";
65 static const WCHAR url_k1
[] = L
"http://username:password@www.winehq.org/site/about";
66 static const WCHAR url_k2
[] = L
"http://www.winehq.org";
67 static const WCHAR url_k3
[] = L
"https://www.winehq.org/post?";
68 static const WCHAR url_k4
[] = L
"HTTP:www.winehq.org";
69 static const WCHAR url_k5
[] = L
"http:/www.winehq.org";
70 static const WCHAR url_k6
[] = L
"www.winehq.org";
71 static const WCHAR url_k7
[] = L
"www";
72 static const WCHAR url_k8
[] = L
"http";
73 static const WCHAR url_k9
[] = L
"http://winehq?";
74 static const WCHAR url_k10
[] = L
"http://winehq/post;a";
76 static void fill_url_components( URL_COMPONENTS
*uc
)
78 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
79 uc
->lpszScheme
= http
;
80 uc
->dwSchemeLength
= lstrlenW( uc
->lpszScheme
);
81 uc
->nScheme
= INTERNET_SCHEME_HTTP
;
82 uc
->lpszHostName
= winehq
;
83 uc
->dwHostNameLength
= lstrlenW( uc
->lpszHostName
);
85 uc
->lpszUserName
= username
;
86 uc
->dwUserNameLength
= lstrlenW( uc
->lpszUserName
);
87 uc
->lpszPassword
= password
;
88 uc
->dwPasswordLength
= lstrlenW( uc
->lpszPassword
);
89 uc
->lpszUrlPath
= about
;
90 uc
->dwUrlPathLength
= lstrlenW( uc
->lpszUrlPath
);
91 uc
->lpszExtraInfo
= query
;
92 uc
->dwExtraInfoLength
= lstrlenW( uc
->lpszExtraInfo
);
95 static void WinHttpCreateUrl_test( void )
102 /* NULL components */
104 SetLastError( 0xdeadbeef );
105 ret
= WinHttpCreateUrl( NULL
, 0, NULL
, &len
);
106 ok( !ret
, "expected failure\n" );
107 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
108 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
110 /* zero'ed components */
111 memset( &uc
, 0, sizeof(URL_COMPONENTS
) );
112 SetLastError( 0xdeadbeef );
113 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
114 ok( !ret
, "expected failure\n" );
115 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
116 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
118 /* valid components, NULL url, NULL length */
119 fill_url_components( &uc
);
120 SetLastError( 0xdeadbeef );
121 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, NULL
);
122 ok( !ret
, "expected failure\n" );
123 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
125 /* valid components, NULL url, insufficient length */
127 SetLastError( 0xdeadbeef );
128 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
129 ok( !ret
, "expected failure\n" );
130 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
131 ok( len
== 57, "expected len 57 got %u\n", len
);
133 /* valid components, NULL url, sufficient length */
134 SetLastError( 0xdeadbeef );
136 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
137 err
= GetLastError();
138 ok( !ret
, "expected failure\n" );
139 ok( err
== ERROR_INVALID_PARAMETER
|| broken(err
== ERROR_INSUFFICIENT_BUFFER
) /* < win7 */,
140 "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
141 ok( len
== 256 || broken(len
== 57) /* < win7 */, "expected len 256 got %u\n", len
);
143 /* correct size, NULL url */
144 fill_url_components( &uc
);
145 SetLastError( 0xdeadbeef );
146 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
147 err
= GetLastError();
148 ok( !ret
, "expected failure\n" );
149 ok( err
== ERROR_INVALID_PARAMETER
|| broken(err
== ERROR_INSUFFICIENT_BUFFER
) /* < win7 */,
150 "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
151 ok( len
== 256 || broken(len
== 57) /* < win7 */, "expected len 256 got %u\n", len
);
153 /* valid components, allocated url, short length */
154 SetLastError( 0xdeadbeef );
155 url
= HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR
) );
158 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
159 ok( !ret
, "expected failure\n" );
160 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
161 ok( len
== 57, "expected len 57 got %u\n", len
);
163 /* allocated url, NULL scheme */
164 SetLastError( 0xdeadbeef );
165 uc
.lpszScheme
= NULL
;
168 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
169 ok( ret
, "expected success\n" );
170 ok( GetLastError() == ERROR_SUCCESS
|| broken(GetLastError() == 0xdeadbeef) /* < win7 */,
171 "expected ERROR_SUCCESS got %u\n", GetLastError() );
172 ok( len
== 56, "expected len 56 got %u\n", len
);
173 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
175 /* allocated url, 0 scheme */
176 fill_url_components( &uc
);
180 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
181 ok( ret
, "expected success\n" );
182 ok( len
== 56, "expected len 56 got %u\n", len
);
184 /* valid components, allocated url */
185 fill_url_components( &uc
);
188 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
189 ok( ret
, "expected success\n" );
190 ok( len
== 56, "expected len 56 got %d\n", len
);
191 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
193 /* valid username, NULL password */
194 fill_url_components( &uc
);
195 uc
.lpszPassword
= NULL
;
198 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
199 ok( ret
, "expected success\n" );
201 /* valid username, empty password */
202 fill_url_components( &uc
);
203 uc
.lpszPassword
= empty
;
206 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
207 ok( ret
, "expected success\n" );
208 ok( len
== 56, "expected len 56 got %u\n", len
);
209 ok( !lstrcmpW( url
, url2
), "url doesn't match\n" );
211 /* valid password, NULL username */
212 fill_url_components( &uc
);
213 SetLastError( 0xdeadbeef );
214 uc
.lpszUserName
= NULL
;
217 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
218 ok( !ret
, "expected failure\n" );
219 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
221 /* valid password, empty username */
222 fill_url_components( &uc
);
223 uc
.lpszUserName
= empty
;
226 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
227 ok( ret
, "expected success\n");
229 /* NULL username, NULL password */
230 fill_url_components( &uc
);
231 uc
.lpszUserName
= NULL
;
232 uc
.lpszPassword
= NULL
;
235 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
236 ok( ret
, "expected success\n" );
237 ok( len
== 38, "expected len 38 got %u\n", len
);
238 ok( !lstrcmpW( url
, url3
), "url doesn't match\n" );
240 /* empty username, empty password */
241 fill_url_components( &uc
);
242 uc
.lpszUserName
= empty
;
243 uc
.lpszPassword
= empty
;
246 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
247 ok( ret
, "expected success\n" );
248 ok( len
== 56, "expected len 56 got %u\n", len
);
249 ok( !lstrcmpW( url
, url4
), "url doesn't match\n" );
251 /* nScheme has lower precedence than lpszScheme */
252 fill_url_components( &uc
);
254 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
257 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
258 ok( ret
, "expected success\n" );
259 ok( len
== lstrlenW( url5
), "expected len %d got %u\n", lstrlenW( url5
) + 1, len
);
260 ok( !lstrcmpW( url
, url5
), "url doesn't match\n" );
262 /* non-standard port */
263 uc
.lpszScheme
= http
;
264 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
268 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
269 ok( ret
, "expected success\n" );
270 ok( len
== 59, "expected len 59 got %u\n", len
);
271 ok( !lstrcmpW( url
, url6
), "url doesn't match\n" );
273 /* escape extra info */
274 fill_url_components( &uc
);
275 uc
.lpszExtraInfo
= escape
;
276 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
279 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
280 ok( ret
, "expected success\n" );
281 ok( len
== 113, "expected len 113 got %u\n", len
);
282 ok( !lstrcmpW( url
, url7
), "url doesn't match %s\n", wine_dbgstr_w(url
) );
284 /* escape extra info */
285 memset( &uc
, 0, sizeof(uc
) );
286 uc
.dwStructSize
= sizeof(uc
);
287 uc
.lpszExtraInfo
= escape2
;
288 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
291 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
292 ok( ret
, "expected success\n" );
293 ok( len
== lstrlenW(url18
), "expected len %u got %u\n", lstrlenW(url18
), len
);
294 ok( !lstrcmpW( url
, url18
), "url doesn't match\n" );
296 /* extra info with Unicode characters */
297 memset( &uc
, 0, sizeof(uc
) );
298 uc
.dwStructSize
= sizeof(uc
);
299 uc
.lpszExtraInfo
= escape3
;
300 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
303 SetLastError( 0xdeadbeef );
304 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
305 err
= GetLastError();
306 ok( !ret
, "expected failure\n" );
307 ok( err
== ERROR_INVALID_PARAMETER
, "got %u\n", err
);
309 /* extra info with Unicode characters, no ICU_ESCAPE */
310 memset( &uc
, 0, sizeof(uc
) );
311 uc
.dwStructSize
= sizeof(uc
);
312 uc
.lpszExtraInfo
= escape3
;
313 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
316 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
317 ok( ret
|| broken(!ret
) /* < win7 */, "expected success\n" );
320 ok( len
== lstrlenW(url19
), "expected len %u got %u\n", lstrlenW(url19
), len
);
321 ok( !lstrcmpW( url
, url19
), "url doesn't match %s\n", wine_dbgstr_w(url
) );
325 memset( &uc
, 0, sizeof(uc
) );
326 uc
.dwStructSize
= sizeof(uc
);
327 uc
.lpszUrlPath
= escape2
;
328 uc
.dwUrlPathLength
= lstrlenW( uc
.lpszUrlPath
);
331 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
332 ok( ret
, "expected success\n" );
333 ok( len
== lstrlenW(url18
), "expected len %u got %u\n", lstrlenW(url18
), len
);
334 ok( !lstrcmpW( url
, url18
), "url doesn't match\n" );
336 /* path with Unicode characters */
337 memset( &uc
, 0, sizeof(uc
) );
338 uc
.dwStructSize
= sizeof(uc
);
339 uc
.lpszUrlPath
= escape4
;
340 uc
.dwUrlPathLength
= lstrlenW( uc
.lpszUrlPath
);
343 SetLastError( 0xdeadbeef );
344 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
345 err
= GetLastError();
346 ok( !ret
, "expected failure\n" );
347 ok( err
== ERROR_INVALID_PARAMETER
, "got %u\n", err
);
349 /* path with Unicode characters, no ICU_ESCAPE */
350 memset( &uc
, 0, sizeof(uc
) );
351 uc
.dwStructSize
= sizeof(uc
);
352 uc
.lpszUrlPath
= escape4
;
353 uc
.dwUrlPathLength
= lstrlenW( uc
.lpszUrlPath
);
356 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
357 ok( ret
|| broken(!ret
) /* < win7 */, "expected success\n" );
360 ok( len
== lstrlenW(url20
), "expected len %u got %u\n", lstrlenW(url20
), len
);
361 ok( !lstrcmpW( url
, url20
), "url doesn't match %s\n", wine_dbgstr_w(url
) );
364 /* NULL lpszScheme, 0 nScheme and nPort */
365 fill_url_components( &uc
);
366 uc
.lpszScheme
= NULL
;
367 uc
.dwSchemeLength
= 0;
372 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
373 ok( ret
, "expected success\n" );
374 ok( len
== 58, "expected len 58 got %u\n", len
);
375 ok( !lstrcmpW( url
, url8
), "url doesn't match\n" );
377 HeapFree( GetProcessHeap(), 0, url
);
380 static void reset_url_components( URL_COMPONENTS
*uc
)
382 memset( uc
, 0, sizeof(URL_COMPONENTS
) );
383 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
384 uc
->dwSchemeLength
= ~0u;
385 uc
->dwHostNameLength
= 1;
387 uc
->dwUserNameLength
= ~0u;
388 uc
->dwPasswordLength
= ~0u;
389 uc
->dwUrlPathLength
= ~0u;
390 uc
->dwExtraInfoLength
= ~0u;
393 static void WinHttpCrackUrl_test( void )
396 WCHAR scheme
[20], user
[20], pass
[20], host
[40], path
[80], extra
[40];
400 /* buffers of sufficient length */
401 scheme
[0] = user
[0] = pass
[0] = host
[0] = path
[0] = extra
[0] = 0;
403 uc
.dwStructSize
= sizeof(URL_COMPONENTS
);
405 uc
.lpszScheme
= scheme
;
406 uc
.dwSchemeLength
= 20;
407 uc
.lpszUserName
= user
;
408 uc
.dwUserNameLength
= 20;
409 uc
.lpszPassword
= pass
;
410 uc
.dwPasswordLength
= 20;
411 uc
.lpszHostName
= host
;
412 uc
.dwHostNameLength
= 20;
414 uc
.lpszUrlPath
= path
;
415 uc
.dwUrlPathLength
= 40;
416 uc
.lpszExtraInfo
= extra
;
417 uc
.dwExtraInfoLength
= 20;
419 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
420 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
421 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme: %u\n", uc
.nScheme
);
422 ok( !memcmp( uc
.lpszScheme
, http
, sizeof(http
) ), "unexpected scheme: %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
423 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
424 ok( !memcmp( uc
.lpszUserName
, username
, sizeof(username
) ), "unexpected username: %s\n", wine_dbgstr_w(uc
.lpszUserName
) );
425 ok( uc
.dwUserNameLength
== 8, "unexpected username length: %u\n", uc
.dwUserNameLength
);
426 ok( !memcmp( uc
.lpszPassword
, password
, sizeof(password
) ), "unexpected password: %s\n", wine_dbgstr_w(uc
.lpszPassword
) );
427 ok( uc
.dwPasswordLength
== 8, "unexpected password length: %u\n", uc
.dwPasswordLength
);
428 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected hostname: %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
429 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length: %u\n", uc
.dwHostNameLength
);
430 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
431 ok( !memcmp( uc
.lpszUrlPath
, about
, sizeof(about
) ), "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
432 ok( uc
.dwUrlPathLength
== 11, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
433 ok( !memcmp( uc
.lpszExtraInfo
, query
, sizeof(query
) ), "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
434 ok( uc
.dwExtraInfoLength
== 6, "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
436 /* buffers of insufficient length */
437 uc
.dwSchemeLength
= 1;
438 uc
.dwHostNameLength
= 1;
439 uc
.dwUrlPathLength
= 40; /* sufficient */
440 SetLastError( 0xdeadbeef );
441 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
442 error
= GetLastError();
443 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
444 ok( error
== ERROR_INSUFFICIENT_BUFFER
, "got %u, expected ERROR_INSUFFICIENT_BUFFER\n", error
);
445 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
446 ok( uc
.dwHostNameLength
== 15, "unexpected hostname length: %u\n", uc
.dwHostNameLength
);
447 ok( uc
.dwUrlPathLength
== 11, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
450 reset_url_components( &uc
);
451 SetLastError( 0xdeadbeef );
452 ret
= WinHttpCrackUrl( url_k1
, 0, 0, &uc
);
453 error
= GetLastError();
454 ok( ret
, "WinHttpCrackUrl failed le=%u\n", error
);
455 ok( error
== ERROR_SUCCESS
|| broken(error
== ERROR_INVALID_PARAMETER
) /* < win7 */,
456 "got %u, expected ERROR_SUCCESS\n", error
);
457 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
458 ok( uc
.lpszScheme
== url_k1
,"unexpected scheme\n" );
459 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
460 ok( uc
.lpszUserName
== url_k1
+ 7, "unexpected username\n" );
461 ok( uc
.dwUserNameLength
== 8, "unexpected username length\n" );
462 ok( uc
.lpszPassword
== url_k1
+ 16, "unexpected password\n" );
463 ok( uc
.dwPasswordLength
== 8, "unexpected password length\n" );
464 ok( uc
.lpszHostName
== url_k1
+ 25, "unexpected hostname\n" );
465 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
466 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
467 ok( uc
.lpszUrlPath
== url_k1
+ 39, "unexpected path\n" );
468 ok( uc
.dwUrlPathLength
== 11, "unexpected path length\n" );
469 ok( uc
.lpszExtraInfo
== url_k1
+ 50, "unexpected extra info\n" );
470 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
472 reset_url_components( &uc
);
473 uc
.dwSchemeLength
= uc
.dwHostNameLength
= uc
.dwUserNameLength
= 1;
474 uc
.dwPasswordLength
= uc
.dwUrlPathLength
= uc
.dwExtraInfoLength
= 1;
475 ret
= WinHttpCrackUrl( url_k2
, 0, 0,&uc
);
476 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
477 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
478 ok( uc
.lpszScheme
== url_k2
, "unexpected scheme\n" );
479 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
480 ok( uc
.lpszUserName
== NULL
,"unexpected username\n" );
481 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
482 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
483 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
484 ok( uc
.lpszHostName
== url_k2
+ 7, "unexpected hostname\n" );
485 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
486 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
487 ok( uc
.lpszUrlPath
== url_k2
+ 21, "unexpected path\n" );
488 ok( uc
.dwUrlPathLength
== 0, "unexpected path length\n" );
489 ok( uc
.lpszExtraInfo
== url_k2
+ 21, "unexpected extra info\n" );
490 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
492 reset_url_components( &uc
);
493 ret
= WinHttpCrackUrl( url_k3
, 0, 0, &uc
);
494 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
495 ok( uc
.nScheme
== INTERNET_SCHEME_HTTPS
, "unexpected scheme\n" );
496 ok( uc
.lpszScheme
== url_k3
, "unexpected scheme\n" );
497 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length\n" );
498 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
499 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
500 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
501 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
502 ok( uc
.lpszHostName
== url_k3
+ 8, "unexpected hostname\n" );
503 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
504 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
505 ok( uc
.lpszUrlPath
== url_k3
+ 22, "unexpected path\n" );
506 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
507 ok( uc
.lpszExtraInfo
== url_k3
+ 27, "unexpected extra info\n" );
508 ok( uc
.dwExtraInfoLength
== 1, "unexpected extra info length\n" );
511 reset_url_components( &uc
);
512 SetLastError( 0xdeadbeef );
513 ret
= WinHttpCrackUrl( url_k4
, 0, 0, &uc
);
514 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
515 error
= GetLastError();
516 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
518 reset_url_components( &uc
);
519 SetLastError( 0xdeadbeef );
520 ret
= WinHttpCrackUrl( url_k5
, 0, 0, &uc
);
521 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
522 error
= GetLastError();
523 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
525 reset_url_components( &uc
);
526 SetLastError( 0xdeadbeef );
527 ret
= WinHttpCrackUrl( url_k6
, 0, 0, &uc
);
528 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
529 error
= GetLastError();
530 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
532 reset_url_components( &uc
);
533 SetLastError( 0xdeadbeef );
534 ret
= WinHttpCrackUrl( url_k7
, 0, 0, &uc
);
535 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
536 error
= GetLastError();
537 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
539 reset_url_components( &uc
);
540 SetLastError( 0xdeadbeef );
541 ret
= WinHttpCrackUrl( url_k8
, 0, 0, &uc
);
542 error
= GetLastError();
543 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
544 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
546 reset_url_components( &uc
);
547 ret
= WinHttpCrackUrl( url_k9
, 0, 0, &uc
);
548 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
549 ok( uc
.lpszUrlPath
== url_k9
+ 14 || broken(uc
.lpszUrlPath
== url_k9
+ 13) /* win8 */,
550 "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
551 ok( uc
.dwUrlPathLength
== 0, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
552 ok( uc
.lpszExtraInfo
== url_k9
+ 14 || broken(uc
.lpszExtraInfo
== url_k9
+ 13) /* win8 */,
553 "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
554 ok( uc
.dwExtraInfoLength
== 0 || broken(uc
.dwExtraInfoLength
== 1) /* win8 */,
555 "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
557 reset_url_components( &uc
);
558 ret
= WinHttpCrackUrl( url_k10
, 0, 0, &uc
);
559 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
560 ok( uc
.lpszUrlPath
== url_k10
+ 13, "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
561 ok( uc
.dwUrlPathLength
== 7, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
562 ok( uc
.lpszExtraInfo
== url_k10
+ 20, "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
563 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
565 reset_url_components( &uc
);
566 SetLastError( 0xdeadbeef );
567 ret
= WinHttpCrackUrl( url4
, 0, 0, &uc
);
568 error
= GetLastError();
569 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
570 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
572 reset_url_components( &uc
);
573 SetLastError( 0xdeadbeef );
574 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
575 error
= GetLastError();
576 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
577 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
579 SetLastError( 0xdeadbeef );
580 ret
= WinHttpCrackUrl( url1
, 0, 0, NULL
);
581 error
= GetLastError();
582 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
583 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
585 SetLastError( 0xdeadbeef );
586 ret
= WinHttpCrackUrl( NULL
, 0, 0, &uc
);
587 error
= GetLastError();
588 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
589 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
591 /* decoding without buffers */
592 reset_url_components( &uc
);
593 SetLastError(0xdeadbeef);
594 ret
= WinHttpCrackUrl( url7
, 0, ICU_DECODE
, &uc
);
595 error
= GetLastError();
596 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
597 ok( error
== ERROR_INVALID_PARAMETER
, "got %u, expected ERROR_INVALID_PARAMETER\n", error
);
599 /* decoding with buffers */
600 uc
.lpszScheme
= scheme
;
601 uc
.dwSchemeLength
= 20;
602 uc
.lpszUserName
= user
;
603 uc
.dwUserNameLength
= 20;
604 uc
.lpszPassword
= pass
;
605 uc
.dwPasswordLength
= 20;
606 uc
.lpszHostName
= host
;
607 uc
.dwHostNameLength
= 20;
609 uc
.lpszUrlPath
= path
;
610 uc
.dwUrlPathLength
= 80;
611 uc
.lpszExtraInfo
= extra
;
612 uc
.dwExtraInfoLength
= 40;
615 ret
= WinHttpCrackUrl( url7
, 0, ICU_DECODE
, &uc
);
616 ok( ret
, "WinHttpCrackUrl failed %u\n", GetLastError() );
617 ok( !memcmp( uc
.lpszUrlPath
+ 11, escape
, 21 * sizeof(WCHAR
) ), "unexpected path\n" );
618 ok( uc
.dwUrlPathLength
== 32, "unexpected path length %u\n", uc
.dwUrlPathLength
);
619 ok( !memcmp( uc
.lpszExtraInfo
, escape
+ 21, 12 * sizeof(WCHAR
) ), "unexpected extra info\n" );
620 ok( uc
.dwExtraInfoLength
== 12, "unexpected extra info length %u\n", uc
.dwExtraInfoLength
);
622 /* Urls with specified port numbers */
623 /* decoding with buffers */
624 uc
.lpszScheme
= scheme
;
625 uc
.dwSchemeLength
= 20;
626 uc
.lpszUserName
= user
;
627 uc
.dwUserNameLength
= 20;
628 uc
.lpszPassword
= pass
;
629 uc
.dwPasswordLength
= 20;
630 uc
.lpszHostName
= host
;
631 uc
.dwHostNameLength
= 20;
633 uc
.lpszUrlPath
= path
;
634 uc
.dwUrlPathLength
= 40;
635 uc
.lpszExtraInfo
= extra
;
636 uc
.dwExtraInfoLength
= 20;
639 ret
= WinHttpCrackUrl( url6
, 0, 0, &uc
);
640 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
641 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected host name: %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
642 ok( uc
.dwHostNameLength
== 14, "unexpected host name length: %d\n", uc
.dwHostNameLength
);
643 ok( uc
.nPort
== 42, "unexpected port: %u\n", uc
.nPort
);
645 /* decoding without buffers */
646 reset_url_components( &uc
);
647 ret
= WinHttpCrackUrl( url8
, 0, 0, &uc
);
648 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
649 ok( uc
.nPort
== 0, "unexpected port: %u\n", uc
.nPort
);
651 reset_url_components( &uc
);
652 ret
= WinHttpCrackUrl( url9
, 0, 0, &uc
);
653 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
654 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
656 reset_url_components( &uc
);
657 ret
= WinHttpCrackUrl( url10
, 0, 0, &uc
);
658 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
659 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
661 reset_url_components( &uc
);
662 SetLastError( 0xdeadbeef );
663 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
664 error
= GetLastError();
665 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
666 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
668 reset_url_components( &uc
);
669 SetLastError( 0xdeadbeef );
670 ret
= WinHttpCrackUrl( http
, 0, 0, &uc
);
671 error
= GetLastError();
672 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
673 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
675 reset_url_components( &uc
);
676 ret
= WinHttpCrackUrl( url11
, 0, 0, &uc
);
677 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
678 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
679 ok( uc
.lpszScheme
== url11
,"unexpected scheme\n" );
680 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
681 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
682 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
683 ok( uc
.lpszHostName
== url11
+ 7, "unexpected hostname\n" );
684 ok( uc
.dwHostNameLength
== 11, "unexpected hostname length\n" );
685 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
686 ok( uc
.lpszUrlPath
== url11
+ 18, "unexpected path\n" );
687 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
688 ok( uc
.lpszExtraInfo
== url11
+ 23, "unexpected extra info\n" );
689 ok( uc
.dwExtraInfoLength
== 39, "unexpected extra info length\n" );
691 uc
.lpszScheme
= scheme
;
692 uc
.dwSchemeLength
= 20;
693 uc
.lpszHostName
= host
;
694 uc
.dwHostNameLength
= 20;
695 uc
.lpszUserName
= NULL
;
696 uc
.dwUserNameLength
= 0;
697 uc
.lpszPassword
= NULL
;
698 uc
.dwPasswordLength
= 0;
699 uc
.lpszUrlPath
= path
;
700 uc
.dwUrlPathLength
= 40;
701 uc
.lpszExtraInfo
= NULL
;
702 uc
.dwExtraInfoLength
= 0;
704 ret
= WinHttpCrackUrl( url12
, 0, ICU_DECODE
, &uc
);
705 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
707 uc
.lpszScheme
= scheme
;
708 uc
.dwSchemeLength
= 20;
709 uc
.lpszHostName
= host
;
710 uc
.dwHostNameLength
= 20;
711 uc
.lpszUserName
= NULL
;
712 uc
.dwUserNameLength
= 0;
713 uc
.lpszPassword
= NULL
;
714 uc
.dwPasswordLength
= 0;
715 uc
.lpszUrlPath
= path
;
716 uc
.dwUrlPathLength
= 40;
717 uc
.lpszExtraInfo
= NULL
;
718 uc
.dwExtraInfoLength
= 0;
720 ret
= WinHttpCrackUrl( url13
, 0, ICU_ESCAPE
|ICU_DECODE
, &uc
);
721 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
722 ok( !lstrcmpW( uc
.lpszHostName
, L
"winehq.o g" ), "unexpected host name\n" );
723 ok( !lstrcmpW( uc
.lpszUrlPath
, L
"/path%20with%20spaces" ), "unexpected path\n" );
724 ok( uc
.dwUrlPathLength
== lstrlenW(L
"/path%20with%20spaces"), "got %u\n", uc
.dwUrlPathLength
);
726 uc
.dwStructSize
= sizeof(uc
);
727 uc
.lpszScheme
= NULL
;
728 uc
.dwSchemeLength
= 0;
730 uc
.lpszHostName
= NULL
;
731 uc
.dwHostNameLength
= ~0u;
733 uc
.lpszUserName
= NULL
;
734 uc
.dwUserNameLength
= ~0u;
735 uc
.lpszPassword
= NULL
;
736 uc
.dwPasswordLength
= ~0u;
737 uc
.lpszUrlPath
= NULL
;
738 uc
.dwUrlPathLength
= ~0u;
739 uc
.lpszExtraInfo
= NULL
;
740 uc
.dwExtraInfoLength
= ~0u;
741 ret
= WinHttpCrackUrl( url14
, 0, 0, &uc
);
742 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
743 ok( !uc
.lpszScheme
, "unexpected scheme %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
744 ok( !uc
.dwSchemeLength
, "unexpected length %u\n", uc
.dwSchemeLength
);
745 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme %u\n", uc
.nScheme
);
746 ok( !lstrcmpW( uc
.lpszHostName
, url14
+ 7 ), "unexpected hostname %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
747 ok( uc
.dwHostNameLength
== 14, "unexpected length %u\n", uc
.dwHostNameLength
);
748 ok( uc
.nPort
== 80, "unexpected port %u\n", uc
.nPort
);
749 ok( !uc
.lpszUserName
, "unexpected username\n" );
750 ok( !uc
.dwUserNameLength
, "unexpected length %u\n", uc
.dwUserNameLength
);
751 ok( !uc
.lpszPassword
, "unexpected password\n" );
752 ok( !uc
.dwPasswordLength
, "unexpected length %u\n", uc
.dwPasswordLength
);
753 ok( !lstrcmpW( uc
.lpszUrlPath
, url14
+ 21 ), "unexpected path %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
754 ok( uc
.dwUrlPathLength
== 5, "unexpected length %u\n", uc
.dwUrlPathLength
);
755 ok( !uc
.lpszExtraInfo
[0], "unexpected extra info %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
756 ok( uc
.dwExtraInfoLength
== 0, "unexpected length %u\n", uc
.dwExtraInfoLength
);
758 uc
.dwStructSize
= sizeof(uc
);
759 uc
.lpszScheme
= scheme
;
760 uc
.dwSchemeLength
= 0;
762 uc
.lpszHostName
= NULL
;
763 uc
.dwHostNameLength
= 0;
765 uc
.lpszUserName
= NULL
;
766 uc
.dwUserNameLength
= ~0u;
767 uc
.lpszPassword
= NULL
;
768 uc
.dwPasswordLength
= ~0u;
769 uc
.lpszUrlPath
= NULL
;
770 uc
.dwUrlPathLength
= 0;
771 uc
.lpszExtraInfo
= NULL
;
772 uc
.dwExtraInfoLength
= 0;
773 SetLastError( 0xdeadbeef );
774 ret
= WinHttpCrackUrl( url14
, 0, 0, &uc
);
775 error
= GetLastError();
776 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
777 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
778 ok( !lstrcmpW( uc
.lpszScheme
, http
), "unexpected scheme %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
779 ok( !uc
.dwSchemeLength
, "unexpected length %u\n", uc
.dwSchemeLength
);
780 ok( uc
.nScheme
== 0, "unexpected scheme %u\n", uc
.nScheme
);
781 ok( !uc
.lpszHostName
, "unexpected hostname %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
782 ok( uc
.dwHostNameLength
== 0, "unexpected length %u\n", uc
.dwHostNameLength
);
783 ok( uc
.nPort
== 0, "unexpected port %u\n", uc
.nPort
);
784 ok( !uc
.lpszUserName
, "unexpected username\n" );
785 ok( uc
.dwUserNameLength
== ~0u, "unexpected length %u\n", uc
.dwUserNameLength
);
786 ok( !uc
.lpszPassword
, "unexpected password\n" );
787 ok( uc
.dwPasswordLength
== ~0u, "unexpected length %u\n", uc
.dwPasswordLength
);
788 ok( !uc
.lpszUrlPath
, "unexpected path %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
789 ok( uc
.dwUrlPathLength
== 0, "unexpected length %u\n", uc
.dwUrlPathLength
);
790 ok( !uc
.lpszExtraInfo
, "unexpected extra info %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
791 ok( uc
.dwExtraInfoLength
== 0, "unexpected length %u\n", uc
.dwExtraInfoLength
);
793 reset_url_components( &uc
);
794 SetLastError( 0xdeadbeef );
795 ret
= WinHttpCrackUrl( url15
, 0, 0, &uc
);
796 error
= GetLastError();
797 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
798 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
800 reset_url_components( &uc
);
802 ret
= WinHttpCrackUrl( url16
, 0, 0, &uc
);
803 ok( ret
, "got %u\n", GetLastError() );
804 ok( !uc
.nPort
, "got %u\n", uc
.nPort
);
806 reset_url_components( &uc
);
808 ret
= WinHttpCrackUrl( url17
, 0, 0, &uc
);
809 ok( ret
, "got %u\n", GetLastError() );
810 todo_wine
ok( uc
.nPort
== 80, "got %u\n", uc
.nPort
);
812 memset( &uc
, 0, sizeof(uc
) );
813 uc
.dwStructSize
= sizeof(uc
);
814 uc
.lpszScheme
= scheme
;
815 uc
.dwSchemeLength
= ARRAY_SIZE(scheme
);
816 uc
.lpszHostName
= host
;
817 uc
.dwHostNameLength
= ARRAY_SIZE(host
);
818 uc
.lpszUrlPath
= path
;
819 uc
.dwUrlPathLength
= ARRAY_SIZE(path
);
820 ret
= WinHttpCrackUrl( url21
, 0, 0, &uc
);
821 ok( ret
, "got %u\n", GetLastError() );
822 ok( !lstrcmpW( uc
.lpszUrlPath
, url21
+ 37 ), "unexpected path %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
823 ok( uc
.dwUrlPathLength
== 50, "unexpected length %u\n", uc
.dwUrlPathLength
);
828 WinHttpCreateUrl_test();
829 WinHttpCrackUrl_test();