From 20a7f50767b1f74bcfff78fc288ee0726b3e004c Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Fri, 29 Mar 2024 11:21:43 +0100 Subject: [PATCH] move get opt tests in seperate file --- tests/CMakeLists.txt | 11 + tests/kds_s2000w_net_get_opt_tests.c | 437 +++++++++++++++++++++++ tests/kds_s2000w_net_get_opt_tests.h | 31 ++ tests/kds_s2000w_net_get_opt_tests_run.c | 87 +++++ tests/kds_s2000w_net_tests.c | 416 --------------------- tests/kds_s2000w_net_tests.h | 21 -- tests/kds_s2000w_net_tests_run.c | 75 ---- 7 files changed, 566 insertions(+), 512 deletions(-) create mode 100644 tests/kds_s2000w_net_get_opt_tests.c create mode 100644 tests/kds_s2000w_net_get_opt_tests.h create mode 100644 tests/kds_s2000w_net_get_opt_tests_run.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8c36c5b..ed63bf6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,6 +4,15 @@ FIND_PACKAGE(CMOCKA REQUIRED) MESSAGE(STATUS "find ${CMOCKA_LIBRARY}") +ADD_EXECUTABLE("kds_s2000w_net_get_opt_tests_run" + "kds_s2000w_net_get_opt_tests_run.c" + "kds_s2000w_net_get_opt_tests.c" + "kds_s2000w_client_mock.c") +ADD_DEPENDENCIES("kds_s2000w_net_get_opt_tests_run" sane-kds_s2000w_net) +TARGET_LINK_LIBRARIES("kds_s2000w_net_get_opt_tests_run" + ${CMOCKA_LIBRARY} + sane-kds_s2000w_net) + ADD_EXECUTABLE("kds_s2000w_net_read_tests_run" "kds_s2000w_net_read_tests_run.c" "kds_s2000w_net_read_tests.c" @@ -34,6 +43,8 @@ TARGET_LINK_LIBRARIES("kds_s2000w_read_config_tests_run" INCLUDE(CTest) ENABLE_TESTING() +ADD_TEST(NAME "kds_s2000w_net_get_opt_tests_run" + COMMAND "./kds_s2000w_net_get_opt_tests_run") ADD_TEST(NAME "kds_s2000w_net_read_tests_run" COMMAND "./kds_s2000w_net_read_tests_run") ADD_TEST(NAME "kds_s2000w_net_tests_run" diff --git a/tests/kds_s2000w_net_get_opt_tests.c b/tests/kds_s2000w_net_get_opt_tests.c new file mode 100644 index 0000000..e589320 --- /dev/null +++ b/tests/kds_s2000w_net_get_opt_tests.c @@ -0,0 +1,437 @@ + +#include +#include +#include +#include "kds_s2000w_net_tests.h" +#include "kds_s2000w_client_mock.h" +#include "../src/kds_s2000w_config.h" +#include "../src/kds_s2000w_net.h" +#include "../src/kds_s2000w_handler.h" +#include "../src/kds_s2000w_image_converter.h" + +void __wrap_load_config(program_config* config, const char* config_stream) +{ + return; +} + +void __wrap_kds_s2000w_convert_jpg_to_pnm(blobdata* in, blobdata* out) +{ + return; +} + +void sane_kds_s2000w_net_control_get_option_zero(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int value = 0; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(value, 24); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_two(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + char value[50] = {0}; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 2, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_string_equal(value, "DocumentFeeder"); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_three(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + char value[50] = {0}; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 3, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_string_equal(value, "Color"); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_four(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = 0; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 4, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 200); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_five(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + char value[50] = {0}; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 5, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_string_equal(value, "Duplex"); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_six(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = 0; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 6, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 8); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_eight(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 8, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 0); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_nine(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + char value[50] = {0}; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 9, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_string_equal(value, "None"); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_ten(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 10, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 0); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_eleven(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + char value[50] = {0}; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 11, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_string_equal(value, "Automatic"); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_twelve(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + char value[50] = {0}; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 12, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_string_equal(value, "Automatic"); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_thirteen(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 13, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 0); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_fourteen(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 14, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 0); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_fifteen(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 15, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 0); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_sixteen(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 16, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 0); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_seventeen(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + char value[50] = {0}; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 17, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_string_equal(value, "None"); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_eightteen(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 18, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 0); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_nineteen(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + char value[50] = {0}; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 19, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_string_equal(value, "None"); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_twenty(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 20, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 0); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_twentyone(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 21, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 0); + + free_handler(h); + h = NULL; +} + +void sane_kds_s2000w_net_control_get_option_twentytwo(void** state) +{ + response* resp = (response*) *state; + will_return(mock_response, resp); + will_return(__wrap_kds_s2000w_client_get_option, 0); + expect_function_call(__wrap_kds_s2000w_client_get_option); + handler* h = init_handler(); + int option_num = 0; + int value = -1; + + _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); + _sane_kds_s2000w_net_control_option(h, 22, SANE_ACTION_GET_VALUE, &value, NULL); + + assert_int_equal(option_num, 24); + assert_int_equal(value, 140); + + free_handler(h); + h = NULL; +} diff --git a/tests/kds_s2000w_net_get_opt_tests.h b/tests/kds_s2000w_net_get_opt_tests.h new file mode 100644 index 0000000..293fd40 --- /dev/null +++ b/tests/kds_s2000w_net_get_opt_tests.h @@ -0,0 +1,31 @@ +#ifndef KDS_S2000W_NET_GET_OPT_TESTS_H +#define KDS_S2000W_NET_GET_OPT_TESTS_H +#include +#include +#include +#include +#include + +void sane_kds_s2000w_net_control_get_option_zero(void** state); +void sane_kds_s2000w_net_control_get_option_two(void** state); +void sane_kds_s2000w_net_control_get_option_three(void** state); +void sane_kds_s2000w_net_control_get_option_four(void** state); +void sane_kds_s2000w_net_control_get_option_five(void** state); +void sane_kds_s2000w_net_control_get_option_six(void** state); +void sane_kds_s2000w_net_control_get_option_eight(void** state); +void sane_kds_s2000w_net_control_get_option_nine(void** state); +void sane_kds_s2000w_net_control_get_option_ten(void** state); +void sane_kds_s2000w_net_control_get_option_eleven(void** state); +void sane_kds_s2000w_net_control_get_option_twelve(void** state); +void sane_kds_s2000w_net_control_get_option_thirteen(void** state); +void sane_kds_s2000w_net_control_get_option_fourteen(void** state); +void sane_kds_s2000w_net_control_get_option_fifteen(void** state); +void sane_kds_s2000w_net_control_get_option_sixteen(void** state); +void sane_kds_s2000w_net_control_get_option_seventeen(void** state); +void sane_kds_s2000w_net_control_get_option_eightteen(void** state); +void sane_kds_s2000w_net_control_get_option_nineteen(void** state); +void sane_kds_s2000w_net_control_get_option_twenty(void** state); +void sane_kds_s2000w_net_control_get_option_twentyone(void** state); +void sane_kds_s2000w_net_control_get_option_twentytwo(void** state); + +#endif \ No newline at end of file diff --git a/tests/kds_s2000w_net_get_opt_tests_run.c b/tests/kds_s2000w_net_get_opt_tests_run.c new file mode 100644 index 0000000..afa1041 --- /dev/null +++ b/tests/kds_s2000w_net_get_opt_tests_run.c @@ -0,0 +1,87 @@ +#include +#include +#include "kds_s2000w_net_get_opt_tests.h" +#include "kds_s2000w_client_mock.h" + +int setup_default_get_option(void** state) +{ + response* resp = kds_s2000w_client_response_init(); + resp->data = realloc(resp->data, 919); + 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(resp->data, responsedata, 919); + resp->code = 200; + resp->size = 919; + *state = resp; + return 0; +} + +int teardown_default_get_option(void** state) +{ + response* resp = (response*) *state; + kds_s2000w_client_response_free(resp); + resp = NULL; + return 0; +} + +int main() +{ + const struct CMUnitTest net_tests[] = { + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_zero, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_two, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_three, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_four, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_five, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_six, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_eight, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_nine, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_ten, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_eleven, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twelve, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_thirteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fifteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_sixteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_seventeen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_eightteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_nineteen, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twenty, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twentyone, setup_default_get_option, teardown_default_get_option), + cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twentytwo, setup_default_get_option, teardown_default_get_option), + }; + + return cmocka_run_group_tests(net_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 bac356a..0a46ab5 100644 --- a/tests/kds_s2000w_net_tests.c +++ b/tests/kds_s2000w_net_tests.c @@ -108,422 +108,6 @@ void kds_s2000w_net_get_select_fd() assert_int_equal(result, SANE_STATUS_UNSUPPORTED); } -void sane_kds_s2000w_net_control_get_option_zero(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int value = 0; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(value, 24); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_two(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - char value[50] = {0}; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 2, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_string_equal(value, "DocumentFeeder"); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_three(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - char value[50] = {0}; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 3, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_string_equal(value, "Color"); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_four(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = 0; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 4, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 200); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_five(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - char value[50] = {0}; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 5, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_string_equal(value, "Duplex"); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_six(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = 0; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 6, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 8); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_eight(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 8, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 0); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_nine(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - char value[50] = {0}; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 9, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_string_equal(value, "None"); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_ten(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 10, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 0); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_eleven(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - char value[50] = {0}; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 11, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_string_equal(value, "Automatic"); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_twelve(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - char value[50] = {0}; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 12, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_string_equal(value, "Automatic"); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_thirteen(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 13, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 0); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_fourteen(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 14, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 0); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_fifteen(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 15, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 0); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_sixteen(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 16, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 0); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_seventeen(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - char value[50] = {0}; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 17, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_string_equal(value, "None"); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_eightteen(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 18, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 0); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_nineteen(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - char value[50] = {0}; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 19, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_string_equal(value, "None"); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_twenty(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 20, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 0); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_twentyone(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 21, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 0); - - free_handler(h); - h = NULL; -} - -void sane_kds_s2000w_net_control_get_option_twentytwo(void** state) -{ - response* resp = (response*) *state; - will_return(mock_response, resp); - will_return(__wrap_kds_s2000w_client_get_option, 0); - expect_function_call(__wrap_kds_s2000w_client_get_option); - handler* h = init_handler(); - int option_num = 0; - int value = -1; - - _sane_kds_s2000w_net_control_option(h, 0, SANE_ACTION_GET_VALUE, &option_num, NULL); - _sane_kds_s2000w_net_control_option(h, 22, SANE_ACTION_GET_VALUE, &value, NULL); - - assert_int_equal(option_num, 24); - assert_int_equal(value, 140); - - free_handler(h); - h = NULL; -} void sane_kds_s2000w_net_start_cancel() { diff --git a/tests/kds_s2000w_net_tests.h b/tests/kds_s2000w_net_tests.h index e00bfd3..19a5380 100644 --- a/tests/kds_s2000w_net_tests.h +++ b/tests/kds_s2000w_net_tests.h @@ -12,27 +12,6 @@ void kds_s2000w_net_init(); void kds_s2000w_net_get_devices_only_remote(); void kds_s2000w_net_set_io_mode(); void kds_s2000w_net_get_select_fd(); -void sane_kds_s2000w_net_control_get_option_zero(void** state); -void sane_kds_s2000w_net_control_get_option_two(void** state); -void sane_kds_s2000w_net_control_get_option_three(void** state); -void sane_kds_s2000w_net_control_get_option_four(void** state); -void sane_kds_s2000w_net_control_get_option_five(void** state); -void sane_kds_s2000w_net_control_get_option_six(void** state); -void sane_kds_s2000w_net_control_get_option_eight(void** state); -void sane_kds_s2000w_net_control_get_option_nine(void** state); -void sane_kds_s2000w_net_control_get_option_ten(void** state); -void sane_kds_s2000w_net_control_get_option_eleven(void** state); -void sane_kds_s2000w_net_control_get_option_twelve(void** state); -void sane_kds_s2000w_net_control_get_option_thirteen(void** state); -void sane_kds_s2000w_net_control_get_option_fourteen(void** state); -void sane_kds_s2000w_net_control_get_option_fifteen(void** state); -void sane_kds_s2000w_net_control_get_option_sixteen(void** state); -void sane_kds_s2000w_net_control_get_option_seventeen(void** state); -void sane_kds_s2000w_net_control_get_option_eightteen(void** state); -void sane_kds_s2000w_net_control_get_option_nineteen(void** state); -void sane_kds_s2000w_net_control_get_option_twenty(void** state); -void sane_kds_s2000w_net_control_get_option_twentyone(void** state); -void sane_kds_s2000w_net_control_get_option_twentytwo(void** state); void sane_kds_s2000w_net_start_cancel(); void sane_kds_s2000w_net_start(void** state); void sane_kds_s2000w_net_start_one_page_per_flatscan(void** state); diff --git a/tests/kds_s2000w_net_tests_run.c b/tests/kds_s2000w_net_tests_run.c index d286f87..0ef32e7 100644 --- a/tests/kds_s2000w_net_tests_run.c +++ b/tests/kds_s2000w_net_tests_run.c @@ -3,60 +3,6 @@ #include "kds_s2000w_net_tests.h" #include "kds_s2000w_client_mock.h" -int setup_default_get_option(void** state) -{ - response* resp = kds_s2000w_client_response_init(); - resp->data = realloc(resp->data, 919); - 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(resp->data, responsedata, 919); - resp->code = 200; - resp->size = 919; - *state = resp; - return 0; -} - -int teardown_default_get_option(void** state) -{ - response* resp = (response*) *state; - kds_s2000w_client_response_free(resp); - resp = NULL; - return 0; -} - int setup_net_start(void** state) { response** response_list = malloc(sizeof(response*) * 3); @@ -104,27 +50,6 @@ int main() 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_setup_teardown(sane_kds_s2000w_net_control_get_option_zero, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_two, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_three, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_four, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_five, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_six, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_eight, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_nine, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_ten, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_eleven, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twelve, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_thirteen, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fourteen, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_fifteen, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_sixteen, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_seventeen, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_eightteen, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_nineteen, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twenty, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twentyone, setup_default_get_option, teardown_default_get_option), - cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_control_get_option_twentytwo, setup_default_get_option, teardown_default_get_option), 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), -- 2.39.5