push 378fe7a60681a28e8b22f62dcfe122d585b92570
[wine/hacks.git] / dlls / wininet / tests / internet.c
blob13a5f5cbb80c4eff6fd6d8161e1e7a1c9f1fa2a3
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);
34 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
36 /* ############################### */
38 static void test_InternetCanonicalizeUrlA(void)
40 CHAR buffer[256];
41 LPCSTR url;
42 DWORD urllen;
43 DWORD dwSize;
44 DWORD res;
46 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
47 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
48 urllen = lstrlenA(url);
50 memset(buffer, '#', sizeof(buffer)-1);
51 buffer[sizeof(buffer)-1] = '\0';
52 dwSize = 1; /* Acrobat Updater use this size */
53 SetLastError(0xdeadbeef);
54 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
55 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
56 "got %u and %u with size %u for '%s' (%d)\n",
57 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
60 /* buffer has no space for the terminating '\0' */
61 memset(buffer, '#', sizeof(buffer)-1);
62 buffer[sizeof(buffer)-1] = '\0';
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));
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));
82 memset(buffer, '#', sizeof(buffer)-1);
83 buffer[sizeof(buffer)-1] = '\0';
84 dwSize = sizeof(buffer);
85 SetLastError(0xdeadbeef);
86 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
87 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
88 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
89 todo_wine ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
90 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
92 /* buffer is larger as the required size */
93 memset(buffer, '#', sizeof(buffer)-1);
94 buffer[sizeof(buffer)-1] = '\0';
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));
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));
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));
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));
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);
138 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
139 ok(!res, "InternetSetOptionA succeeded\n");
140 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
141 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
144 /* ############################### */
146 static void test_InternetQueryOptionA(void)
148 HINTERNET hinet,hurl;
149 DWORD len;
150 DWORD err;
151 static const char useragent[] = {"Wininet Test"};
152 char *buffer;
153 int retval;
155 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
156 ok((hinet != 0x0),"InternetOpen Failed\n");
158 SetLastError(0xdeadbeef);
159 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
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);
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);
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)
180 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
181 todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
183 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
184 HeapFree(GetProcessHeap(),0,buffer);
186 SetLastError(0xdeadbeef);
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);
196 hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
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);
206 InternetCloseHandle(hurl);
207 InternetCloseHandle(hinet);
209 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
210 ok((hinet != 0x0),"InternetOpen Failed\n");
212 SetLastError(0xdeadbeef);
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);
220 InternetCloseHandle(hinet);
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);
232 InternetCloseHandle(hinet);
235 static void test_get_cookie(void)
237 DWORD len;
238 BOOL ret;
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());
247 static void test_null(void)
249 HINTERNET hi, hc;
250 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
251 static const WCHAR szEmpty[] = { 0 };
252 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
253 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
254 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
255 WCHAR buffer[0x20];
256 BOOL r;
257 DWORD sz;
259 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
260 ok(hi != NULL, "open failed\n");
262 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
263 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
264 ok(hc == NULL, "connect failed\n");
266 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
267 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
268 ok(hc == NULL, "connect failed\n");
270 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
271 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
272 ok(hc == NULL, "connect failed\n");
274 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
275 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
276 ok(hc == NULL, "connect failed\n");
278 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
279 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
280 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
281 ok(hc == NULL, "connect failed\n");
283 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
284 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
285 ok(hc == NULL, "connect failed\n");
287 InternetCloseHandle(hi);
289 r = InternetSetCookieW(NULL, NULL, NULL);
290 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
291 ok(r == FALSE, "return wrong\n");
293 r = InternetSetCookieW(szServer, NULL, NULL);
294 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
295 ok(r == FALSE, "return wrong\n");
297 r = InternetSetCookieW(szUrl, szServer, NULL);
298 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
299 ok(r == FALSE, "return wrong\n");
301 r = InternetSetCookieW(szUrl, szServer, szServer);
302 ok(r == TRUE, "return wrong\n");
304 r = InternetSetCookieW(szUrl, NULL, szServer);
305 ok(r == TRUE, "return wrong\n");
307 r = InternetSetCookieW(szUrl, szServer, szEmpty);
308 ok(r == TRUE, "return wrong\n");
310 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
311 ok(r == FALSE, "return wrong\n");
313 r = InternetSetCookieW(szServer, NULL, szServer);
314 todo_wine {
315 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
317 ok(r == FALSE, "return wrong\n");
319 sz = 0;
320 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
321 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
322 "wrong error %u\n", GetLastError());
323 ok( r == FALSE, "return wrong\n");
325 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
326 todo_wine {
327 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
329 ok( r == FALSE, "return wrong\n");
331 sz = 0;
332 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
333 ok( r == FALSE, "return wrong\n");
335 sz = 0;
336 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
337 ok( r == TRUE, "return wrong\n");
339 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
340 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
342 sz = 0x20;
343 memset(buffer, 0, sizeof buffer);
344 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
345 ok( r == TRUE, "return wrong\n");
347 /* sz == lstrlenW(buffer) only in XP SP1 */
348 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
350 /* before XP SP2, buffer is "server; server" */
351 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
353 sz = sizeof(buffer);
354 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
355 ok(r == TRUE, "ret %d\n", r);
358 static void test_version(void)
360 INTERNET_VERSION_INFO version;
361 DWORD size;
362 BOOL res;
364 size = sizeof(version);
365 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
366 ok(res, "Could not get version: %u\n", GetLastError());
367 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
368 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
371 static void InternetTimeFromSystemTimeA_test(void)
373 BOOL ret;
374 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
375 char string[INTERNET_RFC1123_BUFSIZE];
376 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
377 DWORD error;
379 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
380 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
382 ok( !memcmp( string, expect, sizeof(expect) ),
383 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
385 /* test NULL time parameter */
386 SetLastError(0xdeadbeef);
387 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
388 error = GetLastError();
389 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
390 ok( error == ERROR_INVALID_PARAMETER,
391 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
392 error );
394 /* test NULL string parameter */
395 SetLastError(0xdeadbeef);
396 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
397 error = GetLastError();
398 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
399 ok( error == ERROR_INVALID_PARAMETER,
400 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
401 error );
403 /* test invalid format parameter */
404 SetLastError(0xdeadbeef);
405 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
406 error = GetLastError();
407 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
408 ok( error == ERROR_INVALID_PARAMETER,
409 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
410 error );
412 /* test too small buffer size */
413 SetLastError(0xdeadbeef);
414 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
415 error = GetLastError();
416 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
417 ok( error == ERROR_INSUFFICIENT_BUFFER,
418 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
419 error );
422 static void InternetTimeFromSystemTimeW_test(void)
424 BOOL ret;
425 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
426 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
427 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
428 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
429 DWORD error;
431 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
432 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
434 ok( !memcmp( string, expect, sizeof(expect) ),
435 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
437 /* test NULL time parameter */
438 SetLastError(0xdeadbeef);
439 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
440 error = GetLastError();
441 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
442 ok( error == ERROR_INVALID_PARAMETER,
443 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
444 error );
446 /* test NULL string parameter */
447 SetLastError(0xdeadbeef);
448 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
449 error = GetLastError();
450 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
451 ok( error == ERROR_INVALID_PARAMETER,
452 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
453 error );
455 /* test invalid format parameter */
456 SetLastError(0xdeadbeef);
457 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
458 error = GetLastError();
459 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
460 ok( error == ERROR_INVALID_PARAMETER,
461 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
462 error );
464 /* test too small buffer size */
465 SetLastError(0xdeadbeef);
466 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
467 error = GetLastError();
468 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
469 ok( error == ERROR_INSUFFICIENT_BUFFER,
470 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
471 error );
474 static void InternetTimeToSystemTimeA_test(void)
476 BOOL ret;
477 SYSTEMTIME time;
478 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
479 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
480 static const char string2[] = " fri 7 jan 2005 12 06 35";
482 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
483 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
484 ok( !memcmp( &time, &expect, sizeof(expect) ),
485 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
487 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
488 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
489 ok( !memcmp( &time, &expect, sizeof(expect) ),
490 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
493 static void InternetTimeToSystemTimeW_test(void)
495 BOOL ret;
496 SYSTEMTIME time;
497 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
498 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
499 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
500 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
501 '1','2',' ','0','6',' ','3','5',0 };
502 static const WCHAR string3[] = { 'F','r',0 };
504 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
505 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
507 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
508 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
510 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
511 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
513 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
514 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
516 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
517 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
518 ok( !memcmp( &time, &expect, sizeof(expect) ),
519 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
521 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
522 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
523 ok( !memcmp( &time, &expect, sizeof(expect) ),
524 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
526 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
527 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
530 static void test_IsDomainLegalCookieDomainW(void)
532 BOOL ret;
533 DWORD error;
534 static const WCHAR empty[] = {0};
535 static const WCHAR dot[] = {'.',0};
536 static const WCHAR uk[] = {'u','k',0};
537 static const WCHAR com[] = {'c','o','m',0};
538 static const WCHAR dot_com[] = {'.','c','o','m',0};
539 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
540 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
541 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
542 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
543 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
544 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
546 SetLastError(0xdeadbeef);
547 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
548 error = GetLastError();
549 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
550 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
552 SetLastError(0xdeadbeef);
553 ret = pIsDomainLegalCookieDomainW(com, NULL);
554 error = GetLastError();
555 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
556 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
558 SetLastError(0xdeadbeef);
559 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
560 error = GetLastError();
561 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
562 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
564 SetLastError(0xdeadbeef);
565 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
566 error = GetLastError();
567 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
568 ok(error == ERROR_INVALID_NAME, "got %u expected ERROR_INVALID_NAME\n", error);
570 SetLastError(0xdeadbeef);
571 ret = pIsDomainLegalCookieDomainW(com, empty);
572 error = GetLastError();
573 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
574 ok(error == ERROR_INVALID_NAME, "got %u expected ERROR_INVALID_NAME\n", error);
576 SetLastError(0xdeadbeef);
577 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
578 error = GetLastError();
579 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
580 ok(error == ERROR_INVALID_NAME, "got %u expected ERROR_INVALID_NAME\n", error);
582 SetLastError(0xdeadbeef);
583 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
584 error = GetLastError();
585 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
586 ok(error == ERROR_INVALID_NAME, "got %u expected ERROR_INVALID_NAME\n", error);
588 SetLastError(0xdeadbeef);
589 ret = pIsDomainLegalCookieDomainW(com, com);
590 error = GetLastError();
591 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
592 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
594 SetLastError(0xdeadbeef);
595 ret = pIsDomainLegalCookieDomainW(com, dot_com);
596 error = GetLastError();
597 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
598 ok(error == ERROR_INVALID_NAME, "got %u expected ERROR_INVALID_NAME\n", error);
600 SetLastError(0xdeadbeef);
601 ret = pIsDomainLegalCookieDomainW(dot_com, com);
602 error = GetLastError();
603 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
604 ok(error == ERROR_INVALID_NAME, "got %u expected ERROR_INVALID_NAME\n", error);
606 SetLastError(0xdeadbeef);
607 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
608 error = GetLastError();
609 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
610 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
612 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
613 ok(ret, "IsDomainLegalCookieDomainW failed\n");
615 SetLastError(0xdeadbeef);
616 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
617 error = GetLastError();
618 ok(!ret, "IsDomainLegalCookieDomainW failed\n");
619 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
621 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
622 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
624 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
625 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
627 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
628 ok(ret, "IsDomainLegalCookieDomainW failed\n");
630 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
631 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
633 SetLastError(0xdeadbeef);
634 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
635 error = GetLastError();
636 ok(!ret, "IsDomainLegalCookieDomainW failed\n");
637 ok(error == ERROR_INVALID_NAME, "got %u expected ERROR_INVALID_NAME\n", error);
639 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
640 ok(ret, "IsDomainLegalCookieDomainW failed\n");
642 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
643 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
645 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
646 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
648 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
649 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
651 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
652 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
655 /* ############################### */
657 START_TEST(internet)
659 HMODULE hdll;
660 hdll = GetModuleHandleA("wininet.dll");
661 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
662 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
663 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
664 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
665 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
667 test_InternetCanonicalizeUrlA();
668 test_InternetQueryOptionA();
669 test_get_cookie();
670 test_version();
671 test_null();
673 if (!pInternetTimeFromSystemTimeA)
674 skip("skipping the InternetTime tests\n");
675 else
677 InternetTimeFromSystemTimeA_test();
678 InternetTimeFromSystemTimeW_test();
679 InternetTimeToSystemTimeA_test();
680 InternetTimeToSystemTimeW_test();
682 if (!pIsDomainLegalCookieDomainW)
683 skip("skipping IsDomainLegalCookieDomainW tests\n");
684 else
685 test_IsDomainLegalCookieDomainW();