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 #define SET_OPTIONAL2(status, num) \
47 optional[status] = num
49 #define SET_OPTIONAL(status) \
50 SET_OPTIONAL2(status, 1)
52 /* SET_WINE_ALLOW's should be used with an appropriate
53 * todo_wine CHECK_NOTIFIED at a later point in the code */
54 #define SET_WINE_ALLOW2(status, num) \
55 wine_allow[status] = num
57 #define SET_WINE_ALLOW(status) \
58 SET_WINE_ALLOW2(status, 1)
60 #define CHECK_EXPECT(status) \
62 if (!expect[status] && !optional[status] && wine_allow[status]) \
64 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
65 status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
66 status_string[status] : "unknown"); \
67 wine_allow[status]--; \
71 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
72 status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
73 status_string[status] : "unknown"); \
74 if (expect[status]) expect[status]--; \
75 else optional[status]--; \
80 /* CLEAR_NOTIFIED used in cases when notification behavior
81 * differs between Windows versions */
82 #define CLEAR_NOTIFIED(status) \
83 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
85 #define CHECK_NOTIFIED2(status, num) \
87 ok(notified[status] == (num), "expected status %d (%s) %d times, received %d times\n", \
88 status, status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
89 status_string[status] : "unknown", (num), notified[status]); \
90 CLEAR_NOTIFIED(status); \
93 #define CHECK_NOTIFIED(status) \
94 CHECK_NOTIFIED2(status, 1)
96 #define CHECK_NOT_NOTIFIED(status) \
97 CHECK_NOTIFIED2(status, 0)
99 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
100 #define MAX_STATUS_NAME 50
101 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
102 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
103 static CHAR status_string
[MAX_INTERNET_STATUS
][MAX_STATUS_NAME
];
105 static HANDLE hCompleteEvent
;
107 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
108 static BOOL (WINAPI
*pInternetTimeFromSystemTimeA
)(CONST SYSTEMTIME
*,DWORD
,LPSTR
,DWORD
);
109 static BOOL (WINAPI
*pInternetTimeFromSystemTimeW
)(CONST SYSTEMTIME
*,DWORD
,LPWSTR
,DWORD
);
110 static BOOL (WINAPI
*pInternetTimeToSystemTimeA
)(LPCSTR
,SYSTEMTIME
*,DWORD
);
111 static BOOL (WINAPI
*pInternetTimeToSystemTimeW
)(LPCWSTR
,SYSTEMTIME
*,DWORD
);
114 static VOID WINAPI
callback(
117 DWORD dwInternetStatus
,
118 LPVOID lpvStatusInformation
,
119 DWORD dwStatusInformationLength
122 CHECK_EXPECT(dwInternetStatus
);
123 switch (dwInternetStatus
)
125 case INTERNET_STATUS_RESOLVING_NAME
:
126 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
127 GetCurrentThreadId(), hInternet
, dwContext
,
128 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
129 *(LPSTR
)lpvStatusInformation
= '\0';
131 case INTERNET_STATUS_NAME_RESOLVED
:
132 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
133 GetCurrentThreadId(), hInternet
, dwContext
,
134 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
135 *(LPSTR
)lpvStatusInformation
= '\0';
137 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
138 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
139 GetCurrentThreadId(), hInternet
, dwContext
,
140 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
141 *(LPSTR
)lpvStatusInformation
= '\0';
143 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
144 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
145 GetCurrentThreadId(), hInternet
, dwContext
,
146 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
147 *(LPSTR
)lpvStatusInformation
= '\0';
149 case INTERNET_STATUS_SENDING_REQUEST
:
150 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
151 GetCurrentThreadId(), hInternet
, dwContext
,
152 lpvStatusInformation
,dwStatusInformationLength
);
154 case INTERNET_STATUS_REQUEST_SENT
:
155 ok(dwStatusInformationLength
== sizeof(DWORD
),
156 "info length should be sizeof(DWORD) instead of %d\n",
157 dwStatusInformationLength
);
158 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
159 GetCurrentThreadId(), hInternet
, dwContext
,
160 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
162 case INTERNET_STATUS_RECEIVING_RESPONSE
:
163 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
164 GetCurrentThreadId(), hInternet
, dwContext
,
165 lpvStatusInformation
,dwStatusInformationLength
);
167 case INTERNET_STATUS_RESPONSE_RECEIVED
:
168 ok(dwStatusInformationLength
== sizeof(DWORD
),
169 "info length should be sizeof(DWORD) instead of %d\n",
170 dwStatusInformationLength
);
171 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
172 GetCurrentThreadId(), hInternet
, dwContext
,
173 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
175 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
176 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
177 GetCurrentThreadId(), hInternet
,dwContext
,
178 lpvStatusInformation
,dwStatusInformationLength
);
180 case INTERNET_STATUS_PREFETCH
:
181 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
182 GetCurrentThreadId(), hInternet
, dwContext
,
183 lpvStatusInformation
,dwStatusInformationLength
);
185 case INTERNET_STATUS_CLOSING_CONNECTION
:
186 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
187 GetCurrentThreadId(), hInternet
, dwContext
,
188 lpvStatusInformation
,dwStatusInformationLength
);
190 case INTERNET_STATUS_CONNECTION_CLOSED
:
191 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
192 GetCurrentThreadId(), hInternet
, dwContext
,
193 lpvStatusInformation
,dwStatusInformationLength
);
195 case INTERNET_STATUS_HANDLE_CREATED
:
196 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
197 "info length should be sizeof(HINTERNET) instead of %d\n",
198 dwStatusInformationLength
);
199 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
200 GetCurrentThreadId(), hInternet
, dwContext
,
201 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
202 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
203 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
205 case INTERNET_STATUS_HANDLE_CLOSING
:
206 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
207 "info length should be sizeof(HINTERNET) instead of %d\n",
208 dwStatusInformationLength
);
209 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
210 GetCurrentThreadId(), hInternet
, dwContext
,
211 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
213 case INTERNET_STATUS_REQUEST_COMPLETE
:
215 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
216 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
217 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
218 dwStatusInformationLength
);
219 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
220 GetCurrentThreadId(), hInternet
, dwContext
,
221 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
222 SetEvent(hCompleteEvent
);
225 case INTERNET_STATUS_REDIRECT
:
226 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
227 GetCurrentThreadId(), hInternet
, dwContext
,
228 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
229 *(LPSTR
)lpvStatusInformation
= '\0';
230 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
231 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
233 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
234 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
235 GetCurrentThreadId(), hInternet
, dwContext
,
236 lpvStatusInformation
, dwStatusInformationLength
);
239 trace("%04x:Callback %p 0x%lx %d %p %d\n",
240 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
241 lpvStatusInformation
, dwStatusInformationLength
);
245 static void InternetReadFile_test(int flags
)
252 const char *types
[2] = { "*", NULL
};
253 HINTERNET hi
, hic
= 0, hor
= 0;
255 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
257 trace("Starting InternetReadFile test with flags 0x%x\n",flags
);
259 trace("InternetOpenA <--\n");
260 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
261 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
262 trace("InternetOpenA -->\n");
264 if (hi
== 0x0) goto abort
;
266 pInternetSetStatusCallbackA(hi
,&callback
);
268 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
270 trace("InternetConnectA <--\n");
271 hic
=InternetConnectA(hi
, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
272 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
273 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
274 trace("InternetConnectA -->\n");
276 if (hic
== 0x0) goto abort
;
278 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
279 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
281 trace("HttpOpenRequestA <--\n");
282 hor
= HttpOpenRequestA(hic
, "GET", "/about/", NULL
, NULL
, types
,
283 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
,
285 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
287 * If the internet name can't be resolved we are probably behind
288 * a firewall or in some other way not directly connected to the
289 * Internet. Not enough reason to fail the test. Just ignore and
293 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
295 trace("HttpOpenRequestA -->\n");
297 if (hor
== 0x0) goto abort
;
299 length
= sizeof(buffer
);
300 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
301 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
302 ok(!strcmp(buffer
, "http://www.winehq.org/about/"), "Wrong URL %s\n", buffer
);
304 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
305 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
306 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
307 if (first_connection_to_test_url
)
309 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
310 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
311 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME
);
312 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED
);
316 SET_WINE_ALLOW2(INTERNET_STATUS_RESOLVING_NAME
,2);
317 SET_WINE_ALLOW2(INTERNET_STATUS_NAME_RESOLVED
,2);
319 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
320 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
321 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
322 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
323 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
324 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
325 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
326 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
327 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
328 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
329 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
330 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
331 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
332 if (flags
& INTERNET_FLAG_ASYNC
)
333 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
335 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
337 trace("HttpSendRequestA -->\n");
338 SetLastError(0xdeadbeef);
339 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
340 if (flags
& INTERNET_FLAG_ASYNC
)
341 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
342 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
344 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
345 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
346 trace("HttpSendRequestA <--\n");
348 if (flags
& INTERNET_FLAG_ASYNC
)
349 WaitForSingleObject(hCompleteEvent
, INFINITE
);
351 todo_wine
if (first_connection_to_test_url
)
353 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
354 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
358 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
359 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
361 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
362 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
363 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
364 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
365 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
366 if (flags
& INTERNET_FLAG_ASYNC
)
367 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
369 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
370 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
371 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
372 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
375 rc
= InternetQueryOptionA(hor
,INTERNET_OPTION_REQUEST_FLAGS
,&out
,&length
);
376 trace("Option 0x17 -> %i %i\n",rc
,out
);
379 rc
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
380 trace("Option 0x22 -> %i %s\n",rc
,buffer
);
383 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
385 trace("Option 0x16 -> %i %s\n",rc
,buffer
);
387 length
= sizeof(buffer
);
388 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
389 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
390 ok(!strcmp(buffer
, "http://www.winehq.org/site/about"), "Wrong URL %s\n", buffer
);
393 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
394 trace("Option 0x5 -> %i %s (%u)\n",rc
,buffer
,GetLastError());
397 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
399 trace("Option 0x1 -> %i %s\n",rc
,buffer
);
401 SetLastError(0xdeadbeef);
402 rc
= InternetReadFile(NULL
, buffer
, 100, &length
);
403 ok(!rc
, "InternetReadFile should have failed\n");
404 ok(GetLastError() == ERROR_INVALID_HANDLE
,
405 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
409 trace("Entering Query loop\n");
411 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
412 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
415 if (flags
& INTERNET_FLAG_ASYNC
)
416 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
417 rc
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
418 ok(!(rc
== 0 && length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
419 ok(rc
!= 0 || ((flags
& INTERNET_FLAG_ASYNC
) && GetLastError() == ERROR_IO_PENDING
),
420 "InternetQueryDataAvailable failed, error %d\n", GetLastError());
421 if (flags
& INTERNET_FLAG_ASYNC
)
425 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
427 else if (GetLastError() == ERROR_IO_PENDING
)
429 WaitForSingleObject(hCompleteEvent
, INFINITE
);
430 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
437 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
439 rc
= InternetReadFile(hor
,buffer
,length
,&length
);
443 trace("ReadFile -> %i %i\n",rc
,length
);
445 HeapFree(GetProcessHeap(),0,buffer
);
450 /* WinXP does not send, but Win98 does */
451 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
452 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
454 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
456 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
457 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
458 SetLastError(0xdeadbeef);
459 rc
= InternetCloseHandle(hor
);
460 ok ((rc
!= 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
461 SetLastError(0xdeadbeef);
462 rc
= InternetCloseHandle(hor
);
463 ok ((rc
== 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
464 ok (GetLastError() == ERROR_INVALID_HANDLE
,
465 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %u\n",
468 /* We intentionally do not close the handle opened by InternetConnectA as this
469 * tickles bug #9479: native closes child internet handles when the parent handles
470 * are closed. This is verified below by checking that the number of
471 * INTERNET_STATUS_HANDLE_CLOSING notifications matches the number expected. */
473 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING
);
474 rc
= InternetCloseHandle(hi
);
475 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
476 if (flags
& INTERNET_FLAG_ASYNC
)
479 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
480 if (hor
!= 0x0 && (flags
& INTERNET_FLAG_ASYNC
)) todo_wine
482 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
483 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
487 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
488 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
490 CloseHandle(hCompleteEvent
);
491 first_connection_to_test_url
= FALSE
;
494 static void InternetReadFileExA_test(int flags
)
498 const char *types
[2] = { "*", NULL
};
499 HINTERNET hi
, hic
= 0, hor
= 0;
500 INTERNET_BUFFERS inetbuffers
;
502 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
504 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
506 trace("InternetOpenA <--\n");
507 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
508 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
509 trace("InternetOpenA -->\n");
511 if (hi
== 0x0) goto abort
;
513 pInternetSetStatusCallbackA(hi
,&callback
);
515 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
517 trace("InternetConnectA <--\n");
518 hic
=InternetConnectA(hi
, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
519 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
520 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
521 trace("InternetConnectA -->\n");
523 if (hic
== 0x0) goto abort
;
525 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
526 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
528 trace("HttpOpenRequestA <--\n");
529 hor
= HttpOpenRequestA(hic
, "GET", "/about/", NULL
, NULL
, types
,
530 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
,
532 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
534 * If the internet name can't be resolved we are probably behind
535 * a firewall or in some other way not directly connected to the
536 * Internet. Not enough reason to fail the test. Just ignore and
540 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
542 trace("HttpOpenRequestA -->\n");
544 if (hor
== 0x0) goto abort
;
546 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
547 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
548 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
549 if (first_connection_to_test_url
)
551 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
552 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
553 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME
);
554 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED
);
558 SET_WINE_ALLOW2(INTERNET_STATUS_RESOLVING_NAME
,2);
559 SET_WINE_ALLOW2(INTERNET_STATUS_NAME_RESOLVED
,2);
561 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
562 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
563 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
564 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
565 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
566 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
567 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
568 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
569 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
570 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
571 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
572 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
573 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
574 if (flags
& INTERNET_FLAG_ASYNC
)
575 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
577 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
579 trace("HttpSendRequestA -->\n");
580 SetLastError(0xdeadbeef);
581 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
582 if (flags
& INTERNET_FLAG_ASYNC
)
583 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
584 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
586 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
587 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
588 trace("HttpSendRequestA <--\n");
590 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
))
591 WaitForSingleObject(hCompleteEvent
, INFINITE
);
593 if (first_connection_to_test_url
)
595 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
596 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
600 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
601 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
603 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
604 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
605 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
606 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
607 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
608 if (flags
& INTERNET_FLAG_ASYNC
)
609 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
611 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
612 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
613 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
614 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
616 /* tests invalid dwStructSize */
617 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
)+1;
618 inetbuffers
.lpcszHeader
= NULL
;
619 inetbuffers
.dwHeadersLength
= 0;
620 inetbuffers
.dwBufferLength
= 10;
621 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
622 inetbuffers
.dwOffsetHigh
= 1234;
623 inetbuffers
.dwOffsetLow
= 5678;
624 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
625 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
626 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
627 rc
? "TRUE" : "FALSE", GetLastError());
628 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
630 /* tests to see whether lpcszHeader is used - it isn't */
631 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
632 inetbuffers
.lpcszHeader
= (LPCTSTR
)0xdeadbeef;
633 inetbuffers
.dwHeadersLength
= 255;
634 inetbuffers
.dwBufferLength
= 0;
635 inetbuffers
.lpvBuffer
= NULL
;
636 inetbuffers
.dwOffsetHigh
= 1234;
637 inetbuffers
.dwOffsetLow
= 5678;
638 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
639 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
640 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
641 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
642 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
643 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
644 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
647 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
648 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
651 rc
= InternetReadFileEx(NULL
, &inetbuffers
, 0, 0xdeadcafe);
652 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
653 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
654 rc
? "TRUE" : "FALSE", GetLastError());
657 trace("Entering Query loop\n");
659 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
660 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
663 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
664 inetbuffers
.dwBufferLength
= 1024;
665 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
666 inetbuffers
.dwOffsetHigh
= 1234;
667 inetbuffers
.dwOffsetLow
= 5678;
669 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
670 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
671 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
672 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
675 if (GetLastError() == ERROR_IO_PENDING
)
677 trace("InternetReadFileEx -> PENDING\n");
678 ok(flags
& INTERNET_FLAG_ASYNC
,
679 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
680 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
681 WaitForSingleObject(hCompleteEvent
, INFINITE
);
682 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
683 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
687 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
693 trace("InternetReadFileEx -> SUCCEEDED\n");
694 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
695 if (inetbuffers
.dwBufferLength
)
697 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
698 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
702 /* Win98 still sends these when 0 bytes are read, WinXP does not */
703 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
704 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
708 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
709 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
711 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
712 "InternetReadFileEx sets offsets to 0x%x%08x\n",
713 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
715 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
717 if (!inetbuffers
.dwBufferLength
)
720 length
+= inetbuffers
.dwBufferLength
;
722 todo_wine
ok(length
> 0, "failed to read any of the document\n");
723 trace("Finished. Read %d bytes\n", length
);
725 /* WinXP does not send, but Win98 does */
726 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
727 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
729 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
731 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
732 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
733 rc
= InternetCloseHandle(hor
);
734 ok ((rc
!= 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
735 rc
= InternetCloseHandle(hor
);
736 ok ((rc
== 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
739 rc
= InternetCloseHandle(hic
);
740 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
743 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING
);
744 rc
= InternetCloseHandle(hi
);
745 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
746 if (flags
& INTERNET_FLAG_ASYNC
)
748 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
750 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
751 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
752 CloseHandle(hCompleteEvent
);
753 first_connection_to_test_url
= FALSE
;
756 static void InternetOpenUrlA_test(void)
758 HINTERNET myhinternet
, myhttp
;
760 DWORD size
, readbytes
, totalbytes
=0;
763 myhinternet
= InternetOpen("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
764 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
766 ret
= InternetCanonicalizeUrl(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
767 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
770 myhttp
= InternetOpenUrl(myhinternet
, TEST_URL
, 0, 0,
771 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
772 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
773 return; /* WinXP returns this when not connected to the net */
774 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
775 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
776 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
777 totalbytes
+= readbytes
;
778 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
779 totalbytes
+= readbytes
;
780 trace("read 0x%08x bytes\n",totalbytes
);
782 InternetCloseHandle(myhttp
);
783 InternetCloseHandle(myhinternet
);
786 static void InternetTimeFromSystemTimeA_test(void)
789 static const SYSTEMTIME time
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
790 char string
[INTERNET_RFC1123_BUFSIZE
];
791 static const char expect
[] = "Fri, 07 Jan 2005 12:06:35 GMT";
793 ret
= pInternetTimeFromSystemTimeA( &time
, INTERNET_RFC1123_FORMAT
, string
, sizeof(string
) );
794 ok( ret
, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
796 ok( !memcmp( string
, expect
, sizeof(expect
) ),
797 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
800 static void InternetTimeFromSystemTimeW_test(void)
803 static const SYSTEMTIME time
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
804 WCHAR string
[INTERNET_RFC1123_BUFSIZE
+ 1];
805 static const WCHAR expect
[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
806 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
808 ret
= pInternetTimeFromSystemTimeW( &time
, INTERNET_RFC1123_FORMAT
, string
, sizeof(string
) );
809 ok( ret
, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
811 ok( !memcmp( string
, expect
, sizeof(expect
) ),
812 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
815 static void InternetTimeToSystemTimeA_test(void)
819 static const SYSTEMTIME expect
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
820 static const char string
[] = "Fri, 07 Jan 2005 12:06:35 GMT";
821 static const char string2
[] = " fri 7 jan 2005 12 06 35";
823 ret
= pInternetTimeToSystemTimeA( string
, &time
, 0 );
824 ok( ret
, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
825 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
826 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
828 ret
= pInternetTimeToSystemTimeA( string2
, &time
, 0 );
829 ok( ret
, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
830 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
831 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
834 static void InternetTimeToSystemTimeW_test(void)
838 static const SYSTEMTIME expect
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
839 static const WCHAR string
[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
840 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
841 static const WCHAR string2
[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
842 '1','2',' ','0','6',' ','3','5',0 };
843 static const WCHAR string3
[] = { 'F','r',0 };
845 ret
= pInternetTimeToSystemTimeW( NULL
, NULL
, 0 );
846 ok( !ret
, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
848 ret
= pInternetTimeToSystemTimeW( NULL
, &time
, 0 );
849 ok( !ret
, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
851 ret
= pInternetTimeToSystemTimeW( string
, NULL
, 0 );
852 ok( !ret
, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
854 ret
= pInternetTimeToSystemTimeW( string
, &time
, 0 );
855 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
857 ret
= pInternetTimeToSystemTimeW( string
, &time
, 0 );
858 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
859 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
860 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
862 ret
= pInternetTimeToSystemTimeW( string2
, &time
, 0 );
863 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
864 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
865 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
867 ret
= pInternetTimeToSystemTimeW( string3
, &time
, 0 );
868 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
871 static void HttpSendRequestEx_test(void)
877 INTERNET_BUFFERS BufferIn
;
878 DWORD dwBytesWritten
;
884 static char szPostData
[] = "mode=Test";
885 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
887 hSession
= InternetOpen("Wine Regression Test",
888 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
889 ok( hSession
!= NULL
,"Unable to open Internet session\n");
890 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
891 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
893 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
894 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
895 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
896 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
898 skip( "Network unreachable, skipping test\n" );
901 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
904 BufferIn
.dwStructSize
= sizeof( INTERNET_BUFFERS
);
905 BufferIn
.Next
= (LPINTERNET_BUFFERS
)0xdeadcab;
906 BufferIn
.lpcszHeader
= szContentType
;
907 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
908 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
909 BufferIn
.lpvBuffer
= szPostData
;
910 BufferIn
.dwBufferLength
= 3;
911 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
912 BufferIn
.dwOffsetLow
= 0;
913 BufferIn
.dwOffsetHigh
= 0;
915 ret
= HttpSendRequestEx(hRequest
, &BufferIn
, NULL
, 0 ,0);
916 ok(ret
, "HttpSendRequestEx Failed with error %u\n", GetLastError());
918 for (i
= 3; szPostData
[i
]; i
++)
919 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
920 "InternetWriteFile failed\n");
922 ok(HttpEndRequest(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
924 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
925 "Unable to read response\n");
926 szBuffer
[dwBytesRead
] = 0;
928 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
929 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0,"Got string %s\n",szBuffer
);
931 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
933 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
934 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
937 static void InternetOpenRequest_test(void)
939 HINTERNET session
, connect
, request
;
940 static const char *types
[] = { "*", "", NULL
};
941 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
942 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
945 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
946 ok(session
!= NULL
,"Unable to open Internet session\n");
948 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
949 INTERNET_SERVICE_HTTP
, 0, 0);
950 ok(connect
== NULL
, "InternetConnectA should have failed\n");
951 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
953 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
954 INTERNET_SERVICE_HTTP
, 0, 0);
955 ok(connect
== NULL
, "InternetConnectA should have failed\n");
956 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
958 connect
= InternetConnectA(session
, "winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
959 INTERNET_SERVICE_HTTP
, 0, 0);
960 ok(connect
!= NULL
, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
962 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
963 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
965 skip( "Network unreachable, skipping test\n" );
968 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
970 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
971 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
972 ok(InternetCloseHandle(request
), "Close request handle failed\n");
974 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
975 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
977 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
978 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
979 ok(InternetCloseHandle(request
), "Close request handle failed\n");
982 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
983 ok(InternetCloseHandle(session
), "Close session handle failed\n");
986 static void test_http_cache(void)
988 HINTERNET session
, connect
, request
;
989 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
990 DWORD size
, file_size
;
995 static const char *types
[] = { "*", "", NULL
};
997 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
998 ok(session
!= NULL
,"Unable to open Internet session\n");
1000 connect
= InternetConnectA(session
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1001 INTERNET_SERVICE_HTTP
, 0, 0);
1002 ok(connect
!= NULL
, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
1004 request
= HttpOpenRequestA(connect
, NULL
, "/site/about", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1005 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1007 skip( "Network unreachable, skipping test\n" );
1009 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1010 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1014 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1017 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1018 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_url) failed: %u\n", GetLastError());
1019 ok(!strcmp(url
, "http://www.winehq.org/site/about"), "Wrong URL %s\n", url
);
1021 size
= sizeof(file_name
);
1022 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1023 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1024 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1025 ok(!size
, "size = %d\n", size
);
1027 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1028 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1030 size
= sizeof(file_name
);
1031 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1032 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1034 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1035 FILE_ATTRIBUTE_NORMAL
, NULL
);
1036 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1037 file_size
= GetFileSize(file
, NULL
);
1038 ok(file_size
== 0, "file size=%d\n", file_size
);
1040 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1041 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1042 ok(size
== sizeof(buf
), "size=%d\n", size
);
1044 file_size
= GetFileSize(file
, NULL
);
1045 ok(file_size
== sizeof(buf
), "file size=%d\n", file_size
);
1048 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1050 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1051 FILE_ATTRIBUTE_NORMAL
, NULL
);
1052 ok(file
== INVALID_HANDLE_VALUE
, "CreateFile succeeded\n");
1053 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1055 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1056 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1058 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1059 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1060 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1061 ok(!size
, "size = %d\n", size
);
1063 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1064 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1066 size
= sizeof(file_name
);
1067 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1068 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1069 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1070 ok(!size
, "size = %d\n", size
);
1072 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1073 FILE_ATTRIBUTE_NORMAL
, NULL
);
1074 ok(file
== INVALID_HANDLE_VALUE
, "CreateFile succeeded\n");
1075 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1077 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1079 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1080 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1083 static void HttpHeaders_test(void)
1094 hSession
= InternetOpen("Wine Regression Test",
1095 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1096 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1097 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
1098 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1100 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1101 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
1102 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1103 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1105 skip( "Network unreachable, skipping test\n" );
1108 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1111 len
= sizeof(buffer
);
1112 strcpy(buffer
,"Warning");
1113 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1114 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1116 ok(HttpAddRequestHeaders(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1117 "Failed to add new header\n");
1120 len
= sizeof(buffer
);
1121 strcpy(buffer
,"Warning");
1122 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1123 buffer
,&len
,&index
),"Unable to query header\n");
1124 ok(index
== 1, "Index was not incremented\n");
1125 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1126 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1127 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1128 len
= sizeof(buffer
);
1129 strcpy(buffer
,"Warning");
1130 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1131 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1134 len
= 5; /* could store the string but not the NULL terminator */
1135 strcpy(buffer
,"Warning");
1136 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1137 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1138 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1139 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1141 /* a call with NULL will fail but will return the length */
1143 len
= sizeof(buffer
);
1144 SetLastError(0xdeadbeef);
1145 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1146 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1147 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1148 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1149 ok(index
== 0, "Index was incremented\n");
1151 /* even for a len that is too small */
1154 SetLastError(0xdeadbeef);
1155 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1156 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1157 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1158 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1159 ok(index
== 0, "Index was incremented\n");
1163 SetLastError(0xdeadbeef);
1164 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1165 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1166 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1167 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1168 ok(index
== 0, "Index was incremented\n");
1169 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1172 /* a working query */
1174 len
= sizeof(buffer
);
1175 memset(buffer
, 'x', sizeof(buffer
));
1176 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1177 buffer
,&len
,&index
),"Unable to query header\n");
1178 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1179 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1180 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1181 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1182 ok(strncmp(buffer
, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1183 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1184 ok(index
== 0, "Index was incremented\n");
1186 /* Like above two tests, but for W version */
1190 SetLastError(0xdeadbeef);
1191 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1192 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1193 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1194 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1195 ok(index
== 0, "Index was incremented\n");
1196 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1198 /* a working query */
1200 len
= sizeof(wbuffer
);
1201 memset(wbuffer
, 'x', sizeof(wbuffer
));
1202 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1203 wbuffer
,&len
,&index
),"Unable to query header\n");
1204 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1205 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1206 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1207 ok(index
== 0, "Index was incremented\n");
1209 /* end of W version tests */
1211 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1213 len
= sizeof(buffer
);
1214 memset(buffer
, 'x', sizeof(buffer
));
1215 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1216 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1217 ok(len
== 2, "Expected 2, got %d\n", len
);
1218 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1219 ok(index
== 0, "Index was incremented\n");
1221 ok(HttpAddRequestHeaders(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1222 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1225 len
= sizeof(buffer
);
1226 strcpy(buffer
,"Warning");
1227 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1228 buffer
,&len
,&index
),"Unable to query header\n");
1229 ok(index
== 1, "Index was not incremented\n");
1230 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1231 len
= sizeof(buffer
);
1232 strcpy(buffer
,"Warning");
1233 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1234 buffer
,&len
,&index
),"Failed to get second header\n");
1235 ok(index
== 2, "Index was not incremented\n");
1236 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1237 len
= sizeof(buffer
);
1238 strcpy(buffer
,"Warning");
1239 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1240 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1242 ok(HttpAddRequestHeaders(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1245 len
= sizeof(buffer
);
1246 strcpy(buffer
,"Warning");
1247 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1248 buffer
,&len
,&index
),"Unable to query header\n");
1249 ok(index
== 1, "Index was not incremented\n");
1250 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1251 len
= sizeof(buffer
);
1252 strcpy(buffer
,"Warning");
1253 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1254 buffer
,&len
,&index
),"Failed to get second header\n");
1255 ok(index
== 2, "Index was not incremented\n");
1256 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1257 len
= sizeof(buffer
);
1258 strcpy(buffer
,"Warning");
1259 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1260 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1262 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1265 len
= sizeof(buffer
);
1266 strcpy(buffer
,"Warning");
1267 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1268 buffer
,&len
,&index
),"Unable to query header\n");
1269 ok(index
== 1, "Index was not incremented\n");
1270 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1271 len
= sizeof(buffer
);
1272 strcpy(buffer
,"Warning");
1273 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1274 buffer
,&len
,&index
),"Failed to get second header\n");
1275 ok(index
== 2, "Index was not incremented\n");
1276 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1277 len
= sizeof(buffer
);
1278 strcpy(buffer
,"Warning");
1279 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1280 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1282 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1285 len
= sizeof(buffer
);
1286 strcpy(buffer
,"Warning");
1287 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1288 buffer
,&len
,&index
),"Unable to query header\n");
1289 ok(index
== 1, "Index was not incremented\n");
1290 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1291 len
= sizeof(buffer
);
1292 strcpy(buffer
,"Warning");
1293 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1294 ok(index
== 2, "Index was not incremented\n");
1295 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1296 len
= sizeof(buffer
);
1297 strcpy(buffer
,"Warning");
1298 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1300 ok(HttpAddRequestHeaders(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1303 len
= sizeof(buffer
);
1304 strcpy(buffer
,"Warning");
1305 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1306 ok(index
== 1, "Index was not incremented\n");
1307 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1308 len
= sizeof(buffer
);
1309 strcpy(buffer
,"Warning");
1310 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1311 ok(index
== 2, "Index was not incremented\n");
1312 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1313 len
= sizeof(buffer
);
1314 strcpy(buffer
,"Warning");
1315 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1317 ok(HttpAddRequestHeaders(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1320 len
= sizeof(buffer
);
1321 strcpy(buffer
,"Warning");
1322 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1323 ok(index
== 1, "Index was not incremented\n");
1324 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1325 len
= sizeof(buffer
);
1326 strcpy(buffer
,"Warning");
1327 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1328 ok(index
== 2, "Index was not incremented\n");
1329 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1330 len
= sizeof(buffer
);
1331 strcpy(buffer
,"Warning");
1332 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1334 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");
1337 len
= sizeof(buffer
);
1338 strcpy(buffer
,"Warning");
1339 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1340 ok(index
== 1, "Index was not incremented\n");
1341 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1342 len
= sizeof(buffer
);
1343 strcpy(buffer
,"Warning");
1344 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1345 ok(index
== 2, "Index was not incremented\n");
1346 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1347 len
= sizeof(buffer
);
1348 strcpy(buffer
,"Warning");
1349 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1352 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1354 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1355 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1358 static const char contmsg
[] =
1359 "HTTP/1.1 100 Continue\r\n";
1361 static const char okmsg
[] =
1362 "HTTP/1.1 200 OK\r\n"
1363 "Server: winetest\r\n"
1366 static const char notokmsg
[] =
1367 "HTTP/1.1 400 Bad Request\r\n"
1368 "Server: winetest\r\n"
1371 static const char noauthmsg
[] =
1372 "HTTP/1.1 401 Unauthorized\r\n"
1373 "Server: winetest\r\n"
1376 static const char proxymsg
[] =
1377 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1378 "Server: winetest\r\n"
1379 "Proxy-Connection: close\r\n"
1380 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1383 static const char page1
[] =
1385 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1386 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1389 struct server_info
{
1394 static DWORD CALLBACK
server_thread(LPVOID param
)
1396 struct server_info
*si
= param
;
1399 struct sockaddr_in sa
;
1402 int last_request
= 0;
1403 char host_header
[22];
1404 static int test_b
= 0;
1406 WSAStartup(MAKEWORD(1,1), &wsaData
);
1408 s
= socket(AF_INET
, SOCK_STREAM
, 0);
1409 if (s
== INVALID_SOCKET
)
1413 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
1415 memset(&sa
, 0, sizeof sa
);
1416 sa
.sin_family
= AF_INET
;
1417 sa
.sin_port
= htons(si
->port
);
1418 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
1420 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
1426 SetEvent(si
->hEvent
);
1428 sprintf(host_header
, "Host: localhost:%d", si
->port
);
1432 c
= accept(s
, NULL
, NULL
);
1434 memset(buffer
, 0, sizeof buffer
);
1435 for(i
=0; i
<(sizeof buffer
-1); i
++)
1437 r
= recv(c
, &buffer
[i
], 1, 0);
1441 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
1442 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
1445 if (strstr(buffer
, "GET /test1"))
1447 if (!strstr(buffer
, "Content-Length: 0"))
1449 send(c
, okmsg
, sizeof okmsg
-1, 0);
1450 send(c
, page1
, sizeof page1
-1, 0);
1453 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1455 if (strstr(buffer
, "/test2"))
1457 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1459 send(c
, okmsg
, sizeof okmsg
-1, 0);
1460 send(c
, page1
, sizeof page1
-1, 0);
1463 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
1465 if (strstr(buffer
, "/test3"))
1467 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
1468 send(c
, okmsg
, sizeof okmsg
-1, 0);
1470 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
1472 if (strstr(buffer
, "/test4"))
1474 if (strstr(buffer
, "Connection: Close"))
1475 send(c
, okmsg
, sizeof okmsg
-1, 0);
1477 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1479 if (strstr(buffer
, "POST /test5"))
1481 if (strstr(buffer
, "Content-Length: 0"))
1483 send(c
, okmsg
, sizeof okmsg
-1, 0);
1484 send(c
, page1
, sizeof page1
-1, 0);
1487 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1489 if (strstr(buffer
, "GET /test6"))
1491 send(c
, contmsg
, sizeof contmsg
-1, 0);
1492 send(c
, contmsg
, sizeof contmsg
-1, 0);
1493 send(c
, okmsg
, sizeof okmsg
-1, 0);
1494 send(c
, page1
, sizeof page1
-1, 0);
1496 if (strstr(buffer
, "POST /test7"))
1498 if (strstr(buffer
, "Content-Length: 100"))
1500 send(c
, okmsg
, sizeof okmsg
-1, 0);
1501 send(c
, page1
, sizeof page1
-1, 0);
1504 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1506 if (strstr(buffer
, "/test8"))
1508 if (!strstr(buffer
, "Connection: Close") &&
1509 strstr(buffer
, "Connection: Keep-Alive") &&
1510 !strstr(buffer
, "Cache-Control: no-cache") &&
1511 !strstr(buffer
, "Pragma: no-cache") &&
1512 strstr(buffer
, host_header
))
1513 send(c
, okmsg
, sizeof okmsg
-1, 0);
1515 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1517 if (strstr(buffer
, "/test9"))
1519 if (!strstr(buffer
, "Connection: Close") &&
1520 !strstr(buffer
, "Connection: Keep-Alive") &&
1521 !strstr(buffer
, "Cache-Control: no-cache") &&
1522 !strstr(buffer
, "Pragma: no-cache") &&
1523 strstr(buffer
, host_header
))
1524 send(c
, okmsg
, sizeof okmsg
-1, 0);
1526 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1528 if (strstr(buffer
, "/testA"))
1530 if (!strstr(buffer
, "Connection: Close") &&
1531 !strstr(buffer
, "Connection: Keep-Alive") &&
1532 (strstr(buffer
, "Cache-Control: no-cache") ||
1533 strstr(buffer
, "Pragma: no-cache")) &&
1534 strstr(buffer
, host_header
))
1535 send(c
, okmsg
, sizeof okmsg
-1, 0);
1537 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1539 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
1542 send(c
, okmsg
, sizeof okmsg
-1, 0);
1543 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
1544 send(c
, okmsg
, sizeof okmsg
-1, 0);
1546 if (strstr(buffer
, "/testC"))
1548 if (strstr(buffer
, "Cookie: cookie=biscuit"))
1549 send(c
, okmsg
, sizeof okmsg
-1, 0);
1551 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1553 if (strstr(buffer
, "GET /quit"))
1555 send(c
, okmsg
, sizeof okmsg
-1, 0);
1556 send(c
, page1
, sizeof page1
-1, 0);
1562 } while (!last_request
);
1569 static void test_basic_request(int port
, const char *verb
, const char *url
)
1571 HINTERNET hi
, hc
, hr
;
1575 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1576 ok(hi
!= NULL
, "open failed\n");
1578 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1579 ok(hc
!= NULL
, "connect failed\n");
1581 hr
= HttpOpenRequest(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
1582 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1584 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1585 ok(r
, "HttpSendRequest failed\n");
1588 memset(buffer
, 0, sizeof buffer
);
1589 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
1590 ok(r
, "InternetReadFile failed\n");
1591 ok(count
== sizeof page1
- 1, "count was wrong\n");
1592 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
1594 InternetCloseHandle(hr
);
1595 InternetCloseHandle(hc
);
1596 InternetCloseHandle(hi
);
1599 static void test_proxy_indirect(int port
)
1601 HINTERNET hi
, hc
, hr
;
1605 hi
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
1606 ok(hi
!= NULL
, "open failed\n");
1608 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1609 ok(hc
!= NULL
, "connect failed\n");
1611 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1612 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1614 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1615 ok(r
, "HttpSendRequest failed\n");
1618 r
= HttpQueryInfo(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
1619 ok(r
, "HttpQueryInfo failed\n");
1620 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1623 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1624 ok(r
, "HttpQueryInfo failed\n");
1625 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1628 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &val
, &sz
, NULL
);
1629 ok(r
, "HttpQueryInfo failed\n");
1630 ok(val
== 407, "proxy code wrong\n");
1633 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
1634 ok(r
, "HttpQueryInfo failed\n");
1635 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
1638 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
1639 ok(r
, "HttpQueryInfo failed\n");
1640 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
1643 r
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
1644 ok(r
, "HttpQueryInfo failed\n");
1645 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
1648 r
= HttpQueryInfo(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
1649 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
1650 ok(r
== FALSE
, "HttpQueryInfo failed\n");
1652 InternetCloseHandle(hr
);
1653 InternetCloseHandle(hc
);
1654 InternetCloseHandle(hi
);
1657 static void test_proxy_direct(int port
)
1659 HINTERNET hi
, hc
, hr
;
1662 static CHAR username
[] = "mike",
1663 password
[] = "1101";
1665 sprintf(buffer
, "localhost:%d\n", port
);
1666 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
1667 ok(hi
!= NULL
, "open failed\n");
1669 /* try connect without authorization */
1670 hc
= InternetConnect(hi
, "www.winehq.org/", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1671 ok(hc
!= NULL
, "connect failed\n");
1673 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1674 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1676 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1677 ok(r
, "HttpSendRequest failed\n");
1680 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1681 ok(r
, "HttpQueryInfo failed\n");
1682 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1685 /* set the user + password then try again */
1687 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
1688 ok(r
, "failed to set user\n");
1690 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
1691 ok(r
, "failed to set password\n");
1694 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1695 ok(r
, "HttpSendRequest failed\n");
1697 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1698 ok(r
, "HttpQueryInfo failed\n");
1700 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
1704 InternetCloseHandle(hr
);
1705 InternetCloseHandle(hc
);
1706 InternetCloseHandle(hi
);
1709 static void test_header_handling_order(int port
)
1711 static char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
1712 static char connection
[] = "Connection: Close";
1714 static const char *types
[2] = { "*", NULL
};
1715 HINTERNET session
, connect
, request
;
1719 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1720 ok(session
!= NULL
, "InternetOpen failed\n");
1722 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1723 ok(connect
!= NULL
, "InternetConnect failed\n");
1725 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1726 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1728 ret
= HttpAddRequestHeaders(request
, authorization
, ~0UL, HTTP_ADDREQ_FLAG_ADD
);
1729 ok(ret
, "HttpAddRequestHeaders failed\n");
1731 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1732 ok(ret
, "HttpSendRequest failed\n");
1735 size
= sizeof(status
);
1736 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1737 ok(ret
, "HttpQueryInfo failed\n");
1738 ok(status
== 200, "request failed with status %u\n", status
);
1740 InternetCloseHandle(request
);
1742 request
= HttpOpenRequest(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1743 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1745 ret
= HttpSendRequest(request
, connection
, ~0UL, NULL
, 0);
1746 ok(ret
, "HttpSendRequest failed\n");
1749 size
= sizeof(status
);
1750 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1751 ok(ret
, "HttpQueryInfo failed\n");
1752 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
1754 InternetCloseHandle(request
);
1756 request
= HttpOpenRequest(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1757 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1759 ret
= HttpAddRequestHeaders(request
, "Content-Length: 100\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1760 ok(ret
, "HttpAddRequestHeaders failed\n");
1762 ret
= HttpSendRequest(request
, connection
, ~0UL, NULL
, 0);
1763 ok(ret
, "HttpSendRequest failed\n");
1766 size
= sizeof(status
);
1767 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1768 ok(ret
, "HttpQueryInfo failed\n");
1769 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
1771 InternetCloseHandle(request
);
1772 InternetCloseHandle(connect
);
1773 InternetCloseHandle(session
);
1776 static void test_connection_header(int port
)
1778 HINTERNET ses
, con
, req
;
1782 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1783 ok(ses
!= NULL
, "InternetOpen failed\n");
1785 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1786 ok(con
!= NULL
, "InternetConnect failed\n");
1788 req
= HttpOpenRequest(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1789 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1791 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1792 ok(ret
, "HttpSendRequest failed\n");
1795 size
= sizeof(status
);
1796 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1797 ok(ret
, "HttpQueryInfo failed\n");
1798 ok(status
== 200, "request failed with status %u\n", status
);
1800 InternetCloseHandle(req
);
1802 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
1803 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1805 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1806 ok(ret
, "HttpSendRequest failed\n");
1809 size
= sizeof(status
);
1810 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1811 ok(ret
, "HttpQueryInfo failed\n");
1812 ok(status
== 200, "request failed with status %u\n", status
);
1814 InternetCloseHandle(req
);
1816 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1817 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1819 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1820 ok(ret
, "HttpSendRequest failed\n");
1823 size
= sizeof(status
);
1824 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1825 ok(ret
, "HttpQueryInfo failed\n");
1826 ok(status
== 200, "request failed with status %u\n", status
);
1828 InternetCloseHandle(req
);
1830 req
= HttpOpenRequest(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1831 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1833 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1834 ok(ret
, "HttpSendRequest failed\n");
1837 size
= sizeof(status
);
1838 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1839 ok(ret
, "HttpQueryInfo failed\n");
1840 ok(status
== 200, "request failed with status %u\n", status
);
1842 InternetCloseHandle(req
);
1843 InternetCloseHandle(con
);
1844 InternetCloseHandle(ses
);
1847 static void test_http1_1(int port
)
1849 HINTERNET ses
, con
, req
;
1852 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1853 ok(ses
!= NULL
, "InternetOpen failed\n");
1855 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1856 ok(con
!= NULL
, "InternetConnect failed\n");
1858 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1859 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1861 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1864 InternetCloseHandle(req
);
1866 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1867 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1869 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1871 ok(ret
, "HttpSendRequest failed\n");
1874 InternetCloseHandle(req
);
1875 InternetCloseHandle(con
);
1876 InternetCloseHandle(ses
);
1879 static void test_cookie_header(int port
)
1881 HINTERNET ses
, con
, req
;
1882 DWORD size
, status
, error
;
1886 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1887 ok(ses
!= NULL
, "InternetOpen failed\n");
1889 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1890 ok(con
!= NULL
, "InternetConnect failed\n");
1892 InternetSetCookie("http://localhost", "cookie", "biscuit");
1894 req
= HttpOpenRequest(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1895 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1898 size
= sizeof(buffer
);
1899 SetLastError(0xdeadbeef);
1900 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1901 error
= GetLastError();
1902 ok(!ret
, "HttpQueryInfo succeeded\n");
1903 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
1905 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1906 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1909 size
= sizeof(status
);
1910 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1911 ok(ret
, "HttpQueryInfo failed\n");
1912 ok(status
== 200, "request failed with status %u\n", status
);
1915 size
= sizeof(buffer
);
1916 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1917 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
1918 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
1920 InternetCloseHandle(req
);
1921 InternetCloseHandle(con
);
1922 InternetCloseHandle(ses
);
1925 static void test_http_connection(void)
1927 struct server_info si
;
1931 si
.hEvent
= CreateEvent(NULL
, 0, 0, NULL
);
1934 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
1935 ok( hThread
!= NULL
, "create thread failed\n");
1937 r
= WaitForSingleObject(si
.hEvent
, 10000);
1938 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
1939 if (r
!= WAIT_OBJECT_0
)
1942 test_basic_request(si
.port
, "GET", "/test1");
1943 test_proxy_indirect(si
.port
);
1944 test_proxy_direct(si
.port
);
1945 test_header_handling_order(si
.port
);
1946 test_basic_request(si
.port
, "POST", "/test5");
1947 test_basic_request(si
.port
, "GET", "/test6");
1948 test_connection_header(si
.port
);
1949 test_http1_1(si
.port
);
1950 test_cookie_header(si
.port
);
1952 /* send the basic request again to shutdown the server thread */
1953 test_basic_request(si
.port
, "GET", "/quit");
1955 r
= WaitForSingleObject(hThread
, 3000);
1956 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
1957 CloseHandle(hThread
);
1960 static void test_user_agent_header(void)
1962 HINTERNET ses
, con
, req
;
1967 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1968 ok(ses
!= NULL
, "InternetOpen failed\n");
1970 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1971 ok(con
!= NULL
, "InternetConnect failed\n");
1973 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
1974 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1976 size
= sizeof(buffer
);
1977 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1978 err
= GetLastError();
1979 ok(!ret
, "HttpQueryInfo succeeded\n");
1980 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1982 ret
= HttpAddRequestHeaders(req
, "User-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1983 ok(ret
, "HttpAddRequestHeaders succeeded\n");
1985 size
= sizeof(buffer
);
1986 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1987 err
= GetLastError();
1988 ok(ret
, "HttpQueryInfo failed\n");
1989 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1991 InternetCloseHandle(req
);
1993 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
1994 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1996 size
= sizeof(buffer
);
1997 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1998 err
= GetLastError();
1999 ok(!ret
, "HttpQueryInfo succeeded\n");
2000 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
2002 ret
= HttpAddRequestHeaders(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2003 ok(ret
, "HttpAddRequestHeaders failed\n");
2006 size
= sizeof(buffer
);
2007 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
2008 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
2009 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
2011 InternetCloseHandle(req
);
2012 InternetCloseHandle(con
);
2013 InternetCloseHandle(ses
);
2016 static void test_bogus_accept_types_array(void)
2018 HINTERNET ses
, con
, req
;
2019 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", "*/*", NULL
};
2024 ses
= InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
2025 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2026 req
= HttpOpenRequest(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
2028 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2031 size
= sizeof(buffer
);
2032 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
2033 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
2034 ok(!strcmp(buffer
, ", */*, %p, , */*") || /* IE6 */
2035 !strcmp(buffer
, "*/*, %p, */*"),
2036 "got '%s' expected '*/*, %%p, */*' or ', */*, %%p, , */*'\n", buffer
);
2038 InternetCloseHandle(req
);
2039 InternetCloseHandle(con
);
2040 InternetCloseHandle(ses
);
2049 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
2051 INTERNET_ASYNC_RESULT
*result
= info
;
2052 struct context
*ctx
= (struct context
*)context
;
2054 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
2056 if (status
== INTERNET_STATUS_REQUEST_COMPLETE
)
2058 trace("request handle: 0x%08lx\n", result
->dwResult
);
2059 ctx
->req
= (HINTERNET
)result
->dwResult
;
2060 SetEvent(ctx
->event
);
2062 if (status
== INTERNET_STATUS_HANDLE_CLOSING
)
2064 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
2066 if (InternetQueryOption(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
2067 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
2068 SetEvent(ctx
->event
);
2072 static void test_open_url_async(void)
2081 ctx
.event
= CreateEvent(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
2083 ses
= InternetOpen("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2084 ok(ses
!= NULL
, "InternetOpen failed\n");
2086 pInternetSetStatusCallbackA(ses
, cb
);
2087 ResetEvent(ctx
.event
);
2089 req
= InternetOpenUrl(ses
, "http://www.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
2090 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
2092 WaitForSingleObject(ctx
.event
, INFINITE
);
2095 size
= sizeof(type
);
2096 ret
= InternetQueryOption(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
2097 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
2098 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
2099 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
2102 ret
= HttpQueryInfo(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
2103 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
2104 ok(size
> 0, "expected size > 0\n");
2106 ResetEvent(ctx
.event
);
2107 InternetCloseHandle(ctx
.req
);
2108 WaitForSingleObject(ctx
.event
, INFINITE
);
2110 InternetCloseHandle(ses
);
2111 CloseHandle(ctx
.event
);
2114 #define STATUS_STRING(status) \
2115 memcpy(status_string[status], #status, sizeof(CHAR) * \
2116 (strlen(#status) < MAX_STATUS_NAME ? \
2118 MAX_STATUS_NAME - 1))
2119 static void init_status_tests(void)
2121 memset(expect
, 0, sizeof(expect
));
2122 memset(optional
, 0, sizeof(optional
));
2123 memset(wine_allow
, 0, sizeof(wine_allow
));
2124 memset(notified
, 0, sizeof(notified
));
2125 memset(status_string
, 0, sizeof(status_string
));
2126 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
2127 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
2128 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2129 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2130 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
2131 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
2132 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
2133 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
2134 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
2135 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
2136 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
2137 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
2138 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
2139 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
2140 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
2141 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
2142 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
2143 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
2144 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
2145 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
2146 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
2147 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
2148 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
2149 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
2150 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
2151 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
2153 #undef STATUS_STRING
2158 hdll
= GetModuleHandleA("wininet.dll");
2159 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
2160 pInternetTimeFromSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeA");
2161 pInternetTimeFromSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeW");
2162 pInternetTimeToSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeA");
2163 pInternetTimeToSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeW");
2165 if (!pInternetSetStatusCallbackA
)
2166 skip("skipping the InternetReadFile tests\n");
2169 init_status_tests();
2170 InternetReadFile_test(INTERNET_FLAG_ASYNC
);
2171 InternetReadFile_test(0);
2172 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
2173 test_open_url_async();
2175 InternetOpenRequest_test();
2177 InternetOpenUrlA_test();
2178 if (!pInternetTimeFromSystemTimeA
)
2179 skip("skipping the InternetTime tests\n");
2182 InternetTimeFromSystemTimeA_test();
2183 InternetTimeFromSystemTimeW_test();
2184 InternetTimeToSystemTimeA_test();
2185 InternetTimeToSystemTimeW_test();
2187 HttpSendRequestEx_test();
2189 test_http_connection();
2190 test_user_agent_header();
2191 test_bogus_accept_types_array();