handler* h = (handler*) handle;
- // calc max length
+ // max length
*length = h->image->size - h->read_info->read_size;
if (*length > max_length)
*length = max_length;
// read image
- if (h->image->data != NULL && h->read_info->read_size <= 0)
- h->read_info->read_size += _sane_kds_s2000w_net_find_first_data_byte(h->image);
-
if (h->read_info->read_size < h->image->size) {
memcpy(data, h->image->data + h->read_info->read_size, *length);
h->read_info->read_size += *length;
h = NULL;
}
-void sane_kds_s2000w_net_read_without_header_test()
+void sane_kds_s2000w_net_read_test()
{
handler* h = init_handler();
h->image->size = 65536;
char* dataptr = malloc(sizeof(char) * maxlen);
SANE_Int* length = malloc(sizeof(SANE_Int));
- SANE_Status status = _sane_kds_s2000w_net_read(h, (void*) dataptr, maxlen, length);
-
- assert_int_equal(*length, 0);
- assert_null(h->image->data);
- assert_int_equal(h->read_info->read_size, 65536);
- assert_int_equal(status, SANE_STATUS_EOF);
-
- free(dataptr);
- dataptr = NULL;
- free(length);
- length = NULL;
- free(h->image->data);
- h->image->data = NULL;
- free_handler(h);
- h = NULL;
-}
-
-void sane_kds_s2000w_net_read_test()
-{
- handler* h = init_handler();
- h->image->size = 65539;
- h->image->data = malloc(sizeof(char) * 65539);
- char* imagedata = (char*) h->image->data;
- for (int i = 0; i < 3; i++) {
- imagedata[i] = 0x0a;
- }
- for (int i = 3; i < 65539; i++) {
- imagedata[i] = 0xff;
- }
-
- SANE_Int maxlen = 65536;
- char* dataptr = malloc(sizeof(char) * maxlen);
- SANE_Int* length = malloc(sizeof(SANE_Int));
-
_sane_kds_s2000w_net_read(h, (void*) dataptr, maxlen, length);
assert_int_equal(*length, 65536);
- assert_memory_equal(dataptr, h->image->data + 3, 65536);
- assert_int_equal(h->read_info->read_size, 65539);
-
- free(dataptr);
- dataptr = NULL;
- free(length);
- length = NULL;
- free(h->image->data);
- h->image->data = NULL;
- free_handler(h);
- h = NULL;
-}
-
-void sane_kds_s2000w_net_read_bw_test()
-{
- handler* h = init_handler();
- h->image->size = 65540;
- h->image->data = malloc(sizeof(char) * 65540);
- char* imagedata = (char*) h->image->data;
- imagedata[0] = 'P';
- imagedata[1] = '4';
- for (int i = 2; i < 4; i++) {
- imagedata[i] = 0x0a;
- }
- for (int i = 4; i < 65540; i++) {
- imagedata[i] = 0xff;
- }
-
- SANE_Int maxlen = 65536;
- char* dataptr = malloc(sizeof(char) * maxlen);
- SANE_Int* length = malloc(sizeof(SANE_Int));
-
- _sane_kds_s2000w_net_read(h, (void*) dataptr, maxlen, length);
-
- assert_int_equal(*length, 65536);
- assert_memory_equal(dataptr, h->image->data + 4, 65536);
- assert_int_equal(h->read_info->read_size, 65540);
+ assert_memory_equal(dataptr, h->image->data, 65536);
+ assert_int_equal(h->read_info->read_size, 65536);
free(dataptr);
dataptr = NULL;