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 START_TEST(RegEnumValueW
)
15 DWORD NameLength
, DataLength
;
19 /* Create our Test Key */
20 ErrorCode
= RegCreateKeyW( HKEY_CURRENT_USER
, L
"Software\\ReactOS_apitest", &TestKey
);
21 ok_dec(ErrorCode
, ERROR_SUCCESS
);
23 /* All NULL is invalid */
24 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
25 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
27 /* Asking for the buffer length is not enough. */
29 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
30 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
32 /* Or maybe it is, you just have to nicely ask */
34 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
35 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
37 /* Name buffer alone is also prohibited */
38 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, NULL
, NULL
, NULL
, NULL
, NULL
);
39 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
41 /* You need to ask for both a minima */
42 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
43 ok_dec(ErrorCode
, ERROR_NO_MORE_ITEMS
);
45 /* What if I only want to know the value type ? */
46 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, NULL
, &DataType
, NULL
, NULL
, NULL
);
47 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
51 ErrorCode
= RegSetValueExW(TestKey
, L
"Value1", 0, REG_BINARY
, (LPBYTE
)&Data
, sizeof(Data
));
52 ok_dec(ErrorCode
, ERROR_SUCCESS
);
54 /* Try various combinations of Arguments */
56 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
57 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
58 /* Provide a buffer this time */
59 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
60 ok_dec(ErrorCode
, ERROR_SUCCESS
);
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
);
67 /* See if skipping the NULL value is a problem */
69 memset(NameBuffer
, 0xBA, sizeof(NameBuffer
));
70 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
71 ok_dec(ErrorCode
, ERROR_MORE_DATA
);
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);
83 /* Of course, anything smaller is an outrage */
85 memset(NameBuffer
, 0xBA, sizeof(NameBuffer
));
86 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, &NameLength
, NULL
, NULL
, NULL
, NULL
);
87 ok_dec(ErrorCode
, ERROR_MORE_DATA
);
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);
99 /* Of course, asking for data without caring for the name would be strange... */
101 ErrorCode
= RegEnumValueW(TestKey
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, &DataLength
);
102 ok_dec(ErrorCode
, ERROR_INVALID_PARAMETER
);
106 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, &NameLength
, NULL
, &DataType
, NULL
, &DataLength
);
107 ok_dec(ErrorCode
, ERROR_SUCCESS
);
108 ok_dec(DataLength
, sizeof(Data
));
109 ok_hex(DataType
, REG_BINARY
);
111 /* Same, but this time with NULL data buffer and non-zero data size */
114 DataType
= 0x01234567;
115 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, &NameLength
, NULL
, &DataType
, NULL
, &DataLength
);
116 ok_dec(ErrorCode
, ERROR_SUCCESS
);
117 ok_dec(DataLength
, sizeof(Data
));
118 ok_hex(DataType
, REG_BINARY
);
120 /* Same, but this time with data buffer and shrunk data size */
123 DataType
= 0x01234567;
125 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, &NameLength
, NULL
, &DataType
, (LPBYTE
)&Data
, &DataLength
);
126 ok_dec(ErrorCode
, ERROR_MORE_DATA
);
127 ok_dec(DataLength
, sizeof(Data
));
129 ok_hex(DataType
, REG_BINARY
);
131 /* Put the right parameters */
132 DataLength
= sizeof(Data
);
135 DataType
= 0x01234567;
136 ErrorCode
= RegEnumValueW(TestKey
, 0, NameBuffer
, &NameLength
, NULL
, &DataType
, (LPBYTE
)&Data
, &DataLength
);
137 ok_dec(ErrorCode
, ERROR_SUCCESS
);
138 ok_dec(DataLength
, sizeof(Data
));
139 ok_hex(Data
, 0xF00DF00D);
140 ok_hex(DataType
, REG_BINARY
);
143 ErrorCode
= RegDeleteKeyW(TestKey
, L
"");
144 ok_dec(ErrorCode
, ERROR_SUCCESS
);
145 RegCloseKey(TestKey
);