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 HANDLE hCompleteEvent;
37 static BOOL bResponseReceived;
38 static BOOL bReceivingResponse;
40 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET ,INTERNET_STATUS_CALLBACK);
41 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
42 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
43 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
44 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
47 static VOID WINAPI callback(
50 DWORD dwInternetStatus,
51 LPVOID lpvStatusInformation,
52 DWORD dwStatusInformationLength
55 switch (dwInternetStatus)
57 case INTERNET_STATUS_RESOLVING_NAME:
58 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
59 GetCurrentThreadId(), hInternet, dwContext,
60 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
61 *(LPSTR)lpvStatusInformation = '\0';
63 case INTERNET_STATUS_NAME_RESOLVED:
64 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
65 GetCurrentThreadId(), hInternet, dwContext,
66 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
67 *(LPSTR)lpvStatusInformation = '\0';
69 case INTERNET_STATUS_CONNECTING_TO_SERVER:
70 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
71 GetCurrentThreadId(), hInternet, dwContext,
72 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
73 *(LPSTR)lpvStatusInformation = '\0';
75 case INTERNET_STATUS_CONNECTED_TO_SERVER:
76 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
77 GetCurrentThreadId(), hInternet, dwContext,
78 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
79 *(LPSTR)lpvStatusInformation = '\0';
81 case INTERNET_STATUS_SENDING_REQUEST:
82 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
83 GetCurrentThreadId(), hInternet, dwContext,
84 lpvStatusInformation,dwStatusInformationLength);
86 case INTERNET_STATUS_REQUEST_SENT:
87 ok(dwStatusInformationLength == sizeof(DWORD),
88 "info length should be sizeof(DWORD) instead of %d\n",
89 dwStatusInformationLength);
90 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
91 GetCurrentThreadId(), hInternet, dwContext,
92 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
94 case INTERNET_STATUS_RECEIVING_RESPONSE:
95 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
96 GetCurrentThreadId(), hInternet, dwContext,
97 lpvStatusInformation,dwStatusInformationLength);
98 bReceivingResponse = TRUE;
100 case INTERNET_STATUS_RESPONSE_RECEIVED:
101 ok(dwStatusInformationLength == sizeof(DWORD),
102 "info length should be sizeof(DWORD) instead of %d\n",
103 dwStatusInformationLength);
104 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
105 GetCurrentThreadId(), hInternet, dwContext,
106 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
107 bResponseReceived = TRUE;
109 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
110 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
111 GetCurrentThreadId(), hInternet,dwContext,
112 lpvStatusInformation,dwStatusInformationLength);
114 case INTERNET_STATUS_PREFETCH:
115 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
116 GetCurrentThreadId(), hInternet, dwContext,
117 lpvStatusInformation,dwStatusInformationLength);
119 case INTERNET_STATUS_CLOSING_CONNECTION:
120 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
121 GetCurrentThreadId(), hInternet, dwContext,
122 lpvStatusInformation,dwStatusInformationLength);
124 case INTERNET_STATUS_CONNECTION_CLOSED:
125 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
126 GetCurrentThreadId(), hInternet, dwContext,
127 lpvStatusInformation,dwStatusInformationLength);
129 case INTERNET_STATUS_HANDLE_CREATED:
130 ok(dwStatusInformationLength == sizeof(HINTERNET),
131 "info length should be sizeof(HINTERNET) instead of %d\n",
132 dwStatusInformationLength);
133 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
134 GetCurrentThreadId(), hInternet, dwContext,
135 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
137 case INTERNET_STATUS_HANDLE_CLOSING:
138 ok(dwStatusInformationLength == sizeof(HINTERNET),
139 "info length should be sizeof(HINTERNET) instead of %d\n",
140 dwStatusInformationLength);
141 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
142 GetCurrentThreadId(), hInternet, dwContext,
143 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
145 case INTERNET_STATUS_REQUEST_COMPLETE:
147 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
148 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
149 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
150 dwStatusInformationLength);
151 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%d,%d} %d\n",
152 GetCurrentThreadId(), hInternet, dwContext,
153 iar->dwResult,iar->dwError,dwStatusInformationLength);
154 SetEvent(hCompleteEvent);
157 case INTERNET_STATUS_REDIRECT:
158 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
159 GetCurrentThreadId(), hInternet, dwContext,
160 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
161 *(LPSTR)lpvStatusInformation = '\0';
163 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
164 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
165 GetCurrentThreadId(), hInternet, dwContext,
166 lpvStatusInformation, dwStatusInformationLength);
169 trace("%04x:Callback %p 0x%lx %d %p %d\n",
170 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
171 lpvStatusInformation, dwStatusInformationLength);
175 static void InternetReadFile_test(int flags)
181 const char *types[2] = { "*", NULL };
182 HINTERNET hi, hic = 0, hor = 0;
184 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
186 trace("Starting InternetReadFile test with flags 0x%x\n",flags);
188 trace("InternetOpenA <--\n");
189 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
190 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
191 trace("InternetOpenA -->\n");
193 if (hi == 0x0) goto abort;
195 pInternetSetStatusCallbackA(hi,&callback);
197 trace("InternetConnectA <--\n");
198 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
199 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
200 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
201 trace("InternetConnectA -->\n");
203 if (hic == 0x0) goto abort;
205 trace("HttpOpenRequestA <--\n");
206 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
207 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
209 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
211 * If the internet name can't be resolved we are probably behind
212 * a firewall or in some other way not directly connected to the
213 * Internet. Not enough reason to fail the test. Just ignore and
217 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
219 trace("HttpOpenRequestA -->\n");
221 if (hor == 0x0) goto abort;
223 trace("HttpSendRequestA -->\n");
224 SetLastError(0xdeadbeef);
225 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
226 if (flags & INTERNET_FLAG_ASYNC)
227 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
228 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
230 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
231 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
232 trace("HttpSendRequestA <--\n");
234 if (flags & INTERNET_FLAG_ASYNC)
235 WaitForSingleObject(hCompleteEvent, INFINITE);
238 rc = InternetQueryOptionA(hor,INTERNET_OPTION_REQUEST_FLAGS,&out,&length);
239 trace("Option 0x17 -> %i %i\n",rc,out);
242 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
243 trace("Option 0x22 -> %i %s\n",rc,buffer);
246 rc = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
248 trace("Option 0x16 -> %i %s\n",rc,buffer);
251 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
253 trace("Option 0x22 -> %i %s\n",rc,buffer);
256 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
257 trace("Option 0x5 -> %i %s (%u)\n",rc,buffer,GetLastError());
260 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
262 trace("Option 0x1 -> %i %s\n",rc,buffer);
264 SetLastError(0xdeadbeef);
265 rc = InternetReadFile(NULL, buffer, 100, &length);
266 ok(!rc, "InternetReadFile should have failed\n");
267 ok(GetLastError() == ERROR_INVALID_HANDLE,
268 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
272 trace("Entering Query loop\n");
276 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
277 ok(!(rc == 0 && length != 0),"InternetQueryDataAvailable failed\n");
282 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
284 rc = InternetReadFile(hor,buffer,length,&length);
288 trace("ReadFile -> %i %i\n",rc,length);
290 HeapFree(GetProcessHeap(),0,buffer);
295 SetLastError(0xdeadbeef);
296 rc = InternetCloseHandle(hor);
297 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
298 SetLastError(0xdeadbeef);
299 rc = InternetCloseHandle(hor);
300 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
301 ok (GetLastError() == ERROR_INVALID_HANDLE,
302 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %u\n",
306 rc = InternetCloseHandle(hic);
307 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
310 rc = InternetCloseHandle(hi);
311 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
312 if (flags & INTERNET_FLAG_ASYNC)
315 CloseHandle(hCompleteEvent);
318 static void InternetReadFileExA_test(int flags)
322 const char *types[2] = { "*", NULL };
323 HINTERNET hi, hic = 0, hor = 0;
324 INTERNET_BUFFERS inetbuffers;
326 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
328 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
330 trace("InternetOpenA <--\n");
331 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
332 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
333 trace("InternetOpenA -->\n");
335 if (hi == 0x0) goto abort;
337 pInternetSetStatusCallbackA(hi,&callback);
339 trace("InternetConnectA <--\n");
340 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
341 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
342 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
343 trace("InternetConnectA -->\n");
345 if (hic == 0x0) goto abort;
347 trace("HttpOpenRequestA <--\n");
348 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
349 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
351 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
353 * If the internet name can't be resolved we are probably behind
354 * a firewall or in some other way not directly connected to the
355 * Internet. Not enough reason to fail the test. Just ignore and
359 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
361 trace("HttpOpenRequestA -->\n");
363 if (hor == 0x0) goto abort;
365 trace("HttpSendRequestA -->\n");
366 SetLastError(0xdeadbeef);
367 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
368 if (flags & INTERNET_FLAG_ASYNC)
369 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
370 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
372 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
373 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
374 trace("HttpSendRequestA <--\n");
376 if (!rc && (GetLastError() == ERROR_IO_PENDING))
377 WaitForSingleObject(hCompleteEvent, INFINITE);
379 /* tests invalid dwStructSize */
380 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
381 inetbuffers.lpcszHeader = NULL;
382 inetbuffers.dwHeadersLength = 0;
383 inetbuffers.dwBufferLength = 10;
384 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
385 inetbuffers.dwOffsetHigh = 1234;
386 inetbuffers.dwOffsetLow = 5678;
387 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
388 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
389 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
390 rc ? "TRUE" : "FALSE", GetLastError());
391 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
393 /* tests to see whether lpcszHeader is used - it isn't */
394 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
395 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
396 inetbuffers.dwHeadersLength = 255;
397 inetbuffers.dwBufferLength = 0;
398 inetbuffers.lpvBuffer = NULL;
399 inetbuffers.dwOffsetHigh = 1234;
400 inetbuffers.dwOffsetLow = 5678;
401 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
402 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
404 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
405 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
406 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
407 rc ? "TRUE" : "FALSE", GetLastError());
410 trace("Entering Query loop\n");
414 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
415 inetbuffers.dwBufferLength = 1024;
416 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
417 inetbuffers.dwOffsetHigh = 1234;
418 inetbuffers.dwOffsetLow = 5678;
420 bReceivingResponse = FALSE;
421 bResponseReceived = FALSE;
422 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
425 if (GetLastError() == ERROR_IO_PENDING)
427 trace("InternetReadFileEx -> PENDING\n");
428 ok(bReceivingResponse, "INTERNET_STATUS_RECEIVING_RESPONSE should have been sent to callback function\n");
429 WaitForSingleObject(hCompleteEvent, INFINITE);
430 ok(!bResponseReceived, "INTERNET_STATUS_RESPONSE_RECEIVED should not have been sent to callback function\n");
434 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
440 trace("InternetReadFileEx -> SUCCEEDED\n");
441 ok(bReceivingResponse, "INTERNET_STATUS_RECEIVING_RESPONSE should have been sent to callback function\n");
442 ok(bResponseReceived, "INTERNET_STATUS_RESPONSE_RECEIVED should have been sent to callback function\n");
445 trace("read %i bytes\n", inetbuffers.dwBufferLength);
446 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
448 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
449 "InternetReadFileEx sets offsets to 0x%x%08x\n",
450 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
452 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
454 if (!inetbuffers.dwBufferLength)
457 length += inetbuffers.dwBufferLength;
459 ok(length > 0, "failed to read any of the document\n");
460 trace("Finished. Read %d bytes\n", length);
464 rc = InternetCloseHandle(hor);
465 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
466 rc = InternetCloseHandle(hor);
467 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
470 rc = InternetCloseHandle(hic);
471 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
474 rc = InternetCloseHandle(hi);
475 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
476 if (flags & INTERNET_FLAG_ASYNC)
479 CloseHandle(hCompleteEvent);
482 static void InternetOpenUrlA_test(void)
484 HINTERNET myhinternet, myhttp;
486 DWORD size, readbytes, totalbytes=0;
489 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
490 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
492 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
493 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
496 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
497 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
498 if (GetLastError() == 12007)
499 return; /* WinXP returns this when not connected to the net */
500 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
501 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
502 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
503 totalbytes += readbytes;
504 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
505 totalbytes += readbytes;
506 trace("read 0x%08x bytes\n",totalbytes);
509 static void InternetTimeFromSystemTimeA_test(void)
512 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
513 char string[INTERNET_RFC1123_BUFSIZE];
514 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
516 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
517 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
519 ok( !memcmp( string, expect, sizeof(expect) ),
520 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
523 static void InternetTimeFromSystemTimeW_test(void)
526 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
527 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
528 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
529 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
531 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
532 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
534 ok( !memcmp( string, expect, sizeof(expect) ),
535 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
538 static void InternetTimeToSystemTimeA_test(void)
542 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
543 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
544 static const char string2[] = " fri 7 jan 2005 12 06 35";
546 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
547 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
548 ok( !memcmp( &time, &expect, sizeof(expect) ),
549 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
551 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
552 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
553 ok( !memcmp( &time, &expect, sizeof(expect) ),
554 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
557 static void InternetTimeToSystemTimeW_test(void)
561 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
562 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
563 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
564 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
565 '1','2',' ','0','6',' ','3','5',0 };
566 static const WCHAR string3[] = { 'F','r',0 };
568 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
569 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
571 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
572 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
574 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
575 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
577 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
578 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
580 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
581 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
582 ok( !memcmp( &time, &expect, sizeof(expect) ),
583 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
585 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
586 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
587 ok( !memcmp( &time, &expect, sizeof(expect) ),
588 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
590 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
591 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
594 static void HttpSendRequestEx_test(void)
600 INTERNET_BUFFERS BufferIn;
601 DWORD dwBytesWritten;
607 static char szPostData[] = "mode=Test";
608 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
610 hSession = InternetOpen("Wine Regression Test",
611 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
612 ok( hSession != NULL ,"Unable to open Internet session\n");
613 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
614 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
616 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
617 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
618 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
619 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
621 trace( "Network unreachable, skipping test\n" );
624 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
627 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
628 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
629 BufferIn.lpcszHeader = szContentType;
630 BufferIn.dwHeadersLength = sizeof(szContentType);
631 BufferIn.dwHeadersTotal = sizeof(szContentType);
632 BufferIn.lpvBuffer = szPostData;
633 BufferIn.dwBufferLength = 3;
634 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
635 BufferIn.dwOffsetLow = 0;
636 BufferIn.dwOffsetHigh = 0;
638 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
639 ok(ret, "HttpSendRequestEx Failed with error %u\n", GetLastError());
641 for (i = 3; szPostData[i]; i++)
642 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
643 "InternetWriteFile failed\n");
645 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
647 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
648 "Unable to read response\n");
649 szBuffer[dwBytesRead] = 0;
651 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
652 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0,"Got string %s\n",szBuffer);
654 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
656 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
657 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
660 static void InternetOpenRequest_test(void)
662 HINTERNET session, connect, request;
663 static const char *types[] = { "*", "", NULL };
664 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
665 static const WCHAR *typesW[] = { any, empty, NULL };
668 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
669 ok(session != NULL ,"Unable to open Internet session\n");
671 connect = InternetConnectA(session, "winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
672 INTERNET_SERVICE_HTTP, 0, 0);
673 ok(connect != NULL, "Unable to connect to http://winehq.org\n");
675 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
676 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
678 trace( "Network unreachable, skipping test\n" );
681 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
683 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
684 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
685 ok(InternetCloseHandle(request), "Close request handle failed\n");
687 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
688 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
690 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
691 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
692 ok(InternetCloseHandle(request), "Close request handle failed\n");
695 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
696 ok(InternetCloseHandle(session), "Close session handle failed\n");
699 static void HttpHeaders_test(void)
708 hSession = InternetOpen("Wine Regression Test",
709 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
710 ok( hSession != NULL ,"Unable to open Internet session\n");
711 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
712 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
714 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
715 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
716 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
717 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
719 trace( "Network unreachable, skipping test\n" );
722 ok( hRequest != NULL, "Failed to open request handle\n");
725 len = sizeof(buffer);
726 strcpy(buffer,"Warning");
727 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
728 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
730 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
731 "Failed to add new header\n");
734 len = sizeof(buffer);
735 strcpy(buffer,"Warning");
736 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
737 buffer,&len,&index),"Unable to query header\n");
738 ok(index == 1, "Index was not incremented\n");
739 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
740 len = sizeof(buffer);
741 strcpy(buffer,"Warning");
742 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
743 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
745 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
746 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
749 len = sizeof(buffer);
750 strcpy(buffer,"Warning");
751 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
752 buffer,&len,&index),"Unable to query header\n");
753 ok(index == 1, "Index was not incremented\n");
754 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
755 len = sizeof(buffer);
756 strcpy(buffer,"Warning");
757 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
758 buffer,&len,&index),"Failed to get second header\n");
759 ok(index == 2, "Index was not incremented\n");
760 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
761 len = sizeof(buffer);
762 strcpy(buffer,"Warning");
763 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
764 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
766 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
769 len = sizeof(buffer);
770 strcpy(buffer,"Warning");
771 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
772 buffer,&len,&index),"Unable to query header\n");
773 ok(index == 1, "Index was not incremented\n");
774 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
775 len = sizeof(buffer);
776 strcpy(buffer,"Warning");
777 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
778 buffer,&len,&index),"Failed to get second header\n");
779 ok(index == 2, "Index was not incremented\n");
780 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
781 len = sizeof(buffer);
782 strcpy(buffer,"Warning");
783 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
784 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
786 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
789 len = sizeof(buffer);
790 strcpy(buffer,"Warning");
791 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
792 buffer,&len,&index),"Unable to query header\n");
793 ok(index == 1, "Index was not incremented\n");
794 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
795 len = sizeof(buffer);
796 strcpy(buffer,"Warning");
797 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
798 buffer,&len,&index),"Failed to get second header\n");
799 ok(index == 2, "Index was not incremented\n");
800 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
801 len = sizeof(buffer);
802 strcpy(buffer,"Warning");
803 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
804 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
806 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
809 len = sizeof(buffer);
810 strcpy(buffer,"Warning");
811 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
812 buffer,&len,&index),"Unable to query header\n");
813 ok(index == 1, "Index was not incremented\n");
814 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
815 len = sizeof(buffer);
816 strcpy(buffer,"Warning");
817 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
818 ok(index == 2, "Index was not incremented\n");
819 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
820 len = sizeof(buffer);
821 strcpy(buffer,"Warning");
822 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
824 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
827 len = sizeof(buffer);
828 strcpy(buffer,"Warning");
829 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
830 ok(index == 1, "Index was not incremented\n");
831 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
832 len = sizeof(buffer);
833 strcpy(buffer,"Warning");
834 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
835 ok(index == 2, "Index was not incremented\n");
836 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
837 len = sizeof(buffer);
838 strcpy(buffer,"Warning");
839 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
841 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
844 len = sizeof(buffer);
845 strcpy(buffer,"Warning");
846 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
847 ok(index == 1, "Index was not incremented\n");
848 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
849 len = sizeof(buffer);
850 strcpy(buffer,"Warning");
851 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
852 ok(index == 2, "Index was not incremented\n");
853 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
854 len = sizeof(buffer);
855 strcpy(buffer,"Warning");
856 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
858 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");
861 len = sizeof(buffer);
862 strcpy(buffer,"Warning");
863 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
864 ok(index == 1, "Index was not incremented\n");
865 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
866 len = sizeof(buffer);
867 strcpy(buffer,"Warning");
868 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
869 ok(index == 2, "Index was not incremented\n");
870 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
871 len = sizeof(buffer);
872 strcpy(buffer,"Warning");
873 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
876 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
878 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
879 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
882 static const char okmsg[] =
883 "HTTP/1.0 200 OK\r\n"
884 "Server: winetest\r\n"
887 static const char proxymsg[] =
888 "HTTP/1.1 407 Proxy Authentication Required\r\n"
889 "Server: winetest\r\n"
890 "Proxy-Connection: close\r\n"
891 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
894 static const char page1[] =
896 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
897 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
905 static DWORD CALLBACK server_thread(LPVOID param)
907 struct server_info *si = param;
909 struct sockaddr_in sa;
912 int last_request = 0;
914 WSAStartup(MAKEWORD(1,1), &wsaData);
916 s = socket(AF_INET, SOCK_STREAM, 0);
921 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
923 memset(&sa, 0, sizeof sa);
924 sa.sin_family = AF_INET;
925 sa.sin_port = htons(si->port);
926 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
928 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
934 SetEvent(si->hEvent);
938 c = accept(s, NULL, NULL);
940 memset(buffer, 0, sizeof buffer);
941 for(i=0; i<(sizeof buffer-1); i++)
943 r = recv(c, &buffer[i], 1, 0);
947 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
948 buffer[i-3] == '\r' && buffer[i-1] == '\r')
952 if (strstr(buffer, "GET /test1"))
954 send(c, okmsg, sizeof okmsg-1, 0);
955 send(c, page1, sizeof page1-1, 0);
958 if (strstr(buffer, "/test2"))
960 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
962 send(c, okmsg, sizeof okmsg-1, 0);
963 send(c, page1, sizeof page1-1, 0);
966 send(c, proxymsg, sizeof proxymsg-1, 0);
969 if (strstr(buffer, "/quit"))
971 send(c, okmsg, sizeof okmsg-1, 0);
972 send(c, page1, sizeof page1-1, 0);
978 } while (!last_request);
985 static void test_basic_request(int port, const char *url)
987 HINTERNET hi, hc, hr;
991 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
992 ok(hi != NULL, "open failed\n");
994 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
995 ok(hc != NULL, "connect failed\n");
997 hr = HttpOpenRequest(hc, NULL, url, NULL, NULL, NULL, 0, 0);
998 ok(hr != NULL, "HttpOpenRequest failed\n");
1000 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1001 ok(r, "HttpSendRequest failed\n");
1004 memset(buffer, 0, sizeof buffer);
1005 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
1006 ok(r, "InternetReadFile failed\n");
1007 ok(count == sizeof page1 - 1, "count was wrong\n");
1008 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
1010 InternetCloseHandle(hr);
1011 InternetCloseHandle(hc);
1012 InternetCloseHandle(hi);
1015 static void test_proxy_indirect(int port)
1017 HINTERNET hi, hc, hr;
1021 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
1022 ok(hi != NULL, "open failed\n");
1024 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1025 ok(hc != NULL, "connect failed\n");
1027 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1028 ok(hr != NULL, "HttpOpenRequest failed\n");
1030 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1031 ok(r, "HttpSendRequest failed\n");
1034 r = HttpQueryInfo(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
1035 ok(r, "HttpQueryInfo failed\n");
1036 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1039 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1040 ok(r, "HttpQueryInfo failed\n");
1041 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1044 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &val, &sz, NULL);
1045 ok(r, "HttpQueryInfo failed\n");
1046 ok(val == 407, "proxy code wrong\n");
1049 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
1050 ok(r, "HttpQueryInfo failed\n");
1051 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
1054 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
1055 ok(r, "HttpQueryInfo failed\n");
1056 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
1059 r = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
1060 ok(r, "HttpQueryInfo failed\n");
1061 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
1064 r = HttpQueryInfo(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
1065 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
1066 ok(r == FALSE, "HttpQueryInfo failed\n");
1068 InternetCloseHandle(hr);
1069 InternetCloseHandle(hc);
1070 InternetCloseHandle(hi);
1073 static void test_proxy_direct(int port)
1075 HINTERNET hi, hc, hr;
1078 static CHAR username[] = "mike",
1079 password[] = "1101";
1081 sprintf(buffer, "localhost:%d\n", port);
1082 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
1083 ok(hi != NULL, "open failed\n");
1085 /* try connect without authorization */
1086 hc = InternetConnect(hi, "www.winehq.org/", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1087 ok(hc != NULL, "connect failed\n");
1089 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1090 ok(hr != NULL, "HttpOpenRequest failed\n");
1092 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1093 ok(r, "HttpSendRequest failed\n");
1096 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1097 ok(r, "HttpQueryInfo failed\n");
1098 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1101 /* set the user + password then try again */
1103 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
1104 ok(r, "failed to set user\n");
1106 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
1107 ok(r, "failed to set password\n");
1110 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1111 ok(r, "HttpSendRequest failed\n");
1113 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1114 ok(r, "HttpQueryInfo failed\n");
1116 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
1120 InternetCloseHandle(hr);
1121 InternetCloseHandle(hc);
1122 InternetCloseHandle(hi);
1125 static void test_http_connection(void)
1127 struct server_info si;
1131 si.hEvent = CreateEvent(NULL, 0, 0, NULL);
1134 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
1135 ok( hThread != NULL, "create thread failed\n");
1137 r = WaitForSingleObject(si.hEvent, 10000);
1138 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
1139 if (r != WAIT_OBJECT_0)
1142 test_basic_request(si.port, "/test1");
1143 test_proxy_indirect(si.port);
1144 test_proxy_direct(si.port);
1146 /* send the basic request again to shutdown the server thread */
1147 test_basic_request(si.port, "/quit");
1149 r = WaitForSingleObject(hThread, 3000);
1150 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
1151 CloseHandle(hThread);
1157 hdll = GetModuleHandleA("wininet.dll");
1158 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
1159 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1160 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1161 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1162 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1164 if (!pInternetSetStatusCallbackA)
1165 skip("skipping the InternetReadFile tests\n");
1168 InternetReadFile_test(INTERNET_FLAG_ASYNC);
1169 InternetReadFile_test(0);
1170 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
1172 InternetOpenRequest_test();
1173 InternetOpenUrlA_test();
1174 if (!pInternetTimeFromSystemTimeA)
1175 skip("skipping the InternetTime tests\n");
1178 InternetTimeFromSystemTimeA_test();
1179 InternetTimeFromSystemTimeW_test();
1180 InternetTimeToSystemTimeA_test();
1181 InternetTimeToSystemTimeW_test();
1183 HttpSendRequestEx_test();
1185 test_http_connection();