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};
37 static WCHAR escape2
[] = {'\r',0x1f,' ','\n',0x7f,'\r','\n',0};
39 static const WCHAR url1
[] =
40 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
41 '@','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};
42 static const WCHAR url2
[] = {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':',0};
43 static const WCHAR url3
[] =
44 {'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};
45 static const WCHAR url4
[] = {'h','t','t','p',':','/','/',0};
46 static const WCHAR url5
[] =
47 {'f','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
48 '@','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};
49 static const WCHAR url6
[] =
50 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
51 '@','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};
52 static const WCHAR url7
[] =
53 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
54 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',
55 '%','2','0','!','%','2','2','%','2','3','$','%','2','5','&','\'','(',')','*','+',',','-','.','/',':',';','%','3','C','=','%','3','E','?','@','%',
56 '5','B','%','5','C','%','5','D','%','5','E','_','%','6','0','%','7','B','%','7','C','%','7','D','%','7','E',0};
57 static const WCHAR url8
[] =
58 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
59 '@','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};
60 static const WCHAR url9
[] =
61 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
62 '@','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};
63 static const WCHAR url10
[] =
64 {'h','t','t','p','s',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
65 '@','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};
66 static const WCHAR url11
[] =
67 {'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};
68 static const WCHAR url12
[] =
69 {'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};
70 static const WCHAR url13
[] =
71 {'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};
72 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};
73 static const WCHAR url15
[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',':','6','5','5','3','6',0};
74 static const WCHAR url16
[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',':','0',0};
75 static const WCHAR url17
[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',':',0};
76 static const WCHAR url18
[] =
77 {'h','t','t','p',':','/','/','%','0','D','%','1','F','%','2','0','%','0','A','%','7','F','%','0','D','%','0','A',0};
79 static const WCHAR url_k1
[] =
80 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
81 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
82 static const WCHAR url_k2
[] =
83 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
84 static const WCHAR url_k3
[] =
85 {'h','t','t','p','s',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','p','o','s','t','?',0};
86 static const WCHAR url_k4
[] =
87 {'H','T','T','P',':','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
88 static const WCHAR url_k5
[] =
89 {'h','t','t','p',':','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
90 static const WCHAR url_k6
[] =
91 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
92 static const WCHAR url_k7
[] =
94 static const WCHAR url_k8
[] =
96 static const WCHAR url_k9
[] =
97 {'h','t','t','p',':','/','/','w','i','n','e','h','q','?',0};
98 static const WCHAR url_k10
[] =
99 {'h','t','t','p',':','/','/','w','i','n','e','h','q','/','p','o','s','t',';','a',0};
101 static void fill_url_components( URL_COMPONENTS
*uc
)
103 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
104 uc
->lpszScheme
= http
;
105 uc
->dwSchemeLength
= lstrlenW( uc
->lpszScheme
);
106 uc
->nScheme
= INTERNET_SCHEME_HTTP
;
107 uc
->lpszHostName
= winehq
;
108 uc
->dwHostNameLength
= lstrlenW( uc
->lpszHostName
);
110 uc
->lpszUserName
= username
;
111 uc
->dwUserNameLength
= lstrlenW( uc
->lpszUserName
);
112 uc
->lpszPassword
= password
;
113 uc
->dwPasswordLength
= lstrlenW( uc
->lpszPassword
);
114 uc
->lpszUrlPath
= about
;
115 uc
->dwUrlPathLength
= lstrlenW( uc
->lpszUrlPath
);
116 uc
->lpszExtraInfo
= query
;
117 uc
->dwExtraInfoLength
= lstrlenW( uc
->lpszExtraInfo
);
120 static void WinHttpCreateUrl_test( void )
127 /* NULL components */
129 SetLastError( 0xdeadbeef );
130 ret
= WinHttpCreateUrl( NULL
, 0, NULL
, &len
);
131 ok( !ret
, "expected failure\n" );
132 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
133 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
135 /* zero'ed components */
136 memset( &uc
, 0, sizeof(URL_COMPONENTS
) );
137 SetLastError( 0xdeadbeef );
138 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
139 ok( !ret
, "expected failure\n" );
140 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
141 ok( len
== ~0u, "expected len ~0u got %u\n", len
);
143 /* valid components, NULL url, NULL length */
144 fill_url_components( &uc
);
145 SetLastError( 0xdeadbeef );
146 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, NULL
);
147 ok( !ret
, "expected failure\n" );
148 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
150 /* valid components, NULL url, insufficient length */
152 SetLastError( 0xdeadbeef );
153 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
154 ok( !ret
, "expected failure\n" );
155 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
156 ok( len
== 57, "expected len 57 got %u\n", len
);
158 /* valid components, NULL url, sufficient length */
159 SetLastError( 0xdeadbeef );
161 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
162 err
= GetLastError();
163 ok( !ret
, "expected failure\n" );
164 ok( err
== ERROR_INVALID_PARAMETER
|| broken(err
== ERROR_INSUFFICIENT_BUFFER
) /* < win7 */,
165 "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
166 ok( len
== 256 || broken(len
== 57) /* < win7 */, "expected len 256 got %u\n", len
);
168 /* correct size, NULL url */
169 fill_url_components( &uc
);
170 SetLastError( 0xdeadbeef );
171 ret
= WinHttpCreateUrl( &uc
, 0, NULL
, &len
);
172 err
= GetLastError();
173 ok( !ret
, "expected failure\n" );
174 ok( err
== ERROR_INVALID_PARAMETER
|| broken(err
== ERROR_INSUFFICIENT_BUFFER
) /* < win7 */,
175 "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
176 ok( len
== 256 || broken(len
== 57) /* < win7 */, "expected len 256 got %u\n", len
);
178 /* valid components, allocated url, short length */
179 SetLastError( 0xdeadbeef );
180 url
= HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR
) );
183 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
184 ok( !ret
, "expected failure\n" );
185 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
186 ok( len
== 57, "expected len 57 got %u\n", len
);
188 /* allocated url, NULL scheme */
189 SetLastError( 0xdeadbeef );
190 uc
.lpszScheme
= NULL
;
193 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
194 ok( ret
, "expected success\n" );
195 ok( GetLastError() == ERROR_SUCCESS
|| broken(GetLastError() == 0xdeadbeef) /* < win7 */,
196 "expected ERROR_SUCCESS got %u\n", GetLastError() );
197 ok( len
== 56, "expected len 56 got %u\n", len
);
198 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
200 /* allocated url, 0 scheme */
201 fill_url_components( &uc
);
205 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
206 ok( ret
, "expected success\n" );
207 ok( len
== 56, "expected len 56 got %u\n", len
);
209 /* valid components, allocated url */
210 fill_url_components( &uc
);
213 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
214 ok( ret
, "expected success\n" );
215 ok( len
== 56, "expected len 56 got %d\n", len
);
216 ok( !lstrcmpW( url
, url1
), "url doesn't match\n" );
218 /* valid username, NULL password */
219 fill_url_components( &uc
);
220 uc
.lpszPassword
= NULL
;
223 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
224 ok( ret
, "expected success\n" );
226 /* valid username, empty password */
227 fill_url_components( &uc
);
228 uc
.lpszPassword
= empty
;
231 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
232 ok( ret
, "expected success\n" );
233 ok( len
== 56, "expected len 56 got %u\n", len
);
234 ok( !lstrcmpW( url
, url2
), "url doesn't match\n" );
236 /* valid password, NULL username */
237 fill_url_components( &uc
);
238 SetLastError( 0xdeadbeef );
239 uc
.lpszUserName
= NULL
;
242 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
243 ok( !ret
, "expected failure\n" );
244 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
246 /* valid password, empty username */
247 fill_url_components( &uc
);
248 uc
.lpszUserName
= empty
;
251 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
252 ok( ret
, "expected success\n");
254 /* NULL username, NULL password */
255 fill_url_components( &uc
);
256 uc
.lpszUserName
= NULL
;
257 uc
.lpszPassword
= NULL
;
260 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
261 ok( ret
, "expected success\n" );
262 ok( len
== 38, "expected len 38 got %u\n", len
);
263 ok( !lstrcmpW( url
, url3
), "url doesn't match\n" );
265 /* empty username, empty password */
266 fill_url_components( &uc
);
267 uc
.lpszUserName
= empty
;
268 uc
.lpszPassword
= empty
;
271 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
272 ok( ret
, "expected success\n" );
273 ok( len
== 56, "expected len 56 got %u\n", len
);
274 ok( !lstrcmpW( url
, url4
), "url doesn't match\n" );
276 /* nScheme has lower precedence than lpszScheme */
277 fill_url_components( &uc
);
279 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
282 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
283 ok( ret
, "expected success\n" );
284 ok( len
== lstrlenW( url5
), "expected len %d got %u\n", lstrlenW( url5
) + 1, len
);
285 ok( !lstrcmpW( url
, url5
), "url doesn't match\n" );
287 /* non-standard port */
288 uc
.lpszScheme
= http
;
289 uc
.dwSchemeLength
= lstrlenW( uc
.lpszScheme
);
293 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
294 ok( ret
, "expected success\n" );
295 ok( len
== 59, "expected len 59 got %u\n", len
);
296 ok( !lstrcmpW( url
, url6
), "url doesn't match\n" );
298 /* escape extra info */
299 fill_url_components( &uc
);
300 uc
.lpszExtraInfo
= escape
;
301 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
304 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
305 ok( ret
, "expected success\n" );
306 ok( len
== 113, "expected len 113 got %u\n", len
);
307 ok( !lstrcmpW( url
, url7
), "url doesn't match %s\n", wine_dbgstr_w(url
) );
309 /* escape extra info */
310 memset( &uc
, 0, sizeof(uc
) );
311 uc
.dwStructSize
= sizeof(uc
);
312 uc
.lpszExtraInfo
= escape2
;
313 uc
.dwExtraInfoLength
= lstrlenW( uc
.lpszExtraInfo
);
316 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
317 ok( ret
, "expected success\n" );
318 ok( len
== lstrlenW(url18
), "expected len %u got %u\n", lstrlenW(url18
), len
);
319 ok( !lstrcmpW( url
, url18
), "url doesn't match\n" );
322 memset( &uc
, 0, sizeof(uc
) );
323 uc
.dwStructSize
= sizeof(uc
);
324 uc
.lpszUrlPath
= escape2
;
325 uc
.dwUrlPathLength
= lstrlenW( uc
.lpszUrlPath
);
328 ret
= WinHttpCreateUrl( &uc
, ICU_ESCAPE
, url
, &len
);
329 ok( ret
, "expected success\n" );
330 ok( len
== lstrlenW(url18
), "expected len %u got %u\n", lstrlenW(url18
), len
);
331 ok( !lstrcmpW( url
, url18
), "url doesn't match\n" );
333 /* NULL lpszScheme, 0 nScheme and nPort */
334 fill_url_components( &uc
);
335 uc
.lpszScheme
= NULL
;
336 uc
.dwSchemeLength
= 0;
341 ret
= WinHttpCreateUrl( &uc
, 0, url
, &len
);
342 ok( ret
, "expected success\n" );
343 ok( len
== 58, "expected len 58 got %u\n", len
);
344 ok( !lstrcmpW( url
, url8
), "url doesn't match\n" );
346 HeapFree( GetProcessHeap(), 0, url
);
349 static void reset_url_components( URL_COMPONENTS
*uc
)
351 memset( uc
, 0, sizeof(URL_COMPONENTS
) );
352 uc
->dwStructSize
= sizeof(URL_COMPONENTS
);
353 uc
->dwSchemeLength
= ~0u;
354 uc
->dwHostNameLength
= 1;
356 uc
->dwUserNameLength
= ~0u;
357 uc
->dwPasswordLength
= ~0u;
358 uc
->dwUrlPathLength
= ~0u;
359 uc
->dwExtraInfoLength
= ~0u;
362 static void WinHttpCrackUrl_test( void )
364 static const WCHAR hostnameW
[] =
365 {'w','i','n','e','h','q','.','o',' ','g',0};
366 static const WCHAR pathW
[] =
367 {'/','p','a','t','h','%','2','0','w','i','t','h','%','2','0','s','p','a','c','e','s',0};
369 WCHAR scheme
[20], user
[20], pass
[20], host
[20], path
[80], extra
[40];
373 /* buffers of sufficient length */
374 scheme
[0] = user
[0] = pass
[0] = host
[0] = path
[0] = extra
[0] = 0;
376 uc
.dwStructSize
= sizeof(URL_COMPONENTS
);
378 uc
.lpszScheme
= scheme
;
379 uc
.dwSchemeLength
= 20;
380 uc
.lpszUserName
= user
;
381 uc
.dwUserNameLength
= 20;
382 uc
.lpszPassword
= pass
;
383 uc
.dwPasswordLength
= 20;
384 uc
.lpszHostName
= host
;
385 uc
.dwHostNameLength
= 20;
387 uc
.lpszUrlPath
= path
;
388 uc
.dwUrlPathLength
= 40;
389 uc
.lpszExtraInfo
= extra
;
390 uc
.dwExtraInfoLength
= 20;
392 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
393 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
394 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme: %u\n", uc
.nScheme
);
395 ok( !memcmp( uc
.lpszScheme
, http
, sizeof(http
) ), "unexpected scheme: %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
396 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
397 ok( !memcmp( uc
.lpszUserName
, username
, sizeof(username
) ), "unexpected username: %s\n", wine_dbgstr_w(uc
.lpszUserName
) );
398 ok( uc
.dwUserNameLength
== 8, "unexpected username length: %u\n", uc
.dwUserNameLength
);
399 ok( !memcmp( uc
.lpszPassword
, password
, sizeof(password
) ), "unexpected password: %s\n", wine_dbgstr_w(uc
.lpszPassword
) );
400 ok( uc
.dwPasswordLength
== 8, "unexpected password length: %u\n", uc
.dwPasswordLength
);
401 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected hostname: %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
402 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length: %u\n", uc
.dwHostNameLength
);
403 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
404 ok( !memcmp( uc
.lpszUrlPath
, about
, sizeof(about
) ), "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
405 ok( uc
.dwUrlPathLength
== 11, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
406 ok( !memcmp( uc
.lpszExtraInfo
, query
, sizeof(query
) ), "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
407 ok( uc
.dwExtraInfoLength
== 6, "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
409 /* buffers of insufficient length */
410 uc
.dwSchemeLength
= 1;
411 uc
.dwHostNameLength
= 1;
412 uc
.dwUrlPathLength
= 40; /* sufficient */
413 SetLastError( 0xdeadbeef );
414 ret
= WinHttpCrackUrl( url1
, 0, 0, &uc
);
415 error
= GetLastError();
416 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
417 ok( error
== ERROR_INSUFFICIENT_BUFFER
, "got %u, expected ERROR_INSUFFICIENT_BUFFER\n", error
);
418 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length: %u\n", uc
.dwSchemeLength
);
419 ok( uc
.dwHostNameLength
== 15, "unexpected hostname length: %u\n", uc
.dwHostNameLength
);
420 ok( uc
.dwUrlPathLength
== 11, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
423 reset_url_components( &uc
);
424 SetLastError( 0xdeadbeef );
425 ret
= WinHttpCrackUrl( url_k1
, 0, 0, &uc
);
426 error
= GetLastError();
427 ok( ret
, "WinHttpCrackUrl failed le=%u\n", error
);
428 ok( error
== ERROR_SUCCESS
|| broken(error
== ERROR_INVALID_PARAMETER
) /* < win7 */,
429 "got %u, expected ERROR_SUCCESS\n", error
);
430 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
431 ok( uc
.lpszScheme
== url_k1
,"unexpected scheme\n" );
432 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
433 ok( uc
.lpszUserName
== url_k1
+ 7, "unexpected username\n" );
434 ok( uc
.dwUserNameLength
== 8, "unexpected username length\n" );
435 ok( uc
.lpszPassword
== url_k1
+ 16, "unexpected password\n" );
436 ok( uc
.dwPasswordLength
== 8, "unexpected password length\n" );
437 ok( uc
.lpszHostName
== url_k1
+ 25, "unexpected hostname\n" );
438 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
439 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
440 ok( uc
.lpszUrlPath
== url_k1
+ 39, "unexpected path\n" );
441 ok( uc
.dwUrlPathLength
== 11, "unexpected path length\n" );
442 ok( uc
.lpszExtraInfo
== url_k1
+ 50, "unexpected extra info\n" );
443 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
445 reset_url_components( &uc
);
446 uc
.dwSchemeLength
= uc
.dwHostNameLength
= uc
.dwUserNameLength
= 1;
447 uc
.dwPasswordLength
= uc
.dwUrlPathLength
= uc
.dwExtraInfoLength
= 1;
448 ret
= WinHttpCrackUrl( url_k2
, 0, 0,&uc
);
449 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
450 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
451 ok( uc
.lpszScheme
== url_k2
, "unexpected scheme\n" );
452 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
453 ok( uc
.lpszUserName
== NULL
,"unexpected username\n" );
454 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
455 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
456 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
457 ok( uc
.lpszHostName
== url_k2
+ 7, "unexpected hostname\n" );
458 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
459 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
460 ok( uc
.lpszUrlPath
== url_k2
+ 21, "unexpected path\n" );
461 ok( uc
.dwUrlPathLength
== 0, "unexpected path length\n" );
462 ok( uc
.lpszExtraInfo
== url_k2
+ 21, "unexpected extra info\n" );
463 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length\n" );
465 reset_url_components( &uc
);
466 ret
= WinHttpCrackUrl( url_k3
, 0, 0, &uc
);
467 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
468 ok( uc
.nScheme
== INTERNET_SCHEME_HTTPS
, "unexpected scheme\n" );
469 ok( uc
.lpszScheme
== url_k3
, "unexpected scheme\n" );
470 ok( uc
.dwSchemeLength
== 5, "unexpected scheme length\n" );
471 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
472 ok( uc
.dwUserNameLength
== 0, "unexpected username length\n" );
473 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
474 ok( uc
.dwPasswordLength
== 0, "unexpected password length\n" );
475 ok( uc
.lpszHostName
== url_k3
+ 8, "unexpected hostname\n" );
476 ok( uc
.dwHostNameLength
== 14, "unexpected hostname length\n" );
477 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
478 ok( uc
.lpszUrlPath
== url_k3
+ 22, "unexpected path\n" );
479 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
480 ok( uc
.lpszExtraInfo
== url_k3
+ 27, "unexpected extra info\n" );
481 ok( uc
.dwExtraInfoLength
== 1, "unexpected extra info length\n" );
484 reset_url_components( &uc
);
485 SetLastError( 0xdeadbeef );
486 ret
= WinHttpCrackUrl( url_k4
, 0, 0, &uc
);
487 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
488 error
= GetLastError();
489 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
491 reset_url_components( &uc
);
492 SetLastError( 0xdeadbeef );
493 ret
= WinHttpCrackUrl( url_k5
, 0, 0, &uc
);
494 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
495 error
= GetLastError();
496 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
498 reset_url_components( &uc
);
499 SetLastError( 0xdeadbeef );
500 ret
= WinHttpCrackUrl( url_k6
, 0, 0, &uc
);
501 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
502 error
= GetLastError();
503 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
505 reset_url_components( &uc
);
506 SetLastError( 0xdeadbeef );
507 ret
= WinHttpCrackUrl( url_k7
, 0, 0, &uc
);
508 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
509 error
= GetLastError();
510 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
512 reset_url_components( &uc
);
513 SetLastError( 0xdeadbeef );
514 ret
= WinHttpCrackUrl( url_k8
, 0, 0, &uc
);
515 error
= GetLastError();
516 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
517 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
519 reset_url_components( &uc
);
520 ret
= WinHttpCrackUrl( url_k9
, 0, 0, &uc
);
521 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
522 ok( uc
.lpszUrlPath
== url_k9
+ 14 || broken(uc
.lpszUrlPath
== url_k9
+ 13) /* win8 */,
523 "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
524 ok( uc
.dwUrlPathLength
== 0, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
525 ok( uc
.lpszExtraInfo
== url_k9
+ 14 || broken(uc
.lpszExtraInfo
== url_k9
+ 13) /* win8 */,
526 "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
527 ok( uc
.dwExtraInfoLength
== 0 || broken(uc
.dwExtraInfoLength
== 1) /* win8 */,
528 "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
530 reset_url_components( &uc
);
531 ret
= WinHttpCrackUrl( url_k10
, 0, 0, &uc
);
532 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
533 ok( uc
.lpszUrlPath
== url_k10
+ 13, "unexpected path: %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
534 ok( uc
.dwUrlPathLength
== 7, "unexpected path length: %u\n", uc
.dwUrlPathLength
);
535 ok( uc
.lpszExtraInfo
== url_k10
+ 20, "unexpected extra info: %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
536 ok( uc
.dwExtraInfoLength
== 0, "unexpected extra info length: %u\n", uc
.dwExtraInfoLength
);
538 reset_url_components( &uc
);
539 SetLastError( 0xdeadbeef );
540 ret
= WinHttpCrackUrl( url4
, 0, 0, &uc
);
541 error
= GetLastError();
542 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
543 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
545 reset_url_components( &uc
);
546 SetLastError( 0xdeadbeef );
547 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
548 error
= GetLastError();
549 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
550 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u\n", error
);
552 SetLastError( 0xdeadbeef );
553 ret
= WinHttpCrackUrl( url1
, 0, 0, NULL
);
554 error
= GetLastError();
555 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
556 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
558 SetLastError( 0xdeadbeef );
559 ret
= WinHttpCrackUrl( NULL
, 0, 0, &uc
);
560 error
= GetLastError();
561 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
562 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
564 /* decoding without buffers */
565 reset_url_components( &uc
);
566 SetLastError(0xdeadbeef);
567 ret
= WinHttpCrackUrl( url7
, 0, ICU_DECODE
, &uc
);
568 error
= GetLastError();
569 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
570 ok( error
== ERROR_INVALID_PARAMETER
, "got %u, expected ERROR_INVALID_PARAMETER\n", error
);
572 /* decoding with buffers */
573 uc
.lpszScheme
= scheme
;
574 uc
.dwSchemeLength
= 20;
575 uc
.lpszUserName
= user
;
576 uc
.dwUserNameLength
= 20;
577 uc
.lpszPassword
= pass
;
578 uc
.dwPasswordLength
= 20;
579 uc
.lpszHostName
= host
;
580 uc
.dwHostNameLength
= 20;
582 uc
.lpszUrlPath
= path
;
583 uc
.dwUrlPathLength
= 80;
584 uc
.lpszExtraInfo
= extra
;
585 uc
.dwExtraInfoLength
= 40;
588 ret
= WinHttpCrackUrl( url7
, 0, ICU_DECODE
, &uc
);
589 ok( ret
, "WinHttpCrackUrl failed %u\n", GetLastError() );
590 ok( !memcmp( uc
.lpszUrlPath
+ 11, escape
, 21 * sizeof(WCHAR
) ), "unexpected path\n" );
591 ok( uc
.dwUrlPathLength
== 32, "unexpected path length %u\n", uc
.dwUrlPathLength
);
592 ok( !memcmp( uc
.lpszExtraInfo
, escape
+ 21, 12 * sizeof(WCHAR
) ), "unexpected extra info\n" );
593 ok( uc
.dwExtraInfoLength
== 12, "unexpected extra info length %u\n", uc
.dwExtraInfoLength
);
595 /* Urls with specified port numbers */
596 /* decoding with buffers */
597 uc
.lpszScheme
= scheme
;
598 uc
.dwSchemeLength
= 20;
599 uc
.lpszUserName
= user
;
600 uc
.dwUserNameLength
= 20;
601 uc
.lpszPassword
= pass
;
602 uc
.dwPasswordLength
= 20;
603 uc
.lpszHostName
= host
;
604 uc
.dwHostNameLength
= 20;
606 uc
.lpszUrlPath
= path
;
607 uc
.dwUrlPathLength
= 40;
608 uc
.lpszExtraInfo
= extra
;
609 uc
.dwExtraInfoLength
= 20;
612 ret
= WinHttpCrackUrl( url6
, 0, 0, &uc
);
613 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
614 ok( !memcmp( uc
.lpszHostName
, winehq
, sizeof(winehq
) ), "unexpected host name: %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
615 ok( uc
.dwHostNameLength
== 14, "unexpected host name length: %d\n", uc
.dwHostNameLength
);
616 ok( uc
.nPort
== 42, "unexpected port: %u\n", uc
.nPort
);
618 /* decoding without buffers */
619 reset_url_components( &uc
);
620 ret
= WinHttpCrackUrl( url8
, 0, 0, &uc
);
621 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
622 ok( uc
.nPort
== 0, "unexpected port: %u\n", uc
.nPort
);
624 reset_url_components( &uc
);
625 ret
= WinHttpCrackUrl( url9
, 0, 0, &uc
);
626 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
627 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
629 reset_url_components( &uc
);
630 ret
= WinHttpCrackUrl( url10
, 0, 0, &uc
);
631 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
632 ok( uc
.nPort
== 443, "unexpected port: %u\n", uc
.nPort
);
634 reset_url_components( &uc
);
635 SetLastError( 0xdeadbeef );
636 ret
= WinHttpCrackUrl( empty
, 0, 0, &uc
);
637 error
= GetLastError();
638 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
639 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
641 reset_url_components( &uc
);
642 SetLastError( 0xdeadbeef );
643 ret
= WinHttpCrackUrl( http
, 0, 0, &uc
);
644 error
= GetLastError();
645 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
646 ok( error
== ERROR_WINHTTP_UNRECOGNIZED_SCHEME
, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error
);
648 reset_url_components( &uc
);
649 ret
= WinHttpCrackUrl( url11
, 0, 0, &uc
);
650 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
651 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme\n" );
652 ok( uc
.lpszScheme
== url11
,"unexpected scheme\n" );
653 ok( uc
.dwSchemeLength
== 4, "unexpected scheme length\n" );
654 ok( uc
.lpszUserName
== NULL
, "unexpected username\n" );
655 ok( uc
.lpszPassword
== NULL
, "unexpected password\n" );
656 ok( uc
.lpszHostName
== url11
+ 7, "unexpected hostname\n" );
657 ok( uc
.dwHostNameLength
== 11, "unexpected hostname length\n" );
658 ok( uc
.nPort
== 80, "unexpected port: %u\n", uc
.nPort
);
659 ok( uc
.lpszUrlPath
== url11
+ 18, "unexpected path\n" );
660 ok( uc
.dwUrlPathLength
== 5, "unexpected path length\n" );
661 ok( uc
.lpszExtraInfo
== url11
+ 23, "unexpected extra info\n" );
662 ok( uc
.dwExtraInfoLength
== 39, "unexpected extra info length\n" );
664 uc
.lpszScheme
= scheme
;
665 uc
.dwSchemeLength
= 20;
666 uc
.lpszHostName
= host
;
667 uc
.dwHostNameLength
= 20;
668 uc
.lpszUserName
= NULL
;
669 uc
.dwUserNameLength
= 0;
670 uc
.lpszPassword
= NULL
;
671 uc
.dwPasswordLength
= 0;
672 uc
.lpszUrlPath
= path
;
673 uc
.dwUrlPathLength
= 40;
674 uc
.lpszExtraInfo
= NULL
;
675 uc
.dwExtraInfoLength
= 0;
677 ret
= WinHttpCrackUrl( url12
, 0, ICU_DECODE
, &uc
);
678 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
680 uc
.lpszScheme
= scheme
;
681 uc
.dwSchemeLength
= 20;
682 uc
.lpszHostName
= host
;
683 uc
.dwHostNameLength
= 20;
684 uc
.lpszUserName
= NULL
;
685 uc
.dwUserNameLength
= 0;
686 uc
.lpszPassword
= NULL
;
687 uc
.dwPasswordLength
= 0;
688 uc
.lpszUrlPath
= path
;
689 uc
.dwUrlPathLength
= 40;
690 uc
.lpszExtraInfo
= NULL
;
691 uc
.dwExtraInfoLength
= 0;
693 ret
= WinHttpCrackUrl( url13
, 0, ICU_ESCAPE
|ICU_DECODE
, &uc
);
694 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
695 ok( !lstrcmpW( uc
.lpszHostName
, hostnameW
), "unexpected host name\n" );
696 ok( !lstrcmpW( uc
.lpszUrlPath
, pathW
), "unexpected path\n" );
697 ok( uc
.dwUrlPathLength
== lstrlenW(pathW
), "got %u\n", uc
.dwUrlPathLength
);
699 uc
.dwStructSize
= sizeof(uc
);
700 uc
.lpszScheme
= NULL
;
701 uc
.dwSchemeLength
= 0;
703 uc
.lpszHostName
= NULL
;
704 uc
.dwHostNameLength
= ~0u;
706 uc
.lpszUserName
= NULL
;
707 uc
.dwUserNameLength
= ~0u;
708 uc
.lpszPassword
= NULL
;
709 uc
.dwPasswordLength
= ~0u;
710 uc
.lpszUrlPath
= NULL
;
711 uc
.dwUrlPathLength
= ~0u;
712 uc
.lpszExtraInfo
= NULL
;
713 uc
.dwExtraInfoLength
= ~0u;
714 ret
= WinHttpCrackUrl( url14
, 0, 0, &uc
);
715 ok( ret
, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
716 ok( !uc
.lpszScheme
, "unexpected scheme %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
717 ok( !uc
.dwSchemeLength
, "unexpected length %u\n", uc
.dwSchemeLength
);
718 ok( uc
.nScheme
== INTERNET_SCHEME_HTTP
, "unexpected scheme %u\n", uc
.nScheme
);
719 ok( !lstrcmpW( uc
.lpszHostName
, url14
+ 7 ), "unexpected hostname %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
720 ok( uc
.dwHostNameLength
== 14, "unexpected length %u\n", uc
.dwHostNameLength
);
721 ok( uc
.nPort
== 80, "unexpected port %u\n", uc
.nPort
);
722 ok( !uc
.lpszUserName
, "unexpected username\n" );
723 ok( !uc
.dwUserNameLength
, "unexpected length %u\n", uc
.dwUserNameLength
);
724 ok( !uc
.lpszPassword
, "unexpected password\n" );
725 ok( !uc
.dwPasswordLength
, "unexpected length %u\n", uc
.dwPasswordLength
);
726 ok( !lstrcmpW( uc
.lpszUrlPath
, url14
+ 21 ), "unexpected path %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
727 ok( uc
.dwUrlPathLength
== 5, "unexpected length %u\n", uc
.dwUrlPathLength
);
728 ok( !uc
.lpszExtraInfo
[0], "unexpected extra info %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
729 ok( uc
.dwExtraInfoLength
== 0, "unexpected length %u\n", uc
.dwExtraInfoLength
);
731 uc
.dwStructSize
= sizeof(uc
);
732 uc
.lpszScheme
= scheme
;
733 uc
.dwSchemeLength
= 0;
735 uc
.lpszHostName
= NULL
;
736 uc
.dwHostNameLength
= 0;
738 uc
.lpszUserName
= NULL
;
739 uc
.dwUserNameLength
= ~0u;
740 uc
.lpszPassword
= NULL
;
741 uc
.dwPasswordLength
= ~0u;
742 uc
.lpszUrlPath
= NULL
;
743 uc
.dwUrlPathLength
= 0;
744 uc
.lpszExtraInfo
= NULL
;
745 uc
.dwExtraInfoLength
= 0;
746 SetLastError( 0xdeadbeef );
747 ret
= WinHttpCrackUrl( url14
, 0, 0, &uc
);
748 error
= GetLastError();
749 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
750 ok( error
== ERROR_INVALID_PARAMETER
, "got %u\n", error
);
751 ok( !lstrcmpW( uc
.lpszScheme
, http
), "unexpected scheme %s\n", wine_dbgstr_w(uc
.lpszScheme
) );
752 ok( !uc
.dwSchemeLength
, "unexpected length %u\n", uc
.dwSchemeLength
);
753 ok( uc
.nScheme
== 0, "unexpected scheme %u\n", uc
.nScheme
);
754 ok( !uc
.lpszHostName
, "unexpected hostname %s\n", wine_dbgstr_w(uc
.lpszHostName
) );
755 ok( uc
.dwHostNameLength
== 0, "unexpected length %u\n", uc
.dwHostNameLength
);
756 ok( uc
.nPort
== 0, "unexpected port %u\n", uc
.nPort
);
757 ok( !uc
.lpszUserName
, "unexpected username\n" );
758 ok( uc
.dwUserNameLength
== ~0u, "unexpected length %u\n", uc
.dwUserNameLength
);
759 ok( !uc
.lpszPassword
, "unexpected password\n" );
760 ok( uc
.dwPasswordLength
== ~0u, "unexpected length %u\n", uc
.dwPasswordLength
);
761 ok( !uc
.lpszUrlPath
, "unexpected path %s\n", wine_dbgstr_w(uc
.lpszUrlPath
) );
762 ok( uc
.dwUrlPathLength
== 0, "unexpected length %u\n", uc
.dwUrlPathLength
);
763 ok( !uc
.lpszExtraInfo
, "unexpected extra info %s\n", wine_dbgstr_w(uc
.lpszExtraInfo
) );
764 ok( uc
.dwExtraInfoLength
== 0, "unexpected length %u\n", uc
.dwExtraInfoLength
);
766 reset_url_components( &uc
);
767 SetLastError( 0xdeadbeef );
768 ret
= WinHttpCrackUrl( url15
, 0, 0, &uc
);
769 error
= GetLastError();
770 ok( !ret
, "WinHttpCrackUrl succeeded\n" );
771 ok( error
== ERROR_WINHTTP_INVALID_URL
, "got %u\n", error
);
773 reset_url_components( &uc
);
775 ret
= WinHttpCrackUrl( url16
, 0, 0, &uc
);
776 ok( ret
, "got %u\n", GetLastError() );
777 ok( !uc
.nPort
, "got %u\n", uc
.nPort
);
779 reset_url_components( &uc
);
781 ret
= WinHttpCrackUrl( url17
, 0, 0, &uc
);
782 ok( ret
, "got %u\n", GetLastError() );
783 todo_wine
ok( uc
.nPort
== 80, "got %u\n", uc
.nPort
);
788 WinHttpCreateUrl_test();
789 WinHttpCrackUrl_test();