push 014043c4937c940c54cd1214c96e33a3b3c8cf7d
[wine/hacks.git] / dlls / wininet / tests / internet.c
blobd3adf9108efdfccd96283134b8b2d697be9fef86
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 /* ############################### */
32 static void test_InternetCanonicalizeUrlA(void)
34 CHAR buffer[256];
35 LPCSTR url;
36 DWORD urllen;
37 DWORD dwSize;
38 DWORD res;
40 /* Acrobat Updater 5 calls this for Adobe Reader 8.1 */
41 url = "http://swupmf.adobe.com/manifest/50/win/AdobeUpdater.upd";
42 urllen = lstrlenA(url);
44 memset(buffer, '#', sizeof(buffer)-1);
45 buffer[sizeof(buffer)-1] = '\0';
46 dwSize = 1; /* Acrobat Updater use this size */
47 SetLastError(0xdeadbeef);
48 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
49 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
50 "got %u and %u with size %u for '%s' (%d)\n",
51 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
54 /* buffer has no space for the terminating '\0' */
55 memset(buffer, '#', sizeof(buffer)-1);
56 buffer[sizeof(buffer)-1] = '\0';
57 dwSize = urllen;
58 SetLastError(0xdeadbeef);
59 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
60 /* dwSize is nr. of needed bytes with the terminating '\0' */
61 ok( !res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER) && (dwSize == (urllen+1)),
62 "got %u and %u with size %u for '%s' (%d)\n",
63 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
65 /* buffer has the required size */
66 memset(buffer, '#', sizeof(buffer)-1);
67 buffer[sizeof(buffer)-1] = '\0';
68 dwSize = urllen+1;
69 SetLastError(0xdeadbeef);
70 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
71 /* dwSize is nr. of copied bytes without the terminating '\0' */
72 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
73 "got %u and %u with size %u for '%s' (%d)\n",
74 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
76 /* buffer is larger as the required size */
77 memset(buffer, '#', sizeof(buffer)-1);
78 buffer[sizeof(buffer)-1] = '\0';
79 dwSize = urllen+2;
80 SetLastError(0xdeadbeef);
81 res = InternetCanonicalizeUrlA(url, buffer, &dwSize, 0);
82 /* dwSize is nr. of copied bytes without the terminating '\0' */
83 ok( res && (dwSize == urllen) && (lstrcmpA(url, buffer) == 0),
84 "got %u and %u with size %u for '%s' (%d)\n",
85 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
88 /* check NULL pointers */
89 memset(buffer, '#', urllen + 4);
90 buffer[urllen + 4] = '\0';
91 dwSize = urllen+1;
92 SetLastError(0xdeadbeef);
93 res = InternetCanonicalizeUrlA(NULL, buffer, &dwSize, 0);
94 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
95 "got %u and %u with size %u for '%s' (%d)\n",
96 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
98 memset(buffer, '#', urllen + 4);
99 buffer[urllen + 4] = '\0';
100 dwSize = urllen+1;
101 SetLastError(0xdeadbeef);
102 res = InternetCanonicalizeUrlA(url, NULL, &dwSize, 0);
103 ok( !res && (GetLastError() == ERROR_INVALID_PARAMETER),
104 "got %u and %u with size %u for '%s' (%d)\n",
105 res, GetLastError(), dwSize, buffer, lstrlenA(buffer));
107 memset(buffer, '#', urllen + 4);
108 buffer[urllen + 4] = '\0';
109 dwSize = urllen+1;
110 SetLastError(0xdeadbeef);
111 res = InternetCanonicalizeUrlA(url, buffer, NULL, 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 res = InternetSetOptionA(NULL, 0xdeadbeef, buffer, sizeof(buffer));
117 ok(!res, "InternetSetOptionA succeeded\n");
118 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION,
119 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
122 /* ############################### */
124 static void test_InternetQueryOptionA(void)
126 HINTERNET hinet,hurl;
127 DWORD len;
128 DWORD err;
129 static const char useragent[] = {"Wininet Test"};
130 char *buffer;
131 int retval;
133 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
134 ok((hinet != 0x0),"InternetOpen Failed\n");
136 SetLastError(0xdeadbeef);
137 len=strlen(useragent)+1;
138 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
139 err=GetLastError();
140 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
141 ok(retval == 0,"Got wrong return value %d\n",retval);
142 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
144 SetLastError(0xdeadbeef);
145 len=strlen(useragent)+1;
146 buffer=HeapAlloc(GetProcessHeap(),0,len);
147 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
148 err=GetLastError();
149 todo_wine ok(retval == 1,"Got wrong return value %d\n",retval);
150 if (retval)
152 todo_wine ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
153 todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
155 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
156 HeapFree(GetProcessHeap(),0,buffer);
158 SetLastError(0xdeadbeef);
159 len=0;
160 buffer=HeapAlloc(GetProcessHeap(),0,100);
161 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
162 err=GetLastError();
163 todo_wine ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
164 ok(!retval, "Got wrong return value %d\n", retval);
165 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
166 HeapFree(GetProcessHeap(),0,buffer);
168 hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
170 SetLastError(0xdeadbeef);
171 len=0;
172 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
173 err=GetLastError();
174 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
175 ok(retval == 0,"Got wrong return value %d\n",retval);
176 todo_wine ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
178 InternetCloseHandle(hurl);
179 InternetCloseHandle(hinet);
181 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
182 ok((hinet != 0x0),"InternetOpen Failed\n");
184 SetLastError(0xdeadbeef);
185 len=0;
186 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
187 err=GetLastError();
188 todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
189 ok(retval == 0,"Got wrong return value %d\n",retval);
190 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
192 InternetCloseHandle(hinet);
194 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
195 ok((hinet != 0x0),"InternetOpen Failed\n");
196 SetLastError(0xdeadbeef);
197 len=0;
198 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
199 err=GetLastError();
200 todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
201 ok(retval == 0,"Got wrong return value %d\n",retval);
202 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
204 InternetCloseHandle(hinet);
207 static void test_get_cookie(void)
209 DWORD len;
210 BOOL ret;
212 SetLastError(0xdeadbeef);
213 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
214 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
215 "InternetGetCookie should have failed with %s and error %d\n",
216 ret ? "TRUE" : "FALSE", GetLastError());
219 static void test_null(void)
221 HINTERNET hi, hc;
222 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
223 static const WCHAR szEmpty[] = { 0 };
224 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
225 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
226 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
227 WCHAR buffer[0x20];
228 BOOL r;
229 DWORD sz;
231 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
232 ok(hi != NULL, "open failed\n");
234 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
235 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
236 ok(hc == NULL, "connect failed\n");
238 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
239 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
240 ok(hc == NULL, "connect failed\n");
242 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
243 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
244 ok(hc == NULL, "connect failed\n");
246 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
247 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
248 ok(hc == NULL, "connect failed\n");
250 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
251 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
252 ok(hc == NULL, "connect failed\n");
254 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
255 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
256 ok(hc == NULL, "connect failed\n");
258 InternetCloseHandle(hi);
260 r = InternetSetCookieW(NULL, NULL, NULL);
261 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
262 ok(r == FALSE, "return wrong\n");
264 r = InternetSetCookieW(szServer, NULL, NULL);
265 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
266 ok(r == FALSE, "return wrong\n");
268 r = InternetSetCookieW(szUrl, szServer, NULL);
269 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
270 ok(r == FALSE, "return wrong\n");
272 r = InternetSetCookieW(szUrl, szServer, szServer);
273 ok(r == TRUE, "return wrong\n");
275 r = InternetSetCookieW(szUrl, NULL, szServer);
276 ok(r == TRUE, "return wrong\n");
278 r = InternetSetCookieW(szUrl, szServer, szEmpty);
279 ok(r == TRUE, "return wrong\n");
281 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
282 ok(r == FALSE, "return wrong\n");
284 r = InternetSetCookieW(szServer, NULL, szServer);
285 todo_wine {
286 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
288 ok(r == FALSE, "return wrong\n");
290 sz = 0;
291 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
292 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
293 ok( r == FALSE, "return wrong\n");
295 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
296 todo_wine {
297 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
299 ok( r == FALSE, "return wrong\n");
301 sz = 0;
302 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
303 ok( r == FALSE, "return wrong\n");
305 sz = 0;
306 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
307 ok( r == TRUE, "return wrong\n");
309 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
310 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
312 sz = 0x20;
313 memset(buffer, 0, sizeof buffer);
314 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
315 ok( r == TRUE, "return wrong\n");
317 /* sz == lstrlenW(buffer) only in XP SP1 */
318 ok( sz == 1 + lstrlenW(buffer), "sz wrong\n");
320 /* before XP SP2, buffer is "server; server" */
321 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
323 sz = sizeof(buffer);
324 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
325 ok(r == TRUE, "ret %d\n", r);
328 static void test_version(void)
330 INTERNET_VERSION_INFO version;
331 DWORD size;
332 BOOL res;
334 size = sizeof(version);
335 res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
336 ok(res, "Could not get version: %u\n", GetLastError());
337 ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
338 ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
341 /* ############################### */
343 START_TEST(internet)
345 test_InternetCanonicalizeUrlA();
346 test_InternetQueryOptionA();
347 test_get_cookie();
348 test_version();
349 test_null();