2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for NtDeleteKey
9 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
12 #include <ndk/cmfuncs.h>
13 #include <ndk/obfuncs.h>
14 #include <ndk/setypes.h>
18 CreateRegistryKeyHandle(PHANDLE KeyHandle
,
19 ACCESS_MASK AccessMask
,
22 UNICODE_STRING KeyName
;
23 OBJECT_ATTRIBUTES Attributes
;
25 RtlInitUnicodeString(&KeyName
, RegistryPath
);
26 InitializeObjectAttributes(&Attributes
,
32 return NtCreateKey(KeyHandle
, AccessMask
, &Attributes
, 0, NULL
, REG_OPTION_VOLATILE
, 0);
35 START_TEST(NtDeleteKey
)
38 HANDLE ParentKey
, ChildKey
, PetKey
;
39 WCHAR Buffer
[sizeof("\\Registry\\Machine\\Software\\RosTests\\Child\\Pet") + 5];
42 /* Create a registry key */
43 Status
= CreateRegistryKeyHandle(&ParentKey
, KEY_READ
| DELETE
, L
"\\Registry\\Machine\\Software\\RosTests");
44 ok_ntstatus(Status
, STATUS_SUCCESS
);
46 /* Create a children registry key */
47 Status
= CreateRegistryKeyHandle(&ChildKey
, KEY_READ
| DELETE
, L
"\\Registry\\Machine\\Software\\RosTests\\Child");
48 ok_ntstatus(Status
, STATUS_SUCCESS
);
50 /* Try deleting the parent one */
51 Status
= NtDeleteKey(ParentKey
);
52 ok_ntstatus(Status
, STATUS_CANNOT_DELETE
);
54 /* See what happens with Child one */
55 Status
= NtDeleteKey(ChildKey
);
56 ok_ntstatus(Status
, STATUS_SUCCESS
);
58 /* Retry with parent one */
59 Status
= NtDeleteKey(ParentKey
);
60 ok_ntstatus(Status
, STATUS_SUCCESS
);
63 Status
= NtDeleteKey(ParentKey
);
64 ok_ntstatus(Status
, STATUS_SUCCESS
);
66 /* Close everything */
70 /* Same, but this time close the child handle before trying to delete the parent */
71 /* Create a registry key */
72 Status
= CreateRegistryKeyHandle(&ParentKey
, KEY_READ
| DELETE
, L
"\\Registry\\Machine\\Software\\RosTests");
73 ok_ntstatus(Status
, STATUS_SUCCESS
);
75 /* Create a children registry key */
76 Status
= CreateRegistryKeyHandle(&ChildKey
, KEY_READ
, L
"\\Registry\\Machine\\Software\\RosTests\\Child");
77 ok_ntstatus(Status
, STATUS_SUCCESS
);
82 /* Try deleting the parent one */
83 Status
= NtDeleteKey(ParentKey
);
84 ok_ntstatus(Status
, STATUS_CANNOT_DELETE
);
86 /* See what happens with Child one */
87 Status
= CreateRegistryKeyHandle(&ChildKey
, DELETE
, L
"\\Registry\\Machine\\Software\\RosTests\\Child");
88 ok_ntstatus(Status
, STATUS_SUCCESS
);
89 Status
= NtDeleteKey(ChildKey
);
90 ok_ntstatus(Status
, STATUS_SUCCESS
);
92 /* Retry with parent one */
93 Status
= NtDeleteKey(ParentKey
);
94 ok_ntstatus(Status
, STATUS_SUCCESS
);
96 /* Close everything */
100 /* Stress test key creation */
101 Status
= CreateRegistryKeyHandle(&ParentKey
, KEY_READ
| DELETE
, L
"\\Registry\\Machine\\Software\\RosTests");
103 for (i
= 0; i
<= 9999; i
++) {
104 swprintf(Buffer
, L
"\\Registry\\Machine\\Software\\RosTests\\Child%04d", i
);
105 Status
= CreateRegistryKeyHandle(&ChildKey
, KEY_READ
, Buffer
);
108 swprintf(Buffer
, L
"\\Registry\\Machine\\Software\\RosTests\\Child%04d\\Pet", i
);
109 Status
= CreateRegistryKeyHandle(&PetKey
, KEY_READ
, Buffer
);
112 ok_ntstatus(Status
, STATUS_SUCCESS
);
114 /* Test hive rerooting */
115 Status
= CreateRegistryKeyHandle(&PetKey
, DELETE
, L
"\\Registry\\Machine\\Software\\RosTests\\Child5000\\Pet");
116 ok_ntstatus(Status
, STATUS_SUCCESS
);
117 Status
= NtDeleteKey(PetKey
);
118 ok_ntstatus(Status
, STATUS_SUCCESS
);
122 Status
= CreateRegistryKeyHandle(&ChildKey
, DELETE
, L
"\\Registry\\Machine\\Software\\RosTests\\Child5000");
123 ok_ntstatus(Status
, STATUS_SUCCESS
);
124 Status
= NtDeleteKey(ChildKey
);
125 ok_ntstatus(Status
, STATUS_SUCCESS
);
127 /* Test mass key deletion */
128 for (i
= 0; i
<= 9999; i
++) {
130 swprintf(Buffer
, L
"\\Registry\\Machine\\Software\\RosTests\\Child%04d\\Pet", i
);
131 CreateRegistryKeyHandle(&PetKey
, DELETE
, Buffer
);
132 Status
= NtDeleteKey(PetKey
);
135 swprintf(Buffer
, L
"\\Registry\\Machine\\Software\\RosTests\\Child%04d", i
);
136 CreateRegistryKeyHandle(&ChildKey
, DELETE
, Buffer
);
137 Status
= NtDeleteKey(ChildKey
);
141 ok_ntstatus(Status
, STATUS_SUCCESS
);
143 Status
= NtDeleteKey(ParentKey
);
144 ok_ntstatus(Status
, STATUS_SUCCESS
);
146 /* Close ParentKey */