4static wchar_t *OUTPUT_DIR = L
"\\c\\users\\name\\AppData\\Roaming\\prefs-export";
6static void test_save_prefs_wfullpath_error(
void **state) {
7 will_return(__wrap__wfullpath, (
void *)0);
8 will_return(__wrap__wfullpath,
false);
10 bool ret = save_preferences(
false,
23static void test_save_prefs_fail_to_create_storage_dir(
void **state) {
24 will_return(__wrap__wfullpath, OUTPUT_DIR);
25 will_return(__wrap__wfullpath,
true);
26 will_return(__wrap_CreateDirectory,
false);
27 will_return(__wrap_GetLastError, 999);
29 bool ret = save_preferences(
false,
42static void test_save_prefs_fail_to_create_storage_dir_alt(
void **state) {
43 will_return(__wrap__wfullpath, OUTPUT_DIR);
44 will_return(__wrap__wfullpath,
true);
45 will_return(__wrap_CreateDirectory,
true);
46 will_return(__wrap_CreateDirectory,
true);
47 will_return(__wrap_CreateDirectory,
true);
48 will_return(__wrap_CreateDirectory,
true);
49 will_return(__wrap_CreateDirectory,
true);
50 will_return(__wrap_CreateDirectory,
true);
51 will_return(__wrap_CreateDirectory,
false);
52 will_return(__wrap_GetLastError, 999);
54 bool ret = save_preferences(
false,
67static void test_save_prefs_CreateFile_returns_invalid_handle(
void **state) {
68 will_return(__wrap__wfullpath, OUTPUT_DIR);
69 will_return(__wrap__wfullpath,
true);
70 will_return(__wrap_PathAppend, L
"exec-reg.bat");
71 will_return(__wrap_PathAppend,
true);
72 will_return_always(__wrap_CreateDirectory,
true);
73 will_return(__wrap_CreateFile, INVALID_HANDLE_VALUE);
75 bool ret = save_preferences(
false,
88void test_save_prefs_GetStdHandle_returns_invalid_handle(
void **state) {
89 will_return(__wrap__wfullpath, OUTPUT_DIR);
90 will_return(__wrap__wfullpath,
true);
91 will_return(__wrap_PathAppend, L
"exec-reg.bat");
92 will_return(__wrap_PathAppend,
true);
93 will_return(__wrap_GetStdHandle, INVALID_HANDLE_VALUE);
95 bool ret = save_preferences(
false,
108void test_save_prefs_c_preamble(
void **state) {
109 will_return(__wrap__wfullpath, OUTPUT_DIR);
110 will_return(__wrap__wfullpath,
true);
111 will_return(__wrap_PathAppend, L
"exec-reg.bat");
112 will_return(__wrap_PathAppend,
true);
113 will_return(__wrap_GetStdHandle, STD_OUTPUT_HANDLE);
114 expect_value(__wrap_WriteFile, nNumberOfBytesToWrite, SIZEOF_C_PREAMBLE);
115 will_return(__wrap_WriteFile, 10);
116 will_return(__wrap_WriteFile,
true);
117 will_return(__wrap_write_key_filtered_recursive,
true);
119 bool ret = save_preferences(
120 false,
nullptr, OUTPUT_DIR, L
"-", 2, HKEY_DYN_DATA, L
"HKDD:\\", OUTPUT_FORMAT_C,
nullptr);
125void test_save_prefs_commit(
void **state) {
126 will_return(__wrap__wfullpath, OUTPUT_DIR);
127 will_return(__wrap__wfullpath,
true);
128 will_return(__wrap_PathAppend, L
"exec-reg.bat");
129 will_return(__wrap_PathAppend,
true);
130 will_return_always(__wrap_CreateDirectory,
true);
131 will_return(__wrap_write_key_filtered_recursive,
true);
132 will_return(__wrap_CreateFile, (HANDLE)1);
133 will_return(__wrap_CloseHandle,
true);
134 will_return(__wrap_git_commit,
true);
136 bool ret = save_preferences(
true,
149const struct CMUnitTest save_prefs_tests[] = {
150 cmocka_unit_test(test_save_prefs_CreateFile_returns_invalid_handle),
151 cmocka_unit_test(test_save_prefs_GetStdHandle_returns_invalid_handle),
152 cmocka_unit_test(test_save_prefs_c_preamble),
153 cmocka_unit_test(test_save_prefs_fail_to_create_storage_dir),
154 cmocka_unit_test(test_save_prefs_fail_to_create_storage_dir_alt),
155 cmocka_unit_test(test_save_prefs_wfullpath_error),
156 cmocka_unit_test(test_save_prefs_commit),
159int main(
int argc,
char *argv[]) {
162 return cmocka_run_group_tests(save_prefs_tests,
nullptr,
nullptr);