include/mscvpdb.h: Use flexible array members for the rest of structures.
[wine.git] / dlls / winhttp / tests / url.c
blobfadf8b850ca5a7caab081eb06cb40a513ca32e30
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[] = {' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>',
37 '?','@','[','\\',']','^','_','`','{','|','}','~',0};
38 static WCHAR escape2[] = {'\r',0x1f,' ','\n',0x7f,'\r','\n',0};
39 static WCHAR escape3[] = {'?','t','e','x','t','=',0xfb00,0};
40 static WCHAR escape4[] = {'/','t','e','x','t','=',0xfb00,0};
42 static const WCHAR url1[] = L"http://username:password@www.winehq.org/site/about?query";
43 static const WCHAR url2[] = L"http://username:";
44 static const WCHAR url3[] = L"http://www.winehq.org/site/about?query";
45 static const WCHAR url4[] = L"http://";
46 static const WCHAR url5[] = L"ftp://username:password@www.winehq.org:80/site/about?query";
47 static const WCHAR url6[] = L"http://username:password@www.winehq.org:42/site/about?query";
48 static const WCHAR url7[] = L"http://username:password@www.winehq.org/site/about%20!%22%23$%25&'()"
49 "*+,-./:;%3C=%3E?@%5B%5C%5D%5E_%60%7B%7C%7D%7E";
50 static const WCHAR url8[] = L"http://username:password@www.winehq.org:0/site/about?query";
51 static const WCHAR url9[] = L"http://username:password@www.winehq.org:80/site/about?query";
52 static const WCHAR url10[] = L"https://username:password@www.winehq.org:443/site/about?query";
53 static const WCHAR url11[] = L"http://example.net/path?var1=example@example.com&var2=x&var3=y";
54 static const WCHAR url12[] = L"https://tools.google.com/service/update2?w=3:BxDHoWy8ezM";
55 static const WCHAR url13[] = L"http://winehq.o g/path with spaces";
56 static const WCHAR url14[] = L"http://www.winehq.org/test";
57 static const WCHAR url15[] = L"http://winehq.org:65536";
58 static const WCHAR url16[] = L"http://winehq.org:0";
59 static const WCHAR url17[] = L"http://winehq.org:";
60 static const WCHAR url18[] = L"http://%0D%1F%20%0A%7F%0D%0A";
61 static const WCHAR url19[] = L"http://?text=\xfb00";
62 static const WCHAR url20[] = L"http:///text=\xfb00";
63 static const WCHAR url21[] = L"https://nba2k19-ws.2ksports.com:19133/nba/v4/Accounts/get_account?x=3789526775265663876";
64 static const WCHAR url22[] = L"http://winehq.org:/";
66 static const WCHAR url_k1[] = L"http://username:password@www.winehq.org/site/about";
67 static const WCHAR url_k2[] = L"http://www.winehq.org";
68 static const WCHAR url_k3[] = L"https://www.winehq.org/post?";
69 static const WCHAR url_k4[] = L"HTTP:www.winehq.org";
70 static const WCHAR url_k5[] = L"http:/www.winehq.org";
71 static const WCHAR url_k6[] = L"www.winehq.org";
72 static const WCHAR url_k7[] = L"www";
73 static const WCHAR url_k8[] = L"http";
74 static const WCHAR url_k9[] = L"http://winehq?";
75 static const WCHAR url_k10[] = L"http://winehq/post;a";
77 static void fill_url_components( URL_COMPONENTS *uc )
79 uc->dwStructSize = sizeof(URL_COMPONENTS);
80 uc->lpszScheme = http;
81 uc->dwSchemeLength = lstrlenW( uc->lpszScheme );
82 uc->nScheme = INTERNET_SCHEME_HTTP;
83 uc->lpszHostName = winehq;
84 uc->dwHostNameLength = lstrlenW( uc->lpszHostName );
85 uc->nPort = 80;
86 uc->lpszUserName = username;
87 uc->dwUserNameLength = lstrlenW( uc->lpszUserName );
88 uc->lpszPassword = password;
89 uc->dwPasswordLength = lstrlenW( uc->lpszPassword );
90 uc->lpszUrlPath = about;
91 uc->dwUrlPathLength = lstrlenW( uc->lpszUrlPath );
92 uc->lpszExtraInfo = query;
93 uc->dwExtraInfoLength = lstrlenW( uc->lpszExtraInfo );
96 static void WinHttpCreateUrl_test( void )
98 URL_COMPONENTS uc;
99 WCHAR *url;
100 DWORD len, err;
101 BOOL ret;
103 /* NULL components */
104 len = ~0u;
105 SetLastError( 0xdeadbeef );
106 ret = WinHttpCreateUrl( NULL, 0, NULL, &len );
107 ok( !ret, "expected failure\n" );
108 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %lu\n", GetLastError() );
109 ok( len == ~0u, "expected len ~0u got %lu\n", len );
111 /* zero'ed components */
112 memset( &uc, 0, sizeof(URL_COMPONENTS) );
113 SetLastError( 0xdeadbeef );
114 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
115 ok( !ret, "expected failure\n" );
116 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %lu\n", GetLastError() );
117 ok( len == ~0u, "expected len ~0u got %lu\n", len );
119 /* valid components, NULL url, NULL length */
120 fill_url_components( &uc );
121 SetLastError( 0xdeadbeef );
122 ret = WinHttpCreateUrl( &uc, 0, NULL, NULL );
123 ok( !ret, "expected failure\n" );
124 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %lu\n", GetLastError() );
126 /* valid components, NULL url, insufficient length */
127 len = 0;
128 SetLastError( 0xdeadbeef );
129 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
130 ok( !ret, "expected failure\n" );
131 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %lu\n", GetLastError() );
132 ok( len == 57, "expected len 57 got %lu\n", len );
134 /* valid components, NULL url, sufficient length */
135 SetLastError( 0xdeadbeef );
136 len = 256;
137 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
138 err = GetLastError();
139 ok( !ret, "expected failure\n" );
140 ok( err == ERROR_INVALID_PARAMETER || broken(err == ERROR_INSUFFICIENT_BUFFER) /* < win7 */,
141 "expected ERROR_INVALID_PARAMETER got %lu\n", GetLastError() );
142 ok( len == 256 || broken(len == 57) /* < win7 */, "expected len 256 got %lu\n", len );
144 /* correct size, NULL url */
145 fill_url_components( &uc );
146 SetLastError( 0xdeadbeef );
147 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
148 err = GetLastError();
149 ok( !ret, "expected failure\n" );
150 ok( err == ERROR_INVALID_PARAMETER || broken(err == ERROR_INSUFFICIENT_BUFFER) /* < win7 */,
151 "expected ERROR_INVALID_PARAMETER got %lu\n", GetLastError() );
152 ok( len == 256 || broken(len == 57) /* < win7 */, "expected len 256 got %lu\n", len );
154 /* valid components, allocated url, short length */
155 SetLastError( 0xdeadbeef );
156 url = HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) );
157 url[0] = 0;
158 len = 2;
159 ret = WinHttpCreateUrl( &uc, 0, url, &len );
160 ok( !ret, "expected failure\n" );
161 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %lu\n", GetLastError() );
162 ok( len == 57, "expected len 57 got %lu\n", len );
164 /* allocated url, NULL scheme */
165 SetLastError( 0xdeadbeef );
166 uc.lpszScheme = NULL;
167 url[0] = 0;
168 len = 256;
169 ret = WinHttpCreateUrl( &uc, 0, url, &len );
170 ok( ret, "expected success\n" );
171 ok( GetLastError() == ERROR_SUCCESS || broken(GetLastError() == 0xdeadbeef) /* < win7 */,
172 "expected ERROR_SUCCESS got %lu\n", GetLastError() );
173 ok( len == 56, "expected len 56 got %lu\n", len );
174 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
176 /* allocated url, 0 scheme */
177 fill_url_components( &uc );
178 uc.nScheme = 0;
179 url[0] = 0;
180 len = 256;
181 ret = WinHttpCreateUrl( &uc, 0, url, &len );
182 ok( ret, "expected success\n" );
183 ok( len == 56, "expected len 56 got %lu\n", len );
185 /* valid components, allocated url */
186 fill_url_components( &uc );
187 url[0] = 0;
188 len = 256;
189 ret = WinHttpCreateUrl( &uc, 0, url, &len );
190 ok( ret, "expected success\n" );
191 ok( len == 56, "expected len 56 got %lu\n", len );
192 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
194 /* valid username, NULL password */
195 fill_url_components( &uc );
196 uc.lpszPassword = NULL;
197 url[0] = 0;
198 len = 256;
199 ret = WinHttpCreateUrl( &uc, 0, url, &len );
200 ok( ret, "expected success\n" );
202 /* valid username, empty password */
203 fill_url_components( &uc );
204 uc.lpszPassword = empty;
205 url[0] = 0;
206 len = 256;
207 ret = WinHttpCreateUrl( &uc, 0, url, &len );
208 ok( ret, "expected success\n" );
209 ok( len == 56, "expected len 56 got %lu\n", len );
210 ok( !lstrcmpW( url, url2 ), "url doesn't match\n" );
212 /* valid password, NULL username */
213 fill_url_components( &uc );
214 SetLastError( 0xdeadbeef );
215 uc.lpszUserName = NULL;
216 url[0] = 0;
217 len = 256;
218 ret = WinHttpCreateUrl( &uc, 0, url, &len );
219 ok( !ret, "expected failure\n" );
220 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %lu\n", GetLastError() );
222 /* valid password, empty username */
223 fill_url_components( &uc );
224 uc.lpszUserName = empty;
225 url[0] = 0;
226 len = 256;
227 ret = WinHttpCreateUrl( &uc, 0, url, &len );
228 ok( ret, "expected success\n");
230 /* NULL username, NULL password */
231 fill_url_components( &uc );
232 uc.lpszUserName = NULL;
233 uc.lpszPassword = NULL;
234 url[0] = 0;
235 len = 256;
236 ret = WinHttpCreateUrl( &uc, 0, url, &len );
237 ok( ret, "expected success\n" );
238 ok( len == 38, "expected len 38 got %lu\n", len );
239 ok( !lstrcmpW( url, url3 ), "url doesn't match\n" );
241 /* empty username, empty password */
242 fill_url_components( &uc );
243 uc.lpszUserName = empty;
244 uc.lpszPassword = empty;
245 url[0] = 0;
246 len = 256;
247 ret = WinHttpCreateUrl( &uc, 0, url, &len );
248 ok( ret, "expected success\n" );
249 ok( len == 56, "expected len 56 got %lu\n", len );
250 ok( !lstrcmpW( url, url4 ), "url doesn't match\n" );
252 /* nScheme has lower precedence than lpszScheme */
253 fill_url_components( &uc );
254 uc.lpszScheme = ftp;
255 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
256 url[0] = 0;
257 len = 256;
258 ret = WinHttpCreateUrl( &uc, 0, url, &len );
259 ok( ret, "expected success\n" );
260 ok( len == lstrlenW( url5 ), "expected len %d got %lu\n", lstrlenW( url5 ) + 1, len );
261 ok( !lstrcmpW( url, url5 ), "url doesn't match\n" );
263 /* non-standard port */
264 uc.lpszScheme = http;
265 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
266 uc.nPort = 42;
267 url[0] = 0;
268 len = 256;
269 ret = WinHttpCreateUrl( &uc, 0, url, &len );
270 ok( ret, "expected success\n" );
271 ok( len == 59, "expected len 59 got %lu\n", len );
272 ok( !lstrcmpW( url, url6 ), "url doesn't match\n" );
274 /* escape extra info */
275 fill_url_components( &uc );
276 uc.lpszExtraInfo = escape;
277 uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo );
278 url[0] = 0;
279 len = 256;
280 ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
281 ok( ret, "expected success\n" );
282 ok( len == 113, "expected len 113 got %lu\n", len );
283 ok( !lstrcmpW( url, url7 ), "url doesn't match %s\n", wine_dbgstr_w(url) );
285 /* escape extra info */
286 memset( &uc, 0, sizeof(uc) );
287 uc.dwStructSize = sizeof(uc);
288 uc.lpszExtraInfo = escape2;
289 uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo );
290 url[0] = 0;
291 len = 256;
292 ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
293 ok( ret, "expected success\n" );
294 ok( len == lstrlenW(url18), "expected len %u got %lu\n", lstrlenW(url18), len );
295 ok( !lstrcmpW( url, url18 ), "url doesn't match\n" );
297 /* extra info with Unicode characters */
298 memset( &uc, 0, sizeof(uc) );
299 uc.dwStructSize = sizeof(uc);
300 uc.lpszExtraInfo = escape3;
301 uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo );
302 url[0] = 0;
303 len = 256;
304 SetLastError( 0xdeadbeef );
305 ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
306 err = GetLastError();
307 ok( !ret || GetACP() == CP_UTF8, "expected failure\n" );
308 ok( err == ERROR_INVALID_PARAMETER || (!err && GetACP() == CP_UTF8), "got %lu\n", err );
310 /* extra info with Unicode characters, no ICU_ESCAPE */
311 memset( &uc, 0, sizeof(uc) );
312 uc.dwStructSize = sizeof(uc);
313 uc.lpszExtraInfo = escape3;
314 uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo );
315 url[0] = 0;
316 len = 256;
317 ret = WinHttpCreateUrl( &uc, 0, url, &len );
318 ok( ret || broken(!ret) /* < win7 */, "expected success\n" );
319 if (ret)
321 ok( len == lstrlenW(url19), "expected len %u got %lu\n", lstrlenW(url19), len );
322 ok( !lstrcmpW( url, url19 ), "url doesn't match %s\n", wine_dbgstr_w(url) );
325 /* escape path */
326 memset( &uc, 0, sizeof(uc) );
327 uc.dwStructSize = sizeof(uc);
328 uc.lpszUrlPath = escape2;
329 uc.dwUrlPathLength = lstrlenW( uc.lpszUrlPath );
330 url[0] = 0;
331 len = 256;
332 ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
333 ok( ret, "expected success\n" );
334 ok( len == lstrlenW(url18), "expected len %u got %lu\n", lstrlenW(url18), len );
335 ok( !lstrcmpW( url, url18 ), "url doesn't match\n" );
337 /* path with Unicode characters */
338 memset( &uc, 0, sizeof(uc) );
339 uc.dwStructSize = sizeof(uc);
340 uc.lpszUrlPath = escape4;
341 uc.dwUrlPathLength = lstrlenW( uc.lpszUrlPath );
342 url[0] = 0;
343 len = 256;
344 SetLastError( 0xdeadbeef );
345 ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
346 err = GetLastError();
347 ok( !ret || GetACP() == CP_UTF8, "expected failure\n" );
348 ok( err == ERROR_INVALID_PARAMETER || (!err && GetACP() == CP_UTF8), "got %lu\n", err );
350 /* path with Unicode characters, no ICU_ESCAPE */
351 memset( &uc, 0, sizeof(uc) );
352 uc.dwStructSize = sizeof(uc);
353 uc.lpszUrlPath = escape4;
354 uc.dwUrlPathLength = lstrlenW( uc.lpszUrlPath );
355 url[0] = 0;
356 len = 256;
357 ret = WinHttpCreateUrl( &uc, 0, url, &len );
358 ok( ret || broken(!ret) /* < win7 */, "expected success\n" );
359 if (ret)
361 ok( len == lstrlenW(url20), "expected len %u got %lu\n", lstrlenW(url20), len );
362 ok( !lstrcmpW( url, url20 ), "url doesn't match %s\n", wine_dbgstr_w(url) );
365 /* NULL lpszScheme, 0 nScheme and nPort */
366 fill_url_components( &uc );
367 uc.lpszScheme = NULL;
368 uc.dwSchemeLength = 0;
369 uc.nScheme = 0;
370 uc.nPort = 0;
371 url[0] = 0;
372 len = 256;
373 ret = WinHttpCreateUrl( &uc, 0, url, &len );
374 ok( ret, "expected success\n" );
375 ok( len == 58, "expected len 58 got %lu\n", len );
376 ok( !lstrcmpW( url, url8 ), "url doesn't match\n" );
378 HeapFree( GetProcessHeap(), 0, url );
381 static void reset_url_components( URL_COMPONENTS *uc )
383 memset( uc, 0, sizeof(URL_COMPONENTS) );
384 uc->dwStructSize = sizeof(URL_COMPONENTS);
385 uc->dwSchemeLength = ~0u;
386 uc->dwHostNameLength = 1;
387 uc->nPort = 0;
388 uc->dwUserNameLength = ~0u;
389 uc->dwPasswordLength = ~0u;
390 uc->dwUrlPathLength = ~0u;
391 uc->dwExtraInfoLength = ~0u;
394 static void WinHttpCrackUrl_test( void )
396 URL_COMPONENTSW uc;
397 WCHAR scheme[20], user[20], pass[20], host[40], path[80], extra[40];
398 DWORD error;
399 BOOL ret;
401 /* buffers of sufficient length */
402 scheme[0] = user[0] = pass[0] = host[0] = path[0] = extra[0] = 0;
404 uc.dwStructSize = sizeof(URL_COMPONENTS);
405 uc.nScheme = 0;
406 uc.lpszScheme = scheme;
407 uc.dwSchemeLength = 20;
408 uc.lpszUserName = user;
409 uc.dwUserNameLength = 20;
410 uc.lpszPassword = pass;
411 uc.dwPasswordLength = 20;
412 uc.lpszHostName = host;
413 uc.dwHostNameLength = 20;
414 uc.nPort = 0;
415 uc.lpszUrlPath = path;
416 uc.dwUrlPathLength = 40;
417 uc.lpszExtraInfo = extra;
418 uc.dwExtraInfoLength = 20;
420 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
421 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
422 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme: %u\n", uc.nScheme );
423 ok( !memcmp( uc.lpszScheme, http, sizeof(http) ), "unexpected scheme: %s\n", wine_dbgstr_w(uc.lpszScheme) );
424 ok( uc.dwSchemeLength == 4, "unexpected scheme length: %lu\n", uc.dwSchemeLength );
425 ok( !memcmp( uc.lpszUserName, username, sizeof(username) ), "unexpected username: %s\n", wine_dbgstr_w(uc.lpszUserName) );
426 ok( uc.dwUserNameLength == 8, "unexpected username length: %lu\n", uc.dwUserNameLength );
427 ok( !memcmp( uc.lpszPassword, password, sizeof(password) ), "unexpected password: %s\n", wine_dbgstr_w(uc.lpszPassword) );
428 ok( uc.dwPasswordLength == 8, "unexpected password length: %lu\n", uc.dwPasswordLength );
429 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected hostname: %s\n", wine_dbgstr_w(uc.lpszHostName) );
430 ok( uc.dwHostNameLength == 14, "unexpected hostname length: %lu\n", uc.dwHostNameLength );
431 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
432 ok( !memcmp( uc.lpszUrlPath, about, sizeof(about) ), "unexpected path: %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
433 ok( uc.dwUrlPathLength == 11, "unexpected path length: %lu\n", uc.dwUrlPathLength );
434 ok( !memcmp( uc.lpszExtraInfo, query, sizeof(query) ), "unexpected extra info: %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
435 ok( uc.dwExtraInfoLength == 6, "unexpected extra info length: %lu\n", uc.dwExtraInfoLength );
437 /* buffers of insufficient length */
438 uc.dwSchemeLength = 1;
439 uc.dwHostNameLength = 1;
440 uc.dwUrlPathLength = 40; /* sufficient */
441 SetLastError( 0xdeadbeef );
442 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
443 error = GetLastError();
444 ok( !ret, "WinHttpCrackUrl succeeded\n" );
445 ok( error == ERROR_INSUFFICIENT_BUFFER, "got %lu, expected ERROR_INSUFFICIENT_BUFFER\n", error );
446 ok( uc.dwSchemeLength == 5, "unexpected scheme length: %lu\n", uc.dwSchemeLength );
447 ok( uc.dwHostNameLength == 15, "unexpected hostname length: %lu\n", uc.dwHostNameLength );
448 ok( uc.dwUrlPathLength == 11, "unexpected path length: %lu\n", uc.dwUrlPathLength );
450 /* no buffers */
451 reset_url_components( &uc );
452 SetLastError( 0xdeadbeef );
453 ret = WinHttpCrackUrl( url_k1, 0, 0, &uc);
454 error = GetLastError();
455 ok( ret, "WinHttpCrackUrl failed le = %lu\n", error );
456 ok( error == ERROR_SUCCESS || broken(error == ERROR_INVALID_PARAMETER) /* < win7 */,
457 "got %lu, expected ERROR_SUCCESS\n", error );
458 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
459 ok( uc.lpszScheme == url_k1,"unexpected scheme\n" );
460 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
461 ok( uc.lpszUserName == url_k1 + 7, "unexpected username\n" );
462 ok( uc.dwUserNameLength == 8, "unexpected username length\n" );
463 ok( uc.lpszPassword == url_k1 + 16, "unexpected password\n" );
464 ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
465 ok( uc.lpszHostName == url_k1 + 25, "unexpected hostname\n" );
466 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
467 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
468 ok( uc.lpszUrlPath == url_k1 + 39, "unexpected path\n" );
469 ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
470 ok( uc.lpszExtraInfo == url_k1 + 50, "unexpected extra info\n" );
471 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
473 reset_url_components( &uc );
474 uc.dwSchemeLength = uc.dwHostNameLength = uc.dwUserNameLength = 1;
475 uc.dwPasswordLength = uc.dwUrlPathLength = uc.dwExtraInfoLength = 1;
476 ret = WinHttpCrackUrl( url_k2, 0, 0,&uc);
477 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
478 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
479 ok( uc.lpszScheme == url_k2, "unexpected scheme\n" );
480 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
481 ok( uc.lpszUserName == NULL ,"unexpected username\n" );
482 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
483 ok( uc.lpszPassword == NULL, "unexpected password\n" );
484 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
485 ok( uc.lpszHostName == url_k2 + 7, "unexpected hostname\n" );
486 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
487 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
488 ok( uc.lpszUrlPath == url_k2 + 21, "unexpected path\n" );
489 ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
490 ok( uc.lpszExtraInfo == url_k2 + 21, "unexpected extra info\n" );
491 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
493 reset_url_components( &uc );
494 ret = WinHttpCrackUrl( url_k3, 0, 0, &uc );
495 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
496 ok( uc.nScheme == INTERNET_SCHEME_HTTPS, "unexpected scheme\n" );
497 ok( uc.lpszScheme == url_k3, "unexpected scheme\n" );
498 ok( uc.dwSchemeLength == 5, "unexpected scheme length\n" );
499 ok( uc.lpszUserName == NULL, "unexpected username\n" );
500 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
501 ok( uc.lpszPassword == NULL, "unexpected password\n" );
502 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
503 ok( uc.lpszHostName == url_k3 + 8, "unexpected hostname\n" );
504 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
505 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
506 ok( uc.lpszUrlPath == url_k3 + 22, "unexpected path\n" );
507 ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
508 ok( uc.lpszExtraInfo == url_k3 + 27, "unexpected extra info\n" );
509 ok( uc.dwExtraInfoLength == 1, "unexpected extra info length\n" );
511 /* bad parameters */
512 reset_url_components( &uc );
513 SetLastError( 0xdeadbeef );
514 ret = WinHttpCrackUrl( url_k4, 0, 0, &uc );
515 ok( !ret, "WinHttpCrackUrl succeeded\n" );
516 error = GetLastError();
517 ok( error == ERROR_WINHTTP_INVALID_URL, "got %lu\n", error );
519 reset_url_components( &uc );
520 SetLastError( 0xdeadbeef );
521 ret = WinHttpCrackUrl( url_k5, 0, 0, &uc );
522 ok( !ret, "WinHttpCrackUrl succeeded\n" );
523 error = GetLastError();
524 ok( error == ERROR_WINHTTP_INVALID_URL, "got %lu\n", error );
526 reset_url_components( &uc );
527 SetLastError( 0xdeadbeef );
528 ret = WinHttpCrackUrl( url_k6, 0, 0, &uc );
529 ok( !ret, "WinHttpCrackUrl succeeded\n" );
530 error = GetLastError();
531 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %lu\n", error );
533 reset_url_components( &uc );
534 SetLastError( 0xdeadbeef );
535 ret = WinHttpCrackUrl( url_k7, 0, 0, &uc );
536 ok( !ret, "WinHttpCrackUrl succeeded\n" );
537 error = GetLastError();
538 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %lu\n", error );
540 reset_url_components( &uc );
541 SetLastError( 0xdeadbeef );
542 ret = WinHttpCrackUrl( url_k8, 0, 0, &uc );
543 error = GetLastError();
544 ok( !ret, "WinHttpCrackUrl succeeded\n" );
545 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %lu\n", error );
547 reset_url_components( &uc );
548 ret = WinHttpCrackUrl( url_k9, 0, 0, &uc );
549 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
550 ok( uc.lpszUrlPath == url_k9 + 14 || broken(uc.lpszUrlPath == url_k9 + 13) /* win8 */,
551 "unexpected path: %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
552 ok( uc.dwUrlPathLength == 0, "unexpected path length: %lu\n", uc.dwUrlPathLength );
553 ok( uc.lpszExtraInfo == url_k9 + 14 || broken(uc.lpszExtraInfo == url_k9 + 13) /* win8 */,
554 "unexpected extra info: %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
555 ok( uc.dwExtraInfoLength == 0 || broken(uc.dwExtraInfoLength == 1) /* win8 */,
556 "unexpected extra info length: %lu\n", uc.dwExtraInfoLength );
558 reset_url_components( &uc );
559 ret = WinHttpCrackUrl( url_k10, 0, 0, &uc );
560 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
561 ok( uc.lpszUrlPath == url_k10 + 13, "unexpected path: %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
562 ok( uc.dwUrlPathLength == 7, "unexpected path length: %lu\n", uc.dwUrlPathLength );
563 ok( uc.lpszExtraInfo == url_k10 + 20, "unexpected extra info: %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
564 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length: %lu\n", uc.dwExtraInfoLength );
566 reset_url_components( &uc );
567 SetLastError( 0xdeadbeef );
568 ret = WinHttpCrackUrl( url4, 0, 0, &uc );
569 error = GetLastError();
570 ok( !ret, "WinHttpCrackUrl succeeded\n" );
571 ok( error == ERROR_WINHTTP_INVALID_URL, "got %lu\n", error );
573 reset_url_components( &uc );
574 SetLastError( 0xdeadbeef );
575 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
576 error = GetLastError();
577 ok( !ret, "WinHttpCrackUrl succeeded\n" );
578 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %lu\n", error );
580 SetLastError( 0xdeadbeef );
581 ret = WinHttpCrackUrl( url1, 0, 0, NULL );
582 error = GetLastError();
583 ok( !ret, "WinHttpCrackUrl succeeded\n" );
584 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
586 SetLastError( 0xdeadbeef );
587 ret = WinHttpCrackUrl( NULL, 0, 0, &uc );
588 error = GetLastError();
589 ok( !ret, "WinHttpCrackUrl succeeded\n" );
590 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
592 /* decoding without buffers */
593 reset_url_components( &uc );
594 SetLastError(0xdeadbeef);
595 ret = WinHttpCrackUrl( url7, 0, ICU_DECODE, &uc );
596 error = GetLastError();
597 ok( !ret, "WinHttpCrackUrl succeeded\n" );
598 ok( error == ERROR_INVALID_PARAMETER, "got %lu, expected ERROR_INVALID_PARAMETER\n", error );
600 /* decoding with buffers */
601 uc.lpszScheme = scheme;
602 uc.dwSchemeLength = 20;
603 uc.lpszUserName = user;
604 uc.dwUserNameLength = 20;
605 uc.lpszPassword = pass;
606 uc.dwPasswordLength = 20;
607 uc.lpszHostName = host;
608 uc.dwHostNameLength = 20;
609 uc.nPort = 0;
610 uc.lpszUrlPath = path;
611 uc.dwUrlPathLength = 80;
612 uc.lpszExtraInfo = extra;
613 uc.dwExtraInfoLength = 40;
614 path[0] = 0;
616 ret = WinHttpCrackUrl( url7, 0, ICU_DECODE, &uc );
617 ok( ret, "WinHttpCrackUrl failed %lu\n", GetLastError() );
618 ok( !memcmp( uc.lpszUrlPath + 11, escape, 21 * sizeof(WCHAR) ), "unexpected path\n" );
619 ok( uc.dwUrlPathLength == 32, "unexpected path length %lu\n", uc.dwUrlPathLength );
620 ok( !memcmp( uc.lpszExtraInfo, escape + 21, 12 * sizeof(WCHAR) ), "unexpected extra info\n" );
621 ok( uc.dwExtraInfoLength == 12, "unexpected extra info length %lu\n", uc.dwExtraInfoLength );
623 /* Urls with specified port numbers */
624 /* decoding with buffers */
625 uc.lpszScheme = scheme;
626 uc.dwSchemeLength = 20;
627 uc.lpszUserName = user;
628 uc.dwUserNameLength = 20;
629 uc.lpszPassword = pass;
630 uc.dwPasswordLength = 20;
631 uc.lpszHostName = host;
632 uc.dwHostNameLength = 20;
633 uc.nPort = 0;
634 uc.lpszUrlPath = path;
635 uc.dwUrlPathLength = 40;
636 uc.lpszExtraInfo = extra;
637 uc.dwExtraInfoLength = 20;
638 path[0] = 0;
640 ret = WinHttpCrackUrl( url6, 0, 0, &uc );
641 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
642 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected host name: %s\n", wine_dbgstr_w(uc.lpszHostName) );
643 ok( uc.dwHostNameLength == 14, "unexpected host name length: %lu\n", uc.dwHostNameLength );
644 ok( uc.nPort == 42, "unexpected port: %u\n", uc.nPort );
646 /* decoding without buffers */
647 reset_url_components( &uc );
648 ret = WinHttpCrackUrl( url8, 0, 0, &uc );
649 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
650 ok( uc.nPort == 0, "unexpected port: %u\n", uc.nPort );
652 reset_url_components( &uc );
653 ret = WinHttpCrackUrl( url9, 0, 0, &uc );
654 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
655 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
657 reset_url_components( &uc );
658 ret = WinHttpCrackUrl( url10, 0, 0, &uc );
659 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
660 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
662 reset_url_components( &uc );
663 SetLastError( 0xdeadbeef );
664 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
665 error = GetLastError();
666 ok( !ret, "WinHttpCrackUrl succeeded\n" );
667 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %lu, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
669 reset_url_components( &uc );
670 SetLastError( 0xdeadbeef );
671 ret = WinHttpCrackUrl( http, 0, 0, &uc );
672 error = GetLastError();
673 ok( !ret, "WinHttpCrackUrl succeeded\n" );
674 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %lu, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
676 reset_url_components( &uc );
677 ret = WinHttpCrackUrl( url11, 0, 0, &uc);
678 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
679 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
680 ok( uc.lpszScheme == url11,"unexpected scheme\n" );
681 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
682 ok( uc.lpszUserName == NULL, "unexpected username\n" );
683 ok( uc.lpszPassword == NULL, "unexpected password\n" );
684 ok( uc.lpszHostName == url11 + 7, "unexpected hostname\n" );
685 ok( uc.dwHostNameLength == 11, "unexpected hostname length\n" );
686 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
687 ok( uc.lpszUrlPath == url11 + 18, "unexpected path\n" );
688 ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
689 ok( uc.lpszExtraInfo == url11 + 23, "unexpected extra info\n" );
690 ok( uc.dwExtraInfoLength == 39, "unexpected extra info length\n" );
692 uc.lpszScheme = scheme;
693 uc.dwSchemeLength = 20;
694 uc.lpszHostName = host;
695 uc.dwHostNameLength = 20;
696 uc.lpszUserName = NULL;
697 uc.dwUserNameLength = 0;
698 uc.lpszPassword = NULL;
699 uc.dwPasswordLength = 0;
700 uc.lpszUrlPath = path;
701 uc.dwUrlPathLength = 40;
702 uc.lpszExtraInfo = NULL;
703 uc.dwExtraInfoLength = 0;
704 uc.nPort = 0;
705 ret = WinHttpCrackUrl( url12, 0, ICU_DECODE, &uc );
706 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
708 uc.lpszScheme = scheme;
709 uc.dwSchemeLength = 20;
710 uc.lpszHostName = host;
711 uc.dwHostNameLength = 20;
712 uc.lpszUserName = NULL;
713 uc.dwUserNameLength = 0;
714 uc.lpszPassword = NULL;
715 uc.dwPasswordLength = 0;
716 uc.lpszUrlPath = path;
717 uc.dwUrlPathLength = 40;
718 uc.lpszExtraInfo = NULL;
719 uc.dwExtraInfoLength = 0;
720 uc.nPort = 0;
721 ret = WinHttpCrackUrl( url13, 0, ICU_ESCAPE|ICU_DECODE, &uc );
722 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
723 ok( !lstrcmpW( uc.lpszHostName, L"winehq.o g" ), "unexpected host name\n" );
724 ok( !lstrcmpW( uc.lpszUrlPath, L"/path%20with%20spaces" ), "unexpected path\n" );
725 ok( uc.dwUrlPathLength == lstrlenW(L"/path%20with%20spaces"), "got %lu\n", uc.dwUrlPathLength );
727 uc.dwStructSize = sizeof(uc);
728 uc.lpszScheme = NULL;
729 uc.dwSchemeLength = 0;
730 uc.nScheme = 0;
731 uc.lpszHostName = NULL;
732 uc.dwHostNameLength = ~0u;
733 uc.nPort = 0;
734 uc.lpszUserName = NULL;
735 uc.dwUserNameLength = ~0u;
736 uc.lpszPassword = NULL;
737 uc.dwPasswordLength = ~0u;
738 uc.lpszUrlPath = NULL;
739 uc.dwUrlPathLength = ~0u;
740 uc.lpszExtraInfo = NULL;
741 uc.dwExtraInfoLength = ~0u;
742 ret = WinHttpCrackUrl( url14, 0, 0, &uc );
743 ok( ret, "WinHttpCrackUrl failed le = %lu\n", GetLastError() );
744 ok( !uc.lpszScheme, "unexpected scheme %s\n", wine_dbgstr_w(uc.lpszScheme) );
745 ok( !uc.dwSchemeLength, "unexpected length %lu\n", uc.dwSchemeLength );
746 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme %u\n", uc.nScheme );
747 ok( !lstrcmpW( uc.lpszHostName, url14 + 7 ), "unexpected hostname %s\n", wine_dbgstr_w(uc.lpszHostName) );
748 ok( uc.dwHostNameLength == 14, "unexpected length %lu\n", uc.dwHostNameLength );
749 ok( uc.nPort == 80, "unexpected port %u\n", uc.nPort );
750 ok( !uc.lpszUserName, "unexpected username\n" );
751 ok( !uc.dwUserNameLength, "unexpected length %lu\n", uc.dwUserNameLength );
752 ok( !uc.lpszPassword, "unexpected password\n" );
753 ok( !uc.dwPasswordLength, "unexpected length %lu\n", uc.dwPasswordLength );
754 ok( !lstrcmpW( uc.lpszUrlPath, url14 + 21 ), "unexpected path %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
755 ok( uc.dwUrlPathLength == 5, "unexpected length %lu\n", uc.dwUrlPathLength );
756 ok( !uc.lpszExtraInfo[0], "unexpected extra info %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
757 ok( uc.dwExtraInfoLength == 0, "unexpected length %lu\n", uc.dwExtraInfoLength );
759 uc.dwStructSize = sizeof(uc);
760 uc.lpszScheme = scheme;
761 uc.dwSchemeLength = 0;
762 uc.nScheme = 0;
763 uc.lpszHostName = NULL;
764 uc.dwHostNameLength = 0;
765 uc.nPort = 0;
766 uc.lpszUserName = NULL;
767 uc.dwUserNameLength = ~0u;
768 uc.lpszPassword = NULL;
769 uc.dwPasswordLength = ~0u;
770 uc.lpszUrlPath = NULL;
771 uc.dwUrlPathLength = 0;
772 uc.lpszExtraInfo = NULL;
773 uc.dwExtraInfoLength = 0;
774 SetLastError( 0xdeadbeef );
775 ret = WinHttpCrackUrl( url14, 0, 0, &uc );
776 error = GetLastError();
777 ok( !ret, "WinHttpCrackUrl succeeded\n" );
778 ok( error == ERROR_INVALID_PARAMETER, "got %lu\n", error );
779 ok( !lstrcmpW( uc.lpszScheme, http ), "unexpected scheme %s\n", wine_dbgstr_w(uc.lpszScheme) );
780 ok( !uc.dwSchemeLength, "unexpected length %lu\n", uc.dwSchemeLength );
781 ok( uc.nScheme == 0, "unexpected scheme %u\n", uc.nScheme );
782 ok( !uc.lpszHostName, "unexpected hostname %s\n", wine_dbgstr_w(uc.lpszHostName) );
783 ok( uc.dwHostNameLength == 0, "unexpected length %lu\n", uc.dwHostNameLength );
784 ok( uc.nPort == 0, "unexpected port %u\n", uc.nPort );
785 ok( !uc.lpszUserName, "unexpected username\n" );
786 ok( uc.dwUserNameLength == ~0u, "unexpected length %lu\n", uc.dwUserNameLength );
787 ok( !uc.lpszPassword, "unexpected password\n" );
788 ok( uc.dwPasswordLength == ~0u, "unexpected length %lu\n", uc.dwPasswordLength );
789 ok( !uc.lpszUrlPath, "unexpected path %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
790 ok( uc.dwUrlPathLength == 0, "unexpected length %lu\n", uc.dwUrlPathLength );
791 ok( !uc.lpszExtraInfo, "unexpected extra info %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
792 ok( uc.dwExtraInfoLength == 0, "unexpected length %lu\n", uc.dwExtraInfoLength );
794 reset_url_components( &uc );
795 SetLastError( 0xdeadbeef );
796 ret = WinHttpCrackUrl( url15, 0, 0, &uc );
797 error = GetLastError();
798 ok( !ret, "WinHttpCrackUrl succeeded\n" );
799 ok( error == ERROR_WINHTTP_INVALID_URL, "got %lu\n", error );
801 reset_url_components( &uc );
802 uc.nPort = 1;
803 ret = WinHttpCrackUrl( url16, 0, 0, &uc );
804 ok( ret, "got %lu\n", GetLastError() );
805 ok( !uc.nPort, "got %u\n", uc.nPort );
807 reset_url_components( &uc );
808 uc.nPort = 1;
809 ret = WinHttpCrackUrl( url17, 0, 0, &uc );
810 ok( ret, "got %lu\n", GetLastError() );
811 ok( uc.nPort == 80, "got %u\n", uc.nPort );
813 reset_url_components( &uc );
814 uc.nPort = 1;
815 ret = WinHttpCrackUrl( url22, 0, 0, &uc );
816 ok( ret, "got %lu\n", GetLastError() );
817 ok( uc.nPort == 80, "got %u\n", uc.nPort );
819 memset( &uc, 0, sizeof(uc) );
820 uc.dwStructSize = sizeof(uc);
821 uc.lpszScheme = scheme;
822 uc.dwSchemeLength = ARRAY_SIZE(scheme);
823 uc.lpszHostName = host;
824 uc.dwHostNameLength = ARRAY_SIZE(host);
825 uc.lpszUrlPath = path;
826 uc.dwUrlPathLength = ARRAY_SIZE(path);
827 ret = WinHttpCrackUrl( url21, 0, 0, &uc );
828 ok( ret, "got %lu\n", GetLastError() );
829 ok( !lstrcmpW( uc.lpszUrlPath, url21 + 37 ), "unexpected path %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
830 ok( uc.dwUrlPathLength == 50, "unexpected length %lu\n", uc.dwUrlPathLength );
833 START_TEST(url)
835 WinHttpCreateUrl_test();
836 WinHttpCrackUrl_test();