2 * Copyright 2008 Hans Leidekker
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
28 static WCHAR empty[] = {0};
29 static WCHAR ftp[] = {'f','t','p',0};
30 static WCHAR http[] = {'h','t','t','p',0};
31 static WCHAR winehq[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
32 static WCHAR username[] = {'u','s','e','r','n','a','m','e',0};
33 static WCHAR password[] = {'p','a','s','s','w','o','r','d',0};
34 static WCHAR about[] = {'/','s','i','t','e','/','a','b','o','u','t',0};
35 static WCHAR query[] = {'?','q','u','e','r','y',0};
36 static WCHAR escape[] = {' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~',0};
38 static const WCHAR url1[] =
39 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
40 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
41 static const WCHAR url2[] =
42 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',
43 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
44 static const WCHAR url3[] = {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':',0};
45 static const WCHAR url4[] =
46 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
47 static const WCHAR url5[] = {'h','t','t','p',':','/','/',0};
48 static const WCHAR url6[] =
49 {'f','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
50 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','8','0','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
51 static const WCHAR url7[] =
52 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
53 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','4','2','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
54 static const WCHAR url8[] =
55 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
56 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',
57 '%','2','0','!','%','2','2','%','2','3','$','%','2','5','&','\'','(',')','*','+',',','-','.','/',':',';','%','3','C','=','%','3','E','?','@','%',
58 '5','B','%','5','C','%','5','D','%','5','E','_','%','6','0','%','7','B','%','7','C','%','7','D','%','7','E',0};
59 static const WCHAR url9[] =
60 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
61 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','0','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
62 static const WCHAR url10[] =
63 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
64 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','8','0','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
65 static const WCHAR url11[] =
66 {'h','t','t','p','s',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
67 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','4','4','3','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
71 static const WCHAR url_k1[] =
72 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
73 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
74 static const WCHAR url_k2[] =
75 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
76 static const WCHAR url_k3[] =
77 {'h','t','t','p','s',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','p','o','s','t','?',0};
78 static const WCHAR url_k4[] =
79 {'H','T','T','P',':','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
80 static const WCHAR url_k5[] =
81 {'h','t','t','p',':','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
82 static const WCHAR url_k6[] =
83 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
84 static const WCHAR url_k7[] =
86 static const WCHAR url_k8[] =
88 static const WCHAR url_k9[] =
89 {'h','t','t','p',':','/','/','w','i','n','e','h','q','?',0};
90 static const WCHAR url_k10[] =
91 {'h','t','t','p',':','/','/','w','i','n','e','h','q','/','p','o','s','t',';','a',0};
93 static void fill_url_components( URL_COMPONENTS *uc )
95 uc->dwStructSize = sizeof(URL_COMPONENTS);
96 uc->lpszScheme = http;
97 uc->dwSchemeLength = lstrlenW( uc->lpszScheme );
98 uc->nScheme = INTERNET_SCHEME_HTTP;
99 uc->lpszHostName = winehq;
100 uc->dwHostNameLength = lstrlenW( uc->lpszHostName );
102 uc->lpszUserName = username;
103 uc->dwUserNameLength = lstrlenW( uc->lpszUserName );
104 uc->lpszPassword = password;
105 uc->dwPasswordLength = lstrlenW( uc->lpszPassword );
106 uc->lpszUrlPath = about;
107 uc->dwUrlPathLength = lstrlenW( uc->lpszUrlPath );
108 uc->lpszExtraInfo = query;
109 uc->dwExtraInfoLength = lstrlenW( uc->lpszExtraInfo );
112 static void WinHttpCreateUrl_test( void )
119 /* NULL components */
121 SetLastError( 0xdeadbeef );
122 ret = WinHttpCreateUrl( NULL, 0, NULL, &len );
123 ok( !ret, "expected failure\n" );
124 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
125 ok( len == ~0u, "expected len ~0u got %u\n", len );
127 /* zero'ed components */
128 memset( &uc, 0, sizeof(URL_COMPONENTS) );
129 SetLastError( 0xdeadbeef );
130 ret = WinHttpCreateUrl( &uc, 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 /* valid components, NULL url, NULL length */
136 fill_url_components( &uc );
137 SetLastError( 0xdeadbeef );
138 ret = WinHttpCreateUrl( &uc, 0, NULL, NULL );
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 */
144 SetLastError( 0xdeadbeef );
145 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
146 ok( !ret, "expected failure\n" );
147 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
148 GetLastError() == ERROR_INVALID_PARAMETER,
149 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
151 /* correct size, NULL url */
152 fill_url_components( &uc );
153 SetLastError( 0xdeadbeef );
154 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
155 ok( !ret, "expected failure\n" );
156 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
157 GetLastError() == ERROR_INVALID_PARAMETER,
158 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
160 /* valid components, allocated url, short length */
161 SetLastError( 0xdeadbeef );
162 url = HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) );
165 ret = WinHttpCreateUrl( &uc, 0, url, &len );
166 ok( !ret, "expected failure\n" );
167 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
168 ok( len == 57, "expected len 57 got %u\n", len );
170 /* allocated url, NULL scheme */
171 uc.lpszScheme = NULL;
174 ret = WinHttpCreateUrl( &uc, 0, url, &len );
175 ok( ret, "expected success\n" );
176 ok( len == 56, "expected len 56 got %u\n", len );
177 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
179 /* allocated url, 0 scheme */
180 fill_url_components( &uc );
184 ret = WinHttpCreateUrl( &uc, 0, url, &len );
185 ok( ret, "expected success\n" );
186 ok( len == 56, "expected len 56 got %u\n", len );
188 /* valid components, allocated url */
189 fill_url_components( &uc );
192 ret = WinHttpCreateUrl( &uc, 0, url, &len );
193 ok( ret, "expected success\n" );
194 ok( len == 56, "expected len 56 got %d\n", len );
195 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
197 /* valid username, NULL password */
198 fill_url_components( &uc );
199 uc.lpszPassword = NULL;
202 ret = WinHttpCreateUrl( &uc, 0, url, &len );
203 ok( ret, "expected success\n" );
205 /* valid username, empty password */
206 fill_url_components( &uc );
207 uc.lpszPassword = empty;
210 ret = WinHttpCreateUrl( &uc, 0, url, &len );
211 ok( ret, "expected success\n" );
212 ok( len == 56, "expected len 56 got %u\n", len );
213 ok( !lstrcmpW( url, url3 ), "url doesn't match\n" );
215 /* valid password, NULL username */
216 fill_url_components( &uc );
217 SetLastError( 0xdeadbeef );
218 uc.lpszUserName = NULL;
221 ret = WinHttpCreateUrl( &uc, 0, url, &len );
222 ok( !ret, "expected failure\n" );
223 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
225 /* valid password, empty username */
226 fill_url_components( &uc );
227 uc.lpszUserName = empty;
230 ret = WinHttpCreateUrl( &uc, 0, url, &len );
231 ok( ret, "expected success\n");
233 /* NULL username, NULL password */
234 fill_url_components( &uc );
235 uc.lpszUserName = NULL;
236 uc.lpszPassword = NULL;
239 ret = WinHttpCreateUrl( &uc, 0, url, &len );
240 ok( ret, "expected success\n" );
241 ok( len == 38, "expected len 38 got %u\n", len );
242 ok( !lstrcmpW( url, url4 ), "url doesn't match\n" );
244 /* empty username, empty password */
245 fill_url_components( &uc );
246 uc.lpszUserName = empty;
247 uc.lpszPassword = empty;
250 ret = WinHttpCreateUrl( &uc, 0, url, &len );
251 ok( ret, "expected success\n" );
252 ok( len == 56, "expected len 56 got %u\n", len );
253 ok( !lstrcmpW( url, url5 ), "url doesn't match\n" );
255 /* nScheme has lower precedence than lpszScheme */
256 fill_url_components( &uc );
258 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
261 ret = WinHttpCreateUrl( &uc, 0, url, &len );
262 ok( ret, "expected success\n" );
263 ok( len == lstrlenW( url6 ), "expected len %d got %u\n", lstrlenW( url6 ) + 1, len );
264 ok( !lstrcmpW( url, url6 ), "url doesn't match\n" );
266 /* non-standard port */
267 uc.lpszScheme = http;
268 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
272 ret = WinHttpCreateUrl( &uc, 0, url, &len );
273 ok( ret, "expected success\n" );
274 ok( len == 59, "expected len 59 got %u\n", len );
275 ok( !lstrcmpW( url, url7 ), "url doesn't match\n" );
277 /* escape extra info */
278 fill_url_components( &uc );
279 uc.lpszExtraInfo = escape;
280 uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo );
283 ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
284 ok( ret, "expected success\n" );
285 ok( len == 113, "expected len 113 got %u\n", len );
286 ok( !lstrcmpW( url, url8 ), "url doesn't match\n" );
288 /* NULL lpszScheme, 0 nScheme and nPort */
289 fill_url_components( &uc );
290 uc.lpszScheme = NULL;
291 uc.dwSchemeLength = 0;
296 ret = WinHttpCreateUrl( &uc, 0, url, &len );
297 ok( ret, "expected success\n" );
298 ok( len == 58, "expected len 58 got %u\n", len );
299 ok( !lstrcmpW( url, url9 ), "url doesn't match\n" );
301 HeapFree( GetProcessHeap(), 0, url );
304 static void reset_url_components( URL_COMPONENTS *uc )
306 memset( uc, 0, sizeof(URL_COMPONENTS) );
307 uc->dwStructSize = sizeof(URL_COMPONENTS);
308 uc->dwSchemeLength = ~0u;
309 uc->dwHostNameLength = ~0u;
311 uc->dwUserNameLength = ~0u;
312 uc->dwPasswordLength = ~0u;
313 uc->dwUrlPathLength = ~0u;
314 uc->dwExtraInfoLength = ~0u;
317 static void WinHttpCrackUrl_test( void )
320 WCHAR scheme[20], user[20], pass[20], host[20], path[80], extra[40];
324 /* buffers of sufficient length */
332 uc.dwStructSize = sizeof(URL_COMPONENTS);
334 uc.lpszScheme = scheme;
335 uc.dwSchemeLength = 20;
336 uc.lpszUserName = user;
337 uc.dwUserNameLength = 20;
338 uc.lpszPassword = pass;
339 uc.dwPasswordLength = 20;
340 uc.lpszHostName = host;
341 uc.dwHostNameLength = 20;
343 uc.lpszUrlPath = path;
344 uc.dwUrlPathLength = 40;
345 uc.lpszExtraInfo = extra;
346 uc.dwExtraInfoLength = 20;
348 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
349 ok( ret, "WinHttpCrackUrl failed\n" );
350 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
351 ok( !memcmp( uc.lpszScheme, http, sizeof(http) ), "unexpected scheme\n" );
352 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
353 ok( !memcmp( uc.lpszUserName, username, sizeof(username) ), "unexpected username\n" );
354 ok( uc.dwUserNameLength == 8, "unexpected username length\n" );
355 ok( !memcmp( uc.lpszPassword, password, sizeof(password) ), "unexpected password\n" );
356 ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
357 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected hostname\n" );
358 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
359 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
360 ok( !memcmp( uc.lpszUrlPath, about, sizeof(about) ), "unexpected path\n" );
361 ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
362 ok( !memcmp( uc.lpszExtraInfo, query, sizeof(query) ), "unexpected extra info\n" );
363 ok( uc.dwExtraInfoLength == 6, "unexpected extra info length\n" );
365 /* buffer of insufficient length */
367 uc.dwSchemeLength = 1;
369 SetLastError( 0xdeadbeef );
370 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
371 error = GetLastError();
372 ok( !ret, "WinHttpCrackUrl failed\n" );
373 ok( error == ERROR_INSUFFICIENT_BUFFER, "WinHttpCrackUrl failed\n" );
374 ok( uc.dwSchemeLength == 5, "unexpected scheme length: %u\n", uc.dwSchemeLength );
377 reset_url_components( &uc );
378 ret = WinHttpCrackUrl( url_k1, 0, 0,&uc);
380 ok( ret, "WinHttpCrackUrl failed\n" );
381 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
382 ok( uc.lpszScheme == url_k1,"unexpected scheme\n" );
383 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
384 ok( uc.lpszUserName == url_k1 + 7, "unexpected username\n" );
385 ok( uc.dwUserNameLength == 8, "unexpected username length\n" );
386 ok( uc.lpszPassword == url_k1 + 16, "unexpected password\n" );
387 ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
388 ok( uc.lpszHostName == url_k1 + 25, "unexpected hostname\n" );
389 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
390 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
391 ok( uc.lpszUrlPath == url_k1 + 39, "unexpected path\n" );
392 ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
393 ok( uc.lpszExtraInfo == url_k1 + 50, "unexpected extra info\n" );
394 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
396 reset_url_components( &uc );
397 ret = WinHttpCrackUrl( url_k2, 0, 0,&uc);
399 ok( ret, "WinHttpCrackUrl failed\n" );
400 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
401 ok( uc.lpszScheme == url_k2, "unexpected scheme\n" );
402 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
403 ok( uc.lpszUserName == NULL ,"unexpected username\n" );
404 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
405 ok( uc.lpszPassword == NULL, "unexpected password\n" );
406 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
407 ok( uc.lpszHostName == url_k2 + 7, "unexpected hostname\n" );
408 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
409 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
410 ok( uc.lpszUrlPath == url_k2 + 21, "unexpected path\n" );
411 ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
412 ok( uc.lpszExtraInfo == url_k2 + 21, "unexpected extra info\n" );
413 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
415 reset_url_components( &uc );
416 ret = WinHttpCrackUrl( url_k3, 0, 0, &uc );
418 ok( ret, "WinHttpCrackUrl failed\n" );
419 ok( uc.nScheme == INTERNET_SCHEME_HTTPS, "unexpected scheme\n" );
420 ok( uc.lpszScheme == url_k3, "unexpected scheme\n" );
421 ok( uc.dwSchemeLength == 5, "unexpected scheme length\n" );
422 ok( uc.lpszUserName == NULL, "unexpected username\n" );
423 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
424 ok( uc.lpszPassword == NULL, "unexpected password\n" );
425 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
426 ok( uc.lpszHostName == url_k3 + 8, "unexpected hostname\n" );
427 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
428 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
429 ok( uc.lpszUrlPath == url_k3 + 22, "unexpected path\n" );
430 ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
431 ok( uc.lpszExtraInfo == url_k3 + 27, "unexpected extra info\n" );
432 ok( uc.dwExtraInfoLength == 1, "unexpected extra info length\n" );
435 reset_url_components( &uc );
436 ret = WinHttpCrackUrl( url_k4, 0, 0, &uc );
437 ok( !ret, "WinHttpCrackUrl failed\n" );
439 reset_url_components( &uc );
440 ret = WinHttpCrackUrl( url_k5, 0, 0, &uc );
441 ok( !ret, "WinHttpCrackUrl failed\n" );
443 reset_url_components( &uc );
444 ret = WinHttpCrackUrl( url_k6, 0, 0, &uc );
445 ok( !ret, "WinHttpCrackUrl failed\n" );
447 reset_url_components( &uc );
448 ret = WinHttpCrackUrl( url_k7, 0, 0, &uc );
449 ok( !ret, "WinHttpCrackUrl failed\n" );
451 reset_url_components( &uc );
452 ret = WinHttpCrackUrl( url_k8, 0, 0, &uc );
453 ok( !ret, "WinHttpCrackUrl failed\n" );
455 reset_url_components( &uc );
456 ret = WinHttpCrackUrl( url_k9, 0, 0, &uc );
457 ok( ret, "WinHttpCrackUrl failed\n" );
458 ok( uc.lpszUrlPath == url_k9 + 14, "unexpected path\n" );
459 ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
460 ok( uc.lpszExtraInfo == url_k9 + 14, "unexpected extra info\n" );
461 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
463 reset_url_components( &uc );
464 ret = WinHttpCrackUrl( url_k10, 0, 0, &uc );
465 ok( ret, "WinHttpCrackUrl failed\n" );
466 ok( uc.lpszUrlPath == url_k10 + 13, "unexpected path\n" );
467 ok( uc.dwUrlPathLength == 7, "unexpected path length\n" );
468 ok( uc.lpszExtraInfo == url_k10 + 20, "unexpected extra info\n" );
469 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
471 reset_url_components( &uc );
472 ret = WinHttpCrackUrl( url5, 0, 0, &uc );
473 ok( !ret, "WinHttpCrackUrl failed\n" );
475 reset_url_components( &uc );
476 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
477 ok( !ret, "WinHttpCrackUrl failed\n" );
479 ret = WinHttpCrackUrl( url1, 0, 0, NULL );
480 ok( !ret, "WinHttpCrackUrl failed\n" );
482 ret = WinHttpCrackUrl( NULL, 0, 0, &uc );
483 ok( !ret, "WinHttpCrackUrl failed\n" );
485 /* decoding without buffers */
486 reset_url_components( &uc );
487 SetLastError(0xdeadbeef);
488 ret = WinHttpCrackUrl( url8, 0, ICU_DECODE, &uc );
489 error = GetLastError();
490 ok( !ret, "WinHttpCrackUrl failed\n" );
491 ok( error == ERROR_INVALID_PARAMETER, "WinHttpCrackUrl failed\n" );
493 /* decoding with buffers */
494 uc.lpszScheme = scheme;
495 uc.dwSchemeLength = 20;
496 uc.lpszUserName = user;
497 uc.dwUserNameLength = 20;
498 uc.lpszPassword = pass;
499 uc.dwPasswordLength = 20;
500 uc.lpszHostName = host;
501 uc.dwHostNameLength = 20;
503 uc.lpszUrlPath = path;
504 uc.dwUrlPathLength = 80;
505 uc.lpszExtraInfo = extra;
506 uc.dwExtraInfoLength = 40;
509 ret = WinHttpCrackUrl( url8, 0, ICU_DECODE, &uc );
510 ok( ret, "WinHttpCrackUrl failed %u\n", GetLastError() );
511 ok( !memcmp( uc.lpszUrlPath + 11, escape, 21 * sizeof(WCHAR) ), "unexpected path\n" );
512 ok( uc.dwUrlPathLength == 32, "unexpected path length %u\n", uc.dwUrlPathLength );
513 ok( !memcmp( uc.lpszExtraInfo, escape + 21, 12 * sizeof(WCHAR) ), "unexpected extra info\n" );
514 ok( uc.dwExtraInfoLength == 12, "unexpected extra info length %u\n", uc.dwExtraInfoLength );
516 /* Urls with specified port numbers */
517 /* decoding with buffers */
518 uc.lpszScheme = scheme;
519 uc.dwSchemeLength = 20;
520 uc.lpszUserName = user;
521 uc.dwUserNameLength = 20;
522 uc.lpszPassword = pass;
523 uc.dwPasswordLength = 20;
524 uc.lpszHostName = host;
525 uc.dwHostNameLength = 20;
527 uc.lpszUrlPath = path;
528 uc.dwUrlPathLength = 40;
529 uc.lpszExtraInfo = extra;
530 uc.dwExtraInfoLength = 20;
533 ret = WinHttpCrackUrl( url7, 0, 0, &uc );
534 ok( ret, "WinHttpCrackUrl failed\n" );
535 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected host name: %s\n", wine_dbgstr_w(uc.lpszHostName) );
536 ok( uc.dwHostNameLength == 14, "unexpected host name length: %d\n", uc.dwHostNameLength );
537 ok( uc.nPort == 42, "unexpected port: %u\n", uc.nPort );
539 /* decoding without buffers */
540 reset_url_components( &uc );
541 ret = WinHttpCrackUrl( url9, 0, 0, &uc );
542 ok( ret, "WinHttpCrackUrl failed\n" );
543 ok( uc.nPort == 0, "unexpected port: %u\n", uc.nPort );
545 reset_url_components( &uc );
546 ret = WinHttpCrackUrl( url10, 0, 0, &uc );
547 ok( ret, "WinHttpCrackUrl failed\n" );
548 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
550 reset_url_components( &uc );
551 ret = WinHttpCrackUrl( url11, 0, 0, &uc );
552 ok( ret, "WinHttpCrackUrl failed\n" );
553 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
555 reset_url_components( &uc );
556 SetLastError( 0xdeadbeef );
557 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
558 error = GetLastError();
559 ok( !ret, "WinHttpCrackUrl succeeded\n" );
560 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
562 reset_url_components( &uc );
563 SetLastError( 0xdeadbeef );
564 ret = WinHttpCrackUrl( http, 0, 0, &uc );
565 error = GetLastError();
566 ok( !ret, "WinHttpCrackUrl succeeded\n" );
567 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
572 WinHttpCreateUrl_test();
573 WinHttpCrackUrl_test();