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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "wine/test.h"
33 #define TEST_URL "http://www.winehq.org/site/about"
35 static HANDLE hCompleteEvent;
37 static VOID WINAPI callback(
40 DWORD dwInternetStatus,
41 LPVOID lpvStatusInformation,
42 DWORD dwStatusInformationLength
45 switch (dwInternetStatus)
47 case INTERNET_STATUS_RESOLVING_NAME:
48 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %ld\n",
49 GetCurrentThreadId(), hInternet, dwContext,
50 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
52 case INTERNET_STATUS_NAME_RESOLVED:
53 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %ld\n",
54 GetCurrentThreadId(), hInternet, dwContext,
55 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
57 case INTERNET_STATUS_CONNECTING_TO_SERVER:
58 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %ld\n",
59 GetCurrentThreadId(), hInternet, dwContext,
60 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
62 case INTERNET_STATUS_CONNECTED_TO_SERVER:
63 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %ld\n",
64 GetCurrentThreadId(), hInternet, dwContext,
65 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
67 case INTERNET_STATUS_SENDING_REQUEST:
68 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %ld\n",
69 GetCurrentThreadId(), hInternet, dwContext,
70 lpvStatusInformation,dwStatusInformationLength);
72 case INTERNET_STATUS_REQUEST_SENT:
73 ok(dwStatusInformationLength == sizeof(DWORD),
74 "info length should be sizeof(DWORD) instead of %ld\n",
75 dwStatusInformationLength);
76 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%lx %ld\n",
77 GetCurrentThreadId(), hInternet, dwContext,
78 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
80 case INTERNET_STATUS_RECEIVING_RESPONSE:
81 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %ld\n",
82 GetCurrentThreadId(), hInternet, dwContext,
83 lpvStatusInformation,dwStatusInformationLength);
85 case INTERNET_STATUS_RESPONSE_RECEIVED:
86 ok(dwStatusInformationLength == sizeof(DWORD),
87 "info length should be sizeof(DWORD) instead of %ld\n",
88 dwStatusInformationLength);
89 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%lx %ld\n",
90 GetCurrentThreadId(), hInternet, dwContext,
91 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
93 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
94 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %ld\n",
95 GetCurrentThreadId(), hInternet,dwContext,
96 lpvStatusInformation,dwStatusInformationLength);
98 case INTERNET_STATUS_PREFETCH:
99 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %ld\n",
100 GetCurrentThreadId(), hInternet, dwContext,
101 lpvStatusInformation,dwStatusInformationLength);
103 case INTERNET_STATUS_CLOSING_CONNECTION:
104 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %ld\n",
105 GetCurrentThreadId(), hInternet, dwContext,
106 lpvStatusInformation,dwStatusInformationLength);
108 case INTERNET_STATUS_CONNECTION_CLOSED:
109 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %ld\n",
110 GetCurrentThreadId(), hInternet, dwContext,
111 lpvStatusInformation,dwStatusInformationLength);
113 case INTERNET_STATUS_HANDLE_CREATED:
114 ok(dwStatusInformationLength == sizeof(HINTERNET),
115 "info length should be sizeof(HINTERNET) instead of %ld\n",
116 dwStatusInformationLength);
117 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %ld\n",
118 GetCurrentThreadId(), hInternet, dwContext,
119 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
121 case INTERNET_STATUS_HANDLE_CLOSING:
122 ok(dwStatusInformationLength == sizeof(HINTERNET),
123 "info length should be sizeof(HINTERNET) instead of %ld\n",
124 dwStatusInformationLength);
125 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %ld\n",
126 GetCurrentThreadId(), hInternet, dwContext,
127 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
129 case INTERNET_STATUS_REQUEST_COMPLETE:
131 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
132 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
133 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %ld\n",
134 dwStatusInformationLength);
135 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%ld} %ld\n",
136 GetCurrentThreadId(), hInternet, dwContext,
137 iar->dwResult,iar->dwError,dwStatusInformationLength);
138 SetEvent(hCompleteEvent);
141 case INTERNET_STATUS_REDIRECT:
142 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %ld\n",
143 GetCurrentThreadId(), hInternet, dwContext,
144 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
146 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
147 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %ld\n",
148 GetCurrentThreadId(), hInternet, dwContext,
149 lpvStatusInformation, dwStatusInformationLength);
152 trace("%04lx:Callback %p 0x%lx %ld %p %ld\n",
153 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
154 lpvStatusInformation, dwStatusInformationLength);
158 static void InternetReadFile_test(int flags)
164 const char *types[2] = { "*", NULL };
165 HINTERNET hi, hic = 0, hor = 0;
167 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
169 trace("Starting InternetReadFile test with flags 0x%x\n",flags);
171 trace("InternetOpenA <--\n");
172 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
173 ok((hi != 0x0),"InternetOpen failed with error %ld\n", GetLastError());
174 trace("InternetOpenA -->\n");
176 if (hi == 0x0) goto abort;
178 InternetSetStatusCallback(hi,&callback);
180 trace("InternetConnectA <--\n");
181 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
182 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
183 ok((hic != 0x0),"InternetConnect failed with error %ld\n", GetLastError());
184 trace("InternetConnectA -->\n");
186 if (hic == 0x0) goto abort;
188 trace("HttpOpenRequestA <--\n");
189 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
190 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
192 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
194 * If the internet name can't be resolved we are probably behind
195 * a firewall or in some other way not directly connected to the
196 * Internet. Not enough reason to fail the test. Just ignore and
200 ok((hor != 0x0),"HttpOpenRequest failed with error %ld\n", GetLastError());
202 trace("HttpOpenRequestA -->\n");
204 if (hor == 0x0) goto abort;
206 trace("HttpSendRequestA -->\n");
207 SetLastError(0xdeadbeef);
208 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
209 if (flags & INTERNET_FLAG_ASYNC)
210 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
211 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
213 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
214 "Synchronous HttpSendRequest returning 0, error %ld\n", GetLastError());
215 trace("HttpSendRequestA <--\n");
217 if (flags & INTERNET_FLAG_ASYNC)
218 WaitForSingleObject(hCompleteEvent, INFINITE);
221 rc = InternetQueryOptionA(hor,INTERNET_OPTION_REQUEST_FLAGS,&out,&length);
222 trace("Option 0x17 -> %li %li\n",rc,out);
225 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
226 trace("Option 0x22 -> %li %s\n",rc,buffer);
229 rc = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
231 trace("Option 0x16 -> %li %s\n",rc,buffer);
234 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
236 trace("Option 0x22 -> %li %s\n",rc,buffer);
239 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
240 trace("Option 0x5 -> %li %s (%li)\n",rc,buffer,GetLastError());
243 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
245 trace("Option 0x1 -> %li %s\n",rc,buffer);
247 SetLastError(0xdeadbeef);
248 rc = InternetReadFile(NULL, buffer, 100, &length);
249 ok(!rc, "InternetReadFile should have failed\n");
250 ok(GetLastError() == ERROR_INVALID_HANDLE,
251 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %ld\n",
255 trace("Entering Query loop\n");
259 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
260 ok(!(rc == 0 && length != 0),"InternetQueryDataAvailable failed\n");
265 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
267 rc = InternetReadFile(hor,buffer,length,&length);
271 trace("ReadFile -> %li %li\n",rc,length);
273 HeapFree(GetProcessHeap(),0,buffer);
278 SetLastError(0xdeadbeef);
279 rc = InternetCloseHandle(hor);
280 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
281 SetLastError(0xdeadbeef);
282 rc = InternetCloseHandle(hor);
283 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
284 ok (GetLastError() == ERROR_INVALID_HANDLE,
285 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %ld\n",
289 rc = InternetCloseHandle(hic);
290 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
293 rc = InternetCloseHandle(hi);
294 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
295 if (flags & INTERNET_FLAG_ASYNC)
298 CloseHandle(hCompleteEvent);
301 static void InternetReadFileExA_test(int flags)
305 const char *types[2] = { "*", NULL };
306 HINTERNET hi, hic = 0, hor = 0;
307 INTERNET_BUFFERS inetbuffers;
309 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
311 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
313 trace("InternetOpenA <--\n");
314 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
315 ok((hi != 0x0),"InternetOpen failed with error %ld\n", GetLastError());
316 trace("InternetOpenA -->\n");
318 if (hi == 0x0) goto abort;
320 InternetSetStatusCallback(hi,&callback);
322 trace("InternetConnectA <--\n");
323 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
324 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
325 ok((hic != 0x0),"InternetConnect failed with error %ld\n", GetLastError());
326 trace("InternetConnectA -->\n");
328 if (hic == 0x0) goto abort;
330 trace("HttpOpenRequestA <--\n");
331 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
332 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
334 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
336 * If the internet name can't be resolved we are probably behind
337 * a firewall or in some other way not directly connected to the
338 * Internet. Not enough reason to fail the test. Just ignore and
342 ok((hor != 0x0),"HttpOpenRequest failed with error %ld\n", GetLastError());
344 trace("HttpOpenRequestA -->\n");
346 if (hor == 0x0) goto abort;
348 trace("HttpSendRequestA -->\n");
349 SetLastError(0xdeadbeef);
350 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
351 if (flags & INTERNET_FLAG_ASYNC)
352 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
353 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
355 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
356 "Synchronous HttpSendRequest returning 0, error %ld\n", GetLastError());
357 trace("HttpSendRequestA <--\n");
359 if (!rc && (GetLastError() == ERROR_IO_PENDING))
360 WaitForSingleObject(hCompleteEvent, INFINITE);
362 /* tests invalid dwStructSize */
363 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
364 inetbuffers.lpcszHeader = NULL;
365 inetbuffers.dwHeadersLength = 0;
366 inetbuffers.dwBufferLength = 10;
367 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
368 inetbuffers.dwOffsetHigh = 1234;
369 inetbuffers.dwOffsetLow = 5678;
370 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
371 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
372 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %ld\n",
373 rc ? "TRUE" : "FALSE", GetLastError());
374 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
376 /* tests to see whether lpcszHeader is used - it isn't */
377 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
378 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
379 inetbuffers.dwHeadersLength = 255;
380 inetbuffers.dwBufferLength = 0;
381 inetbuffers.lpvBuffer = NULL;
382 inetbuffers.dwOffsetHigh = 1234;
383 inetbuffers.dwOffsetLow = 5678;
384 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
385 ok(rc, "InternetReadFileEx failed with error %ld\n", GetLastError());
387 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
388 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
389 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %ld\n",
390 rc ? "TRUE" : "FALSE", GetLastError());
393 trace("Entering Query loop\n");
397 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
398 inetbuffers.dwBufferLength = 1024;
399 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
400 inetbuffers.dwOffsetHigh = 1234;
401 inetbuffers.dwOffsetLow = 5678;
403 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
406 if (GetLastError() == ERROR_IO_PENDING)
408 trace("InternetReadFileEx -> PENDING\n");
409 WaitForSingleObject(hCompleteEvent, INFINITE);
413 trace("InternetReadFileEx -> FAILED %ld\n", GetLastError());
418 trace("InternetReadFileEx -> SUCCEEDED\n");
420 trace("read %li bytes\n", inetbuffers.dwBufferLength);
421 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
423 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
424 "InternetReadFileEx sets offsets to 0x%lx%08lx\n",
425 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
427 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
429 if (!inetbuffers.dwBufferLength)
432 length += inetbuffers.dwBufferLength;
434 trace("Finished. Read %ld bytes\n", length);
438 rc = InternetCloseHandle(hor);
439 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
440 rc = InternetCloseHandle(hor);
441 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
444 rc = InternetCloseHandle(hic);
445 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
448 rc = InternetCloseHandle(hi);
449 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
450 if (flags & INTERNET_FLAG_ASYNC)
453 CloseHandle(hCompleteEvent);
456 static void InternetOpenUrlA_test(void)
458 HINTERNET myhinternet, myhttp;
460 DWORD size, readbytes, totalbytes=0;
463 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
464 ok((myhinternet != 0), "InternetOpen failed, error %lx\n",GetLastError());
466 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
467 ok( ret, "InternetCanonicalizeUrl failed, error %lx\n",GetLastError());
470 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
471 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
472 if (GetLastError() == 12007)
473 return; /* WinXP returns this when not connected to the net */
474 ok((myhttp != 0),"InternetOpenUrl failed, error %lx\n",GetLastError());
475 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
476 ok( ret, "InternetReadFile failed, error %lx\n",GetLastError());
477 totalbytes += readbytes;
478 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
479 totalbytes += readbytes;
480 trace("read 0x%08lx bytes\n",totalbytes);
483 static void InternetTimeFromSystemTimeA_test(void)
486 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
487 char string[INTERNET_RFC1123_BUFSIZE];
488 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
490 ret = InternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
491 ok( ret, "InternetTimeFromSystemTimeA failed (%ld)\n", GetLastError() );
493 ok( !memcmp( string, expect, sizeof(expect) ),
494 "InternetTimeFromSystemTimeA failed (%ld)\n", GetLastError() );
497 static void InternetTimeFromSystemTimeW_test(void)
500 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
501 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
502 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
503 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
505 ret = InternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
506 ok( ret, "InternetTimeFromSystemTimeW failed (%ld)\n", GetLastError() );
508 ok( !memcmp( string, expect, sizeof(expect) ),
509 "InternetTimeFromSystemTimeW failed (%ld)\n", GetLastError() );
512 static void InternetTimeToSystemTimeA_test(void)
516 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
517 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
518 static const char string2[] = " fri 7 jan 2005 12 06 35";
520 ret = InternetTimeToSystemTimeA( string, &time, 0 );
521 ok( ret, "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
522 ok( !memcmp( &time, &expect, sizeof(expect) ),
523 "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
525 ret = InternetTimeToSystemTimeA( string2, &time, 0 );
526 ok( ret, "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
527 ok( !memcmp( &time, &expect, sizeof(expect) ),
528 "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
531 static void InternetTimeToSystemTimeW_test(void)
535 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
536 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
537 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
538 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
539 '1','2',' ','0','6',' ','3','5',0 };
540 static const WCHAR string3[] = { 'F','r',0 };
542 ret = InternetTimeToSystemTimeW( NULL, NULL, 0 );
543 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
545 ret = InternetTimeToSystemTimeW( NULL, &time, 0 );
546 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
548 ret = InternetTimeToSystemTimeW( string, NULL, 0 );
549 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
551 ret = InternetTimeToSystemTimeW( string, &time, 1 );
552 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
554 ret = InternetTimeToSystemTimeW( string, &time, 0 );
555 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
556 ok( !memcmp( &time, &expect, sizeof(expect) ),
557 "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
559 ret = InternetTimeToSystemTimeW( string2, &time, 0 );
560 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
561 ok( !memcmp( &time, &expect, sizeof(expect) ),
562 "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
564 ret = InternetTimeToSystemTimeW( string3, &time, 0 );
565 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
568 static void HttpSendRequestEx_test(void)
574 INTERNET_BUFFERS BufferIn;
575 DWORD dwBytesWritten;
581 static const char szPostData[] = "mode=Test";
582 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
584 hSession = InternetOpen("Wine Regression Test",
585 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
586 ok( hSession != NULL ,"Unable to open Internet session\n");
587 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
588 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
590 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
591 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
592 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
593 ok( hRequest != NULL, "Failed to open request handle\n");
596 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
597 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
598 BufferIn.lpcszHeader = szContentType;
599 BufferIn.dwHeadersLength = sizeof(szContentType);
600 BufferIn.dwHeadersTotal = sizeof(szContentType);
601 BufferIn.lpvBuffer = (LPVOID)szPostData;
602 BufferIn.dwBufferLength = 3;
603 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
604 BufferIn.dwOffsetLow = 0;
605 BufferIn.dwOffsetHigh = 0;
607 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
608 ok(ret, "HttpSendRequestEx Failed with error %ld\n", GetLastError());
610 for (i = 3; szPostData[i]; i++)
611 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
612 "InternetWriteFile failed\n");
614 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
616 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
617 "Unable to read response\n");
618 szBuffer[dwBytesRead] = 0;
620 ok(dwBytesRead == 13,"Read %lu bytes instead of 13\n",dwBytesRead);
621 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0,"Got string %s\n",szBuffer);
623 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
624 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
625 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
628 static void HttpHeaders_test(void)
637 hSession = InternetOpen("Wine Regression Test",
638 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
639 ok( hSession != NULL ,"Unable to open Internet session\n");
640 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
641 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
643 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
644 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
645 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
646 ok( hRequest != NULL, "Failed to open request handle\n");
649 len = sizeof(buffer);
650 strcpy(buffer,"Warning");
651 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
652 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
654 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
655 "Failed to add new header\n");
658 len = sizeof(buffer);
659 strcpy(buffer,"Warning");
660 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
661 buffer,&len,&index),"Unable to query header\n");
662 ok(index == 1, "Index was not incremented\n");
663 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
664 len = sizeof(buffer);
665 strcpy(buffer,"Warning");
666 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
667 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
669 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
670 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
673 len = sizeof(buffer);
674 strcpy(buffer,"Warning");
675 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
676 buffer,&len,&index),"Unable to query header\n");
677 ok(index == 1, "Index was not incremented\n");
678 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
679 len = sizeof(buffer);
680 strcpy(buffer,"Warning");
681 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
682 buffer,&len,&index),"Failed to get second header\n");
683 ok(index == 2, "Index was not incremented\n");
684 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
685 len = sizeof(buffer);
686 strcpy(buffer,"Warning");
687 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
688 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
690 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
693 len = sizeof(buffer);
694 strcpy(buffer,"Warning");
695 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
696 buffer,&len,&index),"Unable to query header\n");
697 ok(index == 1, "Index was not incremented\n");
698 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
699 len = sizeof(buffer);
700 strcpy(buffer,"Warning");
701 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
702 buffer,&len,&index),"Failed to get second header\n");
703 ok(index == 2, "Index was not incremented\n");
704 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
705 len = sizeof(buffer);
706 strcpy(buffer,"Warning");
707 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
708 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
710 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
713 len = sizeof(buffer);
714 strcpy(buffer,"Warning");
715 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
716 buffer,&len,&index),"Unable to query header\n");
717 ok(index == 1, "Index was not incremented\n");
718 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
719 len = sizeof(buffer);
720 strcpy(buffer,"Warning");
721 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
722 buffer,&len,&index),"Failed to get second header\n");
723 ok(index == 2, "Index was not incremented\n");
724 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
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,"Third Header Should Not Exist\n");
730 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
733 len = sizeof(buffer);
734 strcpy(buffer,"Warning");
735 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
736 buffer,&len,&index),"Unable to query header\n");
737 ok(index == 1, "Index was not incremented\n");
738 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
739 len = sizeof(buffer);
740 strcpy(buffer,"Warning");
741 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
742 ok(index == 2, "Index was not incremented\n");
743 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
744 len = sizeof(buffer);
745 strcpy(buffer,"Warning");
746 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
748 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
751 len = sizeof(buffer);
752 strcpy(buffer,"Warning");
753 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
754 ok(index == 1, "Index was not incremented\n");
755 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
756 len = sizeof(buffer);
757 strcpy(buffer,"Warning");
758 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
759 ok(index == 2, "Index was not incremented\n");
760 ok(strcmp(buffer,"test3")==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, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
765 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
768 len = sizeof(buffer);
769 strcpy(buffer,"Warning");
770 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
771 ok(index == 1, "Index was not incremented\n");
772 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
773 len = sizeof(buffer);
774 strcpy(buffer,"Warning");
775 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
776 ok(index == 2, "Index was not incremented\n");
777 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
778 len = sizeof(buffer);
779 strcpy(buffer,"Warning");
780 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
782 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");
785 len = sizeof(buffer);
786 strcpy(buffer,"Warning");
787 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
788 ok(index == 1, "Index was not incremented\n");
789 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
790 len = sizeof(buffer);
791 strcpy(buffer,"Warning");
792 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
793 ok(index == 2, "Index was not incremented\n");
794 ok(strcmp(buffer,"test7")==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, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
800 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
801 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
802 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
808 InternetReadFile_test(INTERNET_FLAG_ASYNC);
809 InternetReadFile_test(0);
810 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
811 InternetOpenUrlA_test();
812 InternetTimeFromSystemTimeA_test();
813 InternetTimeFromSystemTimeW_test();
814 InternetTimeToSystemTimeA_test();
815 InternetTimeToSystemTimeW_test();
816 HttpSendRequestEx_test();