Commit 188de034 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

wininet: Better closing async handles in tests.

parent 3ab29712
...@@ -178,6 +178,8 @@ static BOOL proxy_active(void) ...@@ -178,6 +178,8 @@ static BOOL proxy_active(void)
return proxy_enable != 0; return proxy_enable != 0;
} }
static int close_handle_cnt;
static VOID WINAPI callback( static VOID WINAPI callback(
HINTERNET hInternet, HINTERNET hInternet,
DWORD_PTR dwContext, DWORD_PTR dwContext,
...@@ -276,6 +278,8 @@ static VOID WINAPI callback( ...@@ -276,6 +278,8 @@ static VOID WINAPI callback(
trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n", trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
GetCurrentThreadId(), hInternet, dwContext, GetCurrentThreadId(), hInternet, dwContext,
*(HINTERNET *)lpvStatusInformation, dwStatusInformationLength); *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
if(!--close_handle_cnt)
SetEvent(hCompleteEvent);
break; break;
case INTERNET_STATUS_REQUEST_COMPLETE: case INTERNET_STATUS_REQUEST_COMPLETE:
{ {
...@@ -309,6 +313,20 @@ static VOID WINAPI callback( ...@@ -309,6 +313,20 @@ static VOID WINAPI callback(
} }
} }
static void close_async_handle(HINTERNET handle, HANDLE complete_event, int handle_cnt)
{
BOOL res;
close_handle_cnt = handle_cnt;
SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
res = InternetCloseHandle(handle);
ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
WaitForSingleObject(hCompleteEvent, INFINITE);
CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
}
static void InternetReadFile_test(int flags, const test_data_t *test) static void InternetReadFile_test(int flags, const test_data_t *test)
{ {
char *post_data = NULL; char *post_data = NULL;
...@@ -567,32 +585,7 @@ static void InternetReadFile_test(int flags, const test_data_t *test) ...@@ -567,32 +585,7 @@ static void InternetReadFile_test(int flags, const test_data_t *test)
} }
abort: abort:
trace("aborting\n"); trace("aborting\n");
SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0)); close_async_handle(hi, hCompleteEvent, 2);
if (hor != 0x0) {
SetLastError(0xdeadbeef);
trace("closing\n");
res = InternetCloseHandle(hor);
ok (res, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
SetLastError(0xdeadbeef);
res = InternetCloseHandle(hor);
ok (!res, "Double close of handle opened by HttpOpenRequestA succeeded\n");
ok (GetLastError() == ERROR_INVALID_HANDLE,
"Double close of handle should have set ERROR_INVALID_HANDLE instead of %u\n",
GetLastError());
}
/* We intentionally do not close the handle opened by InternetConnectA as this
* tickles bug #9479: native closes child internet handles when the parent handles
* are closed. This is verified below by checking that the number of
* INTERNET_STATUS_HANDLE_CLOSING notifications matches the number expected. */
if (hi != 0x0) {
SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING);
trace("closing 2\n");
res = InternetCloseHandle(hi);
ok (res, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
if (flags & INTERNET_FLAG_ASYNC)
Sleep(100);
}
CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
CloseHandle(hCompleteEvent); CloseHandle(hCompleteEvent);
first_connection_to_test_url = FALSE; first_connection_to_test_url = FALSE;
} }
...@@ -930,25 +923,7 @@ static void InternetReadFileExA_test(int flags) ...@@ -930,25 +923,7 @@ static void InternetReadFileExA_test(int flags)
trace("Finished. Read %d bytes\n", length); trace("Finished. Read %d bytes\n", length);
abort: abort:
SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0)); close_async_handle(hi, hCompleteEvent, 2);
if (hor) {
rc = InternetCloseHandle(hor);
ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
rc = InternetCloseHandle(hor);
ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
}
if (hic) {
rc = InternetCloseHandle(hic);
ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
}
if (hi) {
SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING);
rc = InternetCloseHandle(hi);
ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
if (flags & INTERNET_FLAG_ASYNC)
Sleep(100);
CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0));
}
CloseHandle(hCompleteEvent); CloseHandle(hCompleteEvent);
first_connection_to_test_url = FALSE; first_connection_to_test_url = FALSE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment