Jinoh Kang : kernelbase/tests: Add tests for CompareObjectHandles.

Alexandre Julliard julliard at winehq.org
Mon Nov 29 16:26:54 CST 2021


Module: wine
Branch: master
Commit: fef007182a3ea5fc3c5f477903cefcf5ee1c9ca9
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=fef007182a3ea5fc3c5f477903cefcf5ee1c9ca9

Author: Jinoh Kang <jinoh.kang.kr at gmail.com>
Date:   Sun Nov 28 19:41:30 2021 +0900

kernelbase/tests: Add tests for CompareObjectHandles.

Signed-off-by: Jinoh Kang <jinoh.kang.kr at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernelbase/tests/Makefile.in |   1 +
 dlls/kernelbase/tests/process.c   | 102 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+)

diff --git a/dlls/kernelbase/tests/Makefile.in b/dlls/kernelbase/tests/Makefile.in
index fe7ab212e6e..675054c753d 100644
--- a/dlls/kernelbase/tests/Makefile.in
+++ b/dlls/kernelbase/tests/Makefile.in
@@ -2,6 +2,7 @@ TESTDLL   = kernelbase.dll
 
 C_SRCS = \
 	path.c \
+	process.c \
 	sync.c
 
 RC_SRCS = \
diff --git a/dlls/kernelbase/tests/process.c b/dlls/kernelbase/tests/process.c
new file mode 100644
index 00000000000..7aa07df6e4e
--- /dev/null
+++ b/dlls/kernelbase/tests/process.c
@@ -0,0 +1,102 @@
+/*
+ * Process tests
+ *
+ * Copyright 2021 Jinoh Kang
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include <ntstatus.h>
+#define WIN32_NO_STATUS
+#include <windef.h>
+#include <winbase.h>
+#include <winerror.h>
+#include <winternl.h>
+
+#include "wine/test.h"
+
+static BOOL (WINAPI *pCompareObjectHandles)(HANDLE, HANDLE);
+
+static void test_CompareObjectHandles(void)
+{
+    HANDLE h1, h2;
+
+    if (!pCompareObjectHandles)
+    {
+        skip("CompareObjectHandles is not available.\n");
+        return;
+    }
+
+    ok( pCompareObjectHandles( GetCurrentProcess(), GetCurrentProcess() ),
+        "comparing GetCurrentProcess() to self failed with %u\n", GetLastError() );
+
+    ok( pCompareObjectHandles( GetCurrentThread(), GetCurrentThread() ),
+        "comparing GetCurrentThread() to self failed with %u\n", GetLastError() );
+
+    SetLastError(0);
+    ok( !pCompareObjectHandles( GetCurrentProcess(), GetCurrentThread() ) &&
+        GetLastError() == ERROR_NOT_SAME_OBJECT,
+        "comparing GetCurrentProcess() to GetCurrentThread() returned %u\n", GetLastError() );
+
+    h1 = NULL;
+    ok( DuplicateHandle( GetCurrentProcess(), GetCurrentProcess(), GetCurrentProcess(),
+                         &h1, 0, FALSE, DUPLICATE_SAME_ACCESS ),
+        "failed to duplicate current process handle: %u\n", GetLastError() );
+
+    ok( pCompareObjectHandles( GetCurrentProcess(), h1 ),
+        "comparing GetCurrentProcess() with %p failed with %u\n", h1, GetLastError() );
+
+    CloseHandle( h1 );
+
+    h1 = CreateFileA( "\\\\.\\NUL", GENERIC_ALL, 0, NULL, OPEN_EXISTING, 0, 0 );
+    ok( h1 != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError() );
+
+    h2 = NULL;
+    ok( DuplicateHandle( GetCurrentProcess(), h1, GetCurrentProcess(),
+                         &h2, 0, FALSE, DUPLICATE_SAME_ACCESS ),
+        "failed to duplicate handle %p: %u\n", h1, GetLastError() );
+
+    ok( pCompareObjectHandles( h1, h2 ),
+        "comparing %p with %p failed with %u\n", h1, h2, GetLastError() );
+
+    CloseHandle( h2 );
+
+    h2 = CreateFileA( "\\\\.\\NUL", GENERIC_ALL, 0, NULL, OPEN_EXISTING, 0, 0 );
+    ok( h2 != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError() );
+
+    SetLastError(0);
+    ok( !pCompareObjectHandles( h1, h2 ) && GetLastError() == ERROR_NOT_SAME_OBJECT,
+        "comparing %p with %p returned %u\n", h1, h2, GetLastError() );
+
+    CloseHandle( h2 );
+    CloseHandle( h1 );
+}
+
+START_TEST(process)
+{
+    HMODULE hmod;
+
+    hmod = GetModuleHandleA("kernel32.dll");
+    pCompareObjectHandles = (void *)GetProcAddress(hmod, "CompareObjectHandles");
+    ok(!pCompareObjectHandles, "expected CompareObjectHandles only in kernelbase.dll\n");
+
+    hmod = GetModuleHandleA("kernelbase.dll");
+    pCompareObjectHandles = (void *)GetProcAddress(hmod, "CompareObjectHandles");
+
+    test_CompareObjectHandles();
+}




More information about the wine-cvs mailing list