4void test_output_c_sharp_null_escaped_reg_key(
void **state) {
5 DWORD *test_val = malloc(
sizeof(DWORD));
7 bool ret = do_write_c_sharp_reg_code(
nullptr,
10 (
const char *)test_val,
17void test_output_c_sharp_dword(
void **state) {
18 expect_memory(__wrap_write_output,
20 L
"Registry.SetValue(\"HKEY_CLASSES_ROOT\\\\Control Panel\\\\Desktop\", "
21 L
"\"DoubleClickHeight\", 4, RegistryValueKind.DWord);",
23 will_return(__wrap_write_output,
true);
24 DWORD *test_val = malloc(
sizeof(DWORD));
26 bool ret = do_write_c_sharp_reg_code(
nullptr,
27 L
"HKEY_CLASSES_ROOT\\Control Panel\\Desktop",
29 (
const char *)test_val,
36void test_output_c_sharp_qword(
void **state) {
37 expect_memory(__wrap_write_output,
39 L
"Registry.SetValue(\"HKEY_LOCAL_MACHINE\\\\Control Panel\\\\Desktop\", "
40 L
"\"DoubleClickHeight\", 4, RegistryValueKind.QWord);",
42 will_return(__wrap_write_output,
true);
43 QWORD *test_val = malloc(
sizeof(QWORD));
45 bool ret = do_write_c_sharp_reg_code(
nullptr,
46 L
"HKEY_LOCAL_MACHINE\\Control Panel\\Desktop",
48 (
const char *)test_val,
55void test_output_c_sharp_sz(
void **state) {
56 expect_memory(__wrap_write_output,
58 L
"Registry.SetValue(\"HKEY_CURRENT_CONFIG\\\\Environment\", \"TEMP\", "
59 L
"\"\\\"quoted \\\\string\\\" fff\");",
61 will_return(__wrap_write_output,
true);
62 bool ret = do_write_c_sharp_reg_code(
nullptr,
63 L
"HKEY_CURRENT_CONFIG\\Environment",
65 (
const char *)L
"\"quoted \\string\" fff",
71void test_output_c_sharp_expand_sz(
void **state) {
72 expect_memory(__wrap_write_output,
74 L
"Registry.SetValue(\"HKEY_CURRENT_USER\\\\Environment\", \"TEMP\", \"a "
75 L
"midsummer night's %dream%\", RegistryValueKind.ExpandString);",
77 will_return(__wrap_write_output,
true);
78 bool ret = do_write_c_sharp_reg_code(
nullptr,
79 L
"HKEY_CURRENT_USER\\Environment",
81 (
const char *)L
"a midsummer night's %dream%",
87const wchar_t *MULTI_SZ_TEST_DATA = L
"\"quoted string\" fff\0test2\0\0";
89void test_output_c_sharp_multi_sz(
void **state) {
90 expect_memory(__wrap_write_output,
92 L
"Registry.SetValue(\"HKEY_USERS\\\\Environment\", \"TEMP\", { \"\\\"quoted "
93 L
"string\\\" fff\", \"test2\" });",
95 will_return(__wrap_write_output,
true);
96 bool ret = do_write_c_sharp_reg_code(
nullptr,
97 L
"HKEY_USERS\\Environment",
99 (
const char *)MULTI_SZ_TEST_DATA,
100 27 *
sizeof(
wchar_t),
105const wchar_t *MULTI_SZ_TEST_DATA_INVALID = L
"\"quoted string\" fff\0test2";
107void test_output_c_sharp_multi_sz_invalid(
void **state) {
108 bool ret = do_write_c_sharp_reg_code(
nullptr,
109 L
"HKEY_USERS\\Environment",
111 (
const char *)MULTI_SZ_TEST_DATA,
112 25 *
sizeof(
wchar_t),
117void test_output_c_sharp_top_key_invalid(
void **state) {
118 bool ret = do_write_c_sharp_reg_code(
nullptr,
119 L
"HKEY_USER_Z\\Environment",
121 (
const char *)MULTI_SZ_TEST_DATA,
122 25 *
sizeof(
wchar_t),
127void test_output_c_sharp_invalid_type(
void **state) {
128 bool ret = do_write_c_sharp_reg_code(
nullptr,
129 L
"HKEY_USERS\\Environment",
131 (
const char *)MULTI_SZ_TEST_DATA,
132 25 *
sizeof(
wchar_t),
135 assert_int_equal(errno, EINVAL);
138void test_output_c_sharp_none(
void **state) {
139 expect_memory(__wrap_write_output,
141 L
"Registry.SetValue(\"HKEY_CURRENT_USER\\\\Environment\", \"TEMP\", (null), "
142 L
"RegistryValueKind.None);",
144 will_return(__wrap_write_output,
true);
145 bool ret = do_write_c_sharp_reg_code(
nullptr,
146 L
"HKEY_CURRENT_USER\\Environment",
148 (
const char *)MULTI_SZ_TEST_DATA,
154const unsigned char BINARY_TEST_DATA[] = {0x30, 0, 0x02, 0x80, 0x12, 0, 0, 0};
156void test_output_c_sharp_binary(
void **state) {
157 expect_memory(__wrap_write_output,
159 L
"Registry.SetValue(\"HKEY_DYN_DATA\\\\Control Panel\\\\Desktop\", "
160 L
"\"UserPreferencesMask\", { 0x30, 0x00, 0x02, 0x80, 0x12, 0x00, 0x00, 0x00 }, "
161 L
"RegistryValueKind.Binary);",
163 will_return(__wrap_write_output,
true);
164 bool ret = do_write_c_sharp_reg_code(
nullptr,
165 L
"HKEY_DYN_DATA\\Control Panel\\Desktop",
166 L
"UserPreferencesMask",
167 (
const char *)BINARY_TEST_DATA,
168 sizeof(BINARY_TEST_DATA),
173const struct CMUnitTest output_c_sharp_tests[] = {
174 cmocka_unit_test(test_output_c_sharp_binary),
175 cmocka_unit_test(test_output_c_sharp_dword),
176 cmocka_unit_test(test_output_c_sharp_expand_sz),
177 cmocka_unit_test(test_output_c_sharp_multi_sz),
178 cmocka_unit_test(test_output_c_sharp_multi_sz_invalid),
179 cmocka_unit_test(test_output_c_sharp_none),
180 cmocka_unit_test(test_output_c_sharp_null_escaped_reg_key),
181 cmocka_unit_test(test_output_c_sharp_qword),
182 cmocka_unit_test(test_output_c_sharp_sz),
183 cmocka_unit_test(test_output_c_sharp_top_key_invalid),
184 cmocka_unit_test(test_output_c_sharp_invalid_type),
187int main(
int argc,
char *argv[]) {
188 return cmocka_run_group_tests(output_c_sharp_tests,
nullptr,
nullptr);