wnaspi32: Make winaspi.dll into a stand-alone 16-bit module.
[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 *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);
39
40 /* ############################### */
41
42 static void test_InternetCanonicalizeUrlA(void)
43 {
44     CHAR    buffer[256];
45     LPCSTR  url;
46     DWORD   urllen;
47     DWORD   dwSize;
48     DWORD   res;
49
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);
53
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));
62
63
64     /* buffer has no space for the terminating '\0' */
65     memset(buffer, '#', sizeof(buffer)-1);
66     buffer[sizeof(buffer)-1] = '\0';
67     dwSize = urllen;
68     SetLastError(0xdeadbeef);
69     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
70     /* dwSize is nr. of needed bytes with the terminating '\0' */
71     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
72         "got %u and %u with size %u for '%s' (%d)\n",
73         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
74
75     /* buffer has the required size */
76     memset(buffer, '#', sizeof(buffer)-1);
77     buffer[sizeof(buffer)-1] = '\0';
78     dwSize = urllen+1;
79     SetLastError(0xdeadbeef);
80     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
81     /* dwSize is nr. of copied bytes without the terminating '\0' */
82     ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
83         "got %u and %u with size %u for '%s' (%d)\n",
84         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
85
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);
95
96     /* buffer is larger as the required size */
97     memset(buffer, '#', sizeof(buffer)-1);
98     buffer[sizeof(buffer)-1] = '\0';
99     dwSize = urllen+2;
100     SetLastError(0xdeadbeef);
101     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
102     /* dwSize is nr. of copied bytes without the terminating '\0' */
103     ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
104         "got %u and %u with size %u for '%s' (%d)\n",
105         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
106
107
108     /* check NULL pointers */
109     memset(buffer, '#', urllen + 4);
110     buffer[urllen + 4] = '\0';
111     dwSize = urllen+1;
112     SetLastError(0xdeadbeef);
113     res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
114     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
115         "got %u and %u with size %u for '%s' (%d)\n",
116         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
117
118     memset(buffer, '#', urllen + 4);
119     buffer[urllen + 4] = '\0';
120     dwSize = urllen+1;
121     SetLastError(0xdeadbeef);
122     res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
123     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
124         "got %u and %u with size %u for '%s' (%d)\n",
125         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
126
127     memset(buffer, '#', urllen + 4);
128     buffer[urllen + 4] = '\0';
129     dwSize = urllen+1;
130     SetLastError(0xdeadbeef);
131     res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
132     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
133         "got %u and %u with size %u for '%s' (%d)\n",
134         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
135
136     /* test with trailing space */
137     dwSize = 256;
138     res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
139     ok(res == 1, "InternetCanonicalizeUrlA failed\n");
140     ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
141
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());
146 }
147
148 /* ############################### */
149
150 static void test_InternetQueryOptionA(void)
151 {
152   HINTERNET hinet,hurl;
153   DWORD len;
154   DWORD err;
155   static const char useragent[] = {"Wininet Test"};
156   char *buffer;
157   int retval;
158
159   hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
160   ok((hinet != 0x0),"InternetOpen Failed\n");
161
162   SetLastError(0xdeadbeef);
163   retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
164   err=GetLastError();
165   ok(retval == 0,"Got wrong return value %d\n",retval);
166   ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
167
168   SetLastError(0xdeadbeef);
169   len=strlen(useragent)+1;
170   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
171   err=GetLastError();
172   ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
173   ok(retval == 0,"Got wrong return value %d\n",retval);
174   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
175
176   SetLastError(0xdeadbeef);
177   len=strlen(useragent)+1;
178   buffer=HeapAlloc(GetProcessHeap(),0,len);
179   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
180   err=GetLastError();
181   ok(retval == 1,"Got wrong return value %d\n",retval);
182   if (retval)
183   {
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));
186   }
187   ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
188   HeapFree(GetProcessHeap(),0,buffer);
189
190   SetLastError(0xdeadbeef);
191   len=0;
192   buffer=HeapAlloc(GetProcessHeap(),0,100);
193   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
194   err=GetLastError();
195   ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
196   ok(!retval, "Got wrong return value %d\n", retval);
197   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
198   HeapFree(GetProcessHeap(),0,buffer);
199
200   hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
201
202   SetLastError(0xdeadbeef);
203   len=0;
204   retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
205   err=GetLastError();
206   ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
207   ok(retval == 0,"Got wrong return value %d\n",retval);
208   ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
209
210   InternetCloseHandle(hurl);
211   InternetCloseHandle(hinet);
212
213   hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
214   ok((hinet != 0x0),"InternetOpen Failed\n");
215
216   SetLastError(0xdeadbeef);
217   len=0;
218   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
219   err=GetLastError();
220   ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
221   ok(retval == 0,"Got wrong return value %d\n",retval);
222   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
223
224   InternetCloseHandle(hinet);
225
226   hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
227   ok((hinet != 0x0),"InternetOpen Failed\n");
228   SetLastError(0xdeadbeef);
229   len=0;
230   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
231   err=GetLastError();
232   todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
233   ok(retval == 0,"Got wrong return value %d\n",retval);
234   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
235
236   InternetCloseHandle(hinet);
237 }
238
239 static void test_get_cookie(void)
240 {
241   DWORD len;
242   BOOL ret;
243
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());
249 }
250
251
252 static void test_complicated_cookie(void)
253 {
254   DWORD len;
255   BOOL ret;
256
257   CHAR buffer[1024];
258
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");
263
264   /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
265   ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
266   ok(ret == TRUE,"InternetSetCookie failed\n");
267   ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
268   ok(ret == TRUE,"InternetSetCookie failed\n");
269   ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
270   ok(ret == TRUE,"InternetSetCookie failed\n");
271   ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
272   ok(ret == TRUE,"InternetSetCookie failed\n");
273   ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
274   ok(ret == TRUE,"InternetSetCookie failed\n");
275
276   len = 1024;
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");
285
286   len = 1024;
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");
295
296   len = 1024;
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");
305
306   len = 1024;
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");
315
316   len = 1024;
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");
325
326   len = 1024;
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");
335
336   len = 1024;
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");
345 }
346
347 static void test_null(void)
348 {
349   HINTERNET hi, hc;
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 };
355   WCHAR buffer[0x20];
356   BOOL r;
357   DWORD sz;
358
359   SetLastError(0xdeadbeef);
360   hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
361   if (hi == NULL && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
362   {
363     win_skip("Internet*W functions are not implemented\n");
364     return;
365   }
366   ok(hi != NULL, "open failed\n");
367
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");
371
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");
375
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");
379
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");
383
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");
388
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");
392
393   InternetCloseHandle(hi);
394
395   r = InternetSetCookieW(NULL, NULL, NULL);
396   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
397   ok(r == FALSE, "return wrong\n");
398
399   r = InternetSetCookieW(szServer, NULL, NULL);
400   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
401   ok(r == FALSE, "return wrong\n");
402
403   r = InternetSetCookieW(szUrl, szServer, NULL);
404   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
405   ok(r == FALSE, "return wrong\n");
406
407   r = InternetSetCookieW(szUrl, szServer, szServer);
408   ok(r == TRUE, "return wrong\n");
409
410   r = InternetSetCookieW(szUrl, NULL, szServer);
411   ok(r == TRUE, "return wrong\n");
412
413   r = InternetSetCookieW(szUrl, szServer, szEmpty);
414   ok(r == TRUE, "return wrong\n");
415
416   r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
417   ok(r == FALSE, "return wrong\n");
418
419   r = InternetSetCookieW(szServer, NULL, szServer);
420   todo_wine {
421   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
422   }
423   ok(r == FALSE, "return wrong\n");
424
425   sz = 0;
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");
430
431   r = InternetGetCookieW(szServer, NULL, NULL, &sz);
432   todo_wine {
433   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
434   }
435   ok( r == FALSE, "return wrong\n");
436
437   sz = 0;
438   r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
439   ok( r == FALSE, "return wrong\n");
440
441   sz = 0;
442   r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
443   ok( r == TRUE, "return wrong\n");
444
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);
447
448   sz = 0x20;
449   memset(buffer, 0, sizeof buffer);
450   r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
451   ok( r == TRUE, "return wrong\n");
452
453   /* sz == lstrlenW(buffer) only in XP SP1 */
454   ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
455
456   /* before XP SP2, buffer is "server; server" */
457   ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
458
459   sz = sizeof(buffer);
460   r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
461   ok(r == TRUE, "ret %d\n", r);
462 }
463
464 static void test_version(void)
465 {
466     INTERNET_VERSION_INFO version;
467     DWORD size;
468     BOOL res;
469
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);
475 }
476
477 static void InternetTimeFromSystemTimeA_test(void)
478 {
479     BOOL ret;
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";
483     DWORD error;
484
485     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
486     ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
487
488     ok( !memcmp( string, expect, sizeof(expect) ),
489         "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
490
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",
498         error );
499
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",
507         error );
508
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",
516         error );
517
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",
525         error );
526 }
527
528 static void InternetTimeFromSystemTimeW_test(void)
529 {
530     BOOL ret;
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 };
535     DWORD error;
536
537     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
538     ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
539
540     ok( !memcmp( string, expect, sizeof(expect) ),
541         "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
542
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",
550         error );
551
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",
559         error );
560
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",
568         error );
569
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",
577         error );
578 }
579
580 static void InternetTimeToSystemTimeA_test(void)
581 {
582     BOOL ret;
583     SYSTEMTIME time;
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";
587
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() );
592
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() );
597 }
598
599 static void InternetTimeToSystemTimeW_test(void)
600 {
601     BOOL ret;
602     SYSTEMTIME time;
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 };
609
610     ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
611     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
612
613     ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
614     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
615
616     ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
617     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
618
619     ret = pInternetTimeToSystemTimeW( string, &time, 0 );
620     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
621
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() );
626
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() );
631
632     ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
633     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
634 }
635
636 static void test_IsDomainLegalCookieDomainW(void)
637 {
638     BOOL ret;
639     DWORD error;
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};
651
652     SetLastError(0xdeadbeef);
653     ret = pIsDomainLegalCookieDomainW(NULL, NULL);
654     error = GetLastError();
655     if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
656     {
657         win_skip("IsDomainLegalCookieDomainW is not implemented\n");
658         return;
659     }
660     ok(!ret ||
661         broken(ret), /* IE6 */
662         "IsDomainLegalCookieDomainW succeeded\n");
663     ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
664
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);
670
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);
676
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);
684
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);
692
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);
700
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);
708
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);
714
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);
722
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);
730
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);
736
737     ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
738     ok(ret, "IsDomainLegalCookieDomainW failed\n");
739
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);
745
746     ret = pIsDomainLegalCookieDomainW(uk, co_uk);
747     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
748
749     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
750     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
751
752     ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
753     ok(ret, "IsDomainLegalCookieDomainW failed\n");
754
755     ret = pIsDomainLegalCookieDomainW(gmail_com, com);
756     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
757
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);
765
766     ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
767     ok(ret, "IsDomainLegalCookieDomainW failed\n");
768
769     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
770     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
771
772     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
773     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
774
775     ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
776     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
777
778     ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
779     ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
780 }
781
782 /* ############################### */
783
784 START_TEST(internet)
785 {
786     HMODULE hdll;
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);
795
796     test_InternetCanonicalizeUrlA();
797     test_InternetQueryOptionA();
798     test_get_cookie();
799     test_complicated_cookie();
800     test_version();
801     test_null();
802
803     if (!pInternetTimeFromSystemTimeA)
804         win_skip("skipping the InternetTime tests\n");
805     else
806     {
807         InternetTimeFromSystemTimeA_test();
808         InternetTimeFromSystemTimeW_test();
809         InternetTimeToSystemTimeA_test();
810         InternetTimeToSystemTimeW_test();
811     }
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");
818     else
819         test_IsDomainLegalCookieDomainW();
820 }