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
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) \
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) \
56 if (!expect[status] && wine_allow[status]) \
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]--; \
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"); \
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) \
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); \
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(
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';
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';
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';
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';
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
)
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
,
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
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
);
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
);
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
);
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");
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
);
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
);
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
);
367 rc
= InternetQueryOptionA(hor
,INTERNET_OPTION_REQUEST_FLAGS
,&out
,&length
);
368 trace("Option 0x17 -> %i %i\n",rc
,out
);
371 rc
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
372 trace("Option 0x22 -> %i %s\n",rc
,buffer
);
375 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
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
);
385 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
386 trace("Option 0x5 -> %i %s (%u)\n",rc
,buffer
,GetLastError());
389 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
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",
401 trace("Entering Query loop\n");
403 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
404 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
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
)
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
);
429 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
431 rc
= InternetReadFile(hor
,buffer
,length
,&length
);
435 trace("ReadFile -> %i %i\n",rc
,length
);
437 HeapFree(GetProcessHeap(),0,buffer
);
442 /* WinXP does not send, but Win98 does */
443 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
444 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
446 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 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",
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. */
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
)
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
);
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
)
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
,
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
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
);
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
);
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
);
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");
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
);
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
);
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());
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());
645 trace("Entering Query loop\n");
647 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
648 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
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);
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
);
675 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
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
);
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
)
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
);
717 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
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");
727 rc
= InternetCloseHandle(hic
);
728 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
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
)
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
);
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
;
756 DWORD size
, readbytes
, totalbytes
=0;
759 myhinternet
= InternetOpen("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
760 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
762 ret
= InternetCanonicalizeUrl(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
763 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
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)
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)
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)
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)
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)
873 INTERNET_BUFFERS BufferIn
;
874 DWORD dwBytesWritten
;
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" );
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");
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
};
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" );
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");
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
;
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");
1010 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
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
);
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)
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" );
1102 ok( hRequest
!= NULL
, "Failed to open request handle\n");
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");
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");
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 */
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 */
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");
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 */
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");
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");
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");
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");
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");
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");
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");
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");
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"
1322 static const char notokmsg
[] =
1323 "HTTP/1.1 400 Bad Request\r\n"
1324 "Server: winetest\r\n"
1327 static const char noauthmsg
[] =
1328 "HTTP/1.1 401 Unauthorized\r\n"
1329 "Server: winetest\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"
1339 static const char page1
[] =
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"
1345 struct server_info
{
1350 static DWORD CALLBACK
server_thread(LPVOID param
)
1352 struct server_info
*si
= param
;
1355 struct sockaddr_in sa
;
1358 int last_request
= 0;
1360 WSAStartup(MAKEWORD(1,1), &wsaData
);
1362 s
= socket(AF_INET
, SOCK_STREAM
, 0);
1363 if (s
== INVALID_SOCKET
)
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
);
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);
1393 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
1394 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
1397 if (strstr(buffer
, "GET /test1"))
1399 if (!strstr(buffer
, "Content-Length: 0"))
1401 send(c
, okmsg
, sizeof okmsg
-1, 0);
1402 send(c
, page1
, sizeof page1
-1, 0);
1405 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1407 if (strstr(buffer
, "/test2"))
1409 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1411 send(c
, okmsg
, sizeof okmsg
-1, 0);
1412 send(c
, page1
, sizeof page1
-1, 0);
1415 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
1417 if (strstr(buffer
, "/test3"))
1419 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
1420 send(c
, okmsg
, sizeof okmsg
-1, 0);
1422 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
1424 if (strstr(buffer
, "/test4"))
1426 if (strstr(buffer
, "Connection: Close"))
1427 send(c
, okmsg
, sizeof okmsg
-1, 0);
1429 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1431 if (strstr(buffer
, "POST /test5"))
1433 if (strstr(buffer
, "Content-Length: 0"))
1435 send(c
, okmsg
, sizeof okmsg
-1, 0);
1436 send(c
, page1
, sizeof page1
-1, 0);
1439 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1441 if (strstr(buffer
, "GET /test6"))
1443 send(c
, contmsg
, sizeof contmsg
-1, 0);
1444 send(c
, contmsg
, sizeof contmsg
-1, 0);
1445 send(c
, okmsg
, sizeof okmsg
-1, 0);
1446 send(c
, page1
, sizeof page1
-1, 0);
1448 if (strstr(buffer
, "POST /test7"))
1450 if (strstr(buffer
, "Content-Length: 100"))
1452 send(c
, okmsg
, sizeof okmsg
-1, 0);
1453 send(c
, page1
, sizeof page1
-1, 0);
1456 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1458 if (strstr(buffer
, "/test8"))
1460 if (!strstr(buffer
, "Connection: Close") &&
1461 strstr(buffer
, "Connection: Keep-Alive"))
1462 send(c
, okmsg
, sizeof okmsg
-1, 0);
1464 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1466 if (strstr(buffer
, "/test9"))
1468 if (!strstr(buffer
, "Connection: Close") &&
1469 !strstr(buffer
, "Connection: Keep-Alive"))
1470 send(c
, okmsg
, sizeof okmsg
-1, 0);
1472 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1474 if (strstr(buffer
, "GET /quit"))
1476 send(c
, okmsg
, sizeof okmsg
-1, 0);
1477 send(c
, page1
, sizeof page1
-1, 0);
1483 } while (!last_request
);
1490 static void test_basic_request(int port
, const char *verb
, const char *url
)
1492 HINTERNET hi
, hc
, hr
;
1496 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1497 ok(hi
!= NULL
, "open failed\n");
1499 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1500 ok(hc
!= NULL
, "connect failed\n");
1502 hr
= HttpOpenRequest(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
1503 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1505 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1506 ok(r
, "HttpSendRequest failed\n");
1509 memset(buffer
, 0, sizeof buffer
);
1510 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
1511 ok(r
, "InternetReadFile failed\n");
1512 ok(count
== sizeof page1
- 1, "count was wrong\n");
1513 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
1515 InternetCloseHandle(hr
);
1516 InternetCloseHandle(hc
);
1517 InternetCloseHandle(hi
);
1520 static void test_proxy_indirect(int port
)
1522 HINTERNET hi
, hc
, hr
;
1526 hi
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
1527 ok(hi
!= NULL
, "open failed\n");
1529 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1530 ok(hc
!= NULL
, "connect failed\n");
1532 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1533 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1535 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1536 ok(r
, "HttpSendRequest failed\n");
1539 r
= HttpQueryInfo(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
1540 ok(r
, "HttpQueryInfo failed\n");
1541 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1544 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1545 ok(r
, "HttpQueryInfo failed\n");
1546 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1549 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &val
, &sz
, NULL
);
1550 ok(r
, "HttpQueryInfo failed\n");
1551 ok(val
== 407, "proxy code wrong\n");
1554 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
1555 ok(r
, "HttpQueryInfo failed\n");
1556 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
1559 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
1560 ok(r
, "HttpQueryInfo failed\n");
1561 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
1564 r
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
1565 ok(r
, "HttpQueryInfo failed\n");
1566 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
1569 r
= HttpQueryInfo(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
1570 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
1571 ok(r
== FALSE
, "HttpQueryInfo failed\n");
1573 InternetCloseHandle(hr
);
1574 InternetCloseHandle(hc
);
1575 InternetCloseHandle(hi
);
1578 static void test_proxy_direct(int port
)
1580 HINTERNET hi
, hc
, hr
;
1583 static CHAR username
[] = "mike",
1584 password
[] = "1101";
1586 sprintf(buffer
, "localhost:%d\n", port
);
1587 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
1588 ok(hi
!= NULL
, "open failed\n");
1590 /* try connect without authorization */
1591 hc
= InternetConnect(hi
, "www.winehq.org/", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1592 ok(hc
!= NULL
, "connect failed\n");
1594 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1595 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1597 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1598 ok(r
, "HttpSendRequest failed\n");
1601 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1602 ok(r
, "HttpQueryInfo failed\n");
1603 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1606 /* set the user + password then try again */
1608 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
1609 ok(r
, "failed to set user\n");
1611 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
1612 ok(r
, "failed to set password\n");
1615 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1616 ok(r
, "HttpSendRequest failed\n");
1618 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1619 ok(r
, "HttpQueryInfo failed\n");
1621 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
1625 InternetCloseHandle(hr
);
1626 InternetCloseHandle(hc
);
1627 InternetCloseHandle(hi
);
1630 static void test_header_handling_order(int port
)
1632 static char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
1633 static char connection
[] = "Connection: Close";
1635 static const char *types
[2] = { "*", NULL
};
1636 HINTERNET session
, connect
, request
;
1640 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1641 ok(session
!= NULL
, "InternetOpen failed\n");
1643 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1644 ok(connect
!= NULL
, "InternetConnect failed\n");
1646 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1647 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1649 ret
= HttpAddRequestHeaders(request
, authorization
, ~0UL, HTTP_ADDREQ_FLAG_ADD
);
1650 ok(ret
, "HttpAddRequestHeaders failed\n");
1652 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1653 ok(ret
, "HttpSendRequest failed\n");
1656 size
= sizeof(status
);
1657 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1658 ok(ret
, "HttpQueryInfo failed\n");
1659 ok(status
== 200, "request failed with status %u\n", status
);
1661 InternetCloseHandle(request
);
1663 request
= HttpOpenRequest(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1664 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1666 ret
= HttpSendRequest(request
, connection
, ~0UL, NULL
, 0);
1667 ok(ret
, "HttpSendRequest failed\n");
1670 size
= sizeof(status
);
1671 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1672 ok(ret
, "HttpQueryInfo failed\n");
1673 ok(status
== 200, "request failed with status %u\n", status
);
1675 InternetCloseHandle(request
);
1677 request
= HttpOpenRequest(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1678 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1680 ret
= HttpAddRequestHeaders(request
, "Content-Length: 100\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1681 ok(ret
, "HttpAddRequestHeaders failed\n");
1683 ret
= HttpSendRequest(request
, connection
, ~0UL, NULL
, 0);
1684 ok(ret
, "HttpSendRequest failed\n");
1687 size
= sizeof(status
);
1688 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1689 ok(ret
, "HttpQueryInfo failed\n");
1690 ok(status
== 200, "request failed with status %u\n", status
);
1692 InternetCloseHandle(request
);
1693 InternetCloseHandle(connect
);
1694 InternetCloseHandle(session
);
1697 static void test_connection_header(int port
)
1699 HINTERNET ses
, con
, req
;
1703 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1704 ok(ses
!= NULL
, "InternetOpen failed\n");
1706 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1707 ok(con
!= NULL
, "InternetConnect failed\n");
1709 req
= HttpOpenRequest(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1710 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1712 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1713 ok(ret
, "HttpSendRequest failed\n");
1716 size
= sizeof(status
);
1717 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1718 ok(ret
, "HttpQueryInfo failed\n");
1719 ok(status
== 200, "request failed with status %u\n", status
);
1721 InternetCloseHandle(req
);
1723 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
1724 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1726 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1727 ok(ret
, "HttpSendRequest failed\n");
1730 size
= sizeof(status
);
1731 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1732 ok(ret
, "HttpQueryInfo failed\n");
1733 ok(status
== 200, "request failed with status %u\n", status
);
1735 InternetCloseHandle(req
);
1736 InternetCloseHandle(con
);
1737 InternetCloseHandle(ses
);
1740 static void test_http_connection(void)
1742 struct server_info si
;
1746 si
.hEvent
= CreateEvent(NULL
, 0, 0, NULL
);
1749 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
1750 ok( hThread
!= NULL
, "create thread failed\n");
1752 r
= WaitForSingleObject(si
.hEvent
, 10000);
1753 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
1754 if (r
!= WAIT_OBJECT_0
)
1757 test_basic_request(si
.port
, "GET", "/test1");
1758 test_proxy_indirect(si
.port
);
1759 test_proxy_direct(si
.port
);
1760 test_header_handling_order(si
.port
);
1761 test_basic_request(si
.port
, "POST", "/test5");
1762 test_basic_request(si
.port
, "GET", "/test6");
1763 test_connection_header(si
.port
);
1765 /* send the basic request again to shutdown the server thread */
1766 test_basic_request(si
.port
, "GET", "/quit");
1768 r
= WaitForSingleObject(hThread
, 3000);
1769 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
1770 CloseHandle(hThread
);
1773 static void test_user_agent_header(void)
1775 HINTERNET ses
, con
, req
;
1780 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1781 ok(ses
!= NULL
, "InternetOpen failed\n");
1783 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1784 ok(con
!= NULL
, "InternetConnect failed\n");
1786 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
1787 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1789 size
= sizeof(buffer
);
1790 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1791 err
= GetLastError();
1792 ok(!ret
, "HttpQueryInfo succeeded\n");
1793 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1795 ret
= HttpAddRequestHeaders(req
, "User-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1796 ok(ret
, "HttpAddRequestHeaders succeeded\n");
1798 size
= sizeof(buffer
);
1799 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1800 err
= GetLastError();
1801 ok(ret
, "HttpQueryInfo failed\n");
1802 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1804 InternetCloseHandle(req
);
1806 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
1807 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1809 size
= sizeof(buffer
);
1810 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1811 err
= GetLastError();
1812 ok(!ret
, "HttpQueryInfo succeeded\n");
1813 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1815 ret
= HttpAddRequestHeaders(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1816 ok(ret
, "HttpAddRequestHeaders failed\n");
1819 size
= sizeof(buffer
);
1820 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1821 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
1822 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
1824 InternetCloseHandle(req
);
1825 InternetCloseHandle(con
);
1826 InternetCloseHandle(ses
);
1829 static void test_bogus_accept_types_array(void)
1831 HINTERNET ses
, con
, req
;
1832 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", "*/*", NULL
};
1837 ses
= InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
1838 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1839 req
= HttpOpenRequest(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
1841 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1844 size
= sizeof(buffer
);
1845 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1846 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
1847 ok(!strcmp(buffer
, ", */*, %p, , */*") || /* IE6 */
1848 !strcmp(buffer
, "*/*, %p, */*"),
1849 "got '%s' expected '*/*, %%p, */*' or ', */*, %%p, , */*'\n", buffer
);
1851 InternetCloseHandle(req
);
1852 InternetCloseHandle(con
);
1853 InternetCloseHandle(ses
);
1862 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
1864 INTERNET_ASYNC_RESULT
*result
= info
;
1865 struct context
*ctx
= (struct context
*)context
;
1867 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
1869 if (status
== INTERNET_STATUS_REQUEST_COMPLETE
)
1871 trace("request handle: 0x%08lx\n", result
->dwResult
);
1872 ctx
->req
= (HINTERNET
)result
->dwResult
;
1873 SetEvent(ctx
->event
);
1875 if (status
== INTERNET_STATUS_HANDLE_CLOSING
)
1877 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
1879 if (InternetQueryOption(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
1880 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
1881 SetEvent(ctx
->event
);
1885 static void test_open_url_async(void)
1894 ctx
.event
= CreateEvent(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
1896 ses
= InternetOpen("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1897 ok(ses
!= NULL
, "InternetOpen failed\n");
1899 pInternetSetStatusCallbackA(ses
, cb
);
1900 ResetEvent(ctx
.event
);
1902 req
= InternetOpenUrl(ses
, "http://www.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
1903 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
1905 WaitForSingleObject(ctx
.event
, INFINITE
);
1908 size
= sizeof(type
);
1909 ret
= InternetQueryOption(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
1910 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
1911 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
1912 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
1915 ret
= HttpQueryInfo(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
1916 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
1917 ok(size
> 0, "expected size > 0\n");
1919 ResetEvent(ctx
.event
);
1920 InternetCloseHandle(ctx
.req
);
1921 WaitForSingleObject(ctx
.event
, INFINITE
);
1923 InternetCloseHandle(ses
);
1924 CloseHandle(ctx
.event
);
1927 #define STATUS_STRING(status) \
1928 memcpy(status_string[status], #status, sizeof(CHAR) * \
1929 (strlen(#status) < MAX_STATUS_NAME ? \
1931 MAX_STATUS_NAME - 1))
1932 static void init_status_tests(void)
1934 memset(expect
, 0, sizeof(expect
));
1935 memset(wine_allow
, 0, sizeof(wine_allow
));
1936 memset(notified
, 0, sizeof(notified
));
1937 memset(status_string
, 0, sizeof(status_string
));
1938 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
1939 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
1940 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1941 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1942 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
1943 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
1944 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
1945 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
1946 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
1947 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
1948 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
1949 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
1950 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
1951 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
1952 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
1953 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
1954 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
1955 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
1956 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
1957 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
1958 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
1959 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
1960 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
1961 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
1962 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
1963 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
1965 #undef STATUS_STRING
1970 hdll
= GetModuleHandleA("wininet.dll");
1971 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
1972 pInternetTimeFromSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeA");
1973 pInternetTimeFromSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeW");
1974 pInternetTimeToSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeA");
1975 pInternetTimeToSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeW");
1977 if (!pInternetSetStatusCallbackA
)
1978 skip("skipping the InternetReadFile tests\n");
1981 init_status_tests();
1982 InternetReadFile_test(INTERNET_FLAG_ASYNC
);
1983 InternetReadFile_test(0);
1984 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
1985 test_open_url_async();
1987 InternetOpenRequest_test();
1989 InternetOpenUrlA_test();
1990 if (!pInternetTimeFromSystemTimeA
)
1991 skip("skipping the InternetTime tests\n");
1994 InternetTimeFromSystemTimeA_test();
1995 InternetTimeFromSystemTimeW_test();
1996 InternetTimeToSystemTimeA_test();
1997 InternetTimeToSystemTimeW_test();
1999 HttpSendRequestEx_test();
2001 test_http_connection();
2002 test_user_agent_header();
2003 test_bogus_accept_types_array();