winprefs v0.3.2
A registry exporter for programmers.
Loading...
Searching...
No Matches
test_output_c_sharp.c
1#include "constants.h"
2#include "reg_code.h"
3
4void test_output_c_sharp_null_escaped_reg_key(void **state) {
5 DWORD *test_val = malloc(sizeof(DWORD));
6 test_val[0] = 4;
7 bool ret = do_write_c_sharp_reg_code(nullptr,
8 L"HKEY_CURRENT_USER", // invalid argument
9 L"DoubleClickHeight",
10 (const char *)test_val,
11 sizeof(DWORD),
12 REG_DWORD);
13 assert_false(ret);
14 free(test_val);
15}
16
17void test_output_c_sharp_dword(void **state) {
18 expect_memory(__wrap_write_output,
19 out,
20 L"Registry.SetValue(\"HKEY_CLASSES_ROOT\\\\Control Panel\\\\Desktop\", "
21 L"\"DoubleClickHeight\", 4, RegistryValueKind.DWord);",
22 120);
23 will_return(__wrap_write_output, true);
24 DWORD *test_val = malloc(sizeof(DWORD));
25 test_val[0] = 4;
26 bool ret = do_write_c_sharp_reg_code(nullptr,
27 L"HKEY_CLASSES_ROOT\\Control Panel\\Desktop",
28 L"DoubleClickHeight",
29 (const char *)test_val,
30 sizeof(DWORD),
31 REG_DWORD);
32 assert_true(ret);
33 free(test_val);
34}
35
36void test_output_c_sharp_qword(void **state) {
37 expect_memory(__wrap_write_output,
38 out,
39 L"Registry.SetValue(\"HKEY_LOCAL_MACHINE\\\\Control Panel\\\\Desktop\", "
40 L"\"DoubleClickHeight\", 4, RegistryValueKind.QWord);",
41 122);
42 will_return(__wrap_write_output, true);
43 QWORD *test_val = malloc(sizeof(QWORD));
44 test_val[0] = 4;
45 bool ret = do_write_c_sharp_reg_code(nullptr,
46 L"HKEY_LOCAL_MACHINE\\Control Panel\\Desktop",
47 L"DoubleClickHeight",
48 (const char *)test_val,
49 sizeof(QWORD),
50 REG_QWORD);
51 assert_true(ret);
52 free(test_val);
53}
54
55void test_output_c_sharp_sz(void **state) {
56 expect_memory(__wrap_write_output,
57 out,
58 L"Registry.SetValue(\"HKEY_CURRENT_CONFIG\\\\Environment\", \"TEMP\", "
59 L"\"\\\"quoted \\\\string\\\" fff\");",
60 103);
61 will_return(__wrap_write_output, true);
62 bool ret = do_write_c_sharp_reg_code(nullptr,
63 L"HKEY_CURRENT_CONFIG\\Environment",
64 L"TEMP",
65 (const char *)L"\"quoted \\string\" fff",
66 26 * sizeof(wchar_t),
67 REG_SZ);
68 assert_true(ret);
69}
70
71void test_output_c_sharp_expand_sz(void **state) {
72 expect_memory(__wrap_write_output,
73 out,
74 L"Registry.SetValue(\"HKEY_CURRENT_USER\\\\Environment\", \"TEMP\", \"a "
75 L"midsummer night's %dream%\", RegistryValueKind.ExpandString);",
76 131);
77 will_return(__wrap_write_output, true);
78 bool ret = do_write_c_sharp_reg_code(nullptr,
79 L"HKEY_CURRENT_USER\\Environment",
80 L"TEMP",
81 (const char *)L"a midsummer night's %dream%",
82 26 * sizeof(wchar_t),
83 REG_EXPAND_SZ);
84 assert_true(ret);
85}
86
87const wchar_t *MULTI_SZ_TEST_DATA = L"\"quoted string\" fff\0test2\0\0";
88
89void test_output_c_sharp_multi_sz(void **state) {
90 expect_memory(__wrap_write_output,
91 out,
92 L"Registry.SetValue(\"HKEY_USERS\\\\Environment\", \"TEMP\", { \"\\\"quoted "
93 L"string\\\" fff\", \"test2\" });",
94 106);
95 will_return(__wrap_write_output, true);
96 bool ret = do_write_c_sharp_reg_code(nullptr,
97 L"HKEY_USERS\\Environment",
98 L"TEMP",
99 (const char *)MULTI_SZ_TEST_DATA,
100 27 * sizeof(wchar_t),
101 REG_MULTI_SZ);
102 assert_true(ret);
103}
104
105const wchar_t *MULTI_SZ_TEST_DATA_INVALID = L"\"quoted string\" fff\0test2";
106
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",
110 L"TEMP",
111 (const char *)MULTI_SZ_TEST_DATA,
112 25 * sizeof(wchar_t),
113 REG_MULTI_SZ);
114 assert_true(ret);
115}
116
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",
120 L"TEMP",
121 (const char *)MULTI_SZ_TEST_DATA,
122 25 * sizeof(wchar_t),
123 REG_MULTI_SZ);
124 assert_false(ret);
125}
126
127void test_output_c_sharp_invalid_type(void **state) {
128 bool ret = do_write_c_sharp_reg_code(nullptr,
129 L"HKEY_USERS\\Environment",
130 L"TEMP",
131 (const char *)MULTI_SZ_TEST_DATA,
132 25 * sizeof(wchar_t),
133 10240);
134 assert_true(ret);
135 assert_int_equal(errno, EINVAL);
136}
137
138void test_output_c_sharp_none(void **state) {
139 expect_memory(__wrap_write_output,
140 out,
141 L"Registry.SetValue(\"HKEY_CURRENT_USER\\\\Environment\", \"TEMP\", (null), "
142 L"RegistryValueKind.None);",
143 99);
144 will_return(__wrap_write_output, true);
145 bool ret = do_write_c_sharp_reg_code(nullptr,
146 L"HKEY_CURRENT_USER\\Environment",
147 L"TEMP",
148 (const char *)MULTI_SZ_TEST_DATA,
149 0,
150 REG_NONE);
151 assert_true(ret);
152}
153
154const unsigned char BINARY_TEST_DATA[] = {0x30, 0, 0x02, 0x80, 0x12, 0, 0, 0};
155
156void test_output_c_sharp_binary(void **state) {
157 expect_memory(__wrap_write_output,
158 out,
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);",
162 169);
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),
169 REG_BINARY);
170 assert_true(ret);
171}
172
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),
185};
186
187int main(int argc, char *argv[]) {
188 return cmocka_run_group_tests(output_c_sharp_tests, nullptr, nullptr);
189}