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