]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add width height set min
authorBastian Dehn <hhaalo@arcor.de>
Sat, 25 Oct 2025 19:23:20 +0000 (21:23 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 25 Oct 2025 19:23:20 +0000 (21:23 +0200)
src/kds_s2000w_handler_opts.c
tests/kds_s2000w_net_set_opt_tests.c

index a511e5b382d9abcc9d503c13a634d20aabe6eafd..ae45aae425a2e69d79cb5ceca39d72a9e790f0cb 100644 (file)
@@ -547,6 +547,13 @@ int32_t kds_s2000w_handler_opts_set_option(handler_t* h, uint32_t option, void*
        option_descriptor_t* descriptor = kds_s2000w_option_descriptors_full_get_by_number(option);
        json_object* value_object = json_object_object_get(config, descriptor->config_name);
 
+       if (strcmp(descriptor->config_name, IMAGE_WIDTH) == 0
+               || strcmp(descriptor->config_name, IMAGE_HEIGHT) == 0) {
+               int32_t* int_value = (int32_t*) value;
+               if (*int_value < descriptor->descriptor->constraint.range->min)
+                       *int_value = descriptor->descriptor->constraint.range->min;
+       }
+
        _kds_s2000w_handler_opts_set_offset_x(descriptor, h, value);
        _kds_s2000w_handler_opts_set_width(descriptor, h, value);
        _kds_s2000w_handler_opts_set_valid_coord_x(descriptor, h);
index 5c807f899f98840a7c01a8fe1c2ea30f43c5cf68..ce18118e929aaffa55cafdde489bf5c1f60ba535 100644 (file)
@@ -256,6 +256,84 @@ void kds_s2000w_net_set_option_int_br_x(void** state)
        set_value = NULL;
 }
 
+void kds_s2000w_net_set_option_int_scanimage_default_br_x(void** state)
+{
+       int32_t* set_value = malloc(sizeof(int32_t));
+       if (set_value == NULL)
+               return;
+
+       *set_value = 0;
+       response_t* resp = (response_t*) *state;
+       handler_t* h = kds_s2000w_handler_init();
+       response_t* set_opt_resp = kds_s2000w_client_response_init();
+       set_opt_resp->code = 200;
+
+       will_return(mock_response, resp);
+       will_return(__wrap_kds_s2000w_client_get_option, 0);
+       will_return(mock_response, set_opt_resp);
+       will_return(__wrap_kds_s2000w_client_set_option, 0);
+       will_return(mock_response, set_opt_resp);
+       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, 11, SANE_ACTION_SET_VALUE, set_value, NULL);
+
+       json_object* config = json_object_object_get(h->scanner_config, "Configuration");
+       json_object* value_object = json_object_object_get(config, IMAGE_WIDTH);
+       int32_t value = json_object_get_int(value_object);
+
+       assert_int_equal(status, SANE_STATUS_GOOD);
+       assert_int_equal(value, 10);
+
+       kds_s2000w_client_response_free(set_opt_resp);
+       set_opt_resp = NULL;
+       kds_s2000w_handler_free(h);
+       h = NULL;
+       free(set_value);
+       set_value = NULL;
+}
+
+void kds_s2000w_net_set_option_int_scanimage_default_br_y(void** state)
+{
+       int32_t* set_value = malloc(sizeof(int32_t));
+       if (set_value == NULL)
+               return;
+
+       *set_value = 0;
+       response_t* resp = (response_t*) *state;
+       handler_t* h = kds_s2000w_handler_init();
+       response_t* set_opt_resp = kds_s2000w_client_response_init();
+       set_opt_resp->code = 200;
+
+       will_return(mock_response, resp);
+       will_return(__wrap_kds_s2000w_client_get_option, 0);
+       will_return(mock_response, set_opt_resp);
+       will_return(__wrap_kds_s2000w_client_set_option, 0);
+       will_return(mock_response, set_opt_resp);
+       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, 12, SANE_ACTION_SET_VALUE, set_value, NULL);
+
+       json_object* config = json_object_object_get(h->scanner_config, "Configuration");
+       json_object* value_object = json_object_object_get(config, IMAGE_WIDTH);
+       int32_t value = json_object_get_int(value_object);
+
+       assert_int_equal(status, SANE_STATUS_GOOD);
+       assert_int_equal(value, 10);
+
+       kds_s2000w_client_response_free(set_opt_resp);
+       set_opt_resp = NULL;
+       kds_s2000w_handler_free(h);
+       h = NULL;
+       free(set_value);
+       set_value = NULL;
+}
+
 void kds_s2000w_net_set_option_int_word_list(void** state)
 {
        int32_t* set_value = malloc(sizeof(int32_t));
@@ -395,6 +473,8 @@ int main()
                cmocka_unit_test_setup_teardown(kds_s2000w_net_set_option_int, setup_default_option, teardown_default_option),
                cmocka_unit_test_setup_teardown(kds_s2000w_net_set_option_reset, setup_default_option, teardown_default_option),
                cmocka_unit_test_setup_teardown(kds_s2000w_net_set_option_int_br_x, setup_default_option, teardown_default_option),
+               cmocka_unit_test_setup_teardown(kds_s2000w_net_set_option_int_scanimage_default_br_x, setup_default_option, teardown_default_option),
+               cmocka_unit_test_setup_teardown(kds_s2000w_net_set_option_int_scanimage_default_br_y, setup_default_option, teardown_default_option),
                cmocka_unit_test_setup_teardown(kds_s2000w_net_set_option_int_word_list, setup_default_option, teardown_default_option),
                cmocka_unit_test_setup_teardown(kds_s2000w_net_set_invalid_option_string, setup_default_option, teardown_default_option),
                cmocka_unit_test_setup_teardown(kds_s2000w_net_set_invalid_option_int, setup_default_option, teardown_default_option),