]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add test for load option zero
authorBastian Dehn <hhaalo@arcor.de>
Tue, 12 Mar 2024 19:50:57 +0000 (20:50 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 12 Mar 2024 19:50:57 +0000 (20:50 +0100)
src/kds_s2000w_client.c
src/kds_s2000w_handler_opts.c
tests/kds_s2000w_net_tests.c

index ef189e1b99fdeeb345476576075fe4fc0cd38a1c..912a671d2cb9a49e50f0a11826457f7f9ea2639e 100644 (file)
@@ -6,6 +6,7 @@
 #include "kds_s2000w_debug.h"
 #include "kds_s2000w_config.h"
 
+#ifndef TEST
 program_config p_config;
 
 void _kds_s2000w_client_load_config()
@@ -56,8 +57,6 @@ void kds_s2000w_client_response_free(response* response)
        if (response == NULL)
                return;
 
-       free(response->data);
-       response->data = NULL;
        free(response);
        response = NULL;
 }
@@ -512,4 +511,5 @@ int kds_s2000w_client_set_option(int64_t sessionid, response* response)
        curl = NULL;
 
        return result;
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file
index 6232f8db1fedadfa70c4fabe0ffed73cb4ddc5a8..cc47e5398eb5fb72a0aaa9fd7efe12e957230a98 100644 (file)
@@ -72,6 +72,7 @@ void kds_s2000w_handler_get_option(handler* h, int option, void* value, int* inf
                        config = json_object_object_get(resp_config, "Configuration");
                        int* int_value_ptr = (int*) value;
                        *int_value_ptr = json_object_object_length(config) + COUNT_CUSTOM_OPTIONS;
+                       debug_printf_int(DEBUG, "option numbers", *int_value_ptr);
                        break;
                case 2:
                        value_object = json_object_object_get(config, "ScanSource");
index 31d61539edb7d820594338e7d8452419f148d7ec..8f1ca3b336be6304a5e0870473ae2526d8f0fdb8 100644 (file)
@@ -1,9 +1,20 @@
+#define TEST
 #include <stdlib.h>
 #include <sane/sane.h>
 #include "kds_s2000w_net_tests.h"
+#include "../src/kds_s2000w_client.h"
 #include "../src/kds_s2000w_net.h"
 #include "../src/kds_s2000w_handler.h"
 
+int kds_s2000w_client_get_option(int64_t sessionid, response* response)
+{
+       response->data = "{\"Configuration\":{\"testproperty\": 0, \"testproperty2\": 0}}";
+       response->code = 200;
+       response->size = sizeof(response->data);
+
+       return 0;
+}
+
 START_TEST(kds_s2000w_net_get_parameters_with_image_data)
 {
        handler* h = init_handler();
@@ -78,6 +89,19 @@ START_TEST(kds_s2000w_net_get_select_fd)
 }
 END_TEST
 
+START_TEST(sane_kds_s2000w_net_control_option_zero)
+{
+       handler* h = init_handler();
+       int value = 0;
+
+       _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &value, NULL);
+
+       ck_assert_int_eq(value, 4);
+       free_handler(h);
+       h = NULL;
+}
+END_TEST
+
 Suite* net_tests()
 {
        Suite* net_tests_suite = suite_create("kds_s2000w_net");
@@ -88,6 +112,7 @@ Suite* net_tests()
        tcase_add_test(net_tests, kds_s2000w_net_get_parameters_with_image_data);
        tcase_add_test(net_tests, kds_s2000w_net_set_io_mode);
        tcase_add_test(net_tests, kds_s2000w_net_get_select_fd);
+       tcase_add_test(net_tests, sane_kds_s2000w_net_control_option_zero);
        suite_add_tcase(net_tests_suite, net_tests);
        return net_tests_suite;
 }
\ No newline at end of file