]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add test for canceled complete
authorBastian Dehn <hhaalo@arcor.de>
Sat, 28 Dec 2024 08:48:26 +0000 (09:48 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 28 Dec 2024 08:48:26 +0000 (09:48 +0100)
src/kds_s2000w_net.c
tests/kds_s2000w_net_tests.c
tests/kds_s2000w_net_tests.h
tests/kds_s2000w_net_tests_run.c

index df81a2d6150e8a5888b820ca6755d0c99ec1166b..efe087a99cd253de1c7c7b239604f0d051aecef4 100644 (file)
@@ -126,6 +126,13 @@ void _sane_kds_s2000w_net_cancel(SANE_Handle handle)
 
        handler* h = (handler*) handle;
 
+       if (h->read_info->cancel > 0) {
+               debug_printf(DEBUG, "scan completed canceled");
+               reset_handler(h);
+               kds_s2000w_handler_recreate_session(h);
+               return;
+       }
+
        kds_s2000w_net_handler_get_current_scan_status(h);
 
        if (h->current_scan_status->complete_scanned > 0) {
@@ -134,9 +141,8 @@ void _sane_kds_s2000w_net_cancel(SANE_Handle handle)
                return;
        }
 
-       if (h->read_info->cancel > 0
-               || h->current_scan_status->available_images <= 0) {
-               debug_printf(DEBUG, "scan completed - cancel or no availible images");
+       if (h->current_scan_status->available_images <= 0) {
+               debug_printf(DEBUG, "scan completed no availible images");
                reset_handler(h);
                kds_s2000w_handler_recreate_session(h);
                return;
index caa47f06e8dbf3f17379b6d13f62534ce99cc274..0407529cb735bf74ce35fbe808de2fed345e2201 100644 (file)
@@ -458,6 +458,39 @@ void sane_kds_s2000w_net_cancel()
        h = NULL;
 }
 
+void sane_kds_s2000w_net_cancel_canceled()
+{
+       response* resp_status = kds_s2000w_client_response_init();
+       resp_status->data = realloc(resp_status->data, 27);
+       const char* status = "{\"SessionId\":\"1251877821\"}";
+       memcpy(resp_status->data, status, 27);
+       resp_status->code = 200;
+       resp_status->size = 27;
+       will_return(mock_response, resp_status);
+       will_return(__wrap_kds_s2000w_client_open_session, 0);
+       response* set_option = kds_s2000w_client_response_init();
+       set_option->code = 200;
+       set_option->size = 0;
+       will_return(mock_response, set_option);
+       will_return(__wrap_kds_s2000w_client_set_option, 0);
+       expect_function_call(__wrap_kds_s2000w_client_close_session);
+       expect_function_call(__wrap_kds_s2000w_client_open_session);
+       expect_function_call(__wrap_kds_s2000w_client_set_option);
+       handler* h = init_handler();
+       h->read_info->cancel = 1;
+
+       _sane_kds_s2000w_net_cancel(h);
+
+       assert_int_equal(h->read_info->cancel, 0);
+
+       kds_s2000w_client_response_free(resp_status);
+       resp_status = NULL;
+       kds_s2000w_client_response_free(set_option);
+       set_option = NULL;
+       free_handler(h);
+       h = NULL;
+}
+
 void sane_kds_s2000w_net_cancel_completed_scan_feeder()
 {
        response* resp_status = kds_s2000w_client_response_init();
@@ -512,11 +545,11 @@ void sane_kds_s2000w_net_cancel_completed_scan_flatbed()
        will_return(mock_response, resp_status);
        will_return(__wrap_kds_s2000w_client_status_session, 0);
        response* resp_session = kds_s2000w_client_response_init();
-       resp_session->data = realloc(resp_session->data, 28);
-       const char* responsedata = "{\"SessionId\":\"1251877821\"}\0";
-       memcpy(resp_session->data, responsedata, 28);
+       resp_session->data = realloc(resp_session->data, 27);
+       const char* responsedata = "{\"SessionId\":\"1251877821\"}";
+       memcpy(resp_session->data, responsedata, 27);
        resp_session->code = 200;
-       resp_session->size = 28;
+       resp_session->size = 27;
        will_return(mock_response, resp_session);
        will_return(__wrap_kds_s2000w_client_open_session, 0);
        response* resp_options = kds_s2000w_client_response_init();
index 9cdbb4bfff6037ccd1e5c5c7a976b31a24d28eed..f4cc6854734ecba40630f284c99353c6d814bff3 100644 (file)
@@ -12,6 +12,7 @@ void kds_s2000w_net_get_devices_only_remote();
 void kds_s2000w_net_set_io_mode();
 void kds_s2000w_net_get_select_fd();
 void sane_kds_s2000w_net_start_cancel();
+void sane_kds_s2000w_net_cancel_canceled();
 void sane_kds_s2000w_net_cancel_completed_scan_flatbed();
 void sane_kds_s2000w_net_start(void** state);
 void sane_kds_s2000w_net_start_one_page_per_flatscan(void** state);
index ef94ceceb59a746cc6736b8f28bb912b768669da..ed082edebd12cade3afba0b31b49d2626d105539 100644 (file)
@@ -69,6 +69,7 @@ int main()
                cmocka_unit_test(kds_s2000w_net_set_io_mode),
                cmocka_unit_test(kds_s2000w_net_get_select_fd),
                cmocka_unit_test(sane_kds_s2000w_net_start_cancel),
+               cmocka_unit_test(sane_kds_s2000w_net_cancel_canceled),
                cmocka_unit_test(sane_kds_s2000w_net_cancel),
                cmocka_unit_test(sane_kds_s2000w_net_cancel_completed_scan_feeder),
                cmocka_unit_test(sane_kds_s2000w_net_cancel_completed_scan_flatbed),