4void test_output_reg_command_dword(
void **state) {
5 expect_memory(__wrap_write_output,
7 L
"reg add \"HKEY_CLASSES_ROOT\\Control Panel\\Desktop\" /v \"DoubleClickHeight\" "
8 L
"/t REG_DWORD /d 4 /f",
10 will_return(__wrap_write_output,
true);
11 DWORD *test_val = malloc(
sizeof(DWORD));
13 bool ret = do_write_reg_command(
nullptr,
14 L
"HKEY_CLASSES_ROOT\\Control Panel\\Desktop",
16 (
const char *)test_val,
23void test_output_reg_command_qword(
void **state) {
27 L
"reg add \"HKEY_LOCAL_MACHINE\\Control Panel\\Desktop\" /v \"DoubleClickHeight\" "
28 L
"/t REG_QWORD /d 4 /f",
30 will_return(__wrap_write_output,
true);
31 QWORD *test_val = malloc(
sizeof(QWORD));
33 bool ret = do_write_reg_command(
nullptr,
34 L
"HKEY_LOCAL_MACHINE\\Control Panel\\Desktop",
36 (
const char *)test_val,
43void test_output_reg_command_sz(
void **state) {
44 expect_memory(__wrap_write_output,
46 L
"reg add \"HKEY_CURRENT_CONFIG\\Environment\" /v \"TEMP\" /t REG_SZ /d "
47 L
"\"\"\"quoted \\string\"\" fff\" /f",
49 will_return(__wrap_write_output,
true);
50 bool ret = do_write_reg_command(
nullptr,
51 L
"HKEY_CURRENT_CONFIG\\Environment",
53 (
const char *)L
"\"quoted \\string\" fff",
59void test_output_reg_command_expand_sz(
void **state) {
60 expect_memory(__wrap_write_output,
62 L
"reg add \"HKEY_CURRENT_USER\\Environment\" /v \"TEMP\" /t REG_EXPAND_SZ /d \"a "
63 L
"midsummer night's %%dream\" /f",
65 will_return(__wrap_write_output,
true);
66 bool ret = do_write_reg_command(
nullptr,
67 L
"HKEY_CURRENT_USER\\Environment",
69 (
const char *)L
"a midsummer night's %dream%",
75const wchar_t *MULTI_SZ_TEST_DATA = L
"\"quoted string\" fff\0test2\0\0";
77void test_output_reg_command_multi_sz(
void **state) {
78 expect_memory(__wrap_write_output,
80 L
"reg add \"HKEY_USERS\\Environment\" /v \"TEMP\" /t REG_MULTI_SZ /d "
81 L
"\"\"\"quoted string\"\" fff\0test2\\0\" /f",
83 will_return(__wrap_write_output,
true);
84 bool ret = do_write_reg_command(
nullptr,
85 L
"HKEY_USERS\\Environment",
87 (
const char *)MULTI_SZ_TEST_DATA,
93#if SIZEOF_WCHAR_T == 4
94const unsigned char MULTI_SZ_TEST_DATA_INVALID[] = {
95 L
'e', 0, 0, 0,
'n', 0, 0, 0,
'-', 0, 0, 0,
'U', 0, 0, 0,
'S'};
97const unsigned char MULTI_SZ_TEST_DATA_INVALID[] = {L
'e', 0,
'n', 0,
'-', 0,
'U', 0,
'S'};
100void test_output_reg_command_multi_sz_invalid(
void **state) {
101 bool ret = do_write_reg_command(
nullptr,
102 L
"HKEY_USERS\\Environment",
104 (
const char *)MULTI_SZ_TEST_DATA_INVALID,
105 sizeof(MULTI_SZ_TEST_DATA_INVALID),
110void test_output_reg_command_invalid_type(
void **state) {
111 bool ret = do_write_reg_command(
nullptr,
112 L
"HKEY_USERS\\Environment",
114 (
const char *)MULTI_SZ_TEST_DATA,
115 25 *
sizeof(
wchar_t),
118 assert_int_equal(errno, EINVAL);
121void test_output_reg_command_none(
void **state) {
122 expect_memory(__wrap_write_output,
124 L
"reg add \"HKEY_CURRENT_USER\\Environment\" /v \"TEMP\" /t REG_NONE /f",
126 will_return(__wrap_write_output,
true);
127 bool ret = do_write_reg_command(
nullptr,
128 L
"HKEY_CURRENT_USER\\Environment",
130 (
const char *)MULTI_SZ_TEST_DATA,
136const unsigned char BINARY_TEST_DATA[] = {0x30, 0, 0x02, 0x80, 0x12, 0, 0, 0};
138void test_output_reg_command_binary(
void **state) {
139 expect_memory(__wrap_write_output,
141 L
"reg add \"HKEY_DYN_DATA\\Control Panel\\Desktop\" /v \"UserPreferencesMask\" "
142 L
"/t REG_BINARY /d 300002ff12000000 /f",
144 will_return(__wrap_write_output,
true);
145 bool ret = do_write_reg_command(
nullptr,
146 L
"HKEY_DYN_DATA\\Control Panel\\Desktop",
147 L
"UserPreferencesMask",
148 (
const char *)BINARY_TEST_DATA,
149 sizeof(BINARY_TEST_DATA),
154void test_output_reg_command_default_key(
void **state) {
155 expect_memory(__wrap_write_output,
157 L
"reg add \"HKEY_DYN_DATA\\Control Panel\\Desktop\" /ve "
158 L
"/t REG_SZ /d \"out\" /f",
160 will_return(__wrap_write_output,
true);
161 wchar_t *data = L
"out";
162 bool ret = do_write_reg_command(
nullptr,
163 L
"HKEY_DYN_DATA\\Control Panel\\Desktop",
170 expect_memory(__wrap_write_output,
172 L
"reg add \"HKEY_DYN_DATA\\Control Panel\\Desktop\" /ve "
173 L
"/t REG_SZ /d \"out\" /f",
175 will_return(__wrap_write_output,
true);
176 ret = do_write_reg_command(
nullptr,
177 L
"HKEY_DYN_DATA\\Control Panel\\Desktop",
184 expect_memory(__wrap_write_output,
186 L
"reg add \"HKEY_DYN_DATA\\Control Panel\\Desktop\" /ve "
187 L
"/t REG_SZ /d \"out\" /f",
189 will_return(__wrap_write_output,
true);
190 ret = do_write_reg_command(
nullptr,
191 L
"HKEY_DYN_DATA\\Control Panel\\Desktop",
199void test_output_reg_command_skip_too_big(
void **state) {
200 wchar_t *buf = calloc(CMD_MAX_COMMAND_LENGTH + 2000,
sizeof(
wchar_t));
201 wmemset(buf, L
'a', CMD_MAX_COMMAND_LENGTH + 2000);
202 bool ret = do_write_reg_command(
nullptr,
203 L
"HKEY_CURRENT_USER\\Control Panel\\Desktop",
204 L
"UserPreferencesMask",
206 CMD_MAX_COMMAND_LENGTH + 2000,
210 assert_int_equal(errno, EKEYREJECTED);
213const struct CMUnitTest output_reg_command_tests[] = {
214 cmocka_unit_test(test_output_reg_command_binary),
215 cmocka_unit_test(test_output_reg_command_default_key),
216 cmocka_unit_test(test_output_reg_command_dword),
217 cmocka_unit_test(test_output_reg_command_expand_sz),
218 cmocka_unit_test(test_output_reg_command_invalid_type),
219 cmocka_unit_test(test_output_reg_command_multi_sz),
221 cmocka_unit_test(test_output_reg_command_multi_sz_invalid),
223 cmocka_unit_test(test_output_reg_command_none),
224 cmocka_unit_test(test_output_reg_command_qword),
225 cmocka_unit_test(test_output_reg_command_skip_too_big),
226 cmocka_unit_test(test_output_reg_command_sz),
229int main(
int argc,
char *argv[]) {
230 return cmocka_run_group_tests(output_reg_command_tests,
nullptr,
nullptr);