11 #define TEST_URL "http://www.winehq.org/site/about"
12 #define TEST_URL_PATH "/site/about"
13 #define TEST_URL2 "http://www.myserver.com/myscript.php?arg=1"
14 #define TEST_URL2_SERVER "www.myserver.com"
15 #define TEST_URL2_PATH "/myscript.php"
16 #define TEST_URL2_PATHEXTRA "/myscript.php?arg=1"
17 #define TEST_URL2_EXTRA "?arg=1"
18 #define TEST_URL3 "file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml"
22 static VOID WINAPI callback(
25 DWORD dwInternetStatus,
26 LPVOID lpvStatusInformation,
27 DWORD dwStatusInformationLength
32 switch (dwInternetStatus)
34 case INTERNET_STATUS_RESOLVING_NAME:
35 strcpy(name,"INTERNET_STATUS_RESOLVING_NAME");
37 case INTERNET_STATUS_NAME_RESOLVED:
38 strcpy(name,"INTERNET_STATUS_NAME_RESOLVED");
40 case INTERNET_STATUS_CONNECTING_TO_SERVER:
41 strcpy(name,"INTERNET_STATUS_CONNECTING_TO_SERVER");
43 case INTERNET_STATUS_CONNECTED_TO_SERVER:
44 strcpy(name,"INTERNET_STATUS_CONNECTED_TO_SERVER");
46 case INTERNET_STATUS_SENDING_REQUEST:
47 strcpy(name,"INTERNET_STATUS_SENDING_REQUEST");
49 case INTERNET_STATUS_REQUEST_SENT:
50 strcpy(name,"INTERNET_STATUS_REQUEST_SENT");
52 case INTERNET_STATUS_RECEIVING_RESPONSE:
53 strcpy(name,"INTERNET_STATUS_RECEIVING_RESPONSE");
55 case INTERNET_STATUS_RESPONSE_RECEIVED:
56 strcpy(name,"INTERNET_STATUS_RESPONSE_RECEIVED");
58 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
59 strcpy(name,"INTERNET_STATUS_CTL_RESPONSE_RECEIVED");
61 case INTERNET_STATUS_PREFETCH:
62 strcpy(name,"INTERNET_STATUS_PREFETCH");
64 case INTERNET_STATUS_CLOSING_CONNECTION:
65 strcpy(name,"INTERNET_STATUS_CLOSING_CONNECTION");
67 case INTERNET_STATUS_CONNECTION_CLOSED:
68 strcpy(name,"INTERNET_STATUS_CONNECTION_CLOSED");
70 case INTERNET_STATUS_HANDLE_CREATED:
71 strcpy(name,"INTERNET_STATUS_HANDLE_CREATED");
73 case INTERNET_STATUS_HANDLE_CLOSING:
74 strcpy(name,"INTERNET_STATUS_HANDLE_CLOSING");
76 case INTERNET_STATUS_REQUEST_COMPLETE:
77 strcpy(name,"INTERNET_STATUS_REQUEST_COMPLETE");
80 case INTERNET_STATUS_REDIRECT:
81 strcpy(name,"INTERNET_STATUS_REDIRECT");
83 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
84 strcpy(name,"INTERNET_STATUS_INTERMEDIATE_RESPONSE");
88 trace("Callback %p 0x%lx %s(%li) %p %ld\n",hInternet,dwContext,name,
89 dwInternetStatus,lpvStatusInformation,dwStatusInformationLength);
92 static void winapi_test(int flags)
98 const char *types[2] = { "*", NULL };
99 HINTERNET hi, hic = 0, hor = 0;
101 trace("Starting with flags 0x%x\n",flags);
103 trace("InternetOpenA <--\n");
104 hi = InternetOpenA("",0x0,0x0,0x0,flags);
105 ok((hi != 0x0),"InternetOpen Failed\n");
106 trace("InternetOpenA -->\n");
108 if (hi == 0x0) goto abort;
110 InternetSetStatusCallback(hi,&callback);
112 trace("InternetConnectA <--\n");
113 hic=InternetConnectA(hi,"www.winehq.org",0x0,0x0,0x0,0x3,0x0,0xdeadbeef);
114 ok((hic != 0x0),"InternetConnect Failed\n");
115 trace("InternetConnectA -->\n");
117 if (hic == 0x0) goto abort;
119 trace("HttpOpenRequestA <--\n");
120 hor = HttpOpenRequestA(hic, "GET",
122 0x0,0x0,types,0x00400800,0xdeadbead);
123 if (hor == 0x0 && GetLastError() == 12007 /* ERROR_INTERNET_NAME_NOT_RESOLVED */) {
125 * If the internet name can't be resolved we are probably behind
126 * a firewall or in some other way not directly connected to the
127 * Internet. Not enough reason to fail the test. Just ignore and
131 ok((hor != 0x0),"HttpOpenRequest Failed\n");
133 trace("HttpOpenRequestA -->\n");
135 if (hor == 0x0) goto abort;
137 trace("HttpSendRequestA -->\n");
139 rc = HttpSendRequestA(hor, "", 0xffffffff,0x0,0x0);
141 ok(((rc == 0)&&(GetLastError()==997)),
142 "Asynchronous HttpSendRequest NOT returning 0 with error 997\n");
144 ok((rc != 0) || GetLastError() == 12007, /* 12007 == XP */
145 "Synchronous HttpSendRequest returning 0, error %ld\n", GetLastError());
146 trace("HttpSendRequestA <--\n");
148 while ((flags)&&(!goon))
152 rc = InternetQueryOptionA(hor,0x17,&out,&length);
153 trace("Option 0x17 -> %li %li\n",rc,out);
156 rc = InternetQueryOptionA(hor,0x22,buffer,&length);
157 trace("Option 0x22 -> %li %s\n",rc,buffer);
160 rc = HttpQueryInfoA(hor,0x16,buffer,&length,0x0);
162 trace("Option 0x16 -> %li %s\n",rc,buffer);
165 rc = InternetQueryOptionA(hor,0x22,buffer,&length);
167 trace("Option 0x22 -> %li %s\n",rc,buffer);
170 rc = HttpQueryInfoA(hor,0x5,&buffer,&length,0x0);
171 trace("Option 0x5 -> %li %s (%li)\n",rc,buffer,GetLastError());
174 rc = HttpQueryInfoA(hor,0x1,buffer,&length,0x0);
176 trace("Option 0x1 -> %li %s\n",rc,buffer);
179 trace("Entering Query loop\n");
184 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
185 ok(!(rc == 0 && length != 0),"InternetQueryDataAvailable failed\n");
190 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
192 rc = InternetReadFile(hor,buffer,length,&length);
196 trace("ReadFile -> %li %li\n",rc,length);
198 HeapFree(GetProcessHeap(),0,buffer);
203 rc = InternetCloseHandle(hor);
204 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
205 rc = InternetCloseHandle(hor);
206 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
209 rc = InternetCloseHandle(hic);
210 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
213 rc = InternetCloseHandle(hi);
214 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
220 static void InternetOpenUrlA_test(void)
222 HINTERNET myhinternet, myhttp;
224 URL_COMPONENTSA urlComponents;
225 char protocol[32], hostName[1024], userName[1024];
226 char password[1024], extra[1024], path[1024];
227 DWORD size, readbytes, totalbytes=0;
230 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
231 ok((myhinternet != 0), "InternetOpen failed, error %lx\n",GetLastError());
233 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
234 ok( ret, "InternetCanonicalizeUrl failed, error %lx\n",GetLastError());
236 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
237 urlComponents.lpszScheme = protocol;
238 urlComponents.dwSchemeLength = 32;
239 urlComponents.lpszHostName = hostName;
240 urlComponents.dwHostNameLength = 1024;
241 urlComponents.lpszUserName = userName;
242 urlComponents.dwUserNameLength = 1024;
243 urlComponents.lpszPassword = password;
244 urlComponents.dwPasswordLength = 1024;
245 urlComponents.lpszUrlPath = path;
246 urlComponents.dwUrlPathLength = 2048;
247 urlComponents.lpszExtraInfo = extra;
248 urlComponents.dwExtraInfoLength = 1024;
249 ret = InternetCrackUrl(TEST_URL, 0,0,&urlComponents);
250 ok( ret, "InternetCrackUrl failed, error %lx\n",GetLastError());
252 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
253 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
254 if (GetLastError() == 12007)
255 return; /* WinXP returns this when not connected to the net */
256 ok((myhttp != 0),"InternetOpenUrl failed, error %lx\n",GetLastError());
257 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
258 ok( ret, "InternetReadFile failed, error %lx\n",GetLastError());
259 totalbytes += readbytes;
260 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
261 totalbytes += readbytes;
262 trace("read 0x%08lx bytes\n",totalbytes);
265 static void InternetCrackUrl_test(void)
267 URL_COMPONENTSA urlComponents;
268 char protocol[32], hostName[1024], userName[1024];
269 char password[1024], extra[1024], path[1024];
272 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
273 urlComponents.lpszScheme = protocol;
274 urlComponents.dwSchemeLength = 32;
275 urlComponents.lpszHostName = hostName;
276 urlComponents.dwHostNameLength = 1024;
277 urlComponents.lpszUserName = userName;
278 urlComponents.dwUserNameLength = 1024;
279 urlComponents.lpszPassword = password;
280 urlComponents.dwPasswordLength = 1024;
281 urlComponents.lpszUrlPath = path;
282 urlComponents.dwUrlPathLength = 2048;
283 urlComponents.lpszExtraInfo = extra;
284 urlComponents.dwExtraInfoLength = 1024;
285 ret = InternetCrackUrl(TEST_URL, 0,0,&urlComponents);
286 ok( ret, "InternetCrackUrl failed, error %lx\n",GetLastError());
287 ok((strcmp(TEST_URL_PATH,path) == 0),"path cracked wrong\n");
289 /* Bug 1805: Confirm the returned lengths are correct: */
290 /* 1. When extra info split out explicitly */
291 ZeroMemory(&urlComponents, sizeof(urlComponents));
292 urlComponents.dwStructSize = sizeof(urlComponents);
293 urlComponents.dwHostNameLength = 1;
294 urlComponents.dwUrlPathLength = 1;
295 urlComponents.dwExtraInfoLength = 1;
296 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed, error 0x%lx\n", GetLastError());
297 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATH),".dwUrlPathLength should be %d, but is %ld\n", strlen(TEST_URL2_PATH), urlComponents.dwUrlPathLength);
298 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATH,strlen(TEST_URL2_PATH)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATH, urlComponents.lpszUrlPath);
299 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %d, but is %ld\n", strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
300 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
301 ok(urlComponents.dwExtraInfoLength == strlen(TEST_URL2_EXTRA),".dwExtraInfoLength should be %d, but is %ld\n", strlen(TEST_URL2_EXTRA), urlComponents.dwExtraInfoLength);
302 ok(!strncmp(urlComponents.lpszExtraInfo,TEST_URL2_EXTRA,strlen(TEST_URL2_EXTRA)),"lpszExtraInfo should be %s but is %s\n", TEST_URL2_EXTRA, urlComponents.lpszHostName);
304 /* 2. When extra info is not split out explicitly and is in url path */
305 ZeroMemory(&urlComponents, sizeof(urlComponents));
306 urlComponents.dwStructSize = sizeof(urlComponents);
307 urlComponents.dwHostNameLength = 1;
308 urlComponents.dwUrlPathLength = 1;
309 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
310 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATHEXTRA),".dwUrlPathLength should be %d, but is %ld\n", strlen(TEST_URL2_PATHEXTRA), urlComponents.dwUrlPathLength);
311 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATHEXTRA,strlen(TEST_URL2_PATHEXTRA)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATHEXTRA, urlComponents.lpszUrlPath);
312 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %d, but is %ld\n", strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
313 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
315 /*3. Check for %20 */
316 ZeroMemory(&urlComponents, sizeof(urlComponents));
317 urlComponents.dwStructSize = sizeof(urlComponents);
318 urlComponents.lpszScheme = protocol;
319 urlComponents.dwSchemeLength = 32;
320 urlComponents.lpszHostName = hostName;
321 urlComponents.dwHostNameLength = 1024;
322 urlComponents.lpszUserName = userName;
323 urlComponents.dwUserNameLength = 1024;
324 urlComponents.lpszPassword = password;
325 urlComponents.dwPasswordLength = 1024;
326 urlComponents.lpszUrlPath = path;
327 urlComponents.dwUrlPathLength = 2048;
328 urlComponents.lpszExtraInfo = extra;
329 ok(InternetCrackUrlA(TEST_URL3, 0, ICU_DECODE, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
332 static void InternetCrackUrlW_test(void)
335 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
336 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
337 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
339 URL_COMPONENTSW comp;
340 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
349 memset(&comp, 0, sizeof comp);
350 comp.dwStructSize = sizeof comp;
351 comp.lpszScheme = scheme;
352 comp.dwSchemeLength = sizeof scheme;
353 comp.lpszHostName = host;
354 comp.dwHostNameLength = sizeof host;
355 comp.lpszUserName = user;
356 comp.dwUserNameLength = sizeof user;
357 comp.lpszPassword = pwd;
358 comp.dwPasswordLength = sizeof pwd;
359 comp.lpszUrlPath = urlpart;
360 comp.dwUrlPathLength = sizeof urlpart;
361 comp.lpszExtraInfo = extra;
362 comp.dwExtraInfoLength = sizeof extra;
364 r = InternetCrackUrlW(url, 0, 0, &comp );
365 ok( r, "failed to crack url\n");
366 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
367 ok( comp.dwHostNameLength == 12, "host length wrong\n");
368 ok( comp.dwUserNameLength == 0, "user length wrong\n");
369 ok( comp.dwPasswordLength == 0, "password length wrong\n");
370 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
371 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
379 memset(&comp, 0, sizeof comp);
380 comp.dwStructSize = sizeof comp;
381 comp.lpszHostName = host;
382 comp.dwHostNameLength = sizeof host;
383 comp.lpszUrlPath = urlpart;
384 comp.dwUrlPathLength = sizeof urlpart;
386 r = InternetCrackUrlW(url, 0, 0, &comp );
387 ok( r, "failed to crack url\n");
388 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
389 ok( comp.dwHostNameLength == 12, "host length wrong\n");
390 ok( comp.dwUserNameLength == 0, "user length wrong\n");
391 ok( comp.dwPasswordLength == 0, "password length wrong\n");
392 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
393 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
401 memset(&comp, 0, sizeof comp);
402 comp.dwStructSize = sizeof comp;
403 comp.lpszHostName = host;
404 comp.dwHostNameLength = sizeof host;
405 comp.lpszUrlPath = urlpart;
406 comp.dwUrlPathLength = sizeof urlpart;
407 comp.lpszExtraInfo = NULL;
408 comp.dwExtraInfoLength = sizeof extra;
410 r = InternetCrackUrlW(url, 0, 0, &comp );
411 ok( r, "failed to crack url\n");
412 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
413 ok( comp.dwHostNameLength == 12, "host length wrong\n");
414 ok( comp.dwUserNameLength == 0, "user length wrong\n");
415 ok( comp.dwPasswordLength == 0, "password length wrong\n");
416 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
417 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
420 static void InternetTimeFromSystemTimeA_test(void)
423 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
424 char string[INTERNET_RFC1123_BUFSIZE];
425 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
427 ret = InternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
428 ok( ret, "InternetTimeFromSystemTimeA failed (%ld)\n", GetLastError() );
430 ok( !memcmp( string, expect, sizeof(expect) ),
431 "InternetTimeFromSystemTimeA failed (%ld)\n", GetLastError() );
434 static void InternetTimeFromSystemTimeW_test(void)
437 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
438 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
439 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
440 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
442 ret = InternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
443 ok( ret, "InternetTimeFromSystemTimeW failed (%ld)\n", GetLastError() );
445 ok( !memcmp( string, expect, sizeof(expect) ),
446 "InternetTimeFromSystemTimeW failed (%ld)\n", GetLastError() );
449 static void InternetTimeToSystemTimeA_test(void)
453 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
454 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
455 static const char string2[] = " fri 7 jan 2005 12 06 35";
457 ret = InternetTimeToSystemTimeA( string, &time, 0 );
458 ok( ret, "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
459 ok( !memcmp( &time, &expect, sizeof(expect) ),
460 "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
462 ret = InternetTimeToSystemTimeA( string2, &time, 0 );
463 ok( ret, "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
464 ok( !memcmp( &time, &expect, sizeof(expect) ),
465 "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
468 static void InternetTimeToSystemTimeW_test(void)
472 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
473 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
474 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
475 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
476 '1','2',' ','0','6',' ','3','5',0 };
477 static const WCHAR string3[] = { 'F','r',0 };
479 ret = InternetTimeToSystemTimeW( NULL, NULL, 0 );
480 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
482 ret = InternetTimeToSystemTimeW( NULL, &time, 0 );
483 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
485 ret = InternetTimeToSystemTimeW( string, NULL, 0 );
486 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
488 ret = InternetTimeToSystemTimeW( string, &time, 1 );
489 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
491 ret = InternetTimeToSystemTimeW( string, &time, 0 );
492 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
493 ok( !memcmp( &time, &expect, sizeof(expect) ),
494 "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
496 ret = InternetTimeToSystemTimeW( string2, &time, 0 );
497 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
498 ok( !memcmp( &time, &expect, sizeof(expect) ),
499 "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
501 ret = InternetTimeToSystemTimeW( string3, &time, 0 );
502 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
507 winapi_test(0x10000000);
508 winapi_test(0x00000000);
509 InternetCrackUrl_test();
510 InternetOpenUrlA_test();
511 InternetCrackUrlW_test();
512 InternetTimeFromSystemTimeA_test();
513 InternetTimeFromSystemTimeW_test();
514 InternetTimeToSystemTimeA_test();
515 InternetTimeToSystemTimeW_test();