wininet: Add tests for passing invalid parameters into InternetTimeFromSystemTimeA/W.
[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
35 /* ############################### */
36
37 static void test_InternetCanonicalizeUrlA(void)
38 {
39     CHAR    buffer[256];
40     LPCSTR  url;
41     DWORD   urllen;
42     DWORD   dwSize;
43     DWORD   res;
44
45     /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
46     url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
47     urllen = lstrlenA(url);
48
49     memset(buffer, '#', sizeof(buffer)-1);
50     buffer[sizeof(buffer)-1] = '\0';
51     dwSize = 1; /* Acrobat Updater use this size */
52     SetLastError(0xdeadbeef);
53     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
54     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
55         "got %u and %u with size %u for '%s' (%d)\n",
56         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
57
58
59     /* buffer has no space for the terminating '\0' */
60     memset(buffer, '#', sizeof(buffer)-1);
61     buffer[sizeof(buffer)-1] = '\0';
62     dwSize = urllen;
63     SetLastError(0xdeadbeef);
64     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
65     /* dwSize is nr. of needed bytes with the terminating '\0' */
66     ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
67         "got %u and %u with size %u for '%s' (%d)\n",
68         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
69
70     /* buffer has the required size */
71     memset(buffer, '#', sizeof(buffer)-1);
72     buffer[sizeof(buffer)-1] = '\0';
73     dwSize = urllen+1;
74     SetLastError(0xdeadbeef);
75     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
76     /* dwSize is nr. of copied bytes without the terminating '\0' */
77     ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
78         "got %u and %u with size %u for '%s' (%d)\n",
79         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
80
81     memset(buffer, '#', sizeof(buffer)-1);
82     buffer[sizeof(buffer)-1] = '\0';
83     dwSize = sizeof(buffer);
84     SetLastError(0xdeadbeef);
85     res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
86     ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
87     ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
88     todo_wine ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
89        "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
90
91     /* buffer is larger as the required size */
92     memset(buffer, '#', sizeof(buffer)-1);
93     buffer[sizeof(buffer)-1] = '\0';
94     dwSize = urllen+2;
95     SetLastError(0xdeadbeef);
96     res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
97     /* dwSize is nr. of copied bytes without the terminating '\0' */
98     ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
99         "got %u and %u with size %u for '%s' (%d)\n",
100         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
101
102
103     /* check NULL pointers */
104     memset(buffer, '#', urllen + 4);
105     buffer[urllen + 4] = '\0';
106     dwSize = urllen+1;
107     SetLastError(0xdeadbeef);
108     res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
109     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
110         "got %u and %u with size %u for '%s' (%d)\n",
111         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
112
113     memset(buffer, '#', urllen + 4);
114     buffer[urllen + 4] = '\0';
115     dwSize = urllen+1;
116     SetLastError(0xdeadbeef);
117     res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
118     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
119         "got %u and %u with size %u for '%s' (%d)\n",
120         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
121
122     memset(buffer, '#', urllen + 4);
123     buffer[urllen + 4] = '\0';
124     dwSize = urllen+1;
125     SetLastError(0xdeadbeef);
126     res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
127     ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
128         "got %u and %u with size %u for '%s' (%d)\n",
129         res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
130
131     /* test with trailing space */
132     dwSize = 256;
133     res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
134     ok(res == 1, "InternetCanonicalizeUrlA failed\n");
135     ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
136
137     res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
138     ok(!res, "InternetSetOptionA succeeded\n");
139     ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
140        "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
141 }
142
143 /* ############################### */
144
145 static void test_InternetQueryOptionA(void)
146 {
147   HINTERNET hinet,hurl;
148   DWORD len;
149   DWORD err;
150   static const char useragent[] = {"Wininet Test"};
151   char *buffer;
152   int retval;
153
154   hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
155   ok((hinet != 0x0),"InternetOpen Failed\n");
156
157   SetLastError(0xdeadbeef);
158   retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
159   err=GetLastError();
160   ok(retval == 0,"Got wrong return value %d\n",retval);
161   ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
162
163   SetLastError(0xdeadbeef);
164   len=strlen(useragent)+1;
165   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
166   err=GetLastError();
167   ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
168   ok(retval == 0,"Got wrong return value %d\n",retval);
169   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
170
171   SetLastError(0xdeadbeef);
172   len=strlen(useragent)+1;
173   buffer=HeapAlloc(GetProcessHeap(),0,len);
174   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
175   err=GetLastError();
176   ok(retval == 1,"Got wrong return value %d\n",retval);
177   if (retval)
178   {
179       ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
180       todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
181   }
182   ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
183   HeapFree(GetProcessHeap(),0,buffer);
184
185   SetLastError(0xdeadbeef);
186   len=0;
187   buffer=HeapAlloc(GetProcessHeap(),0,100);
188   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
189   err=GetLastError();
190   ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
191   ok(!retval, "Got wrong return value %d\n", retval);
192   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
193   HeapFree(GetProcessHeap(),0,buffer);
194
195   hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
196
197   SetLastError(0xdeadbeef);
198   len=0;
199   retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
200   err=GetLastError();
201   ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
202   ok(retval == 0,"Got wrong return value %d\n",retval);
203   ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
204
205   InternetCloseHandle(hurl);
206   InternetCloseHandle(hinet);
207
208   hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
209   ok((hinet != 0x0),"InternetOpen Failed\n");
210
211   SetLastError(0xdeadbeef);
212   len=0;
213   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
214   err=GetLastError();
215   ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
216   ok(retval == 0,"Got wrong return value %d\n",retval);
217   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
218
219   InternetCloseHandle(hinet);
220
221   hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
222   ok((hinet != 0x0),"InternetOpen Failed\n");
223   SetLastError(0xdeadbeef);
224   len=0;
225   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
226   err=GetLastError();
227   todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
228   ok(retval == 0,"Got wrong return value %d\n",retval);
229   ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
230
231   InternetCloseHandle(hinet);
232 }
233
234 static void test_get_cookie(void)
235 {
236   DWORD len;
237   BOOL ret;
238
239   SetLastError(0xdeadbeef);
240   ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
241   ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
242     "InternetGetCookie should have failed with %s and error %d\n",
243     ret ? "TRUE" : "FALSE", GetLastError());
244 }
245
246 static void test_null(void)
247 {
248   HINTERNET hi, hc;
249   static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
250   static const WCHAR szEmpty[] = { 0 };
251   static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
252   static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
253   static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
254   WCHAR buffer[0x20];
255   BOOL r;
256   DWORD sz;
257
258   hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
259   ok(hi != NULL, "open failed\n");
260
261   hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
262   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
263   ok(hc == NULL, "connect failed\n");
264
265   hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
266   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
267   ok(hc == NULL, "connect failed\n");
268
269   hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
270   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
271   ok(hc == NULL, "connect failed\n");
272
273   hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
274   ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
275   ok(hc == NULL, "connect failed\n");
276
277   hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
278   ok(GetLastError() == ERROR_INVALID_PARAMETER ||
279      GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
280   ok(hc == NULL, "connect failed\n");
281
282   hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
283   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
284   ok(hc == NULL, "connect failed\n");
285
286   InternetCloseHandle(hi);
287
288   r = InternetSetCookieW(NULL, NULL, NULL);
289   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
290   ok(r == FALSE, "return wrong\n");
291
292   r = InternetSetCookieW(szServer, NULL, NULL);
293   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
294   ok(r == FALSE, "return wrong\n");
295
296   r = InternetSetCookieW(szUrl, szServer, NULL);
297   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
298   ok(r == FALSE, "return wrong\n");
299
300   r = InternetSetCookieW(szUrl, szServer, szServer);
301   ok(r == TRUE, "return wrong\n");
302
303   r = InternetSetCookieW(szUrl, NULL, szServer);
304   ok(r == TRUE, "return wrong\n");
305
306   r = InternetSetCookieW(szUrl, szServer, szEmpty);
307   ok(r == TRUE, "return wrong\n");
308
309   r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
310   ok(r == FALSE, "return wrong\n");
311
312   r = InternetSetCookieW(szServer, NULL, szServer);
313   todo_wine {
314   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
315   }
316   ok(r == FALSE, "return wrong\n");
317
318   sz = 0;
319   r = InternetGetCookieW(NULL, NULL, NULL, &sz);
320   ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
321      "wrong error %u\n", GetLastError());
322   ok( r == FALSE, "return wrong\n");
323
324   r = InternetGetCookieW(szServer, NULL, NULL, &sz);
325   todo_wine {
326   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
327   }
328   ok( r == FALSE, "return wrong\n");
329
330   sz = 0;
331   r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
332   ok( r == FALSE, "return wrong\n");
333
334   sz = 0;
335   r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
336   ok( r == TRUE, "return wrong\n");
337
338   /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
339   ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
340
341   sz = 0x20;
342   memset(buffer, 0, sizeof buffer);
343   r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
344   ok( r == TRUE, "return wrong\n");
345
346   /* sz == lstrlenW(buffer) only in XP SP1 */
347   ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
348
349   /* before XP SP2, buffer is "server; server" */
350   ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
351
352   sz = sizeof(buffer);
353   r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
354   ok(r == TRUE, "ret %d\n", r);
355 }
356
357 static void test_version(void)
358 {
359     INTERNET_VERSION_INFO version;
360     DWORD size;
361     BOOL res;
362
363     size = sizeof(version);
364     res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
365     ok(res, "Could not get version: %u\n", GetLastError());
366     ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
367     ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
368 }
369
370 static void InternetTimeFromSystemTimeA_test(void)
371 {
372     BOOL ret;
373     static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
374     char string[INTERNET_RFC1123_BUFSIZE];
375     static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
376     DWORD error;
377
378     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
379     ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
380
381     ok( !memcmp( string, expect, sizeof(expect) ),
382         "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
383
384     /* test NULL time parameter */
385     SetLastError(0xdeadbeef);
386     ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
387     error = GetLastError();
388     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
389     todo_wine
390     ok( error == ERROR_INVALID_PARAMETER,
391         "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
392         error );
393
394     /* test NULL string parameter */
395     SetLastError(0xdeadbeef);
396     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
397     error = GetLastError();
398     todo_wine
399     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
400     ok( error == ERROR_INVALID_PARAMETER,
401         "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
402         error );
403
404     /* test invalid format parameter */
405     SetLastError(0xdeadbeef);
406     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
407     error = GetLastError();
408     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
409     todo_wine
410     ok( error == ERROR_INVALID_PARAMETER,
411         "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
412         error );
413
414     /* test too small buffer size */
415     SetLastError(0xdeadbeef);
416     ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
417     error = GetLastError();
418     ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
419     ok( error == ERROR_INSUFFICIENT_BUFFER,
420         "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
421         error );
422 }
423
424 static void InternetTimeFromSystemTimeW_test(void)
425 {
426     BOOL ret;
427     static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
428     WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
429     static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
430                                     '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
431     DWORD error;
432
433     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
434     ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
435
436     ok( !memcmp( string, expect, sizeof(expect) ),
437         "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
438
439     /* test NULL time parameter */
440     SetLastError(0xdeadbeef);
441     ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
442     error = GetLastError();
443     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
444     todo_wine
445     ok( error == ERROR_INVALID_PARAMETER,
446         "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
447         error );
448
449     /* test NULL string parameter */
450     SetLastError(0xdeadbeef);
451     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
452     error = GetLastError();
453     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
454     todo_wine
455     ok( error == ERROR_INVALID_PARAMETER,
456         "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
457         error );
458
459     /* test invalid format parameter */
460     SetLastError(0xdeadbeef);
461     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
462     error = GetLastError();
463     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
464     todo_wine
465     ok( error == ERROR_INVALID_PARAMETER,
466         "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
467         error );
468
469     /* test too small buffer size */
470     SetLastError(0xdeadbeef);
471     ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
472     error = GetLastError();
473     ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
474     ok( error == ERROR_INSUFFICIENT_BUFFER,
475         "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
476         error );
477 }
478
479 static void InternetTimeToSystemTimeA_test(void)
480 {
481     BOOL ret;
482     SYSTEMTIME time;
483     static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
484     static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
485     static const char string2[] = " fri 7 jan 2005 12 06 35";
486
487     ret = pInternetTimeToSystemTimeA( string, &time, 0 );
488     ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
489     ok( !memcmp( &time, &expect, sizeof(expect) ),
490         "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
491
492     ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
493     ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
494     ok( !memcmp( &time, &expect, sizeof(expect) ),
495         "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
496 }
497
498 static void InternetTimeToSystemTimeW_test(void)
499 {
500     BOOL ret;
501     SYSTEMTIME time;
502     static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
503     static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
504                                     '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
505     static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
506                                      '1','2',' ','0','6',' ','3','5',0 };
507     static const WCHAR string3[] = { 'F','r',0 };
508
509     ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
510     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
511
512     ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
513     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
514
515     ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
516     ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
517
518     ret = pInternetTimeToSystemTimeW( string, &time, 0 );
519     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
520
521     ret = pInternetTimeToSystemTimeW( string, &time, 0 );
522     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
523     ok( !memcmp( &time, &expect, sizeof(expect) ),
524         "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
525
526     ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
527     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
528     ok( !memcmp( &time, &expect, sizeof(expect) ),
529         "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
530
531     ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
532     ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
533 }
534
535 /* ############################### */
536
537 START_TEST(internet)
538 {
539     HMODULE hdll;
540     hdll = GetModuleHandleA("wininet.dll");
541     pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
542     pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
543     pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
544     pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
545
546     test_InternetCanonicalizeUrlA();
547     test_InternetQueryOptionA();
548     test_get_cookie();
549     test_version();
550     test_null();
551
552     if (!pInternetTimeFromSystemTimeA)
553         skip("skipping the InternetTime tests\n");
554     else
555     {
556         InternetTimeFromSystemTimeA_test();
557         InternetTimeFromSystemTimeW_test();
558         InternetTimeToSystemTimeA_test();
559         InternetTimeToSystemTimeW_test();
560     }
561 }