ReactOS  0.4.15-dev-313-g8fde48b
NtDeleteKey.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API Tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Test for NtDeleteKey
5  */
6 
7 #include "precomp.h"
8 
9 static
14 {
17 
20  &KeyName,
22  NULL,
23  NULL);
24 
26 }
27 
29 {
31  HANDLE ParentKey, ChildKey, PetKey;
32  WCHAR Buffer[sizeof("\\Registry\\Machine\\Software\\RosTests\\Child\\Pet") + 5];
33  ULONG i;
34 
35  /* Create a registry key */
36  Status = CreateRegistryKeyHandle(&ParentKey, KEY_READ | DELETE, L"\\Registry\\Machine\\Software\\RosTests");
38 
39  /* Create a children registry key */
40  Status = CreateRegistryKeyHandle(&ChildKey, KEY_READ | DELETE, L"\\Registry\\Machine\\Software\\RosTests\\Child");
42 
43  /* Try deleting the parent one */
44  Status = NtDeleteKey(ParentKey);
46 
47  /* See what happens with Child one */
48  Status = NtDeleteKey(ChildKey);
50 
51  /* Retry with parent one */
52  Status = NtDeleteKey(ParentKey);
54 
55  /* re-retry */
56  Status = NtDeleteKey(ParentKey);
58 
59  /* Close everything */
60  NtClose(ChildKey);
61  NtClose(ParentKey);
62 
63  /* Same, but this time close the child handle before trying to delete the parent */
64  /* Create a registry key */
65  Status = CreateRegistryKeyHandle(&ParentKey, KEY_READ | DELETE, L"\\Registry\\Machine\\Software\\RosTests");
67 
68  /* Create a children registry key */
69  Status = CreateRegistryKeyHandle(&ChildKey, KEY_READ, L"\\Registry\\Machine\\Software\\RosTests\\Child");
71 
72  /* Close the Child */
73  NtClose(ChildKey);
74 
75  /* Try deleting the parent one */
76  Status = NtDeleteKey(ParentKey);
78 
79  /* See what happens with Child one */
80  Status = CreateRegistryKeyHandle(&ChildKey, DELETE, L"\\Registry\\Machine\\Software\\RosTests\\Child");
82  Status = NtDeleteKey(ChildKey);
84 
85  /* Retry with parent one */
86  Status = NtDeleteKey(ParentKey);
88 
89  /* Close everything */
90  NtClose(ChildKey);
91  NtClose(ParentKey);
92 
93  /* Stress test key creation */
94  Status = CreateRegistryKeyHandle(&ParentKey, KEY_READ | DELETE, L"\\Registry\\Machine\\Software\\RosTests");
95 
96  for (i = 0; i <= 9999; i++) {
97  swprintf(Buffer, L"\\Registry\\Machine\\Software\\RosTests\\Child%04d", i);
99  NtClose(ChildKey);
100 
101  swprintf(Buffer, L"\\Registry\\Machine\\Software\\RosTests\\Child%04d\\Pet", i);
103  NtClose(PetKey);
104  }
106 
107  /* Test hive rerooting */
108  Status = CreateRegistryKeyHandle(&PetKey, DELETE, L"\\Registry\\Machine\\Software\\RosTests\\Child5000\\Pet");
110  Status = NtDeleteKey(PetKey);
112 
113  NtClose(PetKey);
114 
115  Status = CreateRegistryKeyHandle(&ChildKey, DELETE, L"\\Registry\\Machine\\Software\\RosTests\\Child5000");
117  Status = NtDeleteKey(ChildKey);
119 
120  /* Test mass key deletion */
121  for (i = 0; i <= 9999; i++) {
122  if (i != 5000) {
123  swprintf(Buffer, L"\\Registry\\Machine\\Software\\RosTests\\Child%04d\\Pet", i);
125  Status = NtDeleteKey(PetKey);
126  NtClose(PetKey);
127 
128  swprintf(Buffer, L"\\Registry\\Machine\\Software\\RosTests\\Child%04d", i);
130  Status = NtDeleteKey(ChildKey);
131  NtClose(ChildKey);
132  }
133  }
135 
136  Status = NtDeleteKey(ParentKey);
138 
139  /* Close ParentKey */
140  NtClose(ParentKey);
141 }
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
NTSTATUS NTAPI NtCreateKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG TitleIndex, IN PUNICODE_STRING Class OPTIONAL, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
Definition: ntapi.c:240
START_TEST(NtDeleteKey)
Definition: NtDeleteKey.c:28
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define KEY_READ
Definition: nt_native.h:1023
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:55
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
_In_ ACCESS_MASK AccessMask
Definition: exfuncs.h:186
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define STATUS_CANNOT_DELETE
Definition: shellext.h:71
static const WCHAR L[]
Definition: oid.c:1250
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI NtDeleteKey(IN HANDLE KeyHandle)
Definition: ntapi.c:408
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:28
static NTSTATUS CreateRegistryKeyHandle(PHANDLE KeyHandle, ACCESS_MASK AccessMask, PWCHAR RegistryPath)
Definition: NtDeleteKey.c:11
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
return STATUS_SUCCESS
Definition: btrfs.c:3014
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define DELETE
Definition: nt_native.h:57