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
[] = {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':',0};
42 static const WCHAR url3
[] =
43 {'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};
44 static const WCHAR url4
[] = {'h','t','t','p',':','/','/',0};
45 static const WCHAR url5
[] =
46 {'f','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
47 '@','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};
48 static const WCHAR url6
[] =
49 {'h','t','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',':','4','2','/','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','/','s','i','t','e','/','a','b','o','u','t',
54 '%','2','0','!','%','2','2','%','2','3','$','%','2','5','&','\'','(',')','*','+',',','-','.','/',':',';','%','3','C','=','%','3','E','?','@','%',
55 '5','B','%','5','C','%','5','D','%','5','E','_','%','6','0','%','7','B','%','7','C','%','7','D','%','7','E',0};
56 static const WCHAR url8
[] =
57 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
58 '@','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};
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',':','8','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','s',':','/','/','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',':','4','4','3','/','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',':','/','/','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};
67 static const WCHAR url12
[] =
68 {'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};
69 static const WCHAR url13
[] =
70 {'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};
71 static const WCHAR url14
[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','t','e','s','t',0};
72 static const WCHAR url15
[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',':','6','5','5','3','6',0};
73 static const WCHAR url16
[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',':','0',0};
74 static const WCHAR url17
[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',':',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 SetLastError( 0xdeadbeef );
176 uc
.lpszScheme
= NULL
;
179 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
180 ok( ret
, "expected success\n" );
181 ok( GetLastError() == ERROR_SUCCESS
|| broken(GetLastError() == 0xdeadbeef) /* < win7 */,
182 "expected ERROR_SUCCESS got %u\n", GetLastError() );
183 ok( len
== 56, "expected len 56 got %u\n", len
);
184 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
186 /* allocated url, 0 scheme */
187 fill_url_components( &uc
);
191 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
192 ok( ret
, "expected success\n" );
193 ok( len
== 56, "expected len 56 got %u\n", len
);
195 /* valid components, allocated url */
196 fill_url_components( &uc
);
199 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
200 ok( ret
, "expected success\n" );
201 ok( len
== 56, "expected len 56 got %d\n", len
);
202 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
204 /* valid username, NULL password */
205 fill_url_components( &uc
);
206 uc
.lpszPassword
= NULL
;
209 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
210 ok( ret
, "expected success\n" );
212 /* valid username, empty password */
213 fill_url_components( &uc
);
214 uc
.lpszPassword
= empty
;
217 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
218 ok( ret
, "expected success\n" );
219 ok( len
== 56, "expected len 56 got %u\n", len
);
220 ok( !lstrcmpW( url
, url2
), "url doesn't match\n" );
222 /* valid password, NULL username */
223 fill_url_components( &uc
);
224 SetLastError( 0xdeadbeef );
225 uc
.lpszUserName
= NULL
;
228 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
229 ok( !ret
, "expected failure\n" );
230 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
232 /* valid password, empty username */
233 fill_url_components( &uc
);
234 uc
.lpszUserName
= empty
;
237 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
238 ok( ret
, "expected success\n");
240 /* NULL username, NULL password */
241 fill_url_components( &uc
);
242 uc
.lpszUserName
= NULL
;
243 uc
.lpszPassword
= NULL
;
246 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
247 ok( ret
, "expected success\n" );
248 ok( len
== 38, "expected len 38 got %u\n", len
);
249 ok( !lstrcmpW( url
, url3
), "url doesn't match\n" );
251 /* empty username, empty password */
252 fill_url_components( &uc
);
253 uc
.lpszUserName
= empty
;
254 uc
.lpszPassword
= empty
;
257 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
258 ok( ret
, "expected success\n" );
259 ok( len
== 56, "expected len 56 got %u\n", len
);
260 ok( !lstrcmpW( url
, url4
), "url doesn't match\n" );
262 /* nScheme has lower precedence than lpszScheme */
263 fill_url_components( &uc
);
265 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
268 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
269 ok( ret
, "expected success\n" );
270 ok( len
== lstrlenW( url5
), "expected len %d got %u\n", lstrlenW( url5
) + 1, len
);
271 ok( !lstrcmpW( url
, url5
), "url doesn't match\n" );
273 /* non-standard port */
274 uc
.lpszScheme
= http
;
275 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
279 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
280 ok( ret
, "expected success\n" );
281 ok( len
== 59, "expected len 59 got %u\n", len
);
282 ok( !lstrcmpW( url
, url6
), "url doesn't match\n" );
284 /* escape extra info */
285 fill_url_components( &uc
);
286 uc
.lpszExtraInfo
= escape
;
287 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
290 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
291 ok( ret
, "expected success\n" );
292 ok( len
== 113, "expected len 113 got %u\n", len
);
293 ok( !lstrcmpW( url
, url7
), "url doesn't match\n" );
295 /* NULL lpszScheme, 0 nScheme and nPort */
296 fill_url_components( &uc
);
297 uc
.lpszScheme
= NULL
;
298 uc
.dwSchemeLength
= 0;
303 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
304 ok( ret
, "expected success\n" );
305 ok( len
== 58, "expected len 58 got %u\n", len
);
306 ok( !lstrcmpW( url
, url8
), "url doesn't match\n" );
308 HeapFree( GetProcessHeap(), 0, url
);
311 static void reset_url_components( URL_COMPONENTS
*uc
)
313 memset( uc
, 0, sizeof(URL_COMPONENTS
) );
314 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
315 uc
->dwSchemeLength
= ~0u;
316 uc
->dwHostNameLength
= 1;
318 uc
->dwUserNameLength
= ~0u;
319 uc
->dwPasswordLength
= ~0u;
320 uc
->dwUrlPathLength
= ~0u;
321 uc
->dwExtraInfoLength
= ~0u;
324 static void WinHttpCrackUrl_test( void )
326 static const WCHAR hostnameW
[] =
327 {'w','i','n','e','h','q','.','o',' ','g',0};
328 static const WCHAR pathW
[] =
329 {'/','p','a','t','h','%','2','0','w','i','t','h','%','2','0','s','p','a','c','e','s',0};
331 WCHAR scheme
[20], user
[20], pass
[20], host
[20], path
[80], extra
[40];
335 /* buffers of sufficient length */
336 scheme
[0] = user
[0] = pass
[0] = host
[0] = path
[0] = extra
[0] = 0;
338 uc
.dwStructSize
= sizeof(URL_COMPONENTS
);
340 uc
.lpszScheme
= scheme
;
341 uc
.dwSchemeLength
= 20;
342 uc
.lpszUserName
= user
;
343 uc
.dwUserNameLength
= 20;
344 uc
.lpszPassword
= pass
;
345 uc
.dwPasswordLength
= 20;
346 uc
.lpszHostName
= host
;
347 uc
.dwHostNameLength
= 20;
349 uc
.lpszUrlPath
= path
;
350 uc
.dwUrlPathLength
= 40;
351 uc
.lpszExtraInfo
= extra
;
352 uc
.dwExtraInfoLength
= 20;
354 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
355 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
356 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme: %u\n", uc
.nScheme
);
357 ok( !memcmp( uc
.lpszScheme
, http
, sizeof(http
) ), "unexpected scheme: %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
358 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
359 ok( !memcmp( uc
.lpszUserName
, username
, sizeof(username
) ), "unexpected username: %s\n", wine_dbgstr_w(uc
.lpszUserName
) );
360 ok( uc
.dwUserNameLength
== 8, "unexpected username length: %u\n", uc
.dwUserNameLength
);
361 ok( !memcmp( uc
.lpszPassword
, password
, sizeof(password
) ), "unexpected password: %s\n", wine_dbgstr_w(uc
.lpszPassword
) );
362 ok( uc
.dwPasswordLength
== 8, "unexpected password length: %u\n", uc
.dwPasswordLength
);
363 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected hostname: %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
364 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length: %u\n", uc
.dwHostNameLength
);
365 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
366 ok( !memcmp( uc
.lpszUrlPath
, about
, sizeof(about
) ), "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
367 ok( uc
.dwUrlPathLength
== 11, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
368 ok( !memcmp( uc
.lpszExtraInfo
, query
, sizeof(query
) ), "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
369 ok( uc
.dwExtraInfoLength
== 6, "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
371 /* buffers of insufficient length */
372 uc
.dwSchemeLength
= 1;
373 uc
.dwHostNameLength
= 1;
374 uc
.dwUrlPathLength
= 40; /* sufficient */
375 SetLastError( 0xdeadbeef );
376 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
377 error
= GetLastError();
378 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
379 ok( error
== ERROR_INSUFFICIENT_BUFFER
, "got %u, expected ERROR_INSUFFICIENT_BUFFER\n", error
);
380 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
381 ok( uc
.dwHostNameLength
== 15, "unexpected hostname length: %u\n", uc
.dwHostNameLength
);
382 ok( uc
.dwUrlPathLength
== 11, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
385 reset_url_components( &uc
);
386 SetLastError( 0xdeadbeef );
387 ret
= WinHttpCrackUrl( url_k1
, 0, 0, &uc
);
388 error
= GetLastError();
389 ok( ret
, "WinHttpCrackUrl failed le=%u\n", error
);
390 ok( error
== ERROR_SUCCESS
|| broken(error
== ERROR_INVALID_PARAMETER
) /* < win7 */,
391 "got %u, expected ERROR_SUCCESS\n", error
);
392 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
393 ok( uc
.lpszScheme
== url_k1
,"unexpected scheme\n" );
394 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
395 ok( uc
.lpszUserName
== url_k1
+ 7, "unexpected username\n" );
396 ok( uc
.dwUserNameLength
== 8, "unexpected username length\n" );
397 ok( uc
.lpszPassword
== url_k1
+ 16, "unexpected password\n" );
398 ok( uc
.dwPasswordLength
== 8, "unexpected password length\n" );
399 ok( uc
.lpszHostName
== url_k1
+ 25, "unexpected hostname\n" );
400 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
401 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
402 ok( uc
.lpszUrlPath
== url_k1
+ 39, "unexpected path\n" );
403 ok( uc
.dwUrlPathLength
== 11, "unexpected path length\n" );
404 ok( uc
.lpszExtraInfo
== url_k1
+ 50, "unexpected extra info\n" );
405 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
407 reset_url_components( &uc
);
408 uc
.dwSchemeLength
= uc
.dwHostNameLength
= uc
.dwUserNameLength
= 1;
409 uc
.dwPasswordLength
= uc
.dwUrlPathLength
= uc
.dwExtraInfoLength
= 1;
410 ret
= WinHttpCrackUrl( url_k2
, 0, 0,&uc
);
411 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
412 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
413 ok( uc
.lpszScheme
== url_k2
, "unexpected scheme\n" );
414 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
415 ok( uc
.lpszUserName
== NULL
,"unexpected username\n" );
416 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
417 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
418 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
419 ok( uc
.lpszHostName
== url_k2
+ 7, "unexpected hostname\n" );
420 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
421 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
422 ok( uc
.lpszUrlPath
== url_k2
+ 21, "unexpected path\n" );
423 ok( uc
.dwUrlPathLength
== 0, "unexpected path length\n" );
424 ok( uc
.lpszExtraInfo
== url_k2
+ 21, "unexpected extra info\n" );
425 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
427 reset_url_components( &uc
);
428 ret
= WinHttpCrackUrl( url_k3
, 0, 0, &uc
);
429 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
430 ok( uc
.nScheme
== INTERNET_SCHEME_HTTPS
, "unexpected scheme\n" );
431 ok( uc
.lpszScheme
== url_k3
, "unexpected scheme\n" );
432 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length\n" );
433 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
434 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
435 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
436 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
437 ok( uc
.lpszHostName
== url_k3
+ 8, "unexpected hostname\n" );
438 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
439 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
440 ok( uc
.lpszUrlPath
== url_k3
+ 22, "unexpected path\n" );
441 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
442 ok( uc
.lpszExtraInfo
== url_k3
+ 27, "unexpected extra info\n" );
443 ok( uc
.dwExtraInfoLength
== 1, "unexpected extra info length\n" );
446 reset_url_components( &uc
);
447 SetLastError( 0xdeadbeef );
448 ret
= WinHttpCrackUrl( url_k4
, 0, 0, &uc
);
449 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
450 error
= GetLastError();
451 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
453 reset_url_components( &uc
);
454 SetLastError( 0xdeadbeef );
455 ret
= WinHttpCrackUrl( url_k5
, 0, 0, &uc
);
456 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
457 error
= GetLastError();
458 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
460 reset_url_components( &uc
);
461 SetLastError( 0xdeadbeef );
462 ret
= WinHttpCrackUrl( url_k6
, 0, 0, &uc
);
463 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
464 error
= GetLastError();
465 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
467 reset_url_components( &uc
);
468 SetLastError( 0xdeadbeef );
469 ret
= WinHttpCrackUrl( url_k7
, 0, 0, &uc
);
470 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
471 error
= GetLastError();
472 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
474 reset_url_components( &uc
);
475 SetLastError( 0xdeadbeef );
476 ret
= WinHttpCrackUrl( url_k8
, 0, 0, &uc
);
477 error
= GetLastError();
478 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
479 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
481 reset_url_components( &uc
);
482 ret
= WinHttpCrackUrl( url_k9
, 0, 0, &uc
);
483 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
484 ok( uc
.lpszUrlPath
== url_k9
+ 14 || broken(uc
.lpszUrlPath
== url_k9
+ 13) /* win8 */,
485 "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
486 ok( uc
.dwUrlPathLength
== 0, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
487 ok( uc
.lpszExtraInfo
== url_k9
+ 14 || broken(uc
.lpszExtraInfo
== url_k9
+ 13) /* win8 */,
488 "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
489 ok( uc
.dwExtraInfoLength
== 0 || broken(uc
.dwExtraInfoLength
== 1) /* win8 */,
490 "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
492 reset_url_components( &uc
);
493 ret
= WinHttpCrackUrl( url_k10
, 0, 0, &uc
);
494 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
495 ok( uc
.lpszUrlPath
== url_k10
+ 13, "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
496 ok( uc
.dwUrlPathLength
== 7, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
497 ok( uc
.lpszExtraInfo
== url_k10
+ 20, "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
498 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
500 reset_url_components( &uc
);
501 SetLastError( 0xdeadbeef );
502 ret
= WinHttpCrackUrl( url4
, 0, 0, &uc
);
503 error
= GetLastError();
504 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
505 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
507 reset_url_components( &uc
);
508 SetLastError( 0xdeadbeef );
509 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
510 error
= GetLastError();
511 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
512 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
514 SetLastError( 0xdeadbeef );
515 ret
= WinHttpCrackUrl( url1
, 0, 0, NULL
);
516 error
= GetLastError();
517 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
518 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
520 SetLastError( 0xdeadbeef );
521 ret
= WinHttpCrackUrl( NULL
, 0, 0, &uc
);
522 error
= GetLastError();
523 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
524 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
526 /* decoding without buffers */
527 reset_url_components( &uc
);
528 SetLastError(0xdeadbeef);
529 ret
= WinHttpCrackUrl( url7
, 0, ICU_DECODE
, &uc
);
530 error
= GetLastError();
531 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
532 ok( error
== ERROR_INVALID_PARAMETER
, "got %u, expected ERROR_INVALID_PARAMETER\n", error
);
534 /* decoding with buffers */
535 uc
.lpszScheme
= scheme
;
536 uc
.dwSchemeLength
= 20;
537 uc
.lpszUserName
= user
;
538 uc
.dwUserNameLength
= 20;
539 uc
.lpszPassword
= pass
;
540 uc
.dwPasswordLength
= 20;
541 uc
.lpszHostName
= host
;
542 uc
.dwHostNameLength
= 20;
544 uc
.lpszUrlPath
= path
;
545 uc
.dwUrlPathLength
= 80;
546 uc
.lpszExtraInfo
= extra
;
547 uc
.dwExtraInfoLength
= 40;
550 ret
= WinHttpCrackUrl( url7
, 0, ICU_DECODE
, &uc
);
551 ok( ret
, "WinHttpCrackUrl failed %u\n", GetLastError() );
552 ok( !memcmp( uc
.lpszUrlPath
+ 11, escape
, 21 * sizeof(WCHAR
) ), "unexpected path\n" );
553 ok( uc
.dwUrlPathLength
== 32, "unexpected path length %u\n", uc
.dwUrlPathLength
);
554 ok( !memcmp( uc
.lpszExtraInfo
, escape
+ 21, 12 * sizeof(WCHAR
) ), "unexpected extra info\n" );
555 ok( uc
.dwExtraInfoLength
== 12, "unexpected extra info length %u\n", uc
.dwExtraInfoLength
);
557 /* Urls with specified port numbers */
558 /* decoding with buffers */
559 uc
.lpszScheme
= scheme
;
560 uc
.dwSchemeLength
= 20;
561 uc
.lpszUserName
= user
;
562 uc
.dwUserNameLength
= 20;
563 uc
.lpszPassword
= pass
;
564 uc
.dwPasswordLength
= 20;
565 uc
.lpszHostName
= host
;
566 uc
.dwHostNameLength
= 20;
568 uc
.lpszUrlPath
= path
;
569 uc
.dwUrlPathLength
= 40;
570 uc
.lpszExtraInfo
= extra
;
571 uc
.dwExtraInfoLength
= 20;
574 ret
= WinHttpCrackUrl( url6
, 0, 0, &uc
);
575 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
576 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected host name: %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
577 ok( uc
.dwHostNameLength
== 14, "unexpected host name length: %d\n", uc
.dwHostNameLength
);
578 ok( uc
.nPort
== 42, "unexpected port: %u\n", uc
.nPort
);
580 /* decoding without buffers */
581 reset_url_components( &uc
);
582 ret
= WinHttpCrackUrl( url8
, 0, 0, &uc
);
583 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
584 ok( uc
.nPort
== 0, "unexpected port: %u\n", uc
.nPort
);
586 reset_url_components( &uc
);
587 ret
= WinHttpCrackUrl( url9
, 0, 0, &uc
);
588 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
589 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
591 reset_url_components( &uc
);
592 ret
= WinHttpCrackUrl( url10
, 0, 0, &uc
);
593 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
594 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
596 reset_url_components( &uc
);
597 SetLastError( 0xdeadbeef );
598 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
599 error
= GetLastError();
600 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
601 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
603 reset_url_components( &uc
);
604 SetLastError( 0xdeadbeef );
605 ret
= WinHttpCrackUrl( http
, 0, 0, &uc
);
606 error
= GetLastError();
607 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
608 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
610 reset_url_components( &uc
);
611 ret
= WinHttpCrackUrl( url11
, 0, 0, &uc
);
612 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
613 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
614 ok( uc
.lpszScheme
== url11
,"unexpected scheme\n" );
615 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
616 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
617 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
618 ok( uc
.lpszHostName
== url11
+ 7, "unexpected hostname\n" );
619 ok( uc
.dwHostNameLength
== 11, "unexpected hostname length\n" );
620 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
621 ok( uc
.lpszUrlPath
== url11
+ 18, "unexpected path\n" );
622 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
623 ok( uc
.lpszExtraInfo
== url11
+ 23, "unexpected extra info\n" );
624 ok( uc
.dwExtraInfoLength
== 39, "unexpected extra info length\n" );
626 uc
.lpszScheme
= scheme
;
627 uc
.dwSchemeLength
= 20;
628 uc
.lpszHostName
= host
;
629 uc
.dwHostNameLength
= 20;
630 uc
.lpszUserName
= NULL
;
631 uc
.dwUserNameLength
= 0;
632 uc
.lpszPassword
= NULL
;
633 uc
.dwPasswordLength
= 0;
634 uc
.lpszUrlPath
= path
;
635 uc
.dwUrlPathLength
= 40;
636 uc
.lpszExtraInfo
= NULL
;
637 uc
.dwExtraInfoLength
= 0;
639 ret
= WinHttpCrackUrl( url12
, 0, ICU_DECODE
, &uc
);
640 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
642 uc
.lpszScheme
= scheme
;
643 uc
.dwSchemeLength
= 20;
644 uc
.lpszHostName
= host
;
645 uc
.dwHostNameLength
= 20;
646 uc
.lpszUserName
= NULL
;
647 uc
.dwUserNameLength
= 0;
648 uc
.lpszPassword
= NULL
;
649 uc
.dwPasswordLength
= 0;
650 uc
.lpszUrlPath
= path
;
651 uc
.dwUrlPathLength
= 40;
652 uc
.lpszExtraInfo
= NULL
;
653 uc
.dwExtraInfoLength
= 0;
655 ret
= WinHttpCrackUrl( url13
, 0, ICU_ESCAPE
|ICU_DECODE
, &uc
);
656 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
657 ok( !lstrcmpW( uc
.lpszHostName
, hostnameW
), "unexpected host name\n" );
658 ok( !lstrcmpW( uc
.lpszUrlPath
, pathW
), "unexpected path\n" );
660 uc
.dwStructSize
= sizeof(uc
);
661 uc
.lpszScheme
= NULL
;
662 uc
.dwSchemeLength
= 0;
664 uc
.lpszHostName
= NULL
;
665 uc
.dwHostNameLength
= ~0u;
667 uc
.lpszUserName
= NULL
;
668 uc
.dwUserNameLength
= ~0u;
669 uc
.lpszPassword
= NULL
;
670 uc
.dwPasswordLength
= ~0u;
671 uc
.lpszUrlPath
= NULL
;
672 uc
.dwUrlPathLength
= ~0u;
673 uc
.lpszExtraInfo
= NULL
;
674 uc
.dwExtraInfoLength
= ~0u;
675 ret
= WinHttpCrackUrl( url14
, 0, 0, &uc
);
676 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
677 ok( !uc
.lpszScheme
, "unexpected scheme %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
678 ok( !uc
.dwSchemeLength
, "unexpected length %u\n", uc
.dwSchemeLength
);
679 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme %u\n", uc
.nScheme
);
680 ok( !lstrcmpW( uc
.lpszHostName
, url14
+ 7 ), "unexpected hostname %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
681 ok( uc
.dwHostNameLength
== 14, "unexpected length %u\n", uc
.dwHostNameLength
);
682 ok( uc
.nPort
== 80, "unexpected port %u\n", uc
.nPort
);
683 ok( !uc
.lpszUserName
, "unexpected username\n" );
684 ok( !uc
.dwUserNameLength
, "unexpected length %u\n", uc
.dwUserNameLength
);
685 ok( !uc
.lpszPassword
, "unexpected password\n" );
686 ok( !uc
.dwPasswordLength
, "unexpected length %u\n", uc
.dwPasswordLength
);
687 ok( !lstrcmpW( uc
.lpszUrlPath
, url14
+ 21 ), "unexpected path %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
688 ok( uc
.dwUrlPathLength
== 5, "unexpected length %u\n", uc
.dwUrlPathLength
);
689 ok( !uc
.lpszExtraInfo
[0], "unexpected extra info %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
690 ok( uc
.dwExtraInfoLength
== 0, "unexpected length %u\n", uc
.dwExtraInfoLength
);
692 uc
.dwStructSize
= sizeof(uc
);
693 uc
.lpszScheme
= scheme
;
694 uc
.dwSchemeLength
= 0;
696 uc
.lpszHostName
= NULL
;
697 uc
.dwHostNameLength
= 0;
699 uc
.lpszUserName
= NULL
;
700 uc
.dwUserNameLength
= ~0u;
701 uc
.lpszPassword
= NULL
;
702 uc
.dwPasswordLength
= ~0u;
703 uc
.lpszUrlPath
= NULL
;
704 uc
.dwUrlPathLength
= 0;
705 uc
.lpszExtraInfo
= NULL
;
706 uc
.dwExtraInfoLength
= 0;
707 SetLastError( 0xdeadbeef );
708 ret
= WinHttpCrackUrl( url14
, 0, 0, &uc
);
709 error
= GetLastError();
710 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
711 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
712 ok( !lstrcmpW( uc
.lpszScheme
, http
), "unexpected scheme %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
713 ok( !uc
.dwSchemeLength
, "unexpected length %u\n", uc
.dwSchemeLength
);
714 ok( uc
.nScheme
== 0, "unexpected scheme %u\n", uc
.nScheme
);
715 ok( !uc
.lpszHostName
, "unexpected hostname %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
716 ok( uc
.dwHostNameLength
== 0, "unexpected length %u\n", uc
.dwHostNameLength
);
717 ok( uc
.nPort
== 0, "unexpected port %u\n", uc
.nPort
);
718 ok( !uc
.lpszUserName
, "unexpected username\n" );
719 ok( uc
.dwUserNameLength
== ~0u, "unexpected length %u\n", uc
.dwUserNameLength
);
720 ok( !uc
.lpszPassword
, "unexpected password\n" );
721 ok( uc
.dwPasswordLength
== ~0u, "unexpected length %u\n", uc
.dwPasswordLength
);
722 ok( !uc
.lpszUrlPath
, "unexpected path %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
723 ok( uc
.dwUrlPathLength
== 0, "unexpected length %u\n", uc
.dwUrlPathLength
);
724 ok( !uc
.lpszExtraInfo
, "unexpected extra info %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
725 ok( uc
.dwExtraInfoLength
== 0, "unexpected length %u\n", uc
.dwExtraInfoLength
);
727 reset_url_components( &uc
);
728 SetLastError( 0xdeadbeef );
729 ret
= WinHttpCrackUrl( url15
, 0, 0, &uc
);
730 error
= GetLastError();
731 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
732 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
734 reset_url_components( &uc
);
736 ret
= WinHttpCrackUrl( url16
, 0, 0, &uc
);
737 ok( ret
, "got %u\n", GetLastError() );
738 ok( !uc
.nPort
, "got %u\n", uc
.nPort
);
740 reset_url_components( &uc
);
742 ret
= WinHttpCrackUrl( url17
, 0, 0, &uc
);
743 ok( ret
, "got %u\n", GetLastError() );
744 todo_wine
ok( uc
.nPort
== 80, "got %u\n", uc
.nPort
);
749 WinHttpCreateUrl_test();
750 WinHttpCrackUrl_test();