From f6746421b1da365d6cf446245702d18b3695bfb8 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 18 Feb 2024 11:22:54 +0100 Subject: [PATCH] move cancle to handler --- src/kds_s2000w_net.c | 7 ++++--- tests/kds_s2000w_net_read_tests.c | 18 +++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/kds_s2000w_net.c b/src/kds_s2000w_net.c index ab7754a..6a8456e 100644 --- a/src/kds_s2000w_net.c +++ b/src/kds_s2000w_net.c @@ -116,7 +116,8 @@ SANE_Status _sane_kds_s2000w_net_control_option(SANE_Handle handle, void _sane_kds_s2000w_net_cancel(SANE_Handle handle) { debug_printf(ALL, "sane_kds_s2000w_net_cancel"); - read_info.cancel = 1; + handler* h = (handler*) handle; + h->read_info.cancel = 1; return; } @@ -161,7 +162,7 @@ SANE_Status _sane_kds_s2000w_net_start(SANE_Handle handle) { debug_printf(ALL, "sane_kds_s2000w_net_start"); handler* h = (handler*) handle; - read_info.cancel = 0; + h->read_info.cancel = 0; h->read_info.scan_started = 1; kds_s2000w_handler_start_scan(handle); return SANE_STATUS_GOOD; @@ -172,7 +173,7 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data, { debug_printf(ALL, "sane_kds_s2000w_net_read"); handler* h = (handler*) handle; - if (read_info.cancel) { + if (h->read_info.cancel) { h->read_info.scan_started = 0; *length = 0; kds_s2000w_handler_stop_scan(handle); diff --git a/tests/kds_s2000w_net_read_tests.c b/tests/kds_s2000w_net_read_tests.c index dca71e5..9e823b8 100644 --- a/tests/kds_s2000w_net_read_tests.c +++ b/tests/kds_s2000w_net_read_tests.c @@ -19,10 +19,9 @@ END_TEST START_TEST(sane_kds_s2000w_net_read_cancel_test) { - readinfo* read_info = get_read_info(); handler h; h.read_info.scan_started = 1; - read_info->cancel = 1; + h.read_info.cancel = 1; int* length = malloc(sizeof(int)); *length = 0; @@ -38,7 +37,8 @@ END_TEST START_TEST(sane_kds_s2000w_net_read_all_lines_test) { readinfo* read_info = get_read_info(); - read_info->cancel = 0; + handler h; + h.read_info.cancel = 0; read_info->read_size = 0; char* image = malloc(sizeof(char) * 53); for (int i = 0; i < 3; i++) { @@ -58,7 +58,7 @@ START_TEST(sane_kds_s2000w_net_read_all_lines_test) SANE_Status status = 0; for (int i = 0; i < 6; i++) { - status = _sane_kds_s2000w_net_read(NULL, dataptr, 65535, length); + status = _sane_kds_s2000w_net_read(&h, dataptr, 65535, length); } ck_assert_int_eq(status, SANE_STATUS_EOF); @@ -76,6 +76,8 @@ END_TEST START_TEST(sane_kds_s2000w_net_read_test) { readinfo* read_info = get_read_info(); + handler h; + h.read_info.cancel = 0; read_info->read_size = 0; read_info->current_metadata.format = 0; read_info->current_metadata.lines = 1; @@ -91,7 +93,7 @@ START_TEST(sane_kds_s2000w_net_read_test) char* dataptr = malloc(sizeof(char) * maxlen); SANE_Int* length = malloc(sizeof(SANE_Int)); - _sane_kds_s2000w_net_read(NULL, (void*) dataptr, maxlen, length); + _sane_kds_s2000w_net_read(&h, dataptr, maxlen, length); ck_assert_int_eq(*length, 65536); ck_assert_mem_eq(dataptr, image + 3, 65536); @@ -110,6 +112,8 @@ END_TEST START_TEST(sane_kds_s2000w_net_read_bytes_per_line_bigger_test) { readinfo* read_info = get_read_info(); + handler h; + h.read_info.cancel = 0; read_info->read_size = 0; read_info->current_metadata.format = 0; read_info->current_metadata.lines = 1; @@ -125,8 +129,8 @@ START_TEST(sane_kds_s2000w_net_read_bytes_per_line_bigger_test) char* dataptr = malloc(sizeof(char) * maxlen); SANE_Int* length = malloc(sizeof(SANE_Int)); - _sane_kds_s2000w_net_read(NULL, (void*) dataptr, maxlen, length); - _sane_kds_s2000w_net_read(NULL, (void*) dataptr, maxlen, length); + _sane_kds_s2000w_net_read(&h, dataptr, maxlen, length); + _sane_kds_s2000w_net_read(&h, dataptr, maxlen, length); ck_assert_int_eq(read_info->read_size, 95003); -- 2.39.5