wininet: If necessary, add a slash between the hostname and path in
[wine/testsucceed.git] / dlls / wininet / tests / http.c
bloba4b66ebec725ba37eaf9cefbd27b755196808e5c
1 /*
2 * Wininet - Http tests
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
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wininet.h"
31 #include "wine/test.h"
33 #define TEST_URL "http://www.winehq.org/site/about"
34 #define TEST_URL_PATH "/site/about"
35 #define TEST_URL2 "http://www.myserver.com/myscript.php?arg=1"
36 #define TEST_URL2_SERVER "www.myserver.com"
37 #define TEST_URL2_PATH "/myscript.php"
38 #define TEST_URL2_PATHEXTRA "/myscript.php?arg=1"
39 #define TEST_URL2_EXTRA "?arg=1"
40 #define TEST_URL3 "file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml"
42 #define CREATE_URL1 "http://username:password@www.winehq.org/site/about"
43 #define CREATE_URL2 "http://username@www.winehq.org/site/about"
44 #define CREATE_URL3 "http://username:"
45 #define CREATE_URL4 "http://www.winehq.org/site/about"
46 #define CREATE_URL5 "http://"
47 #define CREATE_URL6 "nhttp://username:password@www.winehq.org:80/site/about"
48 #define CREATE_URL7 "http://username:password@www.winehq.org:42/site/about"
49 #define CREATE_URL8 "https://username:password@www.winehq.org/site/about"
50 #define CREATE_URL9 "about:blank"
51 #define CREATE_URL10 "about://host/blank"
53 static HANDLE hCompleteEvent;
55 static VOID WINAPI callback(
56 HINTERNET hInternet,
57 DWORD dwContext,
58 DWORD dwInternetStatus,
59 LPVOID lpvStatusInformation,
60 DWORD dwStatusInformationLength
63 switch (dwInternetStatus)
65 case INTERNET_STATUS_RESOLVING_NAME:
66 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %ld\n",
67 GetCurrentThreadId(), hInternet, dwContext,
68 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
69 break;
70 case INTERNET_STATUS_NAME_RESOLVED:
71 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %ld\n",
72 GetCurrentThreadId(), hInternet, dwContext,
73 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
74 break;
75 case INTERNET_STATUS_CONNECTING_TO_SERVER:
76 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %ld\n",
77 GetCurrentThreadId(), hInternet, dwContext,
78 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
79 break;
80 case INTERNET_STATUS_CONNECTED_TO_SERVER:
81 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %ld\n",
82 GetCurrentThreadId(), hInternet, dwContext,
83 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
84 break;
85 case INTERNET_STATUS_SENDING_REQUEST:
86 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %ld\n",
87 GetCurrentThreadId(), hInternet, dwContext,
88 lpvStatusInformation,dwStatusInformationLength);
89 break;
90 case INTERNET_STATUS_REQUEST_SENT:
91 ok(dwStatusInformationLength == sizeof(DWORD),
92 "info length should be sizeof(DWORD) instead of %ld\n",
93 dwStatusInformationLength);
94 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%lx %ld\n",
95 GetCurrentThreadId(), hInternet, dwContext,
96 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
97 break;
98 case INTERNET_STATUS_RECEIVING_RESPONSE:
99 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %ld\n",
100 GetCurrentThreadId(), hInternet, dwContext,
101 lpvStatusInformation,dwStatusInformationLength);
102 break;
103 case INTERNET_STATUS_RESPONSE_RECEIVED:
104 ok(dwStatusInformationLength == sizeof(DWORD),
105 "info length should be sizeof(DWORD) instead of %ld\n",
106 dwStatusInformationLength);
107 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%lx %ld\n",
108 GetCurrentThreadId(), hInternet, dwContext,
109 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
110 break;
111 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
112 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %ld\n",
113 GetCurrentThreadId(), hInternet,dwContext,
114 lpvStatusInformation,dwStatusInformationLength);
115 break;
116 case INTERNET_STATUS_PREFETCH:
117 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %ld\n",
118 GetCurrentThreadId(), hInternet, dwContext,
119 lpvStatusInformation,dwStatusInformationLength);
120 break;
121 case INTERNET_STATUS_CLOSING_CONNECTION:
122 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %ld\n",
123 GetCurrentThreadId(), hInternet, dwContext,
124 lpvStatusInformation,dwStatusInformationLength);
125 break;
126 case INTERNET_STATUS_CONNECTION_CLOSED:
127 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %ld\n",
128 GetCurrentThreadId(), hInternet, dwContext,
129 lpvStatusInformation,dwStatusInformationLength);
130 break;
131 case INTERNET_STATUS_HANDLE_CREATED:
132 ok(dwStatusInformationLength == sizeof(HINTERNET),
133 "info length should be sizeof(HINTERNET) instead of %ld\n",
134 dwStatusInformationLength);
135 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %ld\n",
136 GetCurrentThreadId(), hInternet, dwContext,
137 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
138 break;
139 case INTERNET_STATUS_HANDLE_CLOSING:
140 ok(dwStatusInformationLength == sizeof(HINTERNET),
141 "info length should be sizeof(HINTERNET) instead of %ld\n",
142 dwStatusInformationLength);
143 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %ld\n",
144 GetCurrentThreadId(), hInternet, dwContext,
145 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
146 break;
147 case INTERNET_STATUS_REQUEST_COMPLETE:
149 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
150 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
151 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %ld\n",
152 dwStatusInformationLength);
153 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%ld} %ld\n",
154 GetCurrentThreadId(), hInternet, dwContext,
155 iar->dwResult,iar->dwError,dwStatusInformationLength);
156 SetEvent(hCompleteEvent);
157 break;
159 case INTERNET_STATUS_REDIRECT:
160 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %ld\n",
161 GetCurrentThreadId(), hInternet, dwContext,
162 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
163 break;
164 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
165 trace("%04lx:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %ld\n",
166 GetCurrentThreadId(), hInternet, dwContext,
167 lpvStatusInformation, dwStatusInformationLength);
168 break;
169 default:
170 trace("%04lx:Callback %p 0x%lx %ld %p %ld\n",
171 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
172 lpvStatusInformation, dwStatusInformationLength);
176 static void InternetReadFile_test(int flags)
178 DWORD rc;
179 CHAR buffer[4000];
180 DWORD length;
181 DWORD out;
182 const char *types[2] = { "*", NULL };
183 HINTERNET hi, hic = 0, hor = 0;
185 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
187 trace("Starting InternetReadFile test with flags 0x%x\n",flags);
189 trace("InternetOpenA <--\n");
190 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
191 ok((hi != 0x0),"InternetOpen failed with error %ld\n", GetLastError());
192 trace("InternetOpenA -->\n");
194 if (hi == 0x0) goto abort;
196 InternetSetStatusCallback(hi,&callback);
198 trace("InternetConnectA <--\n");
199 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
200 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
201 ok((hic != 0x0),"InternetConnect failed with error %ld\n", GetLastError());
202 trace("InternetConnectA -->\n");
204 if (hic == 0x0) goto abort;
206 trace("HttpOpenRequestA <--\n");
207 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
208 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
209 0xdeadbead);
210 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
212 * If the internet name can't be resolved we are probably behind
213 * a firewall or in some other way not directly connected to the
214 * Internet. Not enough reason to fail the test. Just ignore and
215 * abort.
217 } else {
218 ok((hor != 0x0),"HttpOpenRequest failed with error %ld\n", GetLastError());
220 trace("HttpOpenRequestA -->\n");
222 if (hor == 0x0) goto abort;
224 trace("HttpSendRequestA -->\n");
225 SetLastError(0xdeadbeef);
226 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
227 if (flags & INTERNET_FLAG_ASYNC)
228 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
229 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
230 else
231 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
232 "Synchronous HttpSendRequest returning 0, error %ld\n", GetLastError());
233 trace("HttpSendRequestA <--\n");
235 if (flags & INTERNET_FLAG_ASYNC)
236 WaitForSingleObject(hCompleteEvent, INFINITE);
238 length = 4;
239 rc = InternetQueryOptionA(hor,INTERNET_OPTION_REQUEST_FLAGS,&out,&length);
240 trace("Option 0x17 -> %li %li\n",rc,out);
242 length = 100;
243 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
244 trace("Option 0x22 -> %li %s\n",rc,buffer);
246 length = 4000;
247 rc = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
248 buffer[length]=0;
249 trace("Option 0x16 -> %li %s\n",rc,buffer);
251 length = 4000;
252 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
253 buffer[length]=0;
254 trace("Option 0x22 -> %li %s\n",rc,buffer);
256 length = 16;
257 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
258 trace("Option 0x5 -> %li %s (%li)\n",rc,buffer,GetLastError());
260 length = 100;
261 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
262 buffer[length]=0;
263 trace("Option 0x1 -> %li %s\n",rc,buffer);
265 SetLastError(0xdeadbeef);
266 rc = InternetReadFile(NULL, buffer, 100, &length);
267 ok(!rc, "InternetReadFile should have failed\n");
268 ok(GetLastError() == ERROR_INVALID_HANDLE,
269 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %ld\n",
270 GetLastError());
272 length = 100;
273 trace("Entering Query loop\n");
275 while (length)
277 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
278 ok(!(rc == 0 && length != 0),"InternetQueryDataAvailable failed\n");
280 if (length)
282 char *buffer;
283 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
285 rc = InternetReadFile(hor,buffer,length,&length);
287 buffer[length]=0;
289 trace("ReadFile -> %li %li\n",rc,length);
291 HeapFree(GetProcessHeap(),0,buffer);
294 abort:
295 if (hor != 0x0) {
296 SetLastError(0xdeadbeef);
297 rc = InternetCloseHandle(hor);
298 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
299 SetLastError(0xdeadbeef);
300 rc = InternetCloseHandle(hor);
301 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
302 ok (GetLastError() == ERROR_INVALID_HANDLE,
303 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %ld\n",
304 GetLastError());
306 if (hic != 0x0) {
307 rc = InternetCloseHandle(hic);
308 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
310 if (hi != 0x0) {
311 rc = InternetCloseHandle(hi);
312 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
313 if (flags & INTERNET_FLAG_ASYNC)
314 Sleep(100);
316 CloseHandle(hCompleteEvent);
319 static void InternetReadFileExA_test(int flags)
321 DWORD rc;
322 DWORD length;
323 const char *types[2] = { "*", NULL };
324 HINTERNET hi, hic = 0, hor = 0;
325 INTERNET_BUFFERS inetbuffers;
327 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
329 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
331 trace("InternetOpenA <--\n");
332 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
333 ok((hi != 0x0),"InternetOpen failed with error %ld\n", GetLastError());
334 trace("InternetOpenA -->\n");
336 if (hi == 0x0) goto abort;
338 InternetSetStatusCallback(hi,&callback);
340 trace("InternetConnectA <--\n");
341 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
342 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
343 ok((hic != 0x0),"InternetConnect failed with error %ld\n", GetLastError());
344 trace("InternetConnectA -->\n");
346 if (hic == 0x0) goto abort;
348 trace("HttpOpenRequestA <--\n");
349 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
350 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
351 0xdeadbead);
352 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
354 * If the internet name can't be resolved we are probably behind
355 * a firewall or in some other way not directly connected to the
356 * Internet. Not enough reason to fail the test. Just ignore and
357 * abort.
359 } else {
360 ok((hor != 0x0),"HttpOpenRequest failed with error %ld\n", GetLastError());
362 trace("HttpOpenRequestA -->\n");
364 if (hor == 0x0) goto abort;
366 trace("HttpSendRequestA -->\n");
367 SetLastError(0xdeadbeef);
368 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
369 if (flags & INTERNET_FLAG_ASYNC)
370 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
371 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
372 else
373 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
374 "Synchronous HttpSendRequest returning 0, error %ld\n", GetLastError());
375 trace("HttpSendRequestA <--\n");
377 if (!rc && (GetLastError() == ERROR_IO_PENDING))
378 WaitForSingleObject(hCompleteEvent, INFINITE);
380 /* tests invalid dwStructSize */
381 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
382 inetbuffers.lpcszHeader = NULL;
383 inetbuffers.dwHeadersLength = 0;
384 inetbuffers.dwBufferLength = 10;
385 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
386 inetbuffers.dwOffsetHigh = 1234;
387 inetbuffers.dwOffsetLow = 5678;
388 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
389 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
390 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %ld\n",
391 rc ? "TRUE" : "FALSE", GetLastError());
392 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
394 /* tests to see whether lpcszHeader is used - it isn't */
395 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
396 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
397 inetbuffers.dwHeadersLength = 255;
398 inetbuffers.dwBufferLength = 0;
399 inetbuffers.lpvBuffer = NULL;
400 inetbuffers.dwOffsetHigh = 1234;
401 inetbuffers.dwOffsetLow = 5678;
402 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
403 ok(rc, "InternetReadFileEx failed with error %ld\n", GetLastError());
405 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
406 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
407 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %ld\n",
408 rc ? "TRUE" : "FALSE", GetLastError());
410 length = 0;
411 trace("Entering Query loop\n");
413 while (TRUE)
415 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
416 inetbuffers.dwBufferLength = 1024;
417 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
418 inetbuffers.dwOffsetHigh = 1234;
419 inetbuffers.dwOffsetLow = 5678;
421 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
422 if (!rc)
424 if (GetLastError() == ERROR_IO_PENDING)
426 trace("InternetReadFileEx -> PENDING\n");
427 WaitForSingleObject(hCompleteEvent, INFINITE);
429 else
431 trace("InternetReadFileEx -> FAILED %ld\n", GetLastError());
432 break;
435 else
436 trace("InternetReadFileEx -> SUCCEEDED\n");
438 trace("read %li bytes\n", inetbuffers.dwBufferLength);
439 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
441 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
442 "InternetReadFileEx sets offsets to 0x%lx%08lx\n",
443 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
445 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
447 if (!inetbuffers.dwBufferLength)
448 break;
450 length += inetbuffers.dwBufferLength;
452 trace("Finished. Read %ld bytes\n", length);
454 abort:
455 if (hor) {
456 rc = InternetCloseHandle(hor);
457 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
458 rc = InternetCloseHandle(hor);
459 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
461 if (hic) {
462 rc = InternetCloseHandle(hic);
463 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
465 if (hi) {
466 rc = InternetCloseHandle(hi);
467 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
468 if (flags & INTERNET_FLAG_ASYNC)
469 Sleep(100);
471 CloseHandle(hCompleteEvent);
474 static void InternetOpenUrlA_test(void)
476 HINTERNET myhinternet, myhttp;
477 char buffer[0x400];
478 URL_COMPONENTSA urlComponents;
479 char protocol[32], hostName[1024], userName[1024];
480 char password[1024], extra[1024], path[1024];
481 DWORD size, readbytes, totalbytes=0;
482 BOOL ret;
484 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
485 ok((myhinternet != 0), "InternetOpen failed, error %lx\n",GetLastError());
486 size = 0x400;
487 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
488 ok( ret, "InternetCanonicalizeUrl failed, error %lx\n",GetLastError());
490 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
491 urlComponents.lpszScheme = protocol;
492 urlComponents.dwSchemeLength = 32;
493 urlComponents.lpszHostName = hostName;
494 urlComponents.dwHostNameLength = 1024;
495 urlComponents.lpszUserName = userName;
496 urlComponents.dwUserNameLength = 1024;
497 urlComponents.lpszPassword = password;
498 urlComponents.dwPasswordLength = 1024;
499 urlComponents.lpszUrlPath = path;
500 urlComponents.dwUrlPathLength = 2048;
501 urlComponents.lpszExtraInfo = extra;
502 urlComponents.dwExtraInfoLength = 1024;
503 ret = InternetCrackUrl(TEST_URL, 0,0,&urlComponents);
504 ok( ret, "InternetCrackUrl failed, error %lx\n",GetLastError());
505 SetLastError(0);
506 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
507 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
508 if (GetLastError() == 12007)
509 return; /* WinXP returns this when not connected to the net */
510 ok((myhttp != 0),"InternetOpenUrl failed, error %lx\n",GetLastError());
511 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
512 ok( ret, "InternetReadFile failed, error %lx\n",GetLastError());
513 totalbytes += readbytes;
514 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
515 totalbytes += readbytes;
516 trace("read 0x%08lx bytes\n",totalbytes);
519 static inline void copy_compsA(
520 URL_COMPONENTSA *src,
521 URL_COMPONENTSA *dst,
522 DWORD scheLen,
523 DWORD hostLen,
524 DWORD userLen,
525 DWORD passLen,
526 DWORD pathLen,
527 DWORD extrLen )
529 *dst = *src;
530 dst->dwSchemeLength = scheLen;
531 dst->dwHostNameLength = hostLen;
532 dst->dwUserNameLength = userLen;
533 dst->dwPasswordLength = passLen;
534 dst->dwUrlPathLength = pathLen;
535 dst->dwExtraInfoLength = extrLen;
536 SetLastError(0xfaceabad);
539 static inline void zero_compsA(
540 URL_COMPONENTSA *dst,
541 DWORD scheLen,
542 DWORD hostLen,
543 DWORD userLen,
544 DWORD passLen,
545 DWORD pathLen,
546 DWORD extrLen )
548 ZeroMemory(dst, sizeof(URL_COMPONENTSA));
549 dst->dwStructSize = sizeof(URL_COMPONENTSA);
550 dst->dwSchemeLength = scheLen;
551 dst->dwHostNameLength = hostLen;
552 dst->dwUserNameLength = userLen;
553 dst->dwPasswordLength = passLen;
554 dst->dwUrlPathLength = pathLen;
555 dst->dwExtraInfoLength = extrLen;
556 SetLastError(0xfaceabad);
559 static void InternetCrackUrl_test(void)
561 URL_COMPONENTSA urlSrc, urlComponents;
562 char protocol[32], hostName[1024], userName[1024];
563 char password[1024], extra[1024], path[1024];
564 BOOL ret;
565 DWORD GLE;
567 ZeroMemory(&urlSrc, sizeof(urlSrc));
568 urlSrc.dwStructSize = sizeof(urlSrc);
569 urlSrc.lpszScheme = protocol;
570 urlSrc.lpszHostName = hostName;
571 urlSrc.lpszUserName = userName;
572 urlSrc.lpszPassword = password;
573 urlSrc.lpszUrlPath = path;
574 urlSrc.lpszExtraInfo = extra;
576 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
577 ret = InternetCrackUrl(TEST_URL, 0,0,&urlComponents);
578 ok( ret, "InternetCrackUrl failed, error %lx\n",GetLastError());
579 ok((strcmp(TEST_URL_PATH,path) == 0),"path cracked wrong\n");
581 /* Bug 1805: Confirm the returned lengths are correct: */
582 /* 1. When extra info split out explicitly */
583 zero_compsA(&urlComponents, 0, 1, 0, 0, 1, 1);
584 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed, error 0x%lx\n", GetLastError());
585 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATH),".dwUrlPathLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_PATH), urlComponents.dwUrlPathLength);
586 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATH,strlen(TEST_URL2_PATH)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATH, urlComponents.lpszUrlPath);
587 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
588 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
589 ok(urlComponents.dwExtraInfoLength == strlen(TEST_URL2_EXTRA),".dwExtraInfoLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_EXTRA), urlComponents.dwExtraInfoLength);
590 ok(!strncmp(urlComponents.lpszExtraInfo,TEST_URL2_EXTRA,strlen(TEST_URL2_EXTRA)),"lpszExtraInfo should be %s but is %s\n", TEST_URL2_EXTRA, urlComponents.lpszHostName);
592 /* 2. When extra info is not split out explicitly and is in url path */
593 zero_compsA(&urlComponents, 0, 1, 0, 0, 1, 0);
594 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
595 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATHEXTRA),".dwUrlPathLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_PATHEXTRA), urlComponents.dwUrlPathLength);
596 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATHEXTRA,strlen(TEST_URL2_PATHEXTRA)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATHEXTRA, urlComponents.lpszUrlPath);
597 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %ld, but is %ld\n", (DWORD)strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
598 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
600 /*3. Check for %20 */
601 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 1024);
602 ok(InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
605 /* Tests for lpsz* members pointing to real strings while
606 * some corresponding length members are set to zero */
607 copy_compsA(&urlSrc, &urlComponents, 0, 1024, 1024, 1024, 2048, 1024);
608 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
609 ok(ret==1, "InternetCrackUrl returned %d with GLE=%ld (expected to return 1)\n",
610 ret, GetLastError());
612 copy_compsA(&urlSrc, &urlComponents, 32, 0, 1024, 1024, 2048, 1024);
613 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
614 ok(ret==1, "InternetCrackUrl returned %d with GLE=%ld (expected to return 1)\n",
615 ret, GetLastError());
617 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 0, 1024, 2048, 1024);
618 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
619 ok(ret==1, "InternetCrackUrl returned %d with GLE=%ld (expected to return 1)\n",
620 ret, GetLastError());
622 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 0, 2048, 1024);
623 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
624 ok(ret==1, "InternetCrackUrl returned %d with GLE=%ld (expected to return 1)\n",
625 ret, GetLastError());
627 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 0, 1024);
628 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
629 GLE = GetLastError();
630 todo_wine
631 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
632 "InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
633 ret, GLE);
635 copy_compsA(&urlSrc, &urlComponents, 32, 1024, 1024, 1024, 2048, 0);
636 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
637 GLE = GetLastError();
638 todo_wine
639 ok(ret==0 && (GLE==ERROR_INVALID_HANDLE || GLE==ERROR_INSUFFICIENT_BUFFER),
640 "InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_HANDLE or ERROR_INSUFFICIENT_BUFFER)\n",
641 ret, GLE);
643 copy_compsA(&urlSrc, &urlComponents, 0, 0, 0, 0, 0, 0);
644 ret = InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents);
645 GLE = GetLastError();
646 todo_wine
647 ok(ret==0 && GLE==ERROR_INVALID_PARAMETER,
648 "InternetCrackUrl returned %d with GLE=%ld (expected to return 0 and ERROR_INVALID_PARAMETER)\n",
649 ret, GLE);
652 static void InternetCrackUrlW_test(void)
654 WCHAR url[] = {
655 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
656 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
657 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
658 'U','L','T', 0 };
659 URL_COMPONENTSW comp;
660 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
661 BOOL r;
663 urlpart[0]=0;
664 scheme[0]=0;
665 extra[0]=0;
666 host[0]=0;
667 user[0]=0;
668 pwd[0]=0;
669 memset(&comp, 0, sizeof comp);
670 comp.dwStructSize = sizeof comp;
671 comp.lpszScheme = scheme;
672 comp.dwSchemeLength = sizeof scheme;
673 comp.lpszHostName = host;
674 comp.dwHostNameLength = sizeof host;
675 comp.lpszUserName = user;
676 comp.dwUserNameLength = sizeof user;
677 comp.lpszPassword = pwd;
678 comp.dwPasswordLength = sizeof pwd;
679 comp.lpszUrlPath = urlpart;
680 comp.dwUrlPathLength = sizeof urlpart;
681 comp.lpszExtraInfo = extra;
682 comp.dwExtraInfoLength = sizeof extra;
684 r = InternetCrackUrlW(url, 0, 0, &comp );
685 ok( r, "failed to crack url\n");
686 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
687 ok( comp.dwHostNameLength == 12, "host length wrong\n");
688 ok( comp.dwUserNameLength == 0, "user length wrong\n");
689 ok( comp.dwPasswordLength == 0, "password length wrong\n");
690 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
691 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
693 urlpart[0]=0;
694 scheme[0]=0;
695 extra[0]=0;
696 host[0]=0;
697 user[0]=0;
698 pwd[0]=0;
699 memset(&comp, 0, sizeof comp);
700 comp.dwStructSize = sizeof comp;
701 comp.lpszHostName = host;
702 comp.dwHostNameLength = sizeof host;
703 comp.lpszUrlPath = urlpart;
704 comp.dwUrlPathLength = sizeof urlpart;
706 r = InternetCrackUrlW(url, 0, 0, &comp );
707 ok( r, "failed to crack url\n");
708 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
709 ok( comp.dwHostNameLength == 12, "host length wrong\n");
710 ok( comp.dwUserNameLength == 0, "user length wrong\n");
711 ok( comp.dwPasswordLength == 0, "password length wrong\n");
712 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
713 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
715 urlpart[0]=0;
716 scheme[0]=0;
717 extra[0]=0;
718 host[0]=0;
719 user[0]=0;
720 pwd[0]=0;
721 memset(&comp, 0, sizeof comp);
722 comp.dwStructSize = sizeof comp;
723 comp.lpszHostName = host;
724 comp.dwHostNameLength = sizeof host;
725 comp.lpszUrlPath = urlpart;
726 comp.dwUrlPathLength = sizeof urlpart;
727 comp.lpszExtraInfo = NULL;
728 comp.dwExtraInfoLength = sizeof extra;
730 r = InternetCrackUrlW(url, 0, 0, &comp );
731 ok( r, "failed to crack url\n");
732 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
733 ok( comp.dwHostNameLength == 12, "host length wrong\n");
734 ok( comp.dwUserNameLength == 0, "user length wrong\n");
735 ok( comp.dwPasswordLength == 0, "password length wrong\n");
736 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
737 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
740 static void InternetTimeFromSystemTimeA_test(void)
742 BOOL ret;
743 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
744 char string[INTERNET_RFC1123_BUFSIZE];
745 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
747 ret = InternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
748 ok( ret, "InternetTimeFromSystemTimeA failed (%ld)\n", GetLastError() );
750 ok( !memcmp( string, expect, sizeof(expect) ),
751 "InternetTimeFromSystemTimeA failed (%ld)\n", GetLastError() );
754 static void InternetTimeFromSystemTimeW_test(void)
756 BOOL ret;
757 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
758 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
759 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
760 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
762 ret = InternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
763 ok( ret, "InternetTimeFromSystemTimeW failed (%ld)\n", GetLastError() );
765 ok( !memcmp( string, expect, sizeof(expect) ),
766 "InternetTimeFromSystemTimeW failed (%ld)\n", GetLastError() );
769 static void InternetTimeToSystemTimeA_test(void)
771 BOOL ret;
772 SYSTEMTIME time;
773 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
774 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
775 static const char string2[] = " fri 7 jan 2005 12 06 35";
777 ret = InternetTimeToSystemTimeA( string, &time, 0 );
778 ok( ret, "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
779 ok( !memcmp( &time, &expect, sizeof(expect) ),
780 "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
782 ret = InternetTimeToSystemTimeA( string2, &time, 0 );
783 ok( ret, "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
784 ok( !memcmp( &time, &expect, sizeof(expect) ),
785 "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
788 static void InternetTimeToSystemTimeW_test(void)
790 BOOL ret;
791 SYSTEMTIME time;
792 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
793 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
794 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
795 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
796 '1','2',' ','0','6',' ','3','5',0 };
797 static const WCHAR string3[] = { 'F','r',0 };
799 ret = InternetTimeToSystemTimeW( NULL, NULL, 0 );
800 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
802 ret = InternetTimeToSystemTimeW( NULL, &time, 0 );
803 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
805 ret = InternetTimeToSystemTimeW( string, NULL, 0 );
806 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
808 ret = InternetTimeToSystemTimeW( string, &time, 1 );
809 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
811 ret = InternetTimeToSystemTimeW( string, &time, 0 );
812 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
813 ok( !memcmp( &time, &expect, sizeof(expect) ),
814 "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
816 ret = InternetTimeToSystemTimeW( string2, &time, 0 );
817 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
818 ok( !memcmp( &time, &expect, sizeof(expect) ),
819 "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
821 ret = InternetTimeToSystemTimeW( string3, &time, 0 );
822 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
825 static void fill_url_components(LPURL_COMPONENTS lpUrlComponents)
827 lpUrlComponents->dwStructSize = sizeof(URL_COMPONENTS);
828 lpUrlComponents->lpszScheme = "http";
829 lpUrlComponents->dwSchemeLength = strlen(lpUrlComponents->lpszScheme);
830 lpUrlComponents->nScheme = INTERNET_SCHEME_HTTP;
831 lpUrlComponents->lpszHostName = "www.winehq.org";
832 lpUrlComponents->dwHostNameLength = strlen(lpUrlComponents->lpszHostName);
833 lpUrlComponents->nPort = 80;
834 lpUrlComponents->lpszUserName = "username";
835 lpUrlComponents->dwUserNameLength = strlen(lpUrlComponents->lpszUserName);
836 lpUrlComponents->lpszPassword = "password";
837 lpUrlComponents->dwPasswordLength = strlen(lpUrlComponents->lpszPassword);
838 lpUrlComponents->lpszUrlPath = "/site/about";
839 lpUrlComponents->dwUrlPathLength = strlen(lpUrlComponents->lpszUrlPath);
840 lpUrlComponents->lpszExtraInfo = "";
841 lpUrlComponents->dwExtraInfoLength = strlen(lpUrlComponents->lpszExtraInfo);
844 static void InternetCreateUrlA_test(void)
846 URL_COMPONENTS urlComp;
847 LPSTR szUrl;
848 DWORD len = -1;
849 BOOL ret;
851 /* test NULL lpUrlComponents */
852 ret = InternetCreateUrlA(NULL, 0, NULL, &len);
853 SetLastError(0xdeadbeef);
854 ok(!ret, "Expected failure\n");
855 ok(GetLastError() == 0xdeadbeef,
856 "Expected 0xdeadbeef, got %ld\n", GetLastError());
857 ok(len == -1, "Expected len -1, got %ld\n", len);
859 /* test garbage lpUrlComponets */
860 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
861 SetLastError(0xdeadbeef);
862 ok(!ret, "Expected failure\n");
863 ok(GetLastError() == 0xdeadbeef,
864 "Expected 0xdeadbeef, got %ld\n", GetLastError());
865 ok(len == -1, "Expected len -1, got %ld\n", len);
867 /* test zero'ed lpUrlComponents */
868 ZeroMemory(&urlComp, sizeof(URL_COMPONENTS));
869 SetLastError(0xdeadbeef);
870 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
871 ok(!ret, "Expected failure\n");
872 ok(GetLastError() == ERROR_INVALID_PARAMETER,
873 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
874 ok(len == -1, "Expected len -1, got %ld\n", len);
876 /* test valid lpUrlComponets, NULL lpdwUrlLength */
877 fill_url_components(&urlComp);
878 SetLastError(0xdeadbeef);
879 ret = InternetCreateUrlA(&urlComp, 0, NULL, NULL);
880 ok(!ret, "Expected failure\n");
881 ok(GetLastError() == ERROR_INVALID_PARAMETER,
882 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
883 ok(len == -1, "Expected len -1, got %ld\n", len);
885 /* test valid lpUrlComponets, emptry szUrl
886 * lpdwUrlLength is size of buffer required on exit, including
887 * the terminating null when GLE == ERROR_INSUFFICIENT_BUFFER
889 SetLastError(0xdeadbeef);
890 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
891 ok(!ret, "Expected failure\n");
892 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
893 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
894 ok(len == 51, "Expected len 51, got %ld\n", len);
896 /* test correct size, NULL szUrl */
897 fill_url_components(&urlComp);
898 SetLastError(0xdeadbeef);
899 ret = InternetCreateUrlA(&urlComp, 0, NULL, &len);
900 ok(!ret, "Expected failure\n");
901 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
902 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
903 ok(len == 51, "Expected len 51, got %ld\n", len);
905 /* test valid lpUrlComponets, alloced szUrl, small size */
906 SetLastError(0xdeadbeef);
907 szUrl = HeapAlloc(GetProcessHeap(), 0, len);
908 len -= 2;
909 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
910 ok(!ret, "Expected failure\n");
911 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
912 "Expected ERROR_INSUFFICIENT_BUFFER, got %ld\n", GetLastError());
913 ok(len == 51, "Expected len 51, got %ld\n", len);
915 /* alloced szUrl, NULL lpszScheme
916 * shows that it uses nScheme instead
918 SetLastError(0xdeadbeef);
919 urlComp.lpszScheme = NULL;
920 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
921 ok(ret, "Expected success\n");
922 ok(GetLastError() == 0xdeadbeef,
923 "Expected 0xdeadbeef, got %ld\n", GetLastError());
924 ok(len == 50, "Expected len 50, got %ld\n", len);
925 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
927 /* alloced szUrl, invalid nScheme
928 * any nScheme out of range seems ignored
930 fill_url_components(&urlComp);
931 SetLastError(0xdeadbeef);
932 urlComp.nScheme = -3;
933 len++;
934 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
935 ok(ret, "Expected success\n");
936 ok(GetLastError() == 0xdeadbeef,
937 "Expected 0xdeadbeef, got %ld\n", GetLastError());
938 ok(len == 50, "Expected len 50, got %ld\n", len);
940 /* test valid lpUrlComponets, alloced szUrl */
941 fill_url_components(&urlComp);
942 SetLastError(0xdeadbeef);
943 len = 51;
944 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
945 ok(ret, "Expected success\n");
946 ok(GetLastError() == 0xdeadbeef,
947 "Expected 0xdeadbeef, got %ld\n", GetLastError());
948 ok(len == 50, "Expected len 50, got %ld\n", len);
949 ok(strstr(szUrl, "80") == NULL, "Didn't expect to find 80 in szUrl\n");
950 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
952 /* valid username, NULL password */
953 fill_url_components(&urlComp);
954 SetLastError(0xdeadbeef);
955 urlComp.lpszPassword = NULL;
956 len = 42;
957 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
958 ok(ret, "Expected success\n");
959 ok(GetLastError() == 0xdeadbeef,
960 "Expected 0xdeadbeef, got %ld\n", GetLastError());
961 ok(len == 41, "Expected len 41, got %ld\n", len);
962 ok(!strcmp(szUrl, CREATE_URL2), "Expected %s, got %s\n", CREATE_URL2, szUrl);
964 /* valid username, empty password */
965 fill_url_components(&urlComp);
966 SetLastError(0xdeadbeef);
967 urlComp.lpszPassword = "";
968 len = 51;
969 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
970 ok(ret, "Expected success\n");
971 ok(GetLastError() == 0xdeadbeef,
972 "Expected 0xdeadbeef, got %ld\n", GetLastError());
973 ok(len == 50, "Expected len 50, got %ld\n", len);
974 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
976 /* valid password, NULL username
977 * if password is provided, username has to exist
979 fill_url_components(&urlComp);
980 SetLastError(0xdeadbeef);
981 urlComp.lpszUserName = NULL;
982 len = 42;
983 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
984 ok(!ret, "Expected failure\n");
985 ok(GetLastError() == ERROR_INVALID_PARAMETER,
986 "Expected ERROR_INVALID_PARAMETER, got %ld\n", GetLastError());
987 ok(len == 42, "Expected len 42, got %ld\n", len);
988 ok(!strcmp(szUrl, CREATE_URL3), "Expected %s, got %s\n", CREATE_URL3, szUrl);
990 /* valid password, empty username
991 * if password is provided, username has to exist
993 fill_url_components(&urlComp);
994 SetLastError(0xdeadbeef);
995 urlComp.lpszUserName = "";
996 len = 51;
997 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
998 ok(ret, "Expected success\n");
999 ok(GetLastError() == 0xdeadbeef,
1000 "Expected 0xdeadbeef, got %ld\n", GetLastError());
1001 ok(len == 50, "Expected len 50, got %ld\n", len);
1002 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
1004 /* NULL username, NULL password */
1005 fill_url_components(&urlComp);
1006 SetLastError(0xdeadbeef);
1007 urlComp.lpszUserName = NULL;
1008 urlComp.lpszPassword = NULL;
1009 len = 42;
1010 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
1011 ok(ret, "Expected success\n");
1012 ok(GetLastError() == 0xdeadbeef,
1013 "Expected 0xdeadbeef, got %ld\n", GetLastError());
1014 ok(len == 32, "Expected len 32, got %ld\n", len);
1015 ok(!strcmp(szUrl, CREATE_URL4), "Expected %s, got %s\n", CREATE_URL4, szUrl);
1017 /* empty username, empty password */
1018 fill_url_components(&urlComp);
1019 SetLastError(0xdeadbeef);
1020 urlComp.lpszUserName = "";
1021 urlComp.lpszPassword = "";
1022 len = 51;
1023 ret = InternetCreateUrlA(&urlComp, 0, szUrl, &len);
1024 ok(ret, "Expected success\n");
1025 ok(GetLastError() == 0xdeadbeef,
1026 "Expected 0xdeadbeef, got %ld\n", GetLastError());
1027 ok(len == 50, "Expected len 50, got %ld\n", len);
1028 ok(!strcmp(szUrl, CREATE_URL5), "Expected %s, got %s\n", CREATE_URL5, szUrl);
1030 /* shows that nScheme is ignored, as the appearance of the port number
1031 * depends on lpszScheme and the string copied depends on lpszScheme.
1033 fill_url_components(&urlComp);
1034 HeapFree(GetProcessHeap(), 0, szUrl);
1035 urlComp.lpszScheme = "nhttp";
1036 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
1037 len = strlen(CREATE_URL6) + 1;
1038 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, len);
1039 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1040 ok(ret, "Expected success\n");
1041 ok(len == strlen(CREATE_URL6), "Expected len %d, got %ld\n", strlen(CREATE_URL6) + 1, len);
1042 ok(!strcmp(szUrl, CREATE_URL6), "Expected %s, got %s\n", CREATE_URL6, szUrl);
1044 /* if lpszScheme != "http" or nPort != 80, display nPort */
1045 HeapFree(GetProcessHeap(), 0, szUrl);
1046 urlComp.lpszScheme = "http";
1047 urlComp.dwSchemeLength = strlen(urlComp.lpszScheme);
1048 urlComp.nPort = 42;
1049 szUrl = HeapAlloc(GetProcessHeap(), 0, ++len);
1050 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1051 ok(ret, "Expected success\n");
1052 ok(len == 53, "Expected len 53, got %ld\n", len);
1053 ok(strstr(szUrl, "42") != NULL, "Expected to find 42 in szUrl\n");
1054 ok(!strcmp(szUrl, CREATE_URL7), "Expected %s, got %s\n", CREATE_URL7, szUrl);
1056 HeapFree(GetProcessHeap(), 0, szUrl);
1058 memset(&urlComp, 0, sizeof(urlComp));
1059 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1060 urlComp.lpszScheme = "http";
1061 urlComp.dwSchemeLength = 0;
1062 urlComp.nScheme = INTERNET_SCHEME_HTTP;
1063 urlComp.lpszHostName = "www.winehq.org";
1064 urlComp.dwHostNameLength = 0;
1065 urlComp.nPort = 80;
1066 urlComp.lpszUserName = "username";
1067 urlComp.dwUserNameLength = 0;
1068 urlComp.lpszPassword = "password";
1069 urlComp.dwPasswordLength = 0;
1070 urlComp.lpszUrlPath = "/site/about";
1071 urlComp.dwUrlPathLength = 0;
1072 urlComp.lpszExtraInfo = "";
1073 urlComp.dwExtraInfoLength = 0;
1074 len = strlen(CREATE_URL1);
1075 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
1076 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1077 ok(ret, "Expected success\n");
1078 ok(len == strlen(CREATE_URL1), "Expected len %d, got %ld\n", strlen(CREATE_URL1), len);
1079 ok(!strcmp(szUrl, CREATE_URL1), "Expected %s, got %s\n", CREATE_URL1, szUrl);
1081 memset(&urlComp, 0, sizeof(urlComp));
1082 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1083 urlComp.lpszScheme = "https";
1084 urlComp.dwSchemeLength = 0;
1085 urlComp.nScheme = INTERNET_SCHEME_HTTP;
1086 urlComp.lpszHostName = "www.winehq.org";
1087 urlComp.dwHostNameLength = 0;
1088 urlComp.nPort = 443;
1089 urlComp.lpszUserName = "username";
1090 urlComp.dwUserNameLength = 0;
1091 urlComp.lpszPassword = "password";
1092 urlComp.dwPasswordLength = 0;
1093 urlComp.lpszUrlPath = "/site/about";
1094 urlComp.dwUrlPathLength = 0;
1095 urlComp.lpszExtraInfo = "";
1096 urlComp.dwExtraInfoLength = 0;
1097 len = strlen(CREATE_URL8);
1098 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
1099 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1100 ok(ret, "Expected success\n");
1101 ok(len == strlen(CREATE_URL8), "Expected len %d, got %ld\n", strlen(CREATE_URL8), len);
1102 ok(!strcmp(szUrl, CREATE_URL8), "Expected %s, got %s\n", CREATE_URL8, szUrl);
1104 HeapFree(GetProcessHeap(), 0, szUrl);
1106 memset(&urlComp, 0, sizeof(urlComp));
1107 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1108 urlComp.lpszScheme = "about";
1109 urlComp.dwSchemeLength = 5;
1110 urlComp.lpszUrlPath = "blank";
1111 urlComp.dwUrlPathLength = 5;
1112 len = strlen(CREATE_URL9);
1113 len++; /* work around bug in native wininet */
1114 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
1115 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1116 ok(ret, "Expected success\n");
1117 ok(len == strlen(CREATE_URL9), "Expected len %d, got %ld\n", strlen(CREATE_URL9), len);
1118 ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
1120 HeapFree(GetProcessHeap(), 0, szUrl);
1122 memset(&urlComp, 0, sizeof(urlComp));
1123 urlComp.dwStructSize = sizeof(URL_COMPONENTS);
1124 urlComp.lpszScheme = "about";
1125 urlComp.lpszHostName = "host";
1126 urlComp.lpszUrlPath = "blank";
1127 len = strlen(CREATE_URL10);
1128 len++; /* work around bug in native wininet */
1129 szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
1130 ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
1131 ok(ret, "Expected success\n");
1132 ok(len == strlen(CREATE_URL10), "Expected len %d, got %ld\n", strlen(CREATE_URL9), len);
1133 ok(!strcmp(szUrl, CREATE_URL10), "Expected %s, got %s\n", CREATE_URL9, szUrl);
1135 HeapFree(GetProcessHeap(), 0, szUrl);
1138 static void HttpSendRequestEx_test(void)
1140 HINTERNET hSession;
1141 HINTERNET hConnect;
1142 HINTERNET hRequest;
1144 INTERNET_BUFFERS BufferIn;
1145 DWORD dwBytesWritten;
1146 DWORD dwBytesRead;
1147 CHAR szBuffer[256];
1148 int i;
1149 BOOL ret;
1151 static const char szPostData[] = "mode=Test";
1152 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
1154 hSession = InternetOpen("Wine Regression Test",
1155 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1156 ok( hSession != NULL ,"Unable to open Internet session\n");
1157 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
1158 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1160 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1161 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
1162 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1163 ok( hRequest != NULL, "Failed to open request handle\n");
1166 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
1167 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
1168 BufferIn.lpcszHeader = szContentType;
1169 BufferIn.dwHeadersLength = sizeof(szContentType);
1170 BufferIn.dwHeadersTotal = sizeof(szContentType);
1171 BufferIn.lpvBuffer = (LPVOID)szPostData;
1172 BufferIn.dwBufferLength = 3;
1173 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
1174 BufferIn.dwOffsetLow = 0;
1175 BufferIn.dwOffsetHigh = 0;
1177 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
1178 ok(ret, "HttpSendRequestEx Failed with error %ld\n", GetLastError());
1180 for (i = 3; szPostData[i]; i++)
1181 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
1182 "InternetWriteFile failed\n");
1184 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
1186 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
1187 "Unable to read response\n");
1188 szBuffer[dwBytesRead] = 0;
1190 ok(dwBytesRead == 13,"Read %lu bytes instead of 13\n",dwBytesRead);
1191 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0,"Got string %s\n",szBuffer);
1193 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1194 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1195 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1198 static void HttpHeaders_test(void)
1200 HINTERNET hSession;
1201 HINTERNET hConnect;
1202 HINTERNET hRequest;
1203 CHAR buffer[256];
1204 DWORD len = 256;
1205 DWORD index = 0;
1207 hSession = InternetOpen("Wine Regression Test",
1208 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1209 ok( hSession != NULL ,"Unable to open Internet session\n");
1210 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
1211 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1213 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1214 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
1215 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1216 ok( hRequest != NULL, "Failed to open request handle\n");
1218 index = 0;
1219 len = sizeof(buffer);
1220 strcpy(buffer,"Warning");
1221 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1222 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1224 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1225 "Failed to add new header\n");
1227 index = 0;
1228 len = sizeof(buffer);
1229 strcpy(buffer,"Warning");
1230 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1231 buffer,&len,&index),"Unable to query header\n");
1232 ok(index == 1, "Index was not incremented\n");
1233 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1234 len = sizeof(buffer);
1235 strcpy(buffer,"Warning");
1236 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1237 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1239 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1240 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1242 index = 0;
1243 len = sizeof(buffer);
1244 strcpy(buffer,"Warning");
1245 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1246 buffer,&len,&index),"Unable to query header\n");
1247 ok(index == 1, "Index was not incremented\n");
1248 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1249 len = sizeof(buffer);
1250 strcpy(buffer,"Warning");
1251 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1252 buffer,&len,&index),"Failed to get second header\n");
1253 ok(index == 2, "Index was not incremented\n");
1254 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1255 len = sizeof(buffer);
1256 strcpy(buffer,"Warning");
1257 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1258 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1260 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1262 index = 0;
1263 len = sizeof(buffer);
1264 strcpy(buffer,"Warning");
1265 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1266 buffer,&len,&index),"Unable to query header\n");
1267 ok(index == 1, "Index was not incremented\n");
1268 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1269 len = sizeof(buffer);
1270 strcpy(buffer,"Warning");
1271 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1272 buffer,&len,&index),"Failed to get second header\n");
1273 ok(index == 2, "Index was not incremented\n");
1274 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1275 len = sizeof(buffer);
1276 strcpy(buffer,"Warning");
1277 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1278 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1280 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1282 index = 0;
1283 len = sizeof(buffer);
1284 strcpy(buffer,"Warning");
1285 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1286 buffer,&len,&index),"Unable to query header\n");
1287 ok(index == 1, "Index was not incremented\n");
1288 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1289 len = sizeof(buffer);
1290 strcpy(buffer,"Warning");
1291 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1292 buffer,&len,&index),"Failed to get second header\n");
1293 ok(index == 2, "Index was not incremented\n");
1294 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1295 len = sizeof(buffer);
1296 strcpy(buffer,"Warning");
1297 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1298 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1300 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1302 index = 0;
1303 len = sizeof(buffer);
1304 strcpy(buffer,"Warning");
1305 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1306 buffer,&len,&index),"Unable to query header\n");
1307 ok(index == 1, "Index was not incremented\n");
1308 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1309 len = sizeof(buffer);
1310 strcpy(buffer,"Warning");
1311 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1312 ok(index == 2, "Index was not incremented\n");
1313 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1314 len = sizeof(buffer);
1315 strcpy(buffer,"Warning");
1316 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1318 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1320 index = 0;
1321 len = sizeof(buffer);
1322 strcpy(buffer,"Warning");
1323 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1324 ok(index == 1, "Index was not incremented\n");
1325 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1326 len = sizeof(buffer);
1327 strcpy(buffer,"Warning");
1328 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1329 ok(index == 2, "Index was not incremented\n");
1330 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1331 len = sizeof(buffer);
1332 strcpy(buffer,"Warning");
1333 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1335 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1337 index = 0;
1338 len = sizeof(buffer);
1339 strcpy(buffer,"Warning");
1340 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1341 ok(index == 1, "Index was not incremented\n");
1342 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1343 len = sizeof(buffer);
1344 strcpy(buffer,"Warning");
1345 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1346 ok(index == 2, "Index was not incremented\n");
1347 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1348 len = sizeof(buffer);
1349 strcpy(buffer,"Warning");
1350 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1352 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");
1354 index = 0;
1355 len = sizeof(buffer);
1356 strcpy(buffer,"Warning");
1357 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1358 ok(index == 1, "Index was not incremented\n");
1359 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1360 len = sizeof(buffer);
1361 strcpy(buffer,"Warning");
1362 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1363 ok(index == 2, "Index was not incremented\n");
1364 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
1365 len = sizeof(buffer);
1366 strcpy(buffer,"Warning");
1367 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1370 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1371 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1372 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1377 START_TEST(http)
1379 InternetReadFile_test(INTERNET_FLAG_ASYNC);
1380 InternetReadFile_test(0);
1381 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
1382 InternetCrackUrl_test();
1383 InternetOpenUrlA_test();
1384 InternetCrackUrlW_test();
1385 InternetTimeFromSystemTimeA_test();
1386 InternetTimeFromSystemTimeW_test();
1387 InternetTimeToSystemTimeA_test();
1388 InternetTimeToSystemTimeW_test();
1389 InternetCreateUrlA_test();
1390 HttpSendRequestEx_test();
1391 HttpHeaders_test();