3const enum OUTPUT_FORMAT formats[] = {
4 OUTPUT_FORMAT_C, OUTPUT_FORMAT_C_SHARP, OUTPUT_FORMAT_POWERSHELL, OUTPUT_FORMAT_REG};
6void test_export_single_value_invalid_format(
void **state) {
7 will_return(__wrap_RegOpenKeyEx, ERROR_SUCCESS);
8 will_return(__wrap_RegQueryValueEx, ERROR_SUCCESS);
9 will_return(__wrap_GetStdHandle, 0);
10 bool ret = export_single_value(
11 HKEY_CURRENT_USER, L
"HKEY_CURRENT_USER\\A\\B\\C", OUTPUT_FORMAT_UNKNOWN,
nullptr);
13 assert_int_equal(errno, EINVAL);
16void test_export_single_value_formats(
void **state) {
17 will_return_always(__wrap_RegOpenKeyEx, ERROR_SUCCESS);
18 will_return_always(__wrap_RegQueryValueEx, ERROR_SUCCESS);
19 will_return_always(__wrap_GetStdHandle, 0);
20 will_return(__wrap_do_write_reg_command,
true);
21 will_return(__wrap_do_write_c_reg_code,
true);
22 will_return(__wrap_do_write_c_sharp_reg_code,
true);
23 will_return(__wrap_do_write_powershell_reg_code,
true);
25 for (i = 0; i < 4; i++) {
26 bool ret = export_single_value(
27 HKEY_CURRENT_USER, L
"HKEY_CURRENT_USER\\A\\B\\C", formats[i],
nullptr);
32void test_export_single_value_formats_fail(
void **state) {
33 will_return_always(__wrap_RegOpenKeyEx, ERROR_SUCCESS);
34 will_return_always(__wrap_RegQueryValueEx, ERROR_SUCCESS);
35 will_return_always(__wrap_GetStdHandle, 0);
36 will_return(__wrap_do_write_reg_command,
false);
37 will_return(__wrap_do_write_c_reg_code,
false);
38 will_return(__wrap_do_write_c_sharp_reg_code,
false);
39 will_return(__wrap_do_write_powershell_reg_code,
false);
41 for (i = 0; i < 4; i++) {
42 bool ret = export_single_value(
43 HKEY_CURRENT_USER, L
"HKEY_CURRENT_USER\\A\\B\\C", formats[i],
nullptr);
48void test_export_single_value_RegOpenKeyEx_fail(
void **state) {
49 will_return(__wrap_RegOpenKeyEx, ERROR_ACCESS_DENIED);
50 bool ret = export_single_value(
51 HKEY_CURRENT_USER, L
"HKEY_CURRENT_USER\\A\\B\\C", OUTPUT_FORMAT_REG,
nullptr);
55void test_export_single_value_RegQueryValueEx_too_large(
void **state) {
56 will_return(__wrap_RegOpenKeyEx, ERROR_SUCCESS);
57 will_return(__wrap_RegQueryValueEx, ERROR_MORE_DATA);
58 bool ret = export_single_value(
59 HKEY_CURRENT_USER, L
"HKEY_CURRENT_USER\\A\\B\\C", OUTPUT_FORMAT_REG,
nullptr);
63void test_export_single_value_RegQueryValueEx_fail(
void **state) {
64 will_return(__wrap_RegOpenKeyEx, ERROR_SUCCESS);
65 will_return(__wrap_RegQueryValueEx, ERROR_ACCESS_DENIED);
66 bool ret = export_single_value(
67 HKEY_CURRENT_USER, L
"HKEY_CURRENT_USER\\A\\B\\C", OUTPUT_FORMAT_REG,
nullptr);
71void test_export_single_value_no_backslash(
void **state) {
72 bool ret = export_single_value(HKEY_CURRENT_USER, L
"", OUTPUT_FORMAT_REG,
nullptr);
74 assert_int_equal(errno, EINVAL);
77void test_export_single_value_null_reg_path(
void **state) {
78 bool ret = export_single_value(HKEY_CURRENT_USER,
nullptr, OUTPUT_FORMAT_REG,
nullptr);
80 assert_int_equal(errno, EINVAL);
83const struct CMUnitTest export_single_value_tests[] = {
84 cmocka_unit_test(test_export_single_value_RegOpenKeyEx_fail),
85 cmocka_unit_test(test_export_single_value_RegQueryValueEx_fail),
86 cmocka_unit_test(test_export_single_value_RegQueryValueEx_too_large),
87 cmocka_unit_test(test_export_single_value_formats),
88 cmocka_unit_test(test_export_single_value_formats_fail),
89 cmocka_unit_test(test_export_single_value_no_backslash),
90 cmocka_unit_test(test_export_single_value_null_reg_path),
91 cmocka_unit_test(test_export_single_value_invalid_format),
94int main(
int argc,
char *argv[]) {
95 return cmocka_run_group_tests(export_single_value_tests,
nullptr,
nullptr);