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 /* ############################### */
32 static void test_InternetCanonicalizeUrlA(void)
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';
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';
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';
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';
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';
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';
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));
118 /* ############################### */
120 static void test_InternetQueryOptionA(void)
122 HINTERNET hinet,hurl;
125 static const char useragent[] = {"Wininet Test"};
129 hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
130 ok((hinet != 0x0),"InternetOpen Failed\n");
132 SetLastError(0xdeadbeef);
133 len=strlen(useragent)+1;
134 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
136 ok(len == strlen(useragent)+1,"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
137 ok(retval == 0,"Got wrong return value %d\n",retval);
138 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
140 SetLastError(0xdeadbeef);
141 len=strlen(useragent)+1;
142 buffer=HeapAlloc(GetProcessHeap(),0,len);
143 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
145 todo_wine ok(retval == 1,"Got wrong return value %d\n",retval);
148 todo_wine ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
149 todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
151 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
152 HeapFree(GetProcessHeap(),0,buffer);
154 SetLastError(0xdeadbeef);
156 buffer=HeapAlloc(GetProcessHeap(),0,100);
157 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
159 todo_wine ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
160 ok(!retval, "Got wrong return value %d\n", retval);
161 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
162 HeapFree(GetProcessHeap(),0,buffer);
164 hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
166 SetLastError(0xdeadbeef);
168 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
170 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
171 ok(retval == 0,"Got wrong return value %d\n",retval);
172 todo_wine ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
174 InternetCloseHandle(hurl);
175 InternetCloseHandle(hinet);
177 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
178 ok((hinet != 0x0),"InternetOpen Failed\n");
180 SetLastError(0xdeadbeef);
182 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
184 todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
185 ok(retval == 0,"Got wrong return value %d\n",retval);
186 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
188 InternetCloseHandle(hinet);
190 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
191 ok((hinet != 0x0),"InternetOpen Failed\n");
192 SetLastError(0xdeadbeef);
194 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
196 todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
197 ok(retval == 0,"Got wrong return value %d\n",retval);
198 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
200 InternetCloseHandle(hinet);
203 static void test_get_cookie(void)
208 SetLastError(0xdeadbeef);
209 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
210 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
211 "InternetGetCookie should have failed with %s and error %d\n",
212 ret ? "TRUE" : "FALSE", GetLastError());
215 static void test_null(void)
218 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
219 static const WCHAR szEmpty[] = { 0 };
220 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
221 static const WCHAR szUrlEmpty[] = { 'h','t','t','p',':','/','/',0 };
222 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
227 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
228 ok(hi != NULL, "open failed\n");
230 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
231 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
232 ok(hc == NULL, "connect failed\n");
234 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 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_FTP, 0, 0);
239 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
240 ok(hc == NULL, "connect failed\n");
242 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
243 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
244 ok(hc == NULL, "connect failed\n");
246 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
247 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
248 ok(hc == NULL, "connect failed\n");
250 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
251 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
252 ok(hc == NULL, "connect failed\n");
254 InternetCloseHandle(hi);
256 r = InternetSetCookieW(NULL, NULL, NULL);
257 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
258 ok(r == FALSE, "return wrong\n");
260 r = InternetSetCookieW(szServer, NULL, NULL);
261 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
262 ok(r == FALSE, "return wrong\n");
264 r = InternetSetCookieW(szUrl, szServer, NULL);
265 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
266 ok(r == FALSE, "return wrong\n");
268 r = InternetSetCookieW(szUrl, szServer, szServer);
269 ok(r == TRUE, "return wrong\n");
271 r = InternetSetCookieW(szUrl, NULL, szServer);
272 ok(r == TRUE, "return wrong\n");
274 r = InternetSetCookieW(szUrl, szServer, szEmpty);
275 ok(r == TRUE, "return wrong\n");
277 r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
278 ok(r == FALSE, "return wrong\n");
280 r = InternetSetCookieW(szServer, NULL, szServer);
282 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
284 ok(r == FALSE, "return wrong\n");
287 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
288 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
289 ok( r == FALSE, "return wrong\n");
291 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
293 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
295 ok( r == FALSE, "return wrong\n");
298 r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
299 ok( r == FALSE, "return wrong\n");
302 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
303 ok( r == TRUE, "return wrong\n");
305 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
306 ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
309 memset(buffer, 0, sizeof buffer);
310 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
311 ok( r == TRUE, "return wrong\n");
313 /* sz == lstrlenW(buffer) only in XP SP1 */
314 ok( sz == 1 + lstrlenW(buffer), "sz wrong\n");
316 /* before XP SP2, buffer is "server; server" */
317 ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
320 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
321 ok(r == TRUE, "ret %d\n", r);
324 /* ############################### */
328 test_InternetCanonicalizeUrlA();
329 test_InternetQueryOptionA();