quartz: Fix discontinuities in wave parser.
[wine] / dlls / wininet / tests / internet.c
1 /*
2  * Wininet - internet tests
3  *
4  * Copyright 2005 Vijay Kiran Kamuju
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22 #include <string.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wininet.h"
26 #include "winerror.h"
27
28 #include "wine/test.h"
29
30 /* ############################### */
31
32 static void test_InternetCanonicalizeUrlA(void)
33 {
34     CHAR    buffer[256];
35     LPCSTR  url;
36     DWORD   urllen;
37     DWORD   dwSize;
38     DWORD   res;
39
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);
43
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));
52
53
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));
64
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));
75
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));
86
87
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));
97
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));
106
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));
115
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());
120 }
121
122 /* ############################### */
123
124 static void test_InternetQueryOptionA(void)
125 {
126   HINTERNET hinet,hurl;
127   DWORD len;
128   DWORD err;
129   static const char useragent[] = {"Wininet Test"};
130   char *buffer;
131   int retval;
132
133   hinet = InternetOpenA(useragent,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
134   ok((hinet != 0x0),"InternetOpen Failed\n");
135
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);
143
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)
151   {
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));
154   }
155   ok(err == 0xdeadbeef, "Got wrong error code %d\n",err);
156   HeapFree(GetProcessHeap(),0,buffer);
157
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);
167
168   hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
169
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);
177
178   InternetCloseHandle(hurl);
179   InternetCloseHandle(hinet);
180
181   hinet = InternetOpenA("",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL, 0);
182   ok((hinet != 0x0),"InternetOpen Failed\n");
183
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);
191
192   InternetCloseHandle(hinet);
193
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);
203
204   InternetCloseHandle(hinet);
205 }
206
207 static void test_get_cookie(void)
208 {
209   DWORD len;
210   BOOL ret;
211
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());
217 }
218
219 static void test_null(void)
220 {
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;
230
231   hi = InternetOpenW(NULL, 0, NULL, NULL, 0);
232   ok(hi != NULL, "open failed\n");
233
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");
237
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");
241
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");
245
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");
249
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");
253
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");
257
258   InternetCloseHandle(hi);
259
260   r = InternetSetCookieW(NULL, NULL, NULL);
261   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
262   ok(r == FALSE, "return wrong\n");
263
264   r = InternetSetCookieW(szServer, NULL, NULL);
265   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
266   ok(r == FALSE, "return wrong\n");
267
268   r = InternetSetCookieW(szUrl, szServer, NULL);
269   ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error\n");
270   ok(r == FALSE, "return wrong\n");
271
272   r = InternetSetCookieW(szUrl, szServer, szServer);
273   ok(r == TRUE, "return wrong\n");
274
275   r = InternetSetCookieW(szUrl, NULL, szServer);
276   ok(r == TRUE, "return wrong\n");
277
278   r = InternetSetCookieW(szUrl, szServer, szEmpty);
279   ok(r == TRUE, "return wrong\n");
280
281   r = InternetSetCookieW(szUrlEmpty, szServer, szServer);
282   ok(r == FALSE, "return wrong\n");
283
284   r = InternetSetCookieW(szServer, NULL, szServer);
285   todo_wine {
286   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
287   }
288   ok(r == FALSE, "return wrong\n");
289
290   sz = 0;
291   r = InternetGetCookieW(NULL, NULL, NULL, &sz);
292   ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME,
293      "wrong error %u\n", GetLastError());
294   ok( r == FALSE, "return wrong\n");
295
296   r = InternetGetCookieW(szServer, NULL, NULL, &sz);
297   todo_wine {
298   ok(GetLastError() == ERROR_INTERNET_UNRECOGNIZED_SCHEME, "wrong error\n");
299   }
300   ok( r == FALSE, "return wrong\n");
301
302   sz = 0;
303   r = InternetGetCookieW(szUrlEmpty, szServer, NULL, &sz);
304   ok( r == FALSE, "return wrong\n");
305
306   sz = 0;
307   r = InternetGetCookieW(szUrl, szServer, NULL, &sz);
308   ok( r == TRUE, "return wrong\n");
309
310   /* sz is 14 on XP SP2 and beyond, 30 on XP SP1 and before */
311   ok( sz == 14 || sz == 30, "sz wrong, got %u, expected 14 or 30\n", sz);
312
313   sz = 0x20;
314   memset(buffer, 0, sizeof buffer);
315   r = InternetGetCookieW(szUrl, szServer, buffer, &sz);
316   ok( r == TRUE, "return wrong\n");
317
318   /* sz == lstrlenW(buffer) only in XP SP1 */
319   ok( sz == 1 + lstrlenW(buffer) || sz == lstrlenW(buffer), "sz wrong %d\n", sz);
320
321   /* before XP SP2, buffer is "server; server" */
322   ok( !lstrcmpW(szExpect, buffer) || !lstrcmpW(szServer, buffer), "cookie data wrong\n");
323
324   sz = sizeof(buffer);
325   r = InternetQueryOptionA(NULL, INTERNET_OPTION_CONNECTED_STATE, buffer, &sz);
326   ok(r == TRUE, "ret %d\n", r);
327 }
328
329 static void test_version(void)
330 {
331     INTERNET_VERSION_INFO version;
332     DWORD size;
333     BOOL res;
334
335     size = sizeof(version);
336     res = InternetQueryOptionA(NULL, INTERNET_OPTION_VERSION, &version, &size);
337     ok(res, "Could not get version: %u\n", GetLastError());
338     ok(version.dwMajorVersion == 1, "dwMajorVersion=%d, expected 1\n", version.dwMajorVersion);
339     ok(version.dwMinorVersion == 2, "dwMinorVersion=%d, expected 2\n", version.dwMinorVersion);
340 }
341
342 /* ############################### */
343
344 START_TEST(internet)
345 {
346   test_InternetCanonicalizeUrlA();
347   test_InternetQueryOptionA();
348   test_get_cookie();
349   test_version();
350   test_null();
351 }