]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add test for cropping mode
authorBastian Dehn <hhaalo@arcor.de>
Sun, 26 Oct 2025 09:04:00 +0000 (10:04 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 26 Oct 2025 09:04:00 +0000 (10:04 +0100)
tests/kds_s2000w_net_set_opt_tests.c

index 9b289065387be1a10393c41072f942d81960d9f0..232dbf3b1994be5ef9af2129b6d2c7283a8bfd69 100644 (file)
@@ -517,6 +517,43 @@ void kds_s2000w_net_set_invalid_option_int_word_list_test(void** state)
        set_value = NULL;
 }
 
+void kds_s2000w_net_set_option_cropping_mode_and_deps(void** state)
+{
+       int32_t* info = malloc(sizeof(int32_t));
+       if (info == NULL)
+               return;
+
+       response_t** responses = (response_t**) *state;
+       handler_t* h = kds_s2000w_handler_init();
+       h->profile = PROFILE_FULL;
+       *info = 0;
+
+       will_return(mock_response, responses[0]);
+       will_return(__wrap_kds_s2000w_client_get_option, 0);
+       will_return(mock_response, responses[1]);
+       will_return(__wrap_kds_s2000w_client_set_option, 0);
+       will_return(mock_response, responses[1]);
+       will_return(__wrap_kds_s2000w_client_set_option, 0);
+       expect_function_call(__wrap_kds_s2000w_client_get_option);
+       expect_function_call(__wrap_kds_s2000w_client_set_option);
+       expect_function_call(__wrap_kds_s2000w_client_set_option);
+
+       SANE_Status status = sane_kds_s2000w_net_control_option(h, 7, SANE_ACTION_SET_VALUE, "Automatic", info);
+
+       json_object* config = json_object_object_get(h->scanner_config, "Configuration");
+       json_object* value_object = json_object_object_get(config, CROPPING_MODE);
+       const char* value = json_object_get_string(value_object);
+
+       assert_int_equal(status, SANE_STATUS_GOOD);
+       assert_string_equal(value, "Automatic");
+       assert_int_equal(*info, SANE_INFO_RELOAD_OPTIONS);
+
+       kds_s2000w_handler_free(h);
+       h = NULL;
+       free(info);
+       info = NULL;
+}
+
 int main()
 {
        const struct CMUnitTest net_tests[] = {
@@ -530,7 +567,8 @@ int main()
                cmocka_unit_test_setup_teardown(kds_s2000w_net_set_option_int_word_list_test, setup_default_option, teardown_default_option),
                cmocka_unit_test_setup_teardown(kds_s2000w_net_set_invalid_option_string_test, setup_default_option, teardown_default_option),
                cmocka_unit_test_setup_teardown(kds_s2000w_net_set_invalid_option_int_test, setup_default_option, teardown_default_option),
-               cmocka_unit_test_setup_teardown(kds_s2000w_net_set_invalid_option_int_word_list_test, setup_default_option, teardown_default_option)
+               cmocka_unit_test_setup_teardown(kds_s2000w_net_set_invalid_option_int_word_list_test, setup_default_option, teardown_default_option),
+               cmocka_unit_test_setup_teardown(kds_s2000w_net_set_option_cropping_mode_and_deps, setup_default_option, teardown_default_option)
        };
 
        return cmocka_run_group_tests(net_tests, NULL, NULL);