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;
38 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET ,INTERNET_STATUS_CALLBACK);
39 static BOOL (WINAPI *pInternetTimeFromSystemTimeA)(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
40 static BOOL (WINAPI *pInternetTimeFromSystemTimeW)(CONST SYSTEMTIME *,DWORD ,LPWSTR ,DWORD);
41 static BOOL (WINAPI *pInternetTimeToSystemTimeA)(LPCSTR ,SYSTEMTIME *,DWORD);
42 static BOOL (WINAPI *pInternetTimeToSystemTimeW)(LPCWSTR ,SYSTEMTIME *,DWORD);
45 static VOID WINAPI callback(
48 DWORD dwInternetStatus,
49 LPVOID lpvStatusInformation,
50 DWORD dwStatusInformationLength
53 switch (dwInternetStatus)
55 case INTERNET_STATUS_RESOLVING_NAME:
56 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
57 GetCurrentThreadId(), hInternet, dwContext,
58 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
59 *(LPSTR)lpvStatusInformation = '\0';
61 case INTERNET_STATUS_NAME_RESOLVED:
62 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
63 GetCurrentThreadId(), hInternet, dwContext,
64 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
65 *(LPSTR)lpvStatusInformation = '\0';
67 case INTERNET_STATUS_CONNECTING_TO_SERVER:
68 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
69 GetCurrentThreadId(), hInternet, dwContext,
70 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
71 *(LPSTR)lpvStatusInformation = '\0';
73 case INTERNET_STATUS_CONNECTED_TO_SERVER:
74 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
75 GetCurrentThreadId(), hInternet, dwContext,
76 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
77 *(LPSTR)lpvStatusInformation = '\0';
79 case INTERNET_STATUS_SENDING_REQUEST:
80 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
81 GetCurrentThreadId(), hInternet, dwContext,
82 lpvStatusInformation,dwStatusInformationLength);
84 case INTERNET_STATUS_REQUEST_SENT:
85 ok(dwStatusInformationLength == sizeof(DWORD),
86 "info length should be sizeof(DWORD) instead of %d\n",
87 dwStatusInformationLength);
88 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
89 GetCurrentThreadId(), hInternet, dwContext,
90 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
92 case INTERNET_STATUS_RECEIVING_RESPONSE:
93 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
94 GetCurrentThreadId(), hInternet, dwContext,
95 lpvStatusInformation,dwStatusInformationLength);
97 case INTERNET_STATUS_RESPONSE_RECEIVED:
98 ok(dwStatusInformationLength == sizeof(DWORD),
99 "info length should be sizeof(DWORD) instead of %d\n",
100 dwStatusInformationLength);
101 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
102 GetCurrentThreadId(), hInternet, dwContext,
103 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
105 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
106 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
107 GetCurrentThreadId(), hInternet,dwContext,
108 lpvStatusInformation,dwStatusInformationLength);
110 case INTERNET_STATUS_PREFETCH:
111 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
112 GetCurrentThreadId(), hInternet, dwContext,
113 lpvStatusInformation,dwStatusInformationLength);
115 case INTERNET_STATUS_CLOSING_CONNECTION:
116 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
117 GetCurrentThreadId(), hInternet, dwContext,
118 lpvStatusInformation,dwStatusInformationLength);
120 case INTERNET_STATUS_CONNECTION_CLOSED:
121 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
122 GetCurrentThreadId(), hInternet, dwContext,
123 lpvStatusInformation,dwStatusInformationLength);
125 case INTERNET_STATUS_HANDLE_CREATED:
126 ok(dwStatusInformationLength == sizeof(HINTERNET),
127 "info length should be sizeof(HINTERNET) instead of %d\n",
128 dwStatusInformationLength);
129 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
130 GetCurrentThreadId(), hInternet, dwContext,
131 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
133 case INTERNET_STATUS_HANDLE_CLOSING:
134 ok(dwStatusInformationLength == sizeof(HINTERNET),
135 "info length should be sizeof(HINTERNET) instead of %d\n",
136 dwStatusInformationLength);
137 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
138 GetCurrentThreadId(), hInternet, dwContext,
139 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
141 case INTERNET_STATUS_REQUEST_COMPLETE:
143 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
144 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
145 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
146 dwStatusInformationLength);
147 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%d,%d} %d\n",
148 GetCurrentThreadId(), hInternet, dwContext,
149 iar->dwResult,iar->dwError,dwStatusInformationLength);
150 SetEvent(hCompleteEvent);
153 case INTERNET_STATUS_REDIRECT:
154 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
155 GetCurrentThreadId(), hInternet, dwContext,
156 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
157 *(LPSTR)lpvStatusInformation = '\0';
159 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
160 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
161 GetCurrentThreadId(), hInternet, dwContext,
162 lpvStatusInformation, dwStatusInformationLength);
165 trace("%04x:Callback %p 0x%lx %d %p %d\n",
166 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
167 lpvStatusInformation, dwStatusInformationLength);
171 static void InternetReadFile_test(int flags)
177 const char *types[2] = { "*", NULL };
178 HINTERNET hi, hic = 0, hor = 0;
180 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
182 trace("Starting InternetReadFile test with flags 0x%x\n",flags);
184 trace("InternetOpenA <--\n");
185 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
186 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
187 trace("InternetOpenA -->\n");
189 if (hi == 0x0) goto abort;
191 pInternetSetStatusCallbackA(hi,&callback);
193 trace("InternetConnectA <--\n");
194 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
195 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
196 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
197 trace("InternetConnectA -->\n");
199 if (hic == 0x0) goto abort;
201 trace("HttpOpenRequestA <--\n");
202 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
203 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
205 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
207 * If the internet name can't be resolved we are probably behind
208 * a firewall or in some other way not directly connected to the
209 * Internet. Not enough reason to fail the test. Just ignore and
213 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
215 trace("HttpOpenRequestA -->\n");
217 if (hor == 0x0) goto abort;
219 trace("HttpSendRequestA -->\n");
220 SetLastError(0xdeadbeef);
221 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
222 if (flags & INTERNET_FLAG_ASYNC)
223 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
224 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
226 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
227 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
228 trace("HttpSendRequestA <--\n");
230 if (flags & INTERNET_FLAG_ASYNC)
231 WaitForSingleObject(hCompleteEvent, INFINITE);
234 rc = InternetQueryOptionA(hor,INTERNET_OPTION_REQUEST_FLAGS,&out,&length);
235 trace("Option 0x17 -> %i %i\n",rc,out);
238 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
239 trace("Option 0x22 -> %i %s\n",rc,buffer);
242 rc = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
244 trace("Option 0x16 -> %i %s\n",rc,buffer);
247 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
249 trace("Option 0x22 -> %i %s\n",rc,buffer);
252 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
253 trace("Option 0x5 -> %i %s (%u)\n",rc,buffer,GetLastError());
256 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
258 trace("Option 0x1 -> %i %s\n",rc,buffer);
260 SetLastError(0xdeadbeef);
261 rc = InternetReadFile(NULL, buffer, 100, &length);
262 ok(!rc, "InternetReadFile should have failed\n");
263 ok(GetLastError() == ERROR_INVALID_HANDLE,
264 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
268 trace("Entering Query loop\n");
272 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
273 ok(!(rc == 0 && length != 0),"InternetQueryDataAvailable failed\n");
278 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
280 rc = InternetReadFile(hor,buffer,length,&length);
284 trace("ReadFile -> %i %i\n",rc,length);
286 HeapFree(GetProcessHeap(),0,buffer);
291 SetLastError(0xdeadbeef);
292 rc = InternetCloseHandle(hor);
293 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
294 SetLastError(0xdeadbeef);
295 rc = InternetCloseHandle(hor);
296 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
297 ok (GetLastError() == ERROR_INVALID_HANDLE,
298 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %u\n",
302 rc = InternetCloseHandle(hic);
303 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
306 rc = InternetCloseHandle(hi);
307 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
308 if (flags & INTERNET_FLAG_ASYNC)
311 CloseHandle(hCompleteEvent);
314 static void InternetReadFileExA_test(int flags)
318 const char *types[2] = { "*", NULL };
319 HINTERNET hi, hic = 0, hor = 0;
320 INTERNET_BUFFERS inetbuffers;
322 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
324 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
326 trace("InternetOpenA <--\n");
327 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
328 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
329 trace("InternetOpenA -->\n");
331 if (hi == 0x0) goto abort;
333 pInternetSetStatusCallbackA(hi,&callback);
335 trace("InternetConnectA <--\n");
336 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
337 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
338 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
339 trace("InternetConnectA -->\n");
341 if (hic == 0x0) goto abort;
343 trace("HttpOpenRequestA <--\n");
344 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
345 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
347 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
349 * If the internet name can't be resolved we are probably behind
350 * a firewall or in some other way not directly connected to the
351 * Internet. Not enough reason to fail the test. Just ignore and
355 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
357 trace("HttpOpenRequestA -->\n");
359 if (hor == 0x0) goto abort;
361 trace("HttpSendRequestA -->\n");
362 SetLastError(0xdeadbeef);
363 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
364 if (flags & INTERNET_FLAG_ASYNC)
365 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
366 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
368 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
369 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
370 trace("HttpSendRequestA <--\n");
372 if (!rc && (GetLastError() == ERROR_IO_PENDING))
373 WaitForSingleObject(hCompleteEvent, INFINITE);
375 /* tests invalid dwStructSize */
376 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
377 inetbuffers.lpcszHeader = NULL;
378 inetbuffers.dwHeadersLength = 0;
379 inetbuffers.dwBufferLength = 10;
380 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
381 inetbuffers.dwOffsetHigh = 1234;
382 inetbuffers.dwOffsetLow = 5678;
383 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
384 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
385 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
386 rc ? "TRUE" : "FALSE", GetLastError());
387 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
389 /* tests to see whether lpcszHeader is used - it isn't */
390 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
391 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
392 inetbuffers.dwHeadersLength = 255;
393 inetbuffers.dwBufferLength = 0;
394 inetbuffers.lpvBuffer = NULL;
395 inetbuffers.dwOffsetHigh = 1234;
396 inetbuffers.dwOffsetLow = 5678;
397 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
398 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
400 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
401 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
402 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
403 rc ? "TRUE" : "FALSE", GetLastError());
406 trace("Entering Query loop\n");
410 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
411 inetbuffers.dwBufferLength = 1024;
412 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
413 inetbuffers.dwOffsetHigh = 1234;
414 inetbuffers.dwOffsetLow = 5678;
416 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
419 if (GetLastError() == ERROR_IO_PENDING)
421 trace("InternetReadFileEx -> PENDING\n");
422 WaitForSingleObject(hCompleteEvent, INFINITE);
426 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
431 trace("InternetReadFileEx -> SUCCEEDED\n");
433 trace("read %i bytes\n", inetbuffers.dwBufferLength);
434 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
436 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
437 "InternetReadFileEx sets offsets to 0x%x%08x\n",
438 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
440 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
442 if (!inetbuffers.dwBufferLength)
445 length += inetbuffers.dwBufferLength;
447 trace("Finished. Read %d bytes\n", length);
451 rc = InternetCloseHandle(hor);
452 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
453 rc = InternetCloseHandle(hor);
454 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
457 rc = InternetCloseHandle(hic);
458 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
461 rc = InternetCloseHandle(hi);
462 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
463 if (flags & INTERNET_FLAG_ASYNC)
466 CloseHandle(hCompleteEvent);
469 static void InternetOpenUrlA_test(void)
471 HINTERNET myhinternet, myhttp;
473 DWORD size, readbytes, totalbytes=0;
476 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
477 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
479 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
480 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
483 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
484 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
485 if (GetLastError() == 12007)
486 return; /* WinXP returns this when not connected to the net */
487 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
488 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
489 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
490 totalbytes += readbytes;
491 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
492 totalbytes += readbytes;
493 trace("read 0x%08x bytes\n",totalbytes);
496 static void InternetTimeFromSystemTimeA_test(void)
499 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
500 char string[INTERNET_RFC1123_BUFSIZE];
501 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
503 ret = pInternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
504 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
506 ok( !memcmp( string, expect, sizeof(expect) ),
507 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
510 static void InternetTimeFromSystemTimeW_test(void)
513 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
514 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
515 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
516 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
518 ret = pInternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
519 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
521 ok( !memcmp( string, expect, sizeof(expect) ),
522 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
525 static void InternetTimeToSystemTimeA_test(void)
529 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
530 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
531 static const char string2[] = " fri 7 jan 2005 12 06 35";
533 ret = pInternetTimeToSystemTimeA( string, &time, 0 );
534 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
535 ok( !memcmp( &time, &expect, sizeof(expect) ),
536 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
538 ret = pInternetTimeToSystemTimeA( string2, &time, 0 );
539 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
540 ok( !memcmp( &time, &expect, sizeof(expect) ),
541 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
544 static void InternetTimeToSystemTimeW_test(void)
548 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
549 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
550 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
551 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
552 '1','2',' ','0','6',' ','3','5',0 };
553 static const WCHAR string3[] = { 'F','r',0 };
555 ret = pInternetTimeToSystemTimeW( NULL, NULL, 0 );
556 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
558 ret = pInternetTimeToSystemTimeW( NULL, &time, 0 );
559 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
561 ret = pInternetTimeToSystemTimeW( string, NULL, 0 );
562 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
564 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
565 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
567 ret = pInternetTimeToSystemTimeW( string, &time, 0 );
568 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
569 ok( !memcmp( &time, &expect, sizeof(expect) ),
570 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
572 ret = pInternetTimeToSystemTimeW( string2, &time, 0 );
573 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
574 ok( !memcmp( &time, &expect, sizeof(expect) ),
575 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
577 ret = pInternetTimeToSystemTimeW( string3, &time, 0 );
578 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
581 static void HttpSendRequestEx_test(void)
587 INTERNET_BUFFERS BufferIn;
588 DWORD dwBytesWritten;
594 static char szPostData[] = "mode=Test";
595 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
597 hSession = InternetOpen("Wine Regression Test",
598 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
599 ok( hSession != NULL ,"Unable to open Internet session\n");
600 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
601 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
603 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
604 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
605 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
606 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
608 trace( "Network unreachable, skipping test\n" );
611 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
614 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
615 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
616 BufferIn.lpcszHeader = szContentType;
617 BufferIn.dwHeadersLength = sizeof(szContentType);
618 BufferIn.dwHeadersTotal = sizeof(szContentType);
619 BufferIn.lpvBuffer = szPostData;
620 BufferIn.dwBufferLength = 3;
621 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
622 BufferIn.dwOffsetLow = 0;
623 BufferIn.dwOffsetHigh = 0;
625 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
626 ok(ret, "HttpSendRequestEx Failed with error %u\n", GetLastError());
628 for (i = 3; szPostData[i]; i++)
629 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
630 "InternetWriteFile failed\n");
632 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
634 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
635 "Unable to read response\n");
636 szBuffer[dwBytesRead] = 0;
638 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
639 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0,"Got string %s\n",szBuffer);
641 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
643 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
644 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
647 static void InternetOpenRequest_test(void)
649 HINTERNET session, connect, request;
650 static const char *types[] = { "*", "", NULL };
651 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
652 static const WCHAR *typesW[] = { any, empty, NULL };
655 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
656 ok(session != NULL ,"Unable to open Internet session\n");
658 connect = InternetConnectA(session, "winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
659 INTERNET_SERVICE_HTTP, 0, 0);
660 ok(connect != NULL, "Unable to connect to http://winehq.org\n");
662 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
663 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
665 trace( "Network unreachable, skipping test\n" );
668 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
670 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
671 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
672 ok(InternetCloseHandle(request), "Close request handle failed\n");
674 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
675 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
677 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
678 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
679 ok(InternetCloseHandle(request), "Close request handle failed\n");
682 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
683 ok(InternetCloseHandle(session), "Close session handle failed\n");
686 static void HttpHeaders_test(void)
695 hSession = InternetOpen("Wine Regression Test",
696 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
697 ok( hSession != NULL ,"Unable to open Internet session\n");
698 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
699 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
701 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
702 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
703 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
704 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
706 trace( "Network unreachable, skipping test\n" );
709 ok( hRequest != NULL, "Failed to open request handle\n");
712 len = sizeof(buffer);
713 strcpy(buffer,"Warning");
714 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
715 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
717 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
718 "Failed to add new header\n");
721 len = sizeof(buffer);
722 strcpy(buffer,"Warning");
723 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
724 buffer,&len,&index),"Unable to query header\n");
725 ok(index == 1, "Index was not incremented\n");
726 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
727 len = sizeof(buffer);
728 strcpy(buffer,"Warning");
729 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
730 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
732 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
733 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
736 len = sizeof(buffer);
737 strcpy(buffer,"Warning");
738 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
739 buffer,&len,&index),"Unable to query header\n");
740 ok(index == 1, "Index was not incremented\n");
741 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
742 len = sizeof(buffer);
743 strcpy(buffer,"Warning");
744 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
745 buffer,&len,&index),"Failed to get second header\n");
746 ok(index == 2, "Index was not incremented\n");
747 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
748 len = sizeof(buffer);
749 strcpy(buffer,"Warning");
750 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
751 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
753 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
756 len = sizeof(buffer);
757 strcpy(buffer,"Warning");
758 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
759 buffer,&len,&index),"Unable to query header\n");
760 ok(index == 1, "Index was not incremented\n");
761 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
762 len = sizeof(buffer);
763 strcpy(buffer,"Warning");
764 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
765 buffer,&len,&index),"Failed to get second header\n");
766 ok(index == 2, "Index was not incremented\n");
767 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
768 len = sizeof(buffer);
769 strcpy(buffer,"Warning");
770 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
771 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
773 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
776 len = sizeof(buffer);
777 strcpy(buffer,"Warning");
778 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
779 buffer,&len,&index),"Unable to query header\n");
780 ok(index == 1, "Index was not incremented\n");
781 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
782 len = sizeof(buffer);
783 strcpy(buffer,"Warning");
784 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
785 buffer,&len,&index),"Failed to get second header\n");
786 ok(index == 2, "Index was not incremented\n");
787 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
788 len = sizeof(buffer);
789 strcpy(buffer,"Warning");
790 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
791 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
793 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
796 len = sizeof(buffer);
797 strcpy(buffer,"Warning");
798 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
799 buffer,&len,&index),"Unable to query header\n");
800 ok(index == 1, "Index was not incremented\n");
801 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
802 len = sizeof(buffer);
803 strcpy(buffer,"Warning");
804 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
805 ok(index == 2, "Index was not incremented\n");
806 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
807 len = sizeof(buffer);
808 strcpy(buffer,"Warning");
809 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
811 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
814 len = sizeof(buffer);
815 strcpy(buffer,"Warning");
816 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
817 ok(index == 1, "Index was not incremented\n");
818 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
819 len = sizeof(buffer);
820 strcpy(buffer,"Warning");
821 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
822 ok(index == 2, "Index was not incremented\n");
823 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
824 len = sizeof(buffer);
825 strcpy(buffer,"Warning");
826 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
828 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
831 len = sizeof(buffer);
832 strcpy(buffer,"Warning");
833 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
834 ok(index == 1, "Index was not incremented\n");
835 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
836 len = sizeof(buffer);
837 strcpy(buffer,"Warning");
838 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
839 ok(index == 2, "Index was not incremented\n");
840 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
841 len = sizeof(buffer);
842 strcpy(buffer,"Warning");
843 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
845 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");
848 len = sizeof(buffer);
849 strcpy(buffer,"Warning");
850 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
851 ok(index == 1, "Index was not incremented\n");
852 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
853 len = sizeof(buffer);
854 strcpy(buffer,"Warning");
855 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
856 ok(index == 2, "Index was not incremented\n");
857 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
858 len = sizeof(buffer);
859 strcpy(buffer,"Warning");
860 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
863 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
865 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
866 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
869 static const char okmsg[] =
870 "HTTP/1.0 200 OK\r\n"
871 "Server: winetest\r\n"
874 static const char proxymsg[] =
875 "HTTP/1.1 407 Proxy Authentication Required\r\n"
876 "Server: winetest\r\n"
877 "Proxy-Connection: close\r\n"
878 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
881 static const char page1[] =
883 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
884 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
892 static DWORD CALLBACK server_thread(LPVOID param)
894 struct server_info *si = param;
896 struct sockaddr_in sa;
899 int last_request = 0;
901 WSAStartup(MAKEWORD(1,1), &wsaData);
903 s = socket(AF_INET, SOCK_STREAM, 0);
908 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
910 memset(&sa, 0, sizeof sa);
911 sa.sin_family = AF_INET;
912 sa.sin_port = htons(si->port);
913 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
915 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
921 SetEvent(si->hEvent);
925 c = accept(s, NULL, NULL);
927 memset(buffer, 0, sizeof buffer);
928 for(i=0; i<(sizeof buffer-1); i++)
930 r = recv(c, &buffer[i], 1, 0);
934 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
935 buffer[i-3] == '\r' && buffer[i-1] == '\r')
939 if (strstr(buffer, "GET /test1"))
941 send(c, okmsg, sizeof okmsg-1, 0);
942 send(c, page1, sizeof page1-1, 0);
945 if (strstr(buffer, "/test2"))
947 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
949 send(c, okmsg, sizeof okmsg-1, 0);
950 send(c, page1, sizeof page1-1, 0);
953 send(c, proxymsg, sizeof proxymsg-1, 0);
956 if (strstr(buffer, "/quit"))
958 send(c, okmsg, sizeof okmsg-1, 0);
959 send(c, page1, sizeof page1-1, 0);
965 } while (!last_request);
972 static void test_basic_request(int port, const char *url)
974 HINTERNET hi, hc, hr;
978 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
979 ok(hi != NULL, "open failed\n");
981 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
982 ok(hc != NULL, "connect failed\n");
984 hr = HttpOpenRequest(hc, NULL, url, NULL, NULL, NULL, 0, 0);
985 ok(hr != NULL, "HttpOpenRequest failed\n");
987 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
988 ok(r, "HttpSendRequest failed\n");
991 memset(buffer, 0, sizeof buffer);
992 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
993 ok(r, "InternetReadFile failed\n");
994 ok(count == sizeof page1 - 1, "count was wrong\n");
995 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
997 InternetCloseHandle(hr);
998 InternetCloseHandle(hc);
999 InternetCloseHandle(hi);
1002 static void test_proxy_indirect(int port)
1004 HINTERNET hi, hc, hr;
1008 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
1009 ok(hi != NULL, "open failed\n");
1011 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1012 ok(hc != NULL, "connect failed\n");
1014 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1015 ok(hr != NULL, "HttpOpenRequest failed\n");
1017 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1018 ok(r, "HttpSendRequest failed\n");
1021 r = HttpQueryInfo(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
1022 ok(r, "HttpQueryInfo failed\n");
1023 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1026 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1027 ok(r, "HttpQueryInfo failed\n");
1028 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1031 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &val, &sz, NULL);
1032 ok(r, "HttpQueryInfo failed\n");
1033 ok(val == 407, "proxy code wrong\n");
1036 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
1037 ok(r, "HttpQueryInfo failed\n");
1038 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
1041 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
1042 ok(r, "HttpQueryInfo failed\n");
1043 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
1046 r = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
1047 ok(r, "HttpQueryInfo failed\n");
1048 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
1051 r = HttpQueryInfo(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
1052 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
1053 ok(r == FALSE, "HttpQueryInfo failed\n");
1055 InternetCloseHandle(hr);
1056 InternetCloseHandle(hc);
1057 InternetCloseHandle(hi);
1060 static void test_proxy_direct(int port)
1062 HINTERNET hi, hc, hr;
1065 static CHAR username[] = "mike",
1066 password[] = "1101";
1068 sprintf(buffer, "localhost:%d\n", port);
1069 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
1070 ok(hi != NULL, "open failed\n");
1072 /* try connect without authorization */
1073 hc = InternetConnect(hi, "www.winehq.org/", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1074 ok(hc != NULL, "connect failed\n");
1076 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1077 ok(hr != NULL, "HttpOpenRequest failed\n");
1079 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1080 ok(r, "HttpSendRequest failed\n");
1083 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1084 ok(r, "HttpQueryInfo failed\n");
1085 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1088 /* set the user + password then try again */
1090 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
1091 ok(r, "failed to set user\n");
1093 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
1094 ok(r, "failed to set password\n");
1097 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1098 ok(r, "HttpSendRequest failed\n");
1100 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1101 ok(r, "HttpQueryInfo failed\n");
1103 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
1107 InternetCloseHandle(hr);
1108 InternetCloseHandle(hc);
1109 InternetCloseHandle(hi);
1112 static void test_http_connection(void)
1114 struct server_info si;
1118 si.hEvent = CreateEvent(NULL, 0, 0, NULL);
1121 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
1122 ok( hThread != NULL, "create thread failed\n");
1124 r = WaitForSingleObject(si.hEvent, 10000);
1125 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
1126 if (r != WAIT_OBJECT_0)
1129 test_basic_request(si.port, "/test1");
1130 test_proxy_indirect(si.port);
1131 test_proxy_direct(si.port);
1133 /* send the basic request again to shutdown the server thread */
1134 test_basic_request(si.port, "/quit");
1136 r = WaitForSingleObject(hThread, 3000);
1137 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
1138 CloseHandle(hThread);
1144 hdll = GetModuleHandleA("wininet.dll");
1145 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
1146 pInternetTimeFromSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeA");
1147 pInternetTimeFromSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeFromSystemTimeW");
1148 pInternetTimeToSystemTimeA = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeA");
1149 pInternetTimeToSystemTimeW = (void*)GetProcAddress(hdll, "InternetTimeToSystemTimeW");
1151 if (!pInternetSetStatusCallbackA)
1152 skip("skipping the InternetReadFile tests\n");
1155 InternetReadFile_test(INTERNET_FLAG_ASYNC);
1156 InternetReadFile_test(0);
1157 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
1159 InternetOpenRequest_test();
1160 InternetOpenUrlA_test();
1161 if (!pInternetTimeFromSystemTimeA)
1162 skip("skipping the InternetTime tests\n");
1165 InternetTimeFromSystemTimeA_test();
1166 InternetTimeFromSystemTimeW_test();
1167 InternetTimeToSystemTimeA_test();
1168 InternetTimeToSystemTimeW_test();
1170 HttpSendRequestEx_test();
1172 test_http_connection();