7935a1986ace123e7ba6f52060bdbd4f89d830af
[reactos.git] / rostests / winetests / winhttp / url.c
1 /*
2 * Copyright 2008 Hans Leidekker
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #include <stdarg.h>
20
21 #include "windef.h"
22 #include "winbase.h"
23 #include "winnls.h"
24 #include "winhttp.h"
25
26 #include "wine/test.h"
27
28 static WCHAR empty[] = {0};
29 static WCHAR ftp[] = {'f','t','p',0};
30 static WCHAR http[] = {'h','t','t','p',0};
31 static WCHAR winehq[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
32 static WCHAR username[] = {'u','s','e','r','n','a','m','e',0};
33 static WCHAR password[] = {'p','a','s','s','w','o','r','d',0};
34 static WCHAR about[] = {'/','s','i','t','e','/','a','b','o','u','t',0};
35 static WCHAR query[] = {'?','q','u','e','r','y',0};
36 static WCHAR escape[] = {' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~',0};
37
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
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};
94
95 static void fill_url_components( URL_COMPONENTS *uc )
96 {
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 );
112 }
113
114 static void WinHttpCreateUrl_test( void )
115 {
116 URL_COMPONENTS uc;
117 WCHAR *url;
118 DWORD len;
119 BOOL ret;
120
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 );
128
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 );
136
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
144 /* valid components, NULL url */
145 SetLastError( 0xdeadbeef );
146 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
147 ok( !ret, "expected failure\n" );
148 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
149 GetLastError() == ERROR_INVALID_PARAMETER,
150 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
151
152 /* correct size, NULL url */
153 fill_url_components( &uc );
154 SetLastError( 0xdeadbeef );
155 ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
156 ok( !ret, "expected failure\n" );
157 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER ||
158 GetLastError() == ERROR_INVALID_PARAMETER,
159 "expected ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
160
161 /* valid components, allocated url, short length */
162 SetLastError( 0xdeadbeef );
163 url = HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) );
164 url[0] = 0;
165 len = 2;
166 ret = WinHttpCreateUrl( &uc, 0, url, &len );
167 ok( !ret, "expected failure\n" );
168 ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
169 ok( len == 57, "expected len 57 got %u\n", len );
170
171 /* allocated url, NULL scheme */
172 SetLastError( 0xdeadbeef );
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( GetLastError() == ERROR_SUCCESS || broken(GetLastError() == 0xdeadbeef) /* < win7 */,
179 "expected ERROR_SUCCESS got %u\n", GetLastError() );
180 ok( len == 56, "expected len 56 got %u\n", len );
181 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
182
183 /* allocated url, 0 scheme */
184 fill_url_components( &uc );
185 uc.nScheme = 0;
186 url[0] = 0;
187 len = 256;
188 ret = WinHttpCreateUrl( &uc, 0, url, &len );
189 ok( ret, "expected success\n" );
190 ok( len == 56, "expected len 56 got %u\n", len );
191
192 /* valid components, allocated url */
193 fill_url_components( &uc );
194 url[0] = 0;
195 len = 256;
196 ret = WinHttpCreateUrl( &uc, 0, url, &len );
197 ok( ret, "expected success\n" );
198 ok( len == 56, "expected len 56 got %d\n", len );
199 ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
200
201 /* valid username, NULL password */
202 fill_url_components( &uc );
203 uc.lpszPassword = NULL;
204 url[0] = 0;
205 len = 256;
206 ret = WinHttpCreateUrl( &uc, 0, url, &len );
207 ok( ret, "expected success\n" );
208
209 /* valid username, empty password */
210 fill_url_components( &uc );
211 uc.lpszPassword = empty;
212 url[0] = 0;
213 len = 256;
214 ret = WinHttpCreateUrl( &uc, 0, url, &len );
215 ok( ret, "expected success\n" );
216 ok( len == 56, "expected len 56 got %u\n", len );
217 ok( !lstrcmpW( url, url2 ), "url doesn't match\n" );
218
219 /* valid password, NULL username */
220 fill_url_components( &uc );
221 SetLastError( 0xdeadbeef );
222 uc.lpszUserName = NULL;
223 url[0] = 0;
224 len = 256;
225 ret = WinHttpCreateUrl( &uc, 0, url, &len );
226 ok( !ret, "expected failure\n" );
227 ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
228
229 /* valid password, empty username */
230 fill_url_components( &uc );
231 uc.lpszUserName = empty;
232 url[0] = 0;
233 len = 256;
234 ret = WinHttpCreateUrl( &uc, 0, url, &len );
235 ok( ret, "expected success\n");
236
237 /* NULL username, NULL password */
238 fill_url_components( &uc );
239 uc.lpszUserName = NULL;
240 uc.lpszPassword = NULL;
241 url[0] = 0;
242 len = 256;
243 ret = WinHttpCreateUrl( &uc, 0, url, &len );
244 ok( ret, "expected success\n" );
245 ok( len == 38, "expected len 38 got %u\n", len );
246 ok( !lstrcmpW( url, url3 ), "url doesn't match\n" );
247
248 /* empty username, empty password */
249 fill_url_components( &uc );
250 uc.lpszUserName = empty;
251 uc.lpszPassword = empty;
252 url[0] = 0;
253 len = 256;
254 ret = WinHttpCreateUrl( &uc, 0, url, &len );
255 ok( ret, "expected success\n" );
256 ok( len == 56, "expected len 56 got %u\n", len );
257 ok( !lstrcmpW( url, url4 ), "url doesn't match\n" );
258
259 /* nScheme has lower precedence than lpszScheme */
260 fill_url_components( &uc );
261 uc.lpszScheme = ftp;
262 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
263 url[0] = 0;
264 len = 256;
265 ret = WinHttpCreateUrl( &uc, 0, url, &len );
266 ok( ret, "expected success\n" );
267 ok( len == lstrlenW( url5 ), "expected len %d got %u\n", lstrlenW( url5 ) + 1, len );
268 ok( !lstrcmpW( url, url5 ), "url doesn't match\n" );
269
270 /* non-standard port */
271 uc.lpszScheme = http;
272 uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
273 uc.nPort = 42;
274 url[0] = 0;
275 len = 256;
276 ret = WinHttpCreateUrl( &uc, 0, url, &len );
277 ok( ret, "expected success\n" );
278 ok( len == 59, "expected len 59 got %u\n", len );
279 ok( !lstrcmpW( url, url6 ), "url doesn't match\n" );
280
281 /* escape extra info */
282 fill_url_components( &uc );
283 uc.lpszExtraInfo = escape;
284 uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo );
285 url[0] = 0;
286 len = 256;
287 ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
288 ok( ret, "expected success\n" );
289 ok( len == 113, "expected len 113 got %u\n", len );
290 ok( !lstrcmpW( url, url7 ), "url doesn't match\n" );
291
292 /* NULL lpszScheme, 0 nScheme and nPort */
293 fill_url_components( &uc );
294 uc.lpszScheme = NULL;
295 uc.dwSchemeLength = 0;
296 uc.nScheme = 0;
297 uc.nPort = 0;
298 url[0] = 0;
299 len = 256;
300 ret = WinHttpCreateUrl( &uc, 0, url, &len );
301 ok( ret, "expected success\n" );
302 ok( len == 58, "expected len 58 got %u\n", len );
303 ok( !lstrcmpW( url, url8 ), "url doesn't match\n" );
304
305 HeapFree( GetProcessHeap(), 0, url );
306 }
307
308 static void reset_url_components( URL_COMPONENTS *uc )
309 {
310 memset( uc, 0, sizeof(URL_COMPONENTS) );
311 uc->dwStructSize = sizeof(URL_COMPONENTS);
312 uc->dwSchemeLength = ~0u;
313 uc->dwHostNameLength = ~0u;
314 uc->nPort = 0;
315 uc->dwUserNameLength = ~0u;
316 uc->dwPasswordLength = ~0u;
317 uc->dwUrlPathLength = ~0u;
318 uc->dwExtraInfoLength = ~0u;
319 }
320
321 static void WinHttpCrackUrl_test( void )
322 {
323 static const WCHAR hostnameW[] =
324 {'w','i','n','e','h','q','.','o',' ','g',0};
325 static const WCHAR pathW[] =
326 {'/','p','a','t','h','%','2','0','w','i','t','h','%','2','0','s','p','a','c','e','s',0};
327 URL_COMPONENTSW uc;
328 WCHAR scheme[20], user[20], pass[20], host[20], path[80], extra[40];
329 DWORD error;
330 BOOL ret;
331
332 /* buffers of sufficient length */
333 scheme[0] = 0;
334 user[0] = 0;
335 pass[0] = 0;
336 host[0] = 0;
337 path[0] = 0;
338 extra[0] = 0;
339
340 uc.dwStructSize = sizeof(URL_COMPONENTS);
341 uc.nScheme = 0;
342 uc.lpszScheme = scheme;
343 uc.dwSchemeLength = 20;
344 uc.lpszUserName = user;
345 uc.dwUserNameLength = 20;
346 uc.lpszPassword = pass;
347 uc.dwPasswordLength = 20;
348 uc.lpszHostName = host;
349 uc.dwHostNameLength = 20;
350 uc.nPort = 0;
351 uc.lpszUrlPath = path;
352 uc.dwUrlPathLength = 40;
353 uc.lpszExtraInfo = extra;
354 uc.dwExtraInfoLength = 20;
355
356 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
357 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
358 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme: %u\n", uc.nScheme );
359 ok( !memcmp( uc.lpszScheme, http, sizeof(http) ), "unexpected scheme: %s\n", wine_dbgstr_w(uc.lpszScheme) );
360 ok( uc.dwSchemeLength == 4, "unexpected scheme length: %u\n", uc.dwSchemeLength );
361 ok( !memcmp( uc.lpszUserName, username, sizeof(username) ), "unexpected username: %s\n", wine_dbgstr_w(uc.lpszUserName) );
362 ok( uc.dwUserNameLength == 8, "unexpected username length: %u\n", uc.dwUserNameLength );
363 ok( !memcmp( uc.lpszPassword, password, sizeof(password) ), "unexpected password: %s\n", wine_dbgstr_w(uc.lpszPassword) );
364 ok( uc.dwPasswordLength == 8, "unexpected password length: %u\n", uc.dwPasswordLength );
365 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected hostname: %s\n", wine_dbgstr_w(uc.lpszHostName) );
366 ok( uc.dwHostNameLength == 14, "unexpected hostname length: %u\n", uc.dwHostNameLength );
367 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
368 ok( !memcmp( uc.lpszUrlPath, about, sizeof(about) ), "unexpected path: %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
369 ok( uc.dwUrlPathLength == 11, "unexpected path length: %u\n", uc.dwUrlPathLength );
370 ok( !memcmp( uc.lpszExtraInfo, query, sizeof(query) ), "unexpected extra info: %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
371 ok( uc.dwExtraInfoLength == 6, "unexpected extra info length: %u\n", uc.dwExtraInfoLength );
372
373 /* buffer of insufficient length */
374 scheme[0] = 0;
375 uc.dwSchemeLength = 1;
376
377 SetLastError( 0xdeadbeef );
378 ret = WinHttpCrackUrl( url1, 0, 0, &uc );
379 error = GetLastError();
380 ok( !ret, "WinHttpCrackUrl succeeded\n" );
381 ok( error == ERROR_INSUFFICIENT_BUFFER, "got %u, expected ERROR_INSUFFICIENT_BUFFER\n", error );
382 ok( uc.dwSchemeLength == 5, "unexpected scheme length: %u\n", uc.dwSchemeLength );
383
384 /* no buffers */
385 reset_url_components( &uc );
386 SetLastError( 0xdeadbeef );
387 ret = WinHttpCrackUrl( url_k1, 0, 0,&uc);
388 error = GetLastError();
389
390 ok( ret, "WinHttpCrackUrl failed le=%u\n", error );
391 ok( error == ERROR_SUCCESS || broken(error == ERROR_INVALID_PARAMETER) /* < win7 */,
392 "got %u, expected ERROR_SUCCESS\n", error );
393 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
394 ok( uc.lpszScheme == url_k1,"unexpected scheme\n" );
395 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
396 ok( uc.lpszUserName == url_k1 + 7, "unexpected username\n" );
397 ok( uc.dwUserNameLength == 8, "unexpected username length\n" );
398 ok( uc.lpszPassword == url_k1 + 16, "unexpected password\n" );
399 ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
400 ok( uc.lpszHostName == url_k1 + 25, "unexpected hostname\n" );
401 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
402 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
403 ok( uc.lpszUrlPath == url_k1 + 39, "unexpected path\n" );
404 ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
405 ok( uc.lpszExtraInfo == url_k1 + 50, "unexpected extra info\n" );
406 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
407
408 reset_url_components( &uc );
409 ret = WinHttpCrackUrl( url_k2, 0, 0,&uc);
410
411 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
412 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
413 ok( uc.lpszScheme == url_k2, "unexpected scheme\n" );
414 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
415 ok( uc.lpszUserName == NULL ,"unexpected username\n" );
416 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
417 ok( uc.lpszPassword == NULL, "unexpected password\n" );
418 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
419 ok( uc.lpszHostName == url_k2 + 7, "unexpected hostname\n" );
420 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
421 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
422 ok( uc.lpszUrlPath == url_k2 + 21, "unexpected path\n" );
423 ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
424 ok( uc.lpszExtraInfo == url_k2 + 21, "unexpected extra info\n" );
425 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
426
427 reset_url_components( &uc );
428 ret = WinHttpCrackUrl( url_k3, 0, 0, &uc );
429
430 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
431 ok( uc.nScheme == INTERNET_SCHEME_HTTPS, "unexpected scheme\n" );
432 ok( uc.lpszScheme == url_k3, "unexpected scheme\n" );
433 ok( uc.dwSchemeLength == 5, "unexpected scheme length\n" );
434 ok( uc.lpszUserName == NULL, "unexpected username\n" );
435 ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
436 ok( uc.lpszPassword == NULL, "unexpected password\n" );
437 ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
438 ok( uc.lpszHostName == url_k3 + 8, "unexpected hostname\n" );
439 ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
440 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
441 ok( uc.lpszUrlPath == url_k3 + 22, "unexpected path\n" );
442 ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
443 ok( uc.lpszExtraInfo == url_k3 + 27, "unexpected extra info\n" );
444 ok( uc.dwExtraInfoLength == 1, "unexpected extra info length\n" );
445
446 /* bad parameters */
447 reset_url_components( &uc );
448 ret = WinHttpCrackUrl( url_k4, 0, 0, &uc );
449 ok( !ret, "WinHttpCrackUrl succeeded\n" );
450
451 reset_url_components( &uc );
452 ret = WinHttpCrackUrl( url_k5, 0, 0, &uc );
453 ok( !ret, "WinHttpCrackUrl succeeded\n" );
454
455 reset_url_components( &uc );
456 ret = WinHttpCrackUrl( url_k6, 0, 0, &uc );
457 ok( !ret, "WinHttpCrackUrl succeeded\n" );
458
459 reset_url_components( &uc );
460 ret = WinHttpCrackUrl( url_k7, 0, 0, &uc );
461 ok( !ret, "WinHttpCrackUrl succeeded\n" );
462
463 reset_url_components( &uc );
464 ret = WinHttpCrackUrl( url_k8, 0, 0, &uc );
465 ok( !ret, "WinHttpCrackUrl succeeded\n" );
466
467 reset_url_components( &uc );
468 ret = WinHttpCrackUrl( url_k9, 0, 0, &uc );
469 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
470 ok( uc.lpszUrlPath == url_k9 + 14 || broken(uc.lpszUrlPath == url_k9 + 13) /* win8 */,
471 "unexpected path: %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
472 ok( uc.dwUrlPathLength == 0, "unexpected path length: %u\n", uc.dwUrlPathLength );
473 ok( uc.lpszExtraInfo == url_k9 + 14 || broken(uc.lpszExtraInfo == url_k9 + 13) /* win8 */,
474 "unexpected extra info: %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
475 ok( uc.dwExtraInfoLength == 0 || broken(uc.dwExtraInfoLength == 1) /* win8 */,
476 "unexpected extra info length: %u\n", uc.dwExtraInfoLength );
477
478 reset_url_components( &uc );
479 ret = WinHttpCrackUrl( url_k10, 0, 0, &uc );
480 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
481 ok( uc.lpszUrlPath == url_k10 + 13, "unexpected path: %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
482 ok( uc.dwUrlPathLength == 7, "unexpected path length: %u\n", uc.dwUrlPathLength );
483 ok( uc.lpszExtraInfo == url_k10 + 20, "unexpected extra info: %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
484 ok( uc.dwExtraInfoLength == 0, "unexpected extra info length: %u\n", uc.dwExtraInfoLength );
485
486 reset_url_components( &uc );
487 ret = WinHttpCrackUrl( url4, 0, 0, &uc );
488 ok( !ret, "WinHttpCrackUrl succeeded\n" );
489
490 reset_url_components( &uc );
491 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
492 ok( !ret, "WinHttpCrackUrl succeeded\n" );
493
494 ret = WinHttpCrackUrl( url1, 0, 0, NULL );
495 ok( !ret, "WinHttpCrackUrl succeeded\n" );
496
497 ret = WinHttpCrackUrl( NULL, 0, 0, &uc );
498 ok( !ret, "WinHttpCrackUrl succeeded\n" );
499
500 /* decoding without buffers */
501 reset_url_components( &uc );
502 SetLastError(0xdeadbeef);
503 ret = WinHttpCrackUrl( url7, 0, ICU_DECODE, &uc );
504 error = GetLastError();
505 ok( !ret, "WinHttpCrackUrl succeeded\n" );
506 ok( error == ERROR_INVALID_PARAMETER, "got %u, expected ERROR_INVALID_PARAMETER\n", error );
507
508 /* decoding with buffers */
509 uc.lpszScheme = scheme;
510 uc.dwSchemeLength = 20;
511 uc.lpszUserName = user;
512 uc.dwUserNameLength = 20;
513 uc.lpszPassword = pass;
514 uc.dwPasswordLength = 20;
515 uc.lpszHostName = host;
516 uc.dwHostNameLength = 20;
517 uc.nPort = 0;
518 uc.lpszUrlPath = path;
519 uc.dwUrlPathLength = 80;
520 uc.lpszExtraInfo = extra;
521 uc.dwExtraInfoLength = 40;
522 path[0] = 0;
523
524 ret = WinHttpCrackUrl( url7, 0, ICU_DECODE, &uc );
525 ok( ret, "WinHttpCrackUrl failed %u\n", GetLastError() );
526 ok( !memcmp( uc.lpszUrlPath + 11, escape, 21 * sizeof(WCHAR) ), "unexpected path\n" );
527 ok( uc.dwUrlPathLength == 32, "unexpected path length %u\n", uc.dwUrlPathLength );
528 ok( !memcmp( uc.lpszExtraInfo, escape + 21, 12 * sizeof(WCHAR) ), "unexpected extra info\n" );
529 ok( uc.dwExtraInfoLength == 12, "unexpected extra info length %u\n", uc.dwExtraInfoLength );
530
531 /* Urls with specified port numbers */
532 /* decoding with buffers */
533 uc.lpszScheme = scheme;
534 uc.dwSchemeLength = 20;
535 uc.lpszUserName = user;
536 uc.dwUserNameLength = 20;
537 uc.lpszPassword = pass;
538 uc.dwPasswordLength = 20;
539 uc.lpszHostName = host;
540 uc.dwHostNameLength = 20;
541 uc.nPort = 0;
542 uc.lpszUrlPath = path;
543 uc.dwUrlPathLength = 40;
544 uc.lpszExtraInfo = extra;
545 uc.dwExtraInfoLength = 20;
546 path[0] = 0;
547
548 ret = WinHttpCrackUrl( url6, 0, 0, &uc );
549 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
550 ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected host name: %s\n", wine_dbgstr_w(uc.lpszHostName) );
551 ok( uc.dwHostNameLength == 14, "unexpected host name length: %d\n", uc.dwHostNameLength );
552 ok( uc.nPort == 42, "unexpected port: %u\n", uc.nPort );
553
554 /* decoding without buffers */
555 reset_url_components( &uc );
556 ret = WinHttpCrackUrl( url8, 0, 0, &uc );
557 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
558 ok( uc.nPort == 0, "unexpected port: %u\n", uc.nPort );
559
560 reset_url_components( &uc );
561 ret = WinHttpCrackUrl( url9, 0, 0, &uc );
562 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
563 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
564
565 reset_url_components( &uc );
566 ret = WinHttpCrackUrl( url10, 0, 0, &uc );
567 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
568 ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
569
570 reset_url_components( &uc );
571 SetLastError( 0xdeadbeef );
572 ret = WinHttpCrackUrl( empty, 0, 0, &uc );
573 error = GetLastError();
574 ok( !ret, "WinHttpCrackUrl succeeded\n" );
575 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
576
577 reset_url_components( &uc );
578 SetLastError( 0xdeadbeef );
579 ret = WinHttpCrackUrl( http, 0, 0, &uc );
580 error = GetLastError();
581 ok( !ret, "WinHttpCrackUrl succeeded\n" );
582 ok( error == ERROR_WINHTTP_UNRECOGNIZED_SCHEME, "got %u, expected ERROR_WINHTTP_UNRECOGNIZED_SCHEME\n", error );
583
584 reset_url_components( &uc );
585 ret = WinHttpCrackUrl( url11, 0, 0, &uc);
586 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
587 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
588 ok( uc.lpszScheme == url11,"unexpected scheme\n" );
589 ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
590 ok( uc.lpszUserName == NULL, "unexpected username\n" );
591 ok( uc.lpszPassword == NULL, "unexpected password\n" );
592 ok( uc.lpszHostName == url11 + 7, "unexpected hostname\n" );
593 ok( uc.dwHostNameLength == 11, "unexpected hostname length\n" );
594 ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
595 ok( uc.lpszUrlPath == url11 + 18, "unexpected path\n" );
596 ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
597 ok( uc.lpszExtraInfo == url11 + 23, "unexpected extra info\n" );
598 ok( uc.dwExtraInfoLength == 39, "unexpected extra info length\n" );
599
600 uc.lpszScheme = scheme;
601 uc.dwSchemeLength = 20;
602 uc.lpszHostName = host;
603 uc.dwHostNameLength = 20;
604 uc.lpszUserName = NULL;
605 uc.dwUserNameLength = 0;
606 uc.lpszPassword = NULL;
607 uc.dwPasswordLength = 0;
608 uc.lpszUrlPath = path;
609 uc.dwUrlPathLength = 40;
610 uc.lpszExtraInfo = NULL;
611 uc.dwExtraInfoLength = 0;
612 uc.nPort = 0;
613 ret = WinHttpCrackUrl( url12, 0, ICU_DECODE, &uc );
614 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
615
616 uc.lpszScheme = scheme;
617 uc.dwSchemeLength = 20;
618 uc.lpszHostName = host;
619 uc.dwHostNameLength = 20;
620 uc.lpszUserName = NULL;
621 uc.dwUserNameLength = 0;
622 uc.lpszPassword = NULL;
623 uc.dwPasswordLength = 0;
624 uc.lpszUrlPath = path;
625 uc.dwUrlPathLength = 40;
626 uc.lpszExtraInfo = NULL;
627 uc.dwExtraInfoLength = 0;
628 uc.nPort = 0;
629 ret = WinHttpCrackUrl( url13, 0, ICU_ESCAPE|ICU_DECODE, &uc );
630 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
631 ok( !lstrcmpW( uc.lpszHostName, hostnameW ), "unexpected host name\n" );
632 ok( !lstrcmpW( uc.lpszUrlPath, pathW ), "unexpected path\n" );
633
634 uc.dwStructSize = sizeof(uc);
635 uc.lpszScheme = NULL;
636 uc.dwSchemeLength = 0;
637 uc.nScheme = 0;
638 uc.lpszHostName = NULL;
639 uc.dwHostNameLength = ~0u;
640 uc.nPort = 0;
641 uc.lpszUserName = NULL;
642 uc.dwUserNameLength = ~0u;
643 uc.lpszPassword = NULL;
644 uc.dwPasswordLength = ~0u;
645 uc.lpszUrlPath = NULL;
646 uc.dwUrlPathLength = ~0u;
647 uc.lpszExtraInfo = NULL;
648 uc.dwExtraInfoLength = ~0u;
649 ret = WinHttpCrackUrl( url14, 0, 0, &uc );
650 ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
651 ok( !uc.lpszScheme, "unexpected scheme %s\n", wine_dbgstr_w(uc.lpszScheme) );
652 ok( !uc.dwSchemeLength, "unexpected length %u\n", uc.dwSchemeLength );
653 ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme %u\n", uc.nScheme );
654 ok( !lstrcmpW( uc.lpszHostName, url14 + 7 ), "unexpected hostname %s\n", wine_dbgstr_w(uc.lpszHostName) );
655 ok( uc.dwHostNameLength == 14, "unexpected length %u\n", uc.dwHostNameLength );
656 ok( uc.nPort == 80, "unexpected port %u\n", uc.nPort );
657 ok( !uc.lpszUserName, "unexpected username\n" );
658 ok( !uc.dwUserNameLength, "unexpected length %u\n", uc.dwUserNameLength );
659 ok( !uc.lpszPassword, "unexpected password\n" );
660 ok( !uc.dwPasswordLength, "unexpected length %u\n", uc.dwPasswordLength );
661 ok( !lstrcmpW( uc.lpszUrlPath, url14 + 21 ), "unexpected path %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
662 ok( uc.dwUrlPathLength == 5, "unexpected length %u\n", uc.dwUrlPathLength );
663 ok( !uc.lpszExtraInfo[0], "unexpected extra info %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
664 ok( uc.dwExtraInfoLength == 0, "unexpected length %u\n", uc.dwExtraInfoLength );
665
666 uc.dwStructSize = sizeof(uc);
667 uc.lpszScheme = scheme;
668 uc.dwSchemeLength = 0;
669 uc.nScheme = 0;
670 uc.lpszHostName = NULL;
671 uc.dwHostNameLength = 0;
672 uc.nPort = 0;
673 uc.lpszUserName = NULL;
674 uc.dwUserNameLength = ~0u;
675 uc.lpszPassword = NULL;
676 uc.dwPasswordLength = ~0u;
677 uc.lpszUrlPath = NULL;
678 uc.dwUrlPathLength = 0;
679 uc.lpszExtraInfo = NULL;
680 uc.dwExtraInfoLength = 0;
681 SetLastError( 0xdeadbeef );
682 ret = WinHttpCrackUrl( url14, 0, 0, &uc );
683 error = GetLastError();
684 ok( !ret, "WinHttpCrackUrl succeeded\n" );
685 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
686 ok( !lstrcmpW( uc.lpszScheme, http ), "unexpected scheme %s\n", wine_dbgstr_w(uc.lpszScheme) );
687 ok( !uc.dwSchemeLength, "unexpected length %u\n", uc.dwSchemeLength );
688 ok( uc.nScheme == 0, "unexpected scheme %u\n", uc.nScheme );
689 ok( !uc.lpszHostName, "unexpected hostname %s\n", wine_dbgstr_w(uc.lpszHostName) );
690 ok( uc.dwHostNameLength == 0, "unexpected length %u\n", uc.dwHostNameLength );
691 ok( uc.nPort == 0, "unexpected port %u\n", uc.nPort );
692 ok( !uc.lpszUserName, "unexpected username\n" );
693 ok( uc.dwUserNameLength == ~0u, "unexpected length %u\n", uc.dwUserNameLength );
694 ok( !uc.lpszPassword, "unexpected password\n" );
695 ok( uc.dwPasswordLength == ~0u, "unexpected length %u\n", uc.dwPasswordLength );
696 ok( !uc.lpszUrlPath, "unexpected path %s\n", wine_dbgstr_w(uc.lpszUrlPath) );
697 ok( uc.dwUrlPathLength == 0, "unexpected length %u\n", uc.dwUrlPathLength );
698 ok( !uc.lpszExtraInfo, "unexpected extra info %s\n", wine_dbgstr_w(uc.lpszExtraInfo) );
699 ok( uc.dwExtraInfoLength == 0, "unexpected length %u\n", uc.dwExtraInfoLength );
700 }
701
702 START_TEST(url)
703 {
704 WinHttpCreateUrl_test();
705 WinHttpCrackUrl_test();
706 }