11 #define TEST_URL "http://www.winehq.org/site/about"
12 #define TEST_URL_PATH "/site/about"
19 DWORD dwInternetStatus,
20 LPVOID lpvStatusInformation,
21 DWORD dwStatusInformationLength
26 switch (dwInternetStatus)
28 case INTERNET_STATUS_RESOLVING_NAME:
29 strcpy(name,"INTERNET_STATUS_RESOLVING_NAME");
31 case INTERNET_STATUS_NAME_RESOLVED:
32 strcpy(name,"INTERNET_STATUS_NAME_RESOLVED");
34 case INTERNET_STATUS_CONNECTING_TO_SERVER:
35 strcpy(name,"INTERNET_STATUS_CONNECTING_TO_SERVER");
37 case INTERNET_STATUS_CONNECTED_TO_SERVER:
38 strcpy(name,"INTERNET_STATUS_CONNECTED_TO_SERVER");
40 case INTERNET_STATUS_SENDING_REQUEST:
41 strcpy(name,"INTERNET_STATUS_SENDING_REQUEST");
43 case INTERNET_STATUS_REQUEST_SENT:
44 strcpy(name,"INTERNET_STATUS_REQUEST_SENT");
46 case INTERNET_STATUS_RECEIVING_RESPONSE:
47 strcpy(name,"INTERNET_STATUS_RECEIVING_RESPONSE");
49 case INTERNET_STATUS_RESPONSE_RECEIVED:
50 strcpy(name,"INTERNET_STATUS_RESPONSE_RECEIVED");
52 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
53 strcpy(name,"INTERNET_STATUS_CTL_RESPONSE_RECEIVED");
55 case INTERNET_STATUS_PREFETCH:
56 strcpy(name,"INTERNET_STATUS_PREFETCH");
58 case INTERNET_STATUS_CLOSING_CONNECTION:
59 strcpy(name,"INTERNET_STATUS_CLOSING_CONNECTION");
61 case INTERNET_STATUS_CONNECTION_CLOSED:
62 strcpy(name,"INTERNET_STATUS_CONNECTION_CLOSED");
64 case INTERNET_STATUS_HANDLE_CREATED:
65 strcpy(name,"INTERNET_STATUS_HANDLE_CREATED");
67 case INTERNET_STATUS_HANDLE_CLOSING:
68 strcpy(name,"INTERNET_STATUS_HANDLE_CLOSING");
70 case INTERNET_STATUS_REQUEST_COMPLETE:
71 strcpy(name,"INTERNET_STATUS_REQUEST_COMPLETE");
74 case INTERNET_STATUS_REDIRECT:
75 strcpy(name,"INTERNET_STATUS_REDIRECT");
77 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
78 strcpy(name,"INTERNET_STATUS_INTERMEDIATE_RESPONSE");
82 trace("Callback %p 0x%lx %s(%li) %p %ld\n",hInternet,dwContext,name,dwInternetStatus,lpvStatusInformation,dwStatusInformationLength);
85 void winapi_test(int flags)
91 const char *types[2] = { "*", NULL };
92 HINTERNET hi, hic = 0, hor = 0;
94 trace("Starting with flags 0x%x\n",flags);
96 trace("InternetOpenA <--\n");
97 hi = InternetOpenA("",0x0,0x0,0x0,flags);
98 ok((hi != 0x0),"InternetOpen Failed\n");
99 trace("InternetOpenA -->\n");
101 if (hi == 0x0) goto abort;
103 InternetSetStatusCallback(hi,&callback);
105 trace("InternetConnectA <--\n");
106 hic=InternetConnectA(hi,"www.winehq.org",0x0,0x0,0x0,0x3,0x0,0xdeadbeef);
107 ok((hic != 0x0),"InternetConnect Failed\n");
108 trace("InternetConnectA -->\n");
110 if (hic == 0x0) goto abort;
112 trace("HttpOpenRequestA <--\n");
113 hor = HttpOpenRequestA(hic, "GET",
115 0x0,0x0,types,0x00400800,0xdeadbead);
116 if (hor == 0x0 && GetLastError() == 12007 /* ERROR_INTERNET_NAME_NOT_RESOLVED */) {
118 * If the internet name can't be resolved we are probably behind
119 * a firewall or in some other way not directly connected to the
120 * Internet. Not enough reason to fail the test. Just ignore and
124 ok((hor != 0x0),"HttpOpenRequest Failed\n");
126 trace("HttpOpenRequestA -->\n");
128 if (hor == 0x0) goto abort;
130 trace("HttpSendRequestA -->\n");
132 rc = HttpSendRequestA(hor, "", 0xffffffff,0x0,0x0);
134 ok(((rc == 0)&&(GetLastError()==997)),
135 "Asynchronous HttpSendRequest NOT returning 0 with error 997\n");
137 ok((rc != 0) || GetLastError() == 12007, /* 12007 == XP */
138 "Synchronous HttpSendRequest returning 0, error %ld\n", GetLastError());
139 trace("HttpSendRequestA <--\n");
141 while ((flags)&&(!goon))
145 rc = InternetQueryOptionA(hor,0x17,&out,&length);
146 trace("Option 0x17 -> %li %li\n",rc,out);
149 rc = InternetQueryOptionA(hor,0x22,buffer,&length);
150 trace("Option 0x22 -> %li %s\n",rc,buffer);
153 rc = HttpQueryInfoA(hor,0x16,buffer,&length,0x0);
155 trace("Option 0x16 -> %li %s\n",rc,buffer);
158 rc = InternetQueryOptionA(hor,0x22,buffer,&length);
160 trace("Option 0x22 -> %li %s\n",rc,buffer);
163 rc = HttpQueryInfoA(hor,0x5,&buffer,&length,0x0);
164 trace("Option 0x5 -> %li %s (%li)\n",rc,buffer,GetLastError());
167 rc = HttpQueryInfoA(hor,0x1,buffer,&length,0x0);
169 trace("Option 0x1 -> %li %s\n",rc,buffer);
172 trace("Entering Query loop\n");
177 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
178 ok((rc != 0),"InternetQueryDataAvailable failed\n");
183 buffer = (char*)HeapAlloc(GetProcessHeap(),0,length+1);
185 rc = InternetReadFile(hor,buffer,length,&length);
189 trace("ReadFile -> %li %li\n",rc,length);
191 HeapFree(GetProcessHeap(),0,buffer);
196 rc = InternetCloseHandle(hor);
197 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
198 rc = InternetCloseHandle(hor);
199 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
202 rc = InternetCloseHandle(hic);
203 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
206 rc = InternetCloseHandle(hi);
207 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
213 void InternetOpenUrlA_test(void)
215 HINTERNET myhinternet, myhttp;
217 URL_COMPONENTSA urlComponents;
218 char protocol[32], hostName[1024], userName[1024];
219 char password[1024], extra[1024], path[1024];
220 DWORD size, readbytes, totalbytes=0;
222 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
223 ok((myhinternet != 0), "InternetOpen failed, error %lx\n",GetLastError());
225 ok (InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE),
226 "InternetCanonicalizeUrl failed, error %lx\n",GetLastError());
228 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
229 urlComponents.lpszScheme = protocol;
230 urlComponents.dwSchemeLength = 32;
231 urlComponents.lpszHostName = hostName;
232 urlComponents.dwHostNameLength = 1024;
233 urlComponents.lpszUserName = userName;
234 urlComponents.dwUserNameLength = 1024;
235 urlComponents.lpszPassword = password;
236 urlComponents.dwPasswordLength = 1024;
237 urlComponents.lpszUrlPath = path;
238 urlComponents.dwUrlPathLength = 2048;
239 urlComponents.lpszExtraInfo = extra;
240 urlComponents.dwExtraInfoLength = 1024;
241 ok((InternetCrackUrl(TEST_URL, 0,0,&urlComponents)),
242 "InternetCrackUrl failed, error %lx\n",GetLastError());
244 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
245 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
246 if (GetLastError() == 12007)
247 return; /* WinXP returns this when not connected to the net */
248 ok((myhttp != 0),"InternetOpenUrl failed, error %lx\n",GetLastError());
249 ok(InternetReadFile(myhttp, buffer,0x400,&readbytes), "InternetReadFile failed, error %lx\n",GetLastError());
250 totalbytes += readbytes;
251 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
252 totalbytes += readbytes;
253 trace("read 0x%08lx bytes\n",totalbytes);
256 void InternetCrackUrl_test(void)
258 URL_COMPONENTSA urlComponents;
259 char protocol[32], hostName[1024], userName[1024];
260 char password[1024], extra[1024], path[1024];
262 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA);
263 urlComponents.lpszScheme = protocol;
264 urlComponents.dwSchemeLength = 32;
265 urlComponents.lpszHostName = hostName;
266 urlComponents.dwHostNameLength = 1024;
267 urlComponents.lpszUserName = userName;
268 urlComponents.dwUserNameLength = 1024;
269 urlComponents.lpszPassword = password;
270 urlComponents.dwPasswordLength = 1024;
271 urlComponents.lpszUrlPath = path;
272 urlComponents.dwUrlPathLength = 2048;
273 urlComponents.lpszExtraInfo = extra;
274 urlComponents.dwExtraInfoLength = 1024;
275 ok((InternetCrackUrl(TEST_URL, 0,0,&urlComponents)),
276 "InternetCrackUrl failed, error %lx\n",GetLastError());
277 ok((strcmp(TEST_URL_PATH,path) == 0),"path cracked wrong\n");
280 void InternetCrackUrlW_test(void)
283 'h','t','t','p',':','/','/','1','9','2','.','1','6','8','.','0','.','2','2','/',
284 'C','F','I','D','E','/','m','a','i','n','.','c','f','m','?','C','F','S','V','R',
285 '=','I','D','E','&','A','C','T','I','O','N','=','I','D','E','_','D','E','F','A',
287 URL_COMPONENTSW comp;
288 WCHAR scheme[20], host[20], user[20], pwd[20], urlpart[50], extra[50];
297 memset(&comp, 0, sizeof comp);
298 comp.dwStructSize = sizeof comp;
299 comp.lpszScheme = scheme;
300 comp.dwSchemeLength = sizeof scheme;
301 comp.lpszHostName = host;
302 comp.dwHostNameLength = sizeof host;
303 comp.lpszUserName = user;
304 comp.dwUserNameLength = sizeof user;
305 comp.lpszPassword = pwd;
306 comp.dwPasswordLength = sizeof pwd;
307 comp.lpszUrlPath = urlpart;
308 comp.dwUrlPathLength = sizeof urlpart;
309 comp.lpszExtraInfo = extra;
310 comp.dwExtraInfoLength = sizeof extra;
312 r = InternetCrackUrlW(url, 0, 0, &comp );
313 ok( r, "failed to crack url\n");
314 ok( comp.dwSchemeLength == 4, "scheme length wrong\n");
315 ok( comp.dwHostNameLength == 12, "host length wrong\n");
316 ok( comp.dwUserNameLength == 0, "user length wrong\n");
317 ok( comp.dwPasswordLength == 0, "password length wrong\n");
318 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
319 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
327 memset(&comp, 0, sizeof comp);
328 comp.dwStructSize = sizeof comp;
329 comp.lpszHostName = host;
330 comp.dwHostNameLength = sizeof host;
331 comp.lpszUrlPath = urlpart;
332 comp.dwUrlPathLength = sizeof urlpart;
334 r = InternetCrackUrlW(url, 0, 0, &comp );
335 ok( r, "failed to crack url\n");
336 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
337 ok( comp.dwHostNameLength == 12, "host length wrong\n");
338 ok( comp.dwUserNameLength == 0, "user length wrong\n");
339 ok( comp.dwPasswordLength == 0, "password length wrong\n");
340 ok( comp.dwUrlPathLength == 44, "url length wrong\n");
341 ok( comp.dwExtraInfoLength == 0, "extra length wrong\n");
349 memset(&comp, 0, sizeof comp);
350 comp.dwStructSize = sizeof comp;
351 comp.lpszHostName = host;
352 comp.dwHostNameLength = sizeof host;
353 comp.lpszUrlPath = urlpart;
354 comp.dwUrlPathLength = sizeof urlpart;
355 comp.lpszExtraInfo = NULL;
356 comp.dwExtraInfoLength = sizeof extra;
358 r = InternetCrackUrlW(url, 0, 0, &comp );
359 ok( r, "failed to crack url\n");
360 ok( comp.dwSchemeLength == 0, "scheme length wrong\n");
361 ok( comp.dwHostNameLength == 12, "host length wrong\n");
362 ok( comp.dwUserNameLength == 0, "user length wrong\n");
363 ok( comp.dwPasswordLength == 0, "password length wrong\n");
364 ok( comp.dwUrlPathLength == 15, "url length wrong\n");
365 ok( comp.dwExtraInfoLength == 29, "extra length wrong\n");
370 winapi_test(0x10000000);
371 winapi_test(0x00000000);
372 InternetCrackUrl_test();
373 InternetOpenUrlA_test();
374 InternetCrackUrlW_test();