[ADVAPI32_APITEST]
[reactos.git] / rostests / apitests / advapi32 / RegEnumKey.c
1 /*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Test for the RegEnumKey API
5 * PROGRAMMER: Thomas Faber & Doug Lyons
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <winreg.h>
12
13 START_TEST(RegEnumKey)
14 {
15 LONG ErrorCode;
16 HKEY TestKey;
17 HKEY hKey;
18 WCHAR nameBuf[4];
19 DWORD nameLen;
20
21 /* Base key for our test */
22 ErrorCode = RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS_apitest", 0, NULL, 0, KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hKey, NULL);
23 ok_dec(ErrorCode, ERROR_SUCCESS);
24
25 /* Create 1 char subkey */
26 ErrorCode = RegCreateKeyExW(hKey, L"1", 0, NULL, 0, READ_CONTROL, NULL, &TestKey, NULL);
27 ok_dec(ErrorCode, ERROR_SUCCESS);
28 RegCloseKey(TestKey);
29
30 /* Enumerate first key with space for 1 char */
31 nameLen = 1;
32 FillMemory(nameBuf, sizeof(nameBuf), 0x55);
33 ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
34 ok_dec(ErrorCode, ERROR_MORE_DATA);
35 ok_hex(nameBuf[0], 0x5555);
36 ok_hex(nameBuf[1], 0x5555);
37 ok_dec(nameLen, 1);
38
39 /* Enumerate first key with space for 2 chars */
40 nameLen = 2;
41 FillMemory(nameBuf, sizeof(nameBuf), 0x55);
42 ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
43 ok_dec(ErrorCode, ERROR_SUCCESS);
44 ok_hex(nameBuf[0], L'1');
45 ok_hex(nameBuf[1], 0);
46 ok_hex(nameBuf[2], 0x5555);
47 ok_dec(nameLen, 1);
48
49 /* Delete the subkey */
50 ErrorCode = RegDeleteKeyW(hKey, L"1");
51 ok_dec(ErrorCode, ERROR_SUCCESS);
52
53 /* Create 2 char subkey */
54 ErrorCode = RegCreateKeyExW(hKey, L"12", 0, NULL, 0, READ_CONTROL, NULL, &TestKey, NULL);
55 ok_dec(ErrorCode, ERROR_SUCCESS);
56 RegCloseKey(TestKey);
57
58 /* Enumerate first key with space for 2 chars */
59 FillMemory(nameBuf, sizeof(nameBuf), 0x55);
60 nameLen = 2;
61 ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
62 ok_dec(ErrorCode, ERROR_MORE_DATA);
63 ok_hex(nameBuf[0], 0x5555);
64 ok_hex(nameBuf[1], 0x5555);
65 ok(nameLen == 2, "nameLen = %ld, expected 2\n", nameLen);
66
67 /* Enumerate first key with space for 3 chars */
68 FillMemory(nameBuf, sizeof(nameBuf), 0x55);
69 nameLen = 3;
70 ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
71 ok_dec(ErrorCode, ERROR_SUCCESS);
72 ok_hex(nameBuf[0], L'1');
73 ok_hex(nameBuf[1], L'2');
74 ok_hex(nameBuf[2], 0);
75 ok_hex(nameBuf[3], 0x5555);
76 ok(nameLen == 2, "nameLen = %ld, expected 2\n", nameLen);
77
78 /* Delete the subkey */
79 ErrorCode = RegDeleteKeyW(hKey, L"12");
80 ok_dec(ErrorCode, ERROR_SUCCESS);
81
82 /* Delete our parent key */
83 ErrorCode = RegDeleteKeyW(hKey, L"");
84 ok_dec(ErrorCode, ERROR_SUCCESS);
85 RegCloseKey(hKey);
86 }