https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2da5db933cc0510f1e80c873b33c79d0bd2a9e61

commit 2da5db933cc0510f1e80c873b33c79d0bd2a9e61
Author:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
AuthorDate: Mon Jan 6 21:51:57 2025 +0100
Commit:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
CommitDate: Tue Jan 21 19:15:50 2025 +0100

    [MOUNTMGR_APITEST] Add utils.c for some utility functions (#6990)
    
    And update the precompiled header.
---
 modules/rostests/apitests/mountmgr/CMakeLists.txt |  6 +--
 modules/rostests/apitests/mountmgr/precomp.h      | 30 ++++++++++----
 modules/rostests/apitests/mountmgr/utils.c        | 49 +++++++++++++++++++++++
 3 files changed, 75 insertions(+), 10 deletions(-)

diff --git a/modules/rostests/apitests/mountmgr/CMakeLists.txt 
b/modules/rostests/apitests/mountmgr/CMakeLists.txt
index 4c499c26a98..dbba2775f56 100644
--- a/modules/rostests/apitests/mountmgr/CMakeLists.txt
+++ b/modules/rostests/apitests/mountmgr/CMakeLists.txt
@@ -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)
diff --git a/modules/rostests/apitests/mountmgr/precomp.h 
b/modules/rostests/apitests/mountmgr/precomp.h
index 33509fb8083..462f62e1a38 100644
--- a/modules/rostests/apitests/mountmgr/precomp.h
+++ b/modules/rostests/apitests/mountmgr/precomp.h
@@ -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 <pie...@reactos.org>
+ *              Copyright 2025 Hermès Bélusca-Maïto 
<hermes.belusca-ma...@reactos.org>
+ */
 
-#define WIN32_NO_STATUS
+#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 */
diff --git a/modules/rostests/apitests/mountmgr/utils.c 
b/modules/rostests/apitests/mountmgr/utils.c
new file mode 100644
index 00000000000..50755581f04
--- /dev/null
+++ b/modules/rostests/apitests/mountmgr/utils.c
@@ -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-ma...@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;
+}

Reply via email to