From: Bastian Dehn Date: Sun, 24 Mar 2024 14:57:49 +0000 (+0100) Subject: setup get option default setup and teardown X-Git-Tag: v1.0.0^2~56 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=624570cacf34241a78d184bb0e2a45e2a27f6357;p=sane-kds-s2000w-net.git setup get option default setup and teardown --- diff --git a/tests/kds_s2000w_client_mock.c b/tests/kds_s2000w_client_mock.c index 01c6657..ca8d5b4 100644 --- a/tests/kds_s2000w_client_mock.c +++ b/tests/kds_s2000w_client_mock.c @@ -5,6 +5,9 @@ void mock_response(response* resp) { response* mock_resp = mock_type(response*); + if (mock_resp == NULL) + return; + if (mock_resp->size > 0) { resp->data = realloc(resp->data, mock_resp->size); memcpy(resp->data, mock_resp->data, mock_resp->size); @@ -15,48 +18,7 @@ void mock_response(response* resp) int __wrap_kds_s2000w_client_get_option(int64_t sessionid, response* response) { - response->data = realloc(response->data, 919); - const char* responsedata = "{ \ - \"Status\": { \ - \"NumImagesScanned\": 0, \ - \"NumImagesStored\": 0, \ - \"State\": \"In Session\", \ - \"ErrorNum\": 0, \ - \"LastError\": \"Status: 200 Success\", \ - \"PaperDetected\": \"0\", \ - \"PercentAvailable\": 99 \ - }, \ - \"Configuration\": { \ - \"DPI\": 200, \ - \"ScanSide\": \"Duplex\", \ - \"ColorMode\": \"Color\", \ - \"SkipBlankPages\": 0, \ - \"AutoStart\": 0, \ - \"ColorDropOut\": \"None\", \ - \"ColorDropOutAggressiveness\": 0, \ - \"OutputType\": \"Images\", \ - \"ColorAutoBrightnessMode\": \"Automatic\", \ - \"ColorBalanceMode\": \"Automatic\", \ - \"ColorBalanceAggressiveness\": 0, \ - \"ColorBalanceRed\": 0, \ - \"ColorBalanceGreen\": 0, \ - \"ColorBalanceBlue\": 0, \ - \"ForegroundBoldnessMode\": \"None\", \ - \"ForegroundBoldnessAggressiveness\": 0, \ - \"BackgroundSmoothingMode\": \"None\", \ - \"BackgroundSmoothingAggressiveness\": 0, \ - \"BinarizationMode\": \"iThresholding\", \ - \"BinarizationContrast\": 0, \ - \"MaxDocumentLength\": 140, \ - \"ScanSource\": \"DocumentFeeder\" \ - } \ - }\0"; - - memcpy(response->data, responsedata, 919); - - response->code = 200; - response->size = sizeof(response->data); - + mock_response(response); return mock_type(int); } diff --git a/tests/kds_s2000w_net_tests.c b/tests/kds_s2000w_net_tests.c index 0358b21..127ea7c 100644 --- a/tests/kds_s2000w_net_tests.c +++ b/tests/kds_s2000w_net_tests.c @@ -108,8 +108,10 @@ void kds_s2000w_net_get_select_fd() assert_int_equal(result, SANE_STATUS_UNSUPPORTED); } -void sane_kds_s2000w_net_control_get_option_zero() +void sane_kds_s2000w_net_control_get_option_zero(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int value = 0; @@ -121,8 +123,10 @@ void sane_kds_s2000w_net_control_get_option_zero() h = NULL; } -void sane_kds_s2000w_net_control_get_option_two() +void sane_kds_s2000w_net_control_get_option_two(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -137,8 +141,10 @@ void sane_kds_s2000w_net_control_get_option_two() h = NULL; } -void sane_kds_s2000w_net_control_get_option_three() +void sane_kds_s2000w_net_control_get_option_three(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -153,8 +159,10 @@ void sane_kds_s2000w_net_control_get_option_three() h = NULL; } -void sane_kds_s2000w_net_control_get_option_four() +void sane_kds_s2000w_net_control_get_option_four(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -169,8 +177,10 @@ void sane_kds_s2000w_net_control_get_option_four() h = NULL; } -void sane_kds_s2000w_net_control_get_option_five() +void sane_kds_s2000w_net_control_get_option_five(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -185,8 +195,10 @@ void sane_kds_s2000w_net_control_get_option_five() h = NULL; } -void sane_kds_s2000w_net_control_get_option_six() +void sane_kds_s2000w_net_control_get_option_six(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -201,8 +213,10 @@ void sane_kds_s2000w_net_control_get_option_six() h = NULL; } -void sane_kds_s2000w_net_control_get_option_eight() +void sane_kds_s2000w_net_control_get_option_eight(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -217,8 +231,10 @@ void sane_kds_s2000w_net_control_get_option_eight() h = NULL; } -void sane_kds_s2000w_net_control_get_option_nine() +void sane_kds_s2000w_net_control_get_option_nine(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -233,8 +249,10 @@ void sane_kds_s2000w_net_control_get_option_nine() h = NULL; } -void sane_kds_s2000w_net_control_get_option_ten() +void sane_kds_s2000w_net_control_get_option_ten(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -249,8 +267,10 @@ void sane_kds_s2000w_net_control_get_option_ten() h = NULL; } -void sane_kds_s2000w_net_control_get_option_eleven() +void sane_kds_s2000w_net_control_get_option_eleven(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -265,8 +285,10 @@ void sane_kds_s2000w_net_control_get_option_eleven() h = NULL; } -void sane_kds_s2000w_net_control_get_option_twelve() +void sane_kds_s2000w_net_control_get_option_twelve(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -281,8 +303,10 @@ void sane_kds_s2000w_net_control_get_option_twelve() h = NULL; } -void sane_kds_s2000w_net_control_get_option_thirteen() +void sane_kds_s2000w_net_control_get_option_thirteen(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -297,8 +321,10 @@ void sane_kds_s2000w_net_control_get_option_thirteen() h = NULL; } -void sane_kds_s2000w_net_control_get_option_fourteen() +void sane_kds_s2000w_net_control_get_option_fourteen(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -313,8 +339,10 @@ void sane_kds_s2000w_net_control_get_option_fourteen() h = NULL; } -void sane_kds_s2000w_net_control_get_option_fifteen() +void sane_kds_s2000w_net_control_get_option_fifteen(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -329,8 +357,10 @@ void sane_kds_s2000w_net_control_get_option_fifteen() h = NULL; } -void sane_kds_s2000w_net_control_get_option_sixteen() +void sane_kds_s2000w_net_control_get_option_sixteen(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -345,8 +375,10 @@ void sane_kds_s2000w_net_control_get_option_sixteen() h = NULL; } -void sane_kds_s2000w_net_control_get_option_seventeen() +void sane_kds_s2000w_net_control_get_option_seventeen(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -361,8 +393,10 @@ void sane_kds_s2000w_net_control_get_option_seventeen() h = NULL; } -void sane_kds_s2000w_net_control_get_option_eightteen() +void sane_kds_s2000w_net_control_get_option_eightteen(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -377,8 +411,10 @@ void sane_kds_s2000w_net_control_get_option_eightteen() h = NULL; } -void sane_kds_s2000w_net_control_get_option_nineteen() +void sane_kds_s2000w_net_control_get_option_nineteen(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -393,8 +429,10 @@ void sane_kds_s2000w_net_control_get_option_nineteen() h = NULL; } -void sane_kds_s2000w_net_control_get_option_twenty() +void sane_kds_s2000w_net_control_get_option_twenty(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -409,8 +447,10 @@ void sane_kds_s2000w_net_control_get_option_twenty() h = NULL; } -void sane_kds_s2000w_net_control_get_option_twentyone() +void sane_kds_s2000w_net_control_get_option_twentyone(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; @@ -425,8 +465,10 @@ void sane_kds_s2000w_net_control_get_option_twentyone() h = NULL; } -void sane_kds_s2000w_net_control_get_option_twentytwo() +void sane_kds_s2000w_net_control_get_option_twentytwo(void** state) { + response* resp = (response*) *state; + will_return(mock_response, resp); will_return(__wrap_kds_s2000w_client_get_option, 0); handler* h = init_handler(); int option_num = 0; diff --git a/tests/kds_s2000w_net_tests_run.c b/tests/kds_s2000w_net_tests_run.c index 3db7cc7..6a49faf 100644 --- a/tests/kds_s2000w_net_tests_run.c +++ b/tests/kds_s2000w_net_tests_run.c @@ -1,4 +1,61 @@ +#include +#include #include "kds_s2000w_net_tests.h" +#include "kds_s2000w_client_mock.h" + +int setup_default_get_option(void** state) +{ + response* resp = kds_s2000w_client_response_init(); + resp->data = realloc(resp->data, 919); + const char* responsedata = "{ \ + \"Status\": { \ + \"NumImagesScanned\": 0, \ + \"NumImagesStored\": 0, \ + \"State\": \"In Session\", \ + \"ErrorNum\": 0, \ + \"LastError\": \"Status: 200 Success\", \ + \"PaperDetected\": \"0\", \ + \"PercentAvailable\": 99 \ + }, \ + \"Configuration\": { \ + \"DPI\": 200, \ + \"ScanSide\": \"Duplex\", \ + \"ColorMode\": \"Color\", \ + \"SkipBlankPages\": 0, \ + \"AutoStart\": 0, \ + \"ColorDropOut\": \"None\", \ + \"ColorDropOutAggressiveness\": 0, \ + \"OutputType\": \"Images\", \ + \"ColorAutoBrightnessMode\": \"Automatic\", \ + \"ColorBalanceMode\": \"Automatic\", \ + \"ColorBalanceAggressiveness\": 0, \ + \"ColorBalanceRed\": 0, \ + \"ColorBalanceGreen\": 0, \ + \"ColorBalanceBlue\": 0, \ + \"ForegroundBoldnessMode\": \"None\", \ + \"ForegroundBoldnessAggressiveness\": 0, \ + \"BackgroundSmoothingMode\": \"None\", \ + \"BackgroundSmoothingAggressiveness\": 0, \ + \"BinarizationMode\": \"iThresholding\", \ + \"BinarizationContrast\": 0, \ + \"MaxDocumentLength\": 140, \ + \"ScanSource\": \"DocumentFeeder\" \ + } \ + }\0"; + memcpy(resp->data, responsedata, 919); + resp->code = 200; + resp->size = 919; + *state = resp; + return 0; +} + +int teardown_default_get_option(void** state) +{ + response* resp = (response*) *state; + kds_s2000w_client_response_free(resp); + resp = NULL; + return 0; +} int main() { @@ -9,27 +66,27 @@ int main() cmocka_unit_test(kds_s2000w_net_get_devices_only_remote), 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_control_get_option_zero), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_two), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_three), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_four), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_five), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_six), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_eight), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_nine), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_ten), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_eleven), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_twelve), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_thirteen), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_fourteen), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_fifteen), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_sixteen), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_seventeen), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_eightteen), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_nineteen), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_twenty), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_twentyone), - cmocka_unit_test(sane_kds_s2000w_net_control_get_option_twentytwo), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_zero, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_two, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_three, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_four, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_five, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_six, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_eight, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_nine, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_ten, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_eleven, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twelve, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_thirteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fifteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_sixteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_seventeen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_eightteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_nineteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twenty, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twentyone, setup_default_get_option, teardown_default_get_option), + 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(sane_kds_s2000w_net_start), cmocka_unit_test(sane_kds_s2000w_net_get_parameter_cancel),