From 9ce9e06cf473e47095a43e1c7d48c19cfe54bed4 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Tue, 25 Feb 2025 18:02:03 +0100 Subject: [PATCH] add br y option --- src/kds_s2000w_handler_opts.c | 10 ++++++- src/kds_s2000w_option_descriptors.c | 27 ++++++++++++++++++- tests/kds_s2000w_net_get_opt_tests.c | 17 +++++++++++- tests/kds_s2000w_net_get_opt_tests.h | 1 + tests/kds_s2000w_net_get_opt_tests_run.c | 3 ++- tests/kds_s2000w_option_descriptor_tests.c | 19 ++++++++++++- tests/kds_s2000w_option_descriptor_tests.h | 1 + .../kds_s2000w_option_descriptor_tests_run.c | 1 + 8 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/kds_s2000w_handler_opts.c b/src/kds_s2000w_handler_opts.c index 6d6dcc5..bc19395 100644 --- a/src/kds_s2000w_handler_opts.c +++ b/src/kds_s2000w_handler_opts.c @@ -7,7 +7,7 @@ #include "kds_s2000w_debug.h" #define AUTOSTART_ON 1 -#define OPTION_COUNT 48 +#define OPTION_COUNT 49 #define OFFSET_X_MAX_INCH 75 #define OFFSET_Y_MAX_INCH 390 @@ -528,6 +528,10 @@ void kds_s2000w_handler_opts_get_option(handler* h, uint32_t option, void* value int* br_x = (int*) value; *br_x = _kds_s2000w_handler_opts_inch_to_pixel(config, h->br->x); break; + case 48: + int* br_y = (int*) value; + *br_y = _kds_s2000w_handler_opts_inch_to_pixel(config, h->br->y); + break; default: break; } @@ -767,6 +771,10 @@ void kds_s2000w_handler_opts_set_option(handler* h, uint32_t option, void* value int* br_x = (int*) value; *br_x = _kds_s2000w_handler_opts_pixel_to_inch(config, h->br->x); break; + case 48: + int* br_y = (int*) value; + *br_y = _kds_s2000w_handler_opts_pixel_to_inch(config, h->br->y); + break; default: break; } diff --git a/src/kds_s2000w_option_descriptors.c b/src/kds_s2000w_option_descriptors.c index 57d02e0..2ccb127 100644 --- a/src/kds_s2000w_option_descriptors.c +++ b/src/kds_s2000w_option_descriptors.c @@ -3,7 +3,7 @@ #include "kds_s2000w_option_descriptors.h" #include "kds_s2000w_debug.h" -#define MAX_OPTION_COUNT 48 +#define MAX_OPTION_COUNT 49 SANE_Option_Descriptor* descriptor_array = NULL; @@ -1132,6 +1132,30 @@ SANE_Option_Descriptor _kds_s2000w_option_descriptor_br_x() return descriptor; } +SANE_Option_Descriptor _kds_s2000w_option_descriptor_br_y() +{ + kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_br_y"); + + SANE_Range* constraint = malloc(sizeof(SANE_Range)); + constraint->min = 0; + constraint->max = 7800; + constraint->quant = 20; + + SANE_Option_Descriptor descriptor = { + SANE_NAME_SCAN_BR_Y, + SANE_TITLE_SCAN_BR_Y, + SANE_DESC_SCAN_BR_Y, + SANE_TYPE_INT, + SANE_UNIT_PIXEL, + sizeof(SANE_Int), + SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED, + SANE_CONSTRAINT_RANGE, + {.range = constraint} + }; + + return descriptor; +} + void kds_s2000w_option_descriptors_init() { kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_init_option_descriptors"); @@ -1185,6 +1209,7 @@ void kds_s2000w_option_descriptors_init() descriptor_array[45] = _kds_s2000w_option_descriptor_document_feeder_timeout(); descriptor_array[46] = _kds_s2000w_option_descriptor_document_feeder_timeout_response(); descriptor_array[47] = _kds_s2000w_option_descriptor_br_x(); + descriptor_array[48] = _kds_s2000w_option_descriptor_br_y(); } void kds_s2000w_option_descriptors_free() diff --git a/tests/kds_s2000w_net_get_opt_tests.c b/tests/kds_s2000w_net_get_opt_tests.c index 03cca15..6bd5463 100644 --- a/tests/kds_s2000w_net_get_opt_tests.c +++ b/tests/kds_s2000w_net_get_opt_tests.c @@ -7,7 +7,7 @@ #include "../src/kds_s2000w_net.h" #include "../src/kds_s2000w_handler.h" -#define MAX_OPTION_COUNT 48 +#define MAX_OPTION_COUNT 49 void sane_kds_s2000w_net_control_get_option_zero_test(void** state) { @@ -627,6 +627,21 @@ void sane_kds_s2000w_net_control_get_option_fourtyseven_test(void** state) assert_int_equal(value, 0); + kds_s2000w_handler_free(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_fourtyeight_test(void** state) +{ + handler* h = kds_s2000w_handler_init(); + response* resp = (response*) *state; + h->current_scanner_config = json_tokener_parse(resp->data); + int32_t value; + + sane_kds_s2000w_net_control_option(h, 48, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(value, 0); + kds_s2000w_handler_free(h); h = NULL; } \ No newline at end of file diff --git a/tests/kds_s2000w_net_get_opt_tests.h b/tests/kds_s2000w_net_get_opt_tests.h index d8cd008..700b8c0 100644 --- a/tests/kds_s2000w_net_get_opt_tests.h +++ b/tests/kds_s2000w_net_get_opt_tests.h @@ -47,5 +47,6 @@ void sane_kds_s2000w_net_control_get_option_fourtyfour_test(void** state); void sane_kds_s2000w_net_control_get_option_fourtyfive_test(void** state); void sane_kds_s2000w_net_control_get_option_fourtysix_test(void** state); void sane_kds_s2000w_net_control_get_option_fourtyseven_test(void** state); +void sane_kds_s2000w_net_control_get_option_fourtyeight_test(void** state); #endif \ No newline at end of file diff --git a/tests/kds_s2000w_net_get_opt_tests_run.c b/tests/kds_s2000w_net_get_opt_tests_run.c index b077855..01ea614 100644 --- a/tests/kds_s2000w_net_get_opt_tests_run.c +++ b/tests/kds_s2000w_net_get_opt_tests_run.c @@ -120,7 +120,8 @@ int main() cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtyfour_test, setup_default_get_option, teardown_default_get_option), cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtyfive_test, setup_default_get_option, teardown_default_get_option), cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtysix_test, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtyseven_test, setup_default_get_option, teardown_default_get_option) + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtyseven_test, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourtyeight_test, setup_default_get_option, teardown_default_get_option) }; return cmocka_run_group_tests(net_tests, NULL, NULL); diff --git a/tests/kds_s2000w_option_descriptor_tests.c b/tests/kds_s2000w_option_descriptor_tests.c index 6af316b..36c873a 100644 --- a/tests/kds_s2000w_option_descriptor_tests.c +++ b/tests/kds_s2000w_option_descriptor_tests.c @@ -4,7 +4,7 @@ #include "kds_s2000w_client_mock.h" #include "../src/kds_s2000w_option_descriptors.h" -#define MAX_OPTION_COUNT 48 +#define MAX_OPTION_COUNT 49 int setup(void** state) { @@ -839,6 +839,23 @@ void kds_s2000w_option_get_descriptor_fourtyseven_test() assert_int_equal(option->constraint.range->quant, 20); } +void kds_s2000w_option_get_descriptor_fourtyeight_test() +{ + SANE_Option_Descriptor* option = kds_s2000w_option_descriptors_get(48); + + assert_string_equal(SANE_NAME_SCAN_BR_Y, option->name); + assert_string_equal(SANE_TITLE_SCAN_BR_Y, option->title); + assert_string_equal(SANE_DESC_SCAN_BR_Y, option->desc); + assert_int_equal(SANE_TYPE_INT, option->type); + assert_int_equal(SANE_UNIT_PIXEL, option->unit); + assert_int_equal(sizeof(SANE_Int), option->size); + assert_int_equal(SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED, option->cap); + assert_int_equal(SANE_CONSTRAINT_RANGE, option->constraint_type); + assert_int_equal(option->constraint.range->min, 0); + assert_int_equal(option->constraint.range->max, 7800); + assert_int_equal(option->constraint.range->quant, 20); +} + void kds_s2000w_option_get_descriptor_get_by_name_test() { SANE_Option_Descriptor* option = kds_s2000w_option_descriptors_get_by_name("config-reset"); diff --git a/tests/kds_s2000w_option_descriptor_tests.h b/tests/kds_s2000w_option_descriptor_tests.h index d412f3d..deb2e75 100644 --- a/tests/kds_s2000w_option_descriptor_tests.h +++ b/tests/kds_s2000w_option_descriptor_tests.h @@ -56,6 +56,7 @@ void kds_s2000w_option_get_descriptor_fourtyfour_test(); void kds_s2000w_option_get_descriptor_fourtyfive_test(); void kds_s2000w_option_get_descriptor_fourtysix_test(); void kds_s2000w_option_get_descriptor_fourtyseven_test(); +void kds_s2000w_option_get_descriptor_fourtyeight_test(); void kds_s2000w_option_get_descriptor_get_by_name_test(); void kds_s2000w_option_get_descriptor_over_max_options_test(); #endif \ No newline at end of file diff --git a/tests/kds_s2000w_option_descriptor_tests_run.c b/tests/kds_s2000w_option_descriptor_tests_run.c index 126e943..c1cc9ab 100644 --- a/tests/kds_s2000w_option_descriptor_tests_run.c +++ b/tests/kds_s2000w_option_descriptor_tests_run.c @@ -51,6 +51,7 @@ int main() cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_fourtyfive_test, setup, teardown), cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_fourtysix_test, setup, teardown), cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_fourtyseven_test, setup, teardown), + cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_fourtyeight_test, setup, teardown), cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_get_by_name_test, setup, teardown), cmocka_unit_test_setup_teardown(kds_s2000w_option_get_descriptor_over_max_options_test, setup, teardown), }; -- 2.39.5