From: Bastian Dehn Date: Mon, 25 Mar 2024 16:09:10 +0000 (+0100) Subject: add test for one page flat scan X-Git-Tag: v1.0.0^2~51 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=9fbb445993b238dedb0f99de84ce8016593256c6;p=sane-kds-s2000w-net.git add test for one page flat scan --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d58040a..0189258 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,12 +14,15 @@ ELSE() --wrap,kds_s2000w_client_start_scan,\ --wrap,kds_s2000w_client_stop_scan,\ --wrap,kds_s2000w_client_open_session,\ +--wrap,kds_s2000w_client_close_session,\ --wrap,kds_s2000w_client_status_session,\ --wrap,kds_s2000w_client_get_image,\ --wrap,kds_s2000w_client_get_metadata,\ --wrap,kds_s2000w_convert_jpg_to_pnm,\ --wrap,kds_s2000w_client_delete_image,\ ---wrap,load_config" CACHE STRING "test coverage compiler flags" FORCE) +--wrap,kds_s2000w_client_set_option,\ +--wrap,load_config,\ +--wrap,usleep" CACHE STRING "test coverage compiler flags" FORCE) ENDIF() MESSAGE(STATUS "CMAKE_C_FLAGS " ${CMAKE_C_FLAGS}) diff --git a/tests/kds_s2000w_client_mock.c b/tests/kds_s2000w_client_mock.c index c5b360d..7fb765d 100644 --- a/tests/kds_s2000w_client_mock.c +++ b/tests/kds_s2000w_client_mock.c @@ -1,7 +1,13 @@ #include #include +#include #include "kds_s2000w_client_mock.h" +int __wrap_usleep(__useconds_t usec) +{ + return 0; +} + void mock_response(response* resp) { response* mock_resp = mock_type(response*); @@ -22,6 +28,12 @@ int __wrap_kds_s2000w_client_get_option(int64_t sessionid, response* response) return mock_type(int); } +int __wrap_kds_s2000w_client_set_option(int64_t sessionid, response* response) +{ + mock_response(response); + return mock_type(int); +} + int __wrap_kds_s2000w_client_stop_scan(int64_t sessionid, response* response) { mock_response(response); @@ -62,4 +74,9 @@ int __wrap_kds_s2000w_client_open_session(response* response) { mock_response(response); return mock_type(int); +} + +void __wrap_kds_s2000w_client_close_session(int64_t sessionid) +{ + return; } \ No newline at end of file diff --git a/tests/kds_s2000w_client_mock.h b/tests/kds_s2000w_client_mock.h index cc3b2f4..6ab9c46 100644 --- a/tests/kds_s2000w_client_mock.h +++ b/tests/kds_s2000w_client_mock.h @@ -9,6 +9,7 @@ void mock_response(response* resp); int __wrap_kds_s2000w_client_get_option(int64_t sessionid, response* response); +int __wrap_kds_s2000w_client_set_option(int64_t sessionid, response* response); int __wrap_kds_s2000w_client_stop_scan(int64_t sessionid, response* response); int __wrap_kds_s2000w_client_status_session(int64_t sessionid, response* response); int __wrap_kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* response); @@ -16,5 +17,6 @@ int __wrap_kds_s2000w_client_get_metadata(int64_t sessionid, int img_number, res int __wrap_kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response* response); int __wrap_kds_s2000w_client_start_scan(int64_t sessionid, response* response); int __wrap_kds_s2000w_client_open_session(response* response); +void __wrap_kds_s2000w_client_close_session(int64_t sessionid); #endif \ No newline at end of file diff --git a/tests/kds_s2000w_net_tests.c b/tests/kds_s2000w_net_tests.c index df4dd7a..5854e85 100644 --- a/tests/kds_s2000w_net_tests.c +++ b/tests/kds_s2000w_net_tests.c @@ -548,6 +548,73 @@ void sane_kds_s2000w_net_start(void** state) h = NULL; } +void sane_kds_s2000w_net_start_one_page_per_flatscan(void** state) +{ + response** response_list = (response**) *state; + will_return(mock_response, response_list[0]); + will_return(__wrap_kds_s2000w_client_start_scan, 0); + response* resp_status = kds_s2000w_client_response_init(); + resp_status->data = realloc(resp_status->data, 205); + const char* status = "{ \ + \"Status\": { \ + \"NumImagesScanned\": 1, \ + \"NumImagesStored\": 1, \ + \"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); + will_return(mock_response, response_list[0]); + will_return(__wrap_kds_s2000w_client_get_image, 0); + will_return(mock_response, response_list[1]); + will_return(__wrap_kds_s2000w_client_get_metadata, 0); + will_return(mock_response, response_list[0]); + will_return(__wrap_kds_s2000w_client_delete_image, 0); + response* resp_open_session = kds_s2000w_client_response_init(); + resp_open_session->data = realloc(resp_open_session->data, 25); + const char* session_data = "{\"SessionId\":\"8154711\"}\0"; + memcpy(resp_open_session->data, session_data, 25); + resp_open_session->code = 200; + resp_open_session->size = 25; + will_return(mock_response, resp_open_session); + will_return(__wrap_kds_s2000w_client_open_session, 0); + response* resp_set_option = kds_s2000w_client_response_init(); + resp_set_option->code = 200; + will_return(mock_response, resp_set_option); + will_return(__wrap_kds_s2000w_client_set_option, 0); + handler* h = init_handler(); + const char* test_config = "{\"Configuration\": { \"ColorMode\": \"Color\" } }"; + h->current_scanner_config = json_tokener_parse(test_config); + + int result = _sane_kds_s2000w_net_start(h); + + assert_int_equal(result, SANE_STATUS_GOOD); + assert_int_equal(h->current_metadata->depth, 8); + assert_int_equal(h->current_metadata->channels, 3); + assert_int_equal(h->current_metadata->format, 1); + assert_int_equal(h->current_metadata->pixels_per_line, 1000); + assert_int_equal(h->current_metadata->lines, 1000); + assert_int_equal(h->current_metadata->valid, 1); + assert_int_equal(h->current_metadata->is_last, 1); + + json_object_put(h->current_scanner_config); + h->current_scanner_config = NULL; + kds_s2000w_client_response_free(resp_status); + resp_status = NULL; + kds_s2000w_client_response_free(resp_open_session); + resp_open_session = NULL; + kds_s2000w_client_response_free(resp_set_option); + resp_set_option = NULL; + free_handler(h); + h = NULL; +} + void sane_kds_s2000w_net_get_parameter_cancel() { handler* h = init_handler(); diff --git a/tests/kds_s2000w_net_tests.h b/tests/kds_s2000w_net_tests.h index ab586f7..f0167e7 100644 --- a/tests/kds_s2000w_net_tests.h +++ b/tests/kds_s2000w_net_tests.h @@ -12,29 +12,30 @@ void kds_s2000w_net_init(); 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_control_get_option_zero(); -void sane_kds_s2000w_net_control_get_option_two(); -void sane_kds_s2000w_net_control_get_option_three(); -void sane_kds_s2000w_net_control_get_option_four(); -void sane_kds_s2000w_net_control_get_option_five(); -void sane_kds_s2000w_net_control_get_option_six(); -void sane_kds_s2000w_net_control_get_option_eight(); -void sane_kds_s2000w_net_control_get_option_nine(); -void sane_kds_s2000w_net_control_get_option_ten(); -void sane_kds_s2000w_net_control_get_option_eleven(); -void sane_kds_s2000w_net_control_get_option_twelve(); -void sane_kds_s2000w_net_control_get_option_thirteen(); -void sane_kds_s2000w_net_control_get_option_fourteen(); -void sane_kds_s2000w_net_control_get_option_fifteen(); -void sane_kds_s2000w_net_control_get_option_sixteen(); -void sane_kds_s2000w_net_control_get_option_seventeen(); -void sane_kds_s2000w_net_control_get_option_eightteen(); -void sane_kds_s2000w_net_control_get_option_nineteen(); -void sane_kds_s2000w_net_control_get_option_twenty(); -void sane_kds_s2000w_net_control_get_option_twentyone(); -void sane_kds_s2000w_net_control_get_option_twentytwo(); +void sane_kds_s2000w_net_control_get_option_zero(void** state); +void sane_kds_s2000w_net_control_get_option_two(void** state); +void sane_kds_s2000w_net_control_get_option_three(void** state); +void sane_kds_s2000w_net_control_get_option_four(void** state); +void sane_kds_s2000w_net_control_get_option_five(void** state); +void sane_kds_s2000w_net_control_get_option_six(void** state); +void sane_kds_s2000w_net_control_get_option_eight(void** state); +void sane_kds_s2000w_net_control_get_option_nine(void** state); +void sane_kds_s2000w_net_control_get_option_ten(void** state); +void sane_kds_s2000w_net_control_get_option_eleven(void** state); +void sane_kds_s2000w_net_control_get_option_twelve(void** state); +void sane_kds_s2000w_net_control_get_option_thirteen(void** state); +void sane_kds_s2000w_net_control_get_option_fourteen(void** state); +void sane_kds_s2000w_net_control_get_option_fifteen(void** state); +void sane_kds_s2000w_net_control_get_option_sixteen(void** state); +void sane_kds_s2000w_net_control_get_option_seventeen(void** state); +void sane_kds_s2000w_net_control_get_option_eightteen(void** state); +void sane_kds_s2000w_net_control_get_option_nineteen(void** state); +void sane_kds_s2000w_net_control_get_option_twenty(void** state); +void sane_kds_s2000w_net_control_get_option_twentyone(void** state); +void sane_kds_s2000w_net_control_get_option_twentytwo(void** state); void sane_kds_s2000w_net_start_cancel(); -void sane_kds_s2000w_net_start(); +void sane_kds_s2000w_net_start(void** state); +void sane_kds_s2000w_net_start_one_page_per_flatscan(void** state); void sane_kds_s2000w_net_get_parameter_cancel(); void sane_kds_s2000w_net_cancel(); void sane_kds_s2000w_net_open(); diff --git a/tests/kds_s2000w_net_tests_run.c b/tests/kds_s2000w_net_tests_run.c index 9bab9a1..2f3cc82 100644 --- a/tests/kds_s2000w_net_tests_run.c +++ b/tests/kds_s2000w_net_tests_run.c @@ -127,6 +127,7 @@ int main() cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twentytwo, setup_default_get_option, teardown_default_get_option), cmocka_unit_test(sane_kds_s2000w_net_start_cancel), cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_start, setup_net_start, teardown_net_start), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_start_one_page_per_flatscan, setup_net_start, teardown_net_start), cmocka_unit_test(sane_kds_s2000w_net_get_parameter_cancel), cmocka_unit_test(sane_kds_s2000w_net_cancel), cmocka_unit_test(sane_kds_s2000w_net_open)