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 *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
31 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
32 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
33 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
34 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
36 /* ############################### */
38 static void test_InternetCanonicalizeUrlA(void)
46 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
47 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
48 urllen = lstrlenA(url);
50 memset(buffer, '#', sizeof(buffer)-1);
51 buffer[sizeof(buffer)-1] = '\0';
52 dwSize = 1; /* Acrobat Updater use this size */
53 SetLastError(0xdeadbeef);
54 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
55 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
56 "got %u and %u with size %u for '%s' (%d)\n",
57 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
60 /* buffer has no space for the terminating '\0' */
61 memset(buffer, '#', sizeof(buffer)-1);
62 buffer[sizeof(buffer)-1] = '\0';
64 SetLastError(0xdeadbeef);
65 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
66 /* dwSize is nr. of needed bytes with the terminating '\0' */
67 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
68 "got %u and %u with size %u for '%s' (%d)\n",
69 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
71 /* buffer has the required size */
72 memset(buffer, '#', sizeof(buffer)-1);
73 buffer[sizeof(buffer)-1] = '\0';
75 SetLastError(0xdeadbeef);
76 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
77 /* dwSize is nr. of copied bytes without the terminating '\0' */
78 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
79 "got %u and %u with size %u for '%s' (%d)\n",
80 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
82 memset(buffer, '#', sizeof(buffer)-1);
83 buffer[sizeof(buffer)-1] = '\0';
84 dwSize = sizeof(buffer);
85 SetLastError(0xdeadbeef);
86 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
87 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
88 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
89 todo_wine ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
90 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
92 /* buffer is larger as the required size */
93 memset(buffer, '#', sizeof(buffer)-1);
94 buffer[sizeof(buffer)-1] = '\0';
96 SetLastError(0xdeadbeef);
97 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
98 /* dwSize is nr. of copied bytes without the terminating '\0' */
99 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
100 "got %u and %u with size %u for '%s' (%d)\n",
101 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
104 /* check NULL pointers */
105 memset(buffer, '#', urllen + 4);
106 buffer[urllen + 4] = '\0';
108 SetLastError(0xdeadbeef);
109 res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
110 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
111 "got %u and %u with size %u for '%s' (%d)\n",
112 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
114 memset(buffer, '#', urllen + 4);
115 buffer[urllen + 4] = '\0';
117 SetLastError(0xdeadbeef);
118 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
119 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
120 "got %u and %u with size %u for '%s' (%d)\n",
121 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
123 memset(buffer, '#', urllen + 4);
124 buffer[urllen + 4] = '\0';
126 SetLastError(0xdeadbeef);
127 res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
128 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
129 "got %u and %u with size %u for '%s' (%d)\n",
130 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
132 /* test with trailing space */
134 res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
135 ok(res == 1, "InternetCanonicalizeUrlA failed\n");
136 ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
138 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
139 ok(!res, "InternetSetOptionA succeeded\n");
140 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
141 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
144 /* ############################### */
146 static void test_InternetQueryOptionA(void)
148 HINTERNET hinet,hurl;
151 static const char useragent[] = {"Wininet Test"};
155 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
156 ok((hinet != 0x0),"InternetOpen Failed\n");
158 SetLastError(0xdeadbeef);
159 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
161 ok(retval == 0,"Got wrong return value %d\n",retval);
162 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
164 SetLastError(0xdeadbeef);
165 len=strlen(useragent)+1;
166 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
168 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
169 ok(retval == 0,"Got wrong return value %d\n",retval);
170 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
172 SetLastError(0xdeadbeef);
173 len=strlen(useragent)+1;
174 buffer=HeapAlloc(GetProcessHeap(),0,len);
175 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
177 ok(retval == 1,"Got wrong return value %d\n",retval);
180 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
181 todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
183 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
184 HeapFree(GetProcessHeap(),0,buffer);
186 SetLastError(0xdeadbeef);
188 buffer=HeapAlloc(GetProcessHeap(),0,100);
189 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
191 ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
192 ok(!retval, "Got wrong return value %d\n", retval);
193 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
194 HeapFree(GetProcessHeap(),0,buffer);
196 hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
198 SetLastError(0xdeadbeef);
200 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
202 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
203 ok(retval == 0,"Got wrong return value %d\n",retval);
204 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
206 InternetCloseHandle(hurl);
207 InternetCloseHandle(hinet);
209 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
210 ok((hinet != 0x0),"InternetOpen Failed\n");
212 SetLastError(0xdeadbeef);
214 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
216 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
217 ok(retval == 0,"Got wrong return value %d\n",retval);
218 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
220 InternetCloseHandle(hinet);
222 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
223 ok((hinet != 0x0),"InternetOpen Failed\n");
224 SetLastError(0xdeadbeef);
226 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
228 todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
229 ok(retval == 0,"Got wrong return value %d\n",retval);
230 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
232 InternetCloseHandle(hinet);
235 static void test_get_cookie(void)
240 SetLastError(0xdeadbeef);
241 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
242 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
243 "InternetGetCookie should have failed with %s and error %d\n",
244 ret ? "TRUE" : "FALSE", GetLastError());
248 static void test_complicated_cookie(void)
255 ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
256 ok(ret == TRUE,"InternetSetCookie failed\n");
257 ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
258 ok(ret == TRUE,"InternetSetCookie failed\n");
260 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
261 ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
262 ok(ret == TRUE,"InternetSetCookie failed\n");
263 ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
264 ok(ret == TRUE,"InternetSetCookie failed\n");
265 ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
266 ok(ret == TRUE,"InternetSetCookie failed\n");
267 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
268 ok(ret == TRUE,"InternetSetCookie failed\n");
269 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
270 ok(ret == TRUE,"InternetSetCookie failed\n");
273 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
274 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
275 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
276 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
277 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
278 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
279 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
280 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
283 ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
284 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
285 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
286 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
287 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
288 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
289 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
290 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
293 ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
294 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
295 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
296 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
297 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
298 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
299 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
300 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
303 ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
304 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
305 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
306 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
307 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
308 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
309 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
310 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
313 ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
314 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
315 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
316 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
317 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
318 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
319 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
320 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
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");
333 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
334 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
335 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
336 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
337 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
338 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
339 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
340 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
343 static void test_null(void)
346 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
347 static const WCHAR szEmpty[] = { 0 };
348 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
349 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
350 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
355 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
356 ok(hi != NULL, "open failed\n");
358 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
359 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
360 ok(hc == NULL, "connect failed\n");
362 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
363 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
364 ok(hc == NULL, "connect failed\n");
366 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
367 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
368 ok(hc == NULL, "connect failed\n");
370 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
371 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
372 ok(hc == NULL, "connect failed\n");
374 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
375 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
376 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
377 ok(hc == NULL, "connect failed\n");
379 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
380 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
381 ok(hc == NULL, "connect failed\n");
383 InternetCloseHandle(hi);
385 r = InternetSetCookieW(NULL, NULL, NULL);
386 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
387 ok(r == FALSE, "return wrong\n");
389 r = InternetSetCookieW(szServer, NULL, NULL);
390 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
391 ok(r == FALSE, "return wrong\n");
393 r = InternetSetCookieW(szUrl, szServer, NULL);
394 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
395 ok(r == FALSE, "return wrong\n");
397 r = InternetSetCookieW(szUrl, szServer, szServer);
398 ok(r == TRUE, "return wrong\n");
400 r = InternetSetCookieW(szUrl, NULL, szServer);
401 ok(r == TRUE, "return wrong\n");
403 r = InternetSetCookieW(szUrl, szServer, szEmpty);
404 ok(r == TRUE, "return wrong\n");
406 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
407 ok(r == FALSE, "return wrong\n");
409 r = InternetSetCookieW(szServer, NULL, szServer);
411 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
413 ok(r == FALSE, "return wrong\n");
416 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
417 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
418 "wrong error %u\n", GetLastError());
419 ok( r == FALSE, "return wrong\n");
421 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
423 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
425 ok( r == FALSE, "return wrong\n");
428 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
429 ok( r == FALSE, "return wrong\n");
432 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
433 ok( r == TRUE, "return wrong\n");
435 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
436 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
439 memset(buffer, 0, sizeof buffer);
440 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
441 ok( r == TRUE, "return wrong\n");
443 /* sz == lstrlenW(buffer) only in XP SP1 */
444 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
446 /* before XP SP2, buffer is "server; server" */
447 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
450 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
451 ok(r == TRUE, "ret %d\n", r);
454 static void test_version(void)
456 INTERNET_VERSION_INFO version;
460 size = sizeof(version);
461 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
462 ok(res, "Could not get version: %u\n", GetLastError());
463 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
464 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
467 static void InternetTimeFromSystemTimeA_test(void)
470 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
471 char string[INTERNET_RFC1123_BUFSIZE];
472 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
475 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
476 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
478 ok( !memcmp( string, expect, sizeof(expect) ),
479 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
481 /* test NULL time parameter */
482 SetLastError(0xdeadbeef);
483 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
484 error = GetLastError();
485 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
486 ok( error == ERROR_INVALID_PARAMETER,
487 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
490 /* test NULL string parameter */
491 SetLastError(0xdeadbeef);
492 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
493 error = GetLastError();
494 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
495 ok( error == ERROR_INVALID_PARAMETER,
496 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
499 /* test invalid format parameter */
500 SetLastError(0xdeadbeef);
501 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
502 error = GetLastError();
503 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
504 ok( error == ERROR_INVALID_PARAMETER,
505 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
508 /* test too small buffer size */
509 SetLastError(0xdeadbeef);
510 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
511 error = GetLastError();
512 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
513 ok( error == ERROR_INSUFFICIENT_BUFFER,
514 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
518 static void InternetTimeFromSystemTimeW_test(void)
521 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
522 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
523 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
524 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
527 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
528 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
530 ok( !memcmp( string, expect, sizeof(expect) ),
531 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
533 /* test NULL time parameter */
534 SetLastError(0xdeadbeef);
535 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
536 error = GetLastError();
537 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
538 ok( error == ERROR_INVALID_PARAMETER,
539 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
542 /* test NULL string parameter */
543 SetLastError(0xdeadbeef);
544 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
545 error = GetLastError();
546 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
547 ok( error == ERROR_INVALID_PARAMETER,
548 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
551 /* test invalid format parameter */
552 SetLastError(0xdeadbeef);
553 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
554 error = GetLastError();
555 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
556 ok( error == ERROR_INVALID_PARAMETER,
557 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
560 /* test too small buffer size */
561 SetLastError(0xdeadbeef);
562 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
563 error = GetLastError();
564 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
565 ok( error == ERROR_INSUFFICIENT_BUFFER,
566 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
570 static void InternetTimeToSystemTimeA_test(void)
574 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
575 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
576 static const char string2[] = " fri 7 jan 2005 12 06 35";
578 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
579 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
580 ok( !memcmp( &time, &expect, sizeof(expect) ),
581 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
583 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
584 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
585 ok( !memcmp( &time, &expect, sizeof(expect) ),
586 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
589 static void InternetTimeToSystemTimeW_test(void)
593 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
594 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
595 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
596 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
597 '1','2',' ','0','6',' ','3','5',0 };
598 static const WCHAR string3[] = { 'F','r',0 };
600 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
601 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
603 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
604 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
606 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
607 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
609 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
610 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
612 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
613 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
614 ok( !memcmp( &time, &expect, sizeof(expect) ),
615 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
617 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
618 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
619 ok( !memcmp( &time, &expect, sizeof(expect) ),
620 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
622 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
623 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
626 static void test_IsDomainLegalCookieDomainW(void)
630 static const WCHAR empty[] = {0};
631 static const WCHAR dot[] = {'.',0};
632 static const WCHAR uk[] = {'u','k',0};
633 static const WCHAR com[] = {'c','o','m',0};
634 static const WCHAR dot_com[] = {'.','c','o','m',0};
635 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
636 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
637 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
638 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
639 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
640 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
642 SetLastError(0xdeadbeef);
643 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
644 error = GetLastError();
646 broken(ret), /* Win98, NT4, W2K, XP (some) */
647 "IsDomainLegalCookieDomainW succeeded\n");
648 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
650 SetLastError(0xdeadbeef);
651 ret = pIsDomainLegalCookieDomainW(com, NULL);
652 error = GetLastError();
653 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
654 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
656 SetLastError(0xdeadbeef);
657 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
658 error = GetLastError();
659 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
660 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
662 SetLastError(0xdeadbeef);
663 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
664 error = GetLastError();
665 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
666 ok(error == ERROR_INVALID_NAME ||
667 broken(error == ERROR_INVALID_PARAMETER), /* Win98, NT4, W2K, XP (some) */
668 "got %u expected ERROR_INVALID_NAME\n", error);
670 SetLastError(0xdeadbeef);
671 ret = pIsDomainLegalCookieDomainW(com, empty);
672 error = GetLastError();
673 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
674 ok(error == ERROR_INVALID_NAME ||
675 broken(error == ERROR_INVALID_PARAMETER), /* Win98, NT4, W2K, XP (some) */
676 "got %u expected ERROR_INVALID_NAME\n", error);
678 SetLastError(0xdeadbeef);
679 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
680 error = GetLastError();
681 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
682 ok(error == ERROR_INVALID_NAME ||
683 broken(error == 0xdeadbeef), /* Win98, NT4, W2K, XP (some) */
684 "got %u expected ERROR_INVALID_NAME\n", error);
686 SetLastError(0xdeadbeef);
687 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
688 error = GetLastError();
689 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
690 ok(error == ERROR_INVALID_NAME ||
691 broken(error == 0xdeadbeef), /* Win98, NT4, W2K, XP (some) */
692 "got %u expected ERROR_INVALID_NAME\n", error);
694 SetLastError(0xdeadbeef);
695 ret = pIsDomainLegalCookieDomainW(com, com);
696 error = GetLastError();
697 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
698 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
700 SetLastError(0xdeadbeef);
701 ret = pIsDomainLegalCookieDomainW(com, dot_com);
702 error = GetLastError();
703 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
704 ok(error == ERROR_INVALID_NAME ||
705 broken(error == 0xdeadbeef), /* Win98, NT4, W2K, XP (some) */
706 "got %u expected ERROR_INVALID_NAME\n", error);
708 SetLastError(0xdeadbeef);
709 ret = pIsDomainLegalCookieDomainW(dot_com, com);
710 error = GetLastError();
711 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
712 ok(error == ERROR_INVALID_NAME ||
713 broken(error == 0xdeadbeef), /* Win98, NT4, W2K, XP (some) */
714 "got %u expected ERROR_INVALID_NAME\n", error);
716 SetLastError(0xdeadbeef);
717 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
718 error = GetLastError();
719 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
720 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
722 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
723 ok(ret, "IsDomainLegalCookieDomainW failed\n");
725 SetLastError(0xdeadbeef);
726 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
727 error = GetLastError();
728 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
729 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
731 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
732 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
734 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
735 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
737 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
738 ok(ret, "IsDomainLegalCookieDomainW failed\n");
740 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
741 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
743 SetLastError(0xdeadbeef);
744 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
745 error = GetLastError();
746 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
747 ok(error == ERROR_INVALID_NAME ||
748 broken(error == 0xdeadbeef), /* Win98, NT4, W2K, XP (some) */
749 "got %u expected ERROR_INVALID_NAME\n", error);
751 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
752 ok(ret, "IsDomainLegalCookieDomainW failed\n");
754 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
755 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
757 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
758 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
760 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
761 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
763 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
764 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
767 /* ############################### */
772 hdll = GetModuleHandleA("wininet.dll");
773 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
774 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
775 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
776 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
777 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
779 test_InternetCanonicalizeUrlA();
780 test_InternetQueryOptionA();
782 test_complicated_cookie();
786 if (!pInternetTimeFromSystemTimeA)
787 skip("skipping the InternetTime tests\n");
790 InternetTimeFromSystemTimeA_test();
791 InternetTimeFromSystemTimeW_test();
792 InternetTimeToSystemTimeA_test();
793 InternetTimeToSystemTimeW_test();
795 if (!pIsDomainLegalCookieDomainW)
796 skip("skipping IsDomainLegalCookieDomainW tests\n");
798 test_IsDomainLegalCookieDomainW();