From 85a15b64e12ea7ddcbbde7ab9c2d81aa496cd53c Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Thu, 26 Dec 2024 19:06:33 +0100 Subject: [PATCH] check status for ending scan in cancel method --- src/kds_s2000w_net.c | 2 ++ tests/kds_s2000w_net_tests.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/kds_s2000w_net.c b/src/kds_s2000w_net.c index 1e54a43..e23cd2e 100644 --- a/src/kds_s2000w_net.c +++ b/src/kds_s2000w_net.c @@ -126,6 +126,8 @@ void _sane_kds_s2000w_net_cancel(SANE_Handle handle) handler* h = (handler*) handle; + kds_s2000w_net_handler_get_current_scan_status(h); + if (h->current_scan_status->complete_scanned > 0) { reset_handler(h); return; diff --git a/tests/kds_s2000w_net_tests.c b/tests/kds_s2000w_net_tests.c index a852cee..a8e1e2a 100644 --- a/tests/kds_s2000w_net_tests.c +++ b/tests/kds_s2000w_net_tests.c @@ -326,11 +326,29 @@ void sane_kds_s2000w_net_start_two_pages_per_feeder(void** state) void sane_kds_s2000w_net_cancel() { + response* resp_status = kds_s2000w_client_response_init(); + resp_status->data = realloc(resp_status->data, 205); + const char* status = "{ \ + \"Status\": { \ + \"NumImagesScanned\": 2, \ + \"NumImagesStored\": 2, \ + \"State\": \"Scanning\", \ + \"ErrorNum\": 0, \ + \"LastError\": \"Status: 200 Success\", \ + \"PaperDetected\": \"0\", \ + \"PercentAvailable\": 99 \ + }}\0"; + memcpy(resp_status->data, status, 205); + resp_status->code = 200; + resp_status->size = 205; + will_return(mock_response, resp_status); + will_return(__wrap_kds_s2000w_client_status_session, 0); response* resp = kds_s2000w_client_response_init(); resp->code = 200; resp->size = 0; will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_stop_scan, 0); + expect_function_call(__wrap_kds_s2000w_client_status_session); expect_function_call(__wrap_kds_s2000w_client_stop_scan); handler* h = init_handler(); h->current_scan_status->available_images = 1; @@ -341,6 +359,8 @@ void sane_kds_s2000w_net_cancel() kds_s2000w_client_response_free(resp); resp = NULL; + kds_s2000w_client_response_free(resp_status); + resp_status = NULL; free_handler(h); h = NULL; } -- 2.39.5