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
[] = {' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~',0};
38 static const WCHAR url1
[] =
39 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
40 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
41 static const WCHAR url2
[] =
42 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',
43 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
44 static const WCHAR url3
[] = {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':',0};
45 static const WCHAR url4
[] =
46 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
47 static const WCHAR url5
[] = {'h','t','t','p',':','/','/',0};
48 static const WCHAR url6
[] =
49 {'f','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
50 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','8','0','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
51 static const WCHAR url7
[] =
52 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
53 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','4','2','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
54 static const WCHAR url8
[] =
55 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
56 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',
57 '%','2','0','!','%','2','2','%','2','3','$','%','2','5','&','\'','(',')','*','+',',','-','.','/',':',';','%','3','C','=','%','3','E','?','@','%',
58 '5','B','%','5','C','%','5','D','%','5','E','_','%','6','0','%','7','B','%','7','C','%','7','D','%','7','E',0};
59 static const WCHAR url9
[] =
60 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
61 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','0','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
62 static const WCHAR url10
[] =
63 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
64 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','8','0','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
65 static const WCHAR url11
[] =
66 {'h','t','t','p','s',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
67 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','4','4','3','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
68 static const WCHAR url12
[] =
69 {'h','t','t','p',':','/','/','e','x','a','m','p','l','e','.','n','e','t','/','p','a','t','h','?','v','a','r','1','=','e','x','a','m','p','l','e','@','e','x','a','m','p','l','e','.','c','o','m','&','v','a','r','2','=','x','&','v','a','r','3','=','y', 0};
70 static const WCHAR url13
[] =
71 {'h','t','t','p','s',':','/','/','t','o','o','l','s','.','g','o','o','g','l','e','.','c','o','m','/','s','e','r','v','i','c','e','/','u','p','d','a','t','e','2','?','w','=','3',':','B','x','D','H','o','W','y','8','e','z','M',0};
72 static const WCHAR url14
[] =
73 {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o',' ','g','/','p','a','t','h',' ','w','i','t','h',' ','s','p','a','c','e','s',0};
75 static const WCHAR url_k1
[] =
76 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
77 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
78 static const WCHAR url_k2
[] =
79 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
80 static const WCHAR url_k3
[] =
81 {'h','t','t','p','s',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','p','o','s','t','?',0};
82 static const WCHAR url_k4
[] =
83 {'H','T','T','P',':','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
84 static const WCHAR url_k5
[] =
85 {'h','t','t','p',':','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
86 static const WCHAR url_k6
[] =
87 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
88 static const WCHAR url_k7
[] =
90 static const WCHAR url_k8
[] =
92 static const WCHAR url_k9
[] =
93 {'h','t','t','p',':','/','/','w','i','n','e','h','q','?',0};
94 static const WCHAR url_k10
[] =
95 {'h','t','t','p',':','/','/','w','i','n','e','h','q','/','p','o','s','t',';','a',0};
97 static void fill_url_components( URL_COMPONENTS
*uc
)
99 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
100 uc
->lpszScheme
= http
;
101 uc
->dwSchemeLength
= lstrlenW( uc
->lpszScheme
);
102 uc
->nScheme
= INTERNET_SCHEME_HTTP
;
103 uc
->lpszHostName
= winehq
;
104 uc
->dwHostNameLength
= lstrlenW( uc
->lpszHostName
);
106 uc
->lpszUserName
= username
;
107 uc
->dwUserNameLength
= lstrlenW( uc
->lpszUserName
);
108 uc
->lpszPassword
= password
;
109 uc
->dwPasswordLength
= lstrlenW( uc
->lpszPassword
);
110 uc
->lpszUrlPath
= about
;
111 uc
->dwUrlPathLength
= lstrlenW( uc
->lpszUrlPath
);
112 uc
->lpszExtraInfo
= query
;
113 uc
->dwExtraInfoLength
= lstrlenW( uc
->lpszExtraInfo
);
116 static void WinHttpCreateUrl_test( void )
123 /* NULL components */
125 SetLastError( 0xdeadbeef );
126 ret
= WinHttpCreateUrl( NULL
, 0, NULL
, &len
);
127 ok( !ret
, "expected failure\n" );
128 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
129 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
131 /* zero'ed components */
132 memset( &uc
, 0, sizeof(URL_COMPONENTS
) );
133 SetLastError( 0xdeadbeef );
134 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
135 ok( !ret
, "expected failure\n" );
136 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
137 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
139 /* valid components, NULL url, NULL length */
140 fill_url_components( &uc
);
141 SetLastError( 0xdeadbeef );
142 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, NULL
);
143 ok( !ret
, "expected failure\n" );
144 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
146 /* valid components, NULL url */
147 SetLastError( 0xdeadbeef );
148 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
149 ok( !ret
, "expected failure\n" );
150 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
151 GetLastError() == ERROR_INVALID_PARAMETER
,
152 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
154 /* correct size, NULL url */
155 fill_url_components( &uc
);
156 SetLastError( 0xdeadbeef );
157 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
158 ok( !ret
, "expected failure\n" );
159 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
160 GetLastError() == ERROR_INVALID_PARAMETER
,
161 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
163 /* valid components, allocated url, short length */
164 SetLastError( 0xdeadbeef );
165 url
= HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR
) );
168 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
169 ok( !ret
, "expected failure\n" );
170 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
171 ok( len
== 57, "expected len 57 got %u\n", len
);
173 /* allocated url, NULL scheme */
174 uc
.lpszScheme
= NULL
;
177 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
178 ok( ret
, "expected success\n" );
179 ok( len
== 56, "expected len 56 got %u\n", len
);
180 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
182 /* allocated url, 0 scheme */
183 fill_url_components( &uc
);
187 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
188 ok( ret
, "expected success\n" );
189 ok( len
== 56, "expected len 56 got %u\n", len
);
191 /* valid components, allocated url */
192 fill_url_components( &uc
);
195 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
196 ok( ret
, "expected success\n" );
197 ok( len
== 56, "expected len 56 got %d\n", len
);
198 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
200 /* valid username, NULL password */
201 fill_url_components( &uc
);
202 uc
.lpszPassword
= NULL
;
205 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
206 ok( ret
, "expected success\n" );
208 /* valid username, empty password */
209 fill_url_components( &uc
);
210 uc
.lpszPassword
= empty
;
213 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
214 ok( ret
, "expected success\n" );
215 ok( len
== 56, "expected len 56 got %u\n", len
);
216 ok( !lstrcmpW( url
, url3
), "url doesn't match\n" );
218 /* valid password, NULL username */
219 fill_url_components( &uc
);
220 SetLastError( 0xdeadbeef );
221 uc
.lpszUserName
= NULL
;
224 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
225 ok( !ret
, "expected failure\n" );
226 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
228 /* valid password, empty username */
229 fill_url_components( &uc
);
230 uc
.lpszUserName
= empty
;
233 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
234 ok( ret
, "expected success\n");
236 /* NULL username, NULL password */
237 fill_url_components( &uc
);
238 uc
.lpszUserName
= NULL
;
239 uc
.lpszPassword
= NULL
;
242 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
243 ok( ret
, "expected success\n" );
244 ok( len
== 38, "expected len 38 got %u\n", len
);
245 ok( !lstrcmpW( url
, url4
), "url doesn't match\n" );
247 /* empty username, empty password */
248 fill_url_components( &uc
);
249 uc
.lpszUserName
= empty
;
250 uc
.lpszPassword
= empty
;
253 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
254 ok( ret
, "expected success\n" );
255 ok( len
== 56, "expected len 56 got %u\n", len
);
256 ok( !lstrcmpW( url
, url5
), "url doesn't match\n" );
258 /* nScheme has lower precedence than lpszScheme */
259 fill_url_components( &uc
);
261 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
264 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
265 ok( ret
, "expected success\n" );
266 ok( len
== lstrlenW( url6
), "expected len %d got %u\n", lstrlenW( url6
) + 1, len
);
267 ok( !lstrcmpW( url
, url6
), "url doesn't match\n" );
269 /* non-standard port */
270 uc
.lpszScheme
= http
;
271 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
275 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
276 ok( ret
, "expected success\n" );
277 ok( len
== 59, "expected len 59 got %u\n", len
);
278 ok( !lstrcmpW( url
, url7
), "url doesn't match\n" );
280 /* escape extra info */
281 fill_url_components( &uc
);
282 uc
.lpszExtraInfo
= escape
;
283 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
286 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
287 ok( ret
, "expected success\n" );
288 ok( len
== 113, "expected len 113 got %u\n", len
);
289 ok( !lstrcmpW( url
, url8
), "url doesn't match\n" );
291 /* NULL lpszScheme, 0 nScheme and nPort */
292 fill_url_components( &uc
);
293 uc
.lpszScheme
= NULL
;
294 uc
.dwSchemeLength
= 0;
299 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
300 ok( ret
, "expected success\n" );
301 ok( len
== 58, "expected len 58 got %u\n", len
);
302 ok( !lstrcmpW( url
, url9
), "url doesn't match\n" );
304 HeapFree( GetProcessHeap(), 0, url
);
307 static void reset_url_components( URL_COMPONENTS
*uc
)
309 memset( uc
, 0, sizeof(URL_COMPONENTS
) );
310 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
311 uc
->dwSchemeLength
= ~0u;
312 uc
->dwHostNameLength
= ~0u;
314 uc
->dwUserNameLength
= ~0u;
315 uc
->dwPasswordLength
= ~0u;
316 uc
->dwUrlPathLength
= ~0u;
317 uc
->dwExtraInfoLength
= ~0u;
320 static void WinHttpCrackUrl_test( void )
322 static const WCHAR hostnameW
[] =
323 {'w','i','n','e','h','q','.','o',' ','g',0};
324 static const WCHAR pathW
[] =
325 {'/','p','a','t','h','%','2','0','w','i','t','h','%','2','0','s','p','a','c','e','s',0};
327 WCHAR scheme
[20], user
[20], pass
[20], host
[20], path
[80], extra
[40];
331 /* buffers of sufficient length */
339 uc
.dwStructSize
= sizeof(URL_COMPONENTS
);
341 uc
.lpszScheme
= scheme
;
342 uc
.dwSchemeLength
= 20;
343 uc
.lpszUserName
= user
;
344 uc
.dwUserNameLength
= 20;
345 uc
.lpszPassword
= pass
;
346 uc
.dwPasswordLength
= 20;
347 uc
.lpszHostName
= host
;
348 uc
.dwHostNameLength
= 20;
350 uc
.lpszUrlPath
= path
;
351 uc
.dwUrlPathLength
= 40;
352 uc
.lpszExtraInfo
= extra
;
353 uc
.dwExtraInfoLength
= 20;
355 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
356 ok( ret
, "WinHttpCrackUrl failed\n" );
357 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
358 ok( !memcmp( uc
.lpszScheme
, http
, sizeof(http
) ), "unexpected scheme\n" );
359 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
360 ok( !memcmp( uc
.lpszUserName
, username
, sizeof(username
) ), "unexpected username\n" );
361 ok( uc
.dwUserNameLength
== 8, "unexpected username length\n" );
362 ok( !memcmp( uc
.lpszPassword
, password
, sizeof(password
) ), "unexpected password\n" );
363 ok( uc
.dwPasswordLength
== 8, "unexpected password length\n" );
364 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected hostname\n" );
365 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
366 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
367 ok( !memcmp( uc
.lpszUrlPath
, about
, sizeof(about
) ), "unexpected path\n" );
368 ok( uc
.dwUrlPathLength
== 11, "unexpected path length\n" );
369 ok( !memcmp( uc
.lpszExtraInfo
, query
, sizeof(query
) ), "unexpected extra info\n" );
370 ok( uc
.dwExtraInfoLength
== 6, "unexpected extra info length\n" );
372 /* buffer of insufficient length */
374 uc
.dwSchemeLength
= 1;
376 SetLastError( 0xdeadbeef );
377 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
378 error
= GetLastError();
379 ok( !ret
, "WinHttpCrackUrl failed\n" );
380 ok( error
== ERROR_INSUFFICIENT_BUFFER
, "WinHttpCrackUrl failed\n" );
381 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
384 reset_url_components( &uc
);
385 ret
= WinHttpCrackUrl( url_k1
, 0, 0,&uc
);
387 ok( ret
, "WinHttpCrackUrl failed\n" );
388 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
389 ok( uc
.lpszScheme
== url_k1
,"unexpected scheme\n" );
390 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
391 ok( uc
.lpszUserName
== url_k1
+ 7, "unexpected username\n" );
392 ok( uc
.dwUserNameLength
== 8, "unexpected username length\n" );
393 ok( uc
.lpszPassword
== url_k1
+ 16, "unexpected password\n" );
394 ok( uc
.dwPasswordLength
== 8, "unexpected password length\n" );
395 ok( uc
.lpszHostName
== url_k1
+ 25, "unexpected hostname\n" );
396 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
397 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
398 ok( uc
.lpszUrlPath
== url_k1
+ 39, "unexpected path\n" );
399 ok( uc
.dwUrlPathLength
== 11, "unexpected path length\n" );
400 ok( uc
.lpszExtraInfo
== url_k1
+ 50, "unexpected extra info\n" );
401 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
403 reset_url_components( &uc
);
404 ret
= WinHttpCrackUrl( url_k2
, 0, 0,&uc
);
406 ok( ret
, "WinHttpCrackUrl failed\n" );
407 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
408 ok( uc
.lpszScheme
== url_k2
, "unexpected scheme\n" );
409 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
410 ok( uc
.lpszUserName
== NULL
,"unexpected username\n" );
411 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
412 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
413 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
414 ok( uc
.lpszHostName
== url_k2
+ 7, "unexpected hostname\n" );
415 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
416 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
417 ok( uc
.lpszUrlPath
== url_k2
+ 21, "unexpected path\n" );
418 ok( uc
.dwUrlPathLength
== 0, "unexpected path length\n" );
419 ok( uc
.lpszExtraInfo
== url_k2
+ 21, "unexpected extra info\n" );
420 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
422 reset_url_components( &uc
);
423 ret
= WinHttpCrackUrl( url_k3
, 0, 0, &uc
);
425 ok( ret
, "WinHttpCrackUrl failed\n" );
426 ok( uc
.nScheme
== INTERNET_SCHEME_HTTPS
, "unexpected scheme\n" );
427 ok( uc
.lpszScheme
== url_k3
, "unexpected scheme\n" );
428 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length\n" );
429 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
430 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
431 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
432 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
433 ok( uc
.lpszHostName
== url_k3
+ 8, "unexpected hostname\n" );
434 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
435 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
436 ok( uc
.lpszUrlPath
== url_k3
+ 22, "unexpected path\n" );
437 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
438 ok( uc
.lpszExtraInfo
== url_k3
+ 27, "unexpected extra info\n" );
439 ok( uc
.dwExtraInfoLength
== 1, "unexpected extra info length\n" );
442 reset_url_components( &uc
);
443 ret
= WinHttpCrackUrl( url_k4
, 0, 0, &uc
);
444 ok( !ret
, "WinHttpCrackUrl failed\n" );
446 reset_url_components( &uc
);
447 ret
= WinHttpCrackUrl( url_k5
, 0, 0, &uc
);
448 ok( !ret
, "WinHttpCrackUrl failed\n" );
450 reset_url_components( &uc
);
451 ret
= WinHttpCrackUrl( url_k6
, 0, 0, &uc
);
452 ok( !ret
, "WinHttpCrackUrl failed\n" );
454 reset_url_components( &uc
);
455 ret
= WinHttpCrackUrl( url_k7
, 0, 0, &uc
);
456 ok( !ret
, "WinHttpCrackUrl failed\n" );
458 reset_url_components( &uc
);
459 ret
= WinHttpCrackUrl( url_k8
, 0, 0, &uc
);
460 ok( !ret
, "WinHttpCrackUrl failed\n" );
462 reset_url_components( &uc
);
463 ret
= WinHttpCrackUrl( url_k9
, 0, 0, &uc
);
464 ok( ret
, "WinHttpCrackUrl failed\n" );
465 ok( uc
.lpszUrlPath
== url_k9
+ 14, "unexpected path\n" );
466 ok( uc
.dwUrlPathLength
== 0, "unexpected path length\n" );
467 ok( uc
.lpszExtraInfo
== url_k9
+ 14, "unexpected extra info\n" );
468 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
470 reset_url_components( &uc
);
471 ret
= WinHttpCrackUrl( url_k10
, 0, 0, &uc
);
472 ok( ret
, "WinHttpCrackUrl failed\n" );
473 ok( uc
.lpszUrlPath
== url_k10
+ 13, "unexpected path\n" );
474 ok( uc
.dwUrlPathLength
== 7, "unexpected path length\n" );
475 ok( uc
.lpszExtraInfo
== url_k10
+ 20, "unexpected extra info\n" );
476 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
478 reset_url_components( &uc
);
479 ret
= WinHttpCrackUrl( url5
, 0, 0, &uc
);
480 ok( !ret
, "WinHttpCrackUrl failed\n" );
482 reset_url_components( &uc
);
483 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
484 ok( !ret
, "WinHttpCrackUrl failed\n" );
486 ret
= WinHttpCrackUrl( url1
, 0, 0, NULL
);
487 ok( !ret
, "WinHttpCrackUrl failed\n" );
489 ret
= WinHttpCrackUrl( NULL
, 0, 0, &uc
);
490 ok( !ret
, "WinHttpCrackUrl failed\n" );
492 /* decoding without buffers */
493 reset_url_components( &uc
);
494 SetLastError(0xdeadbeef);
495 ret
= WinHttpCrackUrl( url8
, 0, ICU_DECODE
, &uc
);
496 error
= GetLastError();
497 ok( !ret
, "WinHttpCrackUrl failed\n" );
498 ok( error
== ERROR_INVALID_PARAMETER
, "WinHttpCrackUrl failed\n" );
500 /* decoding with buffers */
501 uc
.lpszScheme
= scheme
;
502 uc
.dwSchemeLength
= 20;
503 uc
.lpszUserName
= user
;
504 uc
.dwUserNameLength
= 20;
505 uc
.lpszPassword
= pass
;
506 uc
.dwPasswordLength
= 20;
507 uc
.lpszHostName
= host
;
508 uc
.dwHostNameLength
= 20;
510 uc
.lpszUrlPath
= path
;
511 uc
.dwUrlPathLength
= 80;
512 uc
.lpszExtraInfo
= extra
;
513 uc
.dwExtraInfoLength
= 40;
516 ret
= WinHttpCrackUrl( url8
, 0, ICU_DECODE
, &uc
);
517 ok( ret
, "WinHttpCrackUrl failed %u\n", GetLastError() );
518 ok( !memcmp( uc
.lpszUrlPath
+ 11, escape
, 21 * sizeof(WCHAR
) ), "unexpected path\n" );
519 ok( uc
.dwUrlPathLength
== 32, "unexpected path length %u\n", uc
.dwUrlPathLength
);
520 ok( !memcmp( uc
.lpszExtraInfo
, escape
+ 21, 12 * sizeof(WCHAR
) ), "unexpected extra info\n" );
521 ok( uc
.dwExtraInfoLength
== 12, "unexpected extra info length %u\n", uc
.dwExtraInfoLength
);
523 /* Urls with specified port numbers */
524 /* decoding with buffers */
525 uc
.lpszScheme
= scheme
;
526 uc
.dwSchemeLength
= 20;
527 uc
.lpszUserName
= user
;
528 uc
.dwUserNameLength
= 20;
529 uc
.lpszPassword
= pass
;
530 uc
.dwPasswordLength
= 20;
531 uc
.lpszHostName
= host
;
532 uc
.dwHostNameLength
= 20;
534 uc
.lpszUrlPath
= path
;
535 uc
.dwUrlPathLength
= 40;
536 uc
.lpszExtraInfo
= extra
;
537 uc
.dwExtraInfoLength
= 20;
540 ret
= WinHttpCrackUrl( url7
, 0, 0, &uc
);
541 ok( ret
, "WinHttpCrackUrl failed\n" );
542 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected host name: %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
543 ok( uc
.dwHostNameLength
== 14, "unexpected host name length: %d\n", uc
.dwHostNameLength
);
544 ok( uc
.nPort
== 42, "unexpected port: %u\n", uc
.nPort
);
546 /* decoding without buffers */
547 reset_url_components( &uc
);
548 ret
= WinHttpCrackUrl( url9
, 0, 0, &uc
);
549 ok( ret
, "WinHttpCrackUrl failed\n" );
550 ok( uc
.nPort
== 0, "unexpected port: %u\n", uc
.nPort
);
552 reset_url_components( &uc
);
553 ret
= WinHttpCrackUrl( url10
, 0, 0, &uc
);
554 ok( ret
, "WinHttpCrackUrl failed\n" );
555 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
557 reset_url_components( &uc
);
558 ret
= WinHttpCrackUrl( url11
, 0, 0, &uc
);
559 ok( ret
, "WinHttpCrackUrl failed\n" );
560 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
562 reset_url_components( &uc
);
563 SetLastError( 0xdeadbeef );
564 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
565 error
= GetLastError();
566 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
567 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
569 reset_url_components( &uc
);
570 SetLastError( 0xdeadbeef );
571 ret
= WinHttpCrackUrl( http
, 0, 0, &uc
);
572 error
= GetLastError();
573 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
574 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
576 reset_url_components( &uc
);
577 ret
= WinHttpCrackUrl( url12
, 0, 0, &uc
);
578 ok( ret
, "WinHttpCrackUrl failed\n" );
579 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
580 ok( uc
.lpszScheme
== url12
,"unexpected scheme\n" );
581 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
582 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
583 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
584 ok( uc
.lpszHostName
== url12
+ 7, "unexpected hostname\n" );
585 ok( uc
.dwHostNameLength
== 11, "unexpected hostname length\n" );
586 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
587 ok( uc
.lpszUrlPath
== url12
+ 18, "unexpected path\n" );
588 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
589 ok( uc
.lpszExtraInfo
== url12
+ 23, "unexpected extra info\n" );
590 ok( uc
.dwExtraInfoLength
== 39, "unexpected extra info length\n" );
592 uc
.lpszScheme
= scheme
;
593 uc
.dwSchemeLength
= 20;
594 uc
.lpszHostName
= host
;
595 uc
.dwHostNameLength
= 20;
596 uc
.lpszUserName
= NULL
;
597 uc
.dwUserNameLength
= 0;
598 uc
.lpszPassword
= NULL
;
599 uc
.dwPasswordLength
= 0;
600 uc
.lpszUrlPath
= path
;
601 uc
.dwUrlPathLength
= 40;
602 uc
.lpszExtraInfo
= NULL
;
603 uc
.dwExtraInfoLength
= 0;
605 ret
= WinHttpCrackUrl( url13
, 0, ICU_DECODE
, &uc
);
606 ok( ret
, "WinHttpCrackUrl failed\n" );
608 uc
.lpszScheme
= scheme
;
609 uc
.dwSchemeLength
= 20;
610 uc
.lpszHostName
= host
;
611 uc
.dwHostNameLength
= 20;
612 uc
.lpszUserName
= NULL
;
613 uc
.dwUserNameLength
= 0;
614 uc
.lpszPassword
= NULL
;
615 uc
.dwPasswordLength
= 0;
616 uc
.lpszUrlPath
= path
;
617 uc
.dwUrlPathLength
= 40;
618 uc
.lpszExtraInfo
= NULL
;
619 uc
.dwExtraInfoLength
= 0;
621 ret
= WinHttpCrackUrl( url14
, 0, ICU_ESCAPE
|ICU_DECODE
, &uc
);
622 ok( ret
, "WinHttpCrackUrl failed\n" );
623 ok( !lstrcmpW( uc
.lpszHostName
, hostnameW
), "unexpected host name\n" );
624 ok( !lstrcmpW( uc
.lpszUrlPath
, pathW
), "unexpected path\n" );
629 WinHttpCreateUrl_test();
630 WinHttpCrackUrl_test();