[PATCH 2/3] ntdll/tests: Test return values from CloseHandle.

Daniel Lehman dlehman25 at gmail.com
Sun Apr 3 02:13:35 CDT 2022


Signed-off-by: Daniel Lehman <dlehman25 at gmail.com>
---
 dlls/ntdll/tests/exception.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c
index 98d185f5f07..8af8d6b70da 100644
--- a/dlls/ntdll/tests/exception.c
+++ b/dlls/ntdll/tests/exception.c
@@ -8606,7 +8606,9 @@ static inline BOOL is_magic_handle(HANDLE handle)
 
 static void test_closehandle(DWORD numexc, HANDLE handle)
 {
+    NTSTATUS status, expect;
     PVOID vectored_handler;
+    BOOL ret, expectret;
 
     if (!pRtlAddVectoredExceptionHandler || !pRtlRemoveVectoredExceptionHandler || !pRtlRaiseException)
     {
@@ -8618,18 +8620,28 @@ static void test_closehandle(DWORD numexc, HANDLE handle)
     ok(vectored_handler != 0, "RtlAddVectoredExceptionHandler failed\n");
 
     invalid_handle_exceptions = 0;
-    CloseHandle(handle);
-    todo_wine_if(is_magic_handle(handle))
+    expectret = is_magic_handle(handle) || broken(numexc && sizeof(handle) == 4); /* < Win10 */
+    ret = CloseHandle(handle);
+    ok(expectret || (GetLastError() == ERROR_INVALID_HANDLE),
+        "CloseHandle had wrong GetLastError(), got %lu for %p\n", GetLastError(), handle);
+    todo_wine_if(is_magic_handle(handle)) {
+    ok(ret == expectret || broken(HandleToLong(handle) < 0) /* < Win10 */,
+        "CloseHandle expected %d, got %d for %p\n", expectret, ret, handle);
     ok(invalid_handle_exceptions == numexc || broken(!numexc && is_magic_handle(handle)), /* < Win10 */
         "CloseHandle generated %ld exceptions, expected %ld for %p\n",
        invalid_handle_exceptions, numexc, handle);
+    }
 
     invalid_handle_exceptions = 0;
-    pNtClose(handle);
-    todo_wine_if(is_magic_handle(handle))
+    expect = expectret ? STATUS_SUCCESS : STATUS_INVALID_HANDLE;
+    status = pNtClose(handle);
+    todo_wine_if(is_magic_handle(handle)) {
+    ok(status == expect || broken(HandleToLong(handle) < 0), /* < Win10 */
+        "NtClose returned unexpected status %#lx, expected %#lx for %p\n", status, expect, handle);
     ok(invalid_handle_exceptions == numexc || broken(!numexc && is_magic_handle(handle)), /* < Win10 */
         "CloseHandle generated %ld exceptions, expected %ld for %p\n",
        invalid_handle_exceptions, numexc, handle);
+    }
 
     pRtlRemoveVectoredExceptionHandler(vectored_handler);
 }
-- 
2.25.1




More information about the wine-devel mailing list