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 memset(buffer
, '#', sizeof(buffer
)-1);
77 buffer
[sizeof(buffer
)-1] = '\0';
78 dwSize
= sizeof(buffer
);
79 SetLastError(0xdeadbeef);
80 res
= InternetCanonicalizeUrlA("file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml", buffer
, &dwSize
, ICU_DECODE
| ICU_NO_ENCODE
);
81 ok(res
, "InternetCanonicalizeUrlA failed %u\n", GetLastError());
82 ok(dwSize
== lstrlenA(buffer
), "got %d expected %d\n", dwSize
, lstrlenA(buffer
));
83 todo_wine
ok(!lstrcmpA("file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", buffer
),
84 "got %s expected 'file://C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml'\n", buffer
);
86 /* buffer is larger as the required size */
87 memset(buffer
, '#', sizeof(buffer
)-1);
88 buffer
[sizeof(buffer
)-1] = '\0';
90 SetLastError(0xdeadbeef);
91 res
= InternetCanonicalizeUrlA(url
, buffer
, &dwSize
, 0);
92 /* dwSize is nr. of copied bytes without the terminating '\0' */
93 ok( res
&& (dwSize
== urllen
) && (lstrcmpA(url
, buffer
) == 0),
94 "got %u and %u with size %u for '%s' (%d)\n",
95 res
, GetLastError(), dwSize
, buffer
, lstrlenA(buffer
));
98 /* check NULL pointers */
99 memset(buffer
, '#', urllen
+ 4);
100 buffer
[urllen
+ 4] = '\0';
102 SetLastError(0xdeadbeef);
103 res
= InternetCanonicalizeUrlA(NULL
, buffer
, &dwSize
, 0);
104 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
105 "got %u and %u with size %u for '%s' (%d)\n",
106 res
, GetLastError(), dwSize
, buffer
, lstrlenA(buffer
));
108 memset(buffer
, '#', urllen
+ 4);
109 buffer
[urllen
+ 4] = '\0';
111 SetLastError(0xdeadbeef);
112 res
= InternetCanonicalizeUrlA(url
, NULL
, &dwSize
, 0);
113 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
114 "got %u and %u with size %u for '%s' (%d)\n",
115 res
, GetLastError(), dwSize
, buffer
, lstrlenA(buffer
));
117 memset(buffer
, '#', urllen
+ 4);
118 buffer
[urllen
+ 4] = '\0';
120 SetLastError(0xdeadbeef);
121 res
= InternetCanonicalizeUrlA(url
, buffer
, NULL
, 0);
122 ok( !res
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
123 "got %u and %u with size %u for '%s' (%d)\n",
124 res
, GetLastError(), dwSize
, buffer
, lstrlenA(buffer
));
126 /* test with trailing space */
128 res
= InternetCanonicalizeUrlA("http://www.winehq.org/index.php?x= ", buffer
, &dwSize
, ICU_BROWSER_MODE
);
129 ok(res
== 1, "InternetCanonicalizeUrlA failed\n");
130 ok(!strcmp(buffer
, "http://www.winehq.org/index.php?x="), "Trailing space should have been stripped even in ICU_BROWSER_MODE (%s)\n", buffer
);
132 res
= InternetSetOptionA(NULL
, 0xdeadbeef, buffer
, sizeof(buffer
));
133 ok(!res
, "InternetSetOptionA succeeded\n");
134 ok(GetLastError() == ERROR_INTERNET_INVALID_OPTION
,
135 "InternetSetOptionA failed %u, expected ERROR_INTERNET_INVALID_OPTION\n", GetLastError());
138 /* ############################### */
140 static void test_InternetQueryOptionA(void)
142 HINTERNET hinet
,hurl
;
145 static const char useragent
[] = {"Wininet Test"};
149 hinet
= InternetOpenA(useragent
,INTERNET_OPEN_TYPE_DIRECT
,NULL
,NULL
, 0);
150 ok((hinet
!= 0x0),"InternetOpen Failed\n");
152 SetLastError(0xdeadbeef);
153 retval
=InternetQueryOptionA(NULL
,INTERNET_OPTION_USER_AGENT
,NULL
,&len
);
155 ok(retval
== 0,"Got wrong return value %d\n",retval
);
156 ok(err
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "Got wrong error code%d\n",err
);
158 SetLastError(0xdeadbeef);
159 len
=strlen(useragent
)+1;
160 retval
=InternetQueryOptionA(hinet
,INTERNET_OPTION_USER_AGENT
,NULL
,&len
);
162 ok(len
== strlen(useragent
)+1,"Got wrong user agent length %d instead of %d\n",len
,lstrlenA(useragent
));
163 ok(retval
== 0,"Got wrong return value %d\n",retval
);
164 todo_wine
ok(err
== ERROR_INSUFFICIENT_BUFFER
, "Got wrong error code%d\n",err
);
166 SetLastError(0xdeadbeef);
167 len
=strlen(useragent
)+1;
168 buffer
=HeapAlloc(GetProcessHeap(),0,len
);
169 retval
=InternetQueryOptionA(hinet
,INTERNET_OPTION_USER_AGENT
,buffer
,&len
);
171 ok(retval
== 1,"Got wrong return value %d\n",retval
);
174 ok(!strcmp(useragent
,buffer
),"Got wrong user agent string %s instead of %s\n",buffer
,useragent
);
175 todo_wine
ok(len
== strlen(useragent
),"Got wrong user agent length %d instead of %d\n",len
,lstrlenA(useragent
));
177 ok(err
== 0xdeadbeef, "Got wrong error code %d\n",err
);
178 HeapFree(GetProcessHeap(),0,buffer
);
180 SetLastError(0xdeadbeef);
182 buffer
=HeapAlloc(GetProcessHeap(),0,100);
183 retval
=InternetQueryOptionA(hinet
,INTERNET_OPTION_USER_AGENT
,buffer
,&len
);
185 ok(len
== strlen(useragent
) + 1,"Got wrong user agent length %d instead of %d\n", len
, lstrlenA(useragent
) + 1);
186 ok(!retval
, "Got wrong return value %d\n", retval
);
187 ok(err
== ERROR_INSUFFICIENT_BUFFER
, "Got wrong error code %d\n", err
);
188 HeapFree(GetProcessHeap(),0,buffer
);
190 hurl
= InternetConnectA(hinet
,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT
,NULL
,NULL
,INTERNET_SERVICE_HTTP
,0,0);
192 SetLastError(0xdeadbeef);
194 retval
= InternetQueryOptionA(hurl
,INTERNET_OPTION_USER_AGENT
,NULL
,&len
);
196 ok(len
== 0,"Got wrong user agent length %d instead of 0\n",len
);
197 ok(retval
== 0,"Got wrong return value %d\n",retval
);
198 ok(err
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "Got wrong error code %d\n",err
);
200 InternetCloseHandle(hurl
);
201 InternetCloseHandle(hinet
);
203 hinet
= InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT
,NULL
,NULL
, 0);
204 ok((hinet
!= 0x0),"InternetOpen Failed\n");
206 SetLastError(0xdeadbeef);
208 retval
=InternetQueryOptionA(hinet
,INTERNET_OPTION_USER_AGENT
,NULL
,&len
);
210 ok(len
== 1,"Got wrong user agent length %d instead of %d\n",len
,1);
211 ok(retval
== 0,"Got wrong return value %d\n",retval
);
212 ok(err
== ERROR_INSUFFICIENT_BUFFER
, "Got wrong error code%d\n",err
);
214 InternetCloseHandle(hinet
);
216 hinet
= InternetOpenA(NULL
,INTERNET_OPEN_TYPE_DIRECT
,NULL
,NULL
, 0);
217 ok((hinet
!= 0x0),"InternetOpen Failed\n");
218 SetLastError(0xdeadbeef);
220 retval
=InternetQueryOptionA(hinet
,INTERNET_OPTION_USER_AGENT
,NULL
,&len
);
222 todo_wine
ok(len
== 1,"Got wrong user agent length %d instead of %d\n",len
,1);
223 ok(retval
== 0,"Got wrong return value %d\n",retval
);
224 todo_wine
ok(err
== ERROR_INSUFFICIENT_BUFFER
, "Got wrong error code%d\n",err
);
226 InternetCloseHandle(hinet
);
229 static void test_get_cookie(void)
234 SetLastError(0xdeadbeef);
235 ret
= InternetGetCookie("http://www.example.com", NULL
, NULL
, &len
);
236 ok(!ret
&& GetLastError() == ERROR_NO_MORE_ITEMS
,
237 "InternetGetCookie should have failed with %s and error %d\n",
238 ret
? "TRUE" : "FALSE", GetLastError());
241 static void test_null(void)
244 static const WCHAR szServer
[] = { 's','e','r','v','e','r',0 };
245 static const WCHAR szEmpty
[] = { 0 };
246 static const WCHAR szUrl
[] = { 'h','t','t','p',':','/','/','a','.','b','.','c',0 };
247 static const WCHAR szUrlEmpty
[] = { 'h','t','t','p',':','/','/',0 };
248 static const WCHAR szExpect
[] = { 's','e','r','v','e','r',';',' ','s','e','r','v','e','r',0 };
253 hi
= InternetOpenW(NULL
, 0, NULL
, NULL
, 0);
254 ok(hi
!= NULL
, "open failed\n");
256 hc
= InternetConnectW(hi
, NULL
, 0, NULL
, NULL
, 0, 0, 0);
257 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error\n");
258 ok(hc
== NULL
, "connect failed\n");
260 hc
= InternetConnectW(hi
, NULL
, 0, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
261 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error\n");
262 ok(hc
== NULL
, "connect failed\n");
264 hc
= InternetConnectW(hi
, NULL
, 0, NULL
, NULL
, INTERNET_SERVICE_FTP
, 0, 0);
265 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error\n");
266 ok(hc
== NULL
, "connect failed\n");
268 hc
= InternetConnectW(NULL
, szServer
, 0, NULL
, NULL
, INTERNET_SERVICE_FTP
, 0, 0);
269 ok(GetLastError() == ERROR_INVALID_HANDLE
, "wrong error\n");
270 ok(hc
== NULL
, "connect failed\n");
272 hc
= InternetOpenUrlW(hi
, NULL
, NULL
, 0, 0, 0);
273 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
274 GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "wrong error\n");
275 ok(hc
== NULL
, "connect failed\n");
277 hc
= InternetOpenUrlW(hi
, szServer
, NULL
, 0, 0, 0);
278 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "wrong error\n");
279 ok(hc
== NULL
, "connect failed\n");
281 InternetCloseHandle(hi
);
283 r
= InternetSetCookieW(NULL
, NULL
, NULL
);
284 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error\n");
285 ok(r
== FALSE
, "return wrong\n");
287 r
= InternetSetCookieW(szServer
, NULL
, NULL
);
288 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error\n");
289 ok(r
== FALSE
, "return wrong\n");
291 r
= InternetSetCookieW(szUrl
, szServer
, NULL
);
292 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "wrong error\n");
293 ok(r
== FALSE
, "return wrong\n");
295 r
= InternetSetCookieW(szUrl
, szServer
, szServer
);
296 ok(r
== TRUE
, "return wrong\n");
298 r
= InternetSetCookieW(szUrl
, NULL
, szServer
);
299 ok(r
== TRUE
, "return wrong\n");
301 r
= InternetSetCookieW(szUrl
, szServer
, szEmpty
);
302 ok(r
== TRUE
, "return wrong\n");
304 r
= InternetSetCookieW(szUrlEmpty
, szServer
, szServer
);
305 ok(r
== FALSE
, "return wrong\n");
307 r
= InternetSetCookieW(szServer
, NULL
, szServer
);
309 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "wrong error\n");
311 ok(r
== FALSE
, "return wrong\n");
314 r
= InternetGetCookieW(NULL
, NULL
, NULL
, &sz
);
315 ok(GetLastError() == ERROR_INVALID_PARAMETER
|| GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
,
316 "wrong error %u\n", GetLastError());
317 ok( r
== FALSE
, "return wrong\n");
319 r
= InternetGetCookieW(szServer
, NULL
, NULL
, &sz
);
321 ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME
, "wrong error\n");
323 ok( r
== FALSE
, "return wrong\n");
326 r
= InternetGetCookieW(szUrlEmpty
, szServer
, NULL
, &sz
);
327 ok( r
== FALSE
, "return wrong\n");
330 r
= InternetGetCookieW(szUrl
, szServer
, NULL
, &sz
);
331 ok( r
== TRUE
, "return wrong\n");
333 /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
334 ok( sz
== 14 || sz
== 30, "sz wrong, got %u, expected 14 or 30\n", sz
);
337 memset(buffer
, 0, sizeof buffer
);
338 r
= InternetGetCookieW(szUrl
, szServer
, buffer
, &sz
);
339 ok( r
== TRUE
, "return wrong\n");
341 /* sz == lstrlenW(buffer) only in XP SP1 */
342 ok( sz
== 1 + lstrlenW(buffer
) || sz
== lstrlenW(buffer
), "sz wrong %d\n", sz
);
344 /* before XP SP2, buffer is "server; server" */
345 ok( !lstrcmpW(szExpect
, buffer
) || !lstrcmpW(szServer
, buffer
), "cookie data wrong\n");
348 r
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONNECTED_STATE
, buffer
, &sz
);
349 ok(r
== TRUE
, "ret %d\n", r
);
352 static void test_version(void)
354 INTERNET_VERSION_INFO version
;
358 size
= sizeof(version
);
359 res
= InternetQueryOptionA(NULL
, INTERNET_OPTION_VERSION
, &version
, &size
);
360 ok(res
, "Could not get version: %u\n", GetLastError());
361 ok(version
.dwMajorVersion
== 1, "dwMajorVersion=%d, expected 1\n", version
.dwMajorVersion
);
362 ok(version
.dwMinorVersion
== 2, "dwMinorVersion=%d, expected 2\n", version
.dwMinorVersion
);
365 /* ############################### */
369 test_InternetCanonicalizeUrlA();
370 test_InternetQueryOptionA();