push eb25bf65c4616aa55a810ed5c29198b1a080b208
[wine/hacks.git] / dlls / wininet / tests / internet.c
blob56a604b176a05d44de16c5ed02b387be7dc6b8c5
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 *pCreateUrlCacheContainerA)(DWORD, DWORD, DWORD, DWORD,
31 DWORD, DWORD, DWORD, DWORD);
32 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
33 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
34 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
35 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
36 static BOOL (WINAPI *pIsDomainLegalCookieDomainW)(LPCWSTR, LPCWSTR);
38 /* ############################### */
40 static void test_InternetCanonicalizeUrlA(void)
42 CHAR buffer[256];
43 LPCSTR url;
44 DWORD urllen;
45 DWORD dwSize;
46 DWORD res;
48 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
49 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
50 urllen = lstrlenA(url);
52 memset(buffer, '#', sizeof(buffer)-1);
53 buffer[sizeof(buffer)-1] = '\0';
54 dwSize = 1; /* Acrobat Updater use this size */
55 SetLastError(0xdeadbeef);
56 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
57 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
58 "got %u and %u with size %u for '%s' (%d)\n",
59 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
62 /* buffer has no space for the terminating '\0' */
63 memset(buffer, '#', sizeof(buffer)-1);
64 buffer[sizeof(buffer)-1] = '\0';
65 dwSize = urllen;
66 SetLastError(0xdeadbeef);
67 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
68 /* dwSize is nr. of needed bytes with the terminating '\0' */
69 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
70 "got %u and %u with size %u for '%s' (%d)\n",
71 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
73 /* buffer has the required size */
74 memset(buffer, '#', sizeof(buffer)-1);
75 buffer[sizeof(buffer)-1] = '\0';
76 dwSize = urllen+1;
77 SetLastError(0xdeadbeef);
78 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
79 /* dwSize is nr. of copied bytes without the terminating '\0' */
80 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
81 "got %u and %u with size %u for '%s' (%d)\n",
82 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
84 memset(buffer, '#', sizeof(buffer)-1);
85 buffer[sizeof(buffer)-1] = '\0';
86 dwSize = sizeof(buffer);
87 SetLastError(0xdeadbeef);
88 res = InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer, &dwSize, ICU_DECODE | ICU_NO_ENCODE);
89 ok(res, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
90 ok(dwSize == lstrlenA(buffer), "got %d expected %d\n", dwSize, lstrlenA(buffer));
91 todo_wine ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer),
92 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer);
94 /* buffer is larger as the required size */
95 memset(buffer, '#', sizeof(buffer)-1);
96 buffer[sizeof(buffer)-1] = '\0';
97 dwSize = urllen+2;
98 SetLastError(0xdeadbeef);
99 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
100 /* dwSize is nr. of copied bytes without the terminating '\0' */
101 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
102 "got %u and %u with size %u for '%s' (%d)\n",
103 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
106 /* check NULL pointers */
107 memset(buffer, '#', urllen + 4);
108 buffer[urllen + 4] = '\0';
109 dwSize = urllen+1;
110 SetLastError(0xdeadbeef);
111 res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
112 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
113 "got %u and %u with size %u for '%s' (%d)\n",
114 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
116 memset(buffer, '#', urllen + 4);
117 buffer[urllen + 4] = '\0';
118 dwSize = urllen+1;
119 SetLastError(0xdeadbeef);
120 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
121 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
122 "got %u and %u with size %u for '%s' (%d)\n",
123 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
125 memset(buffer, '#', urllen + 4);
126 buffer[urllen + 4] = '\0';
127 dwSize = urllen+1;
128 SetLastError(0xdeadbeef);
129 res = InternetCanonicalizeUrlA(url, buffer, NULL, 0);
130 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
131 "got %u and %u with size %u for '%s' (%d)\n",
132 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
134 /* test with trailing space */
135 dwSize = 256;
136 res = InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer, &dwSize, ICU_BROWSER_MODE);
137 ok(res == 1, "InternetCanonicalizeUrlA failed\n");
138 ok(!strcmp(buffer, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer);
140 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
141 ok(!res, "InternetSetOptionA succeeded\n");
142 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
143 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
146 /* ############################### */
148 static void test_InternetQueryOptionA(void)
150 HINTERNET hinet,hurl;
151 DWORD len;
152 DWORD err;
153 static const char useragent[] = {"Wininet Test"};
154 char *buffer;
155 int retval;
157 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
158 ok((hinet != 0x0),"InternetOpen Failed\n");
160 SetLastError(0xdeadbeef);
161 retval=InternetQueryOptionA(NULL,INTERNET_OPTION_USER_AGENT,NULL,&len);
162 err=GetLastError();
163 ok(retval == 0,"Got wrong return value %d\n",retval);
164 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code%d\n",err);
166 SetLastError(0xdeadbeef);
167 len=strlen(useragent)+1;
168 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
169 err=GetLastError();
170 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
171 ok(retval == 0,"Got wrong return value %d\n",retval);
172 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n",err);
174 SetLastError(0xdeadbeef);
175 len=strlen(useragent)+1;
176 buffer=HeapAlloc(GetProcessHeap(),0,len);
177 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
178 err=GetLastError();
179 ok(retval == 1,"Got wrong return value %d\n",retval);
180 if (retval)
182 ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
183 todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
185 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
186 HeapFree(GetProcessHeap(),0,buffer);
188 SetLastError(0xdeadbeef);
189 len=0;
190 buffer=HeapAlloc(GetProcessHeap(),0,100);
191 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
192 err=GetLastError();
193 ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
194 ok(!retval, "Got wrong return value %d\n", retval);
195 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
196 HeapFree(GetProcessHeap(),0,buffer);
198 hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
200 SetLastError(0xdeadbeef);
201 len=0;
202 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
203 err=GetLastError();
204 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
205 ok(retval == 0,"Got wrong return value %d\n",retval);
206 ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
208 InternetCloseHandle(hurl);
209 InternetCloseHandle(hinet);
211 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
212 ok((hinet != 0x0),"InternetOpen Failed\n");
214 SetLastError(0xdeadbeef);
215 len=0;
216 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
217 err=GetLastError();
218 ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
219 ok(retval == 0,"Got wrong return value %d\n",retval);
220 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
222 InternetCloseHandle(hinet);
224 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
225 ok((hinet != 0x0),"InternetOpen Failed\n");
226 SetLastError(0xdeadbeef);
227 len=0;
228 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
229 err=GetLastError();
230 todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
231 ok(retval == 0,"Got wrong return value %d\n",retval);
232 ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
234 InternetCloseHandle(hinet);
237 static void test_get_cookie(void)
239 DWORD len;
240 BOOL ret;
242 SetLastError(0xdeadbeef);
243 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
244 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
245 "InternetGetCookie should have failed with %s and error %d\n",
246 ret ? "TRUE" : "FALSE", GetLastError());
250 static void test_complicated_cookie(void)
252 DWORD len;
253 BOOL ret;
255 CHAR buffer[1024];
257 ret = InternetSetCookie("http://www.example.com/bar",NULL,"A=B; domain=.example.com");
258 ok(ret == TRUE,"InternetSetCookie failed\n");
259 ret = InternetSetCookie("http://www.example.com/bar",NULL,"C=D; domain=.example.com; path=/");
260 ok(ret == TRUE,"InternetSetCookie failed\n");
262 /* Technically illegal! domain should require 2 dots, but native wininet accepts it */
263 ret = InternetSetCookie("http://www.example.com",NULL,"E=F; domain=example.com");
264 ok(ret == TRUE,"InternetSetCookie failed\n");
265 ret = InternetSetCookie("http://www.example.com",NULL,"G=H; domain=.example.com; path=/foo");
266 ok(ret == TRUE,"InternetSetCookie failed\n");
267 ret = InternetSetCookie("http://www.example.com/bar.html",NULL,"I=J; domain=.example.com");
268 ok(ret == TRUE,"InternetSetCookie failed\n");
269 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"K=L; domain=.example.com");
270 ok(ret == TRUE,"InternetSetCookie failed\n");
271 ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/");
272 ok(ret == TRUE,"InternetSetCookie failed\n");
274 len = 1024;
275 ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len);
276 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
277 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
278 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
279 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
280 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
281 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
282 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
284 len = 1024;
285 ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len);
286 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
287 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
288 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
289 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
290 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
291 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
292 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
294 len = 1024;
295 ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len);
296 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
297 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
298 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
299 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
300 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
301 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
302 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
304 len = 1024;
305 ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len);
306 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
307 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
308 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
309 ok(strstr(buffer,"G=H")!=NULL,"G=H missing\n");
310 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
311 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
312 ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n");
314 len = 1024;
315 ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len);
316 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
317 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
318 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
319 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
320 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
321 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
322 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
324 len = 1024;
325 ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len);
326 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
327 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
328 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
329 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
330 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
331 ok(strstr(buffer,"K=L")==NULL,"K=L present\n");
332 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
334 len = 1024;
335 ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len);
336 ok(strstr(buffer,"A=B")!=NULL,"A=B missing\n");
337 ok(strstr(buffer,"C=D")!=NULL,"C=D missing\n");
338 ok(strstr(buffer,"E=F")!=NULL,"E=F missing\n");
339 ok(strstr(buffer,"G=H")==NULL,"G=H present\n");
340 ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n");
341 ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n");
342 ok(strstr(buffer,"M=N")==NULL,"M=N present\n");
345 static void test_null(void)
347 HINTERNET hi, hc;
348 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
349 static const WCHAR szEmpty[] = { 0 };
350 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
351 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
352 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
353 WCHAR buffer[0x20];
354 BOOL r;
355 DWORD sz;
357 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
358 ok(hi != NULL, "open failed\n");
360 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
361 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
362 ok(hc == NULL, "connect failed\n");
364 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
365 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
366 ok(hc == NULL, "connect failed\n");
368 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
369 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
370 ok(hc == NULL, "connect failed\n");
372 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
373 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
374 ok(hc == NULL, "connect failed\n");
376 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
377 ok(GetLastError() == ERROR_INVALID_PARAMETER ||
378 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
379 ok(hc == NULL, "connect failed\n");
381 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
382 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
383 ok(hc == NULL, "connect failed\n");
385 InternetCloseHandle(hi);
387 r = InternetSetCookieW(NULL, NULL, NULL);
388 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
389 ok(r == FALSE, "return wrong\n");
391 r = InternetSetCookieW(szServer, NULL, NULL);
392 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
393 ok(r == FALSE, "return wrong\n");
395 r = InternetSetCookieW(szUrl, szServer, NULL);
396 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
397 ok(r == FALSE, "return wrong\n");
399 r = InternetSetCookieW(szUrl, szServer, szServer);
400 ok(r == TRUE, "return wrong\n");
402 r = InternetSetCookieW(szUrl, NULL, szServer);
403 ok(r == TRUE, "return wrong\n");
405 r = InternetSetCookieW(szUrl, szServer, szEmpty);
406 ok(r == TRUE, "return wrong\n");
408 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
409 ok(r == FALSE, "return wrong\n");
411 r = InternetSetCookieW(szServer, NULL, szServer);
412 todo_wine {
413 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
415 ok(r == FALSE, "return wrong\n");
417 sz = 0;
418 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
419 ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
420 "wrong error %u\n", GetLastError());
421 ok( r == FALSE, "return wrong\n");
423 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
424 todo_wine {
425 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
427 ok( r == FALSE, "return wrong\n");
429 sz = 0;
430 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
431 ok( r == FALSE, "return wrong\n");
433 sz = 0;
434 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
435 ok( r == TRUE, "return wrong\n");
437 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
438 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
440 sz = 0x20;
441 memset(buffer, 0, sizeof buffer);
442 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
443 ok( r == TRUE, "return wrong\n");
445 /* sz == lstrlenW(buffer) only in XP SP1 */
446 ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
448 /* before XP SP2, buffer is "server; server" */
449 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
451 sz = sizeof(buffer);
452 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
453 ok(r == TRUE, "ret %d\n", r);
456 static void test_version(void)
458 INTERNET_VERSION_INFO version;
459 DWORD size;
460 BOOL res;
462 size = sizeof(version);
463 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
464 ok(res, "Could not get version: %u\n", GetLastError());
465 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
466 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
469 static void InternetTimeFromSystemTimeA_test(void)
471 BOOL ret;
472 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
473 char string[INTERNET_RFC1123_BUFSIZE];
474 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
475 DWORD error;
477 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
478 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
480 ok( !memcmp( string, expect, sizeof(expect) ),
481 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
483 /* test NULL time parameter */
484 SetLastError(0xdeadbeef);
485 ret = pInternetTimeFromSystemTimeA( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
486 error = GetLastError();
487 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
488 ok( error == ERROR_INVALID_PARAMETER,
489 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
490 error );
492 /* test NULL string parameter */
493 SetLastError(0xdeadbeef);
494 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
495 error = GetLastError();
496 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
497 ok( error == ERROR_INVALID_PARAMETER,
498 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
499 error );
501 /* test invalid format parameter */
502 SetLastError(0xdeadbeef);
503 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
504 error = GetLastError();
505 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
506 ok( error == ERROR_INVALID_PARAMETER,
507 "InternetTimeFromSystemTimeA failed with ERROR_INVALID_PARAMETER instead of %u\n",
508 error );
510 /* test too small buffer size */
511 SetLastError(0xdeadbeef);
512 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, 0 );
513 error = GetLastError();
514 ok( !ret, "InternetTimeFromSystemTimeA should have returned FALSE\n" );
515 ok( error == ERROR_INSUFFICIENT_BUFFER,
516 "InternetTimeFromSystemTimeA failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
517 error );
520 static void InternetTimeFromSystemTimeW_test(void)
522 BOOL ret;
523 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
524 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
525 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
526 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
527 DWORD error;
529 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
530 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
532 ok( !memcmp( string, expect, sizeof(expect) ),
533 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
535 /* test NULL time parameter */
536 SetLastError(0xdeadbeef);
537 ret = pInternetTimeFromSystemTimeW( NULL, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
538 error = GetLastError();
539 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
540 ok( error == ERROR_INVALID_PARAMETER,
541 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
542 error );
544 /* test NULL string parameter */
545 SetLastError(0xdeadbeef);
546 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, NULL, sizeof(string) );
547 error = GetLastError();
548 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
549 ok( error == ERROR_INVALID_PARAMETER,
550 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
551 error );
553 /* test invalid format parameter */
554 SetLastError(0xdeadbeef);
555 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT + 1, string, sizeof(string) );
556 error = GetLastError();
557 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
558 ok( error == ERROR_INVALID_PARAMETER,
559 "InternetTimeFromSystemTimeW failed with ERROR_INVALID_PARAMETER instead of %u\n",
560 error );
562 /* test too small buffer size */
563 SetLastError(0xdeadbeef);
564 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string)/sizeof(string[0]) );
565 error = GetLastError();
566 ok( !ret, "InternetTimeFromSystemTimeW should have returned FALSE\n" );
567 ok( error == ERROR_INSUFFICIENT_BUFFER,
568 "InternetTimeFromSystemTimeW failed with ERROR_INSUFFICIENT_BUFFER instead of %u\n",
569 error );
572 static void InternetTimeToSystemTimeA_test(void)
574 BOOL ret;
575 SYSTEMTIME time;
576 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
577 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
578 static const char string2[] = " fri 7 jan 2005 12 06 35";
580 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
581 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
582 ok( !memcmp( &time, &expect, sizeof(expect) ),
583 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
585 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
586 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
587 ok( !memcmp( &time, &expect, sizeof(expect) ),
588 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
591 static void InternetTimeToSystemTimeW_test(void)
593 BOOL ret;
594 SYSTEMTIME time;
595 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
596 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
597 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
598 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
599 '1','2',' ','0','6',' ','3','5',0 };
600 static const WCHAR string3[] = { 'F','r',0 };
602 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
603 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
605 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
606 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
608 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
609 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
611 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
612 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
614 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
615 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
616 ok( !memcmp( &time, &expect, sizeof(expect) ),
617 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
619 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
620 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
621 ok( !memcmp( &time, &expect, sizeof(expect) ),
622 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
624 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
625 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
628 static void test_IsDomainLegalCookieDomainW(void)
630 BOOL ret;
631 DWORD error;
632 static const WCHAR empty[] = {0};
633 static const WCHAR dot[] = {'.',0};
634 static const WCHAR uk[] = {'u','k',0};
635 static const WCHAR com[] = {'c','o','m',0};
636 static const WCHAR dot_com[] = {'.','c','o','m',0};
637 static const WCHAR gmail_com[] = {'g','m','a','i','l','.','c','o','m',0};
638 static const WCHAR dot_gmail_com[] = {'.','g','m','a','i','l','.','c','o','m',0};
639 static const WCHAR mail_gmail_com[] = {'m','a','i','l','.','g','m','a','i','l','.','c','o','m',0};
640 static const WCHAR gmail_co_uk[] = {'g','m','a','i','l','.','c','o','.','u','k',0};
641 static const WCHAR co_uk[] = {'c','o','.','u','k',0};
642 static const WCHAR dot_co_uk[] = {'.','c','o','.','u','k',0};
644 SetLastError(0xdeadbeef);
645 ret = pIsDomainLegalCookieDomainW(NULL, NULL);
646 error = GetLastError();
647 ok(!ret ||
648 broken(ret), /* IE6 */
649 "IsDomainLegalCookieDomainW succeeded\n");
650 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
652 SetLastError(0xdeadbeef);
653 ret = pIsDomainLegalCookieDomainW(com, NULL);
654 error = GetLastError();
655 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
656 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
658 SetLastError(0xdeadbeef);
659 ret = pIsDomainLegalCookieDomainW(NULL, gmail_com);
660 error = GetLastError();
661 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
662 ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
664 SetLastError(0xdeadbeef);
665 ret = pIsDomainLegalCookieDomainW(empty, gmail_com);
666 error = GetLastError();
667 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
668 ok(error == ERROR_INVALID_NAME ||
669 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
670 "got %u expected ERROR_INVALID_NAME\n", error);
672 SetLastError(0xdeadbeef);
673 ret = pIsDomainLegalCookieDomainW(com, empty);
674 error = GetLastError();
675 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
676 ok(error == ERROR_INVALID_NAME ||
677 broken(error == ERROR_INVALID_PARAMETER), /* IE6 */
678 "got %u expected ERROR_INVALID_NAME\n", error);
680 SetLastError(0xdeadbeef);
681 ret = pIsDomainLegalCookieDomainW(gmail_com, dot);
682 error = GetLastError();
683 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
684 ok(error == ERROR_INVALID_NAME ||
685 broken(error == 0xdeadbeef), /* IE6 */
686 "got %u expected ERROR_INVALID_NAME\n", error);
688 SetLastError(0xdeadbeef);
689 ret = pIsDomainLegalCookieDomainW(dot, gmail_com);
690 error = GetLastError();
691 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
692 ok(error == ERROR_INVALID_NAME ||
693 broken(error == 0xdeadbeef), /* IE6 */
694 "got %u expected ERROR_INVALID_NAME\n", error);
696 SetLastError(0xdeadbeef);
697 ret = pIsDomainLegalCookieDomainW(com, com);
698 error = GetLastError();
699 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
700 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
702 SetLastError(0xdeadbeef);
703 ret = pIsDomainLegalCookieDomainW(com, dot_com);
704 error = GetLastError();
705 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
706 ok(error == ERROR_INVALID_NAME ||
707 broken(error == 0xdeadbeef), /* IE6 */
708 "got %u expected ERROR_INVALID_NAME\n", error);
710 SetLastError(0xdeadbeef);
711 ret = pIsDomainLegalCookieDomainW(dot_com, com);
712 error = GetLastError();
713 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
714 ok(error == ERROR_INVALID_NAME ||
715 broken(error == 0xdeadbeef), /* IE6 */
716 "got %u expected ERROR_INVALID_NAME\n", error);
718 SetLastError(0xdeadbeef);
719 ret = pIsDomainLegalCookieDomainW(com, gmail_com);
720 error = GetLastError();
721 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
722 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
724 ret = pIsDomainLegalCookieDomainW(gmail_com, gmail_com);
725 ok(ret, "IsDomainLegalCookieDomainW failed\n");
727 SetLastError(0xdeadbeef);
728 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, co_uk);
729 error = GetLastError();
730 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
731 ok(error == 0xdeadbeef, "got %u expected 0xdeadbeef\n", error);
733 ret = pIsDomainLegalCookieDomainW(uk, co_uk);
734 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
736 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, dot_co_uk);
737 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
739 ret = pIsDomainLegalCookieDomainW(gmail_co_uk, gmail_co_uk);
740 ok(ret, "IsDomainLegalCookieDomainW failed\n");
742 ret = pIsDomainLegalCookieDomainW(gmail_com, com);
743 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
745 SetLastError(0xdeadbeef);
746 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
747 error = GetLastError();
748 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
749 ok(error == ERROR_INVALID_NAME ||
750 broken(error == 0xdeadbeef), /* IE6 */
751 "got %u expected ERROR_INVALID_NAME\n", error);
753 ret = pIsDomainLegalCookieDomainW(gmail_com, mail_gmail_com);
754 ok(ret, "IsDomainLegalCookieDomainW failed\n");
756 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, gmail_com);
757 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
759 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, com);
760 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
762 ret = pIsDomainLegalCookieDomainW(dot_gmail_com, mail_gmail_com);
763 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
765 ret = pIsDomainLegalCookieDomainW(mail_gmail_com, dot_gmail_com);
766 ok(!ret, "IsDomainLegalCookieDomainW succeeded\n");
769 /* ############################### */
771 START_TEST(internet)
773 HMODULE hdll;
774 hdll = GetModuleHandleA("wininet.dll");
775 pCreateUrlCacheContainerA = (void*)GetProcAddress(hdll, "CreateUrlCacheContainerA");
776 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
777 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
778 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
779 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
780 pIsDomainLegalCookieDomainW = (void*)GetProcAddress(hdll, (LPCSTR)117);
782 test_InternetCanonicalizeUrlA();
783 test_InternetQueryOptionA();
784 test_get_cookie();
785 test_complicated_cookie();
786 test_version();
787 test_null();
789 if (!pInternetTimeFromSystemTimeA)
790 win_skip("skipping the InternetTime tests\n");
791 else
793 InternetTimeFromSystemTimeA_test();
794 InternetTimeFromSystemTimeW_test();
795 InternetTimeToSystemTimeA_test();
796 InternetTimeToSystemTimeW_test();
798 if (pIsDomainLegalCookieDomainW && (void*)pIsDomainLegalCookieDomainW == (void*)pCreateUrlCacheContainerA)
799 win_skip("IsDomainLegalCookieDomainW is not available on systems with IE5\n");
800 else if (!pIsDomainLegalCookieDomainW)
801 win_skip("IsDomainLegalCookieDomainW (or ordinal 117) is not available\n");
802 else
803 test_IsDomainLegalCookieDomainW();