comctl32/tests: Destroy the window after the tests.
[wine] / dlls / winhttp / tests / 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[] =
42     {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',
43      '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
44 static const WCHAR url3[] = {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':',0};
45 static const WCHAR url4[] =
46     {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
47 static const WCHAR url5[] = {'h','t','t','p',':','/','/',0};
48 static const WCHAR url6[] =
49     {'f','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
50      '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','8','0','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
51 static const WCHAR url7[] =
52     {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
53      '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','4','2','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
54 static const WCHAR url8[] =
55     {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
56      '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',
57      '%','2','0','!','%','2','2','%','2','3','$','%','2','5','&','\'','(',')','*','+',',','-','.','/',':',';','%','3','C','=','%','3','E','?','@','%',
58      '5','B','%','5','C','%','5','D','%','5','E','_','%','6','0','%','7','B','%','7','C','%','7','D','%','7','E',0};
59 static const WCHAR url9[] =
60     {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
61      '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','0','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',0};
62
63 static const WCHAR url_k1[]  =
64     {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
65      '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
66 static const WCHAR url_k2[]  =
67     {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
68 static const WCHAR url_k3[]  =
69     {'h','t','t','p','s',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','p','o','s','t','?',0};
70 static const WCHAR url_k4[]  =
71     {'H','T','T','P',':','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
72 static const WCHAR url_k5[]  =
73     {'h','t','t','p',':','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
74 static const WCHAR url_k6[]  =
75     {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
76 static const WCHAR url_k7[]  =
77     {'w','w','w',0};
78 static const WCHAR url_k8[]  =
79     {'h','t','t','p',0};
80 static const WCHAR url_k9[]  =
81     {'h','t','t','p',':','/','/','w','i','n','e','h','q','?',0};
82 static const WCHAR url_k10[]  =
83     {'h','t','t','p',':','/','/','w','i','n','e','h','q','/','p','o','s','t',';','a',0};
84
85 static void fill_url_components( URL_COMPONENTS *uc )
86 {
87     uc->dwStructSize = sizeof(URL_COMPONENTS);
88     uc->lpszScheme = http;
89     uc->dwSchemeLength = lstrlenW( uc->lpszScheme );
90     uc->nScheme = INTERNET_SCHEME_HTTP;
91     uc->lpszHostName = winehq;
92     uc->dwHostNameLength = lstrlenW( uc->lpszHostName );
93     uc->nPort = 80;
94     uc->lpszUserName = username;
95     uc->dwUserNameLength = lstrlenW( uc->lpszUserName );
96     uc->lpszPassword = password;
97     uc->dwPasswordLength = lstrlenW( uc->lpszPassword );
98     uc->lpszUrlPath = about;
99     uc->dwUrlPathLength = lstrlenW( uc->lpszUrlPath );
100     uc->lpszExtraInfo = query;
101     uc->dwExtraInfoLength = lstrlenW( uc->lpszExtraInfo );
102 }
103
104 static void WinHttpCreateUrl_test( void )
105 {
106     URL_COMPONENTS uc;
107     WCHAR *url;
108     DWORD len;
109     BOOL ret;
110
111     /* NULL components */
112     len = ~0UL;
113     SetLastError( 0xdeadbeef );
114     ret = WinHttpCreateUrl( NULL, 0, NULL, &len );
115     ok( !ret, "expected failure\n" );
116     ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
117     ok( len == ~0UL, "expected len ~0UL got %u\n", len );
118
119     /* zero'ed components */
120     memset( &uc, 0, sizeof(URL_COMPONENTS) );
121     SetLastError( 0xdeadbeef );
122     ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
123     ok( !ret, "expected failure\n" );
124     ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
125     ok( len == ~0UL, "expected len ~0UL got %u\n", len );
126
127     /* valid components, NULL url, NULL length */
128     fill_url_components( &uc );
129     SetLastError( 0xdeadbeef );
130     ret = WinHttpCreateUrl( &uc, 0, NULL, NULL );
131     ok( !ret, "expected failure\n" );
132     ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
133     ok( len == ~0UL, "expected len ~0UL got %u\n", len );
134
135     /* valid components, NULL url */
136     SetLastError( 0xdeadbeef );
137     ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
138     ok( !ret, "expected failure\n" );
139     ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
140     ok( len == 57, "expected len 57 got %u\n", len );
141
142     /* correct size, NULL url */
143     fill_url_components( &uc );
144     SetLastError( 0xdeadbeef );
145     ret = WinHttpCreateUrl( &uc, 0, NULL, &len );
146     ok( !ret, "expected failure\n" );
147     ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
148     ok( len == 57, "expected len 57 got %u\n", len );
149
150     /* valid components, allocated url, short length */
151     SetLastError( 0xdeadbeef );
152     url = HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) );
153     url[0] = 0;
154     len = 2;
155     ret = WinHttpCreateUrl( &uc, 0, url, &len );
156     ok( !ret, "expected failure\n" );
157     ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER got %u\n", GetLastError() );
158     ok( len == 57, "expected len 57 got %u\n", len );
159
160     /* allocated url, NULL scheme */
161     uc.lpszScheme = NULL;
162     url[0] = 0;
163     len = 256;
164     ret = WinHttpCreateUrl( &uc, 0, url, &len );
165     ok( ret, "expected success\n" );
166     ok( len == 56, "expected len 56 got %u\n", len );
167     ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
168
169     /* allocated url, 0 scheme */
170     fill_url_components( &uc );
171     uc.nScheme = 0;
172     url[0] = 0;
173     len = 256;
174     ret = WinHttpCreateUrl( &uc, 0, url, &len );
175     ok( ret, "expected success\n" );
176     ok( len == 56, "expected len 56 got %u\n", len );
177
178     /* valid components, allocated url */
179     fill_url_components( &uc );
180     url[0] = 0;
181     len = 256;
182     ret = WinHttpCreateUrl( &uc, 0, url, &len );
183     ok( ret, "expected success\n" );
184     ok( len == 56, "expected len 56 got %d\n", len );
185     ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
186
187     /* valid username, NULL password */
188     fill_url_components( &uc );
189     uc.lpszPassword = NULL;
190     url[0] = 0;
191     len = 256;
192     ret = WinHttpCreateUrl( &uc, 0, url, &len );
193     ok( ret, "expected success\n" );
194
195     /* valid username, empty password */
196     fill_url_components( &uc );
197     uc.lpszPassword = empty;
198     url[0] = 0;
199     len = 256;
200     ret = WinHttpCreateUrl( &uc, 0, url, &len );
201     ok( ret, "expected success\n" );
202     ok( len == 56, "expected len 56 got %u\n", len );
203     ok( !lstrcmpW( url, url3 ), "url doesn't match\n" );
204
205     /* valid password, NULL username */
206     fill_url_components( &uc );
207     SetLastError( 0xdeadbeef );
208     uc.lpszUserName = NULL;
209     url[0] = 0;
210     len = 256;
211     ret = WinHttpCreateUrl( &uc, 0, url, &len );
212     ok( !ret, "expected failure\n" );
213     ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", GetLastError() );
214
215     /* valid password, empty username */
216     fill_url_components( &uc );
217     uc.lpszUserName = empty;
218     url[0] = 0;
219     len = 256;
220     ret = WinHttpCreateUrl( &uc, 0, url, &len );
221     ok( ret, "expected success\n");
222
223     /* NULL username, NULL password */
224     fill_url_components( &uc );
225     uc.lpszUserName = NULL;
226     uc.lpszPassword = NULL;
227     url[0] = 0;
228     len = 256;
229     ret = WinHttpCreateUrl( &uc, 0, url, &len );
230     ok( ret, "expected success\n" );
231     ok( len == 38, "expected len 38 got %u\n", len );
232     ok( !lstrcmpW( url, url4 ), "url doesn't match\n" );
233
234     /* empty username, empty password */
235     fill_url_components( &uc );
236     uc.lpszUserName = empty;
237     uc.lpszPassword = empty;
238     url[0] = 0;
239     len = 256;
240     ret = WinHttpCreateUrl( &uc, 0, url, &len );
241     ok( ret, "expected success\n" );
242     ok( len == 56, "expected len 56 got %u\n", len );
243     ok( !lstrcmpW( url, url5 ), "url doesn't match\n" );
244
245     /* nScheme has lower precedence than lpszScheme */
246     fill_url_components( &uc );
247     uc.lpszScheme = ftp;
248     uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
249     url[0] = 0;
250     len = 256;
251     ret = WinHttpCreateUrl( &uc, 0, url, &len );
252     ok( ret, "expected success\n" );
253     ok( len == lstrlenW( url6 ), "expected len %d got %u\n", lstrlenW( url6 ) + 1, len );
254     ok( !lstrcmpW( url, url6 ), "url doesn't match\n" );
255
256     /* non-standard port */
257     uc.lpszScheme = http;
258     uc.dwSchemeLength = lstrlenW( uc.lpszScheme );
259     uc.nPort = 42;
260     url[0] = 0;
261     len = 256;
262     ret = WinHttpCreateUrl( &uc, 0, url, &len );
263     ok( ret, "expected success\n" );
264     ok( len == 59, "expected len 59 got %u\n", len );
265     ok( !lstrcmpW( url, url7 ), "url doesn't match\n" );
266
267     /* escape extra info */
268     fill_url_components( &uc );
269     uc.lpszExtraInfo = escape;
270     uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo );
271     url[0] = 0;
272     len = 256;
273     ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len );
274     ok( ret, "expected success\n" );
275     ok( len == 113, "expected len 113 got %u\n", len );
276     ok( !lstrcmpW( url, url8 ), "url doesn't match\n" );
277
278     /* NULL lpszScheme, 0 nScheme and nPort */
279     fill_url_components( &uc );
280     uc.lpszScheme = NULL;
281     uc.dwSchemeLength = 0;
282     uc.nScheme = 0;
283     uc.nPort = 0;
284     url[0] = 0;
285     len = 256;
286     ret = WinHttpCreateUrl( &uc, 0, url, &len );
287     ok( ret, "expected success\n" );
288     ok( len == 58, "expected len 58 got %u\n", len );
289     ok( !lstrcmpW( url, url9 ), "url doesn't match\n" );
290
291     HeapFree( GetProcessHeap(), 0, url );
292 }
293
294 static void reset_url_components( URL_COMPONENTS *uc )
295 {
296     memset( uc, 0, sizeof(URL_COMPONENTS) );
297     uc->dwStructSize = sizeof(URL_COMPONENTS);
298     uc->dwSchemeLength    = ~0UL;
299     uc->dwHostNameLength  = ~0UL;
300     uc->dwUserNameLength  = ~0UL;
301     uc->dwPasswordLength  = ~0UL;
302     uc->dwUrlPathLength   = ~0UL;
303     uc->dwExtraInfoLength = ~0UL;
304 }
305
306 static void WinHttpCrackUrl_test( void )
307 {
308     URL_COMPONENTSW uc;
309     WCHAR scheme[20], user[20], pass[20], host[20], path[40], extra[20];
310     DWORD error;
311     BOOL ret;
312
313     /* buffers of sufficient length */
314     scheme[0] = 0;
315     user[0] = 0;
316     pass[0] = 0;
317     host[0] = 0;
318     path[0] = 0;
319     extra[0] = 0;
320
321     uc.dwStructSize = sizeof(URL_COMPONENTS);
322     uc.nScheme = 0;
323     uc.lpszScheme = scheme;
324     uc.dwSchemeLength = 20;
325     uc.lpszUserName = user;
326     uc.dwUserNameLength = 20;
327     uc.lpszPassword = pass;
328     uc.dwPasswordLength = 20;
329     uc.lpszHostName = host;
330     uc.dwHostNameLength = 20;
331     uc.lpszUrlPath = path;
332     uc.dwUrlPathLength = 40;
333     uc.lpszExtraInfo = extra;
334     uc.dwExtraInfoLength = 20;
335
336     ret = WinHttpCrackUrl( url1, 0, 0, &uc );
337     ok( ret, "WinHttpCrackUrl failed\n" );
338     ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
339     ok( !memcmp( uc.lpszScheme, http, sizeof(http) ), "unexpected scheme\n" );
340     ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
341     ok( !memcmp( uc.lpszUserName, username, sizeof(username) ), "unexpected username\n" );
342     ok( uc.dwUserNameLength == 8, "unexpected username length\n" );
343     ok( !memcmp( uc.lpszPassword, password, sizeof(password) ), "unexpected password\n" );
344     ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
345     ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected hostname\n" );
346     ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
347     ok( !memcmp( uc.lpszUrlPath, about, sizeof(about) ), "unexpected path\n" );
348     ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
349     ok( !memcmp( uc.lpszExtraInfo, query, sizeof(query) ), "unexpected extra info\n" );
350     ok( uc.dwExtraInfoLength == 6, "unexpected extra info length\n" );
351
352     /* buffer of insufficient length */
353     scheme[0] = 0;
354     uc.dwSchemeLength = 1;
355
356     SetLastError( 0xdeadbeef );
357     ret = WinHttpCrackUrl( url1, 0, 0, &uc );
358     error = GetLastError();
359     ok( !ret, "WinHttpCrackUrl failed\n" );
360     ok( error == ERROR_INSUFFICIENT_BUFFER, "WinHttpCrackUrl failed\n" );
361     ok( uc.dwSchemeLength == 5, "unexpected scheme length: %u\n", uc.dwSchemeLength );
362
363     /* no buffers */
364     reset_url_components( &uc );
365     ret = WinHttpCrackUrl( url_k1, 0, 0,&uc);
366
367     ok( ret, "WinHttpCrackUrl failed\n" );
368     ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
369     ok( uc.lpszScheme == url_k1,"unexpected scheme\n" );
370     ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
371     ok( uc.lpszUserName == url_k1 + 7, "unexpected username\n" );
372     ok( uc.dwUserNameLength == 8, "unexpected username length\n" );
373     ok( uc.lpszPassword == url_k1 + 16, "unexpected password\n" );
374     ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
375     ok( uc.lpszHostName == url_k1 + 25, "unexpected hostname\n" );
376     ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
377     ok( uc.lpszUrlPath == url_k1 + 39, "unexpected path\n" );
378     ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
379     ok( uc.lpszExtraInfo == url_k1 + 50, "unexpected extra info\n" );
380     ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
381
382     reset_url_components( &uc );
383     ret = WinHttpCrackUrl( url_k2, 0, 0,&uc);
384
385     ok( ret, "WinHttpCrackUrl failed\n" );
386     ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
387     ok( uc.lpszScheme == url_k2, "unexpected scheme\n" );
388     ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
389     ok( uc.lpszUserName == NULL ,"unexpected username\n" );
390     ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
391     ok( uc.lpszPassword == NULL, "unexpected password\n" );
392     ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
393     ok( uc.lpszHostName == url_k2 + 7, "unexpected hostname\n" );
394     ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
395     ok( uc.lpszUrlPath == url_k2 + 21, "unexpected path\n" );
396     ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
397     ok( uc.lpszExtraInfo == url_k2 + 21, "unexpected extra info\n" );
398     ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
399
400     reset_url_components( &uc );
401     ret = WinHttpCrackUrl( url_k3, 0, 0, &uc );
402
403     ok( ret, "WinHttpCrackUrl failed\n" );
404     ok( uc.nScheme == INTERNET_SCHEME_HTTPS, "unexpected scheme\n" );
405     ok( uc.lpszScheme == url_k3, "unexpected scheme\n" );
406     ok( uc.dwSchemeLength == 5, "unexpected scheme length\n" );
407     ok( uc.lpszUserName == NULL, "unexpected username\n" );
408     ok( uc.dwUserNameLength == 0, "unexpected username length\n" );
409     ok( uc.lpszPassword == NULL, "unexpected password\n" );
410     ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
411     ok( uc.lpszHostName == url_k3 + 8, "unexpected hostname\n" );
412     ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
413     ok( uc.lpszUrlPath == url_k3 + 22, "unexpected path\n" );
414     ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
415     ok( uc.lpszExtraInfo == url_k3 + 27, "unexpected extra info\n" );
416     ok( uc.dwExtraInfoLength == 1, "unexpected extra info length\n" );
417
418     /* bad parameters */
419     reset_url_components( &uc );
420     ret = WinHttpCrackUrl( url_k4, 0, 0, &uc );
421     ok( !ret, "WinHttpCrackUrl failed\n" );
422
423     reset_url_components( &uc );
424     ret = WinHttpCrackUrl( url_k5, 0, 0, &uc );
425     ok( !ret, "WinHttpCrackUrl failed\n" );
426
427     reset_url_components( &uc );
428     ret = WinHttpCrackUrl( url_k6, 0, 0, &uc );
429     ok( !ret, "WinHttpCrackUrl failed\n" );
430
431     reset_url_components( &uc );
432     ret = WinHttpCrackUrl( url_k7, 0, 0, &uc );
433     ok( !ret, "WinHttpCrackUrl failed\n" );
434
435     reset_url_components( &uc );
436     ret = WinHttpCrackUrl( url_k8, 0, 0, &uc );
437     ok( !ret, "WinHttpCrackUrl failed\n" );
438
439     reset_url_components( &uc );
440     ret = WinHttpCrackUrl( url_k9, 0, 0, &uc );
441     ok( ret, "WinHttpCrackUrl failed\n" );
442     ok( uc.lpszUrlPath == url_k9 + 14, "unexpected path\n" );
443     ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
444     ok( uc.lpszExtraInfo == url_k9 + 14, "unexpected extra info\n" );
445     ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
446
447     reset_url_components( &uc );
448     ret = WinHttpCrackUrl( url_k10, 0, 0, &uc );
449     ok( ret, "WinHttpCrackUrl failed\n" );
450     ok( uc.lpszUrlPath == url_k10 + 13, "unexpected path\n" );
451     ok( uc.dwUrlPathLength == 7, "unexpected path length\n" );
452     ok( uc.lpszExtraInfo == url_k10 + 20, "unexpected extra info\n" );
453     ok( uc.dwExtraInfoLength == 0, "unexpected extra info length\n" );
454
455     reset_url_components( &uc );
456     ret = WinHttpCrackUrl( url5, 0, 0, &uc );
457     ok( !ret, "WinHttpCrackUrl failed\n" );
458
459     reset_url_components( &uc );
460     ret = WinHttpCrackUrl( empty, 0, 0, &uc );
461     ok( !ret, "WinHttpCrackUrl failed\n" );
462
463     ret = WinHttpCrackUrl( url1, 0, 0, NULL );
464     ok( !ret, "WinHttpCrackUrl failed\n" );
465
466     ret = WinHttpCrackUrl( NULL, 0, 0, &uc );
467     ok( !ret, "WinHttpCrackUrl failed\n" );
468
469     /* decoding without buffers */
470     reset_url_components( &uc );
471     SetLastError(0xdeadbeef);
472     ret = WinHttpCrackUrl( url8, 0, ICU_DECODE, &uc );
473     error = GetLastError();
474     ok( !ret, "WinHttpCrackUrl failed\n" );
475     ok( error == ERROR_INVALID_PARAMETER, "WinHttpCrackUrl failed\n" );
476
477     /* decoding with buffers */
478     uc.lpszScheme = scheme;
479     uc.dwSchemeLength = 20;
480     uc.lpszUserName = user;
481     uc.dwUserNameLength = 20;
482     uc.lpszPassword = pass;
483     uc.dwPasswordLength = 20;
484     uc.lpszHostName = host;
485     uc.dwHostNameLength = 20;
486     uc.lpszUrlPath = path;
487     uc.dwUrlPathLength = 40;
488     uc.lpszExtraInfo = extra;
489     uc.dwExtraInfoLength = 20;
490     path[0] = 0;
491
492     ret = WinHttpCrackUrl( url8, 0, ICU_DECODE, &uc );
493     ok( ret, "WinHttpCrackUrl failed\n" );
494     ok( !memcmp( uc.lpszUrlPath + 11, escape, 21 * sizeof(WCHAR) ), "unexpected path\n" );
495     ok( uc.dwUrlPathLength == 32, "unexpected path length\n" );
496     ok( !memcmp( uc.lpszExtraInfo, escape + 21, 12 * sizeof(WCHAR) ), "unexpected extra info\n" );
497     ok( uc.dwExtraInfoLength == 12, "unexpected extra info length\n" );
498 }
499
500 START_TEST(url)
501 {
502     WinHttpCreateUrl_test();
503     WinHttpCrackUrl_test();
504 }