3int wmain(
int argc,
wchar_t *argv[]);
5static void test_main_help(
void **state) {
6 wchar_t **buf = calloc(2,
sizeof(
wchar_t *));
7 buf[0] = calloc(8,
sizeof(
wchar_t));
8 buf[1] = calloc(10,
sizeof(
wchar_t));
9 wmemset(buf[0], L
'\0', 8);
10 wmemset(buf[1], L
'\0', 10);
11 wmemcpy(buf[0], L
"winprefs", 7);
12 wmemcpy(buf[1], L
"--help", 6);
13 int ret =
wmain(2, buf);
18 assert_int_equal(ret, EXIT_SUCCESS);
21static void test_main_invalid_option(
void **state) {
22 wchar_t **buf = calloc(2,
sizeof(
wchar_t *));
23 buf[0] = calloc(8,
sizeof(
wchar_t));
24 buf[1] = calloc(16,
sizeof(
wchar_t));
25 wmemset(buf[0], L
'\0', 8);
26 wmemset(buf[1], L
'\0', 16);
27 wmemcpy(buf[0], L
"winprefs", 7);
28 wmemcpy(buf[1], L
"--invalid-option", 16);
29 int ret =
wmain(2, buf);
34 assert_int_equal(EXIT_FAILURE, ret);
37static void test_main_reg_path_invalid(
void **state) {
38 wchar_t **buf = calloc(3,
sizeof(
wchar_t *));
39 buf[0] = calloc(8,
sizeof(
wchar_t));
40 buf[1] = calloc(8,
sizeof(
wchar_t));
42 wmemset(buf[0], L
'\0', 8);
43 wmemcpy(buf[0], L
"winprefs", 7);
44 wmemset(buf[1], L
'\0', 7);
45 wmemcpy(buf[1], L
"ZZZZ:\\", 7);
46 int ret =
wmain(2, buf);
48 assert_return_code(ret, EXIT_FAILURE);
55static void test_main_reg_path_invalid_alt(
void **state) {
56 wchar_t **buf = calloc(3,
sizeof(
wchar_t *));
57 buf[0] = calloc(8,
sizeof(
wchar_t));
58 buf[1] = calloc(6,
sizeof(
wchar_t));
60 wmemset(buf[0], L
'\0', 8);
61 wmemcpy(buf[0], L
"winprefs", 7);
62 wmemset(buf[1], L
'\0', 6);
63 wmemcpy(buf[1], L
"ZZZZ:", 5);
64 int ret =
wmain(2, buf);
66 assert_return_code(ret, EXIT_FAILURE);
73static void test_main_max_depth_conversion(
void **state) {
74 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
75 wmemset(app_data_folder, L
'\0', 30);
76 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
77 will_return(__wrap_SHGetFolderPath, app_data_folder);
78 will_return(__wrap_SHGetFolderPath, 0);
79 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
80 wmemset(prefs_export_path, L
'\0', 43);
81 wmemcpy(prefs_export_path, app_data_folder, 29);
82 wcsncat(prefs_export_path, L
"prefs-export", 12);
83 will_return(__wrap_PathAppend, prefs_export_path);
84 will_return(__wrap_PathAppend,
true);
86 expect_value(__wrap_save_preferences, max_depth, 50);
87 expect_any(__wrap_save_preferences, commit);
88 expect_any(__wrap_save_preferences, format);
89 expect_any(__wrap_save_preferences, deploy_key);
90 expect_any(__wrap_save_preferences, hk);
91 expect_any(__wrap_save_preferences, output_dir);
92 expect_any(__wrap_save_preferences, output_file);
93 expect_any(__wrap_save_preferences, specified_path);
94 will_return(__wrap_save_preferences,
true);
96 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
97 buf[0] = calloc(8,
sizeof(
wchar_t));
98 buf[1] = calloc(3,
sizeof(
wchar_t));
99 buf[2] = calloc(3,
sizeof(
wchar_t));
101 wmemset(buf[0], L
'\0', 8);
102 wmemcpy(buf[0], L
"winprefs", 7);
103 wmemset(buf[1], L
'\0', 3);
104 wmemcpy(buf[1], L
"-m", 2);
105 wmemset(buf[2], L
'\0', 3);
106 wmemcpy(buf[2], L
"50", 2);
107 int ret =
wmain(3, buf);
109 assert_return_code(ret, EXIT_SUCCESS);
115 free(app_data_folder);
116 free(prefs_export_path);
119static void test_main_commit_arg(
void **state) {
120 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
121 wmemset(app_data_folder, L
'\0', 30);
122 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
123 will_return(__wrap_SHGetFolderPath, app_data_folder);
124 will_return(__wrap_SHGetFolderPath, 0);
125 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
126 wmemset(prefs_export_path, L
'\0', 43);
127 wmemcpy(prefs_export_path, app_data_folder, 29);
128 wcsncat(prefs_export_path, L
"prefs-export", 12);
129 will_return(__wrap_PathAppend, prefs_export_path);
130 will_return(__wrap_PathAppend,
true);
132 expect_any(__wrap_save_preferences, max_depth);
133 expect_value(__wrap_save_preferences, commit,
true);
134 expect_any(__wrap_save_preferences, format);
135 expect_any(__wrap_save_preferences, deploy_key);
136 expect_any(__wrap_save_preferences, hk);
137 expect_any(__wrap_save_preferences, output_dir);
138 expect_any(__wrap_save_preferences, output_file);
139 expect_any(__wrap_save_preferences, specified_path);
140 will_return(__wrap_save_preferences,
true);
142 wchar_t **buf = calloc(3,
sizeof(
wchar_t *));
143 buf[0] = calloc(8,
sizeof(
wchar_t));
144 buf[1] = calloc(3,
sizeof(
wchar_t));
146 wmemset(buf[0], L
'\0', 8);
147 wmemcpy(buf[0], L
"winprefs", 7);
148 wmemset(buf[1], L
'\0', 3);
149 wmemcpy(buf[1], L
"-c", 2);
150 int ret =
wmain(2, buf);
152 assert_return_code(ret, EXIT_SUCCESS);
157 free(app_data_folder);
158 free(prefs_export_path);
161static void test_main_output_dir_arg(
void **state) {
162 expect_any(__wrap_save_preferences, max_depth);
163 expect_any(__wrap_save_preferences, commit);
164 expect_any(__wrap_save_preferences, format);
165 expect_any(__wrap_save_preferences, deploy_key);
166 expect_any(__wrap_save_preferences, hk);
167 expect_any(__wrap_save_preferences, output_file);
168 expect_any(__wrap_save_preferences, specified_path);
169 will_return(__wrap_save_preferences,
true);
171 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
172 buf[0] = calloc(8,
sizeof(
wchar_t));
173 buf[1] = calloc(3,
sizeof(
wchar_t));
174 buf[2] = calloc(7,
sizeof(
wchar_t));
176 wmemset(buf[0], L
'\0', 8);
177 wmemcpy(buf[0], L
"winprefs", 7);
178 wmemset(buf[1], L
'\0', 3);
179 wmemcpy(buf[1], L
"-o", 2);
180 wmemset(buf[2], L
'\0', 7);
181 wmemcpy(buf[2], L
"output", 6);
182 expect_memory(__wrap_save_preferences, output_dir, buf[2], 6 *
sizeof(
wchar_t));
183 int ret =
wmain(3, buf);
185 assert_return_code(ret, EXIT_SUCCESS);
193static void test_main_debug_arg(
void **state) {
194 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
195 wmemset(app_data_folder, L
'\0', 30);
196 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
197 will_return(__wrap_SHGetFolderPath, app_data_folder);
198 will_return(__wrap_SHGetFolderPath, 0);
199 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
200 wmemset(prefs_export_path, L
'\0', 43);
201 wmemcpy(prefs_export_path, app_data_folder, 29);
202 wcsncat(prefs_export_path, L
"prefs-export", 12);
203 will_return(__wrap_PathAppend, prefs_export_path);
204 will_return(__wrap_PathAppend,
true);
206 expect_any(__wrap_save_preferences, max_depth);
207 expect_any(__wrap_save_preferences, commit);
208 expect_any(__wrap_save_preferences, format);
209 expect_any(__wrap_save_preferences, deploy_key);
210 expect_any(__wrap_save_preferences, hk);
211 expect_any(__wrap_save_preferences, output_dir);
212 expect_any(__wrap_save_preferences, output_file);
213 expect_any(__wrap_save_preferences, specified_path);
214 will_return(__wrap_save_preferences,
true);
216 wchar_t **buf = calloc(3,
sizeof(
wchar_t *));
217 buf[0] = calloc(8,
sizeof(
wchar_t));
218 buf[1] = calloc(3,
sizeof(
wchar_t));
220 wmemset(buf[0], L
'\0', 8);
221 wmemcpy(buf[0], L
"winprefs", 7);
222 wmemset(buf[1], L
'\0', 3);
223 wmemcpy(buf[1], L
"-d", 2);
224 debug_print_enabled =
false;
225 int ret =
wmain(2, buf);
227 assert_return_code(ret, EXIT_SUCCESS);
228 assert_true(debug_print_enabled);
229 debug_print_enabled =
false;
234 free(app_data_folder);
235 free(prefs_export_path);
238void test_main_deploy_key_arg(
void **state) {
239 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
240 wmemset(app_data_folder, L
'\0', 30);
241 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
242 will_return(__wrap_SHGetFolderPath, app_data_folder);
243 will_return(__wrap_SHGetFolderPath, 0);
244 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
245 wmemset(prefs_export_path, L
'\0', 43);
246 wmemcpy(prefs_export_path, app_data_folder, 29);
247 wcsncat(prefs_export_path, L
"prefs-export", 12);
248 will_return(__wrap_PathAppend, prefs_export_path);
249 will_return(__wrap_PathAppend,
true);
251 expect_any(__wrap_save_preferences, max_depth);
252 expect_any(__wrap_save_preferences, commit);
253 expect_any(__wrap_save_preferences, format);
254 expect_memory(__wrap_save_preferences, deploy_key, L
"file.key", 8);
255 expect_any(__wrap_save_preferences, hk);
256 expect_any(__wrap_save_preferences, output_dir);
257 expect_any(__wrap_save_preferences, output_file);
258 expect_any(__wrap_save_preferences, specified_path);
259 will_return(__wrap_save_preferences,
true);
261 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
262 buf[0] = calloc(8,
sizeof(
wchar_t));
263 buf[1] = calloc(3,
sizeof(
wchar_t));
264 buf[2] = calloc(9,
sizeof(
wchar_t));
266 wmemset(buf[0], L
'\0', 8);
267 wmemcpy(buf[0], L
"winprefs", 7);
268 wmemset(buf[1], L
'\0', 3);
269 wmemcpy(buf[1], L
"-K", 2);
270 wmemset(buf[2], L
'\0', 9);
271 wmemcpy(buf[2], L
"file.key", 8);
272 int ret =
wmain(3, buf);
274 assert_return_code(ret, EXIT_SUCCESS);
275 debug_print_enabled =
false;
281 free(app_data_folder);
282 free(prefs_export_path);
285void test_main_output_file_arg(
void **state) {
286 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
287 wmemset(app_data_folder, L
'\0', 30);
288 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
289 will_return(__wrap_SHGetFolderPath, app_data_folder);
290 will_return(__wrap_SHGetFolderPath, 0);
291 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
292 wmemset(prefs_export_path, L
'\0', 43);
293 wmemcpy(prefs_export_path, app_data_folder, 29);
294 wcsncat(prefs_export_path, L
"prefs-export", 12);
295 will_return(__wrap_PathAppend, prefs_export_path);
296 will_return(__wrap_PathAppend,
true);
298 expect_any(__wrap_save_preferences, max_depth);
299 expect_any(__wrap_save_preferences, commit);
300 expect_any(__wrap_save_preferences, format);
301 expect_any(__wrap_save_preferences, deploy_key);
302 expect_any(__wrap_save_preferences, hk);
303 expect_any(__wrap_save_preferences, output_dir);
304 expect_memory(__wrap_save_preferences, output_file, L
"exec.reg", 8);
305 expect_any(__wrap_save_preferences, specified_path);
306 will_return(__wrap_save_preferences,
true);
308 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
309 buf[0] = calloc(8,
sizeof(
wchar_t));
310 buf[1] = calloc(3,
sizeof(
wchar_t));
311 buf[2] = calloc(9,
sizeof(
wchar_t));
313 wmemset(buf[0], L
'\0', 8);
314 wmemcpy(buf[0], L
"winprefs", 7);
315 wmemset(buf[1], L
'\0', 3);
316 wmemcpy(buf[1], L
"-f", 2);
317 wmemset(buf[2], L
'\0', 9);
318 wmemcpy(buf[2], L
"exec.reg", 8);
319 int ret =
wmain(3, buf);
321 assert_return_code(ret, EXIT_SUCCESS);
322 debug_print_enabled =
false;
328 free(app_data_folder);
329 free(prefs_export_path);
332static const wchar_t *C_SHARP_FORMAT_NAMES[] = {L
"cs", L
"c#", L
"csharp"};
334static void test_main_format_arg_c_sharp(
void **state) {
335 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
336 wmemset(app_data_folder, L
'\0', 30);
337 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
338 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
339 wmemset(prefs_export_path, L
'\0', 43);
340 wmemcpy(prefs_export_path, app_data_folder, 29);
341 wcsncat(prefs_export_path, L
"prefs-export", 12);
343 expect_any_always(__wrap_save_preferences, max_depth);
344 expect_any_always(__wrap_save_preferences, commit);
345 expect_any_always(__wrap_save_preferences, deploy_key);
346 expect_any_always(__wrap_save_preferences, hk);
347 expect_any_always(__wrap_save_preferences, output_dir);
348 expect_any_always(__wrap_save_preferences, output_file);
349 expect_any_always(__wrap_save_preferences, specified_path);
350 will_return_always(__wrap_save_preferences,
true);
353 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
354 buf[0] = calloc(8,
sizeof(
wchar_t));
355 buf[1] = calloc(3,
sizeof(
wchar_t));
356 buf[2] = calloc(7,
sizeof(
wchar_t));
358 wmemset(buf[0], L
'\0', 8);
359 wmemcpy(buf[0], L
"winprefs", 7);
360 wmemset(buf[1], L
'\0', 3);
361 wmemcpy(buf[1], L
"-F", 2);
362 for (i = 0; i < ARRAY_SIZE(C_SHARP_FORMAT_NAMES); i++) {
363 will_return(__wrap_SHGetFolderPath, app_data_folder);
364 will_return(__wrap_SHGetFolderPath, 0);
365 will_return(__wrap_PathAppend, prefs_export_path);
366 will_return(__wrap_PathAppend,
true);
368 expect_value(__wrap_save_preferences, format, OUTPUT_FORMAT_C_SHARP);
369 wmemset(buf[2], L
'\0', 7);
370 wmemcpy(buf[2], C_SHARP_FORMAT_NAMES[i], wcslen(C_SHARP_FORMAT_NAMES[i]));
371 int ret =
wmain(3, buf);
372 assert_return_code(ret, EXIT_SUCCESS);
379 free(app_data_folder);
380 free(prefs_export_path);
383static void test_main_format_arg_invalid(
void **state) {
384 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
385 buf[0] = calloc(8,
sizeof(
wchar_t));
386 buf[1] = calloc(3,
sizeof(
wchar_t));
387 buf[2] = calloc(8,
sizeof(
wchar_t));
389 wmemset(buf[0], L
'\0', 8);
390 wmemcpy(buf[0], L
"winprefs", 10);
391 wmemset(buf[1], L
'\0', 3);
392 wmemcpy(buf[1], L
"-F", 2);
393 wmemset(buf[2], L
'\0', 8);
394 wmemcpy(buf[2], L
"unknown", 7);
395 int ret =
wmain(3, buf);
396 assert_return_code(ret, EXIT_FAILURE);
403static const wchar_t *FULL_REG_PATH_SUFFIX = L
":\\Software\\Microsoft\\Windows NT\\some value name";
404static const HKEY possible_hkey[] = {HKEY_CLASSES_ROOT,
410static const wchar_t *possible_short_paths[] = {
411 L
"HKCR", L
"HKCC", L
"HKCU", L
"HKDD", L
"HKLM", L
"HKU"};
413static void test_main_format_arg_full_reg_path(
void **state) {
414 will_return_always(__wrap_RegOpenKeyEx, 9999999);
416 expect_value_count(__wrap_export_single_value, format, OUTPUT_FORMAT_REG, -1);
417 will_return_count(__wrap_export_single_value,
true, 3);
418 will_return_count(__wrap_export_single_value,
false, 3);
420 size_t full_reg_path_len = wcslen(FULL_REG_PATH_SUFFIX);
421 wchar_t **buf = calloc(3,
sizeof(
wchar_t *));
422 buf[0] = calloc(9,
sizeof(
wchar_t));
423 buf[1] = calloc(full_reg_path_len + 6,
sizeof(
wchar_t));
425 wmemset(buf[0], L
'\0', 9);
426 wmemcpy(buf[0], L
"winprefs", 8);
429 for (i = 0; i < ARRAY_SIZE(possible_hkey); i++) {
430 expect_value(__wrap_export_single_value, top_key, possible_hkey[i]);
431 wmemset(buf[1], L
'\0', full_reg_path_len + 6);
433 full_reg_path_len + 5,
435 possible_short_paths[i],
436 FULL_REG_PATH_SUFFIX);
437 expect_string(__wrap_export_single_value, reg_path, buf[1]);
438 int ret =
wmain(2, buf);
439 assert_return_code(ret, i > 2 ? EXIT_FAILURE : EXIT_SUCCESS);
447static void test_main_format_arg_reg(
void **state) {
448 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
449 wmemset(app_data_folder, L
'\0', 30);
450 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
451 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
452 wmemset(prefs_export_path, L
'\0', 43);
453 wmemcpy(prefs_export_path, app_data_folder, 29);
454 wcsncat(prefs_export_path, L
"prefs-export", 12);
455 will_return(__wrap_SHGetFolderPath, app_data_folder);
456 will_return(__wrap_SHGetFolderPath, 0);
457 will_return(__wrap_PathAppend, prefs_export_path);
458 will_return(__wrap_PathAppend,
true);
460 expect_any_always(__wrap_save_preferences, max_depth);
461 expect_any_always(__wrap_save_preferences, commit);
462 expect_any_always(__wrap_save_preferences, deploy_key);
463 expect_any_always(__wrap_save_preferences, hk);
464 expect_any_always(__wrap_save_preferences, output_dir);
465 expect_any_always(__wrap_save_preferences, output_file);
466 expect_any_always(__wrap_save_preferences, specified_path);
467 will_return_always(__wrap_save_preferences,
true);
469 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
470 buf[0] = calloc(8,
sizeof(
wchar_t));
471 buf[1] = calloc(3,
sizeof(
wchar_t));
472 buf[2] = calloc(10,
sizeof(
wchar_t));
474 wmemset(buf[0], L
'\0', 8);
475 wmemcpy(buf[0], L
"winprefs", 10);
476 wmemset(buf[1], L
'\0', 3);
477 wmemcpy(buf[1], L
"-F", 2);
479 expect_value(__wrap_save_preferences, format, OUTPUT_FORMAT_REG);
480 wmemset(buf[2], L
'\0', 10);
481 wmemcpy(buf[2], L
"reg", 3);
482 int ret =
wmain(3, buf);
483 assert_return_code(ret, EXIT_SUCCESS);
489 free(app_data_folder);
490 free(prefs_export_path);
493static void test_main_format_arg_default(
void **state) {
494 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
495 wmemset(app_data_folder, L
'\0', 30);
496 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
497 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
498 wmemset(prefs_export_path, L
'\0', 43);
499 wmemcpy(prefs_export_path, app_data_folder, 29);
500 wcsncat(prefs_export_path, L
"prefs-export", 12);
501 will_return(__wrap_SHGetFolderPath, app_data_folder);
502 will_return(__wrap_SHGetFolderPath, 0);
503 will_return(__wrap_PathAppend, prefs_export_path);
504 will_return(__wrap_PathAppend,
true);
506 expect_any_always(__wrap_save_preferences, max_depth);
507 expect_any_always(__wrap_save_preferences, commit);
508 expect_any_always(__wrap_save_preferences, deploy_key);
509 expect_any_always(__wrap_save_preferences, hk);
510 expect_any_always(__wrap_save_preferences, output_dir);
511 expect_any_always(__wrap_save_preferences, output_file);
512 expect_any_always(__wrap_save_preferences, specified_path);
513 will_return_always(__wrap_save_preferences,
true);
515 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
516 buf[0] = calloc(8,
sizeof(
wchar_t));
518 wmemset(buf[0], L
'\0', 8);
519 wmemcpy(buf[0], L
"winprefs", 10);
521 expect_value(__wrap_save_preferences, format, OUTPUT_FORMAT_REG);
522 int ret =
wmain(1, buf);
523 assert_return_code(ret, EXIT_SUCCESS);
527 free(app_data_folder);
528 free(prefs_export_path);
531static void test_main_save_prefs_failed(
void **state) {
532 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
533 wmemset(app_data_folder, L
'\0', 30);
534 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
535 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
536 wmemset(prefs_export_path, L
'\0', 43);
537 wmemcpy(prefs_export_path, app_data_folder, 29);
538 wcsncat(prefs_export_path, L
"prefs-export", 12);
539 will_return(__wrap_SHGetFolderPath, app_data_folder);
540 will_return(__wrap_SHGetFolderPath, 0);
541 will_return(__wrap_PathAppend, prefs_export_path);
542 will_return(__wrap_PathAppend,
true);
544 expect_any_always(__wrap_save_preferences, max_depth);
545 expect_any_always(__wrap_save_preferences, commit);
546 expect_any_always(__wrap_save_preferences, deploy_key);
547 expect_any_always(__wrap_save_preferences, hk);
548 expect_any_always(__wrap_save_preferences, output_dir);
549 expect_any_always(__wrap_save_preferences, output_file);
550 expect_any_always(__wrap_save_preferences, specified_path);
551 will_return_always(__wrap_save_preferences,
false);
553 will_return(__wrap_GetLastError, 0);
554 will_return(__wrap_FormatMessage, 10);
556 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
557 buf[0] = calloc(8,
sizeof(
wchar_t));
559 wmemset(buf[0], L
'\0', 8);
560 wmemcpy(buf[0], L
"winprefs", 10);
562 expect_value(__wrap_save_preferences, format, OUTPUT_FORMAT_REG);
563 int ret =
wmain(1, buf);
564 assert_return_code(ret, EXIT_FAILURE);
568 free(app_data_folder);
569 free(prefs_export_path);
572static const wchar_t *POWERSHELL_FORMAT_NAMES[] = {L
"powershell", L
"ps", L
"ps1"};
574static void test_main_format_arg_powershell(
void **state) {
575 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
576 wmemset(app_data_folder, L
'\0', 30);
577 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
578 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
579 wmemset(prefs_export_path, L
'\0', 43);
580 wmemcpy(prefs_export_path, app_data_folder, 29);
581 wcsncat(prefs_export_path, L
"prefs-export", 12);
583 expect_any_always(__wrap_save_preferences, max_depth);
584 expect_any_always(__wrap_save_preferences, commit);
585 expect_any_always(__wrap_save_preferences, deploy_key);
586 expect_any_always(__wrap_save_preferences, hk);
587 expect_any_always(__wrap_save_preferences, output_dir);
588 expect_any_always(__wrap_save_preferences, output_file);
589 expect_any_always(__wrap_save_preferences, specified_path);
590 will_return_always(__wrap_save_preferences,
true);
593 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
594 buf[0] = calloc(8,
sizeof(
wchar_t));
595 buf[1] = calloc(3,
sizeof(
wchar_t));
596 buf[2] = calloc(11,
sizeof(
wchar_t));
598 wmemset(buf[0], L
'\0', 8);
599 wmemcpy(buf[0], L
"winprefs", 10);
600 wmemset(buf[1], L
'\0', 3);
601 wmemcpy(buf[1], L
"-F", 2);
602 for (i = 0; i < ARRAY_SIZE(POWERSHELL_FORMAT_NAMES); i++) {
603 will_return(__wrap_SHGetFolderPath, app_data_folder);
604 will_return(__wrap_SHGetFolderPath, 0);
605 will_return(__wrap_PathAppend, prefs_export_path);
606 will_return(__wrap_PathAppend,
true);
608 expect_value(__wrap_save_preferences, format, OUTPUT_FORMAT_POWERSHELL);
609 wmemset(buf[2], L
'\0', 11);
610 wmemcpy(buf[2], POWERSHELL_FORMAT_NAMES[i], wcslen(POWERSHELL_FORMAT_NAMES[i]));
611 int ret =
wmain(3, buf);
612 assert_return_code(ret, EXIT_SUCCESS);
619 free(app_data_folder);
620 free(prefs_export_path);
623static const wchar_t *C_FORMAT_NAMES[] = {L
"c", L
"C"};
625static void test_main_format_arg_c(
void **state) {
626 wchar_t *app_data_folder = calloc(30,
sizeof(
wchar_t));
627 wmemset(app_data_folder, L
'\0', 30);
628 wmemcpy(app_data_folder, L
"\\c\\users\\name\\AppData\\Roaming", 29);
629 wchar_t *prefs_export_path = calloc(43,
sizeof(
wchar_t));
630 wmemset(prefs_export_path, L
'\0', 43);
631 wmemcpy(prefs_export_path, app_data_folder, 29);
632 wcsncat(prefs_export_path, L
"prefs-export", 12);
634 expect_any_always(__wrap_save_preferences, max_depth);
635 expect_any_always(__wrap_save_preferences, commit);
636 expect_any_always(__wrap_save_preferences, deploy_key);
637 expect_any_always(__wrap_save_preferences, hk);
638 expect_any_always(__wrap_save_preferences, output_dir);
639 expect_any_always(__wrap_save_preferences, output_file);
640 expect_any_always(__wrap_save_preferences, specified_path);
641 will_return_always(__wrap_save_preferences,
true);
644 wchar_t **buf = calloc(4,
sizeof(
wchar_t *));
645 buf[0] = calloc(8,
sizeof(
wchar_t));
646 buf[1] = calloc(3,
sizeof(
wchar_t));
647 buf[2] = calloc(7,
sizeof(
wchar_t));
649 wmemset(buf[0], L
'\0', 8);
650 wmemcpy(buf[0], L
"winprefs", 7);
651 wmemset(buf[1], L
'\0', 3);
652 wmemcpy(buf[1], L
"-F", 2);
653 for (i = 0; i < ARRAY_SIZE(C_FORMAT_NAMES); i++) {
654 will_return(__wrap_SHGetFolderPath, app_data_folder);
655 will_return(__wrap_SHGetFolderPath, 0);
656 will_return(__wrap_PathAppend, prefs_export_path);
657 will_return(__wrap_PathAppend,
true);
659 expect_value(__wrap_save_preferences, format, OUTPUT_FORMAT_C);
660 wmemset(buf[2], L
'\0', 7);
661 wmemcpy(buf[2], C_FORMAT_NAMES[i], wcslen(C_FORMAT_NAMES[i]));
662 int ret =
wmain(3, buf);
663 assert_return_code(ret, EXIT_SUCCESS);
670 free(app_data_folder);
671 free(prefs_export_path);
674void test_main_top_key_only(
void **state) {
675 expect_any_always(__wrap_save_preferences, max_depth);
676 expect_any_always(__wrap_save_preferences, commit);
677 expect_any_always(__wrap_save_preferences, deploy_key);
678 expect_any_always(__wrap_save_preferences, format);
679 expect_any_always(__wrap_save_preferences, hk);
680 expect_any_always(__wrap_save_preferences, output_dir);
681 expect_any_always(__wrap_save_preferences, output_file);
682 expect_any_always(__wrap_save_preferences, specified_path);
683 will_return_always(__wrap_save_preferences,
true);
685 wchar_t **buf = calloc(5,
sizeof(
wchar_t *));
686 buf[0] = calloc(9,
sizeof(
wchar_t));
687 buf[1] = calloc(3,
sizeof(
wchar_t));
688 buf[2] = calloc(4,
sizeof(
wchar_t));
689 buf[3] = calloc(6,
sizeof(
wchar_t));
691 wmemset(buf[0], L
'\0', 9);
692 wmemcpy(buf[0], L
"winprefs", 8);
693 wmemset(buf[1], L
'\0', 3);
694 wmemcpy(buf[1], L
"-o", 2);
695 wmemset(buf[2], L
'\0', 4);
696 wmemcpy(buf[2], L
"out", 3);
697 wmemset(buf[3], L
'\0', 6);
698 wmemcpy(buf[3], L
"HKCU:", 5);
700 int ret =
wmain(4, buf);
701 assert_return_code(ret, EXIT_SUCCESS);
710void test_main_top_key_only_2(
void **state) {
711 expect_any_always(__wrap_save_preferences, max_depth);
712 expect_any_always(__wrap_save_preferences, commit);
713 expect_any_always(__wrap_save_preferences, deploy_key);
714 expect_any_always(__wrap_save_preferences, format);
715 expect_any_always(__wrap_save_preferences, hk);
716 expect_any_always(__wrap_save_preferences, output_dir);
717 expect_any_always(__wrap_save_preferences, output_file);
718 expect_any_always(__wrap_save_preferences, specified_path);
719 will_return_always(__wrap_save_preferences,
true);
721 wchar_t **buf = calloc(5,
sizeof(
wchar_t *));
722 buf[0] = calloc(9,
sizeof(
wchar_t));
723 buf[1] = calloc(3,
sizeof(
wchar_t));
724 buf[2] = calloc(4,
sizeof(
wchar_t));
725 buf[3] = calloc(7,
sizeof(
wchar_t));
727 wmemset(buf[0], L
'\0', 9);
728 wmemcpy(buf[0], L
"winprefs", 8);
729 wmemset(buf[1], L
'\0', 3);
730 wmemcpy(buf[1], L
"-o", 2);
731 wmemset(buf[2], L
'\0', 4);
732 wmemcpy(buf[2], L
"out", 3);
733 wmemset(buf[3], L
'\0', 6);
734 wmemcpy(buf[3], L
"HKCU:\\", 6);
736 int ret =
wmain(4, buf);
737 assert_return_code(ret, EXIT_SUCCESS);
746const struct CMUnitTest main_tests[] = {
747 cmocka_unit_test(test_main_commit_arg),
748 cmocka_unit_test(test_main_debug_arg),
749 cmocka_unit_test(test_main_deploy_key_arg),
750 cmocka_unit_test(test_main_format_arg_c),
751 cmocka_unit_test(test_main_format_arg_c_sharp),
752 cmocka_unit_test(test_main_format_arg_default),
753 cmocka_unit_test(test_main_format_arg_full_reg_path),
754 cmocka_unit_test(test_main_format_arg_invalid),
755 cmocka_unit_test(test_main_format_arg_powershell),
756 cmocka_unit_test(test_main_format_arg_reg),
757 cmocka_unit_test(test_main_help),
758 cmocka_unit_test(test_main_invalid_option),
759 cmocka_unit_test(test_main_max_depth_conversion),
760 cmocka_unit_test(test_main_output_dir_arg),
761 cmocka_unit_test(test_main_output_file_arg),
762 cmocka_unit_test(test_main_reg_path_invalid),
763 cmocka_unit_test(test_main_reg_path_invalid_alt),
764 cmocka_unit_test(test_main_save_prefs_failed),
765 cmocka_unit_test(test_main_top_key_only),
766 cmocka_unit_test(test_main_top_key_only_2),
769int main(
int argc,
char *argv[]) {
772 return cmocka_run_group_tests(main_tests,
nullptr,
nullptr);
int wmain(int argc, wchar_t *argv[])
Entry point.