]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
load options when it is null
authorBastian Dehn <hhaalo@arcor.de>
Tue, 9 Apr 2024 17:20:22 +0000 (19:20 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 9 Apr 2024 17:20:22 +0000 (19:20 +0200)
src/kds_s2000w_handler.c
src/kds_s2000w_handler.h
src/kds_s2000w_handler_opts.c
tests/kds_s2000w_net_get_opt_tests.c

index 518dfc413c9ac9e187ebfea366fb7ed610a71656..0604070883f59d00a04a1cf98d749df88271eb41 100644 (file)
@@ -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;
index aba0ca5a3c37e4e6fef4fe50ca452b0c0aad9ad4..6a5cf80135e85e516548bedc78938a05a967835f 100644 (file)
@@ -31,6 +31,7 @@ typedef struct {
 } metadata;
 
 typedef struct {
+       int load_options;
        int current_image_number;
        int available_images;
        int downloaded_images;
index 44ea05fb2fb328a29fee2080d32112247f1f37da..e07486b7853c1c555133b219ad9fec4c65a2955b 100644 (file)
@@ -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");
 
index f859abb717a59ae034cf80bf27c86ed61fa2718e..fcd7f4580be02706acd6e065fad74cb0aebfef4d 100644 (file)
@@ -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);