]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
split tests in seperate running units
authorBastian Dehn <hhaalo@arcor.de>
Sun, 17 Mar 2024 17:38:55 +0000 (18:38 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 17 Mar 2024 17:38:55 +0000 (18:38 +0100)
CMakeLists.txt
tests/CMakeLists.txt
tests/kds_s2000w_net_read_tests.c
tests/kds_s2000w_net_read_tests_run.c [new file with mode: 0644]
tests/kds_s2000w_net_tests.c
tests/kds_s2000w_net_tests_run.c [new file with mode: 0644]
tests/kds_s2000w_read_config_tests.c
tests/kds_s2000w_read_config_tests_run.c [new file with mode: 0644]
tests/runtests.c [deleted file]

index f5ea579a0f50edb9a39e18ebb091442519280e38..3e4e4820d74f3efbda14de06c751c9817bf63360 100644 (file)
@@ -5,16 +5,18 @@ if (NOT RUN_TESTS)
        set(CMAKE_C_FLAGS "-Wall -Werror" CACHE STRING "compiler flags")
 else()
        set(CMAKE_C_FLAGS "-fPIC \
-       -fprofile-arcs \
-       -ftest-coverage \
-       -Wall \
-       -g \
-       -Xlinker \
-       --wrap=kds_s2000w_client_get_option \
-       -Xlinker \
-       --wrap=kds_s2000w_client_stop_scan \
-       -Xlinker \
-       --wrap=kds_s2000w_client_open_session" CACHE STRING "test coverage compiler flags")
+-fprofile-arcs \
+-ftest-coverage \
+-Wall \
+-g \
+-Xlinker \
+--wrap=kds_s2000w_client_get_option \
+-Xlinker \
+--wrap=kds_s2000w_client_stop_scan \
+-Xlinker \
+--wrap=kds_s2000w_client_open_session \
+-Xlinker \
+--wrap=load_config" CACHE STRING "test coverage compiler flags")
 endif()
 
 message(STATUS "CMAKE_C_FLAGS " ${CMAKE_C_FLAGS})
index 6c4d1e2e1c80b83a03be1a3d3979dcd7dc6a43da..1ec28034625fd2d32e6a7bef927bda5b93c6063f 100644 (file)
@@ -4,19 +4,37 @@ find_package(CMOCKA REQUIRED)
 
 message(STATUS "find ${CMOCKA_LIBRARY}")
 
-add_executable("runtests"
-       "kds_s2000w_net_read_tests.c"
-       "kds_s2000w_net_tests.c"
-       "kds_s2000w_read_config_tests.c"
-       "runtests.c")
-add_dependencies("runtests" sane-kds_s2000w_net)
-target_link_libraries("runtests"
+add_executable("kds_s2000w_net_read_tests_run"
+       "kds_s2000w_net_read_tests_run.c"
+       "kds_s2000w_net_read_tests.c")
+add_dependencies("kds_s2000w_net_read_tests_run" sane-kds_s2000w_net)
+target_link_libraries("kds_s2000w_net_read_tests_run"
        ${CMOCKA_LIBRARY}
        sane-kds_s2000w_net)
 
-add_custom_target("runningtests" ALL "./runtests"
+add_executable("kds_s2000w_net_tests_run"
+       "kds_s2000w_net_tests_run.c"
+       "kds_s2000w_net_tests.c")
+add_dependencies("kds_s2000w_net_tests_run" sane-kds_s2000w_net)
+target_link_libraries("kds_s2000w_net_tests_run"
+       ${CMOCKA_LIBRARY}
+       sane-kds_s2000w_net)
+
+add_executable("kds_s2000w_read_config_tests_run"
+       "kds_s2000w_read_config_tests_run.c"
+       "kds_s2000w_read_config_tests.c")
+add_dependencies("kds_s2000w_read_config_tests_run" sane-kds_s2000w_net)
+target_link_libraries("kds_s2000w_read_config_tests_run"
+       ${CMOCKA_LIBRARY}
+       sane-kds_s2000w_net)
+
+add_custom_target("runningtests" ALL "./kds_s2000w_net_read_tests_run"
+       COMMAND "./kds_s2000w_net_tests_run"
+       COMMAND "./kds_s2000w_read_config_tests_run"
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
-       DEPENDS "runtests")
+       DEPENDS "kds_s2000w_read_config_tests_run"
+       "kds_s2000w_net_tests_run"
+       "kds_s2000w_net_read_tests_run")
 
 add_custom_target("generate_gcov_coverage"
        ALL gcov ${CMAKE_BINARY_DIR}/src/CMakeFiles/sane-kds_s2000w_net.dir/*.c.o
index 8229c493b26c883e1cb00dcbb678396f034ad91e..b9b907f72d8c49f1adee67c128cdf7eb3b5c9e0f 100644 (file)
@@ -1,9 +1,86 @@
 #include <stdlib.h>
 #include <sane/sane.h>
+#include <string.h>
 #include "kds_s2000w_net_read_tests.h"
+#include "../src/kds_s2000w_config.h"
+#include "../src/kds_s2000w_client.h"
 #include "../src/kds_s2000w_handler.h"
 #include "../src/kds_s2000w_net.h"
 
+void __wrap_load_config(program_config* config, const char* config_stream)
+{
+       config->scanner_url = malloc(sizeof(char) * 28);
+       config->username = malloc(sizeof(char) * 4);
+
+       config->scanner_url = "https://scanner.example.com\0";
+       config->username = "Max\0";
+}
+
+int __wrap_kds_s2000w_client_get_option(int64_t sessionid, response* response)
+{
+       response->data = realloc(response->data, 918);
+       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, 918);
+
+       response->code = 200;
+       response->size = sizeof(response->data);
+
+       return mock_type(int);
+}
+
+int __wrap_kds_s2000w_client_stop_scan(int64_t sessionid, response* response)
+{
+       return mock_type(int);
+}
+
+int __wrap_kds_s2000w_client_open_session(response* response)
+{
+       response->data = realloc(response->data, 27);
+       const char* responsedata = "{\"SessionId\":\"1251877821\"}\0";
+
+       memcpy(response->data, responsedata, 27);
+
+       response->code = 200;
+       response->size = sizeof(response->data);
+
+       return mock_type(int);
+}
+
 void sane_kds_s2000w_net_read_cancel_test()
 {
        handler* h = init_handler();
diff --git a/tests/kds_s2000w_net_read_tests_run.c b/tests/kds_s2000w_net_read_tests_run.c
new file mode 100644 (file)
index 0000000..7918f96
--- /dev/null
@@ -0,0 +1,19 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "kds_s2000w_net_read_tests.h"
+
+int main()
+{
+       const struct CMUnitTest net_read_tests[] = {
+               cmocka_unit_test(sane_kds_s2000w_net_read_cancel_test),
+               cmocka_unit_test(sane_kds_s2000w_net_read_without_data),
+               cmocka_unit_test(sane_kds_s2000w_net_read_empty_image),
+               cmocka_unit_test(sane_kds_s2000w_net_read_test),
+               cmocka_unit_test(sane_kds_s2000w_net_read_bytes_per_line_bigger_test)
+       };
+
+       return cmocka_run_group_tests(net_read_tests, NULL, NULL);
+}
\ No newline at end of file
index 72b50e4231d406403c23d77adb151b8958fb9bbe..251f9729f00a86c78464c0dad7d792605c652174 100644 (file)
@@ -2,10 +2,20 @@
 #include <sane/sane.h>
 #include <string.h>
 #include "kds_s2000w_net_tests.h"
+#include "../src/kds_s2000w_config.h"
 #include "../src/kds_s2000w_client.h"
 #include "../src/kds_s2000w_net.h"
 #include "../src/kds_s2000w_handler.h"
 
+void __wrap_load_config(program_config* config, const char* config_stream)
+{
+       config->scanner_url = malloc(sizeof(char) * 28);
+       config->username = malloc(sizeof(char) * 4);
+
+       config->scanner_url = "https://scanner.example.com\0";
+       config->username = "Max\0";
+}
+
 int __wrap_kds_s2000w_client_get_option(int64_t sessionid, response* response)
 {
        response->data = realloc(response->data, 918);
diff --git a/tests/kds_s2000w_net_tests_run.c b/tests/kds_s2000w_net_tests_run.c
new file mode 100644 (file)
index 0000000..ad947ff
--- /dev/null
@@ -0,0 +1,45 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "kds_s2000w_net_tests.h"
+
+int main()
+{
+       const struct CMUnitTest net_tests[] = {
+               cmocka_unit_test(kds_s2000w_net_get_parameters_with_image_data),
+               cmocka_unit_test(kds_s2000w_net_get_devices),
+               cmocka_unit_test(kds_s2000w_net_init),
+               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(sane_kds_s2000w_net_start_cancel),
+               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)
+       };
+
+       return cmocka_run_group_tests(net_tests, NULL, NULL);
+}
\ No newline at end of file
index 982275c1db92cdb404c76b707dde0f4b47ee0c24..b09419f2abe148f50d95e69df34e45b482c7000e 100644 (file)
@@ -1,7 +1,81 @@
 #include <stdlib.h>
+#include <string.h>
 #include "kds_s2000w_read_config_tests.h"
+#include "../src/kds_s2000w_client.h"
 #include "../src/kds_s2000w_config.h"
 
+int __wrap_kds_s2000w_client_get_option(int64_t sessionid, response* response)
+{
+       response->data = realloc(response->data, 918);
+       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, 918);
+
+       response->code = 200;
+       response->size = sizeof(response->data);
+
+       return mock_type(int);
+}
+
+int __wrap_kds_s2000w_client_stop_scan(int64_t sessionid, response* response)
+{
+       return mock_type(int);
+}
+
+
+int __wrap_kds_s2000w_client_open_session(response* response)
+{
+       response->data = realloc(response->data, 27);
+       const char* responsedata = "{\"SessionId\":\"1251877821\"}\0";
+
+       memcpy(response->data, responsedata, 27);
+
+       response->code = 200;
+       response->size = sizeof(response->data);
+
+       return mock_type(int);
+}
+
+
+void __wrap_load_config(program_config* config, const char* config_stream)
+{
+       __real_load_config(config, config_stream);
+}
+
 void kds_s2000w_config_read_parameter()
 {
        const char* input_stream = "   scanner_url   =   http://scanner.example.com    \n";
diff --git a/tests/kds_s2000w_read_config_tests_run.c b/tests/kds_s2000w_read_config_tests_run.c
new file mode 100644 (file)
index 0000000..15321b7
--- /dev/null
@@ -0,0 +1,18 @@
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include "kds_s2000w_read_config_tests.h"
+
+int main()
+{
+       const struct CMUnitTest read_config[] = {
+               cmocka_unit_test(kds_s2000w_config_read_parameter),
+               cmocka_unit_test(kds_s2000w_config_read_parameters_without_trim),
+               cmocka_unit_test(kds_s2000w_config_multiple_parameters),
+               cmocka_unit_test(kds_s2000w_config_read_empty_config)
+       };
+
+       return cmocka_run_group_tests(read_config, NULL, NULL);
+}
\ No newline at end of file
diff --git a/tests/runtests.c b/tests/runtests.c
deleted file mode 100644 (file)
index bb7ad15..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <setjmp.h>
-#include <cmocka.h>
-#include "kds_s2000w_net_read_tests.h"
-#include "kds_s2000w_net_tests.h"
-#include "kds_s2000w_read_config_tests.h"
-
-int run_cmocka_tests()
-{
-       int result = 0;
-
-       const struct CMUnitTest net_read_tests[] = {
-               cmocka_unit_test(sane_kds_s2000w_net_read_cancel_test),
-               cmocka_unit_test(sane_kds_s2000w_net_read_without_data),
-               cmocka_unit_test(sane_kds_s2000w_net_read_empty_image),
-               cmocka_unit_test(sane_kds_s2000w_net_read_test),
-               cmocka_unit_test(sane_kds_s2000w_net_read_bytes_per_line_bigger_test)
-       };
-
-       const struct CMUnitTest read_config[] = {
-               cmocka_unit_test(kds_s2000w_config_read_parameter),
-               cmocka_unit_test(kds_s2000w_config_read_parameters_without_trim),
-               cmocka_unit_test(kds_s2000w_config_multiple_parameters),
-               cmocka_unit_test(kds_s2000w_config_read_empty_config)
-       };
-
-       const struct CMUnitTest net_tests[] = {
-               cmocka_unit_test(kds_s2000w_net_get_parameters_with_image_data),
-               cmocka_unit_test(kds_s2000w_net_get_devices),
-               cmocka_unit_test(kds_s2000w_net_init),
-               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(sane_kds_s2000w_net_start_cancel),
-               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)
-       };
-
-       result = cmocka_run_group_tests(net_read_tests, NULL, NULL);
-       result |= cmocka_run_group_tests(read_config, NULL, NULL);
-       result |= cmocka_run_group_tests(net_tests, NULL, NULL);
-
-       return result;
-}
-
-int main()
-{
-       return run_cmocka_tests();
-}
\ No newline at end of file