1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPLv2+ - See COPYING in the top level directory 4 * PURPOSE: Test for the RegGetvalueW API 5 * PROGRAMMER: Jérôme Gardou <jerome.gardou@reactos.org> 6 */ 7 8 #include <apitest.h> 9 10 #define WIN32_NO_STATUS 11 #include <winreg.h> 12 13 START_TEST(RegEnumValueW) 14 { 15 LONG ErrorCode; 16 HKEY TestKey; 17 ULONG Data; 18 DWORD NameLength, DataLength; 19 DWORD DataType; 20 WCHAR NameBuffer[7]; 21 22 /* Create our Test Key */ 23 ErrorCode = RegCreateKeyW( HKEY_CURRENT_USER, L"Software\\ReactOS_apitest", &TestKey ); 24 ok_dec(ErrorCode, ERROR_SUCCESS); 25 26 /* All NULL is invalid */ 27 ErrorCode = RegEnumValueW(TestKey, 0, NULL, NULL, NULL, NULL, NULL, NULL); 28 ok_dec(ErrorCode, ERROR_INVALID_PARAMETER); 29 30 /* Asking for the buffer length is not enough. */ 31 NameLength = 8; 32 ErrorCode = RegEnumValueW(TestKey, 0, NULL, &NameLength, NULL, NULL, NULL, NULL); 33 ok_dec(ErrorCode, ERROR_INVALID_PARAMETER); 34 35 /* Or maybe it is, you just have to nicely ask */ 36 NameLength = 0; 37 ErrorCode = RegEnumValueW(TestKey, 0, NULL, &NameLength, NULL, NULL, NULL, NULL); 38 ok_dec(ErrorCode, ERROR_INVALID_PARAMETER); 39 40 /* Name buffer alone is also prohibited */ 41 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, NULL, NULL, NULL, NULL, NULL); 42 ok_dec(ErrorCode, ERROR_INVALID_PARAMETER); 43 44 /* You need to ask for both a minima */ 45 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL); 46 ok_dec(ErrorCode, ERROR_NO_MORE_ITEMS); 47 48 /* What if I only want to know the value type ? */ 49 ErrorCode = RegEnumValueW(TestKey, 0, NULL, NULL, &DataType, NULL, NULL, NULL); 50 ok_dec(ErrorCode, ERROR_INVALID_PARAMETER); 51 52 /* Set a value */ 53 Data = 0xF00DF00D; 54 ErrorCode = RegSetValueExW(TestKey, L"Value1", 0, REG_BINARY, (LPBYTE)&Data, sizeof(Data)); 55 ok_dec(ErrorCode, ERROR_SUCCESS); 56 57 /* Try various combinations of Arguments */ 58 NameLength = 7; 59 ErrorCode = RegEnumValueW(TestKey, 0, NULL, &NameLength, NULL, NULL, NULL, NULL); 60 ok_dec(ErrorCode, ERROR_INVALID_PARAMETER); 61 /* Provide a buffer this time */ 62 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL); 63 ok_dec(ErrorCode, ERROR_SUCCESS); 64 /* This doesn't include the NULL terminator */ 65 ok_dec(NameLength, 6); 66 /* But the string is NULL terminated */ 67 ok_hex(NameBuffer[6], L'\0'); 68 ok(wcscmp(NameBuffer, L"Value1") == 0, "%S\n", NameBuffer); 69 70 /* See if skipping the NULL value is a problem */ 71 NameLength = 6; 72 memset(NameBuffer, 0xBA, sizeof(NameBuffer)); 73 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL); 74 ok_dec(ErrorCode, ERROR_MORE_DATA); 75 /* In fact, this is unchanged */ 76 ok_dec(NameLength, 6); 77 /* And the string is untouched */ 78 ok_hex(NameBuffer[6], 0xBABA); 79 ok_hex(NameBuffer[5], 0xBABA); 80 ok_hex(NameBuffer[4], 0xBABA); 81 ok_hex(NameBuffer[3], 0xBABA); 82 ok_hex(NameBuffer[2], 0xBABA); 83 ok_hex(NameBuffer[1], 0xBABA); 84 ok_hex(NameBuffer[0], 0xBABA); 85 86 /* Of course, anything smaller is an outrage */ 87 NameLength = 5; 88 memset(NameBuffer, 0xBA, sizeof(NameBuffer)); 89 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL); 90 ok_dec(ErrorCode, ERROR_MORE_DATA); 91 /* Untouched... */ 92 ok_dec(NameLength, 5); 93 /* And the string is untouched */ 94 ok_hex(NameBuffer[6], 0xBABA); 95 ok_hex(NameBuffer[5], 0xBABA); 96 ok_hex(NameBuffer[4], 0xBABA); 97 ok_hex(NameBuffer[3], 0xBABA); 98 ok_hex(NameBuffer[2], 0xBABA); 99 ok_hex(NameBuffer[1], 0xBABA); 100 ok_hex(NameBuffer[0], 0xBABA); 101 102 /* Of course, asking for data without caring for the name would be strange... */ 103 DataLength = 0; 104 ErrorCode = RegEnumValueW(TestKey, 0, NULL, NULL, NULL, NULL, NULL, &DataLength); 105 ok_dec(ErrorCode, ERROR_INVALID_PARAMETER); 106 107 DataLength = 0; 108 NameLength = 7; 109 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, NULL, &DataLength); 110 ok_dec(ErrorCode, ERROR_SUCCESS); 111 ok_dec(DataLength, sizeof(Data)); 112 ok_hex(DataType, REG_BINARY); 113 114 /* Same, but this time with NULL data buffer and non-zero data size */ 115 DataLength = 2; 116 NameLength = 7; 117 DataType = 0x01234567; 118 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, NULL, &DataLength); 119 ok_dec(ErrorCode, ERROR_SUCCESS); 120 ok_dec(DataLength, sizeof(Data)); 121 ok_hex(DataType, REG_BINARY); 122 123 /* Same, but this time with data buffer and shrunk data size */ 124 DataLength = 2; 125 Data = 0; 126 DataType = 0x01234567; 127 NameLength = 7; 128 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, (LPBYTE)&Data, &DataLength); 129 ok_dec(ErrorCode, ERROR_MORE_DATA); 130 ok_dec(DataLength, sizeof(Data)); 131 ok_hex(Data, 0); 132 ok_hex(DataType, REG_BINARY); 133 134 /* Put the right parameters */ 135 DataLength = sizeof(Data); 136 NameLength = 7; 137 Data = 0; 138 DataType = 0x01234567; 139 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, (LPBYTE)&Data, &DataLength); 140 ok_dec(ErrorCode, ERROR_SUCCESS); 141 ok_dec(DataLength, sizeof(Data)); 142 ok_hex(Data, 0xF00DF00D); 143 ok_hex(DataType, REG_BINARY); 144 145 /* Delete the key */ 146 ErrorCode = RegDeleteKeyW(TestKey, L""); 147 ok_dec(ErrorCode, ERROR_SUCCESS); 148 RegCloseKey(TestKey); 149 } 150 151