comctl32: A couple fixes for tab icon offsets.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 void InternetQueryOptionA_test(void)
31 {
32   HINTERNET hinet,hurl;
33   DWORD len;
34   DWORD err;
35   static const char useragent[] = {"Wininet Test"};
36   char *buffer;
37   int retval;
38
39   hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
40   ok((hinet != 0x0),"InternetOpen Failed\n");
41
42   SetLastError(0xdeadbeef);
43   len=strlen(useragent)+1;
44   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
45   err=GetLastError();
46   ok(len == strlen(useragent)+1,"Got wrong user agent length %ld instead of %d\n",len,strlen(useragent));
47   ok(retval == 0,"Got wrong return value %d\n",retval);
48   todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%ld\n",err);
49
50   SetLastError(0xdeadbeef);
51   len=strlen(useragent)+1;
52   buffer=HeapAlloc(GetProcessHeap(),0,len);
53   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
54   err=GetLastError();
55   todo_wine ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
56   todo_wine ok(len == strlen(useragent),"Got wrong user agent length %ld instead of %d\n",len,strlen(useragent));
57   todo_wine ok(retval == 1,"Got wrong return value %d\n",retval);
58   ok(err == 0xdeadbeef, "Got wrong error code %ld\n",err);
59   HeapFree(GetProcessHeap(),0,buffer);
60
61   SetLastError(0xdeadbeef);
62   len=0;
63   buffer=HeapAlloc(GetProcessHeap(),0,100);
64   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
65   err=GetLastError();
66   todo_wine ok(len == strlen(useragent) + 1,"Got wrong user agent length %ld instead of %d\n", len, strlen(useragent) + 1);
67   ok(!retval, "Got wrong return value %d\n", retval);
68   todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %ld\n", err);
69   HeapFree(GetProcessHeap(),0,buffer);
70
71   hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
72
73   SetLastError(0xdeadbeef);
74   len=0;
75   retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
76   err=GetLastError();
77   ok(len == 0,"Got wrong user agent length %ld instead of 0\n",len);
78   ok(retval == 0,"Got wrong return value %d\n",retval);
79   todo_wine ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %ld\n",err);
80
81   InternetCloseHandle(hurl);
82   InternetCloseHandle(hinet);
83
84   hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
85   ok((hinet != 0x0),"InternetOpen Failed\n");
86
87   SetLastError(0xdeadbeef);
88   len=0;
89   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
90   err=GetLastError();
91   todo_wine ok(len == 1,"Got wrong user agent length %ld instead of %d\n",len,1);
92   ok(retval == 0,"Got wrong return value %d\n",retval);
93   todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%ld\n",err);
94
95   InternetCloseHandle(hinet);
96
97   hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
98   ok((hinet != 0x0),"InternetOpen Failed\n");
99   SetLastError(0xdeadbeef);
100   len=0;
101   retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
102   err=GetLastError();
103   todo_wine ok(len == 1,"Got wrong user agent length %ld instead of %d\n",len,1);
104   ok(retval == 0,"Got wrong return value %d\n",retval);
105   todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%ld\n",err);
106
107   InternetCloseHandle(hinet);
108 }
109
110 static void test_get_cookie(void)
111 {
112   DWORD len;
113   BOOL ret;
114
115   SetLastError(0xdeadbeef);
116   ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
117   ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
118     "InternetGetCookie should have failed with %s and error %ld\n",
119     ret ? "TRUE" : "FALSE", GetLastError());
120 }
121
122 START_TEST(internet)
123 {
124   InternetQueryOptionA_test();
125   test_get_cookie();
126 }