From: Bastian Dehn Date: Sun, 17 Mar 2024 17:38:55 +0000 (+0100) Subject: split tests in seperate running units X-Git-Tag: v1.0.0^2~72^2~17 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=df636082a936392edbc2aef8347d92a21f4c3a36;p=sane-kds-s2000w-net.git split tests in seperate running units --- diff --git a/CMakeLists.txt b/CMakeLists.txt index f5ea579..3e4e482 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6c4d1e2..1ec2803 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 diff --git a/tests/kds_s2000w_net_read_tests.c b/tests/kds_s2000w_net_read_tests.c index 8229c49..b9b907f 100644 --- a/tests/kds_s2000w_net_read_tests.c +++ b/tests/kds_s2000w_net_read_tests.c @@ -1,9 +1,86 @@ #include #include +#include #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 index 0000000..7918f96 --- /dev/null +++ b/tests/kds_s2000w_net_read_tests_run.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include +#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 diff --git a/tests/kds_s2000w_net_tests.c b/tests/kds_s2000w_net_tests.c index 72b50e4..251f972 100644 --- a/tests/kds_s2000w_net_tests.c +++ b/tests/kds_s2000w_net_tests.c @@ -2,10 +2,20 @@ #include #include #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 index 0000000..ad947ff --- /dev/null +++ b/tests/kds_s2000w_net_tests_run.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#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 diff --git a/tests/kds_s2000w_read_config_tests.c b/tests/kds_s2000w_read_config_tests.c index 982275c..b09419f 100644 --- a/tests/kds_s2000w_read_config_tests.c +++ b/tests/kds_s2000w_read_config_tests.c @@ -1,7 +1,81 @@ #include +#include #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 index 0000000..15321b7 --- /dev/null +++ b/tests/kds_s2000w_read_config_tests_run.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include +#include +#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 index bb7ad15..0000000 --- a/tests/runtests.c +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include -#include -#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