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};
71 static const WCHAR url_k1
[] =
72 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
73 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
74 static const WCHAR url_k2
[] =
75 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
76 static const WCHAR url_k3
[] =
77 {'h','t','t','p','s',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','p','o','s','t','?',0};
78 static const WCHAR url_k4
[] =
79 {'H','T','T','P',':','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
80 static const WCHAR url_k5
[] =
81 {'h','t','t','p',':','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
82 static const WCHAR url_k6
[] =
83 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
84 static const WCHAR url_k7
[] =
86 static const WCHAR url_k8
[] =
88 static const WCHAR url_k9
[] =
89 {'h','t','t','p',':','/','/','w','i','n','e','h','q','?',0};
90 static const WCHAR url_k10
[] =
91 {'h','t','t','p',':','/','/','w','i','n','e','h','q','/','p','o','s','t',';','a',0};
93 static const char *debugstr_w(LPCWSTR str
)
95 static char buf
[1024];
96 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
100 static void fill_url_components( URL_COMPONENTS
*uc
)
102 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
103 uc
->lpszScheme
= http
;
104 uc
->dwSchemeLength
= lstrlenW( uc
->lpszScheme
);
105 uc
->nScheme
= INTERNET_SCHEME_HTTP
;
106 uc
->lpszHostName
= winehq
;
107 uc
->dwHostNameLength
= lstrlenW( uc
->lpszHostName
);
109 uc
->lpszUserName
= username
;
110 uc
->dwUserNameLength
= lstrlenW( uc
->lpszUserName
);
111 uc
->lpszPassword
= password
;
112 uc
->dwPasswordLength
= lstrlenW( uc
->lpszPassword
);
113 uc
->lpszUrlPath
= about
;
114 uc
->dwUrlPathLength
= lstrlenW( uc
->lpszUrlPath
);
115 uc
->lpszExtraInfo
= query
;
116 uc
->dwExtraInfoLength
= lstrlenW( uc
->lpszExtraInfo
);
119 static void WinHttpCreateUrl_test( void )
126 /* NULL components */
128 SetLastError( 0xdeadbeef );
129 ret
= WinHttpCreateUrl( NULL
, 0, NULL
, &len
);
130 ok( !ret
, "expected failure\n" );
131 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
132 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
134 /* zero'ed components */
135 memset( &uc
, 0, sizeof(URL_COMPONENTS
) );
136 SetLastError( 0xdeadbeef );
137 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
138 ok( !ret
, "expected failure\n" );
139 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
140 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
142 /* valid components, NULL url, NULL length */
143 fill_url_components( &uc
);
144 SetLastError( 0xdeadbeef );
145 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, NULL
);
146 ok( !ret
, "expected failure\n" );
147 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
148 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
150 /* valid components, NULL url */
151 SetLastError( 0xdeadbeef );
152 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
153 ok( !ret
, "expected failure\n" );
154 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
155 ok( len
== 57, "expected len 57 got %u\n", len
);
157 /* correct size, NULL url */
158 fill_url_components( &uc
);
159 SetLastError( 0xdeadbeef );
160 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
161 ok( !ret
, "expected failure\n" );
162 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
163 ok( len
== 57, "expected len 57 got %u\n", len
);
165 /* valid components, allocated url, short length */
166 SetLastError( 0xdeadbeef );
167 url
= HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR
) );
170 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
171 ok( !ret
, "expected failure\n" );
172 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
173 ok( len
== 57, "expected len 57 got %u\n", len
);
175 /* allocated url, NULL scheme */
176 uc
.lpszScheme
= NULL
;
179 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
180 ok( ret
, "expected success\n" );
181 ok( len
== 56, "expected len 56 got %u\n", len
);
182 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
184 /* allocated url, 0 scheme */
185 fill_url_components( &uc
);
189 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
190 ok( ret
, "expected success\n" );
191 ok( len
== 56, "expected len 56 got %u\n", len
);
193 /* valid components, allocated url */
194 fill_url_components( &uc
);
197 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
198 ok( ret
, "expected success\n" );
199 ok( len
== 56, "expected len 56 got %d\n", len
);
200 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
202 /* valid username, NULL password */
203 fill_url_components( &uc
);
204 uc
.lpszPassword
= NULL
;
207 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
208 ok( ret
, "expected success\n" );
210 /* valid username, empty password */
211 fill_url_components( &uc
);
212 uc
.lpszPassword
= empty
;
215 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
216 ok( ret
, "expected success\n" );
217 ok( len
== 56, "expected len 56 got %u\n", len
);
218 ok( !lstrcmpW( url
, url3
), "url doesn't match\n" );
220 /* valid password, NULL username */
221 fill_url_components( &uc
);
222 SetLastError( 0xdeadbeef );
223 uc
.lpszUserName
= NULL
;
226 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
227 ok( !ret
, "expected failure\n" );
228 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
230 /* valid password, empty username */
231 fill_url_components( &uc
);
232 uc
.lpszUserName
= empty
;
235 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
236 ok( ret
, "expected success\n");
238 /* NULL username, NULL password */
239 fill_url_components( &uc
);
240 uc
.lpszUserName
= NULL
;
241 uc
.lpszPassword
= NULL
;
244 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
245 ok( ret
, "expected success\n" );
246 ok( len
== 38, "expected len 38 got %u\n", len
);
247 ok( !lstrcmpW( url
, url4
), "url doesn't match\n" );
249 /* empty username, empty password */
250 fill_url_components( &uc
);
251 uc
.lpszUserName
= empty
;
252 uc
.lpszPassword
= empty
;
255 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
256 ok( ret
, "expected success\n" );
257 ok( len
== 56, "expected len 56 got %u\n", len
);
258 ok( !lstrcmpW( url
, url5
), "url doesn't match\n" );
260 /* nScheme has lower precedence than lpszScheme */
261 fill_url_components( &uc
);
263 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
266 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
267 ok( ret
, "expected success\n" );
268 ok( len
== lstrlenW( url6
), "expected len %d got %u\n", lstrlenW( url6
) + 1, len
);
269 ok( !lstrcmpW( url
, url6
), "url doesn't match\n" );
271 /* non-standard port */
272 uc
.lpszScheme
= http
;
273 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
277 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
278 ok( ret
, "expected success\n" );
279 ok( len
== 59, "expected len 59 got %u\n", len
);
280 ok( !lstrcmpW( url
, url7
), "url doesn't match\n" );
282 /* escape extra info */
283 fill_url_components( &uc
);
284 uc
.lpszExtraInfo
= escape
;
285 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
288 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
289 ok( ret
, "expected success\n" );
290 ok( len
== 113, "expected len 113 got %u\n", len
);
291 ok( !lstrcmpW( url
, url8
), "url doesn't match\n" );
293 /* NULL lpszScheme, 0 nScheme and nPort */
294 fill_url_components( &uc
);
295 uc
.lpszScheme
= NULL
;
296 uc
.dwSchemeLength
= 0;
301 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
302 ok( ret
, "expected success\n" );
303 ok( len
== 58, "expected len 58 got %u\n", len
);
304 ok( !lstrcmpW( url
, url9
), "url doesn't match\n" );
306 HeapFree( GetProcessHeap(), 0, url
);
309 static void reset_url_components( URL_COMPONENTS
*uc
)
311 memset( uc
, 0, sizeof(URL_COMPONENTS
) );
312 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
313 uc
->dwSchemeLength
= ~0u;
314 uc
->dwHostNameLength
= ~0u;
316 uc
->dwUserNameLength
= ~0u;
317 uc
->dwPasswordLength
= ~0u;
318 uc
->dwUrlPathLength
= ~0u;
319 uc
->dwExtraInfoLength
= ~0u;
322 static void WinHttpCrackUrl_test( void )
325 WCHAR scheme
[20], user
[20], pass
[20], host
[20], path
[40], extra
[20];
329 /* buffers of sufficient length */
337 uc
.dwStructSize
= sizeof(URL_COMPONENTS
);
339 uc
.lpszScheme
= scheme
;
340 uc
.dwSchemeLength
= 20;
341 uc
.lpszUserName
= user
;
342 uc
.dwUserNameLength
= 20;
343 uc
.lpszPassword
= pass
;
344 uc
.dwPasswordLength
= 20;
345 uc
.lpszHostName
= host
;
346 uc
.dwHostNameLength
= 20;
348 uc
.lpszUrlPath
= path
;
349 uc
.dwUrlPathLength
= 40;
350 uc
.lpszExtraInfo
= extra
;
351 uc
.dwExtraInfoLength
= 20;
353 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
354 ok( ret
, "WinHttpCrackUrl failed\n" );
355 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
356 ok( !memcmp( uc
.lpszScheme
, http
, sizeof(http
) ), "unexpected scheme\n" );
357 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
358 ok( !memcmp( uc
.lpszUserName
, username
, sizeof(username
) ), "unexpected username\n" );
359 ok( uc
.dwUserNameLength
== 8, "unexpected username length\n" );
360 ok( !memcmp( uc
.lpszPassword
, password
, sizeof(password
) ), "unexpected password\n" );
361 ok( uc
.dwPasswordLength
== 8, "unexpected password length\n" );
362 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected hostname\n" );
363 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
364 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
365 ok( !memcmp( uc
.lpszUrlPath
, about
, sizeof(about
) ), "unexpected path\n" );
366 ok( uc
.dwUrlPathLength
== 11, "unexpected path length\n" );
367 ok( !memcmp( uc
.lpszExtraInfo
, query
, sizeof(query
) ), "unexpected extra info\n" );
368 ok( uc
.dwExtraInfoLength
== 6, "unexpected extra info length\n" );
370 /* buffer of insufficient length */
372 uc
.dwSchemeLength
= 1;
374 SetLastError( 0xdeadbeef );
375 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
376 error
= GetLastError();
377 ok( !ret
, "WinHttpCrackUrl failed\n" );
378 ok( error
== ERROR_INSUFFICIENT_BUFFER
, "WinHttpCrackUrl failed\n" );
379 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
382 reset_url_components( &uc
);
383 ret
= WinHttpCrackUrl( url_k1
, 0, 0,&uc
);
385 ok( ret
, "WinHttpCrackUrl failed\n" );
386 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
387 ok( uc
.lpszScheme
== url_k1
,"unexpected scheme\n" );
388 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
389 ok( uc
.lpszUserName
== url_k1
+ 7, "unexpected username\n" );
390 ok( uc
.dwUserNameLength
== 8, "unexpected username length\n" );
391 ok( uc
.lpszPassword
== url_k1
+ 16, "unexpected password\n" );
392 ok( uc
.dwPasswordLength
== 8, "unexpected password length\n" );
393 ok( uc
.lpszHostName
== url_k1
+ 25, "unexpected hostname\n" );
394 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
395 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
396 ok( uc
.lpszUrlPath
== url_k1
+ 39, "unexpected path\n" );
397 ok( uc
.dwUrlPathLength
== 11, "unexpected path length\n" );
398 ok( uc
.lpszExtraInfo
== url_k1
+ 50, "unexpected extra info\n" );
399 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
401 reset_url_components( &uc
);
402 ret
= WinHttpCrackUrl( url_k2
, 0, 0,&uc
);
404 ok( ret
, "WinHttpCrackUrl failed\n" );
405 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
406 ok( uc
.lpszScheme
== url_k2
, "unexpected scheme\n" );
407 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
408 ok( uc
.lpszUserName
== NULL
,"unexpected username\n" );
409 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
410 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
411 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
412 ok( uc
.lpszHostName
== url_k2
+ 7, "unexpected hostname\n" );
413 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
414 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
415 ok( uc
.lpszUrlPath
== url_k2
+ 21, "unexpected path\n" );
416 ok( uc
.dwUrlPathLength
== 0, "unexpected path length\n" );
417 ok( uc
.lpszExtraInfo
== url_k2
+ 21, "unexpected extra info\n" );
418 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
420 reset_url_components( &uc
);
421 ret
= WinHttpCrackUrl( url_k3
, 0, 0, &uc
);
423 ok( ret
, "WinHttpCrackUrl failed\n" );
424 ok( uc
.nScheme
== INTERNET_SCHEME_HTTPS
, "unexpected scheme\n" );
425 ok( uc
.lpszScheme
== url_k3
, "unexpected scheme\n" );
426 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length\n" );
427 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
428 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
429 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
430 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
431 ok( uc
.lpszHostName
== url_k3
+ 8, "unexpected hostname\n" );
432 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
433 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
434 ok( uc
.lpszUrlPath
== url_k3
+ 22, "unexpected path\n" );
435 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
436 ok( uc
.lpszExtraInfo
== url_k3
+ 27, "unexpected extra info\n" );
437 ok( uc
.dwExtraInfoLength
== 1, "unexpected extra info length\n" );
440 reset_url_components( &uc
);
441 ret
= WinHttpCrackUrl( url_k4
, 0, 0, &uc
);
442 ok( !ret
, "WinHttpCrackUrl failed\n" );
444 reset_url_components( &uc
);
445 ret
= WinHttpCrackUrl( url_k5
, 0, 0, &uc
);
446 ok( !ret
, "WinHttpCrackUrl failed\n" );
448 reset_url_components( &uc
);
449 ret
= WinHttpCrackUrl( url_k6
, 0, 0, &uc
);
450 ok( !ret
, "WinHttpCrackUrl failed\n" );
452 reset_url_components( &uc
);
453 ret
= WinHttpCrackUrl( url_k7
, 0, 0, &uc
);
454 ok( !ret
, "WinHttpCrackUrl failed\n" );
456 reset_url_components( &uc
);
457 ret
= WinHttpCrackUrl( url_k8
, 0, 0, &uc
);
458 ok( !ret
, "WinHttpCrackUrl failed\n" );
460 reset_url_components( &uc
);
461 ret
= WinHttpCrackUrl( url_k9
, 0, 0, &uc
);
462 ok( ret
, "WinHttpCrackUrl failed\n" );
463 ok( uc
.lpszUrlPath
== url_k9
+ 14, "unexpected path\n" );
464 ok( uc
.dwUrlPathLength
== 0, "unexpected path length\n" );
465 ok( uc
.lpszExtraInfo
== url_k9
+ 14, "unexpected extra info\n" );
466 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
468 reset_url_components( &uc
);
469 ret
= WinHttpCrackUrl( url_k10
, 0, 0, &uc
);
470 ok( ret
, "WinHttpCrackUrl failed\n" );
471 ok( uc
.lpszUrlPath
== url_k10
+ 13, "unexpected path\n" );
472 ok( uc
.dwUrlPathLength
== 7, "unexpected path length\n" );
473 ok( uc
.lpszExtraInfo
== url_k10
+ 20, "unexpected extra info\n" );
474 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
476 reset_url_components( &uc
);
477 ret
= WinHttpCrackUrl( url5
, 0, 0, &uc
);
478 ok( !ret
, "WinHttpCrackUrl failed\n" );
480 reset_url_components( &uc
);
481 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
482 ok( !ret
, "WinHttpCrackUrl failed\n" );
484 ret
= WinHttpCrackUrl( url1
, 0, 0, NULL
);
485 ok( !ret
, "WinHttpCrackUrl failed\n" );
487 ret
= WinHttpCrackUrl( NULL
, 0, 0, &uc
);
488 ok( !ret
, "WinHttpCrackUrl failed\n" );
490 /* decoding without buffers */
491 reset_url_components( &uc
);
492 SetLastError(0xdeadbeef);
493 ret
= WinHttpCrackUrl( url8
, 0, ICU_DECODE
, &uc
);
494 error
= GetLastError();
495 ok( !ret
, "WinHttpCrackUrl failed\n" );
496 ok( error
== ERROR_INVALID_PARAMETER
, "WinHttpCrackUrl failed\n" );
498 /* decoding with buffers */
499 uc
.lpszScheme
= scheme
;
500 uc
.dwSchemeLength
= 20;
501 uc
.lpszUserName
= user
;
502 uc
.dwUserNameLength
= 20;
503 uc
.lpszPassword
= pass
;
504 uc
.dwPasswordLength
= 20;
505 uc
.lpszHostName
= host
;
506 uc
.dwHostNameLength
= 20;
508 uc
.lpszUrlPath
= path
;
509 uc
.dwUrlPathLength
= 40;
510 uc
.lpszExtraInfo
= extra
;
511 uc
.dwExtraInfoLength
= 20;
514 ret
= WinHttpCrackUrl( url8
, 0, ICU_DECODE
, &uc
);
515 ok( ret
, "WinHttpCrackUrl failed\n" );
516 ok( !memcmp( uc
.lpszUrlPath
+ 11, escape
, 21 * sizeof(WCHAR
) ), "unexpected path\n" );
517 ok( uc
.dwUrlPathLength
== 32, "unexpected path length\n" );
518 ok( !memcmp( uc
.lpszExtraInfo
, escape
+ 21, 12 * sizeof(WCHAR
) ), "unexpected extra info\n" );
519 ok( uc
.dwExtraInfoLength
== 12, "unexpected extra info length\n" );
521 /* Urls with specified port numbers */
522 /* decoding with buffers */
523 uc
.lpszScheme
= scheme
;
524 uc
.dwSchemeLength
= 20;
525 uc
.lpszUserName
= user
;
526 uc
.dwUserNameLength
= 20;
527 uc
.lpszPassword
= pass
;
528 uc
.dwPasswordLength
= 20;
529 uc
.lpszHostName
= host
;
530 uc
.dwHostNameLength
= 20;
532 uc
.lpszUrlPath
= path
;
533 uc
.dwUrlPathLength
= 40;
534 uc
.lpszExtraInfo
= extra
;
535 uc
.dwExtraInfoLength
= 20;
538 ret
= WinHttpCrackUrl( url7
, 0, 0, &uc
);
539 ok( ret
, "WinHttpCrackUrl failed\n" );
540 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected host name: %s\n", debugstr_w(uc
.lpszHostName
) );
541 ok( uc
.dwHostNameLength
== 14, "unexpected host name length: %d\n", uc
.dwHostNameLength
);
542 ok( uc
.nPort
== 42, "unexpected port: %u\n", uc
.nPort
);
544 /* decoding without buffers */
545 reset_url_components( &uc
);
546 ret
= WinHttpCrackUrl( url9
, 0, 0, &uc
);
547 ok( ret
, "WinHttpCrackUrl failed\n" );
548 ok( uc
.nPort
== 0, "unexpected port: %u\n", uc
.nPort
);
550 reset_url_components( &uc
);
551 ret
= WinHttpCrackUrl( url10
, 0, 0, &uc
);
552 ok( ret
, "WinHttpCrackUrl failed\n" );
553 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
555 reset_url_components( &uc
);
556 ret
= WinHttpCrackUrl( url11
, 0, 0, &uc
);
557 ok( ret
, "WinHttpCrackUrl failed\n" );
558 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
560 reset_url_components( &uc
);
561 SetLastError( 0xdeadbeef );
562 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
563 error
= GetLastError();
564 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
565 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
567 reset_url_components( &uc
);
568 SetLastError( 0xdeadbeef );
569 ret
= WinHttpCrackUrl( http
, 0, 0, &uc
);
570 error
= GetLastError();
571 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
572 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
577 WinHttpCreateUrl_test();
578 WinHttpCrackUrl_test();