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(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent);
146 todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent));
147 todo_wine ok(retval == 1,"Got wrong return value %d\n",retval);
148 ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
149 HeapFree(GetProcessHeap(),0,buffer);
151 SetLastError(0xdeadbeef);
153 buffer=HeapAlloc(GetProcessHeap(),0,100);
154 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len);
156 todo_wine ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1);
157 ok(!retval, "Got wrong return value %d\n", retval);
158 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err);
159 HeapFree(GetProcessHeap(),0,buffer);
161 hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
163 SetLastError(0xdeadbeef);
165 retval = InternetQueryOptionA(hurl,INTERNET_OPTION_USER_AGENT,NULL,&len);
167 ok(len == 0,"Got wrong user agent length %d instead of 0\n",len);
168 ok(retval == 0,"Got wrong return value %d\n",retval);
169 todo_wine ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err);
171 InternetCloseHandle(hurl);
172 InternetCloseHandle(hinet);
174 hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
175 ok((hinet != 0x0),"InternetOpen Failed\n");
177 SetLastError(0xdeadbeef);
179 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
181 todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
182 ok(retval == 0,"Got wrong return value %d\n",retval);
183 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
185 InternetCloseHandle(hinet);
187 hinet = InternetOpenA(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
188 ok((hinet != 0x0),"InternetOpen Failed\n");
189 SetLastError(0xdeadbeef);
191 retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len);
193 todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1);
194 ok(retval == 0,"Got wrong return value %d\n",retval);
195 todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err);
197 InternetCloseHandle(hinet);
200 static void test_get_cookie(void)
205 SetLastError(0xdeadbeef);
206 ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len);
207 ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS,
208 "InternetGetCookie should have failed with %s and error %d\n",
209 ret ? "TRUE" : "FALSE", GetLastError());
212 static void test_null(void)
215 static const WCHAR szServer[] = { 's','e','r','v','e','r',0 };
216 static const WCHAR szEmpty[] = { 0 };
217 static const WCHAR szUrl[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
218 static const WCHAR szExpect[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
223 hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
224 ok(hi != NULL, "open failed\n");
226 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, 0, 0, 0);
227 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
228 ok(hc == NULL, "connect failed\n");
230 hc = InternetConnectW(hi, NULL, 0, NULL, NULL, INTERNET_SERVICE_HTTP, 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_FTP, 0, 0);
235 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
236 ok(hc == NULL, "connect failed\n");
238 hc = InternetConnectW(NULL, szServer, 0, NULL, NULL, INTERNET_SERVICE_FTP, 0, 0);
239 ok(GetLastError() == ERROR_INVALID_HANDLE, "wrong error\n");
240 ok(hc == NULL, "connect failed\n");
242 hc = InternetOpenUrlW(hi, NULL, NULL, 0, 0, 0);
243 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
244 ok(hc == NULL, "connect failed\n");
246 hc = InternetOpenUrlW(hi, szServer, NULL, 0, 0, 0);
247 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
248 ok(hc == NULL, "connect failed\n");
250 InternetCloseHandle(hi);
252 r = InternetSetCookieW(NULL, NULL, NULL);
253 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
254 ok(r == FALSE, "return wrong\n");
256 r = InternetSetCookieW(szServer, NULL, NULL);
257 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
258 ok(r == FALSE, "return wrong\n");
260 r = InternetSetCookieW(szUrl, szServer, NULL);
261 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
262 ok(r == FALSE, "return wrong\n");
264 r = InternetSetCookieW(szUrl, szServer, szServer);
265 ok(r == TRUE, "return wrong\n");
268 r = InternetSetCookieW(szUrl, NULL, szServer);
269 ok(r == TRUE, "return wrong\n");
272 r = InternetSetCookieW(szUrl, szServer, szEmpty);
273 ok(r == TRUE, "return wrong\n");
275 r = InternetSetCookieW(szServer, NULL, szServer);
277 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
279 ok(r == FALSE, "return wrong\n");
282 r = InternetGetCookieW(NULL, NULL, NULL, &sz);
283 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
284 ok( r == FALSE, "return wrong\n");
286 r = InternetGetCookieW(szServer, NULL, NULL, &sz);
288 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
290 ok( r == FALSE, "return wrong\n");
293 r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
294 ok( r == TRUE, "return wrong\n");
296 ok( sz == 30, "sz wrong\n");
300 memset(buffer, 0, sizeof buffer);
301 r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
302 ok( r == TRUE, "return wrong\n");
304 ok( sz == lstrlenW(buffer), "sz wrong\n");
305 ok( !lstrcmpW(szExpect, buffer), "cookie data wrong\n");
309 r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
310 ok(r == TRUE, "ret %d\n", r);
314 /* ############################### */
318 test_InternetCanonicalizeUrlA();
319 test_InternetQueryOptionA();