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})
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
#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();
--- /dev/null
+#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
#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);
--- /dev/null
+#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
#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";
--- /dev/null
+#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
+++ /dev/null
-#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