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 10 START_TEST(RegEnumKey) 11 { 12 LONG ErrorCode; 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); 20 ok_dec(ErrorCode, ERROR_SUCCESS); 21 22 /* Create 1 char subkey */ 23 ErrorCode = RegCreateKeyExW(hKey, L"1", 0, NULL, 0, READ_CONTROL, NULL, &TestKey, NULL); 24 ok_dec(ErrorCode, ERROR_SUCCESS); 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); 31 ok_dec(ErrorCode, ERROR_MORE_DATA); 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); 40 ok_dec(ErrorCode, ERROR_SUCCESS); 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"); 48 ok_dec(ErrorCode, ERROR_SUCCESS); 49 50 /* Create 2 char subkey */ 51 ErrorCode = RegCreateKeyExW(hKey, L"12", 0, NULL, 0, READ_CONTROL, NULL, &TestKey, NULL); 52 ok_dec(ErrorCode, ERROR_SUCCESS); 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); 59 ok_dec(ErrorCode, ERROR_MORE_DATA); 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); 68 ok_dec(ErrorCode, ERROR_SUCCESS); 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"); 77 ok_dec(ErrorCode, ERROR_SUCCESS); 78 79 /* Delete our parent key */ 80 ErrorCode = RegDeleteKeyW(hKey, L""); 81 ok_dec(ErrorCode, ERROR_SUCCESS); 82 RegCloseKey(hKey); 83 } 84