wininet: Fail on URLs without a scheme.
[wine.git] / dlls / wininet / tests / url.c
blob7817e8f4feea64c36bb461e776e69744bb75a9b9
1 /*
2 * Wininet - URL tests
4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
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.
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.
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
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31 #include "wininet.h"
33 #include "wine/test.h"
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"
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"
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 )
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);
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 )
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);
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;
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 {"C:\\file.txt",
164 0, 1, INTERNET_SCHEME_UNKNOWN, -1, 0, -1, 0, -1, 0, -1, 0, 2, 9, -1, 0,
165 "C", "", "", "", "\\file.txt", ""}
168 static const WCHAR *w_str_of(const char *str)
170 static WCHAR buf[512];
171 MultiByteToWideChar(CP_ACP, 0, str, -1, buf, sizeof(buf)/sizeof(buf[0]));
172 return buf;
175 static void test_crack_url(const crack_url_test_t *test)
177 WCHAR buf[INTERNET_MAX_URL_LENGTH];
178 URL_COMPONENTSW urlw;
179 URL_COMPONENTSA url;
180 char scheme[32], hostname[1024], username[1024];
181 char password[1024], extrainfo[1024], urlpath[1024];
182 BOOL b;
184 /* test InternetCrackUrlA with NULL buffers */
185 zero_compsA(&url, 1, 1, 1, 1, 1, 1);
187 b = InternetCrackUrlA(test->url, strlen(test->url), 0, &url);
188 ok(b, "InternetCrackUrl failed with error %d\n", GetLastError());
190 if(test->scheme_off == -1)
191 ok(!url.lpszScheme, "[%s] url.lpszScheme = %p, expected NULL\n", test->url, url.lpszScheme);
192 else
193 ok(url.lpszScheme == test->url+test->scheme_off, "[%s] url.lpszScheme = %p, expected %p\n",
194 test->url, url.lpszScheme, test->url+test->scheme_off);
195 ok(url.dwSchemeLength == test->scheme_len, "[%s] url.lpszSchemeLength = %d, expected %d\n",
196 test->url, url.dwSchemeLength, test->scheme_len);
198 ok(url.nScheme == test->scheme, "[%s] url.nScheme = %d, expected %d\n", test->url, url.nScheme, test->scheme);
200 if(test->host_off == -1)
201 ok(!url.lpszHostName, "[%s] url.lpszHostName = %p, expected NULL\n", test->url, url.lpszHostName);
202 else
203 ok(url.lpszHostName == test->url+test->host_off, "[%s] url.lpszHostName = %p, expected %p\n",
204 test->url, url.lpszHostName, test->url+test->host_off);
205 if(test->host_skip_broken != -1 && url.dwHostNameLength == test->host_skip_broken) {
206 win_skip("skipping broken dwHostNameLength result\n");
207 return;
209 ok(url.dwHostNameLength == test->host_len, "[%s] url.lpszHostNameLength = %d, expected %d\n",
210 test->url, url.dwHostNameLength, test->host_len);
212 ok(url.nPort == test->port, "[%s] nPort = %d, expected %d\n", test->url, url.nPort, test->port);
214 if(test->user_off == -1)
215 ok(!url.lpszUserName, "[%s] url.lpszUserName = %p\n", test->url, url.lpszUserName);
216 else
217 ok(url.lpszUserName == test->url+test->user_off, "[%s] url.lpszUserName = %p, expected %p\n",
218 test->url, url.lpszUserName, test->url+test->user_off);
219 ok(url.dwUserNameLength == test->user_len, "[%s] url.lpszUserNameLength = %d, expected %d\n",
220 test->url, url.dwUserNameLength, test->user_len);
222 if(test->pass_off == -1)
223 ok(!url.lpszPassword, "[%s] url.lpszPassword = %p\n", test->url, url.lpszPassword);
224 else
225 ok(url.lpszPassword == test->url+test->pass_off, "[%s] url.lpszPassword = %p, expected %p\n",
226 test->url, url.lpszPassword, test->url+test->pass_off);
227 ok(url.dwPasswordLength == test->pass_len, "[%s] url.lpszPasswordLength = %d, expected %d\n",
228 test->url, url.dwPasswordLength, test->pass_len);
230 if(test->path_off == -1)
231 ok(!url.lpszUrlPath, "[%s] url.lpszPath = %p, expected NULL\n", test->url, url.lpszUrlPath);
232 else
233 ok(url.lpszUrlPath == test->url+test->path_off, "[%s] url.lpszPath = %p, expected %p\n",
234 test->url, url.lpszUrlPath, test->url+test->path_off);
235 ok(url.dwUrlPathLength == test->path_len, "[%s] url.lpszUrlPathLength = %d, expected %d\n",
236 test->url, url.dwUrlPathLength, test->path_len);
238 if(test->extra_off == -1)
239 ok(!url.lpszExtraInfo, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test->url, url.lpszExtraInfo);
240 else
241 ok(url.lpszExtraInfo == test->url+test->extra_off, "[%s] url.lpszExtraInfo = %p, expected %p\n",
242 test->url, url.lpszExtraInfo, test->url+test->extra_off);
243 ok(url.dwExtraInfoLength == test->extra_len, "[%s] url.lpszExtraInfoLength = %d, expected %d\n",
244 test->url, url.dwExtraInfoLength, test->extra_len);
246 /* test InternetCrackUrlW with NULL buffers */
247 memset(&urlw, 0, sizeof(URL_COMPONENTSW));
248 urlw.dwStructSize = sizeof(URL_COMPONENTSW);
249 urlw.dwSchemeLength = 1;
250 urlw.dwHostNameLength = 1;
251 urlw.dwUserNameLength = 1;
252 urlw.dwPasswordLength = 1;
253 urlw.dwUrlPathLength = 1;
254 urlw.dwExtraInfoLength = 1;
256 MultiByteToWideChar(CP_ACP, 0, test->url, -1, buf, sizeof(buf)/sizeof(buf[0]));
257 b = InternetCrackUrlW(buf, lstrlenW(buf), 0, &urlw);
258 if(!b && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
259 win_skip("InternetCrackUrlW is not implemented\n");
260 return;
262 ok(b, "InternetCrackUrl failed with error %d\n", GetLastError());
264 if(test->scheme_off == -1)
265 ok(!urlw.lpszScheme, "[%s] urlw.lpszScheme = %p, expected NULL\n", test->url, urlw.lpszScheme);
266 else
267 ok(urlw.lpszScheme == buf+test->scheme_off, "[%s] urlw.lpszScheme = %p, expected %p\n",
268 test->url, urlw.lpszScheme, buf+test->scheme_off);
269 ok(urlw.dwSchemeLength == test->scheme_len, "[%s] urlw.lpszSchemeLength = %d, expected %d\n",
270 test->url, urlw.dwSchemeLength, test->scheme_len);
272 ok(urlw.nScheme == test->scheme, "[%s] urlw.nScheme = %d, expected %d\n", test->url, urlw.nScheme, test->scheme);
274 if(test->host_off == -1) {
275 ok(!urlw.lpszHostName, "[%s] urlw.lpszHostName = %p, expected NULL\n", test->url, urlw.lpszHostName);
276 ok(urlw.dwHostNameLength == 0 || broken(urlw.dwHostNameLength == 1), "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
277 test->url, urlw.dwHostNameLength, test->host_len);
278 }else {
279 ok(urlw.lpszHostName == buf+test->host_off, "[%s] urlw.lpszHostName = %p, expected %p\n",
280 test->url, urlw.lpszHostName, test->url+test->host_off);
281 ok(urlw.dwHostNameLength == test->host_len, "[%s] urlw.lpszHostNameLength = %d, expected %d\n",
282 test->url, urlw.dwHostNameLength, test->host_len);
285 ok(urlw.nPort == test->port, "[%s] nPort = %d, expected %d\n", test->url, urlw.nPort, test->port);
287 if(test->user_off == -1) {
288 ok(!urlw.lpszUserName, "[%s] urlw.lpszUserName = %p\n", test->url, urlw.lpszUserName);
289 ok(urlw.dwUserNameLength == 0 || broken(urlw.dwUserNameLength == 1), "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
290 test->url, urlw.dwUserNameLength, test->user_len);
291 }else {
292 ok(urlw.lpszUserName == buf+test->user_off, "[%s] urlw.lpszUserName = %p, expected %p\n",
293 test->url, urlw.lpszUserName, buf+test->user_off);
294 ok(urlw.dwUserNameLength == test->user_len, "[%s] urlw.lpszUserNameLength = %d, expected %d\n",
295 test->url, urlw.dwUserNameLength, test->user_len);
298 if(test->pass_off == -1) {
299 ok(!urlw.lpszPassword, "[%s] urlw.lpszPassword = %p\n", test->url, urlw.lpszPassword);
300 ok(urlw.dwPasswordLength == 0 || broken(urlw.dwPasswordLength), "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
301 test->url, urlw.dwPasswordLength, test->pass_len);
302 }else {
303 ok(urlw.lpszPassword == buf+test->pass_off, "[%s] urlw.lpszPassword = %p, expected %p\n",
304 test->url, urlw.lpszPassword, buf+test->pass_off);
305 ok(urlw.dwPasswordLength == test->pass_len, "[%s] urlw.lpszPasswordLength = %d, expected %d\n",
306 test->url, urlw.dwPasswordLength, test->pass_len);
309 if(test->path_off == -1)
310 ok(!urlw.lpszUrlPath, "[%s] urlw.lpszPath = %p, expected NULL\n", test->url, urlw.lpszUrlPath);
311 else
312 ok(urlw.lpszUrlPath == buf+test->path_off, "[%s] urlw.lpszPath = %p, expected %p\n",
313 test->url, urlw.lpszUrlPath, buf+test->path_off);
314 ok(urlw.dwUrlPathLength == test->path_len, "[%s] urlw.lpszUrlPathLength = %d, expected %d\n",
315 test->url, urlw.dwUrlPathLength, test->path_len);
317 if(test->extra_off == -1) {
318 ok(!urlw.lpszExtraInfo, "[%s] url.lpszExtraInfo = %p, expected NULL\n", test->url, urlw.lpszExtraInfo);
319 ok(urlw.dwExtraInfoLength == 0 || broken(urlw.dwExtraInfoLength == 1), "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
320 test->url, urlw.dwExtraInfoLength, test->extra_len);
321 }else {
322 ok(urlw.lpszExtraInfo == buf+test->extra_off, "[%s] urlw.lpszExtraInfo = %p, expected %p\n",
323 test->url, urlw.lpszExtraInfo, buf+test->extra_off);
324 ok(urlw.dwExtraInfoLength == test->extra_len, "[%s] urlw.lpszExtraInfoLength = %d, expected %d\n",
325 test->url, urlw.dwExtraInfoLength, test->extra_len);
328 /* test InternetCrackUrlA with valid buffers */
329 memset(&url, 0, sizeof(URL_COMPONENTSA));
330 url.dwStructSize = sizeof(URL_COMPONENTSA);
331 url.lpszScheme = scheme;
332 url.dwSchemeLength = sizeof(scheme);
333 url.lpszHostName = hostname;
334 url.dwHostNameLength = sizeof(hostname);
335 url.lpszUserName = username;
336 url.dwUserNameLength = sizeof(username);
337 url.lpszPassword = password;
338 url.dwPasswordLength = sizeof(password);
339 url.lpszUrlPath = urlpath;
340 url.dwUrlPathLength = sizeof(urlpath);
341 url.lpszExtraInfo = extrainfo;
342 url.dwExtraInfoLength = sizeof(extrainfo);
344 b = InternetCrackUrlA(test->url, strlen(test->url), 0, &url);
345 ok(b, "InternetCrackUrlA failed with error %d\n", GetLastError());
347 ok(url.dwSchemeLength == strlen(test->exp_scheme), "[%s] Got wrong scheme length: %d\n",
348 test->url, url.dwSchemeLength);
349 ok(!strcmp(scheme, test->exp_scheme), "[%s] Got wrong scheme, expected: %s, got: %s\n",
350 test->url, test->exp_scheme, scheme);
352 ok(url.nScheme == test->scheme, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
353 test->url, test->scheme, url.nScheme);
355 ok(url.dwHostNameLength == strlen(test->exp_hostname), "[%s] Got wrong hostname length: %d\n",
356 test->url, url.dwHostNameLength);
357 ok(!strcmp(hostname, test->exp_hostname), "[%s] Got wrong hostname, expected: %s, got: %s\n",
358 test->url, test->exp_hostname, hostname);
360 ok(url.nPort == test->port, "[%s] Got wrong port, expected: %d, got: %d\n",
361 test->url, test->port, url.nPort);
363 ok(url.dwUserNameLength == strlen(test->exp_username), "[%s] Got wrong username length: %d\n",
364 test->url, url.dwUserNameLength);
365 ok(!strcmp(username, test->exp_username), "[%s] Got wrong username, expected: %s, got: %s\n",
366 test->url, test->exp_username, username);
368 ok(url.dwPasswordLength == strlen(test->exp_password), "[%s] Got wrong password length: %d\n",
369 test->url, url.dwPasswordLength);
370 ok(!strcmp(password, test->exp_password), "[%s] Got wrong password, expected: %s, got: %s\n",
371 test->url, test->exp_password, password);
373 ok(url.dwUrlPathLength == strlen(test->exp_urlpath), "[%s] Got wrong urlpath length: %d\n",
374 test->url, url.dwUrlPathLength);
375 ok(!strcmp(urlpath, test->exp_urlpath), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
376 test->url, test->exp_urlpath, urlpath);
378 ok(url.dwExtraInfoLength == strlen(test->exp_extrainfo), "[%s] Got wrong extrainfo length: %d\n",
379 test->url, url.dwExtraInfoLength);
380 ok(!strcmp(extrainfo, test->exp_extrainfo), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
381 test->url, test->exp_extrainfo, extrainfo);
383 /* test InternetCrackUrlW with valid buffers */
384 memset(&urlw, 0, sizeof(URL_COMPONENTSW));
385 urlw.dwStructSize = sizeof(URL_COMPONENTSW);
386 urlw.lpszScheme = (WCHAR*)scheme;
387 urlw.dwSchemeLength = sizeof(scheme) / sizeof(WCHAR);
388 urlw.lpszHostName = (WCHAR*)hostname;
389 urlw.dwHostNameLength = sizeof(hostname) / sizeof(WCHAR);
390 urlw.lpszUserName = (WCHAR*)username;
391 urlw.dwUserNameLength = sizeof(username) / sizeof(WCHAR);
392 urlw.lpszPassword = (WCHAR*)password;
393 urlw.dwPasswordLength = sizeof(password) / sizeof(WCHAR);
394 urlw.lpszUrlPath = (WCHAR*)urlpath;
395 urlw.dwUrlPathLength = sizeof(urlpath) / sizeof(WCHAR);
396 urlw.lpszExtraInfo = (WCHAR*)extrainfo;
397 urlw.dwExtraInfoLength = sizeof(extrainfo) / sizeof(WCHAR);
399 b = InternetCrackUrlW(buf, lstrlenW(buf), 0, &urlw);
400 ok(b, "InternetCrackUrlW failed with error %d\n", GetLastError());
402 ok(urlw.dwSchemeLength == strlen(test->exp_scheme), "[%s] Got wrong scheme length: %d\n",
403 test->url, urlw.dwSchemeLength);
404 ok(!lstrcmpW((WCHAR*)scheme, w_str_of(test->exp_scheme)), "[%s] Got wrong scheme, expected: %s, got: %s\n",
405 test->url, test->exp_scheme, wine_dbgstr_w((WCHAR*)scheme));
407 ok(urlw.nScheme == test->scheme, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
408 test->url, test->scheme, urlw.nScheme);
410 ok(urlw.dwHostNameLength == strlen(test->exp_hostname), "[%s] Got wrong hostname length: %d\n",
411 test->url, urlw.dwHostNameLength);
412 ok(!lstrcmpW((WCHAR*)hostname, w_str_of(test->exp_hostname)), "[%s] Got wrong hostname, expected: %s, got: %s\n",
413 test->url, test->exp_hostname, wine_dbgstr_w((WCHAR*)hostname));
415 ok(urlw.nPort == test->port, "[%s] Got wrong port, expected: %d, got: %d\n",
416 test->url, test->port, urlw.nPort);
418 ok(urlw.dwUserNameLength == strlen(test->exp_username), "[%s] Got wrong username length: %d\n",
419 test->url, urlw.dwUserNameLength);
420 ok(!lstrcmpW((WCHAR*)username, w_str_of(test->exp_username)), "[%s] Got wrong username, expected: %s, got: %s\n",
421 test->url, test->exp_username, wine_dbgstr_w((WCHAR*)username));
423 ok(urlw.dwPasswordLength == strlen(test->exp_password), "[%s] Got wrong password length: %d\n",
424 test->url, urlw.dwPasswordLength);
425 ok(!lstrcmpW((WCHAR*)password, w_str_of(test->exp_password)), "[%s] Got wrong password, expected: %s, got: %s\n",
426 test->url, test->exp_password, wine_dbgstr_w((WCHAR*)password));
428 ok(urlw.dwUrlPathLength == strlen(test->exp_urlpath), "[%s] Got wrong urlpath length: %d\n",
429 test->url, urlw.dwUrlPathLength);
430 ok(!lstrcmpW((WCHAR*)urlpath, w_str_of(test->exp_urlpath)), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
431 test->url, test->exp_urlpath, wine_dbgstr_w((WCHAR*)urlpath));
433 ok(urlw.dwExtraInfoLength == strlen(test->exp_extrainfo), "[%s] Got wrong extrainfo length: %d\n",
434 test->url, urlw.dwExtraInfoLength);
435 ok(!lstrcmpW((WCHAR*)extrainfo, w_str_of(test->exp_extrainfo)), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
436 test->url, test->exp_extrainfo, wine_dbgstr_w((WCHAR*)extrainfo));
439 static void InternetCrackUrl_test(void)
441 URL_COMPONENTSA urlSrc, urlComponents;
442 char protocol[32], hostName[1024], userName[1024];
443 char password[1024], extra[1024], path[1024];
444 BOOL ret, firstret;
445 DWORD GLE, firstGLE;
447 ZeroMemory(&urlSrc, sizeof(urlSrc));
448 urlSrc.dwStructSize = sizeof(urlSrc);
449 urlSrc.lpszScheme = protocol;
450 urlSrc.lpszHostName = hostName;
451 urlSrc.lpszUserName = userName;
452 urlSrc.lpszPassword = password;
453 urlSrc.lpszUrlPath = path;
454 urlSrc.lpszExtraInfo = extra;
456 /* Tests for lpsz* members pointing to real strings while
457 * some corresponding length members are set to zero.
458 * As of IE7 (wininet 7.0*?) all members are checked. So we
459 * run the first test and expect the outcome to be the same
460 * for the first four (scheme, hostname, username and password).
461 * The last two (path and extrainfo) are the same for all versions
462 * of the wininet.dll.
464 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
465 SetLastError(0xdeadbeef);
466 firstret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
467 firstGLE = GetLastError();
469 copy_compsA(&urlSrc, &urlComponents, 32, 0, 1024, 1024, 2048, 1024);
470 SetLastError(0xdeadbeef);
471 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
472 GLE = GetLastError();
473 ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
474 ret, GLE, firstret);
476 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 0, 1024, 2048, 1024);
477 SetLastError(0xdeadbeef);
478 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
479 GLE = GetLastError();
480 ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
481 ret, GLE, firstret);
483 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 0, 2048, 1024);
484 SetLastError(0xdeadbeef);
485 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
486 GLE = GetLastError();
487 ok(ret==firstret && (GLE==firstGLE), "InternetCrackUrl returned %d with GLE=%d (expected to return %d)\n",
488 ret, GLE, firstret);
490 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 0, 1024);
491 SetLastError(0xdeadbeef);
492 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
493 GLE = GetLastError();
494 todo_wine
495 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
496 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
497 ret, GLE);
499 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 0);
500 SetLastError(0xdeadbeef);
501 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
502 GLE = GetLastError();
503 todo_wine
504 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
505 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
506 ret, GLE);
508 copy_compsA(&urlSrc, &urlComponents, 0, 0, 0, 0, 0, 0);
509 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
510 GLE = GetLastError();
511 todo_wine
512 ok(ret==0 && GLE==ERROR_INVALID_PARAMETER,
513 "InternetCrackUrl returned %d with GLE=%d (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
514 ret, GLE);
516 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
517 ret = InternetCrackUrl("about://host/blank", 0,0,&urlComponents);
518 ok(ret, "InternetCrackUrl failed with %d\n", GetLastError());
519 ok(!strcmp(urlComponents.lpszScheme, "about"), "lpszScheme was \"%s\" instead of \"about\"\n", urlComponents.lpszScheme);
520 ok(!strcmp(urlComponents.lpszHostName, "host"), "lpszHostName was \"%s\" instead of \"host\"\n", urlComponents.lpszHostName);
521 ok(!strcmp(urlComponents.lpszUrlPath, "/blank"), "lpszUrlPath was \"%s\" instead of \"/blank\"\n", urlComponents.lpszUrlPath);
523 /* try a NULL lpszUrl */
524 SetLastError(0xdeadbeef);
525 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
526 ret = InternetCrackUrl(NULL, 0, 0, &urlComponents);
527 GLE = GetLastError();
528 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
529 ok(GLE == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GLE);
531 /* try an empty lpszUrl, GetLastError returns 12006, whatever that means
532 * we just need to fail and not return success
534 SetLastError(0xdeadbeef);
535 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
536 ret = InternetCrackUrl("", 0, 0, &urlComponents);
537 GLE = GetLastError();
538 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
539 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
541 /* Invalid Call: must set size of components structure (Windows only
542 * enforces this on the InternetCrackUrlA version of the call) */
543 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
544 SetLastError(0xdeadbeef);
545 urlComponents.dwStructSize = 0;
546 ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
547 GLE = GetLastError();
548 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
549 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
551 /* Invalid Call: size of dwStructSize must be one of the "standard" sizes
552 * of the URL_COMPONENTS structure (Windows only enforces this on the
553 * InternetCrackUrlA version of the call) */
554 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
555 SetLastError(0xdeadbeef);
556 urlComponents.dwStructSize = sizeof(urlComponents) + 1;
557 ret = InternetCrackUrlA(TEST_URL, 0, 0, &urlComponents);
558 GLE = GetLastError();
559 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
560 ok(GLE != 0xdeadbeef && GLE != ERROR_SUCCESS, "Expected GLE to represent a failure\n");
562 SetLastError(0xdeadbeef);
563 memset(&urlComponents, 0, sizeof(urlComponents));
564 urlComponents.dwStructSize = sizeof(urlComponents);
565 ret = InternetCrackUrlA("file.txt", 0, 0, &urlComponents);
566 GLE = GetLastError();
567 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
568 ok(GLE == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "Expected GLE to represent a failure\n");
570 SetLastError(0xdeadbeef);
571 memset(&urlComponents, 0, sizeof(urlComponents));
572 urlComponents.dwStructSize = sizeof(urlComponents);
573 ret = InternetCrackUrlA("www.winehq.org", 0, 0, &urlComponents);
574 GLE = GetLastError();
575 ok(ret == FALSE, "Expected InternetCrackUrl to fail\n");
576 ok(GLE == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "Expected GLE to represent a failure\n");
579 static void InternetCrackUrlW_test(void)
581 WCHAR url[] = {
582 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
583 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
584 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
585 'U','L','T', 0 };
586 static const WCHAR url2[] = { '.','.','/','R','i','t','z','.','x','m','l',0 };
587 static const WCHAR url3[] = { 'h','t','t','p',':','/','/','x','.','o','r','g',0 };
588 URL_COMPONENTSW comp;
589 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
590 DWORD error;
591 BOOL r;
593 urlpart[0]=0;
594 scheme[0]=0;
595 extra[0]=0;
596 host[0]=0;
597 user[0]=0;
598 pwd[0]=0;
599 memset(&comp, 0, sizeof comp);
600 comp.dwStructSize = sizeof(comp);
601 comp.lpszScheme = scheme;
602 comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
603 comp.lpszHostName = host;
604 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
605 comp.lpszUserName = user;
606 comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
607 comp.lpszPassword = pwd;
608 comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
609 comp.lpszUrlPath = urlpart;
610 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
611 comp.lpszExtraInfo = extra;
612 comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
614 SetLastError(0xdeadbeef);
615 r = InternetCrackUrlW(NULL, 0, 0, &comp );
616 error = GetLastError();
617 if (!r && error == ERROR_CALL_NOT_IMPLEMENTED)
619 win_skip("InternetCrackUrlW is not implemented\n");
620 return;
622 ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
623 ok( error == ERROR_INVALID_PARAMETER ||
624 broken(error == ERROR_INTERNET_UNRECOGNIZED_SCHEME), /* IE5 */
625 "expected ERROR_INVALID_PARAMETER got %u\n", error);
627 if (error == ERROR_INVALID_PARAMETER)
629 /* Crashes on IE5 */
630 SetLastError(0xdeadbeef);
631 r = InternetCrackUrlW(url, 0, 0, NULL );
632 error = GetLastError();
633 ok( !r, "InternetCrackUrlW succeeded unexpectedly\n");
634 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error);
637 r = InternetCrackUrlW(url, 0, 0, &comp );
638 ok( r, "failed to crack url\n");
639 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
640 ok( comp.dwHostNameLength == 12, "host length wrong\n");
641 ok( comp.dwUserNameLength == 0, "user length wrong\n");
642 ok( comp.dwPasswordLength == 0, "password length wrong\n");
643 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
644 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
646 urlpart[0]=0;
647 scheme[0]=0;
648 extra[0]=0;
649 host[0]=0;
650 user[0]=0;
651 pwd[0]=0;
652 memset(&comp, 0, sizeof comp);
653 comp.dwStructSize = sizeof comp;
654 comp.lpszHostName = host;
655 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
656 comp.lpszUrlPath = urlpart;
657 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
659 r = InternetCrackUrlW(url, 0, 0, &comp );
660 ok( r, "failed to crack url\n");
661 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
662 ok( comp.dwHostNameLength == 12, "host length wrong\n");
663 ok( comp.dwUserNameLength == 0, "user length wrong\n");
664 ok( comp.dwPasswordLength == 0, "password length wrong\n");
665 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
666 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
668 urlpart[0]=0;
669 scheme[0]=0;
670 extra[0]=0;
671 host[0]=0;
672 user[0]=0;
673 pwd[0]=0;
674 memset(&comp, 0, sizeof comp);
675 comp.dwStructSize = sizeof comp;
676 comp.lpszHostName = host;
677 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
678 comp.lpszUrlPath = urlpart;
679 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
680 comp.lpszExtraInfo = NULL;
681 comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
683 r = InternetCrackUrlW(url, 0, 0, &comp );
684 ok( r, "failed to crack url\n");
685 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
686 ok( comp.dwHostNameLength == 12, "host length wrong\n");
687 ok( comp.dwUserNameLength == 0, "user length wrong\n");
688 ok( comp.dwPasswordLength == 0, "password length wrong\n");
689 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
690 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
692 urlpart[0]=0;
693 scheme[0]=0;
694 extra[0]=0;
695 host[0]=0;
696 user[0]=0;
697 pwd[0]=0;
698 memset(&comp, 0, sizeof(comp));
699 comp.dwStructSize = sizeof(comp);
700 comp.lpszScheme = scheme;
701 comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
702 comp.lpszHostName = host;
703 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
704 comp.lpszUserName = user;
705 comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
706 comp.lpszPassword = pwd;
707 comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
708 comp.lpszUrlPath = urlpart;
709 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
710 comp.lpszExtraInfo = extra;
711 comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
713 r = InternetCrackUrlW(url2, 0, 0, &comp);
714 ok(!r, "InternetCrackUrl should have failed\n");
715 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
716 "InternetCrackUrl should have failed with error ERROR_INTERNET_UNRECOGNIZED_SCHEME instead of error %d\n",
717 GetLastError());
719 /* Test to see whether cracking a URL without a filename initializes urlpart */
720 urlpart[0]=0xba;
721 scheme[0]=0;
722 extra[0]=0;
723 host[0]=0;
724 user[0]=0;
725 pwd[0]=0;
726 memset(&comp, 0, sizeof comp);
727 comp.dwStructSize = sizeof comp;
728 comp.lpszScheme = scheme;
729 comp.dwSchemeLength = sizeof(scheme)/sizeof(scheme[0]);
730 comp.lpszHostName = host;
731 comp.dwHostNameLength = sizeof(host)/sizeof(host[0]);
732 comp.lpszUserName = user;
733 comp.dwUserNameLength = sizeof(user)/sizeof(user[0]);
734 comp.lpszPassword = pwd;
735 comp.dwPasswordLength = sizeof(pwd)/sizeof(pwd[0]);
736 comp.lpszUrlPath = urlpart;
737 comp.dwUrlPathLength = sizeof(urlpart)/sizeof(urlpart[0]);
738 comp.lpszExtraInfo = extra;
739 comp.dwExtraInfoLength = sizeof(extra)/sizeof(extra[0]);
740 r = InternetCrackUrlW(url3, 0, 0, &comp );
741 ok( r, "InternetCrackUrlW failed unexpectedly\n");
742 ok( host[0] == 'x', "host should be x.org\n");
743 ok( urlpart[0] == 0, "urlpart should be empty\n");
746 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents)
748 static CHAR http[] = "http",
749 winehq[] = "www.winehq.org",
750 username[] = "username",
751 password[] = "password",
752 site_about[] = "/site/about",
753 empty[] = "";
755 lpUrlComponents->dwStructSize = sizeof(URL_COMPONENTS);
756 lpUrlComponents->lpszScheme = http;
757 lpUrlComponents->dwSchemeLength = strlen(lpUrlComponents->lpszScheme);
758 lpUrlComponents->nScheme = INTERNET_SCHEME_HTTP;
759 lpUrlComponents->lpszHostName = winehq;
760 lpUrlComponents->dwHostNameLength = strlen(lpUrlComponents->lpszHostName);
761 lpUrlComponents->nPort = 80;
762 lpUrlComponents->lpszUserName = username;
763 lpUrlComponents->dwUserNameLength = strlen(lpUrlComponents->lpszUserName);
764 lpUrlComponents->lpszPassword = password;
765 lpUrlComponents->dwPasswordLength = strlen(lpUrlComponents->lpszPassword);
766 lpUrlComponents->lpszUrlPath = site_about;
767 lpUrlComponents->dwUrlPathLength = strlen(lpUrlComponents->lpszUrlPath);
768 lpUrlComponents->lpszExtraInfo = empty;
769 lpUrlComponents->dwExtraInfoLength = strlen(lpUrlComponents->lpszExtraInfo);
772 static void InternetCreateUrlA_test(void)
774 URL_COMPONENTS urlComp;
775 LPSTR szUrl;
776 DWORD len = -1;
777 BOOL ret;
778 static CHAR empty[] = "",
779 nhttp[] = "nhttp",
780 http[] = "http",
781 https[] = "https",
782 winehq[] = "www.winehq.org",
783 localhost[] = "localhost",
784 username[] = "username",
785 password[] = "password",
786 root[] = "/",
787 site_about[] = "/site/about",
788 extra_info[] = "?test=123",
789 about[] = "about",
790 blank[] = "blank",
791 host[] = "host";
793 /* test NULL lpUrlComponents */
794 SetLastError(0xdeadbeef);
795 ret = InternetCreateUrlA(NULL, 0, NULL, &len);
796 ok(!ret, "Expected failure\n");
797 ok(GetLastError() == ERROR_INVALID_PARAMETER,
798 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
799 ok(len == -1, "Expected len -1, got %d\n", len);
801 /* test zero'ed lpUrlComponents */
802 ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
803 SetLastError(0xdeadbeef);
804 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
805 ok(!ret, "Expected failure\n");
806 ok(GetLastError() == ERROR_INVALID_PARAMETER,
807 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
808 ok(len == -1, "Expected len -1, got %d\n", len);
810 /* test valid lpUrlComponents, NULL lpdwUrlLength */
811 fill_url_components(&urlComp);
812 SetLastError(0xdeadbeef);
813 ret = InternetCreateUrlA(&urlComp, 0, NULL, NULL);
814 ok(!ret, "Expected failure\n");
815 ok(GetLastError() == ERROR_INVALID_PARAMETER,
816 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
818 /* test valid lpUrlComponents, empty szUrl
819 * lpdwUrlLength is size of buffer required on exit, including
820 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
822 SetLastError(0xdeadbeef);
823 ret = InternetCreateUrlA(&urlComp, 0, NULL, &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);
829 /* test correct size, NULL szUrl */
830 fill_url_components(&urlComp);
831 SetLastError(0xdeadbeef);
832 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
833 ok(!ret, "Expected failure\n");
834 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
835 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
836 ok(len == 51, "Expected len 51, got %d\n", len);
838 /* test valid lpUrlComponents, alloc-ed szUrl, small size */
839 SetLastError(0xdeadbeef);
840 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
841 len -= 2;
842 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
843 ok(!ret, "Expected failure\n");
844 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
845 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
846 ok(len == 51, "Expected len 51, got %d\n", len);
848 /* alloc-ed szUrl, NULL lpszScheme
849 * shows that it uses nScheme instead
851 SetLastError(0xdeadbeef);
852 urlComp.lpszScheme = NULL;
853 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
854 ok(ret, "Expected success\n");
855 ok(GetLastError() == 0xdeadbeef,
856 "Expected 0xdeadbeef, got %d\n", GetLastError());
857 ok(len == 50, "Expected len 50, got %d\n", len);
858 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
860 /* alloc-ed szUrl, invalid nScheme
861 * any nScheme out of range seems ignored
863 fill_url_components(&urlComp);
864 SetLastError(0xdeadbeef);
865 urlComp.nScheme = -3;
866 len++;
867 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
868 ok(ret, "Expected success\n");
869 ok(GetLastError() == 0xdeadbeef,
870 "Expected 0xdeadbeef, got %d\n", GetLastError());
871 ok(len == 50, "Expected len 50, got %d\n", len);
873 /* test valid lpUrlComponents, alloc-ed szUrl */
874 fill_url_components(&urlComp);
875 SetLastError(0xdeadbeef);
876 len = 51;
877 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
878 ok(ret, "Expected success\n");
879 ok(GetLastError() == 0xdeadbeef,
880 "Expected 0xdeadbeef, got %d\n", GetLastError());
881 ok(len == 50, "Expected len 50, got %d\n", len);
882 ok(strstr(szUrl, "80") == NULL, "Didn't expect to find 80 in szUrl\n");
883 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
885 /* valid username, NULL password */
886 fill_url_components(&urlComp);
887 SetLastError(0xdeadbeef);
888 urlComp.lpszPassword = NULL;
889 len = 42;
890 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
891 ok(ret, "Expected success\n");
892 ok(GetLastError() == 0xdeadbeef,
893 "Expected 0xdeadbeef, got %d\n", GetLastError());
894 ok(len == 41, "Expected len 41, got %d\n", len);
895 ok(!strcmp(szUrl, CREATE_URL2), "Expected %s, got %s\n", CREATE_URL2, szUrl);
897 /* valid username, empty password */
898 fill_url_components(&urlComp);
899 SetLastError(0xdeadbeef);
900 urlComp.lpszPassword = empty;
901 len = 51;
902 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
903 ok(ret, "Expected success\n");
904 ok(GetLastError() == 0xdeadbeef,
905 "Expected 0xdeadbeef, got %d\n", GetLastError());
906 ok(len == 50, "Expected len 50, got %d\n", len);
907 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
909 /* valid password, NULL username
910 * if password is provided, username has to exist
912 fill_url_components(&urlComp);
913 SetLastError(0xdeadbeef);
914 urlComp.lpszUserName = NULL;
915 len = 42;
916 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
917 ok(!ret, "Expected failure\n");
918 ok(GetLastError() == ERROR_INVALID_PARAMETER,
919 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
920 ok(len == 42, "Expected len 42, got %d\n", len);
921 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
923 /* valid password, empty username
924 * if password is provided, username has to exist
926 fill_url_components(&urlComp);
927 SetLastError(0xdeadbeef);
928 urlComp.lpszUserName = empty;
929 len = 51;
930 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
931 ok(ret, "Expected success\n");
932 ok(GetLastError() == 0xdeadbeef,
933 "Expected 0xdeadbeef, got %d\n", GetLastError());
934 ok(len == 50, "Expected len 50, got %d\n", len);
935 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
937 /* NULL username, NULL password */
938 fill_url_components(&urlComp);
939 SetLastError(0xdeadbeef);
940 urlComp.lpszUserName = NULL;
941 urlComp.lpszPassword = NULL;
942 len = 42;
943 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
944 ok(ret, "Expected success\n");
945 ok(GetLastError() == 0xdeadbeef,
946 "Expected 0xdeadbeef, got %d\n", GetLastError());
947 ok(len == 32, "Expected len 32, got %d\n", len);
948 ok(!strcmp(szUrl, CREATE_URL4), "Expected %s, got %s\n", CREATE_URL4, szUrl);
950 /* empty username, empty password */
951 fill_url_components(&urlComp);
952 SetLastError(0xdeadbeef);
953 urlComp.lpszUserName = empty;
954 urlComp.lpszPassword = empty;
955 len = 51;
956 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
957 ok(ret, "Expected success\n");
958 ok(GetLastError() == 0xdeadbeef,
959 "Expected 0xdeadbeef, got %d\n", GetLastError());
960 ok(len == 50, "Expected len 50, got %d\n", len);
961 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
963 /* shows that nScheme is ignored, as the appearance of the port number
964 * depends on lpszScheme and the string copied depends on lpszScheme.
966 fill_url_components(&urlComp);
967 HeapFree(GetProcessHeap(), 0, szUrl);
968 urlComp.lpszScheme = nhttp;
969 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
970 len = strlen(CREATE_URL6) + 1;
971 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
972 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
973 ok(ret, "Expected success\n");
974 ok(len == strlen(CREATE_URL6), "Expected len %d, got %d\n", lstrlenA(CREATE_URL6) + 1, len);
975 ok(!strcmp(szUrl, CREATE_URL6), "Expected %s, got %s\n", CREATE_URL6, szUrl);
977 /* if lpszScheme != "http" or nPort != 80, display nPort */
978 HeapFree(GetProcessHeap(), 0, szUrl);
979 urlComp.lpszScheme = http;
980 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
981 urlComp.nPort = 42;
982 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
983 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
984 ok(ret, "Expected success\n");
985 ok(len == 53, "Expected len 53, got %d\n", len);
986 ok(strstr(szUrl, "42") != NULL, "Expected to find 42 in szUrl\n");
987 ok(!strcmp(szUrl, CREATE_URL7), "Expected %s, got %s\n", CREATE_URL7, szUrl);
989 HeapFree(GetProcessHeap(), 0, szUrl);
991 memset(&urlComp, 0, sizeof(urlComp));
992 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
993 urlComp.lpszScheme = http;
994 urlComp.dwSchemeLength = 0;
995 urlComp.nScheme = INTERNET_SCHEME_HTTP;
996 urlComp.lpszHostName = winehq;
997 urlComp.dwHostNameLength = 0;
998 urlComp.nPort = 80;
999 urlComp.lpszUserName = username;
1000 urlComp.dwUserNameLength = 0;
1001 urlComp.lpszPassword = password;
1002 urlComp.dwPasswordLength = 0;
1003 urlComp.lpszUrlPath = site_about;
1004 urlComp.dwUrlPathLength = 0;
1005 urlComp.lpszExtraInfo = empty;
1006 urlComp.dwExtraInfoLength = 0;
1007 len = strlen(CREATE_URL1);
1008 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1009 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1010 ok(ret, "Expected success\n");
1011 ok(len == strlen(CREATE_URL1), "Expected len %d, got %d\n", lstrlenA(CREATE_URL1), len);
1012 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
1014 HeapFree(GetProcessHeap(), 0, szUrl);
1016 memset(&urlComp, 0, sizeof(urlComp));
1017 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1018 urlComp.lpszScheme = https;
1019 urlComp.dwSchemeLength = 0;
1020 urlComp.nScheme = INTERNET_SCHEME_HTTP;
1021 urlComp.lpszHostName = winehq;
1022 urlComp.dwHostNameLength = 0;
1023 urlComp.nPort = 443;
1024 urlComp.lpszUserName = username;
1025 urlComp.dwUserNameLength = 0;
1026 urlComp.lpszPassword = password;
1027 urlComp.dwPasswordLength = 0;
1028 urlComp.lpszUrlPath = site_about;
1029 urlComp.dwUrlPathLength = 0;
1030 urlComp.lpszExtraInfo = empty;
1031 urlComp.dwExtraInfoLength = 0;
1032 len = strlen(CREATE_URL8);
1033 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1034 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1035 ok(ret, "Expected success\n");
1036 ok(len == strlen(CREATE_URL8), "Expected len %d, got %d\n", lstrlenA(CREATE_URL8), len);
1037 ok(!strcmp(szUrl, CREATE_URL8), "Expected %s, got %s\n", CREATE_URL8, szUrl);
1039 HeapFree(GetProcessHeap(), 0, szUrl);
1041 memset(&urlComp, 0, sizeof(urlComp));
1042 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1043 urlComp.lpszScheme = about;
1044 urlComp.dwSchemeLength = 5;
1045 urlComp.lpszUrlPath = blank;
1046 urlComp.dwUrlPathLength = 5;
1047 len = strlen(CREATE_URL9);
1048 len++; /* work around bug in native wininet */
1049 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1050 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1051 ok(ret, "Expected success\n");
1052 ok(len == strlen(CREATE_URL9), "Expected len %d, got %d\n", lstrlenA(CREATE_URL9), len);
1053 ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
1055 HeapFree(GetProcessHeap(), 0, szUrl);
1057 memset(&urlComp, 0, sizeof(urlComp));
1058 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1059 urlComp.lpszScheme = about;
1060 urlComp.lpszHostName = host;
1061 urlComp.lpszUrlPath = blank;
1062 len = strlen(CREATE_URL10);
1063 len++; /* work around bug in native wininet */
1064 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1065 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1066 ok(ret, "Expected success\n");
1067 ok(len == strlen(CREATE_URL10), "Expected len %d, got %d\n", lstrlenA(CREATE_URL10), len);
1068 ok(!strcmp(szUrl, CREATE_URL10), "Expected %s, got %s\n", CREATE_URL10, szUrl);
1070 HeapFree(GetProcessHeap(), 0, szUrl);
1072 memset(&urlComp, 0, sizeof(urlComp));
1073 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1074 urlComp.nPort = 8080;
1075 urlComp.lpszScheme = about;
1076 len = strlen(CREATE_URL11);
1077 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1078 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1079 ok(ret, "Expected success\n");
1080 ok(len == strlen(CREATE_URL11), "Expected len %d, got %d\n", lstrlenA(CREATE_URL11), len);
1081 ok(!strcmp(szUrl, CREATE_URL11), "Expected %s, got %s\n", CREATE_URL11, szUrl);
1083 HeapFree(GetProcessHeap(), 0, szUrl);
1085 memset(&urlComp, 0, sizeof(urlComp));
1086 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1087 urlComp.lpszScheme = http;
1088 urlComp.dwSchemeLength = 0;
1089 urlComp.nScheme = INTERNET_SCHEME_HTTP;
1090 urlComp.lpszHostName = winehq;
1091 urlComp.dwHostNameLength = 0;
1092 urlComp.nPort = 65535;
1093 len = strlen(CREATE_URL12);
1094 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1095 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1096 ok(ret, "Expected success\n");
1097 ok(len == strlen(CREATE_URL12), "Expected len %d, got %d\n", lstrlenA(CREATE_URL12), len);
1098 ok(!strcmp(szUrl, CREATE_URL12), "Expected %s, got %s\n", CREATE_URL12, szUrl);
1100 HeapFree(GetProcessHeap(), 0, szUrl);
1102 memset(&urlComp, 0, sizeof(urlComp));
1103 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1104 urlComp.lpszScheme = http;
1105 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
1106 urlComp.lpszHostName = localhost;
1107 urlComp.dwHostNameLength = strlen(urlComp.lpszHostName);
1108 urlComp.nPort = 80;
1109 urlComp.lpszUrlPath = root;
1110 urlComp.dwUrlPathLength = strlen(urlComp.lpszUrlPath);
1111 urlComp.lpszExtraInfo = extra_info;
1112 urlComp.dwExtraInfoLength = strlen(urlComp.lpszExtraInfo);
1113 len = 256;
1114 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
1115 InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1116 ok(ret, "Expected success\n");
1117 ok(len == strlen(CREATE_URL13), "Got len %u\n", len);
1118 ok(!strcmp(szUrl, CREATE_URL13), "Expected \"%s\", got \"%s\"\n", CREATE_URL13, szUrl);
1120 HeapFree(GetProcessHeap(), 0, szUrl);
1123 static void InternetCanonicalizeUrl_test(void)
1125 char src[] = "http://www.winehq.org/%27/ /./>/#> ";
1126 char dst[64];
1127 DWORD dstlen;
1129 dstlen = sizeof(dst);
1130 InternetCanonicalizeUrlA(src, dst, &dstlen, 0);
1131 ok(strcmp(dst, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1133 /* despite what MSDN says, ICU_BROWSER_MODE seems to be ignored */
1134 dstlen = sizeof(dst);
1135 InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_BROWSER_MODE);
1136 ok(strcmp(dst, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1138 /* ICU_ESCAPE is supposed to be ignored */
1139 dstlen = sizeof(dst);
1140 InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_ESCAPE);
1141 ok(strcmp(dst, "http://www.winehq.org/%27/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1143 dstlen = sizeof(dst);
1144 InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_DECODE);
1145 ok(strcmp(dst, "http://www.winehq.org/'/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1147 dstlen = sizeof(dst);
1148 InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_ENCODE_PERCENT);
1149 ok(strcmp(dst, "http://www.winehq.org/%2527/%20/%3E/#>") == 0, "Got \"%s\"\n", dst);
1151 dstlen = sizeof(dst);
1152 InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_ENCODE_SPACES_ONLY);
1153 ok(strcmp(dst, "http://www.winehq.org/%27/%20/>/#>") == 0, "Got \"%s\"\n", dst);
1155 dstlen = sizeof(dst);
1156 InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_NO_ENCODE);
1157 ok(strcmp(dst, "http://www.winehq.org/%27/ />/#>") == 0, "Got \"%s\"\n", dst);
1159 dstlen = sizeof(dst);
1160 InternetCanonicalizeUrlA(src, dst, &dstlen, ICU_NO_META);
1161 ok(strcmp(dst, "http://www.winehq.org/%27/%20/./%3E/#>") == 0, "Got \"%s\"\n", dst);
1164 START_TEST(url)
1166 int i;
1168 if(!GetProcAddress(GetModuleHandleA("wininet.dll"), "InternetGetCookieExW")) {
1169 win_skip("Too old IE (older than 6.0)\n");
1170 return;
1173 for(i=0; i < sizeof(crack_url_tests)/sizeof(*crack_url_tests); i++)
1174 test_crack_url(crack_url_tests+i);
1176 InternetCrackUrl_test();
1177 InternetCrackUrlW_test();
1178 InternetCreateUrlA_test();
1179 InternetCanonicalizeUrl_test();