reactos/rostests/apitests/ntdll/NtDeleteKey.c

97 lines
2.9 KiB
C
Raw Normal View History

/*
* PROJECT: ReactOS API Tests
* LICENSE: GPLv2+ - See COPYING in the top level directory
* PURPOSE: Test for NtDeleteKey
*/
#include <apitest.h>
#define WIN32_NO_STATUS
#include <ndk/rtlfuncs.h>
#include <ndk/cmfuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/setypes.h>
static
NTSTATUS
CreateRegistryKeyHandle(PHANDLE KeyHandle,
ACCESS_MASK AccessMask,
PWCHAR RegistryPath)
{
UNICODE_STRING KeyName;
OBJECT_ATTRIBUTES Attributes;
RtlInitUnicodeString(&KeyName, RegistryPath);
InitializeObjectAttributes(&Attributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
return NtCreateKey(KeyHandle, AccessMask, &Attributes, 0, NULL, REG_OPTION_VOLATILE, 0);
}
START_TEST(NtDeleteKey)
{
NTSTATUS Status;
HANDLE ParentKey, ChildKey;
/* Create a registry key */
Status = CreateRegistryKeyHandle(&ParentKey, KEY_READ | DELETE, L"\\Registry\\Machine\\Software\\RosTests");
ok_ntstatus(Status, STATUS_SUCCESS);
/* Create a children registry key */
Status = CreateRegistryKeyHandle(&ChildKey, KEY_READ | DELETE, L"\\Registry\\Machine\\Software\\RosTests\\Child");
ok_ntstatus(Status, STATUS_SUCCESS);
/* Try deleting the parent one */
Status = NtDeleteKey(ParentKey);
ok_ntstatus(Status, STATUS_CANNOT_DELETE);
/* See what happens with Child one */
Status = NtDeleteKey(ChildKey);
ok_ntstatus(Status, STATUS_SUCCESS);
/* Retry with parent one */
Status = NtDeleteKey(ParentKey);
ok_ntstatus(Status, STATUS_SUCCESS);
/* re-retry */
Status = NtDeleteKey(ParentKey);
ok_ntstatus(Status, STATUS_SUCCESS);
/* Close everything */
NtClose(ChildKey);
NtClose(ParentKey);
/* Same, but this time close the child handle before trying to delete the parent */
/* Create a registry key */
Status = CreateRegistryKeyHandle(&ParentKey, KEY_READ | DELETE, L"\\Registry\\Machine\\Software\\RosTests");
ok_ntstatus(Status, STATUS_SUCCESS);
/* Create a children registry key */
Status = CreateRegistryKeyHandle(&ChildKey, KEY_READ, L"\\Registry\\Machine\\Software\\RosTests\\Child");
ok_ntstatus(Status, STATUS_SUCCESS);
/* Close the Child */
NtClose(ChildKey);
/* Try deleting the parent one */
Status = NtDeleteKey(ParentKey);
ok_ntstatus(Status, STATUS_CANNOT_DELETE);
/* See what happens with Child one */
Status = CreateRegistryKeyHandle(&ChildKey, DELETE, L"\\Registry\\Machine\\Software\\RosTests\\Child");
ok_ntstatus(Status, STATUS_SUCCESS);
Status = NtDeleteKey(ChildKey);
ok_ntstatus(Status, STATUS_SUCCESS);
/* Retry with parent one */
Status = NtDeleteKey(ParentKey);
ok_ntstatus(Status, STATUS_SUCCESS);
/* Close everything */
NtClose(ChildKey);
NtClose(ParentKey);
}