Module: wine Branch: master Commit: 188de034974feb31fd67cec0d013257edde533c1 URL: http://source.winehq.org/git/wine.git/?a=commit;h=188de034974feb31fd67cec0d0...
Author: Jacek Caban jacek@codeweavers.com Date: Fri May 13 13:48:50 2011 +0200
wininet: Better closing async handles in tests.
---
dlls/wininet/tests/http.c | 65 ++++++++++++++------------------------------- 1 files changed, 20 insertions(+), 45 deletions(-)
diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index c959e5c..a754dd7 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -178,6 +178,8 @@ static BOOL proxy_active(void) return proxy_enable != 0; }
+static int close_handle_cnt; + static VOID WINAPI callback( HINTERNET hInternet, DWORD_PTR dwContext, @@ -276,6 +278,8 @@ static VOID WINAPI callback( trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n", GetCurrentThreadId(), hInternet, dwContext, *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength); + if(!--close_handle_cnt) + SetEvent(hCompleteEvent); break; case INTERNET_STATUS_REQUEST_COMPLETE: { @@ -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) { char *post_data = NULL; @@ -567,32 +585,7 @@ static void InternetReadFile_test(int flags, const test_data_t *test) } abort: trace("aborting\n"); - SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0)); - 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)); + close_async_handle(hi, hCompleteEvent, 2); CloseHandle(hCompleteEvent); first_connection_to_test_url = FALSE; } @@ -930,25 +923,7 @@ static void InternetReadFileExA_test(int flags) trace("Finished. Read %d bytes\n", length);
abort: - SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, (hor != 0x0) + (hic != 0x0)); - 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)); - } + close_async_handle(hi, hCompleteEvent, 2); CloseHandle(hCompleteEvent); first_connection_to_test_url = FALSE; }