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
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)
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';
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';
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';
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';
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';
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';
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 */
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;
155 static const char useragent[] = {"Wininet Test"};
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);
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);
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);
181 ok(retval == 1,"Got wrong return value %d\n",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);
192 buffer=HeapAlloc(GetProcessHeap(),0,100);
193 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
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.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
202 SetLastError(0xdeadbeef);
204 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
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);
218 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
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);
230 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
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)
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)
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");
277 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
278 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
279 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
280 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
281 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
282 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
283 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
284 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
287 ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
288 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
289 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
290 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
291 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
292 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
293 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
294 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
297 ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
298 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
299 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
300 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
301 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
302 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
303 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
304 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
307 ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
308 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
309 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
310 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
311 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
312 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
313 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
314 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
317 ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
318 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
319 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
320 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
321 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
322 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
323 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
324 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
327 ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
328 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
329 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
330 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
331 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
332 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
333 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
334 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
337 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
338 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
339 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
340 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
341 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
342 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
343 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
344 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
347 static void test_null(void)
350 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
351 static const WCHAR szEmpty[] = { 0 };
352 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
353 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
354 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
359 SetLastError(0xdeadbeef);
360 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
361 if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
363 win_skip("Internet*W functions are not implemented\n");
366 ok(hi != NULL, "open failed\n");
368 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
369 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
370 ok(hc == NULL, "connect failed\n");
372 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
373 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
374 ok(hc == NULL, "connect failed\n");
376 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
377 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
378 ok(hc == NULL, "connect failed\n");
380 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
381 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
382 ok(hc == NULL, "connect failed\n");
384 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
385 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
386 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
387 ok(hc == NULL, "connect failed\n");
389 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
390 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
391 ok(hc == NULL, "connect failed\n");
393 InternetCloseHandle(hi);
395 r = InternetSetCookieW(NULL, NULL, NULL);
396 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
397 ok(r == FALSE, "return wrong\n");
399 r = InternetSetCookieW(szServer, NULL, NULL);
400 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
401 ok(r == FALSE, "return wrong\n");
403 r = InternetSetCookieW(szUrl, szServer, NULL);
404 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
405 ok(r == FALSE, "return wrong\n");
407 r = InternetSetCookieW(szUrl, szServer, szServer);
408 ok(r == TRUE, "return wrong\n");
410 r = InternetSetCookieW(szUrl, NULL, szServer);
411 ok(r == TRUE, "return wrong\n");
413 r = InternetSetCookieW(szUrl, szServer, szEmpty);
414 ok(r == TRUE, "return wrong\n");
416 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
417 ok(r == FALSE, "return wrong\n");
419 r = InternetSetCookieW(szServer, NULL, szServer);
421 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
423 ok(r == FALSE, "return wrong\n");
426 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
427 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
428 "wrong error %u\n", GetLastError());
429 ok( r == FALSE, "return wrong\n");
431 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
433 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
435 ok( r == FALSE, "return wrong\n");
438 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
439 ok( r == FALSE, "return wrong\n");
442 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
443 ok( r == TRUE, "return wrong\n");
445 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
446 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
449 memset(buffer, 0, sizeof buffer);
450 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
451 ok( r == TRUE, "return wrong\n");
453 /* sz == lstrlenW(buffer) only in XP SP1 */
454 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
456 /* before XP SP2, buffer is "server; server" */
457 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
460 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
461 ok(r == TRUE, "ret %d\n", r);
464 static void test_version(void)
466 INTERNET_VERSION_INFO version;
470 size = sizeof(version);
471 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
472 ok(res, "Could not get version: %u\n", GetLastError());
473 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
474 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
477 static void InternetTimeFromSystemTimeA_test(void)
480 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
481 char string[INTERNET_RFC1123_BUFSIZE];
482 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
485 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
486 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
488 ok( !memcmp( string, expect, sizeof(expect) ),
489 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
491 /* test NULL time parameter */
492 SetLastError(0xdeadbeef);
493 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
494 error = GetLastError();
495 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
496 ok( error == ERROR_INVALID_PARAMETER,
497 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
500 /* test NULL string parameter */
501 SetLastError(0xdeadbeef);
502 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, 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",
509 /* test invalid format parameter */
510 SetLastError(0xdeadbeef);
511 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, 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",
518 /* test too small buffer size */
519 SetLastError(0xdeadbeef);
520 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
521 error = GetLastError();
522 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
523 ok( error == ERROR_INSUFFICIENT_BUFFER,
524 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
528 static void InternetTimeFromSystemTimeW_test(void)
531 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
532 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
533 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
534 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
537 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
538 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
540 ok( !memcmp( string, expect, sizeof(expect) ),
541 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
543 /* test NULL time parameter */
544 SetLastError(0xdeadbeef);
545 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
546 error = GetLastError();
547 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
548 ok( error == ERROR_INVALID_PARAMETER,
549 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
552 /* test NULL string parameter */
553 SetLastError(0xdeadbeef);
554 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, 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",
561 /* test invalid format parameter */
562 SetLastError(0xdeadbeef);
563 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, 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",
570 /* test too small buffer size */
571 SetLastError(0xdeadbeef);
572 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
573 error = GetLastError();
574 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
575 ok( error == ERROR_INSUFFICIENT_BUFFER,
576 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
580 static void InternetTimeToSystemTimeA_test(void)
584 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
585 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
586 static const char string2[] = " fri 7 jan 2005 12 06 35";
588 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
589 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
590 ok( !memcmp( &time, &expect, sizeof(expect) ),
591 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
593 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
594 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
595 ok( !memcmp( &time, &expect, sizeof(expect) ),
596 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
599 static void InternetTimeToSystemTimeW_test(void)
603 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
604 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
605 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
606 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
607 '1','2',' ','0','6',' ','3','5',0 };
608 static const WCHAR string3[] = { 'F','r',0 };
610 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
611 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
613 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
614 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
616 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
617 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
619 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
620 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
622 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
623 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
624 ok( !memcmp( &time, &expect, sizeof(expect) ),
625 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
627 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
628 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
629 ok( !memcmp( &time, &expect, sizeof(expect) ),
630 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
632 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
633 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
636 static void test_IsDomainLegalCookieDomainW(void)
640 static const WCHAR empty[] = {0};
641 static const WCHAR dot[] = {'.',0};
642 static const WCHAR uk[] = {'u','k',0};
643 static const WCHAR com[] = {'c','o','m',0};
644 static const WCHAR dot_com[] = {'.','c','o','m',0};
645 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
646 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
647 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
648 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
649 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
650 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
652 SetLastError(0xdeadbeef);
653 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
654 error = GetLastError();
655 if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
657 win_skip("IsDomainLegalCookieDomainW is not implemented\n");
661 broken(ret), /* IE6 */
662 "IsDomainLegalCookieDomainW succeeded\n");
663 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
665 SetLastError(0xdeadbeef);
666 ret = pIsDomainLegalCookieDomainW(com, NULL);
667 error = GetLastError();
668 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
669 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
671 SetLastError(0xdeadbeef);
672 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
673 error = GetLastError();
674 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
675 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
677 SetLastError(0xdeadbeef);
678 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
679 error = GetLastError();
680 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
681 ok(error == ERROR_INVALID_NAME ||
682 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
683 "got %u expected ERROR_INVALID_NAME\n", error);
685 SetLastError(0xdeadbeef);
686 ret = pIsDomainLegalCookieDomainW(com, empty);
687 error = GetLastError();
688 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
689 ok(error == ERROR_INVALID_NAME ||
690 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
691 "got %u expected ERROR_INVALID_NAME\n", error);
693 SetLastError(0xdeadbeef);
694 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
695 error = GetLastError();
696 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
697 ok(error == ERROR_INVALID_NAME ||
698 broken(error == 0xdeadbeef), /* IE6 */
699 "got %u expected ERROR_INVALID_NAME\n", error);
701 SetLastError(0xdeadbeef);
702 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
703 error = GetLastError();
704 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
705 ok(error == ERROR_INVALID_NAME ||
706 broken(error == 0xdeadbeef), /* IE6 */
707 "got %u expected ERROR_INVALID_NAME\n", error);
709 SetLastError(0xdeadbeef);
710 ret = pIsDomainLegalCookieDomainW(com, com);
711 error = GetLastError();
712 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
713 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
715 SetLastError(0xdeadbeef);
716 ret = pIsDomainLegalCookieDomainW(com, dot_com);
717 error = GetLastError();
718 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
719 ok(error == ERROR_INVALID_NAME ||
720 broken(error == 0xdeadbeef), /* IE6 */
721 "got %u expected ERROR_INVALID_NAME\n", error);
723 SetLastError(0xdeadbeef);
724 ret = pIsDomainLegalCookieDomainW(dot_com, com);
725 error = GetLastError();
726 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
727 ok(error == ERROR_INVALID_NAME ||
728 broken(error == 0xdeadbeef), /* IE6 */
729 "got %u expected ERROR_INVALID_NAME\n", error);
731 SetLastError(0xdeadbeef);
732 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
733 error = GetLastError();
734 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
735 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
737 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
738 ok(ret, "IsDomainLegalCookieDomainW failed\n");
740 SetLastError(0xdeadbeef);
741 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
742 error = GetLastError();
743 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
744 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
746 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
747 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
749 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
750 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
752 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
753 ok(ret, "IsDomainLegalCookieDomainW failed\n");
755 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
756 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
758 SetLastError(0xdeadbeef);
759 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
760 error = GetLastError();
761 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
762 ok(error == ERROR_INVALID_NAME ||
763 broken(error == 0xdeadbeef), /* IE6 */
764 "got %u expected ERROR_INVALID_NAME\n", error);
766 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
767 ok(ret, "IsDomainLegalCookieDomainW failed\n");
769 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
770 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
772 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
773 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
775 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
776 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
778 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
779 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
782 /* ############################### */
787 hdll = GetModuleHandleA("wininet.dll");
788 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
789 pCreateUrlCacheContainerW = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerW");
790 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
791 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
792 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
793 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
794 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
796 test_InternetCanonicalizeUrlA();
797 test_InternetQueryOptionA();
799 test_complicated_cookie();
803 if (!pInternetTimeFromSystemTimeA)
804 win_skip("skipping the InternetTime tests\n");
807 InternetTimeFromSystemTimeA_test();
808 InternetTimeFromSystemTimeW_test();
809 InternetTimeToSystemTimeA_test();
810 InternetTimeToSystemTimeW_test();
812 if (pIsDomainLegalCookieDomainW &&
813 ((void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA ||
814 (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerW))
815 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
816 else if (!pIsDomainLegalCookieDomainW)
817 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
819 test_IsDomainLegalCookieDomainW();