4void test_output_c_null_escaped_reg_key(
void **state) {
5 DWORD *test_val = malloc(
sizeof(DWORD));
7 bool ret = do_write_c_reg_code(
nullptr,
10 (
const char *)test_val,
17void test_output_c_dword(
void **state) {
18 expect_memory(__wrap_write_output,
20 L
"dnum = 4; RegSetKeyValue(HKEY_CLASSES_ROOT, TEXT(\"Control Panel\\Desktop\"), "
21 L
"TEXT(\"DoubleClickHeight\"), REG_DWORD, (LPCVOID)&dnum, sizeof(DWORD));",
22 64 *
sizeof(
wchar_t));
23 will_return(__wrap_write_output,
true);
24 DWORD *test_val = malloc(
sizeof(DWORD));
26 bool ret = do_write_c_reg_code(
nullptr,
27 L
"HKEY_CLASSES_ROOT\\Control Panel\\Desktop",
29 (
const char *)test_val,
36void test_output_c_qword(
void **state) {
37 expect_memory(__wrap_write_output,
39 L
"qnum = 4; RegSetKeyValue(HKEY_LOCAL_MACHINE, TEXT(\"Control Panel\\Desktop\"), "
40 L
"TEXT(\"DoubleClickHeight\"), REG_QWORD, (LPCVOID)&qnum, sizeof(QWORD));",
41 64 *
sizeof(
wchar_t));
42 will_return(__wrap_write_output,
true);
43 QWORD *test_val = malloc(
sizeof(QWORD));
45 bool ret = do_write_c_reg_code(
nullptr,
46 L
"HKEY_LOCAL_MACHINE\\Control Panel\\Desktop",
48 (
const char *)test_val,
55void test_output_c_sz(
void **state) {
59 L
"RegSetKeyValue(HKEY_CURRENT_CONFIG, TEXT(\"Environment\"), TEXT(\"TEMP\"), REG_SZ, "
60 L
"TEXT(\"\\\"quoted \\\\string\\\" fff\"), 104);",
61 50 *
sizeof(
wchar_t));
62 will_return(__wrap_write_output,
true);
63 bool ret = do_write_c_reg_code(
nullptr,
64 L
"HKEY_CURRENT_CONFIG\\Environment",
66 (
const char *)L
"\"quoted \\string\" fff",
72void test_output_c_expand_sz(
void **state) {
76 L
"RegSetKeyValue(HKEY_CURRENT_USER, TEXT(\"Environment\"), TEXT(\"TEMP\"), REG_EXPAND_SZ, "
77 L
"TEXT(\"a midsummer night's %dream%\"), 52);",
78 50 *
sizeof(
wchar_t));
79 will_return(__wrap_write_output,
true);
80 bool ret = do_write_c_reg_code(
nullptr,
81 L
"HKEY_CURRENT_USER\\Environment",
83 (
const char *)L
"a midsummer night's %dream%",
89const wchar_t *MULTI_SZ_TEST_DATA = L
"\"quoted string\" fff\0test2\0\0";
91void test_output_c_multi_sz(
void **state) {
92 expect_memory(__wrap_write_output,
94 L
"RegSetKeyValue(HKEY_USERS, TEXT(\"Environment\"), TEXT(\"TEMP\"), "
95 L
"REG_MULTI_SZ, TEXT(\"\\\"quoted string\\\" fff\\0test2\\0\\0\"), 54);",
96 50 *
sizeof(
wchar_t));
97 will_return(__wrap_write_output,
true);
98 bool ret = do_write_c_reg_code(
nullptr,
99 L
"HKEY_USERS\\Environment",
101 (
const char *)MULTI_SZ_TEST_DATA,
102 28 *
sizeof(
wchar_t),
107const wchar_t *MULTI_SZ_TEST_DATA_INVALID = L
"\"quoted string\" fff\0test2";
109void test_output_c_multi_sz_invalid(
void **state) {
110 bool ret = do_write_c_reg_code(
nullptr,
111 L
"HKEY_USERS\\Environment",
113 (
const char *)MULTI_SZ_TEST_DATA,
114 25 *
sizeof(
wchar_t),
119void test_output_c_top_key_invalid(
void **state) {
120 bool ret = do_write_c_reg_code(
nullptr,
121 L
"HKEY_USER_Z\\Environment",
123 (
const char *)MULTI_SZ_TEST_DATA,
124 25 *
sizeof(
wchar_t),
129void test_output_c_invalid_type(
void **state) {
130 bool ret = do_write_c_reg_code(
nullptr,
131 L
"HKEY_USERS\\Environment",
133 (
const char *)MULTI_SZ_TEST_DATA,
134 25 *
sizeof(
wchar_t),
137 assert_int_equal(errno, EINVAL);
140void test_output_c_none(
void **state) {
141 expect_memory(__wrap_write_output,
143 L
"RegSetKeyValue(HKEY_CURRENT_USER, TEXT(\"Environment\"), TEXT(\"TEMP\"), "
144 L
"REG_NONE, NULL, 0);",
145 89 *
sizeof(
wchar_t));
146 will_return(__wrap_write_output,
true);
147 bool ret = do_write_c_reg_code(
nullptr,
148 L
"HKEY_CURRENT_USER\\Environment",
150 (
const char *)MULTI_SZ_TEST_DATA,
156const unsigned char BINARY_TEST_DATA[] = {0x30, 0, 0x02, 0x80, 0x12, 0, 0, 0};
158void test_output_c_binary(
void **state) {
159 expect_memory(__wrap_write_output,
161 L
"data = { 0x30, 0x00, 0x02, 0x80, 0x12, 0x00, 0x00, 0x00 }; "
162 L
"RegSetKeyValue(HKEY_DYN_DATA, TEXT(\"Control Panel\\\\Desktop\"), "
163 L
"TEXT(\"UserPreferencesMask\"), REG_BINARY, (LPCVOID)&data, 8);",
164 182 *
sizeof(
wchar_t));
165 will_return(__wrap_write_output,
true);
166 bool ret = do_write_c_reg_code(
nullptr,
167 L
"HKEY_DYN_DATA\\Control Panel\\Desktop",
168 L
"UserPreferencesMask",
169 (
const char *)BINARY_TEST_DATA,
170 sizeof(BINARY_TEST_DATA),
175const struct CMUnitTest output_c_tests[] = {
176 cmocka_unit_test(test_output_c_binary),
177 cmocka_unit_test(test_output_c_dword),
178 cmocka_unit_test(test_output_c_expand_sz),
179 cmocka_unit_test(test_output_c_multi_sz),
180 cmocka_unit_test(test_output_c_multi_sz_invalid),
181 cmocka_unit_test(test_output_c_none),
182 cmocka_unit_test(test_output_c_null_escaped_reg_key),
183 cmocka_unit_test(test_output_c_qword),
184 cmocka_unit_test(test_output_c_sz),
185 cmocka_unit_test(test_output_c_top_key_invalid),
186 cmocka_unit_test(test_output_c_invalid_type),
189int main(
int argc,
char *argv[]) {
190 return cmocka_run_group_tests(output_c_tests,
nullptr,
nullptr);