2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for NtDeleteKey
11 CreateRegistryKeyHandle(PHANDLE KeyHandle
,
12 ACCESS_MASK AccessMask
,
15 UNICODE_STRING KeyName
;
16 OBJECT_ATTRIBUTES Attributes
;
18 RtlInitUnicodeString(&KeyName
, RegistryPath
);
19 InitializeObjectAttributes(&Attributes
,
25 return NtCreateKey(KeyHandle
, AccessMask
, &Attributes
, 0, NULL
, REG_OPTION_VOLATILE
, 0);
28 START_TEST(NtDeleteKey
)
31 HANDLE ParentKey
, ChildKey
, PetKey
;
32 WCHAR Buffer
[sizeof("\\Registry\\Machine\\Software\\RosTests\\Child\\Pet") + 5];
35 /* Create a registry key */
36 Status
= CreateRegistryKeyHandle(&ParentKey
, KEY_READ
| DELETE
, L
"\\Registry\\Machine\\Software\\RosTests");
37 ok_ntstatus(Status
, STATUS_SUCCESS
);
39 /* Create a children registry key */
40 Status
= CreateRegistryKeyHandle(&ChildKey
, KEY_READ
| DELETE
, L
"\\Registry\\Machine\\Software\\RosTests\\Child");
41 ok_ntstatus(Status
, STATUS_SUCCESS
);
43 /* Try deleting the parent one */
44 Status
= NtDeleteKey(ParentKey
);
45 ok_ntstatus(Status
, STATUS_CANNOT_DELETE
);
47 /* See what happens with Child one */
48 Status
= NtDeleteKey(ChildKey
);
49 ok_ntstatus(Status
, STATUS_SUCCESS
);
51 /* Retry with parent one */
52 Status
= NtDeleteKey(ParentKey
);
53 ok_ntstatus(Status
, STATUS_SUCCESS
);
56 Status
= NtDeleteKey(ParentKey
);
57 ok_ntstatus(Status
, STATUS_SUCCESS
);
59 /* Close everything */
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");
66 ok_ntstatus(Status
, STATUS_SUCCESS
);
68 /* Create a children registry key */
69 Status
= CreateRegistryKeyHandle(&ChildKey
, KEY_READ
, L
"\\Registry\\Machine\\Software\\RosTests\\Child");
70 ok_ntstatus(Status
, STATUS_SUCCESS
);
75 /* Try deleting the parent one */
76 Status
= NtDeleteKey(ParentKey
);
77 ok_ntstatus(Status
, STATUS_CANNOT_DELETE
);
79 /* See what happens with Child one */
80 Status
= CreateRegistryKeyHandle(&ChildKey
, DELETE
, L
"\\Registry\\Machine\\Software\\RosTests\\Child");
81 ok_ntstatus(Status
, STATUS_SUCCESS
);
82 Status
= NtDeleteKey(ChildKey
);
83 ok_ntstatus(Status
, STATUS_SUCCESS
);
85 /* Retry with parent one */
86 Status
= NtDeleteKey(ParentKey
);
87 ok_ntstatus(Status
, STATUS_SUCCESS
);
89 /* Close everything */
93 /* Stress test key creation */
94 Status
= CreateRegistryKeyHandle(&ParentKey
, KEY_READ
| DELETE
, L
"\\Registry\\Machine\\Software\\RosTests");
96 for (i
= 0; i
<= 9999; i
++) {
97 swprintf(Buffer
, L
"\\Registry\\Machine\\Software\\RosTests\\Child%04d", i
);
98 Status
= CreateRegistryKeyHandle(&ChildKey
, KEY_READ
, Buffer
);
101 swprintf(Buffer
, L
"\\Registry\\Machine\\Software\\RosTests\\Child%04d\\Pet", i
);
102 Status
= CreateRegistryKeyHandle(&PetKey
, KEY_READ
, Buffer
);
105 ok_ntstatus(Status
, STATUS_SUCCESS
);
107 /* Test hive rerooting */
108 Status
= CreateRegistryKeyHandle(&PetKey
, DELETE
, L
"\\Registry\\Machine\\Software\\RosTests\\Child5000\\Pet");
109 ok_ntstatus(Status
, STATUS_SUCCESS
);
110 Status
= NtDeleteKey(PetKey
);
111 ok_ntstatus(Status
, STATUS_SUCCESS
);
115 Status
= CreateRegistryKeyHandle(&ChildKey
, DELETE
, L
"\\Registry\\Machine\\Software\\RosTests\\Child5000");
116 ok_ntstatus(Status
, STATUS_SUCCESS
);
117 Status
= NtDeleteKey(ChildKey
);
118 ok_ntstatus(Status
, STATUS_SUCCESS
);
120 /* Test mass key deletion */
121 for (i
= 0; i
<= 9999; i
++) {
123 swprintf(Buffer
, L
"\\Registry\\Machine\\Software\\RosTests\\Child%04d\\Pet", i
);
124 CreateRegistryKeyHandle(&PetKey
, DELETE
, Buffer
);
125 Status
= NtDeleteKey(PetKey
);
128 swprintf(Buffer
, L
"\\Registry\\Machine\\Software\\RosTests\\Child%04d", i
);
129 CreateRegistryKeyHandle(&ChildKey
, DELETE
, Buffer
);
130 Status
= NtDeleteKey(ChildKey
);
134 ok_ntstatus(Status
, STATUS_SUCCESS
);
136 Status
= NtDeleteKey(ParentKey
);
137 ok_ntstatus(Status
, STATUS_SUCCESS
);
139 /* Close ParentKey */