From: Jérôme Gardou Date: Mon, 7 Jul 2014 14:46:04 +0000 (+0000) Subject: [NTDLL_APITEST] X-Git-Tag: backups/0.3.17@66124~912 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=d331e1725bed312464ae9142dacecff61c8c9912 [NTDLL_APITEST] - Add tests for NtDeleteKey svn path=/trunk/; revision=63699 --- diff --git a/rostests/apitests/ntdll/CMakeLists.txt b/rostests/apitests/ntdll/CMakeLists.txt index 8891df5f712..03309b83c16 100644 --- a/rostests/apitests/ntdll/CMakeLists.txt +++ b/rostests/apitests/ntdll/CMakeLists.txt @@ -5,6 +5,7 @@ list(APPEND SOURCE NtContinue.c NtCreateFile.c NtCreateThread.c + NtDeleteKey.c NtFreeVirtualMemory.c NtMapViewOfSection.c NtMutant.c diff --git a/rostests/apitests/ntdll/NtDeleteKey.c b/rostests/apitests/ntdll/NtDeleteKey.c new file mode 100644 index 00000000000..2e2a327783c --- /dev/null +++ b/rostests/apitests/ntdll/NtDeleteKey.c @@ -0,0 +1,96 @@ +/* + * PROJECT: ReactOS API Tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Test for NtDeleteKey + */ + +#include + +#define WIN32_NO_STATUS +#include +#include +#include +#include + +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); +} diff --git a/rostests/apitests/ntdll/testlist.c b/rostests/apitests/ntdll/testlist.c index 0a4a8466089..69fc3db2920 100644 --- a/rostests/apitests/ntdll/testlist.c +++ b/rostests/apitests/ntdll/testlist.c @@ -8,6 +8,7 @@ extern void func_NtAllocateVirtualMemory(void); extern void func_NtContinue(void); extern void func_NtCreateFile(void); extern void func_NtCreateThread(void); +extern void func_NtDeleteKey(void); extern void func_NtFreeVirtualMemory(void); extern void func_NtMapViewOfSection(void); extern void func_NtMutant(void); @@ -38,6 +39,7 @@ const struct test winetest_testlist[] = { "NtContinue", func_NtContinue }, { "NtCreateFile", func_NtCreateFile }, { "NtCreateThread", func_NtCreateThread }, + { "NtDeleteKey", func_NtDeleteKey }, { "NtFreeVirtualMemory", func_NtFreeVirtualMemory }, { "NtMapViewOfSection", func_NtMapViewOfSection }, { "NtMutant", func_NtMutant },