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};
74 static const WCHAR url15
[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','t','e','s','t',0};
76 static const WCHAR url_k1
[] =
77 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
78 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
79 static const WCHAR url_k2
[] =
80 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
81 static const WCHAR url_k3
[] =
82 {'h','t','t','p','s',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','p','o','s','t','?',0};
83 static const WCHAR url_k4
[] =
84 {'H','T','T','P',':','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
85 static const WCHAR url_k5
[] =
86 {'h','t','t','p',':','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
87 static const WCHAR url_k6
[] =
88 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
89 static const WCHAR url_k7
[] =
91 static const WCHAR url_k8
[] =
93 static const WCHAR url_k9
[] =
94 {'h','t','t','p',':','/','/','w','i','n','e','h','q','?',0};
95 static const WCHAR url_k10
[] =
96 {'h','t','t','p',':','/','/','w','i','n','e','h','q','/','p','o','s','t',';','a',0};
98 static void fill_url_components( URL_COMPONENTS
*uc
)
100 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
101 uc
->lpszScheme
= http
;
102 uc
->dwSchemeLength
= lstrlenW( uc
->lpszScheme
);
103 uc
->nScheme
= INTERNET_SCHEME_HTTP
;
104 uc
->lpszHostName
= winehq
;
105 uc
->dwHostNameLength
= lstrlenW( uc
->lpszHostName
);
107 uc
->lpszUserName
= username
;
108 uc
->dwUserNameLength
= lstrlenW( uc
->lpszUserName
);
109 uc
->lpszPassword
= password
;
110 uc
->dwPasswordLength
= lstrlenW( uc
->lpszPassword
);
111 uc
->lpszUrlPath
= about
;
112 uc
->dwUrlPathLength
= lstrlenW( uc
->lpszUrlPath
);
113 uc
->lpszExtraInfo
= query
;
114 uc
->dwExtraInfoLength
= lstrlenW( uc
->lpszExtraInfo
);
117 static void WinHttpCreateUrl_test( void )
124 /* NULL components */
126 SetLastError( 0xdeadbeef );
127 ret
= WinHttpCreateUrl( NULL
, 0, NULL
, &len
);
128 ok( !ret
, "expected failure\n" );
129 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
130 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
132 /* zero'ed components */
133 memset( &uc
, 0, sizeof(URL_COMPONENTS
) );
134 SetLastError( 0xdeadbeef );
135 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
136 ok( !ret
, "expected failure\n" );
137 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
138 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
140 /* valid components, NULL url, NULL length */
141 fill_url_components( &uc
);
142 SetLastError( 0xdeadbeef );
143 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, NULL
);
144 ok( !ret
, "expected failure\n" );
145 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
147 /* valid components, NULL url */
148 SetLastError( 0xdeadbeef );
149 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
150 ok( !ret
, "expected failure\n" );
151 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
152 GetLastError() == ERROR_INVALID_PARAMETER
,
153 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
155 /* correct size, NULL url */
156 fill_url_components( &uc
);
157 SetLastError( 0xdeadbeef );
158 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
159 ok( !ret
, "expected failure\n" );
160 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
||
161 GetLastError() == ERROR_INVALID_PARAMETER
,
162 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
164 /* valid components, allocated url, short length */
165 SetLastError( 0xdeadbeef );
166 url
= HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR
) );
169 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
170 ok( !ret
, "expected failure\n" );
171 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
172 ok( len
== 57, "expected len 57 got %u\n", len
);
174 /* allocated url, NULL scheme */
175 uc
.lpszScheme
= NULL
;
178 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
179 ok( ret
, "expected success\n" );
180 ok( len
== 56, "expected len 56 got %u\n", len
);
181 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
183 /* allocated url, 0 scheme */
184 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 %u\n", len
);
192 /* valid components, allocated url */
193 fill_url_components( &uc
);
196 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
197 ok( ret
, "expected success\n" );
198 ok( len
== 56, "expected len 56 got %d\n", len
);
199 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
201 /* valid username, NULL password */
202 fill_url_components( &uc
);
203 uc
.lpszPassword
= NULL
;
206 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
207 ok( ret
, "expected success\n" );
209 /* valid username, empty password */
210 fill_url_components( &uc
);
211 uc
.lpszPassword
= empty
;
214 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
215 ok( ret
, "expected success\n" );
216 ok( len
== 56, "expected len 56 got %u\n", len
);
217 ok( !lstrcmpW( url
, url3
), "url doesn't match\n" );
219 /* valid password, NULL username */
220 fill_url_components( &uc
);
221 SetLastError( 0xdeadbeef );
222 uc
.lpszUserName
= NULL
;
225 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
226 ok( !ret
, "expected failure\n" );
227 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
229 /* valid password, empty username */
230 fill_url_components( &uc
);
231 uc
.lpszUserName
= empty
;
234 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
235 ok( ret
, "expected success\n");
237 /* NULL username, NULL password */
238 fill_url_components( &uc
);
239 uc
.lpszUserName
= NULL
;
240 uc
.lpszPassword
= NULL
;
243 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
244 ok( ret
, "expected success\n" );
245 ok( len
== 38, "expected len 38 got %u\n", len
);
246 ok( !lstrcmpW( url
, url4
), "url doesn't match\n" );
248 /* empty username, empty password */
249 fill_url_components( &uc
);
250 uc
.lpszUserName
= empty
;
251 uc
.lpszPassword
= empty
;
254 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
255 ok( ret
, "expected success\n" );
256 ok( len
== 56, "expected len 56 got %u\n", len
);
257 ok( !lstrcmpW( url
, url5
), "url doesn't match\n" );
259 /* nScheme has lower precedence than lpszScheme */
260 fill_url_components( &uc
);
262 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
265 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
266 ok( ret
, "expected success\n" );
267 ok( len
== lstrlenW( url6
), "expected len %d got %u\n", lstrlenW( url6
) + 1, len
);
268 ok( !lstrcmpW( url
, url6
), "url doesn't match\n" );
270 /* non-standard port */
271 uc
.lpszScheme
= http
;
272 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
276 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
277 ok( ret
, "expected success\n" );
278 ok( len
== 59, "expected len 59 got %u\n", len
);
279 ok( !lstrcmpW( url
, url7
), "url doesn't match\n" );
281 /* escape extra info */
282 fill_url_components( &uc
);
283 uc
.lpszExtraInfo
= escape
;
284 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
287 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
288 ok( ret
, "expected success\n" );
289 ok( len
== 113, "expected len 113 got %u\n", len
);
290 ok( !lstrcmpW( url
, url8
), "url doesn't match\n" );
292 /* NULL lpszScheme, 0 nScheme and nPort */
293 fill_url_components( &uc
);
294 uc
.lpszScheme
= NULL
;
295 uc
.dwSchemeLength
= 0;
300 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
301 ok( ret
, "expected success\n" );
302 ok( len
== 58, "expected len 58 got %u\n", len
);
303 ok( !lstrcmpW( url
, url9
), "url doesn't match\n" );
305 HeapFree( GetProcessHeap(), 0, url
);
308 static void reset_url_components( URL_COMPONENTS
*uc
)
310 memset( uc
, 0, sizeof(URL_COMPONENTS
) );
311 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
312 uc
->dwSchemeLength
= ~0u;
313 uc
->dwHostNameLength
= ~0u;
315 uc
->dwUserNameLength
= ~0u;
316 uc
->dwPasswordLength
= ~0u;
317 uc
->dwUrlPathLength
= ~0u;
318 uc
->dwExtraInfoLength
= ~0u;
321 static void WinHttpCrackUrl_test( void )
323 static const WCHAR hostnameW
[] =
324 {'w','i','n','e','h','q','.','o',' ','g',0};
325 static const WCHAR pathW
[] =
326 {'/','p','a','t','h','%','2','0','w','i','t','h','%','2','0','s','p','a','c','e','s',0};
328 WCHAR scheme
[20], user
[20], pass
[20], host
[20], path
[80], extra
[40];
332 /* buffers of sufficient length */
340 uc
.dwStructSize
= sizeof(URL_COMPONENTS
);
342 uc
.lpszScheme
= scheme
;
343 uc
.dwSchemeLength
= 20;
344 uc
.lpszUserName
= user
;
345 uc
.dwUserNameLength
= 20;
346 uc
.lpszPassword
= pass
;
347 uc
.dwPasswordLength
= 20;
348 uc
.lpszHostName
= host
;
349 uc
.dwHostNameLength
= 20;
351 uc
.lpszUrlPath
= path
;
352 uc
.dwUrlPathLength
= 40;
353 uc
.lpszExtraInfo
= extra
;
354 uc
.dwExtraInfoLength
= 20;
356 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
357 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
358 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme: %u\n", uc
.nScheme
);
359 ok( !memcmp( uc
.lpszScheme
, http
, sizeof(http
) ), "unexpected scheme: %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
360 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
361 ok( !memcmp( uc
.lpszUserName
, username
, sizeof(username
) ), "unexpected username: %s\n", wine_dbgstr_w(uc
.lpszUserName
) );
362 ok( uc
.dwUserNameLength
== 8, "unexpected username length: %u\n", uc
.dwUserNameLength
);
363 ok( !memcmp( uc
.lpszPassword
, password
, sizeof(password
) ), "unexpected password: %s\n", wine_dbgstr_w(uc
.lpszPassword
) );
364 ok( uc
.dwPasswordLength
== 8, "unexpected password length: %u\n", uc
.dwPasswordLength
);
365 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected hostname: %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
366 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length: %u\n", uc
.dwHostNameLength
);
367 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
368 ok( !memcmp( uc
.lpszUrlPath
, about
, sizeof(about
) ), "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
369 ok( uc
.dwUrlPathLength
== 11, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
370 ok( !memcmp( uc
.lpszExtraInfo
, query
, sizeof(query
) ), "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
371 ok( uc
.dwExtraInfoLength
== 6, "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
373 /* buffer of insufficient length */
375 uc
.dwSchemeLength
= 1;
377 SetLastError( 0xdeadbeef );
378 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
379 error
= GetLastError();
380 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
381 ok( error
== ERROR_INSUFFICIENT_BUFFER
, "got %u, expected ERROR_INSUFFICIENT_BUFFER\n", error
);
382 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
385 reset_url_components( &uc
);
386 ret
= WinHttpCrackUrl( url_k1
, 0, 0,&uc
);
388 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
389 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
390 ok( uc
.lpszScheme
== url_k1
,"unexpected scheme\n" );
391 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
392 ok( uc
.lpszUserName
== url_k1
+ 7, "unexpected username\n" );
393 ok( uc
.dwUserNameLength
== 8, "unexpected username length\n" );
394 ok( uc
.lpszPassword
== url_k1
+ 16, "unexpected password\n" );
395 ok( uc
.dwPasswordLength
== 8, "unexpected password length\n" );
396 ok( uc
.lpszHostName
== url_k1
+ 25, "unexpected hostname\n" );
397 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
398 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
399 ok( uc
.lpszUrlPath
== url_k1
+ 39, "unexpected path\n" );
400 ok( uc
.dwUrlPathLength
== 11, "unexpected path length\n" );
401 ok( uc
.lpszExtraInfo
== url_k1
+ 50, "unexpected extra info\n" );
402 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
404 reset_url_components( &uc
);
405 ret
= WinHttpCrackUrl( url_k2
, 0, 0,&uc
);
407 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
408 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
409 ok( uc
.lpszScheme
== url_k2
, "unexpected scheme\n" );
410 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
411 ok( uc
.lpszUserName
== NULL
,"unexpected username\n" );
412 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
413 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
414 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
415 ok( uc
.lpszHostName
== url_k2
+ 7, "unexpected hostname\n" );
416 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
417 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
418 ok( uc
.lpszUrlPath
== url_k2
+ 21, "unexpected path\n" );
419 ok( uc
.dwUrlPathLength
== 0, "unexpected path length\n" );
420 ok( uc
.lpszExtraInfo
== url_k2
+ 21, "unexpected extra info\n" );
421 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
423 reset_url_components( &uc
);
424 ret
= WinHttpCrackUrl( url_k3
, 0, 0, &uc
);
426 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
427 ok( uc
.nScheme
== INTERNET_SCHEME_HTTPS
, "unexpected scheme\n" );
428 ok( uc
.lpszScheme
== url_k3
, "unexpected scheme\n" );
429 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length\n" );
430 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
431 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
432 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
433 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
434 ok( uc
.lpszHostName
== url_k3
+ 8, "unexpected hostname\n" );
435 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
436 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
437 ok( uc
.lpszUrlPath
== url_k3
+ 22, "unexpected path\n" );
438 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
439 ok( uc
.lpszExtraInfo
== url_k3
+ 27, "unexpected extra info\n" );
440 ok( uc
.dwExtraInfoLength
== 1, "unexpected extra info length\n" );
443 reset_url_components( &uc
);
444 ret
= WinHttpCrackUrl( url_k4
, 0, 0, &uc
);
445 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
447 reset_url_components( &uc
);
448 ret
= WinHttpCrackUrl( url_k5
, 0, 0, &uc
);
449 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
451 reset_url_components( &uc
);
452 ret
= WinHttpCrackUrl( url_k6
, 0, 0, &uc
);
453 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
455 reset_url_components( &uc
);
456 ret
= WinHttpCrackUrl( url_k7
, 0, 0, &uc
);
457 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
459 reset_url_components( &uc
);
460 ret
= WinHttpCrackUrl( url_k8
, 0, 0, &uc
);
461 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
463 reset_url_components( &uc
);
464 ret
= WinHttpCrackUrl( url_k9
, 0, 0, &uc
);
465 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
466 ok( uc
.lpszUrlPath
== url_k9
+ 14 || broken(uc
.lpszUrlPath
== url_k9
+ 13) /* win8 */,
467 "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
468 ok( uc
.dwUrlPathLength
== 0, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
469 ok( uc
.lpszExtraInfo
== url_k9
+ 14 || broken(uc
.lpszExtraInfo
== url_k9
+ 13) /* win8 */,
470 "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
471 ok( uc
.dwExtraInfoLength
== 0 || broken(uc
.dwExtraInfoLength
== 1) /* win8 */,
472 "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
474 reset_url_components( &uc
);
475 ret
= WinHttpCrackUrl( url_k10
, 0, 0, &uc
);
476 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
477 ok( uc
.lpszUrlPath
== url_k10
+ 13, "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
478 ok( uc
.dwUrlPathLength
== 7, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
479 ok( uc
.lpszExtraInfo
== url_k10
+ 20, "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
480 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
482 reset_url_components( &uc
);
483 ret
= WinHttpCrackUrl( url5
, 0, 0, &uc
);
484 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
486 reset_url_components( &uc
);
487 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
488 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
490 ret
= WinHttpCrackUrl( url1
, 0, 0, NULL
);
491 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
493 ret
= WinHttpCrackUrl( NULL
, 0, 0, &uc
);
494 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
496 /* decoding without buffers */
497 reset_url_components( &uc
);
498 SetLastError(0xdeadbeef);
499 ret
= WinHttpCrackUrl( url8
, 0, ICU_DECODE
, &uc
);
500 error
= GetLastError();
501 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
502 ok( error
== ERROR_INVALID_PARAMETER
, "got %u, expected ERROR_INVALID_PARAMETER\n", error
);
504 /* decoding with buffers */
505 uc
.lpszScheme
= scheme
;
506 uc
.dwSchemeLength
= 20;
507 uc
.lpszUserName
= user
;
508 uc
.dwUserNameLength
= 20;
509 uc
.lpszPassword
= pass
;
510 uc
.dwPasswordLength
= 20;
511 uc
.lpszHostName
= host
;
512 uc
.dwHostNameLength
= 20;
514 uc
.lpszUrlPath
= path
;
515 uc
.dwUrlPathLength
= 80;
516 uc
.lpszExtraInfo
= extra
;
517 uc
.dwExtraInfoLength
= 40;
520 ret
= WinHttpCrackUrl( url8
, 0, ICU_DECODE
, &uc
);
521 ok( ret
, "WinHttpCrackUrl failed %u\n", GetLastError() );
522 ok( !memcmp( uc
.lpszUrlPath
+ 11, escape
, 21 * sizeof(WCHAR
) ), "unexpected path\n" );
523 ok( uc
.dwUrlPathLength
== 32, "unexpected path length %u\n", uc
.dwUrlPathLength
);
524 ok( !memcmp( uc
.lpszExtraInfo
, escape
+ 21, 12 * sizeof(WCHAR
) ), "unexpected extra info\n" );
525 ok( uc
.dwExtraInfoLength
== 12, "unexpected extra info length %u\n", uc
.dwExtraInfoLength
);
527 /* Urls with specified port numbers */
528 /* decoding with buffers */
529 uc
.lpszScheme
= scheme
;
530 uc
.dwSchemeLength
= 20;
531 uc
.lpszUserName
= user
;
532 uc
.dwUserNameLength
= 20;
533 uc
.lpszPassword
= pass
;
534 uc
.dwPasswordLength
= 20;
535 uc
.lpszHostName
= host
;
536 uc
.dwHostNameLength
= 20;
538 uc
.lpszUrlPath
= path
;
539 uc
.dwUrlPathLength
= 40;
540 uc
.lpszExtraInfo
= extra
;
541 uc
.dwExtraInfoLength
= 20;
544 ret
= WinHttpCrackUrl( url7
, 0, 0, &uc
);
545 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
546 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected host name: %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
547 ok( uc
.dwHostNameLength
== 14, "unexpected host name length: %d\n", uc
.dwHostNameLength
);
548 ok( uc
.nPort
== 42, "unexpected port: %u\n", uc
.nPort
);
550 /* decoding without buffers */
551 reset_url_components( &uc
);
552 ret
= WinHttpCrackUrl( url9
, 0, 0, &uc
);
553 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
554 ok( uc
.nPort
== 0, "unexpected port: %u\n", uc
.nPort
);
556 reset_url_components( &uc
);
557 ret
= WinHttpCrackUrl( url10
, 0, 0, &uc
);
558 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
559 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
561 reset_url_components( &uc
);
562 ret
= WinHttpCrackUrl( url11
, 0, 0, &uc
);
563 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
564 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
566 reset_url_components( &uc
);
567 SetLastError( 0xdeadbeef );
568 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
569 error
= GetLastError();
570 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
571 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
573 reset_url_components( &uc
);
574 SetLastError( 0xdeadbeef );
575 ret
= WinHttpCrackUrl( http
, 0, 0, &uc
);
576 error
= GetLastError();
577 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
578 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
580 reset_url_components( &uc
);
581 ret
= WinHttpCrackUrl( url12
, 0, 0, &uc
);
582 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
583 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
584 ok( uc
.lpszScheme
== url12
,"unexpected scheme\n" );
585 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
586 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
587 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
588 ok( uc
.lpszHostName
== url12
+ 7, "unexpected hostname\n" );
589 ok( uc
.dwHostNameLength
== 11, "unexpected hostname length\n" );
590 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
591 ok( uc
.lpszUrlPath
== url12
+ 18, "unexpected path\n" );
592 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
593 ok( uc
.lpszExtraInfo
== url12
+ 23, "unexpected extra info\n" );
594 ok( uc
.dwExtraInfoLength
== 39, "unexpected extra info length\n" );
596 uc
.lpszScheme
= scheme
;
597 uc
.dwSchemeLength
= 20;
598 uc
.lpszHostName
= host
;
599 uc
.dwHostNameLength
= 20;
600 uc
.lpszUserName
= NULL
;
601 uc
.dwUserNameLength
= 0;
602 uc
.lpszPassword
= NULL
;
603 uc
.dwPasswordLength
= 0;
604 uc
.lpszUrlPath
= path
;
605 uc
.dwUrlPathLength
= 40;
606 uc
.lpszExtraInfo
= NULL
;
607 uc
.dwExtraInfoLength
= 0;
609 ret
= WinHttpCrackUrl( url13
, 0, ICU_DECODE
, &uc
);
610 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
612 uc
.lpszScheme
= scheme
;
613 uc
.dwSchemeLength
= 20;
614 uc
.lpszHostName
= host
;
615 uc
.dwHostNameLength
= 20;
616 uc
.lpszUserName
= NULL
;
617 uc
.dwUserNameLength
= 0;
618 uc
.lpszPassword
= NULL
;
619 uc
.dwPasswordLength
= 0;
620 uc
.lpszUrlPath
= path
;
621 uc
.dwUrlPathLength
= 40;
622 uc
.lpszExtraInfo
= NULL
;
623 uc
.dwExtraInfoLength
= 0;
625 ret
= WinHttpCrackUrl( url14
, 0, ICU_ESCAPE
|ICU_DECODE
, &uc
);
626 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
627 ok( !lstrcmpW( uc
.lpszHostName
, hostnameW
), "unexpected host name\n" );
628 ok( !lstrcmpW( uc
.lpszUrlPath
, pathW
), "unexpected path\n" );
630 uc
.dwStructSize
= sizeof(uc
);
631 uc
.lpszScheme
= NULL
;
632 uc
.dwSchemeLength
= 0;
634 uc
.lpszHostName
= NULL
;
635 uc
.dwHostNameLength
= ~0u;
637 uc
.lpszUserName
= NULL
;
638 uc
.dwUserNameLength
= ~0u;
639 uc
.lpszPassword
= NULL
;
640 uc
.dwPasswordLength
= ~0u;
641 uc
.lpszUrlPath
= NULL
;
642 uc
.dwUrlPathLength
= ~0u;
643 uc
.lpszExtraInfo
= NULL
;
644 uc
.dwExtraInfoLength
= ~0u;
645 ret
= WinHttpCrackUrl( url15
, 0, 0, &uc
);
646 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
647 ok( !uc
.lpszScheme
, "unexpected scheme %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
648 ok( !uc
.dwSchemeLength
, "unexpected length %u\n", uc
.dwSchemeLength
);
649 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme %u\n", uc
.nScheme
);
650 ok( !lstrcmpW( uc
.lpszHostName
, url15
+ 7 ), "unexpected hostname %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
651 ok( uc
.dwHostNameLength
== 14, "unexpected length %u\n", uc
.dwHostNameLength
);
652 ok( uc
.nPort
== 80, "unexpected port %u\n", uc
.nPort
);
653 ok( !uc
.lpszUserName
, "unexpected username\n" );
654 ok( !uc
.dwUserNameLength
, "unexpected length %u\n", uc
.dwUserNameLength
);
655 ok( !uc
.lpszPassword
, "unexpected password\n" );
656 ok( !uc
.dwPasswordLength
, "unexpected length %u\n", uc
.dwPasswordLength
);
657 ok( !lstrcmpW( uc
.lpszUrlPath
, url15
+ 21 ), "unexpected path %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
658 ok( uc
.dwUrlPathLength
== 5, "unexpected length %u\n", uc
.dwUrlPathLength
);
659 ok( !uc
.lpszExtraInfo
[0], "unexpected extra info %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
660 ok( uc
.dwExtraInfoLength
== 0, "unexpected length %u\n", uc
.dwExtraInfoLength
);
662 uc
.dwStructSize
= sizeof(uc
);
663 uc
.lpszScheme
= scheme
;
664 uc
.dwSchemeLength
= 0;
666 uc
.lpszHostName
= NULL
;
667 uc
.dwHostNameLength
= 0;
669 uc
.lpszUserName
= NULL
;
670 uc
.dwUserNameLength
= ~0u;
671 uc
.lpszPassword
= NULL
;
672 uc
.dwPasswordLength
= ~0u;
673 uc
.lpszUrlPath
= NULL
;
674 uc
.dwUrlPathLength
= 0;
675 uc
.lpszExtraInfo
= NULL
;
676 uc
.dwExtraInfoLength
= 0;
677 SetLastError( 0xdeadbeef );
678 ret
= WinHttpCrackUrl( url15
, 0, 0, &uc
);
679 error
= GetLastError();
680 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
681 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
682 ok( !lstrcmpW( uc
.lpszScheme
, http
), "unexpected scheme %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
683 ok( !uc
.dwSchemeLength
, "unexpected length %u\n", uc
.dwSchemeLength
);
684 ok( uc
.nScheme
== 0, "unexpected scheme %u\n", uc
.nScheme
);
685 ok( !uc
.lpszHostName
, "unexpected hostname %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
686 ok( uc
.dwHostNameLength
== 0, "unexpected length %u\n", uc
.dwHostNameLength
);
687 ok( uc
.nPort
== 0, "unexpected port %u\n", uc
.nPort
);
688 ok( !uc
.lpszUserName
, "unexpected username\n" );
689 ok( uc
.dwUserNameLength
== ~0u, "unexpected length %u\n", uc
.dwUserNameLength
);
690 ok( !uc
.lpszPassword
, "unexpected password\n" );
691 ok( uc
.dwPasswordLength
== ~0u, "unexpected length %u\n", uc
.dwPasswordLength
);
692 ok( !uc
.lpszUrlPath
, "unexpected path %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
693 ok( uc
.dwUrlPathLength
== 0, "unexpected length %u\n", uc
.dwUrlPathLength
);
694 ok( !uc
.lpszExtraInfo
, "unexpected extra info %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
695 ok( uc
.dwExtraInfoLength
== 0, "unexpected length %u\n", uc
.dwExtraInfoLength
);
700 WinHttpCreateUrl_test();
701 WinHttpCrackUrl_test();