--wrap,kds_s2000w_client_start_scan,\
--wrap,kds_s2000w_client_stop_scan,\
--wrap,kds_s2000w_client_open_session,\
+--wrap,kds_s2000w_client_close_session,\
--wrap,kds_s2000w_client_status_session,\
--wrap,kds_s2000w_client_get_image,\
--wrap,kds_s2000w_client_get_metadata,\
--wrap,kds_s2000w_convert_jpg_to_pnm,\
--wrap,kds_s2000w_client_delete_image,\
---wrap,load_config" CACHE STRING "test coverage compiler flags" FORCE)
+--wrap,kds_s2000w_client_set_option,\
+--wrap,load_config,\
+--wrap,usleep" CACHE STRING "test coverage compiler flags" FORCE)
ENDIF()
MESSAGE(STATUS "CMAKE_C_FLAGS " ${CMAKE_C_FLAGS})
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include "kds_s2000w_client_mock.h"
+int __wrap_usleep(__useconds_t usec)
+{
+ return 0;
+}
+
void mock_response(response* resp)
{
response* mock_resp = mock_type(response*);
return mock_type(int);
}
+int __wrap_kds_s2000w_client_set_option(int64_t sessionid, response* response)
+{
+ mock_response(response);
+ return mock_type(int);
+}
+
int __wrap_kds_s2000w_client_stop_scan(int64_t sessionid, response* response)
{
mock_response(response);
{
mock_response(response);
return mock_type(int);
+}
+
+void __wrap_kds_s2000w_client_close_session(int64_t sessionid)
+{
+ return;
}
\ No newline at end of file
void mock_response(response* resp);
int __wrap_kds_s2000w_client_get_option(int64_t sessionid, response* response);
+int __wrap_kds_s2000w_client_set_option(int64_t sessionid, response* response);
int __wrap_kds_s2000w_client_stop_scan(int64_t sessionid, response* response);
int __wrap_kds_s2000w_client_status_session(int64_t sessionid, response* response);
int __wrap_kds_s2000w_client_get_image(int64_t sessionid, int img_number, response* response);
int __wrap_kds_s2000w_client_delete_image(int64_t sessionid, int img_number, response* response);
int __wrap_kds_s2000w_client_start_scan(int64_t sessionid, response* response);
int __wrap_kds_s2000w_client_open_session(response* response);
+void __wrap_kds_s2000w_client_close_session(int64_t sessionid);
#endif
\ No newline at end of file
h = NULL;
}
+void sane_kds_s2000w_net_start_one_page_per_flatscan(void** state)
+{
+ response** response_list = (response**) *state;
+ will_return(mock_response, response_list[0]);
+ will_return(__wrap_kds_s2000w_client_start_scan, 0);
+ response* resp_status = kds_s2000w_client_response_init();
+ resp_status->data = realloc(resp_status->data, 205);
+ const char* status = "{ \
+ \"Status\": { \
+ \"NumImagesScanned\": 1, \
+ \"NumImagesStored\": 1, \
+ \"State\": \"Scanning\", \
+ \"ErrorNum\": 0, \
+ \"LastError\": \"Status: 200 Success\", \
+ \"PaperDetected\": \"0\", \
+ \"PercentAvailable\": 99 \
+ }}\0";
+ memcpy(resp_status->data, status, 205);
+ resp_status->code = 200;
+ resp_status->size = 205;
+ will_return(mock_response, resp_status);
+ will_return(__wrap_kds_s2000w_client_status_session, 0);
+ will_return(mock_response, response_list[0]);
+ will_return(__wrap_kds_s2000w_client_get_image, 0);
+ will_return(mock_response, response_list[1]);
+ will_return(__wrap_kds_s2000w_client_get_metadata, 0);
+ will_return(mock_response, response_list[0]);
+ will_return(__wrap_kds_s2000w_client_delete_image, 0);
+ response* resp_open_session = kds_s2000w_client_response_init();
+ resp_open_session->data = realloc(resp_open_session->data, 25);
+ const char* session_data = "{\"SessionId\":\"8154711\"}\0";
+ memcpy(resp_open_session->data, session_data, 25);
+ resp_open_session->code = 200;
+ resp_open_session->size = 25;
+ will_return(mock_response, resp_open_session);
+ will_return(__wrap_kds_s2000w_client_open_session, 0);
+ response* resp_set_option = kds_s2000w_client_response_init();
+ resp_set_option->code = 200;
+ will_return(mock_response, resp_set_option);
+ will_return(__wrap_kds_s2000w_client_set_option, 0);
+ handler* h = init_handler();
+ const char* test_config = "{\"Configuration\": { \"ColorMode\": \"Color\" } }";
+ h->current_scanner_config = json_tokener_parse(test_config);
+
+ int result = _sane_kds_s2000w_net_start(h);
+
+ assert_int_equal(result, SANE_STATUS_GOOD);
+ assert_int_equal(h->current_metadata->depth, 8);
+ assert_int_equal(h->current_metadata->channels, 3);
+ assert_int_equal(h->current_metadata->format, 1);
+ assert_int_equal(h->current_metadata->pixels_per_line, 1000);
+ assert_int_equal(h->current_metadata->lines, 1000);
+ assert_int_equal(h->current_metadata->valid, 1);
+ assert_int_equal(h->current_metadata->is_last, 1);
+
+ json_object_put(h->current_scanner_config);
+ h->current_scanner_config = NULL;
+ kds_s2000w_client_response_free(resp_status);
+ resp_status = NULL;
+ kds_s2000w_client_response_free(resp_open_session);
+ resp_open_session = NULL;
+ kds_s2000w_client_response_free(resp_set_option);
+ resp_set_option = NULL;
+ free_handler(h);
+ h = NULL;
+}
+
void sane_kds_s2000w_net_get_parameter_cancel()
{
handler* h = init_handler();
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 sane_kds_s2000w_net_control_get_option_two();
-void sane_kds_s2000w_net_control_get_option_three();
-void sane_kds_s2000w_net_control_get_option_four();
-void sane_kds_s2000w_net_control_get_option_five();
-void sane_kds_s2000w_net_control_get_option_six();
-void sane_kds_s2000w_net_control_get_option_eight();
-void sane_kds_s2000w_net_control_get_option_nine();
-void sane_kds_s2000w_net_control_get_option_ten();
-void sane_kds_s2000w_net_control_get_option_eleven();
-void sane_kds_s2000w_net_control_get_option_twelve();
-void sane_kds_s2000w_net_control_get_option_thirteen();
-void sane_kds_s2000w_net_control_get_option_fourteen();
-void sane_kds_s2000w_net_control_get_option_fifteen();
-void sane_kds_s2000w_net_control_get_option_sixteen();
-void sane_kds_s2000w_net_control_get_option_seventeen();
-void sane_kds_s2000w_net_control_get_option_eightteen();
-void sane_kds_s2000w_net_control_get_option_nineteen();
-void sane_kds_s2000w_net_control_get_option_twenty();
-void sane_kds_s2000w_net_control_get_option_twentyone();
-void sane_kds_s2000w_net_control_get_option_twentytwo();
+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 sane_kds_s2000w_net_start(void** state);
+void sane_kds_s2000w_net_start_one_page_per_flatscan(void** state);
void sane_kds_s2000w_net_get_parameter_cancel();
void sane_kds_s2000w_net_cancel();
void sane_kds_s2000w_net_open();
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_setup_teardown(sane_kds_s2000w_net_start, setup_net_start, teardown_net_start),
+ cmocka_unit_test_setup_teardown(sane_kds_s2000w_net_start_one_page_per_flatscan, setup_net_start, teardown_net_start),
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)