push 955563f995be8b0942dbb757ceb5b3a4c8ccafbf
[wine/hacks.git] / dlls / wininet / tests / internet.c
blob5f36c3d93547c4c359cb8dd7d0c1b6991c040f5a
1 /*
2 * Wininet - internet tests
4 * Copyright 2005 Vijay Kiran Kamuju
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wininet.h"
26 #include "winerror.h"
28 #include "wine/test.h"
30 static BOOL (WINAPI *pCreateUrlCacheContainerA)(DWORD, DWORD, DWORD, DWORD,
31 DWORD, DWORD, DWORD, DWORD);
32 static BOOL (WINAPI *pCreateUrlCacheContainerW)(DWORD, DWORD, DWORD, DWORD,
33 DWORD, DWORD, DWORD, DWORD);
34 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
35 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
36 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
37 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
38 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
40 /* ############################### */
42 static void test_InternetCanonicalizeUrlA(void)
44 CHAR buffer[256];
45 LPCSTR url;
46 DWORD urllen;
47 DWORD dwSize;
48 DWORD res;
50 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
51 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
52 urllen = lstrlenA(url);
54 memset(buffer, '#', sizeof(buffer)-1);
55 buffer[sizeof(buffer)-1] = '\0';
56 dwSize = 1; /* Acrobat Updater use this size */
57 SetLastError(0xdeadbeef);
58 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
59 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
60 "got %u and %u with size %u for '%s' (%d)\n",
61 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
64 /* buffer has no space for the terminating '\0' */
65 memset(buffer, '#', sizeof(buffer)-1);
66 buffer[sizeof(buffer)-1] = '\0';
67 dwSize = urllen;
68 SetLastError(0xdeadbeef);
69 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
70 /* dwSize is nr. of needed bytes with the terminating '\0' */
71 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
72 "got %u and %u with size %u for '%s' (%d)\n",
73 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
75 /* buffer has the required size */
76 memset(buffer, '#', sizeof(buffer)-1);
77 buffer[sizeof(buffer)-1] = '\0';
78 dwSize = urllen+1;
79 SetLastError(0xdeadbeef);
80 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
81 /* dwSize is nr. of copied bytes without the terminating '\0' */
82 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
83 "got %u and %u with size %u for '%s' (%d)\n",
84 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
86 memset(buffer, '#', sizeof(buffer)-1);
87 buffer[sizeof(buffer)-1] = '\0';
88 dwSize = sizeof(buffer);
89 SetLastError(0xdeadbeef);
90 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
91 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
92 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
93 todo_wine ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
94 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
96 /* buffer is larger as the required size */
97 memset(buffer, '#', sizeof(buffer)-1);
98 buffer[sizeof(buffer)-1] = '\0';
99 dwSize = urllen+2;
100 SetLastError(0xdeadbeef);
101 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
102 /* dwSize is nr. of copied bytes without the terminating '\0' */
103 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
104 "got %u and %u with size %u for '%s' (%d)\n",
105 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
108 /* check NULL pointers */
109 memset(buffer, '#', urllen + 4);
110 buffer[urllen + 4] = '\0';
111 dwSize = urllen+1;
112 SetLastError(0xdeadbeef);
113 res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
114 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
115 "got %u and %u with size %u for '%s' (%d)\n",
116 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
118 memset(buffer, '#', urllen + 4);
119 buffer[urllen + 4] = '\0';
120 dwSize = urllen+1;
121 SetLastError(0xdeadbeef);
122 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
123 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
124 "got %u and %u with size %u for '%s' (%d)\n",
125 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
127 memset(buffer, '#', urllen + 4);
128 buffer[urllen + 4] = '\0';
129 dwSize = urllen+1;
130 SetLastError(0xdeadbeef);
131 res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
132 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
133 "got %u and %u with size %u for '%s' (%d)\n",
134 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
136 /* test with trailing space */
137 dwSize = 256;
138 res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
139 ok(res == 1, "InternetCanonicalizeUrlA failed\n");
140 ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
142 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
143 ok(!res, "InternetSetOptionA succeeded\n");
144 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
145 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
148 /* ############################### */
150 static void test_InternetQueryOptionA(void)
152 HINTERNET hinet,hurl;
153 DWORD len;
154 DWORD err;
155 static const char useragent[] = {"Wininet Test"};
156 char *buffer;
157 int retval;
159 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
160 ok((hinet != 0x0),"InternetOpen Failed\n");
162 SetLastError(0xdeadbeef);
163 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
164 err=GetLastError();
165 ok(retval == 0,"Got wrong return value %d\n",retval);
166 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
168 SetLastError(0xdeadbeef);
169 len=strlen(useragent)+1;
170 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
171 err=GetLastError();
172 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
173 ok(retval == 0,"Got wrong return value %d\n",retval);
174 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
176 SetLastError(0xdeadbeef);
177 len=strlen(useragent)+1;
178 buffer=HeapAlloc(GetProcessHeap(),0,len);
179 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
180 err=GetLastError();
181 ok(retval == 1,"Got wrong return value %d\n",retval);
182 if (retval)
184 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
185 todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
187 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
188 HeapFree(GetProcessHeap(),0,buffer);
190 SetLastError(0xdeadbeef);
191 len=0;
192 buffer=HeapAlloc(GetProcessHeap(),0,100);
193 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
194 err=GetLastError();
195 ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
196 ok(!retval, "Got wrong return value %d\n", retval);
197 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
198 HeapFree(GetProcessHeap(),0,buffer);
200 hurl = InternetConnectA(hinet,"www.winehq.org",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
202 SetLastError(0xdeadbeef);
203 len=0;
204 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
205 err=GetLastError();
206 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
207 ok(retval == 0,"Got wrong return value %d\n",retval);
208 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
210 InternetCloseHandle(hurl);
211 InternetCloseHandle(hinet);
213 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
214 ok((hinet != 0x0),"InternetOpen Failed\n");
216 SetLastError(0xdeadbeef);
217 len=0;
218 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
219 err=GetLastError();
220 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
221 ok(retval == 0,"Got wrong return value %d\n",retval);
222 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
224 InternetCloseHandle(hinet);
226 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
227 ok((hinet != 0x0),"InternetOpen Failed\n");
228 SetLastError(0xdeadbeef);
229 len=0;
230 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
231 err=GetLastError();
232 todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
233 ok(retval == 0,"Got wrong return value %d\n",retval);
234 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
236 InternetCloseHandle(hinet);
239 static void test_get_cookie(void)
241 DWORD len;
242 BOOL ret;
244 SetLastError(0xdeadbeef);
245 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
246 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
247 "InternetGetCookie should have failed with %s and error %d\n",
248 ret ? "TRUE" : "FALSE", GetLastError());
252 static void test_complicated_cookie(void)
254 DWORD len;
255 BOOL ret;
257 CHAR buffer[1024];
259 ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
260 ok(ret == TRUE,"InternetSetCookie failed\n");
261 ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
262 ok(ret == TRUE,"InternetSetCookie failed\n");
264 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
265 ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
266 ok(ret == TRUE,"InternetSetCookie failed\n");
267 ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
268 ok(ret == TRUE,"InternetSetCookie failed\n");
269 ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
270 ok(ret == TRUE,"InternetSetCookie failed\n");
271 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
272 ok(ret == TRUE,"InternetSetCookie failed\n");
273 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
274 ok(ret == TRUE,"InternetSetCookie failed\n");
275 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar");
276 ok(ret == TRUE,"InternetSetCookie failed\n");
278 len = 1024;
279 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
280 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
281 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
282 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
283 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
284 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
285 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
286 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
287 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
289 len = 1024;
290 ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
291 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
292 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
293 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
294 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
295 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
296 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
297 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
298 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
300 len = 1024;
301 ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
302 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
303 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
304 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
305 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
306 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
307 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
308 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
309 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
311 len = 1024;
312 ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
313 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
314 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
315 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
316 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
317 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
318 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
319 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
320 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
322 len = 1024;
323 ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
324 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
325 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
326 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
327 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
328 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
329 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
330 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
331 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
333 len = 1024;
334 ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
335 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
336 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
337 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
338 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
339 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
340 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
341 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
342 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
344 len = 1024;
345 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
346 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
347 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
348 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
349 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
350 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
351 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
352 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
353 ok(strstr(buffer,"O=P")==NULL,"O=P present\n");
356 static void test_null(void)
358 HINTERNET hi, hc;
359 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
360 static const WCHAR szEmpty[] = { 0 };
361 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
362 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
363 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
364 WCHAR buffer[0x20];
365 BOOL r;
366 DWORD sz;
368 SetLastError(0xdeadbeef);
369 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
370 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
372 win_skip("Internet*W functions are not implemented\n");
373 return;
375 ok(hi != NULL, "open failed\n");
377 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
378 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
379 ok(hc == NULL, "connect failed\n");
381 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
382 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
383 ok(hc == NULL, "connect failed\n");
385 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
386 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
387 ok(hc == NULL, "connect failed\n");
389 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
390 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
391 ok(hc == NULL, "connect failed\n");
393 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
394 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
395 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
396 ok(hc == NULL, "connect failed\n");
398 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
399 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
400 ok(hc == NULL, "connect failed\n");
402 InternetCloseHandle(hi);
404 r = InternetSetCookieW(NULL, NULL, NULL);
405 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
406 ok(r == FALSE, "return wrong\n");
408 r = InternetSetCookieW(szServer, NULL, NULL);
409 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
410 ok(r == FALSE, "return wrong\n");
412 r = InternetSetCookieW(szUrl, szServer, NULL);
413 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
414 ok(r == FALSE, "return wrong\n");
416 r = InternetSetCookieW(szUrl, szServer, szServer);
417 ok(r == TRUE, "return wrong\n");
419 r = InternetSetCookieW(szUrl, NULL, szServer);
420 ok(r == TRUE, "return wrong\n");
422 r = InternetSetCookieW(szUrl, szServer, szEmpty);
423 ok(r == TRUE, "return wrong\n");
425 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
426 ok(r == FALSE, "return wrong\n");
428 r = InternetSetCookieW(szServer, NULL, szServer);
429 todo_wine {
430 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
432 ok(r == FALSE, "return wrong\n");
434 sz = 0;
435 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
436 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
437 "wrong error %u\n", GetLastError());
438 ok( r == FALSE, "return wrong\n");
440 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
441 todo_wine {
442 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
444 ok( r == FALSE, "return wrong\n");
446 sz = 0;
447 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
448 ok( r == FALSE, "return wrong\n");
450 sz = 0;
451 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
452 ok( r == TRUE, "return wrong\n");
454 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
455 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
457 sz = 0x20;
458 memset(buffer, 0, sizeof buffer);
459 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
460 ok( r == TRUE, "return wrong\n");
462 /* sz == lstrlenW(buffer) only in XP SP1 */
463 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
465 /* before XP SP2, buffer is "server; server" */
466 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
468 sz = sizeof(buffer);
469 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
470 ok(r == TRUE, "ret %d\n", r);
473 static void test_version(void)
475 INTERNET_VERSION_INFO version;
476 DWORD size;
477 BOOL res;
479 size = sizeof(version);
480 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
481 ok(res, "Could not get version: %u\n", GetLastError());
482 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
483 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
486 static void InternetTimeFromSystemTimeA_test(void)
488 BOOL ret;
489 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
490 char string[INTERNET_RFC1123_BUFSIZE];
491 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
492 DWORD error;
494 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
495 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
497 ok( !memcmp( string, expect, sizeof(expect) ),
498 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
500 /* test NULL time parameter */
501 SetLastError(0xdeadbeef);
502 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
503 error = GetLastError();
504 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
505 ok( error == ERROR_INVALID_PARAMETER,
506 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
507 error );
509 /* test NULL string parameter */
510 SetLastError(0xdeadbeef);
511 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
512 error = GetLastError();
513 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
514 ok( error == ERROR_INVALID_PARAMETER,
515 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
516 error );
518 /* test invalid format parameter */
519 SetLastError(0xdeadbeef);
520 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
521 error = GetLastError();
522 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
523 ok( error == ERROR_INVALID_PARAMETER,
524 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
525 error );
527 /* test too small buffer size */
528 SetLastError(0xdeadbeef);
529 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
530 error = GetLastError();
531 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
532 ok( error == ERROR_INSUFFICIENT_BUFFER,
533 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
534 error );
537 static void InternetTimeFromSystemTimeW_test(void)
539 BOOL ret;
540 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
541 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
542 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
543 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
544 DWORD error;
546 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
547 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
549 ok( !memcmp( string, expect, sizeof(expect) ),
550 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
552 /* test NULL time parameter */
553 SetLastError(0xdeadbeef);
554 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
555 error = GetLastError();
556 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
557 ok( error == ERROR_INVALID_PARAMETER,
558 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
559 error );
561 /* test NULL string parameter */
562 SetLastError(0xdeadbeef);
563 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
564 error = GetLastError();
565 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
566 ok( error == ERROR_INVALID_PARAMETER,
567 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
568 error );
570 /* test invalid format parameter */
571 SetLastError(0xdeadbeef);
572 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
573 error = GetLastError();
574 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
575 ok( error == ERROR_INVALID_PARAMETER,
576 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
577 error );
579 /* test too small buffer size */
580 SetLastError(0xdeadbeef);
581 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
582 error = GetLastError();
583 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
584 ok( error == ERROR_INSUFFICIENT_BUFFER,
585 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
586 error );
589 static void InternetTimeToSystemTimeA_test(void)
591 BOOL ret;
592 SYSTEMTIME time;
593 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
594 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
595 static const char string2[] = " fri 7 jan 2005 12 06 35";
597 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
598 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
599 ok( !memcmp( &time, &expect, sizeof(expect) ),
600 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
602 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
603 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
604 ok( !memcmp( &time, &expect, sizeof(expect) ),
605 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
608 static void InternetTimeToSystemTimeW_test(void)
610 BOOL ret;
611 SYSTEMTIME time;
612 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
613 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
614 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
615 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
616 '1','2',' ','0','6',' ','3','5',0 };
617 static const WCHAR string3[] = { 'F','r',0 };
619 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
620 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
622 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
623 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
625 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
626 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
628 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
629 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
631 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
632 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
633 ok( !memcmp( &time, &expect, sizeof(expect) ),
634 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
636 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
637 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
638 ok( !memcmp( &time, &expect, sizeof(expect) ),
639 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
641 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
642 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
645 static void test_IsDomainLegalCookieDomainW(void)
647 BOOL ret;
648 DWORD error;
649 static const WCHAR empty[] = {0};
650 static const WCHAR dot[] = {'.',0};
651 static const WCHAR uk[] = {'u','k',0};
652 static const WCHAR com[] = {'c','o','m',0};
653 static const WCHAR dot_com[] = {'.','c','o','m',0};
654 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
655 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
656 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
657 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
658 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
659 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
661 SetLastError(0xdeadbeef);
662 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
663 error = GetLastError();
664 if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
666 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
667 return;
669 ok(!ret ||
670 broken(ret), /* IE6 */
671 "IsDomainLegalCookieDomainW succeeded\n");
672 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
674 SetLastError(0xdeadbeef);
675 ret = pIsDomainLegalCookieDomainW(com, NULL);
676 error = GetLastError();
677 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
678 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
680 SetLastError(0xdeadbeef);
681 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
682 error = GetLastError();
683 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
684 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
686 SetLastError(0xdeadbeef);
687 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
688 error = GetLastError();
689 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
690 ok(error == ERROR_INVALID_NAME ||
691 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
692 "got %u expected ERROR_INVALID_NAME\n", error);
694 SetLastError(0xdeadbeef);
695 ret = pIsDomainLegalCookieDomainW(com, empty);
696 error = GetLastError();
697 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
698 ok(error == ERROR_INVALID_NAME ||
699 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
700 "got %u expected ERROR_INVALID_NAME\n", error);
702 SetLastError(0xdeadbeef);
703 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
704 error = GetLastError();
705 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
706 ok(error == ERROR_INVALID_NAME ||
707 broken(error == 0xdeadbeef), /* IE6 */
708 "got %u expected ERROR_INVALID_NAME\n", error);
710 SetLastError(0xdeadbeef);
711 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
712 error = GetLastError();
713 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
714 ok(error == ERROR_INVALID_NAME ||
715 broken(error == 0xdeadbeef), /* IE6 */
716 "got %u expected ERROR_INVALID_NAME\n", error);
718 SetLastError(0xdeadbeef);
719 ret = pIsDomainLegalCookieDomainW(com, com);
720 error = GetLastError();
721 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
722 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
724 SetLastError(0xdeadbeef);
725 ret = pIsDomainLegalCookieDomainW(com, dot_com);
726 error = GetLastError();
727 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
728 ok(error == ERROR_INVALID_NAME ||
729 broken(error == 0xdeadbeef), /* IE6 */
730 "got %u expected ERROR_INVALID_NAME\n", error);
732 SetLastError(0xdeadbeef);
733 ret = pIsDomainLegalCookieDomainW(dot_com, com);
734 error = GetLastError();
735 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
736 ok(error == ERROR_INVALID_NAME ||
737 broken(error == 0xdeadbeef), /* IE6 */
738 "got %u expected ERROR_INVALID_NAME\n", error);
740 SetLastError(0xdeadbeef);
741 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
742 error = GetLastError();
743 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
744 ok(error == ERROR_SXS_KEY_NOT_FOUND ||
745 error == ERROR_SUCCESS || /* IE8 on W2K3 */
746 error == 0xdeadbeef, /* up to IE7 */
747 "unexpected error: %u\n", error);
749 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
750 ok(ret, "IsDomainLegalCookieDomainW failed\n");
752 SetLastError(0xdeadbeef);
753 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
754 error = GetLastError();
755 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
756 ok(error == ERROR_SXS_KEY_NOT_FOUND || /* IE8 on XP */
757 error == ERROR_FILE_NOT_FOUND || /* IE8 on Vista */
758 error == ERROR_SUCCESS || /* IE8 on W2K3 */
759 error == 0xdeadbeef, /* up to IE7 */
760 "unexpected error: %u\n", error);
762 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
763 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
765 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
766 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
768 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
769 ok(ret, "IsDomainLegalCookieDomainW failed\n");
771 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
772 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
774 SetLastError(0xdeadbeef);
775 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
776 error = GetLastError();
777 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
778 ok(error == ERROR_INVALID_NAME ||
779 broken(error == 0xdeadbeef), /* IE6 */
780 "got %u expected ERROR_INVALID_NAME\n", error);
782 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
783 ok(ret, "IsDomainLegalCookieDomainW failed\n");
785 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
786 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
788 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
789 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
791 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
792 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
794 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
795 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
798 /* ############################### */
800 START_TEST(internet)
802 HMODULE hdll;
803 hdll = GetModuleHandleA("wininet.dll");
804 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
805 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
806 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
807 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
808 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
809 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
810 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
812 test_InternetCanonicalizeUrlA();
813 test_InternetQueryOptionA();
814 test_get_cookie();
815 test_complicated_cookie();
816 test_version();
817 test_null();
819 if (!pInternetTimeFromSystemTimeA)
820 win_skip("skipping the InternetTime tests\n");
821 else
823 InternetTimeFromSystemTimeA_test();
824 InternetTimeFromSystemTimeW_test();
825 InternetTimeToSystemTimeA_test();
826 InternetTimeToSystemTimeW_test();
828 if (pIsDomainLegalCookieDomainW &&
829 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
830 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
831 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
832 else if (!pIsDomainLegalCookieDomainW)
833 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
834 else
835 test_IsDomainLegalCookieDomainW();