]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change tests with strdup
authorBastian Dehn <hhaalo@arcor.de>
Mon, 3 Feb 2025 20:38:35 +0000 (21:38 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 3 Feb 2025 20:38:35 +0000 (21:38 +0100)
tests/kds_s2000w_net_get_opt_tests_run.c
tests/kds_s2000w_net_tests.c
tests/kds_s2000w_net_tests_run.c

index 5ddc78204082eb38f22a2e0744f06f5c800335fb..2bd71ee4af250e28ad410e61d3e5fd13bfc07ac5 100644 (file)
@@ -6,7 +6,6 @@
 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, \
@@ -41,10 +40,10 @@ int setup_default_get_option(void** state)
                        \"MaxDocumentLength\": 140, \
                        \"ScanSource\": \"DocumentFeeder\" \
                } \
-       }\0";
-       memcpy(resp->data, responsedata, 919);
+       }";
+       resp->data = strdup(responsedata);
        resp->code = 200;
-       resp->size = 919;
+       resp->size = 918;
        *state = resp;
        return 0;
 }
index a2cd8c60946c3aa7fabdd8fb5f171be121ea8da8..ea110a8fd905eedf3007f634a9e1cdbb7287a97c 100644 (file)
@@ -210,7 +210,6 @@ void sane_kds_s2000w_net_start_test(void** 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\": 2, \
@@ -220,10 +219,10 @@ void sane_kds_s2000w_net_start_test(void** state)
                        \"LastError\": \"Status: 200 Success\", \
                        \"PaperDetected\": \"0\", \
                        \"PercentAvailable\": 99 \
-               }}\0";
-       memcpy(resp_status->data, status, 205);
+               }}";
+       resp_status->data = strdup(status);
        resp_status->code = 200;
-       resp_status->size = 205;
+       resp_status->size = 204;
        will_return(mock_response, resp_status);
        will_return(__wrap_kds_s2000w_client_status_session, 0);
        will_return(mock_response, response_list[2]);
@@ -257,7 +256,6 @@ void sane_kds_s2000w_net_start_one_page_per_flatscan_test(void** 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, \
@@ -267,10 +265,10 @@ void sane_kds_s2000w_net_start_one_page_per_flatscan_test(void** state)
                        \"LastError\": \"Status: 200 Success\", \
                        \"PaperDetected\": \"0\", \
                        \"PercentAvailable\": 99 \
-               }}\0";
-       memcpy(resp_status->data, status, 205);
+               }}";
+       resp_status->data = strdup(status);
        resp_status->code = 200;
-       resp_status->size = 205;
+       resp_status->size = 204;
        will_return(mock_response, resp_status);
        will_return(__wrap_kds_s2000w_client_status_session, 0);
        will_return(mock_response, response_list[2]);
@@ -305,7 +303,6 @@ void sane_kds_s2000w_net_start_one_page_per_feeder_test(void** 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, 210);
        const char* status = "{ \
                \"Status\": { \
                        \"NumImagesScanned\": 1, \
@@ -315,10 +312,10 @@ void sane_kds_s2000w_net_start_one_page_per_feeder_test(void** state)
                        \"LastError\": \"Status: 200 Success\", \
                        \"PaperDetected\": \"0\", \
                        \"PercentAvailable\": 99 \
-               }}\0";
-       memcpy(resp_status->data, status, 210);
+               }}";
+       resp_status->data = strdup(status);
        resp_status->code = 200;
-       resp_status->size = 210;
+       resp_status->size = 209;
        will_return(mock_response, resp_status);
        will_return(__wrap_kds_s2000w_client_status_session, 0);
        will_return(mock_response, response_list[2]);
@@ -355,7 +352,6 @@ void sane_kds_s2000w_net_start_two_pages_per_feeder_test(void** 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, 210);
        const char* status = "{ \
                \"Status\": { \
                        \"NumImagesScanned\": 2, \
@@ -365,10 +361,10 @@ void sane_kds_s2000w_net_start_two_pages_per_feeder_test(void** state)
                        \"LastError\": \"Status: 200 Success\", \
                        \"PaperDetected\": \"0\", \
                        \"PercentAvailable\": 99 \
-               }}\0";
-       memcpy(resp_status->data, status, 210);
+               }}";
+       resp_status->data = strdup(status);
        resp_status->code = 200;
-       resp_status->size = 210;
+       resp_status->size = 209;
        will_return(mock_response, resp_status);
        will_return(__wrap_kds_s2000w_client_status_session, 0);
        will_return(mock_response, response_list[2]);
@@ -399,9 +395,11 @@ void sane_kds_s2000w_net_start_two_pages_per_feeder_test(void** state)
                        \"PaperDetected\": \"0\", \
                        \"PercentAvailable\": 99 \
                }}\0";
-       memcpy(resp_status->data, status2, 210);
+       free(resp_status->data);
+       resp_status->data = NULL;
+       resp_status->data = strdup(status2);
        resp_status->code = 200;
-       resp_status->size = 210;
+       resp_status->size = 209;
        will_return(mock_response, resp_status);
        will_return(__wrap_kds_s2000w_client_status_session, 0);
        will_return(mock_response, response_list[2]);
@@ -430,7 +428,6 @@ void sane_kds_s2000w_net_start_two_pages_per_feeder_test(void** state)
 void sane_kds_s2000w_net_cancel_test()
 {
        response* resp_status = kds_s2000w_client_response_init();
-       resp_status->data = realloc(resp_status->data, 205);
        const char* status = "{ \
                \"Status\": { \
                        \"NumImagesScanned\": 2, \
@@ -440,10 +437,10 @@ void sane_kds_s2000w_net_cancel_test()
                        \"LastError\": \"Status: 200 Success\", \
                        \"PaperDetected\": \"0\", \
                        \"PercentAvailable\": 99 \
-               }}\0";
-       memcpy(resp_status->data, status, 205);
+               }}";
+       resp_status->data = strdup(status);
        resp_status->code = 200;
-       resp_status->size = 205;
+       resp_status->size = 204;
        will_return(mock_response, resp_status);
        will_return(__wrap_kds_s2000w_client_status_session, 0);
        response* resp = kds_s2000w_client_response_init();
@@ -484,9 +481,8 @@ void sane_kds_s2000w_net_cancel_start_test()
 void sane_kds_s2000w_net_cancel_canceled_test()
 {
        response* resp_status = kds_s2000w_client_response_init();
-       resp_status->data = realloc(resp_status->data, 27);
        const char* status = "{\"SessionId\":\"1251877821\"}";
-       memcpy(resp_status->data, status, 27);
+       resp_status->data = strdup(status);
        resp_status->code = 200;
        resp_status->size = 27;
        will_return(mock_response, resp_status);
@@ -517,7 +513,6 @@ void sane_kds_s2000w_net_cancel_canceled_test()
 void sane_kds_s2000w_net_cancel_completed_scan_feeder_test()
 {
        response* resp_status = kds_s2000w_client_response_init();
-       resp_status->data = realloc(resp_status->data, 210);
        const char* status = "{ \
                \"Status\": { \
                        \"NumImagesScanned\": 2, \
@@ -527,10 +522,10 @@ void sane_kds_s2000w_net_cancel_completed_scan_feeder_test()
                        \"LastError\": \"Status: 200 Success\", \
                        \"PaperDetected\": \"0\", \
                        \"PercentAvailable\": 99 \
-               }}\0";
-       memcpy(resp_status->data, status, 210);
+               }}";
+       resp_status->data = strdup(status);
        resp_status->code = 200;
-       resp_status->size = 210;
+       resp_status->size = 209;
        will_return(mock_response, resp_status);
        will_return(__wrap_kds_s2000w_client_status_session, 0);
        expect_function_call(__wrap_kds_s2000w_client_status_session);
@@ -551,7 +546,6 @@ void sane_kds_s2000w_net_cancel_completed_scan_feeder_test()
 void sane_kds_s2000w_net_cancel_completed_scan_flatbed_test()
 {
        response* resp_status = kds_s2000w_client_response_init();
-       resp_status->data = realloc(resp_status->data, 205);
        const char* status = "{ \
                \"Status\": { \
                        \"NumImagesScanned\": 2, \
@@ -561,16 +555,15 @@ void sane_kds_s2000w_net_cancel_completed_scan_flatbed_test()
                        \"LastError\": \"Status: 200 Success\", \
                        \"PaperDetected\": \"0\", \
                        \"PercentAvailable\": 99 \
-               }}\0";
-       memcpy(resp_status->data, status, 205);
+               }}";
+       resp_status->data = strdup(status);
        resp_status->code = 200;
-       resp_status->size = 205;
+       resp_status->size = 204;
        will_return(mock_response, resp_status);
        will_return(__wrap_kds_s2000w_client_status_session, 0);
        response* resp_session = kds_s2000w_client_response_init();
-       resp_session->data = realloc(resp_session->data, 27);
        const char* responsedata = "{\"SessionId\":\"1251877821\"}";
-       memcpy(resp_session->data, responsedata, 27);
+       resp_session->data = strdup(responsedata);
        resp_session->code = 200;
        resp_session->size = 27;
        will_return(mock_response, resp_session);
index 665bcf382c6b5afb22e578e7bb6f52631576cf8a..e8386959e4e5d7535e80209b3241efd487a03ea1 100644 (file)
@@ -9,7 +9,6 @@ int setup(void** state)
        response_list[0] = kds_s2000w_client_response_init();
        response_list[0]->code = 200;
        response_list[1] = kds_s2000w_client_response_init();
-       response_list[1]->data = realloc(response_list[1]->data, 107);
        const char* metadata = "{\
                \"Metadata\": {\
                        \"BitDepth\": 8, \
@@ -17,14 +16,14 @@ int setup(void** state)
                        \"ImageWidth\": 1920, \
                        \"ImageHeight\": 1080, \
                }\
-       }\0";
-       memcpy(response_list[1]->data, metadata, 107);
+       }";
+       response_list[1]->data = strdup(metadata);
        response_list[1]->code = 200;
-       response_list[1]->size = 107;
+       response_list[1]->size = 106;
        response_list[2] = kds_s2000w_client_response_init();
        response_list[2]->code = 200;
        response_list[2]->size = 17;
-       response_list[2]->data = realloc(response_list[2]->data, 17);
+       response_list[2]->data = malloc(sizeof(char) * 17);
        char* image_data = (char*) response_list[2]->data;
        image_data[0] = 0x50;
        image_data[1] = 0x36;