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>
10 #define WIN32_NO_STATUS
13 START_TEST(RegEnumValueW
)
18 DWORD NameLength
, DataLength
;
22 /* Create our Test Key */
23 ErrorCode
= RegCreateKeyW( HKEY_CURRENT_USER
, L
"Software\\ReactOS_apitest", &TestKey
);
24 ok_dec(ErrorCode
, ERROR_SUCCESS
);
26 /* All NULL is invalid */
27 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
28 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
30 /* Asking for the buffer length is not enough. */
32 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
33 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
35 /* Or maybe it is, you just have to nicely ask */
37 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
38 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
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
);
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
);
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
);
54 ErrorCode
= RegSetValueExW(TestKey
, L
"Value1", 0, REG_BINARY
, (LPBYTE
)&Data
, sizeof(Data
));
55 ok_dec(ErrorCode
, ERROR_SUCCESS
);
57 /* Try various combinations of Arguments */
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
);
70 /* See if skipping the NULL value is a problem */
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);
86 /* Of course, anything smaller is an outrage */
88 memset(NameBuffer
, 0xBA, sizeof(NameBuffer
));
89 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
90 ok_dec(ErrorCode
, ERROR_MORE_DATA
);
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);
102 /* Of course, asking for data without caring for the name would be strange... */
104 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, &DataLength
);
105 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
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
);
114 /* Same, but this time with NULL data buffer and non-zero data size */
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
);
123 /* Same, but this time with data buffer and shrunk data size */
126 DataType
= 0x01234567;
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
));
132 ok_hex(DataType
, REG_BINARY
);
134 /* Put the right parameters */
135 DataLength
= sizeof(Data
);
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
);
146 ErrorCode
= RegDeleteKeyW(TestKey
, L
"");
147 ok_dec(ErrorCode
, ERROR_SUCCESS
);
148 RegCloseKey(TestKey
);