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"
24 DWORD dwInternetStatus,
25 LPVOID lpvStatusInformation,
26 DWORD dwStatusInformationLength
31 switch (dwInternetStatus)
33 case INTERNET_STATUS_RESOLVING_NAME:
34 strcpy(name,"INTERNET_STATUS_RESOLVING_NAME");
36 case INTERNET_STATUS_NAME_RESOLVED:
37 strcpy(name,"INTERNET_STATUS_NAME_RESOLVED");
39 case INTERNET_STATUS_CONNECTING_TO_SERVER:
40 strcpy(name,"INTERNET_STATUS_CONNECTING_TO_SERVER");
42 case INTERNET_STATUS_CONNECTED_TO_SERVER:
43 strcpy(name,"INTERNET_STATUS_CONNECTED_TO_SERVER");
45 case INTERNET_STATUS_SENDING_REQUEST:
46 strcpy(name,"INTERNET_STATUS_SENDING_REQUEST");
48 case INTERNET_STATUS_REQUEST_SENT:
49 strcpy(name,"INTERNET_STATUS_REQUEST_SENT");
51 case INTERNET_STATUS_RECEIVING_RESPONSE:
52 strcpy(name,"INTERNET_STATUS_RECEIVING_RESPONSE");
54 case INTERNET_STATUS_RESPONSE_RECEIVED:
55 strcpy(name,"INTERNET_STATUS_RESPONSE_RECEIVED");
57 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
58 strcpy(name,"INTERNET_STATUS_CTL_RESPONSE_RECEIVED");
60 case INTERNET_STATUS_PREFETCH:
61 strcpy(name,"INTERNET_STATUS_PREFETCH");
63 case INTERNET_STATUS_CLOSING_CONNECTION:
64 strcpy(name,"INTERNET_STATUS_CLOSING_CONNECTION");
66 case INTERNET_STATUS_CONNECTION_CLOSED:
67 strcpy(name,"INTERNET_STATUS_CONNECTION_CLOSED");
69 case INTERNET_STATUS_HANDLE_CREATED:
70 strcpy(name,"INTERNET_STATUS_HANDLE_CREATED");
72 case INTERNET_STATUS_HANDLE_CLOSING:
73 strcpy(name,"INTERNET_STATUS_HANDLE_CLOSING");
75 case INTERNET_STATUS_REQUEST_COMPLETE:
76 strcpy(name,"INTERNET_STATUS_REQUEST_COMPLETE");
79 case INTERNET_STATUS_REDIRECT:
80 strcpy(name,"INTERNET_STATUS_REDIRECT");
82 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
83 strcpy(name,"INTERNET_STATUS_INTERMEDIATE_RESPONSE");
87 trace("Callback %p 0x%lx %s(%li) %p %ld\n",hInternet,dwContext,name,dwInternetStatus,lpvStatusInformation,dwStatusInformationLength);
90 void winapi_test(int flags)
96 const char *types[2] = { "*", NULL };
97 HINTERNET hi, hic = 0, hor = 0;
99 trace("Starting with flags 0x%x\n",flags);
101 trace("InternetOpenA <--\n");
102 hi = InternetOpenA("",0x0,0x0,0x0,flags);
103 ok((hi != 0x0),"InternetOpen Failed\n");
104 trace("InternetOpenA -->\n");
106 if (hi == 0x0) goto abort;
108 InternetSetStatusCallback(hi,&callback);
110 trace("InternetConnectA <--\n");
111 hic=InternetConnectA(hi,"www.winehq.org",0x0,0x0,0x0,0x3,0x0,0xdeadbeef);
112 ok((hic != 0x0),"InternetConnect Failed\n");
113 trace("InternetConnectA -->\n");
115 if (hic == 0x0) goto abort;
117 trace("HttpOpenRequestA <--\n");
118 hor = HttpOpenRequestA(hic, "GET",
120 0x0,0x0,types,0x00400800,0xdeadbead);
121 if (hor == 0x0 && GetLastError() == 12007 /* ERROR_INTERNET_NAME_NOT_RESOLVED */) {
123 * If the internet name can't be resolved we are probably behind
124 * a firewall or in some other way not directly connected to the
125 * Internet. Not enough reason to fail the test. Just ignore and
129 ok((hor != 0x0),"HttpOpenRequest Failed\n");
131 trace("HttpOpenRequestA -->\n");
133 if (hor == 0x0) goto abort;
135 trace("HttpSendRequestA -->\n");
137 rc = HttpSendRequestA(hor, "", 0xffffffff,0x0,0x0);
139 ok(((rc == 0)&&(GetLastError()==997)),
140 "Asynchronous HttpSendRequest NOT returning 0 with error 997\n");
142 ok((rc != 0) || GetLastError() == 12007, /* 12007 == XP */
143 "Synchronous HttpSendRequest returning 0, error %ld\n", GetLastError());
144 trace("HttpSendRequestA <--\n");
146 while ((flags)&&(!goon))
150 rc = InternetQueryOptionA(hor,0x17,&out,&length);
151 trace("Option 0x17 -> %li %li\n",rc,out);
154 rc = InternetQueryOptionA(hor,0x22,buffer,&length);
155 trace("Option 0x22 -> %li %s\n",rc,buffer);
158 rc = HttpQueryInfoA(hor,0x16,buffer,&length,0x0);
160 trace("Option 0x16 -> %li %s\n",rc,buffer);
163 rc = InternetQueryOptionA(hor,0x22,buffer,&length);
165 trace("Option 0x22 -> %li %s\n",rc,buffer);
168 rc = HttpQueryInfoA(hor,0x5,&buffer,&length,0x0);
169 trace("Option 0x5 -> %li %s (%li)\n",rc,buffer,GetLastError());
172 rc = HttpQueryInfoA(hor,0x1,buffer,&length,0x0);
174 trace("Option 0x1 -> %li %s\n",rc,buffer);
177 trace("Entering Query loop\n");
182 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
183 ok(!(rc == 0 && length != 0),"InternetQueryDataAvailable failed\n");
188 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
190 rc = InternetReadFile(hor,buffer,length,&length);
194 trace("ReadFile -> %li %li\n",rc,length);
196 HeapFree(GetProcessHeap(),0,buffer);
201 rc = InternetCloseHandle(hor);
202 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
203 rc = InternetCloseHandle(hor);
204 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
207 rc = InternetCloseHandle(hic);
208 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
211 rc = InternetCloseHandle(hi);
212 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
218 void InternetOpenUrlA_test(void)
220 HINTERNET myhinternet, myhttp;
222 URL_COMPONENTSA urlComponents;
223 char protocol[32], hostName[1024], userName[1024];
224 char password[1024], extra[1024], path[1024];
225 DWORD size, readbytes, totalbytes=0;
228 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
229 ok((myhinternet != 0), "InternetOpen failed, error %lx\n",GetLastError());
231 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
232 ok( ret, "InternetCanonicalizeUrl failed, error %lx\n",GetLastError());
234 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
235 urlComponents.lpszScheme = protocol;
236 urlComponents.dwSchemeLength = 32;
237 urlComponents.lpszHostName = hostName;
238 urlComponents.dwHostNameLength = 1024;
239 urlComponents.lpszUserName = userName;
240 urlComponents.dwUserNameLength = 1024;
241 urlComponents.lpszPassword = password;
242 urlComponents.dwPasswordLength = 1024;
243 urlComponents.lpszUrlPath = path;
244 urlComponents.dwUrlPathLength = 2048;
245 urlComponents.lpszExtraInfo = extra;
246 urlComponents.dwExtraInfoLength = 1024;
247 ret = InternetCrackUrl(TEST_URL, 0,0,&urlComponents);
248 ok( ret, "InternetCrackUrl failed, error %lx\n",GetLastError());
250 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
251 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
252 if (GetLastError() == 12007)
253 return; /* WinXP returns this when not connected to the net */
254 ok((myhttp != 0),"InternetOpenUrl failed, error %lx\n",GetLastError());
255 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
256 ok( ret, "InternetReadFile failed, error %lx\n",GetLastError());
257 totalbytes += readbytes;
258 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
259 totalbytes += readbytes;
260 trace("read 0x%08lx bytes\n",totalbytes);
263 void InternetCrackUrl_test(void)
265 URL_COMPONENTSA urlComponents;
266 char protocol[32], hostName[1024], userName[1024];
267 char password[1024], extra[1024], path[1024];
270 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
271 urlComponents.lpszScheme = protocol;
272 urlComponents.dwSchemeLength = 32;
273 urlComponents.lpszHostName = hostName;
274 urlComponents.dwHostNameLength = 1024;
275 urlComponents.lpszUserName = userName;
276 urlComponents.dwUserNameLength = 1024;
277 urlComponents.lpszPassword = password;
278 urlComponents.dwPasswordLength = 1024;
279 urlComponents.lpszUrlPath = path;
280 urlComponents.dwUrlPathLength = 2048;
281 urlComponents.lpszExtraInfo = extra;
282 urlComponents.dwExtraInfoLength = 1024;
283 ret = InternetCrackUrl(TEST_URL, 0,0,&urlComponents);
284 ok( ret, "InternetCrackUrl failed, error %lx\n",GetLastError());
285 ok((strcmp(TEST_URL_PATH,path) == 0),"path cracked wrong\n");
287 /* Bug 1805: Confirm the returned lengths are correct: */
288 /* 1. When extra info split out explicitly */
289 ZeroMemory(&urlComponents, sizeof(urlComponents));
290 urlComponents.dwStructSize = sizeof(urlComponents);
291 urlComponents.dwHostNameLength = 1;
292 urlComponents.dwUrlPathLength = 1;
293 urlComponents.dwExtraInfoLength = 1;
294 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed, error 0x%lx\n", GetLastError());
295 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATH),".dwUrlPathLength should be %d, but is %ld\n", strlen(TEST_URL2_PATH), urlComponents.dwUrlPathLength);
296 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATH,strlen(TEST_URL2_PATH)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATH, urlComponents.lpszUrlPath);
297 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %d, but is %ld\n", strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
298 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
299 ok(urlComponents.dwExtraInfoLength == strlen(TEST_URL2_EXTRA),".dwExtraInfoLength should be %d, but is %ld\n", strlen(TEST_URL2_EXTRA), urlComponents.dwExtraInfoLength);
300 ok(!strncmp(urlComponents.lpszExtraInfo,TEST_URL2_EXTRA,strlen(TEST_URL2_EXTRA)),"lpszExtraInfo should be %s but is %s\n", TEST_URL2_EXTRA, urlComponents.lpszHostName);
302 /* 2. When extra info is not split out explicitly and is in url path */
303 ZeroMemory(&urlComponents, sizeof(urlComponents));
304 urlComponents.dwStructSize = sizeof(urlComponents);
305 urlComponents.dwHostNameLength = 1;
306 urlComponents.dwUrlPathLength = 1;
307 ok(InternetCrackUrlA(TEST_URL2, 0, 0, &urlComponents),"InternetCrackUrl failed with GLE 0x%lx\n",GetLastError());
308 ok(urlComponents.dwUrlPathLength == strlen(TEST_URL2_PATHEXTRA),".dwUrlPathLength should be %d, but is %ld\n", strlen(TEST_URL2_PATHEXTRA), urlComponents.dwUrlPathLength);
309 ok(!strncmp(urlComponents.lpszUrlPath,TEST_URL2_PATHEXTRA,strlen(TEST_URL2_PATHEXTRA)),"lpszUrlPath should be %s but is %s\n", TEST_URL2_PATHEXTRA, urlComponents.lpszUrlPath);
310 ok(urlComponents.dwHostNameLength == strlen(TEST_URL2_SERVER),".dwHostNameLength should be %d, but is %ld\n", strlen(TEST_URL2_SERVER), urlComponents.dwHostNameLength);
311 ok(!strncmp(urlComponents.lpszHostName,TEST_URL2_SERVER,strlen(TEST_URL2_SERVER)),"lpszHostName should be %s but is %s\n", TEST_URL2_SERVER, urlComponents.lpszHostName);
317 void InternetCrackUrlW_test(void)
320 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
321 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
322 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
324 URL_COMPONENTSW comp;
325 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
334 memset(&comp, 0, sizeof comp);
335 comp.dwStructSize = sizeof comp;
336 comp.lpszScheme = scheme;
337 comp.dwSchemeLength = sizeof scheme;
338 comp.lpszHostName = host;
339 comp.dwHostNameLength = sizeof host;
340 comp.lpszUserName = user;
341 comp.dwUserNameLength = sizeof user;
342 comp.lpszPassword = pwd;
343 comp.dwPasswordLength = sizeof pwd;
344 comp.lpszUrlPath = urlpart;
345 comp.dwUrlPathLength = sizeof urlpart;
346 comp.lpszExtraInfo = extra;
347 comp.dwExtraInfoLength = sizeof extra;
349 r = InternetCrackUrlW(url, 0, 0, &comp );
350 ok( r, "failed to crack url\n");
351 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
352 ok( comp.dwHostNameLength == 12, "host length wrong\n");
353 ok( comp.dwUserNameLength == 0, "user length wrong\n");
354 ok( comp.dwPasswordLength == 0, "password length wrong\n");
355 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
356 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
364 memset(&comp, 0, sizeof comp);
365 comp.dwStructSize = sizeof comp;
366 comp.lpszHostName = host;
367 comp.dwHostNameLength = sizeof host;
368 comp.lpszUrlPath = urlpart;
369 comp.dwUrlPathLength = sizeof urlpart;
371 r = InternetCrackUrlW(url, 0, 0, &comp );
372 ok( r, "failed to crack url\n");
373 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
374 ok( comp.dwHostNameLength == 12, "host length wrong\n");
375 ok( comp.dwUserNameLength == 0, "user length wrong\n");
376 ok( comp.dwPasswordLength == 0, "password length wrong\n");
377 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
378 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
386 memset(&comp, 0, sizeof comp);
387 comp.dwStructSize = sizeof comp;
388 comp.lpszHostName = host;
389 comp.dwHostNameLength = sizeof host;
390 comp.lpszUrlPath = urlpart;
391 comp.dwUrlPathLength = sizeof urlpart;
392 comp.lpszExtraInfo = NULL;
393 comp.dwExtraInfoLength = sizeof extra;
395 r = InternetCrackUrlW(url, 0, 0, &comp );
396 ok( r, "failed to crack url\n");
397 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
398 ok( comp.dwHostNameLength == 12, "host length wrong\n");
399 ok( comp.dwUserNameLength == 0, "user length wrong\n");
400 ok( comp.dwPasswordLength == 0, "password length wrong\n");
401 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
402 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
405 static void InternetTimeFromSystemTimeA_test()
408 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
409 char string[INTERNET_RFC1123_BUFSIZE];
410 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
412 ret = InternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
413 ok( ret, "InternetTimeFromSystemTimeA failed (%ld)\n", GetLastError() );
415 ok( !memcmp( string, expect, sizeof(expect) ),
416 "InternetTimeFromSystemTimeA failed (%ld)\n", GetLastError() );
419 static void InternetTimeFromSystemTimeW_test()
422 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
423 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
424 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
425 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
427 ret = InternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
428 ok( ret, "InternetTimeFromSystemTimeW failed (%ld)\n", GetLastError() );
430 ok( !memcmp( string, expect, sizeof(expect) ),
431 "InternetTimeFromSystemTimeW failed (%ld)\n", GetLastError() );
434 static void InternetTimeToSystemTimeA_test()
438 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
439 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
440 static const char string2[] = " fri 7 jan 2005 12 06 35";
442 ret = InternetTimeToSystemTimeA( string, &time, 0 );
443 ok( ret, "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
444 ok( !memcmp( &time, &expect, sizeof(expect) ),
445 "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
447 ret = InternetTimeToSystemTimeA( string2, &time, 0 );
448 ok( ret, "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
449 ok( !memcmp( &time, &expect, sizeof(expect) ),
450 "InternetTimeToSystemTimeA failed (%ld)\n", GetLastError() );
453 static void InternetTimeToSystemTimeW_test()
457 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
458 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
459 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
460 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
461 '1','2',' ','0','6',' ','3','5',0 };
462 static const WCHAR string3[] = { 'F','r',0 };
464 ret = InternetTimeToSystemTimeW( NULL, NULL, 0 );
465 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
467 ret = InternetTimeToSystemTimeW( NULL, &time, 0 );
468 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
470 ret = InternetTimeToSystemTimeW( string, NULL, 0 );
471 ok( !ret, "InternetTimeToSystemTimeW succeeded (%ld)\n", GetLastError() );
473 ret = InternetTimeToSystemTimeW( string, &time, 1 );
474 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
476 ret = InternetTimeToSystemTimeW( string, &time, 0 );
477 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
478 ok( !memcmp( &time, &expect, sizeof(expect) ),
479 "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
481 ret = InternetTimeToSystemTimeW( string2, &time, 0 );
482 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
483 ok( !memcmp( &time, &expect, sizeof(expect) ),
484 "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
486 ret = InternetTimeToSystemTimeW( string3, &time, 0 );
487 ok( ret, "InternetTimeToSystemTimeW failed (%ld)\n", GetLastError() );
492 winapi_test(0x10000000);
493 winapi_test(0x00000000);
494 InternetCrackUrl_test();
495 InternetOpenUrlA_test();
496 InternetCrackUrlW_test();
497 InternetTimeFromSystemTimeA_test();
498 InternetTimeFromSystemTimeW_test();
499 InternetTimeToSystemTimeA_test();
500 InternetTimeToSystemTimeW_test();