]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
add test for write byte length
authorBastian Dehn <hhaalo@arcor.de>
Sun, 11 Feb 2024 12:37:43 +0000 (13:37 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 11 Feb 2024 12:37:43 +0000 (13:37 +0100)
src/kds_s2000w_net.c
src/kds_s2000w_net.h [new file with mode: 0644]
tests/kds_s2000w_net_tests.c
tests/runtests.c

index ff628554faf2b492bb9b33c309f0fdc14bdf3dfc..08329081bf5dd50d30501a744cd8c3d44e85ced2 100644 (file)
@@ -1,10 +1,5 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sane/sane.h>
-#include "kds_s2000w_option_descriptors.h"
-#include "kds_s2000w_handler.h"
+
+#include "kds_s2000w_net.h"
 
 SANE_Option_Descriptor* option_descriptors = NULL;
 SANE_Device* device_info = NULL;
@@ -15,6 +10,11 @@ int scan_started = 0;
 int readed_bytes_per_line = 0;
 int readed_lines = 0;
 
+metadata* get_current_metadata()
+{
+       return &current_metadata;
+}
+
 int _sane_kds_s2000w_net_find_first_data_byte(const char* data)
 {
        const int header_spaces = 3;
@@ -243,9 +243,8 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
        SANE_Int max_length, SANE_Int* length)
 {
        printf("is all scanned: %i\n", current_metadata.scanned_all_complete);
-
        int skip_header_bytes = _sane_kds_s2000w_net_find_first_data_byte(current_metadata.image);
-
+       
        if (read_size <= 0) {
                read_size += skip_header_bytes;
        }
@@ -269,7 +268,6 @@ SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
                return SANE_STATUS_CANCELLED;
        }
 
-
        int maxlen = 0;
        if (current_metadata.bytes_per_line < max_length) {
                maxlen = current_metadata.bytes_per_line - readed_bytes_per_line;
diff --git a/src/kds_s2000w_net.h b/src/kds_s2000w_net.h
new file mode 100644 (file)
index 0000000..a344bbc
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef KDS_S2000W_NET_H
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sane/sane.h>
+#include "kds_s2000w_option_descriptors.h"
+#include "kds_s2000w_handler.h"
+
+// test helper method
+metadata* get_current_metadata();
+
+int _sane_kds_s2000w_net_find_first_data_byte(const char* data);
+SANE_Status _sane_kds_s2000w_net_init(SANE_Int* version_code, SANE_Auth_Callback authorize);
+void _sane_kds_s2000w_net_exit(void);
+SANE_Status _sane_kds_s2000w_net_get_devices(SANE_Device*** device_list,
+       SANE_Bool local_only);
+SANE_Status _sane_kds_s2000w_net_open(SANE_String_Const devicename,
+       SANE_Handle handle);
+void _sane_kds_s2000w_net_close(SANE_Handle handle);
+const SANE_Option_Descriptor* _sane_kds_s2000w_net_get_option_descriptor(
+       SANE_Handle handle, SANE_Int option);
+SANE_Status _sane_kds_s2000w_net_control_option(SANE_Handle handle,
+       SANE_Int option, SANE_Action action, void* value, SANE_Int* info);
+void _sane_kds_s2000w_net_cancel(SANE_Handle handle);
+SANE_Status _sane_kds_s2000w_net_get_parameters(SANE_Handle handle,
+       SANE_Parameters* params);
+SANE_Status _sane_kds_s2000w_net_start(SANE_Handle handle);
+SANE_Status _sane_kds_s2000w_net_read(SANE_Handle handle, SANE_Byte* data,
+       SANE_Int max_length, SANE_Int* length);
+SANE_Status _sane_kds_s2000w_net_set_io_mode(SANE_Handle handle,
+       SANE_Bool non_blocking);
+SANE_Status _sane_kds_s2000w_net_get_select_fd(SANE_Handle handle, SANE_Int* fd);
+SANE_String_Const _sane_kds_s2000w_net_strstatus(SANE_Status status);
+#endif
\ No newline at end of file
index a76de1f2f81fe8d7948f361d8bcadeba80a69bbb..69ac67551f60cde4dab28334b1b8adca3e4dd3d8 100644 (file)
@@ -1,5 +1,9 @@
 #include <check.h>
-int _sane_kds_s2000w_net_find_first_data_byte(const char* data);
+#include <stdlib.h>
+#include <sane/sane.h>
+#include "../src/kds_s2000w_net.h"
+
+
 
 START_TEST(sane_kds_s2000w_net_find_first_data_byte_test)
 {
@@ -14,4 +18,33 @@ START_TEST(sane_kds_s2000w_net_find_first_data_byte_test)
 
        ck_assert_int_eq(header_bytes, 16);
 }
+END_TEST
+
+START_TEST(_sane_kds_s2000w_net_read_test)
+{
+       metadata* current_metadata_ptr = get_current_metadata();
+       current_metadata_ptr->scanned_all_complete = 1;
+       current_metadata_ptr->lines = 1;
+       current_metadata_ptr->bytes_per_line = 65536;
+       char* image = malloc(sizeof(char) * 65536);
+       for (int i = 0; i < 65536; i++) {
+               image[i] = 0x0a;
+       }
+       current_metadata_ptr->image = image;
+
+       SANE_Int maxlen = 65536;
+       char* dataptr = malloc(sizeof(char) * maxlen);
+       SANE_Int* length = malloc(sizeof(SANE_Int));
+
+       _sane_kds_s2000w_net_read(NULL, (void*) dataptr, maxlen, length);
+
+       ck_assert_int_eq(*length, 65536);
+
+       free(dataptr);
+       dataptr = NULL;
+       free(length);
+       length = NULL;
+       free(image);
+       image = NULL;
+}
 END_TEST
\ No newline at end of file
index 72bf4dee62a6ff19015f2416a4910d13bdebb850..696908e46faf15ad7af03b7909180a85bcd00437 100644 (file)
@@ -10,6 +10,7 @@ Suite* first_tests()
 
        tc_core = tcase_create("core");
        tcase_add_test(tc_core, sane_kds_s2000w_net_find_first_data_byte_test);
+       tcase_add_test(tc_core, _sane_kds_s2000w_net_read_test);
 
        suite_add_tcase(suite, tc_core);