2021-11-28 11:41:30 +01:00
|
|
|
/*
|
|
|
|
* 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;
|
2021-12-28 20:09:49 +01:00
|
|
|
BOOL ret;
|
2021-11-28 11:41:30 +01:00
|
|
|
|
|
|
|
if (!pCompareObjectHandles)
|
|
|
|
{
|
|
|
|
skip("CompareObjectHandles is not available.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-28 20:09:49 +01:00
|
|
|
ret = pCompareObjectHandles( GetCurrentProcess(), GetCurrentProcess() );
|
2022-02-28 08:27:35 +01:00
|
|
|
ok( ret, "comparing GetCurrentProcess() to self failed with %lu\n", GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
2021-12-28 20:09:49 +01:00
|
|
|
ret = pCompareObjectHandles( GetCurrentThread(), GetCurrentThread() );
|
2022-02-28 08:27:35 +01:00
|
|
|
ok( ret, "comparing GetCurrentThread() to self failed with %lu\n", GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
|
|
|
SetLastError(0);
|
2021-12-28 20:09:49 +01:00
|
|
|
ret = pCompareObjectHandles( GetCurrentProcess(), GetCurrentThread() );
|
|
|
|
ok( !ret && GetLastError() == ERROR_NOT_SAME_OBJECT,
|
2022-02-28 08:27:35 +01:00
|
|
|
"comparing GetCurrentProcess() to GetCurrentThread() returned %lu\n", GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
|
|
|
h1 = NULL;
|
2021-12-28 20:09:49 +01:00
|
|
|
ret = DuplicateHandle( GetCurrentProcess(), GetCurrentProcess(), GetCurrentProcess(),
|
|
|
|
&h1, 0, FALSE, DUPLICATE_SAME_ACCESS );
|
2022-02-28 08:27:35 +01:00
|
|
|
ok( ret, "failed to duplicate current process handle: %lu\n", GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
2021-12-28 20:09:49 +01:00
|
|
|
ret = pCompareObjectHandles( GetCurrentProcess(), h1 );
|
2022-02-28 08:27:35 +01:00
|
|
|
ok( ret, "comparing GetCurrentProcess() with %p failed with %lu\n", h1, GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
|
|
|
CloseHandle( h1 );
|
|
|
|
|
2021-12-16 18:03:55 +01:00
|
|
|
h1 = CreateFileA( "\\\\.\\NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
|
2022-02-28 08:27:35 +01:00
|
|
|
ok( h1 != INVALID_HANDLE_VALUE, "CreateFile failed (%ld)\n", GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
|
|
|
h2 = NULL;
|
2021-12-28 20:09:49 +01:00
|
|
|
ret = DuplicateHandle( GetCurrentProcess(), h1, GetCurrentProcess(),
|
|
|
|
&h2, 0, FALSE, DUPLICATE_SAME_ACCESS );
|
2022-02-28 08:27:35 +01:00
|
|
|
ok( ret, "failed to duplicate handle %p: %lu\n", h1, GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
2021-12-28 20:09:49 +01:00
|
|
|
ret = pCompareObjectHandles( h1, h2 );
|
2022-02-28 08:27:35 +01:00
|
|
|
ok( ret, "comparing %p with %p failed with %lu\n", h1, h2, GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
|
|
|
CloseHandle( h2 );
|
|
|
|
|
2021-12-16 18:03:55 +01:00
|
|
|
h2 = CreateFileA( "\\\\.\\NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
|
2022-02-28 08:27:35 +01:00
|
|
|
ok( h2 != INVALID_HANDLE_VALUE, "CreateFile failed (%ld)\n", GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
|
|
|
SetLastError(0);
|
2021-12-28 20:09:49 +01:00
|
|
|
ret = pCompareObjectHandles( h1, h2 );
|
|
|
|
ok( !ret && GetLastError() == ERROR_NOT_SAME_OBJECT,
|
2022-02-28 08:27:35 +01:00
|
|
|
"comparing %p with %p returned %lu\n", h1, h2, GetLastError() );
|
2021-11-28 11:41:30 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|