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
28 #include "wine/test.h"
30 static void InternetQueryOptionA_test(void)
35 static const char useragent[] = {"Wininet Test"};
39 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
40 ok((hinet != 0x0),"InternetOpen Failed\n");
42 SetLastError(0xdeadbeef);
43 len=strlen(useragent)+1;
44 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
46 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
47 ok(retval == 0,"Got wrong return value %d\n",retval);
48 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
50 SetLastError(0xdeadbeef);
51 len=strlen(useragent)+1;
52 buffer=HeapAlloc(GetProcessHeap(),0,len);
53 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
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 %d instead of %d\n",len,lstrlenA(useragent));
57 todo_wine ok(retval == 1,"Got wrong return value %d\n",retval);
58 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
59 HeapFree(GetProcessHeap(),0,buffer);
61 SetLastError(0xdeadbeef);
63 buffer=HeapAlloc(GetProcessHeap(),0,100);
64 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
66 todo_wine ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
67 ok(!retval, "Got wrong return value %d\n", retval);
68 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
69 HeapFree(GetProcessHeap(),0,buffer);
71 hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
73 SetLastError(0xdeadbeef);
75 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
77 ok(len == 0,"Got wrong user agent length %d 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 %d\n",err);
81 InternetCloseHandle(hurl);
82 InternetCloseHandle(hinet);
84 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
85 ok((hinet != 0x0),"InternetOpen Failed\n");
87 SetLastError(0xdeadbeef);
89 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
91 todo_wine ok(len == 1,"Got wrong user agent length %d 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%d\n",err);
95 InternetCloseHandle(hinet);
97 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
98 ok((hinet != 0x0),"InternetOpen Failed\n");
99 SetLastError(0xdeadbeef);
101 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
103 todo_wine ok(len == 1,"Got wrong user agent length %d 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%d\n",err);
107 InternetCloseHandle(hinet);
110 static void test_get_cookie(void)
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 %d\n",
119 ret ? "TRUE" : "FALSE", GetLastError());
122 static void test_null(void)
125 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
126 static const WCHAR szEmpty[] = { 0 };
127 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
128 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
133 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
134 ok(hi != NULL, "open failed\n");
136 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
137 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
138 ok(hc == NULL, "connect failed\n");
140 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
141 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
142 ok(hc == NULL, "connect failed\n");
144 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
145 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
146 ok(hc == NULL, "connect failed\n");
148 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
149 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
150 ok(hc == NULL, "connect failed\n");
152 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
153 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
154 ok(hc == NULL, "connect failed\n");
156 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
157 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
158 ok(hc == NULL, "connect failed\n");
160 InternetCloseHandle(hi);
162 r = InternetSetCookieW(NULL, NULL, NULL);
163 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
164 ok(r == FALSE, "return wrong\n");
166 r = InternetSetCookieW(szServer, NULL, NULL);
167 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
168 ok(r == FALSE, "return wrong\n");
170 r = InternetSetCookieW(szUrl, szServer, NULL);
171 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
172 ok(r == FALSE, "return wrong\n");
174 r = InternetSetCookieW(szUrl, szServer, szServer);
175 ok(r == TRUE, "return wrong\n");
178 r = InternetSetCookieW(szUrl, NULL, szServer);
179 ok(r == TRUE, "return wrong\n");
182 r = InternetSetCookieW(szUrl, szServer, szEmpty);
183 ok(r == TRUE, "return wrong\n");
185 r = InternetSetCookieW(szServer, NULL, szServer);
187 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
189 ok(r == FALSE, "return wrong\n");
192 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
193 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
194 ok( r == FALSE, "return wrong\n");
196 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
198 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
200 ok( r == FALSE, "return wrong\n");
203 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
204 ok( r == TRUE, "return wrong\n");
206 ok( sz == 30, "sz wrong\n");
210 memset(buffer, 0, sizeof buffer);
211 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
212 ok( r == TRUE, "return wrong\n");
214 ok( sz == lstrlenW(buffer), "sz wrong\n");
215 ok( !lstrcmpW(szExpect, buffer), "cookie data wrong\n");
221 InternetQueryOptionA_test();