ReactOS 0.4.15-dev-7834-g00c4b3d
RegEnumValueW.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 RegGetvalueW API
5 * PROGRAMMER: Jérôme Gardou <jerome.gardou@reactos.org>
6 */
7
8#include "precomp.h"
9
11{
13 HKEY TestKey;
14 ULONG Data;
15 DWORD NameLength, DataLength;
17 WCHAR NameBuffer[7];
18
19 /* Create our Test Key */
20 ErrorCode = RegCreateKeyW( HKEY_CURRENT_USER, L"Software\\ReactOS_apitest", &TestKey );
22
23 /* All NULL is invalid */
24 ErrorCode = RegEnumValueW(TestKey, 0, NULL, NULL, NULL, NULL, NULL, NULL);
26
27 /* Asking for the buffer length is not enough. */
28 NameLength = 8;
29 ErrorCode = RegEnumValueW(TestKey, 0, NULL, &NameLength, NULL, NULL, NULL, NULL);
31
32 /* Or maybe it is, you just have to nicely ask */
33 NameLength = 0;
34 ErrorCode = RegEnumValueW(TestKey, 0, NULL, &NameLength, NULL, NULL, NULL, NULL);
36
37 /* Name buffer alone is also prohibited */
38 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, NULL, NULL, NULL, NULL, NULL);
40
41 /* You need to ask for both a minima */
42 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL);
44
45 /* What if I only want to know the value type ? */
48
49 /* Set a value */
50 Data = 0xF00DF00D;
51 ErrorCode = RegSetValueExW(TestKey, L"Value1", 0, REG_BINARY, (LPBYTE)&Data, sizeof(Data));
53
54 /* Try various combinations of Arguments */
55 NameLength = 7;
56 ErrorCode = RegEnumValueW(TestKey, 0, NULL, &NameLength, NULL, NULL, NULL, NULL);
58 /* Provide a buffer this time */
59 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL);
61 /* This doesn't include the NULL terminator */
62 ok_dec(NameLength, 6);
63 /* But the string is NULL terminated */
64 ok_hex(NameBuffer[6], L'\0');
65 ok(wcscmp(NameBuffer, L"Value1") == 0, "%S\n", NameBuffer);
66
67 /* See if skipping the NULL value is a problem */
68 NameLength = 6;
69 memset(NameBuffer, 0xBA, sizeof(NameBuffer));
70 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL);
72 /* In fact, this is unchanged */
73 ok_dec(NameLength, 6);
74 /* And the string is untouched */
75 ok_hex(NameBuffer[6], 0xBABA);
76 ok_hex(NameBuffer[5], 0xBABA);
77 ok_hex(NameBuffer[4], 0xBABA);
78 ok_hex(NameBuffer[3], 0xBABA);
79 ok_hex(NameBuffer[2], 0xBABA);
80 ok_hex(NameBuffer[1], 0xBABA);
81 ok_hex(NameBuffer[0], 0xBABA);
82
83 /* Of course, anything smaller is an outrage */
84 NameLength = 5;
85 memset(NameBuffer, 0xBA, sizeof(NameBuffer));
86 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, NULL, NULL, NULL);
88 /* Untouched... */
89 ok_dec(NameLength, 5);
90 /* And the string is untouched */
91 ok_hex(NameBuffer[6], 0xBABA);
92 ok_hex(NameBuffer[5], 0xBABA);
93 ok_hex(NameBuffer[4], 0xBABA);
94 ok_hex(NameBuffer[3], 0xBABA);
95 ok_hex(NameBuffer[2], 0xBABA);
96 ok_hex(NameBuffer[1], 0xBABA);
97 ok_hex(NameBuffer[0], 0xBABA);
98
99 /* Of course, asking for data without caring for the name would be strange... */
100 DataLength = 0;
103
104 DataLength = 0;
105 NameLength = 7;
106 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, NULL, &DataLength);
108 ok_dec(DataLength, sizeof(Data));
110
111 /* Same, but this time with NULL data buffer and non-zero data size */
112 DataLength = 2;
113 NameLength = 7;
114 DataType = 0x01234567;
115 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, NULL, &DataLength);
117 ok_dec(DataLength, sizeof(Data));
119
120 /* Same, but this time with data buffer and shrunk data size */
121 DataLength = 2;
122 Data = 0;
123 DataType = 0x01234567;
124 NameLength = 7;
125 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, (LPBYTE)&Data, &DataLength);
127 ok_dec(DataLength, sizeof(Data));
128 ok_hex(Data, 0);
130
131 /* Put the right parameters */
132 DataLength = sizeof(Data);
133 NameLength = 7;
134 Data = 0;
135 DataType = 0x01234567;
136 ErrorCode = RegEnumValueW(TestKey, 0, NameBuffer, &NameLength, NULL, &DataType, (LPBYTE)&Data, &DataLength);
138 ok_dec(DataLength, sizeof(Data));
139 ok_hex(Data, 0xF00DF00D);
141
142 /* Delete the key */
143 ErrorCode = RegDeleteKeyW(TestKey, L"");
145 RegCloseKey(TestKey);
146}
147
#define ok_hex(expression, result)
Definition: atltest.h:94
#define ok(value,...)
Definition: atltest.h:57
#define ok_dec(expression, result)
Definition: atltest.h:101
#define START_TEST(x)
Definition: atltest.h:75
#define RegCloseKey(hKey)
Definition: registry.h:49
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1444
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1239
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1201
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define REG_BINARY
Definition: nt_native.h:1496
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define memset(x, y, z)
Definition: compat.h:39
DataType
Definition: simd.h:252
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define HKEY_CURRENT_USER
Definition: winreg.h:11
__wchar_t WCHAR
Definition: xmlstorage.h:180