wininet: Quiet a noisy fixme.
[wine/multimedia.git] / dlls / wininet / tests / internet.c
blob5fbfd76864568719ac836cc916ac0a9380bfbb1f
1 /*
2 * Wininet - internet tests
4 * Copyright 2005 Vijay Kiran Kamuju
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wininet.h"
26 #include "winerror.h"
28 #include "wine/test.h"
30 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
31 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
32 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
33 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
35 /* ############################### */
37 static void test_InternetCanonicalizeUrlA(void)
39 CHAR buffer[256];
40 LPCSTR url;
41 DWORD urllen;
42 DWORD dwSize;
43 DWORD res;
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);
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));
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));
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));
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);
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));
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));
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));
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));
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);
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());
143 /* ############################### */
145 static void test_InternetQueryOptionA(void)
147 HINTERNET hinet,hurl;
148 DWORD len;
149 DWORD err;
150 static const char useragent[] = {"Wininet Test"};
151 char *buffer;
152 int retval;
154 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
155 ok((hinet != 0x0),"InternetOpen Failed\n");
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);
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);
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)
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));
182 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
183 HeapFree(GetProcessHeap(),0,buffer);
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);
195 hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
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);
205 InternetCloseHandle(hurl);
206 InternetCloseHandle(hinet);
208 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
209 ok((hinet != 0x0),"InternetOpen Failed\n");
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);
219 InternetCloseHandle(hinet);
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);
231 InternetCloseHandle(hinet);
234 static void test_get_cookie(void)
236 DWORD len;
237 BOOL ret;
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());
246 static void test_null(void)
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;
258 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
259 ok(hi != NULL, "open failed\n");
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");
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");
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");
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");
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");
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");
286 InternetCloseHandle(hi);
288 r = InternetSetCookieW(NULL, NULL, NULL);
289 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
290 ok(r == FALSE, "return wrong\n");
292 r = InternetSetCookieW(szServer, NULL, NULL);
293 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
294 ok(r == FALSE, "return wrong\n");
296 r = InternetSetCookieW(szUrl, szServer, NULL);
297 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
298 ok(r == FALSE, "return wrong\n");
300 r = InternetSetCookieW(szUrl, szServer, szServer);
301 ok(r == TRUE, "return wrong\n");
303 r = InternetSetCookieW(szUrl, NULL, szServer);
304 ok(r == TRUE, "return wrong\n");
306 r = InternetSetCookieW(szUrl, szServer, szEmpty);
307 ok(r == TRUE, "return wrong\n");
309 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
310 ok(r == FALSE, "return wrong\n");
312 r = InternetSetCookieW(szServer, NULL, szServer);
313 todo_wine {
314 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
316 ok(r == FALSE, "return wrong\n");
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");
324 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
325 todo_wine {
326 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
328 ok( r == FALSE, "return wrong\n");
330 sz = 0;
331 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
332 ok( r == FALSE, "return wrong\n");
334 sz = 0;
335 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
336 ok( r == TRUE, "return wrong\n");
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);
341 sz = 0x20;
342 memset(buffer, 0, sizeof buffer);
343 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
344 ok( r == TRUE, "return wrong\n");
346 /* sz == lstrlenW(buffer) only in XP SP1 */
347 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
349 /* before XP SP2, buffer is "server; server" */
350 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
352 sz = sizeof(buffer);
353 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
354 ok(r == TRUE, "ret %d\n", r);
357 static void test_version(void)
359 INTERNET_VERSION_INFO version;
360 DWORD size;
361 BOOL res;
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);
370 static void InternetTimeFromSystemTimeA_test(void)
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;
378 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
379 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
381 ok( !memcmp( string, expect, sizeof(expect) ),
382 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
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 ok( error == ERROR_INVALID_PARAMETER,
390 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
391 error );
393 /* test NULL string parameter */
394 SetLastError(0xdeadbeef);
395 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
396 error = GetLastError();
397 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
398 ok( error == ERROR_INVALID_PARAMETER,
399 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
400 error );
402 /* test invalid format parameter */
403 SetLastError(0xdeadbeef);
404 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
405 error = GetLastError();
406 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
407 ok( error == ERROR_INVALID_PARAMETER,
408 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
409 error );
411 /* test too small buffer size */
412 SetLastError(0xdeadbeef);
413 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
414 error = GetLastError();
415 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
416 ok( error == ERROR_INSUFFICIENT_BUFFER,
417 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
418 error );
421 static void InternetTimeFromSystemTimeW_test(void)
423 BOOL ret;
424 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
425 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
426 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
427 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
428 DWORD error;
430 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
431 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
433 ok( !memcmp( string, expect, sizeof(expect) ),
434 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
436 /* test NULL time parameter */
437 SetLastError(0xdeadbeef);
438 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
439 error = GetLastError();
440 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
441 ok( error == ERROR_INVALID_PARAMETER,
442 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
443 error );
445 /* test NULL string parameter */
446 SetLastError(0xdeadbeef);
447 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
448 error = GetLastError();
449 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
450 ok( error == ERROR_INVALID_PARAMETER,
451 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
452 error );
454 /* test invalid format parameter */
455 SetLastError(0xdeadbeef);
456 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
457 error = GetLastError();
458 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
459 ok( error == ERROR_INVALID_PARAMETER,
460 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
461 error );
463 /* test too small buffer size */
464 SetLastError(0xdeadbeef);
465 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
466 error = GetLastError();
467 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
468 ok( error == ERROR_INSUFFICIENT_BUFFER,
469 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
470 error );
473 static void InternetTimeToSystemTimeA_test(void)
475 BOOL ret;
476 SYSTEMTIME time;
477 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
478 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
479 static const char string2[] = " fri 7 jan 2005 12 06 35";
481 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
482 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
483 ok( !memcmp( &time, &expect, sizeof(expect) ),
484 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
486 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
487 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
488 ok( !memcmp( &time, &expect, sizeof(expect) ),
489 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
492 static void InternetTimeToSystemTimeW_test(void)
494 BOOL ret;
495 SYSTEMTIME time;
496 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
497 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
498 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
499 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
500 '1','2',' ','0','6',' ','3','5',0 };
501 static const WCHAR string3[] = { 'F','r',0 };
503 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
504 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
506 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
507 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
509 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
510 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
512 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
513 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
515 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
516 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
517 ok( !memcmp( &time, &expect, sizeof(expect) ),
518 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
520 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
521 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
522 ok( !memcmp( &time, &expect, sizeof(expect) ),
523 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
525 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
526 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
529 /* ############################### */
531 START_TEST(internet)
533 HMODULE hdll;
534 hdll = GetModuleHandleA("wininet.dll");
535 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
536 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
537 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
538 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
540 test_InternetCanonicalizeUrlA();
541 test_InternetQueryOptionA();
542 test_get_cookie();
543 test_version();
544 test_null();
546 if (!pInternetTimeFromSystemTimeA)
547 skip("skipping the InternetTime tests\n");
548 else
550 InternetTimeFromSystemTimeA_test();
551 InternetTimeFromSystemTimeW_test();
552 InternetTimeToSystemTimeA_test();
553 InternetTimeToSystemTimeW_test();