wininet: Make a test pass on IE6.
[wine/multimedia.git] / dlls / wininet / tests / http.c
blob0a02dfe9ed7deaa0b4c0c881bca9b8cb88f092c9
1 /*
2 * Wininet - Http tests
4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wininet.h"
30 #include "winsock.h"
32 #include "wine/test.h"
34 #define TEST_URL "http://www.winehq.org/site/about"
36 static BOOL first_connection_to_test_url = TRUE;
38 /* Adapted from dlls/urlmon/tests/protocol.c */
40 #define SET_EXPECT2(status, num) \
41 expect[status] = num
43 #define SET_EXPECT(status) \
44 SET_EXPECT2(status, 1)
46 /* SET_WINE_ALLOW's should be used with an appropriate
47 * todo_wine CHECK_NOTIFIED at a later point in the code */
48 #define SET_WINE_ALLOW2(status, num) \
49 wine_allow[status] = num
51 #define SET_WINE_ALLOW(status) \
52 SET_WINE_ALLOW2(status, 1)
54 #define CHECK_EXPECT(status) \
55 do { \
56 if (!expect[status] && wine_allow[status]) \
57 { \
58 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
59 status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
60 status_string[status] : "unknown"); \
61 wine_allow[status]--; \
62 } \
63 else \
64 { \
65 ok(expect[status], "unexpected status %d (%s)\n", status, \
66 status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
67 status_string[status] : "unknown"); \
68 expect[status]--; \
69 } \
70 notified[status]++; \
71 }while(0)
73 /* CLEAR_NOTIFIED used in cases when notification behavior
74 * differs between Windows versions */
75 #define CLEAR_NOTIFIED(status) \
76 expect[status] = wine_allow[status] = notified[status] = 0;
78 #define CHECK_NOTIFIED2(status, num) \
79 do { \
80 ok(notified[status] == (num), "expected status %d (%s) %d times, received %d times\n", \
81 status, status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
82 status_string[status] : "unknown", (num), notified[status]); \
83 CLEAR_NOTIFIED(status); \
84 }while(0)
86 #define CHECK_NOTIFIED(status) \
87 CHECK_NOTIFIED2(status, 1)
89 #define CHECK_NOT_NOTIFIED(status) \
90 CHECK_NOTIFIED2(status, 0)
92 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
93 #define MAX_STATUS_NAME 50
94 static int expect[MAX_INTERNET_STATUS], wine_allow[MAX_INTERNET_STATUS],
95 notified[MAX_INTERNET_STATUS];
96 static CHAR status_string[MAX_INTERNET_STATUS][MAX_STATUS_NAME];
98 static HANDLE hCompleteEvent;
100 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET ,INTERNET_STATUS_CALLBACK);
101 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
102 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
103 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
104 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
107 static VOID WINAPI callback(
108 HINTERNET hInternet,
109 DWORD_PTR dwContext,
110 DWORD dwInternetStatus,
111 LPVOID lpvStatusInformation,
112 DWORD dwStatusInformationLength
115 CHECK_EXPECT(dwInternetStatus);
116 switch (dwInternetStatus)
118 case INTERNET_STATUS_RESOLVING_NAME:
119 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
120 GetCurrentThreadId(), hInternet, dwContext,
121 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
122 *(LPSTR)lpvStatusInformation = '\0';
123 break;
124 case INTERNET_STATUS_NAME_RESOLVED:
125 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
126 GetCurrentThreadId(), hInternet, dwContext,
127 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
128 *(LPSTR)lpvStatusInformation = '\0';
129 break;
130 case INTERNET_STATUS_CONNECTING_TO_SERVER:
131 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
132 GetCurrentThreadId(), hInternet, dwContext,
133 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
134 *(LPSTR)lpvStatusInformation = '\0';
135 break;
136 case INTERNET_STATUS_CONNECTED_TO_SERVER:
137 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
138 GetCurrentThreadId(), hInternet, dwContext,
139 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
140 *(LPSTR)lpvStatusInformation = '\0';
141 break;
142 case INTERNET_STATUS_SENDING_REQUEST:
143 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
144 GetCurrentThreadId(), hInternet, dwContext,
145 lpvStatusInformation,dwStatusInformationLength);
146 break;
147 case INTERNET_STATUS_REQUEST_SENT:
148 ok(dwStatusInformationLength == sizeof(DWORD),
149 "info length should be sizeof(DWORD) instead of %d\n",
150 dwStatusInformationLength);
151 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
152 GetCurrentThreadId(), hInternet, dwContext,
153 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
154 break;
155 case INTERNET_STATUS_RECEIVING_RESPONSE:
156 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
157 GetCurrentThreadId(), hInternet, dwContext,
158 lpvStatusInformation,dwStatusInformationLength);
159 break;
160 case INTERNET_STATUS_RESPONSE_RECEIVED:
161 ok(dwStatusInformationLength == sizeof(DWORD),
162 "info length should be sizeof(DWORD) instead of %d\n",
163 dwStatusInformationLength);
164 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
165 GetCurrentThreadId(), hInternet, dwContext,
166 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
167 break;
168 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
169 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
170 GetCurrentThreadId(), hInternet,dwContext,
171 lpvStatusInformation,dwStatusInformationLength);
172 break;
173 case INTERNET_STATUS_PREFETCH:
174 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
175 GetCurrentThreadId(), hInternet, dwContext,
176 lpvStatusInformation,dwStatusInformationLength);
177 break;
178 case INTERNET_STATUS_CLOSING_CONNECTION:
179 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
180 GetCurrentThreadId(), hInternet, dwContext,
181 lpvStatusInformation,dwStatusInformationLength);
182 break;
183 case INTERNET_STATUS_CONNECTION_CLOSED:
184 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
185 GetCurrentThreadId(), hInternet, dwContext,
186 lpvStatusInformation,dwStatusInformationLength);
187 break;
188 case INTERNET_STATUS_HANDLE_CREATED:
189 ok(dwStatusInformationLength == sizeof(HINTERNET),
190 "info length should be sizeof(HINTERNET) instead of %d\n",
191 dwStatusInformationLength);
192 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
193 GetCurrentThreadId(), hInternet, dwContext,
194 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
195 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
196 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
197 break;
198 case INTERNET_STATUS_HANDLE_CLOSING:
199 ok(dwStatusInformationLength == sizeof(HINTERNET),
200 "info length should be sizeof(HINTERNET) instead of %d\n",
201 dwStatusInformationLength);
202 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
203 GetCurrentThreadId(), hInternet, dwContext,
204 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
205 break;
206 case INTERNET_STATUS_REQUEST_COMPLETE:
208 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
209 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
210 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
211 dwStatusInformationLength);
212 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
213 GetCurrentThreadId(), hInternet, dwContext,
214 iar->dwResult,iar->dwError,dwStatusInformationLength);
215 SetEvent(hCompleteEvent);
216 break;
218 case INTERNET_STATUS_REDIRECT:
219 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
220 GetCurrentThreadId(), hInternet, dwContext,
221 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
222 *(LPSTR)lpvStatusInformation = '\0';
223 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
224 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
225 break;
226 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
227 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
228 GetCurrentThreadId(), hInternet, dwContext,
229 lpvStatusInformation, dwStatusInformationLength);
230 break;
231 default:
232 trace("%04x:Callback %p 0x%lx %d %p %d\n",
233 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
234 lpvStatusInformation, dwStatusInformationLength);
238 static void InternetReadFile_test(int flags)
240 BOOL res;
241 DWORD rc;
242 CHAR buffer[4000];
243 DWORD length;
244 DWORD out;
245 const char *types[2] = { "*", NULL };
246 HINTERNET hi, hic = 0, hor = 0;
248 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
250 trace("Starting InternetReadFile test with flags 0x%x\n",flags);
252 trace("InternetOpenA <--\n");
253 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
254 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
255 trace("InternetOpenA -->\n");
257 if (hi == 0x0) goto abort;
259 pInternetSetStatusCallbackA(hi,&callback);
261 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
263 trace("InternetConnectA <--\n");
264 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
265 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
266 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
267 trace("InternetConnectA -->\n");
269 if (hic == 0x0) goto abort;
271 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
272 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
273 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME);
274 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED);
276 trace("HttpOpenRequestA <--\n");
277 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
278 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
279 0xdeadbead);
280 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
282 * If the internet name can't be resolved we are probably behind
283 * a firewall or in some other way not directly connected to the
284 * Internet. Not enough reason to fail the test. Just ignore and
285 * abort.
287 } else {
288 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
290 trace("HttpOpenRequestA -->\n");
292 if (hor == 0x0) goto abort;
294 length = sizeof(buffer);
295 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
296 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
297 ok(!strcmp(buffer, "http://www.winehq.org/about/"), "Wrong URL %s\n", buffer);
299 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
300 todo_wine
302 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
303 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
305 if (first_connection_to_test_url)
307 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
308 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
310 else
312 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME);
313 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED);
315 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER);
316 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
317 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER);
318 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
319 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
320 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
321 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
322 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
323 SET_EXPECT(INTERNET_STATUS_REDIRECT);
324 if (flags & INTERNET_FLAG_ASYNC)
325 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
326 else
327 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
329 trace("HttpSendRequestA -->\n");
330 SetLastError(0xdeadbeef);
331 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
332 if (flags & INTERNET_FLAG_ASYNC)
333 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
334 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
335 else
336 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
337 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
338 trace("HttpSendRequestA <--\n");
340 if (flags & INTERNET_FLAG_ASYNC)
341 WaitForSingleObject(hCompleteEvent, INFINITE);
343 if (first_connection_to_test_url)
345 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
346 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
348 else todo_wine
350 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
351 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
353 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
354 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
355 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
356 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
357 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
358 if (flags & INTERNET_FLAG_ASYNC)
359 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
360 else
361 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
362 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
363 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
364 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
366 length = 4;
367 rc = InternetQueryOptionA(hor,INTERNET_OPTION_REQUEST_FLAGS,&out,&length);
368 trace("Option 0x17 -> %i %i\n",rc,out);
370 length = 100;
371 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
372 trace("Option 0x22 -> %i %s\n",rc,buffer);
374 length = 4000;
375 rc = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
376 buffer[length]=0;
377 trace("Option 0x16 -> %i %s\n",rc,buffer);
379 length = sizeof(buffer);
380 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
381 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
382 ok(!strcmp(buffer, "http://www.winehq.org/site/about"), "Wrong URL %s\n", buffer);
384 length = 16;
385 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
386 trace("Option 0x5 -> %i %s (%u)\n",rc,buffer,GetLastError());
388 length = 100;
389 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
390 buffer[length]=0;
391 trace("Option 0x1 -> %i %s\n",rc,buffer);
393 SetLastError(0xdeadbeef);
394 rc = InternetReadFile(NULL, buffer, 100, &length);
395 ok(!rc, "InternetReadFile should have failed\n");
396 ok(GetLastError() == ERROR_INVALID_HANDLE,
397 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
398 GetLastError());
400 length = 100;
401 trace("Entering Query loop\n");
403 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
404 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
405 while (TRUE)
407 if (flags & INTERNET_FLAG_ASYNC)
408 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
409 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
410 ok(!(rc == 0 && length != 0),"InternetQueryDataAvailable failed with non-zero length\n");
411 ok(rc != 0 || ((flags & INTERNET_FLAG_ASYNC) && GetLastError() == ERROR_IO_PENDING),
412 "InternetQueryDataAvailable failed, error %d\n", GetLastError());
413 if (flags & INTERNET_FLAG_ASYNC)
415 if (rc != 0)
417 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
419 else if (GetLastError() == ERROR_IO_PENDING)
421 WaitForSingleObject(hCompleteEvent, INFINITE);
422 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
423 continue;
426 if (length)
428 char *buffer;
429 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
431 rc = InternetReadFile(hor,buffer,length,&length);
433 buffer[length]=0;
435 trace("ReadFile -> %i %i\n",rc,length);
437 HeapFree(GetProcessHeap(),0,buffer);
439 if (length == 0)
440 break;
442 /* WinXP does not send, but Win98 does */
443 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
444 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
445 abort:
446 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
447 if (hor != 0x0) {
448 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
449 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
450 SetLastError(0xdeadbeef);
451 rc = InternetCloseHandle(hor);
452 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
453 SetLastError(0xdeadbeef);
454 rc = InternetCloseHandle(hor);
455 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
456 ok (GetLastError() == ERROR_INVALID_HANDLE,
457 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %u\n",
458 GetLastError());
460 /* We intentionally do not close the handle opened by InternetConnectA as this
461 * tickles bug #9479: native closes child internet handles when the parent handles
462 * are closed. This is verified below by checking that the number of
463 * INTERNET_STATUS_HANDLE_CLOSING notifications matches the number expected. */
464 if (hi != 0x0) {
465 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING);
466 rc = InternetCloseHandle(hi);
467 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
468 if (flags & INTERNET_FLAG_ASYNC)
469 Sleep(100);
471 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
472 if (hor != 0x0) todo_wine
474 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
475 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
477 else
479 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
480 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
482 CloseHandle(hCompleteEvent);
483 first_connection_to_test_url = FALSE;
486 static void InternetReadFileExA_test(int flags)
488 DWORD rc;
489 DWORD length;
490 const char *types[2] = { "*", NULL };
491 HINTERNET hi, hic = 0, hor = 0;
492 INTERNET_BUFFERS inetbuffers;
494 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
496 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
498 trace("InternetOpenA <--\n");
499 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
500 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
501 trace("InternetOpenA -->\n");
503 if (hi == 0x0) goto abort;
505 pInternetSetStatusCallbackA(hi,&callback);
507 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
509 trace("InternetConnectA <--\n");
510 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
511 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
512 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
513 trace("InternetConnectA -->\n");
515 if (hic == 0x0) goto abort;
517 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
518 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
519 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME);
520 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED);
522 trace("HttpOpenRequestA <--\n");
523 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
524 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
525 0xdeadbead);
526 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
528 * If the internet name can't be resolved we are probably behind
529 * a firewall or in some other way not directly connected to the
530 * Internet. Not enough reason to fail the test. Just ignore and
531 * abort.
533 } else {
534 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
536 trace("HttpOpenRequestA -->\n");
538 if (hor == 0x0) goto abort;
540 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
541 todo_wine
543 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
544 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
546 if (first_connection_to_test_url)
548 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
549 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
551 else
553 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME);
554 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED);
556 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER);
557 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
558 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER);
559 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
560 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
561 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
562 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
563 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
564 SET_EXPECT(INTERNET_STATUS_REDIRECT);
565 if (flags & INTERNET_FLAG_ASYNC)
566 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
567 else
568 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
570 trace("HttpSendRequestA -->\n");
571 SetLastError(0xdeadbeef);
572 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
573 if (flags & INTERNET_FLAG_ASYNC)
574 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
575 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
576 else
577 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
578 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
579 trace("HttpSendRequestA <--\n");
581 if (!rc && (GetLastError() == ERROR_IO_PENDING))
582 WaitForSingleObject(hCompleteEvent, INFINITE);
584 if (first_connection_to_test_url)
586 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
587 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
589 else todo_wine
591 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
592 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
594 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
595 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
596 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
597 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
598 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
599 if (flags & INTERNET_FLAG_ASYNC)
600 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
601 else
602 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
603 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
604 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
605 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
607 /* tests invalid dwStructSize */
608 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
609 inetbuffers.lpcszHeader = NULL;
610 inetbuffers.dwHeadersLength = 0;
611 inetbuffers.dwBufferLength = 10;
612 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
613 inetbuffers.dwOffsetHigh = 1234;
614 inetbuffers.dwOffsetLow = 5678;
615 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
616 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
617 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
618 rc ? "TRUE" : "FALSE", GetLastError());
619 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
621 /* tests to see whether lpcszHeader is used - it isn't */
622 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
623 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
624 inetbuffers.dwHeadersLength = 255;
625 inetbuffers.dwBufferLength = 0;
626 inetbuffers.lpvBuffer = NULL;
627 inetbuffers.dwOffsetHigh = 1234;
628 inetbuffers.dwOffsetLow = 5678;
629 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
630 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
631 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
632 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
633 todo_wine
635 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
636 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
639 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
640 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
641 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
642 rc ? "TRUE" : "FALSE", GetLastError());
644 length = 0;
645 trace("Entering Query loop\n");
647 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
648 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
649 while (TRUE)
651 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
652 inetbuffers.dwBufferLength = 1024;
653 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
654 inetbuffers.dwOffsetHigh = 1234;
655 inetbuffers.dwOffsetLow = 5678;
657 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
658 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
659 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
660 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
661 if (!rc)
663 if (GetLastError() == ERROR_IO_PENDING)
665 trace("InternetReadFileEx -> PENDING\n");
666 ok(flags & INTERNET_FLAG_ASYNC,
667 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
668 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
669 WaitForSingleObject(hCompleteEvent, INFINITE);
670 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
671 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
673 else
675 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
676 break;
679 else
681 trace("InternetReadFileEx -> SUCCEEDED\n");
682 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
683 if (inetbuffers.dwBufferLength)
685 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
686 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
688 else
690 /* Win98 still sends these when 0 bytes are read, WinXP does not */
691 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
692 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
696 trace("read %i bytes\n", inetbuffers.dwBufferLength);
697 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
699 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
700 "InternetReadFileEx sets offsets to 0x%x%08x\n",
701 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
703 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
705 if (!inetbuffers.dwBufferLength)
706 break;
708 length += inetbuffers.dwBufferLength;
710 ok(length > 0, "failed to read any of the document\n");
711 trace("Finished. Read %d bytes\n", length);
713 /* WinXP does not send, but Win98 does */
714 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
715 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
716 abort:
717 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
718 if (hor) {
719 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
720 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
721 rc = InternetCloseHandle(hor);
722 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
723 rc = InternetCloseHandle(hor);
724 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
726 if (hic) {
727 rc = InternetCloseHandle(hic);
728 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
730 if (hi) {
731 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING);
732 rc = InternetCloseHandle(hi);
733 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
734 if (flags & INTERNET_FLAG_ASYNC)
735 Sleep(100);
736 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
738 if (hor != 0x0) todo_wine
740 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
741 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
743 else
745 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
746 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
748 CloseHandle(hCompleteEvent);
749 first_connection_to_test_url = FALSE;
752 static void InternetOpenUrlA_test(void)
754 HINTERNET myhinternet, myhttp;
755 char buffer[0x400];
756 DWORD size, readbytes, totalbytes=0;
757 BOOL ret;
759 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
760 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
761 size = 0x400;
762 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
763 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
765 SetLastError(0);
766 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
767 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
768 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
769 return; /* WinXP returns this when not connected to the net */
770 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
771 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
772 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
773 totalbytes += readbytes;
774 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
775 totalbytes += readbytes;
776 trace("read 0x%08x bytes\n",totalbytes);
778 InternetCloseHandle(myhttp);
779 InternetCloseHandle(myhinternet);
782 static void InternetTimeFromSystemTimeA_test(void)
784 BOOL ret;
785 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
786 char string[INTERNET_RFC1123_BUFSIZE];
787 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
789 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
790 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
792 ok( !memcmp( string, expect, sizeof(expect) ),
793 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
796 static void InternetTimeFromSystemTimeW_test(void)
798 BOOL ret;
799 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
800 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
801 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
802 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
804 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
805 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
807 ok( !memcmp( string, expect, sizeof(expect) ),
808 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
811 static void InternetTimeToSystemTimeA_test(void)
813 BOOL ret;
814 SYSTEMTIME time;
815 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
816 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
817 static const char string2[] = " fri 7 jan 2005 12 06 35";
819 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
820 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
821 ok( !memcmp( &time, &expect, sizeof(expect) ),
822 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
824 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
825 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
826 ok( !memcmp( &time, &expect, sizeof(expect) ),
827 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
830 static void InternetTimeToSystemTimeW_test(void)
832 BOOL ret;
833 SYSTEMTIME time;
834 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
835 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
836 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
837 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
838 '1','2',' ','0','6',' ','3','5',0 };
839 static const WCHAR string3[] = { 'F','r',0 };
841 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
842 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
844 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
845 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
847 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
848 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
850 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
851 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
853 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
854 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
855 ok( !memcmp( &time, &expect, sizeof(expect) ),
856 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
858 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
859 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
860 ok( !memcmp( &time, &expect, sizeof(expect) ),
861 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
863 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
864 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
867 static void HttpSendRequestEx_test(void)
869 HINTERNET hSession;
870 HINTERNET hConnect;
871 HINTERNET hRequest;
873 INTERNET_BUFFERS BufferIn;
874 DWORD dwBytesWritten;
875 DWORD dwBytesRead;
876 CHAR szBuffer[256];
877 int i;
878 BOOL ret;
880 static char szPostData[] = "mode=Test";
881 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
883 hSession = InternetOpen("Wine Regression Test",
884 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
885 ok( hSession != NULL ,"Unable to open Internet session\n");
886 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
887 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
889 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
890 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
891 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
892 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
894 trace( "Network unreachable, skipping test\n" );
895 goto done;
897 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
900 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
901 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
902 BufferIn.lpcszHeader = szContentType;
903 BufferIn.dwHeadersLength = sizeof(szContentType)-1;
904 BufferIn.dwHeadersTotal = sizeof(szContentType)-1;
905 BufferIn.lpvBuffer = szPostData;
906 BufferIn.dwBufferLength = 3;
907 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
908 BufferIn.dwOffsetLow = 0;
909 BufferIn.dwOffsetHigh = 0;
911 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
912 ok(ret, "HttpSendRequestEx Failed with error %u\n", GetLastError());
914 for (i = 3; szPostData[i]; i++)
915 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
916 "InternetWriteFile failed\n");
918 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
920 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
921 "Unable to read response\n");
922 szBuffer[dwBytesRead] = 0;
924 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
925 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0,"Got string %s\n",szBuffer);
927 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
928 done:
929 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
930 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
933 static void InternetOpenRequest_test(void)
935 HINTERNET session, connect, request;
936 static const char *types[] = { "*", "", NULL };
937 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
938 static const WCHAR *typesW[] = { any, empty, NULL };
939 BOOL ret;
941 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
942 ok(session != NULL ,"Unable to open Internet session\n");
944 connect = InternetConnectA(session, NULL, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
945 INTERNET_SERVICE_HTTP, 0, 0);
946 ok(connect == NULL, "InternetConnectA should have failed\n");
947 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
949 connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
950 INTERNET_SERVICE_HTTP, 0, 0);
951 ok(connect == NULL, "InternetConnectA should have failed\n");
952 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
954 connect = InternetConnectA(session, "winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
955 INTERNET_SERVICE_HTTP, 0, 0);
956 ok(connect != NULL, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
958 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
959 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
961 trace( "Network unreachable, skipping test\n" );
962 goto done;
964 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
966 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
967 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
968 ok(InternetCloseHandle(request), "Close request handle failed\n");
970 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
971 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
973 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
974 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
975 ok(InternetCloseHandle(request), "Close request handle failed\n");
977 done:
978 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
979 ok(InternetCloseHandle(session), "Close session handle failed\n");
982 static void test_http_cache(void)
984 HINTERNET session, connect, request;
985 char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH];
986 DWORD size, file_size;
987 BYTE buf[100];
988 HANDLE file;
989 BOOL ret;
991 static const char *types[] = { "*", "", NULL };
993 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
994 ok(session != NULL ,"Unable to open Internet session\n");
996 connect = InternetConnectA(session, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
997 INTERNET_SERVICE_HTTP, 0, 0);
998 ok(connect != NULL, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
1000 request = HttpOpenRequestA(connect, NULL, "/site/about", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0);
1001 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1003 trace( "Network unreachable, skipping test\n" );
1005 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1006 ok(InternetCloseHandle(session), "Close session handle failed\n");
1008 return;
1010 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1012 size = sizeof(url);
1013 ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size);
1014 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_url) failed: %u\n", GetLastError());
1015 ok(!strcmp(url, "http://www.winehq.org/site/about"), "Wrong URL %s\n", url);
1017 size = sizeof(file_name);
1018 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1019 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1020 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1021 ok(!size, "size = %d\n", size);
1023 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1024 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1026 size = sizeof(file_name);
1027 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1028 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1030 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1031 FILE_ATTRIBUTE_NORMAL, NULL);
1032 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1033 file_size = GetFileSize(file, NULL);
1034 ok(file_size == 0, "file size=%d\n", file_size);
1036 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1037 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1038 ok(size == sizeof(buf), "size=%d\n", size);
1040 file_size = GetFileSize(file, NULL);
1041 ok(file_size == sizeof(buf), "file size=%d\n", file_size);
1042 CloseHandle(file);
1044 ok(InternetCloseHandle(request), "Close request handle failed\n");
1046 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1047 FILE_ATTRIBUTE_NORMAL, NULL);
1048 ok(file == INVALID_HANDLE_VALUE, "CreateFile succeeded\n");
1049 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1051 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1052 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1054 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1055 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1056 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1057 ok(!size, "size = %d\n", size);
1059 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1060 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1062 size = sizeof(file_name);
1063 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1064 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1065 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1066 ok(!size, "size = %d\n", size);
1068 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1069 FILE_ATTRIBUTE_NORMAL, NULL);
1070 ok(file == INVALID_HANDLE_VALUE, "CreateFile succeeded\n");
1071 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1073 ok(InternetCloseHandle(request), "Close request handle failed\n");
1075 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1076 ok(InternetCloseHandle(session), "Close session handle failed\n");
1079 static void HttpHeaders_test(void)
1081 HINTERNET hSession;
1082 HINTERNET hConnect;
1083 HINTERNET hRequest;
1084 CHAR buffer[256];
1085 DWORD len = 256;
1086 DWORD index = 0;
1088 hSession = InternetOpen("Wine Regression Test",
1089 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1090 ok( hSession != NULL ,"Unable to open Internet session\n");
1091 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
1092 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1094 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1095 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
1096 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1097 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1099 trace( "Network unreachable, skipping test\n" );
1100 goto done;
1102 ok( hRequest != NULL, "Failed to open request handle\n");
1104 index = 0;
1105 len = sizeof(buffer);
1106 strcpy(buffer,"Warning");
1107 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1108 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1110 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1111 "Failed to add new header\n");
1113 index = 0;
1114 len = sizeof(buffer);
1115 strcpy(buffer,"Warning");
1116 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1117 buffer,&len,&index),"Unable to query header\n");
1118 ok(index == 1, "Index was not incremented\n");
1119 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1120 ok(len == 5, "Invalid length (exp. 5, got %d)\n", len);
1121 ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1122 len = sizeof(buffer);
1123 strcpy(buffer,"Warning");
1124 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1125 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1127 index = 0;
1128 len = 5; /* could store the string but not the NULL terminator */
1129 strcpy(buffer,"Warning");
1130 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1131 buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n");
1132 ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */
1133 ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
1135 /* a call with NULL will fail but will return the length */
1136 index = 0;
1137 len = sizeof(buffer);
1138 SetLastError(0xdeadbeef);
1139 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1140 NULL,&len,&index) == FALSE,"Query worked\n");
1141 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1142 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1143 ok(index == 0, "Index was incremented\n");
1145 /* even for a len that is too small */
1146 index = 0;
1147 len = 15;
1148 SetLastError(0xdeadbeef);
1149 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1150 NULL,&len,&index) == FALSE,"Query worked\n");
1151 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1152 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1153 ok(index == 0, "Index was incremented\n");
1155 index = 0;
1156 len = 0;
1157 SetLastError(0xdeadbeef);
1158 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1159 NULL,&len,&index) == FALSE,"Query worked\n");
1160 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1161 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1162 ok(index == 0, "Index was incremented\n");
1165 /* a working query */
1166 index = 0;
1167 len = sizeof(buffer);
1168 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1169 buffer,&len,&index),"Unable to query header\n");
1170 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1171 ok(strncmp(buffer, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1172 ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1173 ok(index == 0, "Index was incremented\n");
1177 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1178 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1180 index = 0;
1181 len = sizeof(buffer);
1182 strcpy(buffer,"Warning");
1183 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1184 buffer,&len,&index),"Unable to query header\n");
1185 ok(index == 1, "Index was not incremented\n");
1186 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1187 len = sizeof(buffer);
1188 strcpy(buffer,"Warning");
1189 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1190 buffer,&len,&index),"Failed to get second header\n");
1191 ok(index == 2, "Index was not incremented\n");
1192 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1193 len = sizeof(buffer);
1194 strcpy(buffer,"Warning");
1195 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1196 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1198 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1200 index = 0;
1201 len = sizeof(buffer);
1202 strcpy(buffer,"Warning");
1203 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1204 buffer,&len,&index),"Unable to query header\n");
1205 ok(index == 1, "Index was not incremented\n");
1206 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1207 len = sizeof(buffer);
1208 strcpy(buffer,"Warning");
1209 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1210 buffer,&len,&index),"Failed to get second header\n");
1211 ok(index == 2, "Index was not incremented\n");
1212 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1213 len = sizeof(buffer);
1214 strcpy(buffer,"Warning");
1215 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1216 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1218 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1220 index = 0;
1221 len = sizeof(buffer);
1222 strcpy(buffer,"Warning");
1223 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1224 buffer,&len,&index),"Unable to query header\n");
1225 ok(index == 1, "Index was not incremented\n");
1226 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1227 len = sizeof(buffer);
1228 strcpy(buffer,"Warning");
1229 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1230 buffer,&len,&index),"Failed to get second header\n");
1231 ok(index == 2, "Index was not incremented\n");
1232 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1233 len = sizeof(buffer);
1234 strcpy(buffer,"Warning");
1235 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1236 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1238 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1240 index = 0;
1241 len = sizeof(buffer);
1242 strcpy(buffer,"Warning");
1243 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1244 buffer,&len,&index),"Unable to query header\n");
1245 ok(index == 1, "Index was not incremented\n");
1246 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1247 len = sizeof(buffer);
1248 strcpy(buffer,"Warning");
1249 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1250 ok(index == 2, "Index was not incremented\n");
1251 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1252 len = sizeof(buffer);
1253 strcpy(buffer,"Warning");
1254 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1256 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1258 index = 0;
1259 len = sizeof(buffer);
1260 strcpy(buffer,"Warning");
1261 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1262 ok(index == 1, "Index was not incremented\n");
1263 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1264 len = sizeof(buffer);
1265 strcpy(buffer,"Warning");
1266 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1267 ok(index == 2, "Index was not incremented\n");
1268 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1269 len = sizeof(buffer);
1270 strcpy(buffer,"Warning");
1271 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1273 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1275 index = 0;
1276 len = sizeof(buffer);
1277 strcpy(buffer,"Warning");
1278 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1279 ok(index == 1, "Index was not incremented\n");
1280 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1281 len = sizeof(buffer);
1282 strcpy(buffer,"Warning");
1283 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1284 ok(index == 2, "Index was not incremented\n");
1285 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1286 len = sizeof(buffer);
1287 strcpy(buffer,"Warning");
1288 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1290 ok(HttpAddRequestHeaders(hRequest,"Warning:test7",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE), "HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work\n");
1292 index = 0;
1293 len = sizeof(buffer);
1294 strcpy(buffer,"Warning");
1295 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1296 ok(index == 1, "Index was not incremented\n");
1297 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1298 len = sizeof(buffer);
1299 strcpy(buffer,"Warning");
1300 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1301 ok(index == 2, "Index was not incremented\n");
1302 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
1303 len = sizeof(buffer);
1304 strcpy(buffer,"Warning");
1305 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1308 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1309 done:
1310 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1311 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1314 static const char contmsg[] =
1315 "HTTP/1.1 100 Continue\r\n";
1317 static const char okmsg[] =
1318 "HTTP/1.1 200 OK\r\n"
1319 "Server: winetest\r\n"
1320 "\r\n";
1322 static const char notokmsg[] =
1323 "HTTP/1.1 400 Bad Request\r\n"
1324 "Server: winetest\r\n"
1325 "\r\n";
1327 static const char noauthmsg[] =
1328 "HTTP/1.1 401 Unauthorized\r\n"
1329 "Server: winetest\r\n"
1330 "\r\n";
1332 static const char proxymsg[] =
1333 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1334 "Server: winetest\r\n"
1335 "Proxy-Connection: close\r\n"
1336 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1337 "\r\n";
1339 static const char page1[] =
1340 "<HTML>\r\n"
1341 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1342 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1343 "</HTML>\r\n\r\n";
1345 struct server_info {
1346 HANDLE hEvent;
1347 int port;
1350 static DWORD CALLBACK server_thread(LPVOID param)
1352 struct server_info *si = param;
1353 int r, c, i, on;
1354 SOCKET s;
1355 struct sockaddr_in sa;
1356 char buffer[0x100];
1357 WSADATA wsaData;
1358 int last_request = 0;
1360 WSAStartup(MAKEWORD(1,1), &wsaData);
1362 s = socket(AF_INET, SOCK_STREAM, 0);
1363 if (s == INVALID_SOCKET)
1364 return 1;
1366 on = 1;
1367 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
1369 memset(&sa, 0, sizeof sa);
1370 sa.sin_family = AF_INET;
1371 sa.sin_port = htons(si->port);
1372 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
1374 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
1375 if (r<0)
1376 return 1;
1378 listen(s, 0);
1380 SetEvent(si->hEvent);
1384 c = accept(s, NULL, NULL);
1386 memset(buffer, 0, sizeof buffer);
1387 for(i=0; i<(sizeof buffer-1); i++)
1389 r = recv(c, &buffer[i], 1, 0);
1390 if (r != 1)
1391 break;
1392 if (i<4) continue;
1393 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
1394 buffer[i-3] == '\r' && buffer[i-1] == '\r')
1395 break;
1398 if (strstr(buffer, "GET /test1"))
1400 if (!strstr(buffer, "Content-Length: 0"))
1402 send(c, okmsg, sizeof okmsg-1, 0);
1403 send(c, page1, sizeof page1-1, 0);
1405 else
1406 send(c, notokmsg, sizeof notokmsg-1, 0);
1409 if (strstr(buffer, "/test2"))
1411 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1413 send(c, okmsg, sizeof okmsg-1, 0);
1414 send(c, page1, sizeof page1-1, 0);
1416 else
1417 send(c, proxymsg, sizeof proxymsg-1, 0);
1420 if (strstr(buffer, "/test3"))
1422 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
1423 send(c, okmsg, sizeof okmsg-1, 0);
1424 else
1425 send(c, noauthmsg, sizeof noauthmsg-1, 0);
1428 if (strstr(buffer, "/test4"))
1430 if (strstr(buffer, "Connection: Close"))
1431 send(c, okmsg, sizeof okmsg-1, 0);
1432 else
1433 send(c, notokmsg, sizeof notokmsg-1, 0);
1436 if (strstr(buffer, "POST /test5"))
1438 if (strstr(buffer, "Content-Length: 0"))
1440 send(c, okmsg, sizeof okmsg-1, 0);
1441 send(c, page1, sizeof page1-1, 0);
1443 else
1444 send(c, notokmsg, sizeof notokmsg-1, 0);
1447 if (strstr(buffer, "GET /test6"))
1449 send(c, contmsg, sizeof contmsg-1, 0);
1450 send(c, contmsg, sizeof contmsg-1, 0);
1451 send(c, okmsg, sizeof okmsg-1, 0);
1452 send(c, page1, sizeof page1-1, 0);
1455 if (strstr(buffer, "POST /test7"))
1457 if (strstr(buffer, "Content-Length: 100"))
1459 send(c, okmsg, sizeof okmsg-1, 0);
1460 send(c, page1, sizeof page1-1, 0);
1462 else
1463 send(c, notokmsg, sizeof notokmsg-1, 0);
1466 if (strstr(buffer, "GET /quit"))
1468 send(c, okmsg, sizeof okmsg-1, 0);
1469 send(c, page1, sizeof page1-1, 0);
1470 last_request = 1;
1473 shutdown(c, 2);
1474 closesocket(c);
1475 } while (!last_request);
1477 closesocket(s);
1479 return 0;
1482 static void test_basic_request(int port, const char *verb, const char *url)
1484 HINTERNET hi, hc, hr;
1485 DWORD r, count;
1486 char buffer[0x100];
1488 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1489 ok(hi != NULL, "open failed\n");
1491 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1492 ok(hc != NULL, "connect failed\n");
1494 hr = HttpOpenRequest(hc, verb, url, NULL, NULL, NULL, 0, 0);
1495 ok(hr != NULL, "HttpOpenRequest failed\n");
1497 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1498 ok(r, "HttpSendRequest failed\n");
1500 count = 0;
1501 memset(buffer, 0, sizeof buffer);
1502 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
1503 ok(r, "InternetReadFile failed\n");
1504 ok(count == sizeof page1 - 1, "count was wrong\n");
1505 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
1507 InternetCloseHandle(hr);
1508 InternetCloseHandle(hc);
1509 InternetCloseHandle(hi);
1512 static void test_proxy_indirect(int port)
1514 HINTERNET hi, hc, hr;
1515 DWORD r, sz, val;
1516 char buffer[0x40];
1518 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
1519 ok(hi != NULL, "open failed\n");
1521 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1522 ok(hc != NULL, "connect failed\n");
1524 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1525 ok(hr != NULL, "HttpOpenRequest failed\n");
1527 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1528 ok(r, "HttpSendRequest failed\n");
1530 sz = sizeof buffer;
1531 r = HttpQueryInfo(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
1532 ok(r, "HttpQueryInfo failed\n");
1533 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1535 sz = sizeof buffer;
1536 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1537 ok(r, "HttpQueryInfo failed\n");
1538 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1540 sz = sizeof val;
1541 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &val, &sz, NULL);
1542 ok(r, "HttpQueryInfo failed\n");
1543 ok(val == 407, "proxy code wrong\n");
1545 sz = sizeof buffer;
1546 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
1547 ok(r, "HttpQueryInfo failed\n");
1548 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
1550 sz = sizeof buffer;
1551 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
1552 ok(r, "HttpQueryInfo failed\n");
1553 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
1555 sz = sizeof buffer;
1556 r = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
1557 ok(r, "HttpQueryInfo failed\n");
1558 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
1560 sz = sizeof buffer;
1561 r = HttpQueryInfo(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
1562 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
1563 ok(r == FALSE, "HttpQueryInfo failed\n");
1565 InternetCloseHandle(hr);
1566 InternetCloseHandle(hc);
1567 InternetCloseHandle(hi);
1570 static void test_proxy_direct(int port)
1572 HINTERNET hi, hc, hr;
1573 DWORD r, sz;
1574 char buffer[0x40];
1575 static CHAR username[] = "mike",
1576 password[] = "1101";
1578 sprintf(buffer, "localhost:%d\n", port);
1579 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
1580 ok(hi != NULL, "open failed\n");
1582 /* try connect without authorization */
1583 hc = InternetConnect(hi, "www.winehq.org/", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1584 ok(hc != NULL, "connect failed\n");
1586 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1587 ok(hr != NULL, "HttpOpenRequest failed\n");
1589 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1590 ok(r, "HttpSendRequest failed\n");
1592 sz = sizeof buffer;
1593 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1594 ok(r, "HttpQueryInfo failed\n");
1595 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1598 /* set the user + password then try again */
1599 todo_wine {
1600 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
1601 ok(r, "failed to set user\n");
1603 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
1604 ok(r, "failed to set password\n");
1607 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1608 ok(r, "HttpSendRequest failed\n");
1609 sz = sizeof buffer;
1610 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1611 ok(r, "HttpQueryInfo failed\n");
1612 todo_wine {
1613 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
1617 InternetCloseHandle(hr);
1618 InternetCloseHandle(hc);
1619 InternetCloseHandle(hi);
1622 static void test_header_handling_order(int port)
1624 static char authorization[] = "Authorization: Basic dXNlcjpwd2Q=";
1625 static char connection[] = "Connection: Close";
1627 static const char *types[2] = { "*", NULL };
1628 HINTERNET session, connect, request;
1629 DWORD size, status;
1630 BOOL ret;
1632 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1633 ok(session != NULL, "InternetOpen failed\n");
1635 connect = InternetConnect(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1636 ok(connect != NULL, "InternetConnect failed\n");
1638 request = HttpOpenRequest(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
1639 ok(request != NULL, "HttpOpenRequest failed\n");
1641 ret = HttpAddRequestHeaders(request, authorization, ~0UL, HTTP_ADDREQ_FLAG_ADD);
1642 ok(ret, "HttpAddRequestHeaders failed\n");
1644 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1645 ok(ret, "HttpSendRequest failed\n");
1647 status = 0;
1648 size = sizeof(status);
1649 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
1650 ok(ret, "HttpQueryInfo failed\n");
1651 ok(status == 200, "request failed with status %u\n", status);
1653 InternetCloseHandle(request);
1655 request = HttpOpenRequest(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
1656 ok(request != NULL, "HttpOpenRequest failed\n");
1658 ret = HttpSendRequest(request, connection, ~0UL, NULL, 0);
1659 ok(ret, "HttpSendRequest failed\n");
1661 status = 0;
1662 size = sizeof(status);
1663 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
1664 ok(ret, "HttpQueryInfo failed\n");
1665 ok(status == 200, "request failed with status %u\n", status);
1667 InternetCloseHandle(request);
1669 request = HttpOpenRequest(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
1670 ok(request != NULL, "HttpOpenRequest failed\n");
1672 ret = HttpAddRequestHeaders(request, "Content-Length: 100\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
1673 ok(ret, "HttpAddRequestHeaders failed\n");
1675 ret = HttpSendRequest(request, connection, ~0UL, NULL, 0);
1676 ok(ret, "HttpSendRequest failed\n");
1678 status = 0;
1679 size = sizeof(status);
1680 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
1681 ok(ret, "HttpQueryInfo failed\n");
1682 ok(status == 200, "request failed with status %u\n", status);
1684 InternetCloseHandle(request);
1685 InternetCloseHandle(connect);
1686 InternetCloseHandle(session);
1689 static void test_http_connection(void)
1691 struct server_info si;
1692 HANDLE hThread;
1693 DWORD id = 0, r;
1695 si.hEvent = CreateEvent(NULL, 0, 0, NULL);
1696 si.port = 7531;
1698 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
1699 ok( hThread != NULL, "create thread failed\n");
1701 r = WaitForSingleObject(si.hEvent, 10000);
1702 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
1703 if (r != WAIT_OBJECT_0)
1704 return;
1706 test_basic_request(si.port, "GET", "/test1");
1707 test_proxy_indirect(si.port);
1708 test_proxy_direct(si.port);
1709 test_header_handling_order(si.port);
1710 test_basic_request(si.port, "POST", "/test5");
1711 test_basic_request(si.port, "GET", "/test6");
1713 /* send the basic request again to shutdown the server thread */
1714 test_basic_request(si.port, "GET", "/quit");
1716 r = WaitForSingleObject(hThread, 3000);
1717 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
1718 CloseHandle(hThread);
1721 static void test_user_agent_header(void)
1723 HINTERNET ses, con, req;
1724 DWORD size, err;
1725 char buffer[64];
1726 BOOL ret;
1728 ses = InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1729 ok(ses != NULL, "InternetOpen failed\n");
1731 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1732 ok(con != NULL, "InternetConnect failed\n");
1734 req = HttpOpenRequest(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
1735 ok(req != NULL, "HttpOpenRequest failed\n");
1737 size = sizeof(buffer);
1738 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1739 err = GetLastError();
1740 ok(!ret, "HttpQueryInfo succeeded\n");
1741 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
1743 ret = HttpAddRequestHeaders(req, "User-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
1744 ok(ret, "HttpAddRequestHeaders succeeded\n");
1746 size = sizeof(buffer);
1747 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1748 err = GetLastError();
1749 ok(ret, "HttpQueryInfo failed\n");
1750 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
1752 InternetCloseHandle(req);
1754 req = HttpOpenRequest(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
1755 ok(req != NULL, "HttpOpenRequest failed\n");
1757 size = sizeof(buffer);
1758 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1759 err = GetLastError();
1760 ok(!ret, "HttpQueryInfo succeeded\n");
1761 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
1763 ret = HttpAddRequestHeaders(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
1764 ok(ret, "HttpAddRequestHeaders failed\n");
1766 buffer[0] = 0;
1767 size = sizeof(buffer);
1768 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1769 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
1770 ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
1772 InternetCloseHandle(req);
1773 InternetCloseHandle(con);
1774 InternetCloseHandle(ses);
1777 static void test_bogus_accept_types_array(void)
1779 HINTERNET ses, con, req;
1780 static const char *types[] = { (const char *)6240, "*/*", "%p", "", "*/*", NULL };
1781 DWORD size;
1782 char buffer[32];
1783 BOOL ret;
1785 ses = InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
1786 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1787 req = HttpOpenRequest(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
1789 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
1791 buffer[0] = 0;
1792 size = sizeof(buffer);
1793 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
1794 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
1795 ok(!strcmp(buffer, ", */*, %p, , */*") || /* IE6 */
1796 !strcmp(buffer, "*/*, %p, */*"),
1797 "got '%s' expected '*/*, %%p, */*' or ', */*, %%p, , */*'\n", buffer);
1799 InternetCloseHandle(req);
1800 InternetCloseHandle(con);
1801 InternetCloseHandle(ses);
1804 #define STATUS_STRING(status) \
1805 memcpy(status_string[status], #status, sizeof(CHAR) * \
1806 (strlen(#status) < MAX_STATUS_NAME ? \
1807 strlen(#status) : \
1808 MAX_STATUS_NAME - 1))
1809 static void init_status_tests(void)
1811 memset(expect, 0, sizeof(expect));
1812 memset(wine_allow, 0, sizeof(wine_allow));
1813 memset(notified, 0, sizeof(notified));
1814 memset(status_string, 0, sizeof(status_string));
1815 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME);
1816 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED);
1817 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER);
1818 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER);
1819 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST);
1820 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT);
1821 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE);
1822 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED);
1823 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED);
1824 STATUS_STRING(INTERNET_STATUS_PREFETCH);
1825 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION);
1826 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED);
1827 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED);
1828 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING);
1829 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY);
1830 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE);
1831 STATUS_STRING(INTERNET_STATUS_REDIRECT);
1832 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE);
1833 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED);
1834 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE);
1835 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT);
1836 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED);
1837 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED);
1838 STATUS_STRING(INTERNET_STATUS_P3P_HEADER);
1839 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF);
1840 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);
1842 #undef STATUS_STRING
1844 START_TEST(http)
1846 HMODULE hdll;
1847 hdll = GetModuleHandleA("wininet.dll");
1848 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
1849 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1850 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1851 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1852 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1854 if (!pInternetSetStatusCallbackA)
1855 skip("skipping the InternetReadFile tests\n");
1856 else
1858 init_status_tests();
1859 InternetReadFile_test(INTERNET_FLAG_ASYNC);
1860 InternetReadFile_test(0);
1861 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
1863 InternetOpenRequest_test();
1864 test_http_cache();
1865 InternetOpenUrlA_test();
1866 if (!pInternetTimeFromSystemTimeA)
1867 skip("skipping the InternetTime tests\n");
1868 else
1870 InternetTimeFromSystemTimeA_test();
1871 InternetTimeFromSystemTimeW_test();
1872 InternetTimeToSystemTimeA_test();
1873 InternetTimeToSystemTimeW_test();
1875 HttpSendRequestEx_test();
1876 HttpHeaders_test();
1877 test_http_connection();
1878 test_user_agent_header();
1879 test_bogus_accept_types_array();