[MOUNTMGR_APITEST] Add utils.c for some utility functions (#6990)

And update the precompiled header.
This commit is contained in:
Hermès Bélusca-Maïto 2025-01-06 21:51:57 +01:00
parent 357505e752
commit 2da5db933c
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 75 additions and 10 deletions

View file

@ -1,6 +1,7 @@
list(APPEND SOURCE
QueryPoints.c)
QueryPoints.c
utils.c)
list(APPEND PCH_SKIP_SOURCE
testlist.c)
@ -9,9 +10,8 @@ add_executable(mountmgr_apitest
${SOURCE}
${PCH_SKIP_SOURCE})
add_pch(mountmgr_apitest precomp.h "${PCH_SKIP_SOURCE}")
target_link_libraries(mountmgr_apitest wine ${PSEH_LIB})
set_module_type(mountmgr_apitest win32cui)
add_importlibs(mountmgr_apitest msvcrt kernel32 ntdll)
# TODO: Enable this when we get more than one source file to justify its use
#add_pch(mountmgr_apitest precomp.h "${PCH_SKIP_SOURCE}")
add_rostests_file(TARGET mountmgr_apitest)

View file

@ -1,12 +1,28 @@
#ifndef _MOUNTMGR_APITEST_PRECOMP_H_
#define _MOUNTMGR_APITEST_PRECOMP_H_
/*
* PROJECT: ReactOS API Tests
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Precompiled header
* COPYRIGHT: Copyright 2019 Pierre Schweitzer <pierre@reactos.org>
* Copyright 2025 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
*/
#pragma once
#define WIN32_NO_STATUS
#include <apitest.h>
#include <strsafe.h>
#include <ntstatus.h>
#include <mountmgr.h>
#define NTOS_MODE_USER
#include <ndk/iofuncs.h>
#include <ndk/rtlfuncs.h>
#endif /* _MOUNTMGR_APITEST_PRECOMP_H_ */
#include <mountmgr.h>
#include <strsafe.h>
/* utils.c */
LPCSTR wine_dbgstr_us(const UNICODE_STRING *us);
HANDLE
GetMountMgrHandle(VOID);
/* EOF */

View file

@ -0,0 +1,49 @@
/*
* PROJECT: ReactOS API Tests
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Utility functions
* COPYRIGHT: Copyright 2025 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
*/
#include "precomp.h"
LPCSTR wine_dbgstr_us(const UNICODE_STRING *us)
{
if (!us) return "(null)";
return wine_dbgstr_wn(us->Buffer, us->Length / sizeof(WCHAR));
}
/**
* @brief
* Retrieves a handle to the MountMgr controlling device.
* The handle should be closed with NtClose() once it is no longer in use.
**/
HANDLE
GetMountMgrHandle(VOID)
{
NTSTATUS Status;
UNICODE_STRING MountMgrDevice;
OBJECT_ATTRIBUTES ObjectAttributes;
IO_STATUS_BLOCK IoStatusBlock;
HANDLE MountMgrHandle = NULL;
RtlInitUnicodeString(&MountMgrDevice, MOUNTMGR_DEVICE_NAME);
InitializeObjectAttributes(&ObjectAttributes,
&MountMgrDevice,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status = NtOpenFile(&MountMgrHandle,
FILE_READ_ATTRIBUTES | SYNCHRONIZE,
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(Status))
{
winetest_print("NtOpenFile(%s) failed, Status 0x%08lx\n",
wine_dbgstr_us(&MountMgrDevice), Status);
}
return MountMgrHandle;
}