wined3d: Recognize Nvidia GT520 cards.
[wine] / dlls / wininet / tests / url.c
1 /*
2  * Wininet - URL tests
3  *
4  * Copyright 2002 Aric Stewart
5  * Copyright 2004 Mike McCormack
6  * Copyright 2005 Hans Leidekker
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31 #include "wininet.h"
32
33 #include "wine/test.h"
34
35 #define TEST_URL "http://www.winehq.org/site/about#hi"
36 #define TEST_URL3 "file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml"
37
38 #define CREATE_URL1 "http://username:password@www.winehq.org/site/about"
39 #define CREATE_URL2 "http://username@www.winehq.org/site/about"
40 #define CREATE_URL3 "http://username:"
41 #define CREATE_URL4 "http://www.winehq.org/site/about"
42 #define CREATE_URL5 "http://"
43 #define CREATE_URL6 "nhttp://username:password@www.winehq.org:80/site/about"
44 #define CREATE_URL7 "http://username:password@www.winehq.org:42/site/about"
45 #define CREATE_URL8 "https://username:password@www.winehq.org/site/about"
46 #define CREATE_URL9 "about:blank"
47 #define CREATE_URL10 "about://host/blank"
48 #define CREATE_URL11 "about:"
49 #define CREATE_URL12 "http://www.winehq.org:65535"
50 #define CREATE_URL13 "http://localhost/?test=123"
51
52 static void copy_compsA(
53     URL_COMPONENTSA *src, 
54     URL_COMPONENTSA *dst, 
55     DWORD scheLen,
56     DWORD hostLen,
57     DWORD userLen,
58     DWORD passLen,
59     DWORD pathLen,
60     DWORD extrLen )
61 {
62     *dst = *src;
63     dst->dwSchemeLength    = scheLen;
64     dst->dwHostNameLength  = hostLen;
65     dst->dwUserNameLength  = userLen;
66     dst->dwPasswordLength  = passLen;
67     dst->dwUrlPathLength   = pathLen;
68     dst->dwExtraInfoLength = extrLen;
69     SetLastError(0xfaceabad);
70 }
71
72 static void zero_compsA(
73     URL_COMPONENTSA *dst, 
74     DWORD scheLen,
75     DWORD hostLen,
76     DWORD userLen,
77     DWORD passLen,
78     DWORD pathLen,
79     DWORD extrLen )
80 {
81     ZeroMemory(dst, sizeof(URL_COMPONENTSA));
82     dst->dwStructSize = sizeof(URL_COMPONENTSA);
83     dst->dwSchemeLength    = scheLen;
84     dst->dwHostNameLength  = hostLen;
85     dst->dwUserNameLength  = userLen;
86     dst->dwPasswordLength  = passLen;
87     dst->dwUrlPathLength   = pathLen;
88     dst->dwExtraInfoLength = extrLen;
89     SetLastError(0xfaceabad);
90 }
91
92 typedef struct {
93     const char *url;
94     int scheme_off;
95     int scheme_len;
96     INTERNET_SCHEME scheme;
97     int host_off;
98     int host_len;
99     int host_skip_broken;
100     INTERNET_PORT port;
101     int user_off;
102     int user_len;
103     int pass_off;
104     int pass_len;
105     int path_off;
106     int path_len;
107     int extra_off;
108     int extra_len;
109     const char *exp_scheme;
110     const char *exp_hostname;
111     const char *exp_username;
112     const char *exp_password;
113     const char *exp_urlpath;
114     const char *exp_extrainfo;
115 } crack_url_test_t;
116
117 static const crack_url_test_t crack_url_tests[] = {
118     {"http://www.winehq.org/site/about#hi",
119         0, 4, INTERNET_SCHEME_HTTP, 7, 14, -1, 80, -1, 0, -1, 0, 21, 11, 32, 3,
120         "http", "www.winehq.org", "", "", "/site/about", "#hi"},
121     {"http://www.myserver.com/myscript.php?arg=1",
122         0, 4, INTERNET_SCHEME_HTTP, 7, 16, -1, 80, -1, 0, -1, 0, 23, 13, 36, 6,
123         "http", "www.myserver.com", "", "", "/myscript.php", "?arg=1"},
124     {"http://www.winehq.org?test=123",
125         0, 4, INTERNET_SCHEME_HTTP, 7, 14, 23, 80, -1, 0, -1, 0, 21, 0, 21, 9,
126         "http", "www.winehq.org", "", "", "", "?test=123"},
127     {"http://www.winehq.org/myscript.php;test=123",
128         0, 4, INTERNET_SCHEME_HTTP, 7, 14, 23, 80, -1, 0, -1, 0, 21, 22, -1, 0,
129         "http", "www.winehq.org", "", "", "/myscript.php;test=123", ""},
130     {"file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
131         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 55, -1, 0,
132         "file", "", "", "", "C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", ""},
133     {"fide:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
134         0, 4, INTERNET_SCHEME_UNKNOWN, 7, 0, -1, 0, -1, 0, -1, 0, 7, 55, -1, 0,
135         "fide", "", "", "", "/C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", ""},
136     {"file://C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
137         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 54, -1, 0,
138         "file", "", "", "", "C:\\Program%20Files\\Atmel\\AVR%20Tools\\STK500\\STK500.xml", ""},
139     {"file://C:/Program%20Files/Atmel/..",
140         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 27, -1, 0,
141         "file", "", "", "", "C:\\Program%20Files\\Atmel\\..\\", ""},
142     {"file://C:/Program%20Files/Atmel/../Asdf.xml",
143         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 36, -1, 0,
144         "file", "", "", "", "C:\\Program%20Files\\Atmel\\..\\Asdf.xml", ""},
145     {"file:///C:/Program%20Files/Atmel/..",
146         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 28, -1, 0,
147         "file", "", "", "", "C:\\Program Files\\Atmel\\..\\", ""},
148     {"file:///C:/Program%20Files/Atmel/../Asdf.xml",
149         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 37, -1, 0,
150         "file", "", "", "", "C:\\Program Files\\Atmel\\..\\Asdf.xml", ""},
151     {"file://C:/Program%20Files/Atmel/.",
152         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 26, -1, 0,
153         "file", "", "", "", "C:\\Program%20Files\\Atmel\\.\\", ""},
154     {"file://C:/Program%20Files/Atmel/./Asdf.xml",
155         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 35, -1, 0,
156         "file", "", "", "", "C:\\Program%20Files\\Atmel\\.\\Asdf.xml", ""},
157     {"file:///C:/Program%20Files/Atmel/.",
158         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 27, -1, 0,
159         "file", "", "", "", "C:\\Program Files\\Atmel\\.\\", ""},
160     {"file:///C:/Program%20Files/Atmel/./Asdf.xml",
161         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 36, -1, 0,
162         "file", "", "", "", "C:\\Program Files\\Atmel\\.\\Asdf.xml", ""},
163 };
164
165 static const WCHAR *w_str_of(const char *str)
166 {
167     static WCHAR buf[512];
168     MultiByteToWideChar(CP_ACP, 0, str, -1, buf, sizeof(buf)/sizeof(buf[0]));
169     return buf;
170 }
171
172 static void test_crack_url(const crack_url_test_t *test)
173 {
174     WCHAR buf[INTERNET_MAX_URL_LENGTH];
175     URL_COMPONENTSW urlw;
176     URL_COMPONENTSA url;
177     char scheme[32], hostname[1024], username[1024];
178     char password[1024], extrainfo[1024], urlpath[1024];
179     BOOL b;
180
181     /* test InternetCrackUrlA with NULL buffers */
182     zero_compsA(&url, 1, 1, 1, 1, 1, 1);
183
184     b = InternetCrackUrlA(test->url, strlen(test->url), 0, &url);
185     ok(b, "InternetCrackUrl failed with error %d\n", GetLastError());
186
187     if(test->scheme_off == -1)
188         ok(!url.lpszScheme, "[%s] url.lpszScheme = %p, expected NULL\n", test->url, url.lpszScheme);
189     else
190         ok(url.lpszScheme == test->url+test->scheme_off, "[%s] url.lpszScheme = %p, expected %p\n",
191            test->url, url.lpszScheme, test->url+test->scheme_off);
192     ok(url.dwSchemeLength == test->scheme_len, "[%s] url.lpszSchemeLength = %d, expected %d\n",
193        test->url, url.dwSchemeLength, test->scheme_len);
194
195     ok(url.nScheme == test->scheme, "[%s] url.nScheme = %d, expected %d\n", test->url, url.nScheme, test->scheme);
196
197     if(test->host_off == -1)
198         ok(!url.lpszHostName, "[%s] url.lpszHostName = %p, expected NULL\n", test->url, url.lpszHostName);
199     else
200         ok(url.lpszHostName == test->url+test->host_off, "[%s] url.lpszHostName = %p, expected %p\n",
201            test->url, url.lpszHostName, test->url+test->host_off);
202     if(test->host_skip_broken != -1 && url.dwHostNameLength == test->host_skip_broken) {
203         win_skip("skipping broken dwHostNameLength result\n");
204         return;
205     }
206     ok(url.dwHostNameLength == test->host_len, "[%s] url.lpszHostNameLength = %d, expected %d\n",
207        test->url, url.dwHostNameLength, test->host_len);
208
209     ok(url.nPort == test->port, "[%s] nPort = %d, expected %d\n", test->url, url.nPort, test->port);
210
211     if(test->user_off == -1)
212         ok(!url.lpszUserName, "[%s] url.lpszUserName = %p\n", test->url, url.lpszUserName);
213     else
214         ok(url.lpszUserName == test->url+test->user_off, "[%s] url.lpszUserName = %p, expected %p\n",
215            test->url, url.lpszUserName, test->url+test->user_off);
216     ok(url.dwUserNameLength == test->user_len, "[%s] url.lpszUserNameLength = %d, expected %d\n",
217        test->url, url.dwUserNameLength, test->user_len);
218
219     if(test->pass_off == -1)
220         ok(!url.lpszPassword, "[%s] url.lpszPassword = %p\n", test->url, url.lpszPassword);
221     else
222         ok(url.lpszPassword == test->url+test->pass_off, "[%s] url.lpszPassword = %p, expected %p\n",
223            test->url, url.lpszPassword, test->url+test->pass_off);
224     ok(url.dwPasswordLength == test->pass_len, "[%s] url.lpszPasswordLength = %d, expected %d\n",
225        test->url, url.dwPasswordLength, test->pass_len);
226
227     if(test->path_off == -1)
228         ok(!url.lpszUrlPath, "[%s] url.lpszPath = %p, expected NULL\n", test->url, url.lpszUrlPath);
229     else
230         ok(url.lpszUrlPath == test->url+test->path_off, "[%s] url.lpszPath = %p, expected %p\n",
231            test->url, url.lpszUrlPath, test->url+test->path_off);
232     ok(url.dwUrlPathLength == test->path_len, "[%s] url.lpszUrlPathLength = %d, expected %d\n",
233        test->url, url.dwUrlPathLength, test->path_len);
234
235     if(test->extra_off == -1)
236         ok(!url.lpszExtraInfo, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test->url, url.lpszExtraInfo);
237     else
238         ok(url.lpszExtraInfo == test->url+test->extra_off, "[%s] url.lpszExtraInfo = %p, expected %p\n",
239            test->url, url.lpszExtraInfo, test->url+test->extra_off);
240     ok(url.dwExtraInfoLength == test->extra_len, "[%s] url.lpszExtraInfoLength = %d, expected %d\n",
241        test->url, url.dwExtraInfoLength, test->extra_len);
242
243     /* test InternetCrackUrlW with NULL buffers */
244     memset(&urlw, 0, sizeof(URL_COMPONENTSW));
245     urlw.dwStructSize = sizeof(URL_COMPONENTSW);
246     urlw.dwSchemeLength = 1;
247     urlw.dwHostNameLength = 1;
248     urlw.dwUserNameLength = 1;
249     urlw.dwPasswordLength = 1;
250     urlw.dwUrlPathLength = 1;
251     urlw.dwExtraInfoLength = 1;
252
253     MultiByteToWideChar(CP_ACP, 0, test->url, -1, buf, sizeof(buf)/sizeof(buf[0]));
254     b = InternetCrackUrlW(buf, lstrlenW(buf), 0, &urlw);
255     if(!b && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
256         win_skip("InternetCrackUrlW is not implemented\n");
257         return;
258     }
259     ok(b, "InternetCrackUrl failed with error %d\n", GetLastError());
260
261     if(test->scheme_off == -1)
262         ok(!urlw.lpszScheme, "[%s] urlw.lpszScheme = %p, expected NULL\n", test->url, urlw.lpszScheme);
263     else
264         ok(urlw.lpszScheme == buf+test->scheme_off, "[%s] urlw.lpszScheme = %p, expected %p\n",
265            test->url, urlw.lpszScheme, buf+test->scheme_off);
266     ok(urlw.dwSchemeLength == test->scheme_len, "[%s] urlw.lpszSchemeLength = %d, expected %d\n",
267        test->url, urlw.dwSchemeLength, test->scheme_len);
268
269     ok(urlw.nScheme == test->scheme, "[%s] urlw.nScheme = %d, expected %d\n", test->url, urlw.nScheme, test->scheme);
270
271     if(test->host_off == -1) {
272         ok(!urlw.lpszHostName, "[%s] urlw.lpszHostName = %p, expected NULL\n", test->url, urlw.lpszHostName);
273         ok(urlw.dwHostNameLength == 0 || broken(urlw.dwHostNameLength == 1), "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
274            test->url, urlw.dwHostNameLength, test->host_len);
275     }else {
276         ok(urlw.lpszHostName == buf+test->host_off, "[%s] urlw.lpszHostName = %p, expected %p\n",
277            test->url, urlw.lpszHostName, test->url+test->host_off);
278         ok(urlw.dwHostNameLength == test->host_len, "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
279            test->url, urlw.dwHostNameLength, test->host_len);
280     }
281
282     ok(urlw.nPort == test->port, "[%s] nPort = %d, expected %d\n", test->url, urlw.nPort, test->port);
283
284     if(test->user_off == -1) {
285         ok(!urlw.lpszUserName, "[%s] urlw.lpszUserName = %p\n", test->url, urlw.lpszUserName);
286         ok(urlw.dwUserNameLength == 0 || broken(urlw.dwUserNameLength == 1), "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
287            test->url, urlw.dwUserNameLength, test->user_len);
288     }else {
289         ok(urlw.lpszUserName == buf+test->user_off, "[%s] urlw.lpszUserName = %p, expected %p\n",
290            test->url, urlw.lpszUserName, buf+test->user_off);
291         ok(urlw.dwUserNameLength == test->user_len, "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
292            test->url, urlw.dwUserNameLength, test->user_len);
293     }
294
295     if(test->pass_off == -1) {
296         ok(!urlw.lpszPassword, "[%s] urlw.lpszPassword = %p\n", test->url, urlw.lpszPassword);
297         ok(urlw.dwPasswordLength == 0 || broken(urlw.dwPasswordLength), "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
298            test->url, urlw.dwPasswordLength, test->pass_len);
299     }else {
300         ok(urlw.lpszPassword == buf+test->pass_off, "[%s] urlw.lpszPassword = %p, expected %p\n",
301            test->url, urlw.lpszPassword, buf+test->pass_off);
302         ok(urlw.dwPasswordLength == test->pass_len, "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
303            test->url, urlw.dwPasswordLength, test->pass_len);
304     }
305
306     if(test->path_off == -1)
307         ok(!urlw.lpszUrlPath, "[%s] urlw.lpszPath = %p, expected NULL\n", test->url, urlw.lpszUrlPath);
308     else
309         ok(urlw.lpszUrlPath == buf+test->path_off, "[%s] urlw.lpszPath = %p, expected %p\n",
310            test->url, urlw.lpszUrlPath, buf+test->path_off);
311     ok(urlw.dwUrlPathLength == test->path_len, "[%s] urlw.lpszUrlPathLength = %d, expected %d\n",
312        test->url, urlw.dwUrlPathLength, test->path_len);
313
314     if(test->extra_off == -1) {
315         ok(!urlw.lpszExtraInfo, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test->url, urlw.lpszExtraInfo);
316         ok(urlw.dwExtraInfoLength == 0 || broken(urlw.dwExtraInfoLength == 1), "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
317            test->url, urlw.dwExtraInfoLength, test->extra_len);
318     }else {
319         ok(urlw.lpszExtraInfo == buf+test->extra_off, "[%s] urlw.lpszExtraInfo = %p, expected %p\n",
320            test->url, urlw.lpszExtraInfo, buf+test->extra_off);
321         ok(urlw.dwExtraInfoLength == test->extra_len, "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
322            test->url, urlw.dwExtraInfoLength, test->extra_len);
323     }
324
325     /* test InternetCrackUrlA with valid buffers */
326     memset(&url, 0, sizeof(URL_COMPONENTSA));
327     url.dwStructSize = sizeof(URL_COMPONENTSA);
328     url.lpszScheme = scheme;
329     url.dwSchemeLength = sizeof(scheme);
330     url.lpszHostName = hostname;
331     url.dwHostNameLength = sizeof(hostname);
332     url.lpszUserName = username;
333     url.dwUserNameLength = sizeof(username);
334     url.lpszPassword = password;
335     url.dwPasswordLength = sizeof(password);
336     url.lpszUrlPath = urlpath;
337     url.dwUrlPathLength = sizeof(urlpath);
338     url.lpszExtraInfo = extrainfo;
339     url.dwExtraInfoLength = sizeof(extrainfo);
340
341     b = InternetCrackUrlA(test->url, strlen(test->url), 0, &url);
342     ok(b, "InternetCrackUrlA failed with error %d\n", GetLastError());
343
344     ok(url.dwSchemeLength == strlen(test->exp_scheme), "[%s] Got wrong scheme length: %d\n",
345             test->url, url.dwSchemeLength);
346     ok(!strcmp(scheme, test->exp_scheme), "[%s] Got wrong scheme, expected: %s, got: %s\n",
347             test->url, test->exp_scheme, scheme);
348
349     ok(url.nScheme == test->scheme, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
350             test->url, test->scheme, url.nScheme);
351
352     ok(url.dwHostNameLength == strlen(test->exp_hostname), "[%s] Got wrong hostname length: %d\n",
353             test->url, url.dwHostNameLength);
354     ok(!strcmp(hostname, test->exp_hostname), "[%s] Got wrong hostname, expected: %s, got: %s\n",
355             test->url, test->exp_hostname, hostname);
356
357     ok(url.nPort == test->port, "[%s] Got wrong port, expected: %d, got: %d\n",
358             test->url, test->port, url.nPort);
359
360     ok(url.dwUserNameLength == strlen(test->exp_username), "[%s] Got wrong username length: %d\n",
361             test->url, url.dwUserNameLength);
362     ok(!strcmp(username, test->exp_username), "[%s] Got wrong username, expected: %s, got: %s\n",
363             test->url, test->exp_username, username);
364
365     ok(url.dwPasswordLength == strlen(test->exp_password), "[%s] Got wrong password length: %d\n",
366             test->url, url.dwPasswordLength);
367     ok(!strcmp(password, test->exp_password), "[%s] Got wrong password, expected: %s, got: %s\n",
368             test->url, test->exp_password, password);
369
370     ok(url.dwUrlPathLength == strlen(test->exp_urlpath), "[%s] Got wrong urlpath length: %d\n",
371             test->url, url.dwUrlPathLength);
372     ok(!strcmp(urlpath, test->exp_urlpath), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
373             test->url, test->exp_urlpath, urlpath);
374
375     ok(url.dwExtraInfoLength == strlen(test->exp_extrainfo), "[%s] Got wrong extrainfo length: %d\n",
376             test->url, url.dwExtraInfoLength);
377     ok(!strcmp(extrainfo, test->exp_extrainfo), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
378             test->url, test->exp_extrainfo, extrainfo);
379
380     /* test InternetCrackUrlW with valid buffers */
381     memset(&urlw, 0, sizeof(URL_COMPONENTSW));
382     urlw.dwStructSize = sizeof(URL_COMPONENTSW);
383     urlw.lpszScheme = (WCHAR*)scheme;
384     urlw.dwSchemeLength = sizeof(scheme) / sizeof(WCHAR);
385     urlw.lpszHostName = (WCHAR*)hostname;
386     urlw.dwHostNameLength = sizeof(hostname) / sizeof(WCHAR);
387     urlw.lpszUserName = (WCHAR*)username;
388     urlw.dwUserNameLength = sizeof(username) / sizeof(WCHAR);
389     urlw.lpszPassword = (WCHAR*)password;
390     urlw.dwPasswordLength = sizeof(password) / sizeof(WCHAR);
391     urlw.lpszUrlPath = (WCHAR*)urlpath;
392     urlw.dwUrlPathLength = sizeof(urlpath) / sizeof(WCHAR);
393     urlw.lpszExtraInfo = (WCHAR*)extrainfo;
394     urlw.dwExtraInfoLength = sizeof(extrainfo) / sizeof(WCHAR);
395
396     b = InternetCrackUrlW(buf, lstrlenW(buf), 0, &urlw);
397     ok(b, "InternetCrackUrlW failed with error %d\n", GetLastError());
398
399     ok(urlw.dwSchemeLength == strlen(test->exp_scheme), "[%s] Got wrong scheme length: %d\n",
400             test->url, urlw.dwSchemeLength);
401     ok(!lstrcmpW((WCHAR*)scheme, w_str_of(test->exp_scheme)), "[%s] Got wrong scheme, expected: %s, got: %s\n",
402             test->url, test->exp_scheme, wine_dbgstr_w((WCHAR*)scheme));
403
404     ok(urlw.nScheme == test->scheme, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
405             test->url, test->scheme, urlw.nScheme);
406
407     ok(urlw.dwHostNameLength == strlen(test->exp_hostname), "[%s] Got wrong hostname length: %d\n",
408             test->url, urlw.dwHostNameLength);
409     ok(!lstrcmpW((WCHAR*)hostname, w_str_of(test->exp_hostname)), "[%s] Got wrong hostname, expected: %s, got: %s\n",
410             test->url, test->exp_hostname, wine_dbgstr_w((WCHAR*)hostname));
411
412     ok(urlw.nPort == test->port, "[%s] Got wrong port, expected: %d, got: %d\n",
413             test->url, test->port, urlw.nPort);
414
415     ok(urlw.dwUserNameLength == strlen(test->exp_username), "[%s] Got wrong username length: %d\n",
416             test->url, urlw.dwUserNameLength);
417     ok(!lstrcmpW((WCHAR*)username, w_str_of(test->exp_username)), "[%s] Got wrong username, expected: %s, got: %s\n",
418             test->url, test->exp_username, wine_dbgstr_w((WCHAR*)username));
419
420     ok(urlw.dwPasswordLength == strlen(test->exp_password), "[%s] Got wrong password length: %d\n",
421             test->url, urlw.dwPasswordLength);
422     ok(!lstrcmpW((WCHAR*)password, w_str_of(test->exp_password)), "[%s] Got wrong password, expected: %s, got: %s\n",
423             test->url, test->exp_password, wine_dbgstr_w((WCHAR*)password));
424
425     ok(urlw.dwUrlPathLength == strlen(test->exp_urlpath), "[%s] Got wrong urlpath length: %d\n",
426             test->url, urlw.dwUrlPathLength);
427     ok(!lstrcmpW((WCHAR*)urlpath, w_str_of(test->exp_urlpath)), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
428             test->url, test->exp_urlpath, wine_dbgstr_w((WCHAR*)urlpath));
429
430     ok(urlw.dwExtraInfoLength == strlen(test->exp_extrainfo), "[%s] Got wrong extrainfo length: %d\n",
431             test->url, urlw.dwExtraInfoLength);
432     ok(!lstrcmpW((WCHAR*)extrainfo, w_str_of(test->exp_extrainfo)), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
433             test->url, test->exp_extrainfo, wine_dbgstr_w((WCHAR*)extrainfo));
434 }
435
436 static void InternetCrackUrl_test(void)
437 {
438   URL_COMPONENTSA urlSrc, urlComponents;
439   char protocol[32], hostName[1024], userName[1024];
440   char password[1024], extra[1024], path[1024];
441   BOOL ret, firstret;
442   DWORD GLE, firstGLE;
443
444   ZeroMemory(&urlSrc, sizeof(urlSrc));
445   urlSrc.dwStructSize = sizeof(urlSrc);
446   urlSrc.lpszScheme = protocol;
447   urlSrc.lpszHostName = hostName;
448   urlSrc.lpszUserName = userName;
449   urlSrc.lpszPassword = password;
450   urlSrc.lpszUrlPath = path;
451   urlSrc.lpszExtraInfo = extra;
452
453   /* Tests for lpsz* members pointing to real strings while 
454    * some corresponding length members are set to zero.
455    * As of IE7 (wininet 7.0*?) all members are checked. So we
456    * run the first test and expect the outcome to be the same
457    * for the first four (scheme, hostname, username and password).
458    * The last two (path and extrainfo) are the same for all versions
459    * of the wininet.dll.
460    */
461   copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
462   SetLastError(0xdeadbeef);
463   firstret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
464   firstGLE = GetLastError();
465
466   copy_compsA(&urlSrc, &urlComponents, 32, 0, 1024, 1024, 2048, 1024);
467   SetLastError(0xdeadbeef);
468   ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
469   GLE = GetLastError();
470   ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
471     ret, GLE, firstret);
472
473   copy_compsA(&urlSrc, &urlComponents, 32, 1024, 0, 1024, 2048, 1024);
474   SetLastError(0xdeadbeef);
475   ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
476   GLE = GetLastError();
477   ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
478     ret, GLE, firstret);
479
480   copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 0, 2048, 1024);
481   SetLastError(0xdeadbeef);
482   ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
483   GLE = GetLastError();
484   ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
485     ret, GLE, firstret);
486
487   copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 0, 1024);
488   SetLastError(0xdeadbeef);
489   ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
490   GLE = GetLastError();
491   todo_wine
492   ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
493      "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
494     ret, GLE);
495
496   copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 0);
497   SetLastError(0xdeadbeef);
498   ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
499   GLE = GetLastError();
500   todo_wine
501   ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
502      "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
503     ret, GLE);
504
505   copy_compsA(&urlSrc, &urlComponents, 0, 0, 0, 0, 0, 0);
506   ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
507   GLE = GetLastError();
508   todo_wine
509   ok(ret==0 && GLE==ERROR_INVALID_PARAMETER,
510      "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
511     ret, GLE);
512
513   copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
514   ret = InternetCrackUrl("about://host/blank", 0,0,&urlComponents);
515   ok(ret, "InternetCrackUrl failed with %d\n", GetLastError());
516   ok(!strcmp(urlComponents.lpszScheme, "about"), "lpszScheme was \"%s\" instead of \"about\"\n", urlComponents.lpszScheme);
517   ok(!strcmp(urlComponents.lpszHostName, "host"), "lpszHostName was \"%s\" instead of \"host\"\n", urlComponents.lpszHostName);
518   ok(!strcmp(urlComponents.lpszUrlPath, "/blank"), "lpszUrlPath was \"%s\" instead of \"/blank\"\n", urlComponents.lpszUrlPath);
519
520   /* try a NULL lpszUrl */
521   SetLastError(0xdeadbeef);
522   copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
523   ret = InternetCrackUrl(NULL, 0, 0, &urlComponents);
524   GLE = GetLastError();
525   ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
526   ok(GLE == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GLE);
527
528   /* try an empty lpszUrl, GetLastError returns 12006, whatever that means
529    * we just need to fail and not return success
530    */
531   SetLastError(0xdeadbeef);
532   copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
533   ret = InternetCrackUrl("", 0, 0, &urlComponents);
534   GLE = GetLastError();
535   ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
536   ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
537
538   /* Invalid Call: must set size of components structure (Windows only
539    * enforces this on the InternetCrackUrlA version of the call) */
540   copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
541   SetLastError(0xdeadbeef);
542   urlComponents.dwStructSize = 0;
543   ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
544   ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
545   ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
546
547   /* Invalid Call: size of dwStructSize must be one of the "standard" sizes
548    * of the URL_COMPONENTS structure (Windows only enforces this on the
549    * InternetCrackUrlA version of the call) */
550   copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
551   SetLastError(0xdeadbeef);
552   urlComponents.dwStructSize = sizeof(urlComponents) + 1;
553   ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
554   ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
555   ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
556 }
557
558 static void InternetCrackUrlW_test(void)
559 {
560     WCHAR url[] = {
561         'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
562         'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
563         '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
564         'U','L','T', 0 };
565     static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
566     static const WCHAR url3[] = { 'h','t','t','p',':','/','/','x','.','o','r','g',0 };
567     URL_COMPONENTSW comp;
568     WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
569     DWORD error;
570     BOOL r;
571
572     urlpart[0]=0;
573     scheme[0]=0;
574     extra[0]=0;
575     host[0]=0;
576     user[0]=0;
577     pwd[0]=0;
578     memset(&comp, 0, sizeof comp);
579     comp.dwStructSize = sizeof(comp);
580     comp.lpszScheme = scheme;
581     comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
582     comp.lpszHostName = host;
583     comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
584     comp.lpszUserName = user;
585     comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
586     comp.lpszPassword = pwd;
587     comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
588     comp.lpszUrlPath = urlpart;
589     comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
590     comp.lpszExtraInfo = extra;
591     comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
592
593     SetLastError(0xdeadbeef);
594     r = InternetCrackUrlW(NULL, 0, 0, &comp );
595     error = GetLastError();
596     if (!r && error == ERROR_CALL_NOT_IMPLEMENTED)
597     {
598         win_skip("InternetCrackUrlW is not implemented\n");
599         return;
600     }
601     ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
602     ok( error == ERROR_INVALID_PARAMETER ||
603         broken(error == ERROR_INTERNET_UNRECOGNIZED_SCHEME), /* IE5 */
604         "expected ERROR_INVALID_PARAMETER got %u\n", error);
605
606     if (error == ERROR_INVALID_PARAMETER)
607     {
608         /* Crashes on IE5 */
609         SetLastError(0xdeadbeef);
610         r = InternetCrackUrlW(url, 0, 0, NULL );
611         error = GetLastError();
612         ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
613         ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
614     }
615
616     r = InternetCrackUrlW(url, 0, 0, &comp );
617     ok( r, "failed to crack url\n");
618     ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
619     ok( comp.dwHostNameLength == 12, "host length wrong\n");
620     ok( comp.dwUserNameLength == 0, "user length wrong\n");
621     ok( comp.dwPasswordLength == 0, "password length wrong\n");
622     ok( comp.dwUrlPathLength == 15, "url length wrong\n");
623     ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
624  
625     urlpart[0]=0;
626     scheme[0]=0;
627     extra[0]=0;
628     host[0]=0;
629     user[0]=0;
630     pwd[0]=0;
631     memset(&comp, 0, sizeof comp);
632     comp.dwStructSize = sizeof comp;
633     comp.lpszHostName = host;
634     comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
635     comp.lpszUrlPath = urlpart;
636     comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
637
638     r = InternetCrackUrlW(url, 0, 0, &comp );
639     ok( r, "failed to crack url\n");
640     ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
641     ok( comp.dwHostNameLength == 12, "host length wrong\n");
642     ok( comp.dwUserNameLength == 0, "user length wrong\n");
643     ok( comp.dwPasswordLength == 0, "password length wrong\n");
644     ok( comp.dwUrlPathLength == 44, "url length wrong\n");
645     ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
646
647     urlpart[0]=0;
648     scheme[0]=0;
649     extra[0]=0;
650     host[0]=0;
651     user[0]=0;
652     pwd[0]=0;
653     memset(&comp, 0, sizeof comp);
654     comp.dwStructSize = sizeof comp;
655     comp.lpszHostName = host;
656     comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
657     comp.lpszUrlPath = urlpart;
658     comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
659     comp.lpszExtraInfo = NULL;
660     comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
661
662     r = InternetCrackUrlW(url, 0, 0, &comp );
663     ok( r, "failed to crack url\n");
664     ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
665     ok( comp.dwHostNameLength == 12, "host length wrong\n");
666     ok( comp.dwUserNameLength == 0, "user length wrong\n");
667     ok( comp.dwPasswordLength == 0, "password length wrong\n");
668     ok( comp.dwUrlPathLength == 15, "url length wrong\n");
669     ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
670
671     urlpart[0]=0;
672     scheme[0]=0;
673     extra[0]=0;
674     host[0]=0;
675     user[0]=0;
676     pwd[0]=0;
677     memset(&comp, 0, sizeof(comp));
678     comp.dwStructSize = sizeof(comp);
679     comp.lpszScheme = scheme;
680     comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
681     comp.lpszHostName = host;
682     comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
683     comp.lpszUserName = user;
684     comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
685     comp.lpszPassword = pwd;
686     comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
687     comp.lpszUrlPath = urlpart;
688     comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
689     comp.lpszExtraInfo = extra;
690     comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
691
692     r = InternetCrackUrlW(url2, 0, 0, &comp);
693     todo_wine {
694     ok(!r, "InternetCrackUrl should have failed\n");
695     ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
696         "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
697         GetLastError());
698     }
699
700     /* Test to see whether cracking a URL without a filename initializes urlpart */
701     urlpart[0]=0xba;
702     scheme[0]=0;
703     extra[0]=0;
704     host[0]=0;
705     user[0]=0;
706     pwd[0]=0;
707     memset(&comp, 0, sizeof comp);
708     comp.dwStructSize = sizeof comp;
709     comp.lpszScheme = scheme;
710     comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
711     comp.lpszHostName = host;
712     comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
713     comp.lpszUserName = user;
714     comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
715     comp.lpszPassword = pwd;
716     comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
717     comp.lpszUrlPath = urlpart;
718     comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
719     comp.lpszExtraInfo = extra;
720     comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
721     r = InternetCrackUrlW(url3, 0, 0, &comp );
722     ok( r, "InternetCrackUrlW failed unexpectedly\n");
723     ok( host[0] == 'x', "host should be x.org\n");
724     ok( urlpart[0] == 0, "urlpart should be empty\n");
725 }
726
727 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents)
728 {
729     static CHAR http[]       = "http",
730                 winehq[]     = "www.winehq.org",
731                 username[]   = "username",
732                 password[]   = "password",
733                 site_about[] = "/site/about",
734                 empty[]      = "";
735
736     lpUrlComponents->dwStructSize = sizeof(URL_COMPONENTS);
737     lpUrlComponents->lpszScheme = http;
738     lpUrlComponents->dwSchemeLength = strlen(lpUrlComponents->lpszScheme);
739     lpUrlComponents->nScheme = INTERNET_SCHEME_HTTP;
740     lpUrlComponents->lpszHostName = winehq;
741     lpUrlComponents->dwHostNameLength = strlen(lpUrlComponents->lpszHostName);
742     lpUrlComponents->nPort = 80;
743     lpUrlComponents->lpszUserName = username;
744     lpUrlComponents->dwUserNameLength = strlen(lpUrlComponents->lpszUserName);
745     lpUrlComponents->lpszPassword = password;
746     lpUrlComponents->dwPasswordLength = strlen(lpUrlComponents->lpszPassword);
747     lpUrlComponents->lpszUrlPath = site_about;
748     lpUrlComponents->dwUrlPathLength = strlen(lpUrlComponents->lpszUrlPath);
749     lpUrlComponents->lpszExtraInfo = empty;
750     lpUrlComponents->dwExtraInfoLength = strlen(lpUrlComponents->lpszExtraInfo);
751 }
752
753 static void InternetCreateUrlA_test(void)
754 {
755         URL_COMPONENTS urlComp;
756         LPSTR szUrl;
757         DWORD len = -1;
758         BOOL ret;
759         static CHAR empty[]      = "",
760                     nhttp[]      = "nhttp",
761                     http[]       = "http",
762                     https[]      = "https",
763                     winehq[]     = "www.winehq.org",
764                     localhost[]  = "localhost",
765                     username[]   = "username",
766                     password[]   = "password",
767                     root[]       = "/",
768                     site_about[] = "/site/about",
769                     extra_info[] = "?test=123",
770                     about[]      = "about",
771                     blank[]      = "blank",
772                     host[]       = "host";
773
774         /* test NULL lpUrlComponents */
775         SetLastError(0xdeadbeef);
776         ret = InternetCreateUrlA(NULL, 0, NULL, &len);
777         ok(!ret, "Expected failure\n");
778         ok(GetLastError() == ERROR_INVALID_PARAMETER,
779                 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
780         ok(len == -1, "Expected len -1, got %d\n", len);
781
782         /* test zero'ed lpUrlComponents */
783         ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
784         SetLastError(0xdeadbeef);
785         ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
786         ok(!ret, "Expected failure\n");
787         ok(GetLastError() == ERROR_INVALID_PARAMETER,
788                 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
789         ok(len == -1, "Expected len -1, got %d\n", len);
790
791         /* test valid lpUrlComponents, NULL lpdwUrlLength */
792         fill_url_components(&urlComp);
793         SetLastError(0xdeadbeef);
794         ret = InternetCreateUrlA(&urlComp, 0, NULL, NULL);
795         ok(!ret, "Expected failure\n");
796         ok(GetLastError() == ERROR_INVALID_PARAMETER,
797                 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
798
799         /* test valid lpUrlComponents, empty szUrl
800          * lpdwUrlLength is size of buffer required on exit, including
801          * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
802          */
803         SetLastError(0xdeadbeef);
804         ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
805         ok(!ret, "Expected failure\n");
806         ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
807                 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
808         ok(len == 51, "Expected len 51, got %d\n", len);
809
810         /* test correct size, NULL szUrl */
811         fill_url_components(&urlComp);
812         SetLastError(0xdeadbeef);
813         ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
814         ok(!ret, "Expected failure\n");
815         ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
816                 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
817         ok(len == 51, "Expected len 51, got %d\n", len);
818
819         /* test valid lpUrlComponents, alloc-ed szUrl, small size */
820         SetLastError(0xdeadbeef);
821         szUrl = HeapAlloc(GetProcessHeap(), 0, len);
822         len -= 2;
823         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
824         ok(!ret, "Expected failure\n");
825         ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
826                 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
827         ok(len == 51, "Expected len 51, got %d\n", len);
828
829         /* alloc-ed szUrl, NULL lpszScheme
830          * shows that it uses nScheme instead
831          */
832         SetLastError(0xdeadbeef);
833         urlComp.lpszScheme = NULL;
834         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
835         ok(ret, "Expected success\n");
836         ok(GetLastError() == 0xdeadbeef,
837                 "Expected 0xdeadbeef, got %d\n", GetLastError());
838         ok(len == 50, "Expected len 50, got %d\n", len);
839         ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
840
841         /* alloc-ed szUrl, invalid nScheme
842          * any nScheme out of range seems ignored
843          */
844         fill_url_components(&urlComp);
845         SetLastError(0xdeadbeef);
846         urlComp.nScheme = -3;
847         len++;
848         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
849         ok(ret, "Expected success\n");
850         ok(GetLastError() == 0xdeadbeef,
851                 "Expected 0xdeadbeef, got %d\n", GetLastError());
852         ok(len == 50, "Expected len 50, got %d\n", len);
853
854         /* test valid lpUrlComponents, alloc-ed szUrl */
855         fill_url_components(&urlComp);
856         SetLastError(0xdeadbeef);
857         len = 51;
858         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
859         ok(ret, "Expected success\n");
860         ok(GetLastError() == 0xdeadbeef,
861                 "Expected 0xdeadbeef, got %d\n", GetLastError());
862         ok(len == 50, "Expected len 50, got %d\n", len);
863         ok(strstr(szUrl, "80") == NULL, "Didn't expect to find 80 in szUrl\n");
864         ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
865
866         /* valid username, NULL password */
867         fill_url_components(&urlComp);
868         SetLastError(0xdeadbeef);
869         urlComp.lpszPassword = NULL;
870         len = 42;
871         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
872         ok(ret, "Expected success\n");
873         ok(GetLastError() == 0xdeadbeef,
874                 "Expected 0xdeadbeef, got %d\n", GetLastError());
875         ok(len == 41, "Expected len 41, got %d\n", len);
876         ok(!strcmp(szUrl, CREATE_URL2), "Expected %s, got %s\n", CREATE_URL2, szUrl);
877
878         /* valid username, empty password */
879         fill_url_components(&urlComp);
880         SetLastError(0xdeadbeef);
881         urlComp.lpszPassword = empty;
882         len = 51;
883         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
884         ok(ret, "Expected success\n");
885         ok(GetLastError() == 0xdeadbeef,
886                 "Expected 0xdeadbeef, got %d\n", GetLastError());
887         ok(len == 50, "Expected len 50, got %d\n", len);
888         ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
889
890         /* valid password, NULL username
891          * if password is provided, username has to exist
892          */
893         fill_url_components(&urlComp);
894         SetLastError(0xdeadbeef);
895         urlComp.lpszUserName = NULL;
896         len = 42;
897         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
898         ok(!ret, "Expected failure\n");
899         ok(GetLastError() == ERROR_INVALID_PARAMETER,
900                 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
901         ok(len == 42, "Expected len 42, got %d\n", len);
902         ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
903
904         /* valid password, empty username
905          * if password is provided, username has to exist
906          */
907         fill_url_components(&urlComp);
908         SetLastError(0xdeadbeef);
909         urlComp.lpszUserName = empty;
910         len = 51;
911         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
912         ok(ret, "Expected success\n");
913         ok(GetLastError() == 0xdeadbeef,
914                 "Expected 0xdeadbeef, got %d\n", GetLastError());
915         ok(len == 50, "Expected len 50, got %d\n", len);
916         ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
917
918         /* NULL username, NULL password */
919         fill_url_components(&urlComp);
920         SetLastError(0xdeadbeef);
921         urlComp.lpszUserName = NULL;
922         urlComp.lpszPassword = NULL;
923         len = 42;
924         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
925         ok(ret, "Expected success\n");
926         ok(GetLastError() == 0xdeadbeef,
927                 "Expected 0xdeadbeef, got %d\n", GetLastError());
928         ok(len == 32, "Expected len 32, got %d\n", len);
929         ok(!strcmp(szUrl, CREATE_URL4), "Expected %s, got %s\n", CREATE_URL4, szUrl);
930
931         /* empty username, empty password */
932         fill_url_components(&urlComp);
933         SetLastError(0xdeadbeef);
934         urlComp.lpszUserName = empty;
935         urlComp.lpszPassword = empty;
936         len = 51;
937         ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
938         ok(ret, "Expected success\n");
939         ok(GetLastError() == 0xdeadbeef,
940                 "Expected 0xdeadbeef, got %d\n", GetLastError());
941         ok(len == 50, "Expected len 50, got %d\n", len);
942         ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
943
944         /* shows that nScheme is ignored, as the appearance of the port number
945          * depends on lpszScheme and the string copied depends on lpszScheme.
946          */
947         fill_url_components(&urlComp);
948         HeapFree(GetProcessHeap(), 0, szUrl);
949         urlComp.lpszScheme = nhttp;
950         urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
951         len = strlen(CREATE_URL6) + 1;
952         szUrl = HeapAlloc(GetProcessHeap(), 0, len);
953         ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
954         ok(ret, "Expected success\n");
955         ok(len == strlen(CREATE_URL6), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6) + 1, len);
956         ok(!strcmp(szUrl, CREATE_URL6), "Expected %s, got %s\n", CREATE_URL6, szUrl);
957
958         /* if lpszScheme != "http" or nPort != 80, display nPort */
959         HeapFree(GetProcessHeap(), 0, szUrl);
960         urlComp.lpszScheme = http;
961         urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
962         urlComp.nPort = 42;
963         szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
964         ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
965         ok(ret, "Expected success\n");
966         ok(len == 53, "Expected len 53, got %d\n", len);
967         ok(strstr(szUrl, "42") != NULL, "Expected to find 42 in szUrl\n");
968         ok(!strcmp(szUrl, CREATE_URL7), "Expected %s, got %s\n", CREATE_URL7, szUrl);
969
970         HeapFree(GetProcessHeap(), 0, szUrl);
971
972         memset(&urlComp, 0, sizeof(urlComp));
973         urlComp.dwStructSize = sizeof(URL_COMPONENTS);
974         urlComp.lpszScheme = http;
975         urlComp.dwSchemeLength = 0;
976         urlComp.nScheme = INTERNET_SCHEME_HTTP;
977         urlComp.lpszHostName = winehq;
978         urlComp.dwHostNameLength = 0;
979         urlComp.nPort = 80;
980         urlComp.lpszUserName = username;
981         urlComp.dwUserNameLength = 0;
982         urlComp.lpszPassword = password;
983         urlComp.dwPasswordLength = 0;
984         urlComp.lpszUrlPath = site_about;
985         urlComp.dwUrlPathLength = 0;
986         urlComp.lpszExtraInfo = empty;
987         urlComp.dwExtraInfoLength = 0;
988         len = strlen(CREATE_URL1);
989         szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
990         ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
991         ok(ret, "Expected success\n");
992         ok(len == strlen(CREATE_URL1), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1), len);
993         ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
994
995         HeapFree(GetProcessHeap(), 0, szUrl);
996
997         memset(&urlComp, 0, sizeof(urlComp));
998         urlComp.dwStructSize = sizeof(URL_COMPONENTS);
999         urlComp.lpszScheme = https;
1000         urlComp.dwSchemeLength = 0;
1001         urlComp.nScheme = INTERNET_SCHEME_HTTP;
1002         urlComp.lpszHostName = winehq;
1003         urlComp.dwHostNameLength = 0;
1004         urlComp.nPort = 443;
1005         urlComp.lpszUserName = username;
1006         urlComp.dwUserNameLength = 0;
1007         urlComp.lpszPassword = password;
1008         urlComp.dwPasswordLength = 0;
1009         urlComp.lpszUrlPath = site_about;
1010         urlComp.dwUrlPathLength = 0;
1011         urlComp.lpszExtraInfo = empty;
1012         urlComp.dwExtraInfoLength = 0;
1013         len = strlen(CREATE_URL8);
1014         szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1015         ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1016         ok(ret, "Expected success\n");
1017         ok(len == strlen(CREATE_URL8), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8), len);
1018         ok(!strcmp(szUrl, CREATE_URL8), "Expected %s, got %s\n", CREATE_URL8, szUrl);
1019
1020         HeapFree(GetProcessHeap(), 0, szUrl);
1021
1022         memset(&urlComp, 0, sizeof(urlComp));
1023         urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1024         urlComp.lpszScheme = about;
1025         urlComp.dwSchemeLength = 5;
1026         urlComp.lpszUrlPath = blank;
1027         urlComp.dwUrlPathLength = 5;
1028         len = strlen(CREATE_URL9);
1029         len++; /* work around bug in native wininet */
1030         szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1031         ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1032         ok(ret, "Expected success\n");
1033         ok(len == strlen(CREATE_URL9), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9), len);
1034         ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
1035
1036         HeapFree(GetProcessHeap(), 0, szUrl);
1037
1038         memset(&urlComp, 0, sizeof(urlComp));
1039         urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1040         urlComp.lpszScheme = about;
1041         urlComp.lpszHostName = host;
1042         urlComp.lpszUrlPath = blank;
1043         len = strlen(CREATE_URL10);
1044         len++; /* work around bug in native wininet */
1045         szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1046         ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1047         ok(ret, "Expected success\n");
1048         ok(len == strlen(CREATE_URL10), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10), len);
1049         ok(!strcmp(szUrl, CREATE_URL10), "Expected %s, got %s\n", CREATE_URL10, szUrl);
1050
1051         HeapFree(GetProcessHeap(), 0, szUrl);
1052
1053         memset(&urlComp, 0, sizeof(urlComp));
1054         urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1055         urlComp.nPort = 8080;
1056         urlComp.lpszScheme = about;
1057         len = strlen(CREATE_URL11);
1058         szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1059         ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1060         ok(ret, "Expected success\n");
1061         ok(len == strlen(CREATE_URL11), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11), len);
1062         ok(!strcmp(szUrl, CREATE_URL11), "Expected %s, got %s\n", CREATE_URL11, szUrl);
1063
1064         HeapFree(GetProcessHeap(), 0, szUrl);
1065
1066         memset(&urlComp, 0, sizeof(urlComp));
1067         urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1068         urlComp.lpszScheme = http;
1069         urlComp.dwSchemeLength = 0;
1070         urlComp.nScheme = INTERNET_SCHEME_HTTP;
1071         urlComp.lpszHostName = winehq;
1072         urlComp.dwHostNameLength = 0;
1073         urlComp.nPort = 65535;
1074         len = strlen(CREATE_URL12);
1075         szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1076         ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1077         ok(ret, "Expected success\n");
1078         ok(len == strlen(CREATE_URL12), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12), len);
1079         ok(!strcmp(szUrl, CREATE_URL12), "Expected %s, got %s\n", CREATE_URL12, szUrl);
1080
1081         HeapFree(GetProcessHeap(), 0, szUrl);
1082
1083     memset(&urlComp, 0, sizeof(urlComp));
1084     urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1085     urlComp.lpszScheme = http;
1086     urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
1087     urlComp.lpszHostName = localhost;
1088     urlComp.dwHostNameLength = strlen(urlComp.lpszHostName);
1089     urlComp.nPort = 80;
1090     urlComp.lpszUrlPath = root;
1091     urlComp.dwUrlPathLength = strlen(urlComp.lpszUrlPath);
1092     urlComp.lpszExtraInfo = extra_info;
1093     urlComp.dwExtraInfoLength = strlen(urlComp.lpszExtraInfo);
1094     len = 256;
1095     szUrl = HeapAlloc(GetProcessHeap(), 0, len);
1096     InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1097     ok(ret, "Expected success\n");
1098     ok(len == strlen(CREATE_URL13), "Got len %u\n", len);
1099     ok(!strcmp(szUrl, CREATE_URL13), "Expected \"%s\", got \"%s\"\n", CREATE_URL13, szUrl);
1100
1101     HeapFree(GetProcessHeap(), 0, szUrl);
1102 }
1103
1104 static void InternetCanonicalizeUrl_test(void)
1105 {
1106     char src[] = "http://www.winehq.org/%27/ /./>/#>  ";
1107     char dst[64];
1108     DWORD dstlen;
1109
1110     dstlen = sizeof(dst);
1111     InternetCanonicalizeUrlA(src, dst, &dstlen, 0);
1112     ok(strcmp(dst, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1113
1114     /* despite what MSDN says, ICU_BROWSER_MODE seems to be ignored */
1115     dstlen = sizeof(dst);
1116     InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_BROWSER_MODE);
1117     ok(strcmp(dst, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1118
1119     /* ICU_ESCAPE is supposed to be ignored */
1120     dstlen = sizeof(dst);
1121     InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_ESCAPE);
1122     ok(strcmp(dst, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1123
1124     dstlen = sizeof(dst);
1125     InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_DECODE);
1126     ok(strcmp(dst, "http://www.winehq.org/'/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1127
1128     dstlen = sizeof(dst);
1129     InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_ENCODE_PERCENT);
1130     ok(strcmp(dst, "http://www.winehq.org/%2527/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1131
1132     dstlen = sizeof(dst);
1133     InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_ENCODE_SPACES_ONLY);
1134     ok(strcmp(dst, "http://www.winehq.org/%27/%20/>/#>") == 0, "Got \"%s\"\n", dst);
1135
1136     dstlen = sizeof(dst);
1137     InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_NO_ENCODE);
1138     ok(strcmp(dst, "http://www.winehq.org/%27/ />/#>") == 0, "Got \"%s\"\n", dst);
1139
1140     dstlen = sizeof(dst);
1141     InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_NO_META);
1142     ok(strcmp(dst, "http://www.winehq.org/%27/%20/./%3E/#>") == 0, "Got \"%s\"\n", dst);
1143 }
1144
1145 START_TEST(url)
1146 {
1147     int i;
1148
1149     if(!GetProcAddress(GetModuleHandleA("wininet.dll"), "InternetGetCookieExW")) {
1150         win_skip("Too old IE (older than 6.0)\n");
1151         return;
1152     }
1153
1154     for(i=0; i < sizeof(crack_url_tests)/sizeof(*crack_url_tests); i++)
1155         test_crack_url(crack_url_tests+i);
1156
1157     InternetCrackUrl_test();
1158     InternetCrackUrlW_test();
1159     InternetCreateUrlA_test();
1160     InternetCanonicalizeUrl_test();
1161 }