quartz: Free two assert calls from having side effects.
[wine/testsucceed.git] / dlls / winhttp / tests / url.c
blobe75335129d2c178e42f894c9e3e5727fbbb7ab0a
1 /*
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
19 #include <stdarg.h>
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winnls.h"
24 #include "winhttp.h"
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};
73 static const WCHAR url_k1[] =
74 {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
75 '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
76 static const WCHAR url_k2[] =
77 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
78 static const WCHAR url_k3[] =
79 {'h','t','t','p','s',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','p','o','s','t','?',0};
80 static const WCHAR url_k4[] =
81 {'H','T','T','P',':','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
82 static const WCHAR url_k5[] =
83 {'h','t','t','p',':','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
84 static const WCHAR url_k6[] =
85 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
86 static const WCHAR url_k7[] =
87 {'w','w','w',0};
88 static const WCHAR url_k8[] =
89 {'h','t','t','p',0};
90 static const WCHAR url_k9[] =
91 {'h','t','t','p',':','/','/','w','i','n','e','h','q','?',0};
92 static const WCHAR url_k10[] =
93 {'h','t','t','p',':','/','/','w','i','n','e','h','q','/','p','o','s','t',';','a',0};
95 static void fill_url_components( URL_COMPONENTS *uc )
97 uc->dwStructSize = sizeof(URL_COMPONENTS);
98 uc->lpszScheme = http;
99 uc->dwSchemeLength = lstrlenW( uc->lpszScheme );
100 uc->nScheme = INTERNET_SCHEME_HTTP;
101 uc->lpszHostName = winehq;
102 uc->dwHostNameLength = lstrlenW( uc->lpszHostName );
103 uc->nPort = 80;
104 uc->lpszUserName = username;
105 uc->dwUserNameLength = lstrlenW( uc->lpszUserName );
106 uc->lpszPassword = password;
107 uc->dwPasswordLength = lstrlenW( uc->lpszPassword );
108 uc->lpszUrlPath = about;
109 uc->dwUrlPathLength = lstrlenW( uc->lpszUrlPath );
110 uc->lpszExtraInfo = query;
111 uc->dwExtraInfoLength = lstrlenW( uc->lpszExtraInfo );
114 static void WinHttpCreateUrl_test( void )
116 URL_COMPONENTS uc;
117 WCHAR *url;
118 DWORD len;
119 BOOL ret;
121 /* NULL components */
122 len = ~0u;
123 SetLastError( 0xdeadbeef );
124 ret = WinHttpCreateUrl( NULL, 0, NULL, &len );
125 ok( !ret, "expected failure\n" );
126 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
127 ok( len == ~0u, "expected len ~0u got %u\n", len );
129 /* zero'ed components */
130 memset( &uc, 0, sizeof(URL_COMPONENTS) );
131 SetLastError( 0xdeadbeef );
132 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
133 ok( !ret, "expected failure\n" );
134 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
135 ok( len == ~0u, "expected len ~0u got %u\n", len );
137 /* valid components, NULL url, NULL length */
138 fill_url_components( &uc );
139 SetLastError( 0xdeadbeef );
140 ret = WinHttpCreateUrl( &uc, 0, NULL, NULL );
141 ok( !ret, "expected failure\n" );
142 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
143 ok( len == ~0u, "expected len ~0u got %u\n", len );
145 /* valid components, NULL url */
146 SetLastError( 0xdeadbeef );
147 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
148 ok( !ret, "expected failure\n" );
149 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
150 GetLastError() == ERROR_INVALID_PARAMETER,
151 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
153 /* correct size, NULL url */
154 fill_url_components( &uc );
155 SetLastError( 0xdeadbeef );
156 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
157 ok( !ret, "expected failure\n" );
158 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
159 GetLastError() == ERROR_INVALID_PARAMETER,
160 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
162 /* valid components, allocated url, short length */
163 SetLastError( 0xdeadbeef );
164 url = HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) );
165 url[0] = 0;
166 len = 2;
167 ret = WinHttpCreateUrl( &uc, 0, url, &len );
168 ok( !ret, "expected failure\n" );
169 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
170 ok( len == 57, "expected len 57 got %u\n", len );
172 /* allocated url, NULL scheme */
173 uc.lpszScheme = NULL;
174 url[0] = 0;
175 len = 256;
176 ret = WinHttpCreateUrl( &uc, 0, url, &len );
177 ok( ret, "expected success\n" );
178 ok( len == 56, "expected len 56 got %u\n", len );
179 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
181 /* allocated url, 0 scheme */
182 fill_url_components( &uc );
183 uc.nScheme = 0;
184 url[0] = 0;
185 len = 256;
186 ret = WinHttpCreateUrl( &uc, 0, url, &len );
187 ok( ret, "expected success\n" );
188 ok( len == 56, "expected len 56 got %u\n", len );
190 /* valid components, allocated url */
191 fill_url_components( &uc );
192 url[0] = 0;
193 len = 256;
194 ret = WinHttpCreateUrl( &uc, 0, url, &len );
195 ok( ret, "expected success\n" );
196 ok( len == 56, "expected len 56 got %d\n", len );
197 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
199 /* valid username, NULL password */
200 fill_url_components( &uc );
201 uc.lpszPassword = NULL;
202 url[0] = 0;
203 len = 256;
204 ret = WinHttpCreateUrl( &uc, 0, url, &len );
205 ok( ret, "expected success\n" );
207 /* valid username, empty password */
208 fill_url_components( &uc );
209 uc.lpszPassword = empty;
210 url[0] = 0;
211 len = 256;
212 ret = WinHttpCreateUrl( &uc, 0, url, &len );
213 ok( ret, "expected success\n" );
214 ok( len == 56, "expected len 56 got %u\n", len );
215 ok( !lstrcmpW( url, url3 ), "url doesn't match\n" );
217 /* valid password, NULL username */
218 fill_url_components( &uc );
219 SetLastError( 0xdeadbeef );
220 uc.lpszUserName = NULL;
221 url[0] = 0;
222 len = 256;
223 ret = WinHttpCreateUrl( &uc, 0, url, &len );
224 ok( !ret, "expected failure\n" );
225 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
227 /* valid password, empty username */
228 fill_url_components( &uc );
229 uc.lpszUserName = empty;
230 url[0] = 0;
231 len = 256;
232 ret = WinHttpCreateUrl( &uc, 0, url, &len );
233 ok( ret, "expected success\n");
235 /* NULL username, NULL password */
236 fill_url_components( &uc );
237 uc.lpszUserName = NULL;
238 uc.lpszPassword = NULL;
239 url[0] = 0;
240 len = 256;
241 ret = WinHttpCreateUrl( &uc, 0, url, &len );
242 ok( ret, "expected success\n" );
243 ok( len == 38, "expected len 38 got %u\n", len );
244 ok( !lstrcmpW( url, url4 ), "url doesn't match\n" );
246 /* empty username, empty password */
247 fill_url_components( &uc );
248 uc.lpszUserName = empty;
249 uc.lpszPassword = empty;
250 url[0] = 0;
251 len = 256;
252 ret = WinHttpCreateUrl( &uc, 0, url, &len );
253 ok( ret, "expected success\n" );
254 ok( len == 56, "expected len 56 got %u\n", len );
255 ok( !lstrcmpW( url, url5 ), "url doesn't match\n" );
257 /* nScheme has lower precedence than lpszScheme */
258 fill_url_components( &uc );
259 uc.lpszScheme = ftp;
260 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
261 url[0] = 0;
262 len = 256;
263 ret = WinHttpCreateUrl( &uc, 0, url, &len );
264 ok( ret, "expected success\n" );
265 ok( len == lstrlenW( url6 ), "expected len %d got %u\n", lstrlenW( url6 ) + 1, len );
266 ok( !lstrcmpW( url, url6 ), "url doesn't match\n" );
268 /* non-standard port */
269 uc.lpszScheme = http;
270 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
271 uc.nPort = 42;
272 url[0] = 0;
273 len = 256;
274 ret = WinHttpCreateUrl( &uc, 0, url, &len );
275 ok( ret, "expected success\n" );
276 ok( len == 59, "expected len 59 got %u\n", len );
277 ok( !lstrcmpW( url, url7 ), "url doesn't match\n" );
279 /* escape extra info */
280 fill_url_components( &uc );
281 uc.lpszExtraInfo = escape;
282 uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo );
283 url[0] = 0;
284 len = 256;
285 ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
286 ok( ret, "expected success\n" );
287 ok( len == 113, "expected len 113 got %u\n", len );
288 ok( !lstrcmpW( url, url8 ), "url doesn't match\n" );
290 /* NULL lpszScheme, 0 nScheme and nPort */
291 fill_url_components( &uc );
292 uc.lpszScheme = NULL;
293 uc.dwSchemeLength = 0;
294 uc.nScheme = 0;
295 uc.nPort = 0;
296 url[0] = 0;
297 len = 256;
298 ret = WinHttpCreateUrl( &uc, 0, url, &len );
299 ok( ret, "expected success\n" );
300 ok( len == 58, "expected len 58 got %u\n", len );
301 ok( !lstrcmpW( url, url9 ), "url doesn't match\n" );
303 HeapFree( GetProcessHeap(), 0, url );
306 static void reset_url_components( URL_COMPONENTS *uc )
308 memset( uc, 0, sizeof(URL_COMPONENTS) );
309 uc->dwStructSize = sizeof(URL_COMPONENTS);
310 uc->dwSchemeLength = ~0u;
311 uc->dwHostNameLength = ~0u;
312 uc->nPort = 0;
313 uc->dwUserNameLength = ~0u;
314 uc->dwPasswordLength = ~0u;
315 uc->dwUrlPathLength = ~0u;
316 uc->dwExtraInfoLength = ~0u;
319 static void WinHttpCrackUrl_test( void )
321 URL_COMPONENTSW uc;
322 WCHAR scheme[20], user[20], pass[20], host[20], path[80], extra[40];
323 DWORD error;
324 BOOL ret;
326 /* buffers of sufficient length */
327 scheme[0] = 0;
328 user[0] = 0;
329 pass[0] = 0;
330 host[0] = 0;
331 path[0] = 0;
332 extra[0] = 0;
334 uc.dwStructSize = sizeof(URL_COMPONENTS);
335 uc.nScheme = 0;
336 uc.lpszScheme = scheme;
337 uc.dwSchemeLength = 20;
338 uc.lpszUserName = user;
339 uc.dwUserNameLength = 20;
340 uc.lpszPassword = pass;
341 uc.dwPasswordLength = 20;
342 uc.lpszHostName = host;
343 uc.dwHostNameLength = 20;
344 uc.nPort = 0;
345 uc.lpszUrlPath = path;
346 uc.dwUrlPathLength = 40;
347 uc.lpszExtraInfo = extra;
348 uc.dwExtraInfoLength = 20;
350 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
351 ok( ret, "WinHttpCrackUrl failed\n" );
352 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
353 ok( !memcmp( uc.lpszScheme, http, sizeof(http) ), "unexpected scheme\n" );
354 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
355 ok( !memcmp( uc.lpszUserName, username, sizeof(username) ), "unexpected username\n" );
356 ok( uc.dwUserNameLength == 8, "unexpected username length\n" );
357 ok( !memcmp( uc.lpszPassword, password, sizeof(password) ), "unexpected password\n" );
358 ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
359 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected hostname\n" );
360 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
361 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
362 ok( !memcmp( uc.lpszUrlPath, about, sizeof(about) ), "unexpected path\n" );
363 ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
364 ok( !memcmp( uc.lpszExtraInfo, query, sizeof(query) ), "unexpected extra info\n" );
365 ok( uc.dwExtraInfoLength == 6, "unexpected extra info length\n" );
367 /* buffer of insufficient length */
368 scheme[0] = 0;
369 uc.dwSchemeLength = 1;
371 SetLastError( 0xdeadbeef );
372 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
373 error = GetLastError();
374 ok( !ret, "WinHttpCrackUrl failed\n" );
375 ok( error == ERROR_INSUFFICIENT_BUFFER, "WinHttpCrackUrl failed\n" );
376 ok( uc.dwSchemeLength == 5, "unexpected scheme length: %u\n", uc.dwSchemeLength );
378 /* no buffers */
379 reset_url_components( &uc );
380 ret = WinHttpCrackUrl( url_k1, 0, 0,&uc);
382 ok( ret, "WinHttpCrackUrl failed\n" );
383 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
384 ok( uc.lpszScheme == url_k1,"unexpected scheme\n" );
385 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
386 ok( uc.lpszUserName == url_k1 + 7, "unexpected username\n" );
387 ok( uc.dwUserNameLength == 8, "unexpected username length\n" );
388 ok( uc.lpszPassword == url_k1 + 16, "unexpected password\n" );
389 ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
390 ok( uc.lpszHostName == url_k1 + 25, "unexpected hostname\n" );
391 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
392 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
393 ok( uc.lpszUrlPath == url_k1 + 39, "unexpected path\n" );
394 ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
395 ok( uc.lpszExtraInfo == url_k1 + 50, "unexpected extra info\n" );
396 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
398 reset_url_components( &uc );
399 ret = WinHttpCrackUrl( url_k2, 0, 0,&uc);
401 ok( ret, "WinHttpCrackUrl failed\n" );
402 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
403 ok( uc.lpszScheme == url_k2, "unexpected scheme\n" );
404 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
405 ok( uc.lpszUserName == NULL ,"unexpected username\n" );
406 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
407 ok( uc.lpszPassword == NULL, "unexpected password\n" );
408 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
409 ok( uc.lpszHostName == url_k2 + 7, "unexpected hostname\n" );
410 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
411 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
412 ok( uc.lpszUrlPath == url_k2 + 21, "unexpected path\n" );
413 ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
414 ok( uc.lpszExtraInfo == url_k2 + 21, "unexpected extra info\n" );
415 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
417 reset_url_components( &uc );
418 ret = WinHttpCrackUrl( url_k3, 0, 0, &uc );
420 ok( ret, "WinHttpCrackUrl failed\n" );
421 ok( uc.nScheme == INTERNET_SCHEME_HTTPS, "unexpected scheme\n" );
422 ok( uc.lpszScheme == url_k3, "unexpected scheme\n" );
423 ok( uc.dwSchemeLength == 5, "unexpected scheme length\n" );
424 ok( uc.lpszUserName == NULL, "unexpected username\n" );
425 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
426 ok( uc.lpszPassword == NULL, "unexpected password\n" );
427 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
428 ok( uc.lpszHostName == url_k3 + 8, "unexpected hostname\n" );
429 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
430 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
431 ok( uc.lpszUrlPath == url_k3 + 22, "unexpected path\n" );
432 ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
433 ok( uc.lpszExtraInfo == url_k3 + 27, "unexpected extra info\n" );
434 ok( uc.dwExtraInfoLength == 1, "unexpected extra info length\n" );
436 /* bad parameters */
437 reset_url_components( &uc );
438 ret = WinHttpCrackUrl( url_k4, 0, 0, &uc );
439 ok( !ret, "WinHttpCrackUrl failed\n" );
441 reset_url_components( &uc );
442 ret = WinHttpCrackUrl( url_k5, 0, 0, &uc );
443 ok( !ret, "WinHttpCrackUrl failed\n" );
445 reset_url_components( &uc );
446 ret = WinHttpCrackUrl( url_k6, 0, 0, &uc );
447 ok( !ret, "WinHttpCrackUrl failed\n" );
449 reset_url_components( &uc );
450 ret = WinHttpCrackUrl( url_k7, 0, 0, &uc );
451 ok( !ret, "WinHttpCrackUrl failed\n" );
453 reset_url_components( &uc );
454 ret = WinHttpCrackUrl( url_k8, 0, 0, &uc );
455 ok( !ret, "WinHttpCrackUrl failed\n" );
457 reset_url_components( &uc );
458 ret = WinHttpCrackUrl( url_k9, 0, 0, &uc );
459 ok( ret, "WinHttpCrackUrl failed\n" );
460 ok( uc.lpszUrlPath == url_k9 + 14, "unexpected path\n" );
461 ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
462 ok( uc.lpszExtraInfo == url_k9 + 14, "unexpected extra info\n" );
463 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
465 reset_url_components( &uc );
466 ret = WinHttpCrackUrl( url_k10, 0, 0, &uc );
467 ok( ret, "WinHttpCrackUrl failed\n" );
468 ok( uc.lpszUrlPath == url_k10 + 13, "unexpected path\n" );
469 ok( uc.dwUrlPathLength == 7, "unexpected path length\n" );
470 ok( uc.lpszExtraInfo == url_k10 + 20, "unexpected extra info\n" );
471 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
473 reset_url_components( &uc );
474 ret = WinHttpCrackUrl( url5, 0, 0, &uc );
475 ok( !ret, "WinHttpCrackUrl failed\n" );
477 reset_url_components( &uc );
478 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
479 ok( !ret, "WinHttpCrackUrl failed\n" );
481 ret = WinHttpCrackUrl( url1, 0, 0, NULL );
482 ok( !ret, "WinHttpCrackUrl failed\n" );
484 ret = WinHttpCrackUrl( NULL, 0, 0, &uc );
485 ok( !ret, "WinHttpCrackUrl failed\n" );
487 /* decoding without buffers */
488 reset_url_components( &uc );
489 SetLastError(0xdeadbeef);
490 ret = WinHttpCrackUrl( url8, 0, ICU_DECODE, &uc );
491 error = GetLastError();
492 ok( !ret, "WinHttpCrackUrl failed\n" );
493 ok( error == ERROR_INVALID_PARAMETER, "WinHttpCrackUrl failed\n" );
495 /* decoding with buffers */
496 uc.lpszScheme = scheme;
497 uc.dwSchemeLength = 20;
498 uc.lpszUserName = user;
499 uc.dwUserNameLength = 20;
500 uc.lpszPassword = pass;
501 uc.dwPasswordLength = 20;
502 uc.lpszHostName = host;
503 uc.dwHostNameLength = 20;
504 uc.nPort = 0;
505 uc.lpszUrlPath = path;
506 uc.dwUrlPathLength = 80;
507 uc.lpszExtraInfo = extra;
508 uc.dwExtraInfoLength = 40;
509 path[0] = 0;
511 ret = WinHttpCrackUrl( url8, 0, ICU_DECODE, &uc );
512 ok( ret, "WinHttpCrackUrl failed %u\n", GetLastError() );
513 ok( !memcmp( uc.lpszUrlPath + 11, escape, 21 * sizeof(WCHAR) ), "unexpected path\n" );
514 ok( uc.dwUrlPathLength == 32, "unexpected path length %u\n", uc.dwUrlPathLength );
515 ok( !memcmp( uc.lpszExtraInfo, escape + 21, 12 * sizeof(WCHAR) ), "unexpected extra info\n" );
516 ok( uc.dwExtraInfoLength == 12, "unexpected extra info length %u\n", uc.dwExtraInfoLength );
518 /* Urls with specified port numbers */
519 /* decoding with buffers */
520 uc.lpszScheme = scheme;
521 uc.dwSchemeLength = 20;
522 uc.lpszUserName = user;
523 uc.dwUserNameLength = 20;
524 uc.lpszPassword = pass;
525 uc.dwPasswordLength = 20;
526 uc.lpszHostName = host;
527 uc.dwHostNameLength = 20;
528 uc.nPort = 0;
529 uc.lpszUrlPath = path;
530 uc.dwUrlPathLength = 40;
531 uc.lpszExtraInfo = extra;
532 uc.dwExtraInfoLength = 20;
533 path[0] = 0;
535 ret = WinHttpCrackUrl( url7, 0, 0, &uc );
536 ok( ret, "WinHttpCrackUrl failed\n" );
537 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected host name: %s\n", wine_dbgstr_w(uc.lpszHostName) );
538 ok( uc.dwHostNameLength == 14, "unexpected host name length: %d\n", uc.dwHostNameLength );
539 ok( uc.nPort == 42, "unexpected port: %u\n", uc.nPort );
541 /* decoding without buffers */
542 reset_url_components( &uc );
543 ret = WinHttpCrackUrl( url9, 0, 0, &uc );
544 ok( ret, "WinHttpCrackUrl failed\n" );
545 ok( uc.nPort == 0, "unexpected port: %u\n", uc.nPort );
547 reset_url_components( &uc );
548 ret = WinHttpCrackUrl( url10, 0, 0, &uc );
549 ok( ret, "WinHttpCrackUrl failed\n" );
550 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
552 reset_url_components( &uc );
553 ret = WinHttpCrackUrl( url11, 0, 0, &uc );
554 ok( ret, "WinHttpCrackUrl failed\n" );
555 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
557 reset_url_components( &uc );
558 SetLastError( 0xdeadbeef );
559 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
560 error = GetLastError();
561 ok( !ret, "WinHttpCrackUrl succeeded\n" );
562 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
564 reset_url_components( &uc );
565 SetLastError( 0xdeadbeef );
566 ret = WinHttpCrackUrl( http, 0, 0, &uc );
567 error = GetLastError();
568 ok( !ret, "WinHttpCrackUrl succeeded\n" );
569 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
571 reset_url_components( &uc );
572 ret = WinHttpCrackUrl( url12, 0, 0, &uc);
574 ok( ret, "WinHttpCrackUrl failed\n" );
575 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
576 ok( uc.lpszScheme == url12,"unexpected scheme\n" );
577 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
578 ok( uc.lpszUserName == NULL, "unexpected username\n" );
579 ok( uc.lpszPassword == NULL, "unexpected password\n" );
580 ok( uc.lpszHostName == url12 + 7, "unexpected hostname\n" );
581 ok( uc.dwHostNameLength == 11, "unexpected hostname length\n" );
582 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
583 ok( uc.lpszUrlPath == url12 + 18, "unexpected path\n" );
584 ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
585 ok( uc.lpszExtraInfo == url12 + 23, "unexpected extra info\n" );
586 ok( uc.dwExtraInfoLength == 39, "unexpected extra info length\n" );
589 START_TEST(url)
591 WinHttpCreateUrl_test();
592 WinHttpCrackUrl_test();