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