]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add set option test
authorBastian Dehn <hhaalo@arcor.de>
Sat, 25 Oct 2025 16:32:45 +0000 (18:32 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 25 Oct 2025 16:38:17 +0000 (18:38 +0200)
tests/CMakeLists.txt
tests/kds_s2000w_net_set_opt_tests.c [new file with mode: 0644]

index 861de06a20131b2bcee1a2355846fbf8a623bf74..0c7a79260c5f2f7bdb5115f3e18139ae6f8eb36f 100644 (file)
@@ -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 (file)
index 0000000..7db462f
--- /dev/null
@@ -0,0 +1,136 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <stdlib.h>
+#include <string.h>
+#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