gdi32/tests: Fix tests on NT4.
[wine] / dlls / wininet / tests / internet.c
1 /*
2  * Wininet - internet tests
3  *
4  * Copyright 2005 Vijay Kiran Kamuju
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wininet.h"
26 #include "winerror.h"
27
28 #include "wine/test.h"
29
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);
35
36 /* ############################### */
37
38 static void test_InternetCanonicalizeUrlA(void)
39 {
40     CHAR    buffer[256];
41     LPCSTR  url;
42     DWORD   urllen;
43     DWORD   dwSize;
44     DWORD   res;
45
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);
49
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));
58
59
60     /* buffer has no space for the terminating '\0' */
61     memset(buffer, '#', sizeof(buffer)-1);
62     buffer[sizeof(buffer)-1] = '\0';
63     dwSize = urllen;
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));
70
71     /* buffer has the required size */
72     memset(buffer, '#', sizeof(buffer)-1);
73     buffer[sizeof(buffer)-1] = '\0';
74     dwSize = urllen+1;
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));
81
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);
91
92     /* buffer is larger as the required size */
93     memset(buffer, '#', sizeof(buffer)-1);
94     buffer[sizeof(buffer)-1] = '\0';
95     dwSize = urllen+2;
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));
102
103
104     /* check NULL pointers */
105     memset(buffer, '#', urllen + 4);
106     buffer[urllen + 4] = '\0';
107     dwSize = urllen+1;
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));
113
114     memset(buffer, '#', urllen + 4);
115     buffer[urllen + 4] = '\0';
116     dwSize = urllen+1;
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));
122
123     memset(buffer, '#', urllen + 4);
124     buffer[urllen + 4] = '\0';
125     dwSize = urllen+1;
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));
131
132     /* test with trailing space */
133     dwSize = 256;
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);
137
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());
142 }
143
144 /* ############################### */
145
146 static void test_InternetQueryOptionA(void)
147 {
148   HINTERNET hinet,hurl;
149   DWORD len;
150   DWORD err;
151   static const char useragent[] = {"Wininet Test"};
152   char *buffer;
153   int retval;
154
155   hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
156   ok((hinet != 0x0),"InternetOpen Failed\n");
157
158   SetLastError(0xdeadbeef);
159   retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
160   err=GetLastError();
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);
163
164   SetLastError(0xdeadbeef);
165   len=strlen(useragent)+1;
166   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
167   err=GetLastError();
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);
171
172   SetLastError(0xdeadbeef);
173   len=strlen(useragent)+1;
174   buffer=HeapAlloc(GetProcessHeap(),0,len);
175   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
176   err=GetLastError();
177   ok(retval == 1,"Got wrong return value %d\n",retval);
178   if (retval)
179   {
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));
182   }
183   ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
184   HeapFree(GetProcessHeap(),0,buffer);
185
186   SetLastError(0xdeadbeef);
187   len=0;
188   buffer=HeapAlloc(GetProcessHeap(),0,100);
189   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
190   err=GetLastError();
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);
195
196   hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
197
198   SetLastError(0xdeadbeef);
199   len=0;
200   retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
201   err=GetLastError();
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);
205
206   InternetCloseHandle(hurl);
207   InternetCloseHandle(hinet);
208
209   hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
210   ok((hinet != 0x0),"InternetOpen Failed\n");
211
212   SetLastError(0xdeadbeef);
213   len=0;
214   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
215   err=GetLastError();
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);
219
220   InternetCloseHandle(hinet);
221
222   hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
223   ok((hinet != 0x0),"InternetOpen Failed\n");
224   SetLastError(0xdeadbeef);
225   len=0;
226   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
227   err=GetLastError();
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);
231
232   InternetCloseHandle(hinet);
233 }
234
235 static void test_get_cookie(void)
236 {
237   DWORD len;
238   BOOL ret;
239
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());
245 }
246
247
248 static void test_complicated_cookie(void)
249 {
250   DWORD len;
251   BOOL ret;
252
253   CHAR buffer[1024];
254
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");
259
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");
271
272   len = 1024;
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");
281
282   len = 1024;
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");
291
292   len = 1024;
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");
301
302   len = 1024;
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");
311
312   len = 1024;
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");
321
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
332   len = 1024;
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");
341 }
342
343 static void test_null(void)
344 {
345   HINTERNET hi, hc;
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 };
351   WCHAR buffer[0x20];
352   BOOL r;
353   DWORD sz;
354
355   hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
356   ok(hi != NULL, "open failed\n");
357
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");
361
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");
365
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");
369
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");
373
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");
378
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");
382
383   InternetCloseHandle(hi);
384
385   r = InternetSetCookieW(NULL, NULL, NULL);
386   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
387   ok(r == FALSE, "return wrong\n");
388
389   r = InternetSetCookieW(szServer, NULL, NULL);
390   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
391   ok(r == FALSE, "return wrong\n");
392
393   r = InternetSetCookieW(szUrl, szServer, NULL);
394   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
395   ok(r == FALSE, "return wrong\n");
396
397   r = InternetSetCookieW(szUrl, szServer, szServer);
398   ok(r == TRUE, "return wrong\n");
399
400   r = InternetSetCookieW(szUrl, NULL, szServer);
401   ok(r == TRUE, "return wrong\n");
402
403   r = InternetSetCookieW(szUrl, szServer, szEmpty);
404   ok(r == TRUE, "return wrong\n");
405
406   r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
407   ok(r == FALSE, "return wrong\n");
408
409   r = InternetSetCookieW(szServer, NULL, szServer);
410   todo_wine {
411   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
412   }
413   ok(r == FALSE, "return wrong\n");
414
415   sz = 0;
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");
420
421   r = InternetGetCookieW(szServer, NULL, NULL, &sz);
422   todo_wine {
423   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
424   }
425   ok( r == FALSE, "return wrong\n");
426
427   sz = 0;
428   r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
429   ok( r == FALSE, "return wrong\n");
430
431   sz = 0;
432   r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
433   ok( r == TRUE, "return wrong\n");
434
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);
437
438   sz = 0x20;
439   memset(buffer, 0, sizeof buffer);
440   r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
441   ok( r == TRUE, "return wrong\n");
442
443   /* sz == lstrlenW(buffer) only in XP SP1 */
444   ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
445
446   /* before XP SP2, buffer is "server; server" */
447   ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
448
449   sz = sizeof(buffer);
450   r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
451   ok(r == TRUE, "ret %d\n", r);
452 }
453
454 static void test_version(void)
455 {
456     INTERNET_VERSION_INFO version;
457     DWORD size;
458     BOOL res;
459
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);
465 }
466
467 static void InternetTimeFromSystemTimeA_test(void)
468 {
469     BOOL ret;
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";
473     DWORD error;
474
475     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
476     ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
477
478     ok( !memcmp( string, expect, sizeof(expect) ),
479         "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
480
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",
488         error );
489
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",
497         error );
498
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",
506         error );
507
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",
515         error );
516 }
517
518 static void InternetTimeFromSystemTimeW_test(void)
519 {
520     BOOL ret;
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 };
525     DWORD error;
526
527     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
528     ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
529
530     ok( !memcmp( string, expect, sizeof(expect) ),
531         "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
532
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",
540         error );
541
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",
549         error );
550
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",
558         error );
559
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",
567         error );
568 }
569
570 static void InternetTimeToSystemTimeA_test(void)
571 {
572     BOOL ret;
573     SYSTEMTIME time;
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";
577
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() );
582
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() );
587 }
588
589 static void InternetTimeToSystemTimeW_test(void)
590 {
591     BOOL ret;
592     SYSTEMTIME time;
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 };
599
600     ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
601     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
602
603     ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
604     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
605
606     ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
607     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
608
609     ret = pInternetTimeToSystemTimeW( string, &time, 0 );
610     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
611
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() );
616
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() );
621
622     ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
623     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
624 }
625
626 static void test_IsDomainLegalCookieDomainW(void)
627 {
628     BOOL ret;
629     DWORD error;
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};
641
642     SetLastError(0xdeadbeef);
643     ret = pIsDomainLegalCookieDomainW(NULL, NULL);
644     error = GetLastError();
645     ok(!ret ||
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);
649
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);
655
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);
661
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);
669
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);
677
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);
685
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);
693
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);
699
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);
707
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);
715
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);
721
722     ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
723     ok(ret, "IsDomainLegalCookieDomainW failed\n");
724
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);
730
731     ret = pIsDomainLegalCookieDomainW(uk, co_uk);
732     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
733
734     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
735     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
736
737     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
738     ok(ret, "IsDomainLegalCookieDomainW failed\n");
739
740     ret = pIsDomainLegalCookieDomainW(gmail_com, com);
741     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
742
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);
750
751     ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
752     ok(ret, "IsDomainLegalCookieDomainW failed\n");
753
754     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
755     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
756
757     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
758     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
759
760     ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
761     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
762
763     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
764     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
765 }
766
767 /* ############################### */
768
769 START_TEST(internet)
770 {
771     HMODULE hdll;
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);
778
779     test_InternetCanonicalizeUrlA();
780     test_InternetQueryOptionA();
781     test_get_cookie();
782     test_complicated_cookie();
783     test_version();
784     test_null();
785
786     if (!pInternetTimeFromSystemTimeA)
787         skip("skipping the InternetTime tests\n");
788     else
789     {
790         InternetTimeFromSystemTimeA_test();
791         InternetTimeFromSystemTimeW_test();
792         InternetTimeToSystemTimeA_test();
793         InternetTimeToSystemTimeW_test();
794     }
795     if (!pIsDomainLegalCookieDomainW)
796         skip("skipping IsDomainLegalCookieDomainW tests\n");
797     else
798         test_IsDomainLegalCookieDomainW();
799 }