From 1cf8b1ec85bd362acc48ebb812b79ca6e43aaf0a Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Tue, 9 Apr 2024 19:20:22 +0200 Subject: [PATCH] load options when it is null --- src/kds_s2000w_handler.c | 2 + src/kds_s2000w_handler.h | 1 + src/kds_s2000w_handler_opts.c | 5 +++ tests/kds_s2000w_net_get_opt_tests.c | 61 +--------------------------- 4 files changed, 9 insertions(+), 60 deletions(-) diff --git a/src/kds_s2000w_handler.c b/src/kds_s2000w_handler.c index 518dfc4..0604070 100644 --- a/src/kds_s2000w_handler.c +++ b/src/kds_s2000w_handler.c @@ -182,6 +182,7 @@ handler* init_handler() h->sessionid = 0; h->state = NOTCONNECTED; + h->current_scan_status->load_options = 0; h->current_scan_status->current_image_number = 1; h->current_scan_status->available_images = 0; h->current_scan_status->downloaded_images = 0; @@ -239,6 +240,7 @@ void reset_handler(handler* h) h->jpg_image->data = NULL; h->state = NOTCONNECTED; + h->current_scan_status->load_options = 0; h->current_scan_status->current_image_number = 1; h->current_scan_status->available_images = 0; h->current_scan_status->downloaded_images = 0; diff --git a/src/kds_s2000w_handler.h b/src/kds_s2000w_handler.h index aba0ca5..6a5cf80 100644 --- a/src/kds_s2000w_handler.h +++ b/src/kds_s2000w_handler.h @@ -31,6 +31,7 @@ typedef struct { } metadata; typedef struct { + int load_options; int current_image_number; int available_images; int downloaded_images; diff --git a/src/kds_s2000w_handler_opts.c b/src/kds_s2000w_handler_opts.c index 44ea05f..e07486b 100644 --- a/src/kds_s2000w_handler_opts.c +++ b/src/kds_s2000w_handler_opts.c @@ -61,6 +61,11 @@ void kds_s2000w_handler_get_option(handler* h, int option, void* value, int* inf { json_object* config = NULL; json_object* value_object = NULL; + if (h->current_scan_status->load_options == 0 && option > 0) { + h->current_scan_status->load_options = 1; + _load_options(h); + } + if (h->current_scanner_config != NULL) config = json_object_object_get(h->current_scanner_config, "Configuration"); diff --git a/tests/kds_s2000w_net_get_opt_tests.c b/tests/kds_s2000w_net_get_opt_tests.c index f859abb..fcd7f45 100644 --- a/tests/kds_s2000w_net_get_opt_tests.c +++ b/tests/kds_s2000w_net_get_opt_tests.c @@ -48,13 +48,10 @@ void sane_kds_s2000w_net_control_get_option_two(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; char value[50] = {0}; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 2, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_string_equal(value, "DocumentFeeder"); free_handler(h); @@ -68,13 +65,10 @@ void sane_kds_s2000w_net_control_get_option_three(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; char value[50] = {0}; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 3, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_string_equal(value, "Color"); free_handler(h); @@ -88,13 +82,10 @@ void sane_kds_s2000w_net_control_get_option_four(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = 0; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 4, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 200); free_handler(h); @@ -108,13 +99,11 @@ void sane_kds_s2000w_net_control_get_option_five(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; + char value[50] = {0}; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 5, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_string_equal(value, "Duplex"); free_handler(h); @@ -128,13 +117,10 @@ void sane_kds_s2000w_net_control_get_option_six(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = 0; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 6, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 8); free_handler(h); @@ -148,13 +134,10 @@ void sane_kds_s2000w_net_control_get_option_eight(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 8, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 0); free_handler(h); @@ -168,13 +151,10 @@ void sane_kds_s2000w_net_control_get_option_nine(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; char value[50] = {0}; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 9, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_string_equal(value, "None"); free_handler(h); @@ -188,13 +168,10 @@ void sane_kds_s2000w_net_control_get_option_ten(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 10, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 0); free_handler(h); @@ -208,13 +185,10 @@ void sane_kds_s2000w_net_control_get_option_eleven(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; char value[50] = {0}; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 11, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_string_equal(value, "Automatic"); free_handler(h); @@ -228,13 +202,10 @@ void sane_kds_s2000w_net_control_get_option_twelve(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; char value[50] = {0}; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 12, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_string_equal(value, "Automatic"); free_handler(h); @@ -248,13 +219,10 @@ void sane_kds_s2000w_net_control_get_option_thirteen(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 13, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 0); free_handler(h); @@ -268,13 +236,10 @@ void sane_kds_s2000w_net_control_get_option_fourteen(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 14, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 0); free_handler(h); @@ -288,13 +253,10 @@ void sane_kds_s2000w_net_control_get_option_fifteen(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 15, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 0); free_handler(h); @@ -308,13 +270,10 @@ void sane_kds_s2000w_net_control_get_option_sixteen(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 16, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 0); free_handler(h); @@ -328,13 +287,10 @@ void sane_kds_s2000w_net_control_get_option_seventeen(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; char value[50] = {0}; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 17, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_string_equal(value, "None"); free_handler(h); @@ -348,13 +304,10 @@ void sane_kds_s2000w_net_control_get_option_eightteen(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 18, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 0); free_handler(h); @@ -368,13 +321,10 @@ void sane_kds_s2000w_net_control_get_option_nineteen(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; char value[50] = {0}; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 19, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_string_equal(value, "None"); free_handler(h); @@ -388,13 +338,10 @@ void sane_kds_s2000w_net_control_get_option_twenty(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 20, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 0); free_handler(h); @@ -408,13 +355,10 @@ void sane_kds_s2000w_net_control_get_option_twentyone(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 21, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 0); free_handler(h); @@ -428,13 +372,10 @@ void sane_kds_s2000w_net_control_get_option_twentytwo(void** state) will_return(__wrap_kds_s2000w_client_get_option, 0); expect_function_call(__wrap_kds_s2000w_client_get_option); handler* h = init_handler(); - int option_num = 0; int value = -1; - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); _sane_kds_s2000w_net_control_option(h, 22, SANE_ACTION_GET_VALUE, &value, NULL); - assert_int_equal(option_num, 24); assert_int_equal(value, 140); free_handler(h); -- 2.39.5