xmllite/reader: Return correct error for multiple colons in qualified name.
[wine.git] / dlls / winhttp / tests / url.c
blob6bde1de70e466b6e4f59be35508abc9064a9c6f8
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[] = {'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[] =
90 {'w','w','w',0};
91 static const WCHAR url_k8[] =
92 {'h','t','t','p',0};
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 );
106 uc->nPort = 80;
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 )
119 URL_COMPONENTS uc;
120 WCHAR *url;
121 DWORD len, err;
122 BOOL ret;
124 /* NULL components */
125 len = ~0u;
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, insufficient length */
148 len = 0;
149 SetLastError( 0xdeadbeef );
150 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
151 ok( !ret, "expected failure\n" );
152 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
153 ok( len == 57, "expected len 57 got %u\n", len );
155 /* valid components, NULL url, sufficient length */
156 SetLastError( 0xdeadbeef );
157 len = 256;
158 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
159 err = GetLastError();
160 ok( !ret, "expected failure\n" );
161 ok( err == ERROR_INVALID_PARAMETER || broken(err == ERROR_INSUFFICIENT_BUFFER) /* < win7 */,
162 "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
163 ok( len == 256 || broken(len == 57) /* < win7 */, "expected len 256 got %u\n", len );
165 /* correct size, NULL url */
166 fill_url_components( &uc );
167 SetLastError( 0xdeadbeef );
168 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
169 err = GetLastError();
170 ok( !ret, "expected failure\n" );
171 ok( err == ERROR_INVALID_PARAMETER || broken(err == ERROR_INSUFFICIENT_BUFFER) /* < win7 */,
172 "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
173 ok( len == 256 || broken(len == 57) /* < win7 */, "expected len 256 got %u\n", len );
175 /* valid components, allocated url, short length */
176 SetLastError( 0xdeadbeef );
177 url = HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) );
178 url[0] = 0;
179 len = 2;
180 ret = WinHttpCreateUrl( &uc, 0, url, &len );
181 ok( !ret, "expected failure\n" );
182 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
183 ok( len == 57, "expected len 57 got %u\n", len );
185 /* allocated url, NULL scheme */
186 SetLastError( 0xdeadbeef );
187 uc.lpszScheme = NULL;
188 url[0] = 0;
189 len = 256;
190 ret = WinHttpCreateUrl( &uc, 0, url, &len );
191 ok( ret, "expected success\n" );
192 ok( GetLastError() == ERROR_SUCCESS || broken(GetLastError() == 0xdeadbeef) /* < win7 */,
193 "expected ERROR_SUCCESS got %u\n", GetLastError() );
194 ok( len == 56, "expected len 56 got %u\n", len );
195 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
197 /* allocated url, 0 scheme */
198 fill_url_components( &uc );
199 uc.nScheme = 0;
200 url[0] = 0;
201 len = 256;
202 ret = WinHttpCreateUrl( &uc, 0, url, &len );
203 ok( ret, "expected success\n" );
204 ok( len == 56, "expected len 56 got %u\n", len );
206 /* valid components, allocated url */
207 fill_url_components( &uc );
208 url[0] = 0;
209 len = 256;
210 ret = WinHttpCreateUrl( &uc, 0, url, &len );
211 ok( ret, "expected success\n" );
212 ok( len == 56, "expected len 56 got %d\n", len );
213 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
215 /* valid username, NULL password */
216 fill_url_components( &uc );
217 uc.lpszPassword = NULL;
218 url[0] = 0;
219 len = 256;
220 ret = WinHttpCreateUrl( &uc, 0, url, &len );
221 ok( ret, "expected success\n" );
223 /* valid username, empty password */
224 fill_url_components( &uc );
225 uc.lpszPassword = empty;
226 url[0] = 0;
227 len = 256;
228 ret = WinHttpCreateUrl( &uc, 0, url, &len );
229 ok( ret, "expected success\n" );
230 ok( len == 56, "expected len 56 got %u\n", len );
231 ok( !lstrcmpW( url, url2 ), "url doesn't match\n" );
233 /* valid password, NULL username */
234 fill_url_components( &uc );
235 SetLastError( 0xdeadbeef );
236 uc.lpszUserName = NULL;
237 url[0] = 0;
238 len = 256;
239 ret = WinHttpCreateUrl( &uc, 0, url, &len );
240 ok( !ret, "expected failure\n" );
241 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
243 /* valid password, empty username */
244 fill_url_components( &uc );
245 uc.lpszUserName = empty;
246 url[0] = 0;
247 len = 256;
248 ret = WinHttpCreateUrl( &uc, 0, url, &len );
249 ok( ret, "expected success\n");
251 /* NULL username, NULL password */
252 fill_url_components( &uc );
253 uc.lpszUserName = NULL;
254 uc.lpszPassword = NULL;
255 url[0] = 0;
256 len = 256;
257 ret = WinHttpCreateUrl( &uc, 0, url, &len );
258 ok( ret, "expected success\n" );
259 ok( len == 38, "expected len 38 got %u\n", len );
260 ok( !lstrcmpW( url, url3 ), "url doesn't match\n" );
262 /* empty username, empty password */
263 fill_url_components( &uc );
264 uc.lpszUserName = empty;
265 uc.lpszPassword = empty;
266 url[0] = 0;
267 len = 256;
268 ret = WinHttpCreateUrl( &uc, 0, url, &len );
269 ok( ret, "expected success\n" );
270 ok( len == 56, "expected len 56 got %u\n", len );
271 ok( !lstrcmpW( url, url4 ), "url doesn't match\n" );
273 /* nScheme has lower precedence than lpszScheme */
274 fill_url_components( &uc );
275 uc.lpszScheme = ftp;
276 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
277 url[0] = 0;
278 len = 256;
279 ret = WinHttpCreateUrl( &uc, 0, url, &len );
280 ok( ret, "expected success\n" );
281 ok( len == lstrlenW( url5 ), "expected len %d got %u\n", lstrlenW( url5 ) + 1, len );
282 ok( !lstrcmpW( url, url5 ), "url doesn't match\n" );
284 /* non-standard port */
285 uc.lpszScheme = http;
286 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
287 uc.nPort = 42;
288 url[0] = 0;
289 len = 256;
290 ret = WinHttpCreateUrl( &uc, 0, url, &len );
291 ok( ret, "expected success\n" );
292 ok( len == 59, "expected len 59 got %u\n", len );
293 ok( !lstrcmpW( url, url6 ), "url doesn't match\n" );
295 /* escape extra info */
296 fill_url_components( &uc );
297 uc.lpszExtraInfo = escape;
298 uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo );
299 url[0] = 0;
300 len = 256;
301 ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
302 ok( ret, "expected success\n" );
303 ok( len == 113, "expected len 113 got %u\n", len );
304 ok( !lstrcmpW( url, url7 ), "url doesn't match\n" );
306 /* NULL lpszScheme, 0 nScheme and nPort */
307 fill_url_components( &uc );
308 uc.lpszScheme = NULL;
309 uc.dwSchemeLength = 0;
310 uc.nScheme = 0;
311 uc.nPort = 0;
312 url[0] = 0;
313 len = 256;
314 ret = WinHttpCreateUrl( &uc, 0, url, &len );
315 ok( ret, "expected success\n" );
316 ok( len == 58, "expected len 58 got %u\n", len );
317 ok( !lstrcmpW( url, url8 ), "url doesn't match\n" );
319 HeapFree( GetProcessHeap(), 0, url );
322 static void reset_url_components( URL_COMPONENTS *uc )
324 memset( uc, 0, sizeof(URL_COMPONENTS) );
325 uc->dwStructSize = sizeof(URL_COMPONENTS);
326 uc->dwSchemeLength = ~0u;
327 uc->dwHostNameLength = 1;
328 uc->nPort = 0;
329 uc->dwUserNameLength = ~0u;
330 uc->dwPasswordLength = ~0u;
331 uc->dwUrlPathLength = ~0u;
332 uc->dwExtraInfoLength = ~0u;
335 static void WinHttpCrackUrl_test( void )
337 static const WCHAR hostnameW[] =
338 {'w','i','n','e','h','q','.','o',' ','g',0};
339 static const WCHAR pathW[] =
340 {'/','p','a','t','h','%','2','0','w','i','t','h','%','2','0','s','p','a','c','e','s',0};
341 URL_COMPONENTSW uc;
342 WCHAR scheme[20], user[20], pass[20], host[20], path[80], extra[40];
343 DWORD error;
344 BOOL ret;
346 /* buffers of sufficient length */
347 scheme[0] = user[0] = pass[0] = host[0] = path[0] = extra[0] = 0;
349 uc.dwStructSize = sizeof(URL_COMPONENTS);
350 uc.nScheme = 0;
351 uc.lpszScheme = scheme;
352 uc.dwSchemeLength = 20;
353 uc.lpszUserName = user;
354 uc.dwUserNameLength = 20;
355 uc.lpszPassword = pass;
356 uc.dwPasswordLength = 20;
357 uc.lpszHostName = host;
358 uc.dwHostNameLength = 20;
359 uc.nPort = 0;
360 uc.lpszUrlPath = path;
361 uc.dwUrlPathLength = 40;
362 uc.lpszExtraInfo = extra;
363 uc.dwExtraInfoLength = 20;
365 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
366 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
367 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme: %u\n", uc.nScheme );
368 ok( !memcmp( uc.lpszScheme, http, sizeof(http) ), "unexpected scheme: %s\n", wine_dbgstr_w(uc.lpszScheme) );
369 ok( uc.dwSchemeLength == 4, "unexpected scheme length: %u\n", uc.dwSchemeLength );
370 ok( !memcmp( uc.lpszUserName, username, sizeof(username) ), "unexpected username: %s\n", wine_dbgstr_w(uc.lpszUserName) );
371 ok( uc.dwUserNameLength == 8, "unexpected username length: %u\n", uc.dwUserNameLength );
372 ok( !memcmp( uc.lpszPassword, password, sizeof(password) ), "unexpected password: %s\n", wine_dbgstr_w(uc.lpszPassword) );
373 ok( uc.dwPasswordLength == 8, "unexpected password length: %u\n", uc.dwPasswordLength );
374 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected hostname: %s\n", wine_dbgstr_w(uc.lpszHostName) );
375 ok( uc.dwHostNameLength == 14, "unexpected hostname length: %u\n", uc.dwHostNameLength );
376 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
377 ok( !memcmp( uc.lpszUrlPath, about, sizeof(about) ), "unexpected path: %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
378 ok( uc.dwUrlPathLength == 11, "unexpected path length: %u\n", uc.dwUrlPathLength );
379 ok( !memcmp( uc.lpszExtraInfo, query, sizeof(query) ), "unexpected extra info: %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
380 ok( uc.dwExtraInfoLength == 6, "unexpected extra info length: %u\n", uc.dwExtraInfoLength );
382 /* buffers of insufficient length */
383 uc.dwSchemeLength = 1;
384 uc.dwHostNameLength = 1;
385 uc.dwUrlPathLength = 40; /* sufficient */
386 SetLastError( 0xdeadbeef );
387 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
388 error = GetLastError();
389 ok( !ret, "WinHttpCrackUrl succeeded\n" );
390 ok( error == ERROR_INSUFFICIENT_BUFFER, "got %u, expected ERROR_INSUFFICIENT_BUFFER\n", error );
391 ok( uc.dwSchemeLength == 5, "unexpected scheme length: %u\n", uc.dwSchemeLength );
392 ok( uc.dwHostNameLength == 15, "unexpected hostname length: %u\n", uc.dwHostNameLength );
393 ok( uc.dwUrlPathLength == 11, "unexpected path length: %u\n", uc.dwUrlPathLength );
395 /* no buffers */
396 reset_url_components( &uc );
397 SetLastError( 0xdeadbeef );
398 ret = WinHttpCrackUrl( url_k1, 0, 0, &uc);
399 error = GetLastError();
400 ok( ret, "WinHttpCrackUrl failed le=%u\n", error );
401 ok( error == ERROR_SUCCESS || broken(error == ERROR_INVALID_PARAMETER) /* < win7 */,
402 "got %u, expected ERROR_SUCCESS\n", error );
403 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
404 ok( uc.lpszScheme == url_k1,"unexpected scheme\n" );
405 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
406 ok( uc.lpszUserName == url_k1 + 7, "unexpected username\n" );
407 ok( uc.dwUserNameLength == 8, "unexpected username length\n" );
408 ok( uc.lpszPassword == url_k1 + 16, "unexpected password\n" );
409 ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
410 ok( uc.lpszHostName == url_k1 + 25, "unexpected hostname\n" );
411 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
412 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
413 ok( uc.lpszUrlPath == url_k1 + 39, "unexpected path\n" );
414 ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
415 ok( uc.lpszExtraInfo == url_k1 + 50, "unexpected extra info\n" );
416 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
418 reset_url_components( &uc );
419 uc.dwSchemeLength = uc.dwHostNameLength = uc.dwUserNameLength = 1;
420 uc.dwPasswordLength = uc.dwUrlPathLength = uc.dwExtraInfoLength = 1;
421 ret = WinHttpCrackUrl( url_k2, 0, 0,&uc);
422 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
423 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
424 ok( uc.lpszScheme == url_k2, "unexpected scheme\n" );
425 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
426 ok( uc.lpszUserName == NULL ,"unexpected username\n" );
427 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
428 ok( uc.lpszPassword == NULL, "unexpected password\n" );
429 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
430 ok( uc.lpszHostName == url_k2 + 7, "unexpected hostname\n" );
431 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
432 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
433 ok( uc.lpszUrlPath == url_k2 + 21, "unexpected path\n" );
434 ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
435 ok( uc.lpszExtraInfo == url_k2 + 21, "unexpected extra info\n" );
436 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
438 reset_url_components( &uc );
439 ret = WinHttpCrackUrl( url_k3, 0, 0, &uc );
440 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
441 ok( uc.nScheme == INTERNET_SCHEME_HTTPS, "unexpected scheme\n" );
442 ok( uc.lpszScheme == url_k3, "unexpected scheme\n" );
443 ok( uc.dwSchemeLength == 5, "unexpected scheme length\n" );
444 ok( uc.lpszUserName == NULL, "unexpected username\n" );
445 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
446 ok( uc.lpszPassword == NULL, "unexpected password\n" );
447 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
448 ok( uc.lpszHostName == url_k3 + 8, "unexpected hostname\n" );
449 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
450 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
451 ok( uc.lpszUrlPath == url_k3 + 22, "unexpected path\n" );
452 ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
453 ok( uc.lpszExtraInfo == url_k3 + 27, "unexpected extra info\n" );
454 ok( uc.dwExtraInfoLength == 1, "unexpected extra info length\n" );
456 /* bad parameters */
457 reset_url_components( &uc );
458 SetLastError( 0xdeadbeef );
459 ret = WinHttpCrackUrl( url_k4, 0, 0, &uc );
460 ok( !ret, "WinHttpCrackUrl succeeded\n" );
461 error = GetLastError();
462 ok( error == ERROR_WINHTTP_INVALID_URL, "got %u\n", error );
464 reset_url_components( &uc );
465 SetLastError( 0xdeadbeef );
466 ret = WinHttpCrackUrl( url_k5, 0, 0, &uc );
467 ok( !ret, "WinHttpCrackUrl succeeded\n" );
468 error = GetLastError();
469 ok( error == ERROR_WINHTTP_INVALID_URL, "got %u\n", error );
471 reset_url_components( &uc );
472 SetLastError( 0xdeadbeef );
473 ret = WinHttpCrackUrl( url_k6, 0, 0, &uc );
474 ok( !ret, "WinHttpCrackUrl succeeded\n" );
475 error = GetLastError();
476 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u\n", error );
478 reset_url_components( &uc );
479 SetLastError( 0xdeadbeef );
480 ret = WinHttpCrackUrl( url_k7, 0, 0, &uc );
481 ok( !ret, "WinHttpCrackUrl succeeded\n" );
482 error = GetLastError();
483 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u\n", error );
485 reset_url_components( &uc );
486 SetLastError( 0xdeadbeef );
487 ret = WinHttpCrackUrl( url_k8, 0, 0, &uc );
488 error = GetLastError();
489 ok( !ret, "WinHttpCrackUrl succeeded\n" );
490 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u\n", error );
492 reset_url_components( &uc );
493 ret = WinHttpCrackUrl( url_k9, 0, 0, &uc );
494 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
495 ok( uc.lpszUrlPath == url_k9 + 14 || broken(uc.lpszUrlPath == url_k9 + 13) /* win8 */,
496 "unexpected path: %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
497 ok( uc.dwUrlPathLength == 0, "unexpected path length: %u\n", uc.dwUrlPathLength );
498 ok( uc.lpszExtraInfo == url_k9 + 14 || broken(uc.lpszExtraInfo == url_k9 + 13) /* win8 */,
499 "unexpected extra info: %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
500 ok( uc.dwExtraInfoLength == 0 || broken(uc.dwExtraInfoLength == 1) /* win8 */,
501 "unexpected extra info length: %u\n", uc.dwExtraInfoLength );
503 reset_url_components( &uc );
504 ret = WinHttpCrackUrl( url_k10, 0, 0, &uc );
505 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
506 ok( uc.lpszUrlPath == url_k10 + 13, "unexpected path: %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
507 ok( uc.dwUrlPathLength == 7, "unexpected path length: %u\n", uc.dwUrlPathLength );
508 ok( uc.lpszExtraInfo == url_k10 + 20, "unexpected extra info: %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
509 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length: %u\n", uc.dwExtraInfoLength );
511 reset_url_components( &uc );
512 SetLastError( 0xdeadbeef );
513 ret = WinHttpCrackUrl( url4, 0, 0, &uc );
514 error = GetLastError();
515 ok( !ret, "WinHttpCrackUrl succeeded\n" );
516 ok( error == ERROR_WINHTTP_INVALID_URL, "got %u\n", error );
518 reset_url_components( &uc );
519 SetLastError( 0xdeadbeef );
520 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
521 error = GetLastError();
522 ok( !ret, "WinHttpCrackUrl succeeded\n" );
523 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u\n", error );
525 SetLastError( 0xdeadbeef );
526 ret = WinHttpCrackUrl( url1, 0, 0, NULL );
527 error = GetLastError();
528 ok( !ret, "WinHttpCrackUrl succeeded\n" );
529 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
531 SetLastError( 0xdeadbeef );
532 ret = WinHttpCrackUrl( NULL, 0, 0, &uc );
533 error = GetLastError();
534 ok( !ret, "WinHttpCrackUrl succeeded\n" );
535 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
537 /* decoding without buffers */
538 reset_url_components( &uc );
539 SetLastError(0xdeadbeef);
540 ret = WinHttpCrackUrl( url7, 0, ICU_DECODE, &uc );
541 error = GetLastError();
542 ok( !ret, "WinHttpCrackUrl succeeded\n" );
543 ok( error == ERROR_INVALID_PARAMETER, "got %u, expected ERROR_INVALID_PARAMETER\n", error );
545 /* decoding with buffers */
546 uc.lpszScheme = scheme;
547 uc.dwSchemeLength = 20;
548 uc.lpszUserName = user;
549 uc.dwUserNameLength = 20;
550 uc.lpszPassword = pass;
551 uc.dwPasswordLength = 20;
552 uc.lpszHostName = host;
553 uc.dwHostNameLength = 20;
554 uc.nPort = 0;
555 uc.lpszUrlPath = path;
556 uc.dwUrlPathLength = 80;
557 uc.lpszExtraInfo = extra;
558 uc.dwExtraInfoLength = 40;
559 path[0] = 0;
561 ret = WinHttpCrackUrl( url7, 0, ICU_DECODE, &uc );
562 ok( ret, "WinHttpCrackUrl failed %u\n", GetLastError() );
563 ok( !memcmp( uc.lpszUrlPath + 11, escape, 21 * sizeof(WCHAR) ), "unexpected path\n" );
564 ok( uc.dwUrlPathLength == 32, "unexpected path length %u\n", uc.dwUrlPathLength );
565 ok( !memcmp( uc.lpszExtraInfo, escape + 21, 12 * sizeof(WCHAR) ), "unexpected extra info\n" );
566 ok( uc.dwExtraInfoLength == 12, "unexpected extra info length %u\n", uc.dwExtraInfoLength );
568 /* Urls with specified port numbers */
569 /* decoding with buffers */
570 uc.lpszScheme = scheme;
571 uc.dwSchemeLength = 20;
572 uc.lpszUserName = user;
573 uc.dwUserNameLength = 20;
574 uc.lpszPassword = pass;
575 uc.dwPasswordLength = 20;
576 uc.lpszHostName = host;
577 uc.dwHostNameLength = 20;
578 uc.nPort = 0;
579 uc.lpszUrlPath = path;
580 uc.dwUrlPathLength = 40;
581 uc.lpszExtraInfo = extra;
582 uc.dwExtraInfoLength = 20;
583 path[0] = 0;
585 ret = WinHttpCrackUrl( url6, 0, 0, &uc );
586 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
587 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected host name: %s\n", wine_dbgstr_w(uc.lpszHostName) );
588 ok( uc.dwHostNameLength == 14, "unexpected host name length: %d\n", uc.dwHostNameLength );
589 ok( uc.nPort == 42, "unexpected port: %u\n", uc.nPort );
591 /* decoding without buffers */
592 reset_url_components( &uc );
593 ret = WinHttpCrackUrl( url8, 0, 0, &uc );
594 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
595 ok( uc.nPort == 0, "unexpected port: %u\n", uc.nPort );
597 reset_url_components( &uc );
598 ret = WinHttpCrackUrl( url9, 0, 0, &uc );
599 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
600 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
602 reset_url_components( &uc );
603 ret = WinHttpCrackUrl( url10, 0, 0, &uc );
604 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
605 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
607 reset_url_components( &uc );
608 SetLastError( 0xdeadbeef );
609 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
610 error = GetLastError();
611 ok( !ret, "WinHttpCrackUrl succeeded\n" );
612 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
614 reset_url_components( &uc );
615 SetLastError( 0xdeadbeef );
616 ret = WinHttpCrackUrl( http, 0, 0, &uc );
617 error = GetLastError();
618 ok( !ret, "WinHttpCrackUrl succeeded\n" );
619 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
621 reset_url_components( &uc );
622 ret = WinHttpCrackUrl( url11, 0, 0, &uc);
623 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
624 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
625 ok( uc.lpszScheme == url11,"unexpected scheme\n" );
626 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
627 ok( uc.lpszUserName == NULL, "unexpected username\n" );
628 ok( uc.lpszPassword == NULL, "unexpected password\n" );
629 ok( uc.lpszHostName == url11 + 7, "unexpected hostname\n" );
630 ok( uc.dwHostNameLength == 11, "unexpected hostname length\n" );
631 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
632 ok( uc.lpszUrlPath == url11 + 18, "unexpected path\n" );
633 ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
634 ok( uc.lpszExtraInfo == url11 + 23, "unexpected extra info\n" );
635 ok( uc.dwExtraInfoLength == 39, "unexpected extra info length\n" );
637 uc.lpszScheme = scheme;
638 uc.dwSchemeLength = 20;
639 uc.lpszHostName = host;
640 uc.dwHostNameLength = 20;
641 uc.lpszUserName = NULL;
642 uc.dwUserNameLength = 0;
643 uc.lpszPassword = NULL;
644 uc.dwPasswordLength = 0;
645 uc.lpszUrlPath = path;
646 uc.dwUrlPathLength = 40;
647 uc.lpszExtraInfo = NULL;
648 uc.dwExtraInfoLength = 0;
649 uc.nPort = 0;
650 ret = WinHttpCrackUrl( url12, 0, ICU_DECODE, &uc );
651 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
653 uc.lpszScheme = scheme;
654 uc.dwSchemeLength = 20;
655 uc.lpszHostName = host;
656 uc.dwHostNameLength = 20;
657 uc.lpszUserName = NULL;
658 uc.dwUserNameLength = 0;
659 uc.lpszPassword = NULL;
660 uc.dwPasswordLength = 0;
661 uc.lpszUrlPath = path;
662 uc.dwUrlPathLength = 40;
663 uc.lpszExtraInfo = NULL;
664 uc.dwExtraInfoLength = 0;
665 uc.nPort = 0;
666 ret = WinHttpCrackUrl( url13, 0, ICU_ESCAPE|ICU_DECODE, &uc );
667 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
668 ok( !lstrcmpW( uc.lpszHostName, hostnameW ), "unexpected host name\n" );
669 ok( !lstrcmpW( uc.lpszUrlPath, pathW ), "unexpected path\n" );
671 uc.dwStructSize = sizeof(uc);
672 uc.lpszScheme = NULL;
673 uc.dwSchemeLength = 0;
674 uc.nScheme = 0;
675 uc.lpszHostName = NULL;
676 uc.dwHostNameLength = ~0u;
677 uc.nPort = 0;
678 uc.lpszUserName = NULL;
679 uc.dwUserNameLength = ~0u;
680 uc.lpszPassword = NULL;
681 uc.dwPasswordLength = ~0u;
682 uc.lpszUrlPath = NULL;
683 uc.dwUrlPathLength = ~0u;
684 uc.lpszExtraInfo = NULL;
685 uc.dwExtraInfoLength = ~0u;
686 ret = WinHttpCrackUrl( url14, 0, 0, &uc );
687 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
688 ok( !uc.lpszScheme, "unexpected scheme %s\n", wine_dbgstr_w(uc.lpszScheme) );
689 ok( !uc.dwSchemeLength, "unexpected length %u\n", uc.dwSchemeLength );
690 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme %u\n", uc.nScheme );
691 ok( !lstrcmpW( uc.lpszHostName, url14 + 7 ), "unexpected hostname %s\n", wine_dbgstr_w(uc.lpszHostName) );
692 ok( uc.dwHostNameLength == 14, "unexpected length %u\n", uc.dwHostNameLength );
693 ok( uc.nPort == 80, "unexpected port %u\n", uc.nPort );
694 ok( !uc.lpszUserName, "unexpected username\n" );
695 ok( !uc.dwUserNameLength, "unexpected length %u\n", uc.dwUserNameLength );
696 ok( !uc.lpszPassword, "unexpected password\n" );
697 ok( !uc.dwPasswordLength, "unexpected length %u\n", uc.dwPasswordLength );
698 ok( !lstrcmpW( uc.lpszUrlPath, url14 + 21 ), "unexpected path %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
699 ok( uc.dwUrlPathLength == 5, "unexpected length %u\n", uc.dwUrlPathLength );
700 ok( !uc.lpszExtraInfo[0], "unexpected extra info %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
701 ok( uc.dwExtraInfoLength == 0, "unexpected length %u\n", uc.dwExtraInfoLength );
703 uc.dwStructSize = sizeof(uc);
704 uc.lpszScheme = scheme;
705 uc.dwSchemeLength = 0;
706 uc.nScheme = 0;
707 uc.lpszHostName = NULL;
708 uc.dwHostNameLength = 0;
709 uc.nPort = 0;
710 uc.lpszUserName = NULL;
711 uc.dwUserNameLength = ~0u;
712 uc.lpszPassword = NULL;
713 uc.dwPasswordLength = ~0u;
714 uc.lpszUrlPath = NULL;
715 uc.dwUrlPathLength = 0;
716 uc.lpszExtraInfo = NULL;
717 uc.dwExtraInfoLength = 0;
718 SetLastError( 0xdeadbeef );
719 ret = WinHttpCrackUrl( url14, 0, 0, &uc );
720 error = GetLastError();
721 ok( !ret, "WinHttpCrackUrl succeeded\n" );
722 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
723 ok( !lstrcmpW( uc.lpszScheme, http ), "unexpected scheme %s\n", wine_dbgstr_w(uc.lpszScheme) );
724 ok( !uc.dwSchemeLength, "unexpected length %u\n", uc.dwSchemeLength );
725 ok( uc.nScheme == 0, "unexpected scheme %u\n", uc.nScheme );
726 ok( !uc.lpszHostName, "unexpected hostname %s\n", wine_dbgstr_w(uc.lpszHostName) );
727 ok( uc.dwHostNameLength == 0, "unexpected length %u\n", uc.dwHostNameLength );
728 ok( uc.nPort == 0, "unexpected port %u\n", uc.nPort );
729 ok( !uc.lpszUserName, "unexpected username\n" );
730 ok( uc.dwUserNameLength == ~0u, "unexpected length %u\n", uc.dwUserNameLength );
731 ok( !uc.lpszPassword, "unexpected password\n" );
732 ok( uc.dwPasswordLength == ~0u, "unexpected length %u\n", uc.dwPasswordLength );
733 ok( !uc.lpszUrlPath, "unexpected path %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
734 ok( uc.dwUrlPathLength == 0, "unexpected length %u\n", uc.dwUrlPathLength );
735 ok( !uc.lpszExtraInfo, "unexpected extra info %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
736 ok( uc.dwExtraInfoLength == 0, "unexpected length %u\n", uc.dwExtraInfoLength );
738 reset_url_components( &uc );
739 SetLastError( 0xdeadbeef );
740 ret = WinHttpCrackUrl( url15, 0, 0, &uc );
741 error = GetLastError();
742 ok( !ret, "WinHttpCrackUrl succeeded\n" );
743 ok( error == ERROR_WINHTTP_INVALID_URL, "got %u\n", error );
745 reset_url_components( &uc );
746 uc.nPort = 1;
747 ret = WinHttpCrackUrl( url16, 0, 0, &uc );
748 ok( ret, "got %u\n", GetLastError() );
749 ok( !uc.nPort, "got %u\n", uc.nPort );
751 reset_url_components( &uc );
752 uc.nPort = 1;
753 ret = WinHttpCrackUrl( url17, 0, 0, &uc );
754 ok( ret, "got %u\n", GetLastError() );
755 todo_wine ok( uc.nPort == 80, "got %u\n", uc.nPort );
758 START_TEST(url)
760 WinHttpCreateUrl_test();
761 WinHttpCrackUrl_test();