From: Bastian Dehn Date: Sat, 25 Oct 2025 16:32:45 +0000 (+0200) Subject: add set option test X-Git-Tag: v1.1.16^2~1^2~10 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=029d9a9abac812696d8e1cdc45238d597c31fb39;p=sane-kds-s2000w-net.git add set option test --- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 861de06..0c7a792 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,6 +14,14 @@ TARGET_LINK_LIBRARIES("kds_s2000w_net_get_opt_tests" ${CMOCKA_LIBRARY} sane-kds_s2000w_net-static) +ADD_EXECUTABLE("kds_s2000w_net_set_opt_tests" + "kds_s2000w_net_set_opt_tests.c" + "kds_s2000w_client_mock.c") +ADD_DEPENDENCIES("kds_s2000w_net_set_opt_tests" sane-kds_s2000w_net-static) +TARGET_LINK_LIBRARIES("kds_s2000w_net_set_opt_tests" + ${CMOCKA_LIBRARY} + sane-kds_s2000w_net-static) + ADD_EXECUTABLE("kds_s2000w_net_read_tests" "kds_s2000w_net_read_tests.c" "kds_s2000w_client_mock.c") @@ -72,6 +80,7 @@ ADD_CUSTOM_TARGET("runningtests" ALL ./kds_s2000w_read_config_tests COMMAND ./kds_s2000w_option_descriptor_tests COMMAND ./kds_s2000w_net_get_opt_tests + COMMAND ./kds_s2000w_net_set_opt_tests COMMAND ./kds_s2000w_net_tests COMMAND ./kds_s2000w_net_read_tests COMMAND ./kds_s2000w_image_type_check_tests @@ -81,6 +90,7 @@ ADD_CUSTOM_TARGET("runningtests" DEPENDS "kds_s2000w_read_config_tests" "kds_s2000w_option_descriptor_tests" "kds_s2000w_net_get_opt_tests" + "kds_s2000w_net_set_opt_tests" "kds_s2000w_net_tests" "kds_s2000w_net_read_tests" "kds_s2000w_image_type_check_tests" diff --git a/tests/kds_s2000w_net_set_opt_tests.c b/tests/kds_s2000w_net_set_opt_tests.c new file mode 100644 index 0000000..7db462f --- /dev/null +++ b/tests/kds_s2000w_net_set_opt_tests.c @@ -0,0 +1,136 @@ +#include +#include +#include +#include +#include +#include +#include +#include "kds_s2000w_client_mock.h" +#include "../src/kds_s2000w_client.h" +#include "../src/kds_s2000w_net.h" +#include "../src/kds_s2000w_handler.h" +#include "../src/kds_s2000w_option_descriptors.h" + +int setup_default_option(void** state) +{ + kds_s2000w_option_descriptors_init(PROFILE_FULL); + response_t* resp = kds_s2000w_client_response_init(); + 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, \ + \"SkipBlankPagesContent\": 5, \ + \"AutoStart\": 0, \ + \"ColorDropOut\": \"None\", \ + \"ColorDropOutAggressiveness\" :0, \ + \"OutputType\": \"Images\", \ + \"ColorAutoBrightnessMode\": \"Automatic\", \ + \"ColorBrightness\": 0, \ + \"ColorContrast\": 0, \ + \"ColorBalanceMode\": \"Automatic\", \ + \"ColorBalanceAggressiveness\": 0, \ + \"ColorBalanceRed\": 0, \ + \"ColorBalanceGreen\": 0, \ + \"ColorBalanceBlue\": 0, \ + \"ColorSharpen\": \"Normal\", \ + \"ForegroundBoldnessMode\": \"None\", \ + \"ForegroundBoldnessAggressiveness\": 0, \ + \"BackgroundSmoothingMode\": \"None\", \ + \"BackgroundSmoothingAggressiveness\": 0, \ + \"BinarizationMode\": \"iThresholding\", \ + \"BinarizationContrast\": 0, \ + \"MaxDocumentLength\": 140, \ + \"MultifeedSensitivity\": \"None\", \ + \"MultifeedResponse\": \"Stop\", \ + \"PostScanRotation\": \"Automatic\", \ + \"EdgeFill\": \"Automatic\", \ + \"ScanSource\": \"DocumentFeeder\", \ + \"ImageBorder\": \"None\", \ + \"TransportHandling\": \"Normal\", \ + \"DocumentFeederTimeout\": 2, \ + \"DocumentFeederTimeoutResponse\": \"Stop\", \ + \"JpegQuality\": \"Good\", \ + \"HoleFill\": 0, \ + \"CroppingMode\": \"AutomaticStraighten\", \ + \"CroppingImage\": \"EntireDocument\", \ + \"ImageOffsetX\": 0, \ + \"ImageOffsetY\": 0, \ + \"ImageWidth\": 10, \ + \"ImageHeight\": 10 \ + } \ + }"; + resp->size = 1503; + resp->data = malloc(resp->size); + memcpy(resp->data, responsedata, resp->size); + resp->code = 200; + *state = resp; + return 0; +} + +int teardown_default_option(void** state) +{ + kds_s2000w_option_descriptors_free(); + response_t* resp = (response_t*) *state; + kds_s2000w_client_response_free(resp); + resp = NULL; + return 0; +} + +void kds_s2000w_net_set_option_string(void** state) +{ + int32_t* info = malloc(sizeof(int32_t)); + if (info == NULL) + return; + + response_t* resp = (response_t*) *state; + handler_t* h = kds_s2000w_handler_init(); + *info = 0; + response_t* set_opt_resp = kds_s2000w_client_response_init(); + set_opt_resp->code = 200; + + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + will_return(mock_response, set_opt_resp); + will_return(__wrap_kds_s2000w_client_set_option, 0); + will_return(mock_response, set_opt_resp); + will_return(__wrap_kds_s2000w_client_set_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + expect_function_call(__wrap_kds_s2000w_client_set_option); + expect_function_call(__wrap_kds_s2000w_client_set_option); + + sane_kds_s2000w_net_control_option(h, 3, SANE_ACTION_SET_VALUE, "Gray", info); + + json_object* config = json_object_object_get(h->scanner_config, "Configuration"); + json_object* value_object = json_object_object_get(config, COLOR_MODE); + const char* value = json_object_get_string(value_object); + + assert_string_equal(value, "Gray"); + assert_int_equal(*info, SANE_INFO_RELOAD_PARAMS); + + kds_s2000w_client_response_free(set_opt_resp); + set_opt_resp = NULL; + kds_s2000w_handler_free(h); + h = NULL; + free(info); + info = NULL; +} + +int main() +{ + const struct CMUnitTest net_tests[] = { + cmocka_unit_test_setup_teardown(kds_s2000w_net_set_option_string, setup_default_option, teardown_default_option) + }; + + return cmocka_run_group_tests(net_tests, NULL, NULL); +} \ No newline at end of file