ReactOS  0.4.14-dev-552-g2fad488
RegEnumKey.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 the RegEnumKey API
5  * PROGRAMMER: Thomas Faber & Doug Lyons
6  */
7 
8 #include "precomp.h"
9 
11 {
13  HKEY TestKey;
14  HKEY hKey;
15  WCHAR nameBuf[4];
16  DWORD nameLen;
17 
18  /* Base key for our test */
19  ErrorCode = RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS_apitest", 0, NULL, 0, KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS, NULL, &hKey, NULL);
21 
22  /* Create 1 char subkey */
23  ErrorCode = RegCreateKeyExW(hKey, L"1", 0, NULL, 0, READ_CONTROL, NULL, &TestKey, NULL);
25  RegCloseKey(TestKey);
26 
27  /* Enumerate first key with space for 1 char */
28  nameLen = 1;
29  FillMemory(nameBuf, sizeof(nameBuf), 0x55);
30  ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
32  ok_hex(nameBuf[0], 0x5555);
33  ok_hex(nameBuf[1], 0x5555);
34  ok_dec(nameLen, 1);
35 
36  /* Enumerate first key with space for 2 chars */
37  nameLen = 2;
38  FillMemory(nameBuf, sizeof(nameBuf), 0x55);
39  ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
41  ok_hex(nameBuf[0], L'1');
42  ok_hex(nameBuf[1], 0);
43  ok_hex(nameBuf[2], 0x5555);
44  ok_dec(nameLen, 1);
45 
46  /* Delete the subkey */
47  ErrorCode = RegDeleteKeyW(hKey, L"1");
49 
50  /* Create 2 char subkey */
51  ErrorCode = RegCreateKeyExW(hKey, L"12", 0, NULL, 0, READ_CONTROL, NULL, &TestKey, NULL);
53  RegCloseKey(TestKey);
54 
55  /* Enumerate first key with space for 2 chars */
56  FillMemory(nameBuf, sizeof(nameBuf), 0x55);
57  nameLen = 2;
58  ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
60  ok_hex(nameBuf[0], 0x5555);
61  ok_hex(nameBuf[1], 0x5555);
62  ok(nameLen == 2, "nameLen = %ld, expected 2\n", nameLen);
63 
64  /* Enumerate first key with space for 3 chars */
65  FillMemory(nameBuf, sizeof(nameBuf), 0x55);
66  nameLen = 3;
67  ErrorCode = RegEnumKeyExW(hKey, 0, nameBuf, &nameLen, NULL, NULL, NULL, NULL);
69  ok_hex(nameBuf[0], L'1');
70  ok_hex(nameBuf[1], L'2');
71  ok_hex(nameBuf[2], 0);
72  ok_hex(nameBuf[3], 0x5555);
73  ok(nameLen == 2, "nameLen = %ld, expected 2\n", nameLen);
74 
75  /* Delete the subkey */
76  ErrorCode = RegDeleteKeyW(hKey, L"12");
78 
79  /* Delete our parent key */
80  ErrorCode = RegDeleteKeyW(hKey, L"");
82  RegCloseKey(hKey);
83 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1237
#define ok_hex(expression, result)
Definition: atltest.h:94
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define RegEnumKey
Definition: winreg.h:509
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
#define READ_CONTROL
Definition: nt_native.h:58
static const WCHAR L[]
Definition: oid.c:1250
START_TEST(RegEnumKey)
Definition: RegEnumKey.c:10
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ok(value,...)
Definition: atltest.h:57
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
#define ok_dec(expression, result)
Definition: atltest.h:101
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019