Akihiro Sagawa : advapi32/tests: Add another key unloading test with NtUnloadKey.

Alexandre Julliard julliard at winehq.org
Wed Feb 17 16:23:34 CST 2021


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

Author: Akihiro Sagawa <sagawa.aki at gmail.com>
Date:   Fri Feb 12 20:30:16 2021 +0900

advapi32/tests: Add another key unloading test with NtUnloadKey.

Signed-off-by: Akihiro Sagawa <sagawa.aki at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/advapi32/tests/registry.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index c8f9adf7732..dfadd13ea8c 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -22,6 +22,8 @@
 #include <assert.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
 #include "wine/test.h"
 #include "windef.h"
 #include "winbase.h"
@@ -48,8 +50,10 @@ static LONG (WINAPI *pRegDeleteTreeA)(HKEY,const char *);
 static DWORD (WINAPI *pRegDeleteKeyExA)(HKEY,LPCSTR,REGSAM,DWORD);
 static BOOL (WINAPI *pIsWow64Process)(HANDLE,PBOOL);
 static NTSTATUS (WINAPI * pNtDeleteKey)(HANDLE);
+static NTSTATUS (WINAPI * pNtUnloadKey)(POBJECT_ATTRIBUTES);
 static NTSTATUS (WINAPI * pRtlFormatCurrentUserKeyPath)(UNICODE_STRING*);
 static NTSTATUS (WINAPI * pRtlFreeUnicodeString)(PUNICODE_STRING);
+static NTSTATUS (WINAPI * pRtlInitUnicodeString)(PUNICODE_STRING,PCWSTR);
 static LONG (WINAPI *pRegDeleteKeyValueA)(HKEY,LPCSTR,LPCSTR);
 static LONG (WINAPI *pRegSetKeyValueW)(HKEY,LPCWSTR,LPCWSTR,DWORD,const void*,DWORD);
 static LONG (WINAPI *pRegLoadMUIStringA)(HKEY,LPCSTR,LPSTR,DWORD,LPDWORD,DWORD,LPCSTR);
@@ -90,7 +94,9 @@ static void InitFunctionPtrs(void)
     pIsWow64Process = (void *)GetProcAddress( hkernel32, "IsWow64Process" );
     pRtlFormatCurrentUserKeyPath = (void *)GetProcAddress( hntdll, "RtlFormatCurrentUserKeyPath" );
     pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
+    pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
     pNtDeleteKey = (void *)GetProcAddress( hntdll, "NtDeleteKey" );
+    pNtUnloadKey = (void *)GetProcAddress( hntdll, "NtUnloadKey" );
 }
 
 /* delete key and all its subkeys */
@@ -1561,7 +1567,11 @@ static void test_reg_load_key(void)
 
 static void test_reg_unload_key(void)
 {
+    UNICODE_STRING key_name;
+    OBJECT_ATTRIBUTES attr;
+    NTSTATUS status;
     DWORD ret;
+    HKEY key;
 
     if (!set_privileges(SE_RESTORE_NAME, TRUE) ||
         !set_privileges(SE_BACKUP_NAME, FALSE))
@@ -1570,6 +1580,17 @@ static void test_reg_unload_key(void)
         return;
     }
 
+    ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Test", 0, KEY_READ, &key);
+    ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
+
+    /* try to unload though the key handle is live */
+    pRtlInitUnicodeString(&key_name, L"\\REGISTRY\\Machine\\Test");
+    InitializeObjectAttributes(&attr, &key_name, OBJ_CASE_INSENSITIVE, NULL, NULL);
+    status = pNtUnloadKey(&attr);
+    ok(status == STATUS_CANNOT_DELETE, "expected STATUS_CANNOT_DELETE, got %08x\n", status);
+
+    RegCloseKey(key);
+
     ret = RegUnLoadKeyA(HKEY_LOCAL_MACHINE, "Test");
     ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
 




More information about the wine-cvs mailing list