2 * test status notifications
4 * Copyright 2008 Hans Leidekker for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/test.h"
29 static const WCHAR user_agent
[] = {'w','i','n','e','t','e','s','t',0};
30 static const WCHAR test_winehq
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
37 winhttp_receive_response
,
46 enum api function
; /* api responsible for notification */
47 unsigned int status
; /* status received */
50 BOOL skipped_for_proxy
;
56 const struct notification
*test
;
63 static BOOL
proxy_active(void)
65 WINHTTP_PROXY_INFO proxy_info
;
68 if (WinHttpGetDefaultProxyConfiguration(&proxy_info
))
70 active
= (proxy_info
.lpszProxy
!= NULL
);
72 GlobalFree(proxy_info
.lpszProxy
);
73 if (proxy_info
.lpszProxyBypass
!= NULL
)
74 GlobalFree(proxy_info
.lpszProxyBypass
);
82 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
84 BOOL status_ok
, function_ok
;
85 struct info
*info
= (struct info
*)context
;
86 unsigned int i
= info
->index
;
88 if (status
== WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
)
90 DWORD size
= sizeof(struct info
*);
91 WinHttpQueryOption( handle
, WINHTTP_OPTION_CONTEXT_VALUE
, &info
, &size
);
93 ok(i
< info
->count
, "%u: unexpected notification 0x%08x\n", info
->line
, status
);
94 if (i
>= info
->count
) return;
96 status_ok
= (info
->test
[i
].status
== status
);
97 function_ok
= (info
->test
[i
].function
== info
->function
);
98 if (!info
->test
[i
].ignore
&& !info
->test
[i
].todo
)
100 ok(status_ok
, "%u: expected status 0x%08x got 0x%08x\n", info
->line
, info
->test
[i
].status
, status
);
101 ok(function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
103 else if (!info
->test
[i
].ignore
)
105 todo_wine
ok(status_ok
, "%u: expected status 0x%08x got 0x%08x\n", info
->line
, info
->test
[i
].status
, status
);
108 todo_wine
ok(function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
111 if (status_ok
&& function_ok
) info
->index
++;
114 while (info
->test
[info
->index
].skipped_for_proxy
)
118 if (status
& (WINHTTP_CALLBACK_FLAG_ALL_COMPLETIONS
| WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
))
120 SetEvent( info
->wait
);
124 static const struct notification cache_test
[] =
126 { winhttp_connect
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
},
127 { winhttp_open_request
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
},
128 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME
},
129 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED
},
130 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER
},
131 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER
},
132 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST
},
133 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_REQUEST_SENT
},
134 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE
},
135 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED
},
136 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION
, FALSE
, TRUE
},
137 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED
, FALSE
, TRUE
},
138 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, FALSE
, TRUE
},
139 { winhttp_open_request
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
},
140 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER
},
141 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER
},
142 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST
},
143 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_REQUEST_SENT
},
144 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE
},
145 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED
},
146 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION
, FALSE
, TRUE
},
147 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED
, FALSE
, TRUE
},
148 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, FALSE
, TRUE
},
149 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, TRUE
, TRUE
},
150 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, TRUE
, TRUE
}
153 static void setup_test( struct info
*info
, enum api function
, unsigned int line
)
155 info
->function
= function
;
159 static void test_connection_cache( void )
161 HANDLE ses
, con
, req
;
164 struct info info
, *context
= &info
;
166 info
.test
= cache_test
;
167 info
.count
= sizeof(cache_test
) / sizeof(cache_test
[0]);
171 ses
= WinHttpOpen( user_agent
, 0, NULL
, NULL
, 0 );
172 ok(ses
!= NULL
, "failed to open session %u\n", GetLastError());
174 WinHttpSetStatusCallback( ses
, check_notification
, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS
, 0 );
176 ret
= WinHttpSetOption( ses
, WINHTTP_OPTION_CONTEXT_VALUE
, &context
, sizeof(struct info
*) );
177 ok(ret
, "failed to set context value %u\n", GetLastError());
179 setup_test( &info
, winhttp_connect
, __LINE__
);
180 con
= WinHttpConnect( ses
, test_winehq
, 0, 0 );
181 ok(con
!= NULL
, "failed to open a connection %u\n", GetLastError());
183 setup_test( &info
, winhttp_open_request
, __LINE__
);
184 req
= WinHttpOpenRequest( con
, NULL
, NULL
, NULL
, NULL
, NULL
, 0 );
185 ok(req
!= NULL
, "failed to open a request %u\n", GetLastError());
187 setup_test( &info
, winhttp_send_request
, __LINE__
);
188 ret
= WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 );
189 if (!ret
&& GetLastError() == ERROR_WINHTTP_CANNOT_CONNECT
)
191 skip("connection failed, skipping\n");
194 ok(ret
, "failed to send request %u\n", GetLastError());
196 setup_test( &info
, winhttp_receive_response
, __LINE__
);
197 ret
= WinHttpReceiveResponse( req
, NULL
);
198 ok(ret
, "failed to receive response %u\n", GetLastError());
200 size
= sizeof(status
);
201 ret
= WinHttpQueryHeaders( req
, WINHTTP_QUERY_STATUS_CODE
| WINHTTP_QUERY_FLAG_NUMBER
, NULL
, &status
, &size
, NULL
);
202 ok(ret
, "failed unexpectedly %u\n", GetLastError());
203 ok(status
== 200, "request failed unexpectedly %u\n", status
);
205 setup_test( &info
, winhttp_close_handle
, __LINE__
);
206 WinHttpCloseHandle( req
);
208 setup_test( &info
, winhttp_open_request
, __LINE__
);
209 req
= WinHttpOpenRequest( con
, NULL
, NULL
, NULL
, NULL
, NULL
, 0 );
210 ok(req
!= NULL
, "failed to open a request %u\n", GetLastError());
212 ret
= WinHttpSetOption( req
, WINHTTP_OPTION_CONTEXT_VALUE
, &context
, sizeof(struct info
*) );
213 ok(ret
, "failed to set context value %u\n", GetLastError());
215 setup_test( &info
, winhttp_send_request
, __LINE__
);
216 ret
= WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 );
217 if (!ret
&& GetLastError() == ERROR_WINHTTP_CANNOT_CONNECT
)
219 skip("connection failed, skipping\n");
222 ok(ret
, "failed to send request %u\n", GetLastError());
224 setup_test( &info
, winhttp_receive_response
, __LINE__
);
225 ret
= WinHttpReceiveResponse( req
, NULL
);
226 ok(ret
, "failed to receive response %u\n", GetLastError());
228 size
= sizeof(status
);
229 ret
= WinHttpQueryHeaders( req
, WINHTTP_QUERY_STATUS_CODE
| WINHTTP_QUERY_FLAG_NUMBER
, NULL
, &status
, &size
, NULL
);
230 ok(ret
, "failed unexpectedly %u\n", GetLastError());
231 ok(status
== 200, "request failed unexpectedly %u\n", status
);
233 setup_test( &info
, winhttp_close_handle
, __LINE__
);
234 WinHttpCloseHandle( req
);
236 setup_test( &info
, winhttp_close_handle
, __LINE__
);
237 WinHttpCloseHandle( req
);
238 WinHttpCloseHandle( con
);
239 WinHttpCloseHandle( ses
);
241 Sleep(2000); /* make sure connection is evicted from cache */
245 ses
= WinHttpOpen( user_agent
, 0, NULL
, NULL
, 0 );
246 ok(ses
!= NULL
, "failed to open session %u\n", GetLastError());
248 WinHttpSetStatusCallback( ses
, check_notification
, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS
, 0 );
250 ret
= WinHttpSetOption( ses
, WINHTTP_OPTION_CONTEXT_VALUE
, &context
, sizeof(struct info
*) );
251 ok(ret
, "failed to set context value %u\n", GetLastError());
253 setup_test( &info
, winhttp_connect
, __LINE__
);
254 con
= WinHttpConnect( ses
, test_winehq
, 0, 0 );
255 ok(con
!= NULL
, "failed to open a connection %u\n", GetLastError());
257 setup_test( &info
, winhttp_open_request
, __LINE__
);
258 req
= WinHttpOpenRequest( con
, NULL
, NULL
, NULL
, NULL
, NULL
, 0 );
259 ok(req
!= NULL
, "failed to open a request %u\n", GetLastError());
261 ret
= WinHttpSetOption( req
, WINHTTP_OPTION_CONTEXT_VALUE
, &context
, sizeof(struct info
*) );
262 ok(ret
, "failed to set context value %u\n", GetLastError());
264 setup_test( &info
, winhttp_send_request
, __LINE__
);
265 ret
= WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 );
266 if (!ret
&& GetLastError() == ERROR_WINHTTP_CANNOT_CONNECT
)
268 skip("connection failed, skipping\n");
271 ok(ret
, "failed to send request %u\n", GetLastError());
273 setup_test( &info
, winhttp_receive_response
, __LINE__
);
274 ret
= WinHttpReceiveResponse( req
, NULL
);
275 ok(ret
, "failed to receive response %u\n", GetLastError());
277 size
= sizeof(status
);
278 ret
= WinHttpQueryHeaders( req
, WINHTTP_QUERY_STATUS_CODE
| WINHTTP_QUERY_FLAG_NUMBER
, NULL
, &status
, &size
, NULL
);
279 ok(ret
, "failed unexpectedly %u\n", GetLastError());
280 ok(status
== 200, "request failed unexpectedly %u\n", status
);
282 setup_test( &info
, winhttp_close_handle
, __LINE__
);
283 WinHttpCloseHandle( req
);
285 setup_test( &info
, winhttp_open_request
, __LINE__
);
286 req
= WinHttpOpenRequest( con
, NULL
, NULL
, NULL
, NULL
, NULL
, 0 );
287 ok(req
!= NULL
, "failed to open a request %u\n", GetLastError());
289 ret
= WinHttpSetOption( req
, WINHTTP_OPTION_CONTEXT_VALUE
, &context
, sizeof(struct info
*) );
290 ok(ret
, "failed to set context value %u\n", GetLastError());
292 setup_test( &info
, winhttp_send_request
, __LINE__
);
293 ret
= WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 );
294 if (!ret
&& GetLastError() == ERROR_WINHTTP_CANNOT_CONNECT
)
296 skip("connection failed, skipping\n");
299 ok(ret
, "failed to send request %u\n", GetLastError());
301 setup_test( &info
, winhttp_receive_response
, __LINE__
);
302 ret
= WinHttpReceiveResponse( req
, NULL
);
303 ok(ret
, "failed to receive response %u\n", GetLastError());
305 size
= sizeof(status
);
306 ret
= WinHttpQueryHeaders( req
, WINHTTP_QUERY_STATUS_CODE
| WINHTTP_QUERY_FLAG_NUMBER
, NULL
, &status
, &size
, NULL
);
307 ok(ret
, "failed unexpectedly %u\n", GetLastError());
308 ok(status
== 200, "request failed unexpectedly %u\n", status
);
310 setup_test( &info
, winhttp_close_handle
, __LINE__
);
312 WinHttpCloseHandle( req
);
313 WinHttpCloseHandle( con
);
314 WinHttpCloseHandle( ses
);
316 Sleep(2000); /* make sure connection is evicted from cache */
319 static const struct notification redirect_test
[] =
321 { winhttp_connect
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
},
322 { winhttp_open_request
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
},
323 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME
, FALSE
, TRUE
},
324 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED
, FALSE
, TRUE
},
325 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER
},
326 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER
},
327 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST
},
328 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_REQUEST_SENT
},
329 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE
},
330 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED
},
331 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_REDIRECT
},
332 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME
, FALSE
, TRUE
, TRUE
},
333 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED
, FALSE
, TRUE
, TRUE
},
334 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER
, FALSE
, FALSE
, TRUE
},
335 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER
, FALSE
, FALSE
, TRUE
},
336 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST
},
337 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_REQUEST_SENT
},
338 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE
},
339 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED
},
340 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION
, FALSE
, TRUE
},
341 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED
, FALSE
, TRUE
},
342 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, FALSE
, TRUE
},
343 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, TRUE
, TRUE
},
344 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, TRUE
, TRUE
}
347 static void test_redirect( void )
349 HANDLE ses
, con
, req
;
352 struct info info
, *context
= &info
;
354 info
.test
= redirect_test
;
355 info
.count
= sizeof(redirect_test
) / sizeof(redirect_test
[0]);
359 ses
= WinHttpOpen( user_agent
, 0, NULL
, NULL
, 0 );
360 ok(ses
!= NULL
, "failed to open session %u\n", GetLastError());
362 WinHttpSetStatusCallback( ses
, check_notification
, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS
, 0 );
364 ret
= WinHttpSetOption( ses
, WINHTTP_OPTION_CONTEXT_VALUE
, &context
, sizeof(struct info
*) );
365 ok(ret
, "failed to set context value %u\n", GetLastError());
367 setup_test( &info
, winhttp_connect
, __LINE__
);
368 con
= WinHttpConnect( ses
, test_winehq
, 0, 0 );
369 ok(con
!= NULL
, "failed to open a connection %u\n", GetLastError());
371 setup_test( &info
, winhttp_open_request
, __LINE__
);
372 req
= WinHttpOpenRequest( con
, NULL
, NULL
, NULL
, NULL
, NULL
, 0 );
373 ok(req
!= NULL
, "failed to open a request %u\n", GetLastError());
375 setup_test( &info
, winhttp_send_request
, __LINE__
);
376 ret
= WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 );
377 if (!ret
&& GetLastError() == ERROR_WINHTTP_CANNOT_CONNECT
)
379 skip("connection failed, skipping\n");
382 ok(ret
, "failed to send request %u\n", GetLastError());
384 setup_test( &info
, winhttp_receive_response
, __LINE__
);
385 ret
= WinHttpReceiveResponse( req
, NULL
);
386 ok(ret
, "failed to receive response %u\n", GetLastError());
388 size
= sizeof(status
);
389 ret
= WinHttpQueryHeaders( req
, WINHTTP_QUERY_STATUS_CODE
| WINHTTP_QUERY_FLAG_NUMBER
, NULL
, &status
, &size
, NULL
);
390 ok(ret
, "failed unexpectedly %u\n", GetLastError());
391 ok(status
== 200, "request failed unexpectedly %u\n", status
);
393 setup_test( &info
, winhttp_close_handle
, __LINE__
);
395 WinHttpCloseHandle( req
);
396 WinHttpCloseHandle( con
);
397 WinHttpCloseHandle( ses
);
400 static const struct notification async_test
[] =
402 { winhttp_connect
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
},
403 { winhttp_open_request
, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED
},
404 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME
, FALSE
, TRUE
},
405 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED
, FALSE
, TRUE
},
406 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER
},
407 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER
},
408 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST
},
409 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_REQUEST_SENT
},
410 { winhttp_send_request
, WINHTTP_CALLBACK_STATUS_SENDREQUEST_COMPLETE
},
411 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE
},
412 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED
},
413 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_REDIRECT
},
414 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RESOLVING_NAME
, FALSE
, TRUE
, TRUE
},
415 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_NAME_RESOLVED
, FALSE
, TRUE
, TRUE
},
416 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER
, FALSE
, FALSE
, TRUE
},
417 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER
, FALSE
, FALSE
, TRUE
},
418 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST
},
419 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_REQUEST_SENT
},
420 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE
},
421 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED
},
422 { winhttp_receive_response
, WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE
},
423 { winhttp_query_data
, WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE
},
424 { winhttp_read_data
, WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE
, FALSE
, TRUE
},
425 { winhttp_read_data
, WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED
, FALSE
, TRUE
},
426 { winhttp_read_data
, WINHTTP_CALLBACK_STATUS_READ_COMPLETE
, FALSE
, TRUE
},
427 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION
, FALSE
, TRUE
},
428 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED
, FALSE
, TRUE
},
429 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, FALSE
, TRUE
},
430 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, TRUE
, TRUE
},
431 { winhttp_close_handle
, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING
, TRUE
, TRUE
}
434 static void test_async( void )
436 HANDLE ses
, con
, req
;
439 struct info info
, *context
= &info
;
442 info
.test
= async_test
;
443 info
.count
= sizeof(async_test
) / sizeof(async_test
[0]);
445 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
447 ses
= WinHttpOpen( user_agent
, 0, NULL
, NULL
, WINHTTP_FLAG_ASYNC
);
448 ok(ses
!= NULL
, "failed to open session %u\n", GetLastError());
450 WinHttpSetStatusCallback( ses
, check_notification
, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS
, 0 );
452 ret
= WinHttpSetOption( ses
, WINHTTP_OPTION_CONTEXT_VALUE
, &context
, sizeof(struct info
*) );
453 ok(ret
, "failed to set context value %u\n", GetLastError());
455 setup_test( &info
, winhttp_connect
, __LINE__
);
456 con
= WinHttpConnect( ses
, test_winehq
, 0, 0 );
457 ok(con
!= NULL
, "failed to open a connection %u\n", GetLastError());
459 setup_test( &info
, winhttp_open_request
, __LINE__
);
460 req
= WinHttpOpenRequest( con
, NULL
, NULL
, NULL
, NULL
, NULL
, 0 );
461 ok(req
!= NULL
, "failed to open a request %u\n", GetLastError());
463 setup_test( &info
, winhttp_send_request
, __LINE__
);
464 ret
= WinHttpSendRequest( req
, NULL
, 0, NULL
, 0, 0, 0 );
465 if (!ret
&& GetLastError() == ERROR_WINHTTP_CANNOT_CONNECT
)
467 skip("connection failed, skipping\n");
468 WinHttpCloseHandle( req
);
469 WinHttpCloseHandle( con
);
470 WinHttpCloseHandle( ses
);
471 CloseHandle( info
.wait
);
474 ok(ret
, "failed to send request %u\n", GetLastError());
476 WaitForSingleObject( info
.wait
, INFINITE
);
478 setup_test( &info
, winhttp_receive_response
, __LINE__
);
479 ret
= WinHttpReceiveResponse( req
, NULL
);
480 ok(ret
, "failed to receive response %u\n", GetLastError());
482 WaitForSingleObject( info
.wait
, INFINITE
);
484 size
= sizeof(status
);
485 ret
= WinHttpQueryHeaders( req
, WINHTTP_QUERY_STATUS_CODE
| WINHTTP_QUERY_FLAG_NUMBER
, NULL
, &status
, &size
, NULL
);
486 ok(ret
, "failed unexpectedly %u\n", GetLastError());
487 ok(status
== 200, "request failed unexpectedly %u\n", status
);
489 setup_test( &info
, winhttp_query_data
, __LINE__
);
490 ret
= WinHttpQueryDataAvailable( req
, NULL
);
491 ok(ret
, "failed to query data available %u\n", GetLastError());
493 WaitForSingleObject( info
.wait
, INFINITE
);
495 setup_test( &info
, winhttp_read_data
, __LINE__
);
496 ret
= WinHttpReadData( req
, buffer
, sizeof(buffer
), NULL
);
497 ok(ret
, "failed to query data available %u\n", GetLastError());
499 WaitForSingleObject( info
.wait
, INFINITE
);
501 setup_test( &info
, winhttp_close_handle
, __LINE__
);
502 WinHttpCloseHandle( req
);
503 WinHttpCloseHandle( con
);
504 WinHttpCloseHandle( ses
);
506 WaitForSingleObject( info
.wait
, INFINITE
);
507 CloseHandle( info
.wait
);
510 START_TEST (notification
)
512 test_connection_cache();
514 Sleep(2000); /* make sure previous connection is evicted from cache */