summaryrefslogtreecommitdiff
path: root/backend/test.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2023-02-12 17:36:10 +0100
committerJörg Frings-Fürst <debian@jff.email>2023-02-12 17:36:10 +0100
commite0d94cf4d39395df1e2c6bb4d967200298c13881 (patch)
treebe5c7cace6697afc753c152d13ad5145d0884a42 /backend/test.c
parent527bedac30eb120915718eb7997e6dacd583512e (diff)
parent84357741a6a6e6430f199b2c3f7498e0e97da9ad (diff)
Update upstream source from tag 'upstream/1.2.1'
Update to upstream version '1.2.1' with Debian dir a9bb43f754a5c9a361b076af3635cc767b7e652e
Diffstat (limited to 'backend/test.c')
-rw-r--r--backend/test.c172
1 files changed, 103 insertions, 69 deletions
diff --git a/backend/test.c b/backend/test.c
index 3c7a949..ea73290 100644
--- a/backend/test.c
+++ b/backend/test.c
@@ -391,11 +391,11 @@ init_options (Test_Device * test_device)
od->desc = SANE_DESC_SCAN_MODE;
od->type = SANE_TYPE_STRING;
od->unit = SANE_UNIT_NONE;
- od->size = max_string_size (mode_list);
+ od->size = (SANE_Int) max_string_size (mode_list);
od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
od->constraint_type = SANE_CONSTRAINT_STRING_LIST;
od->constraint.string_list = mode_list;
- test_device->val[opt_mode].s = malloc (od->size);
+ test_device->val[opt_mode].s = malloc ((size_t) od->size);
if (!test_device->val[opt_mode].s)
goto fail;
strcpy (test_device->val[opt_mode].s, init_mode);
@@ -454,7 +454,7 @@ init_options (Test_Device * test_device)
od->desc = SANE_I18N ("Set the order of frames in three-pass color mode.");
od->type = SANE_TYPE_STRING;
od->unit = SANE_UNIT_NONE;
- od->size = max_string_size (order_list);
+ od->size = (SANE_Int) max_string_size (order_list);
od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
if (strcmp (init_mode, SANE_VALUE_SCAN_MODE_COLOR) != 0)
od->cap |= SANE_CAP_INACTIVE;
@@ -462,7 +462,7 @@ init_options (Test_Device * test_device)
od->cap |= SANE_CAP_INACTIVE;
od->constraint_type = SANE_CONSTRAINT_STRING_LIST;
od->constraint.string_list = order_list;
- test_device->val[opt_three_pass_order].s = malloc (od->size);
+ test_device->val[opt_three_pass_order].s = malloc ((size_t) od->size);
if (!test_device->val[opt_three_pass_order].s)
goto fail;
strcpy (test_device->val[opt_three_pass_order].s, init_three_pass_order);
@@ -487,11 +487,11 @@ init_options (Test_Device * test_device)
od->desc = SANE_I18N("If Automatic Document Feeder is selected, the feeder will be 'empty' after 10 scans.");
od->type = SANE_TYPE_STRING;
od->unit = SANE_UNIT_NONE;
- od->size = max_string_size (source_list);
+ od->size = (SANE_Int) max_string_size (source_list);
od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
od->constraint_type = SANE_CONSTRAINT_STRING_LIST;
od->constraint.string_list = source_list;
- test_device->val[opt_scan_source].s = malloc (od->size);
+ test_device->val[opt_scan_source].s = malloc ((size_t) od->size);
if (!test_device->val[opt_scan_source].s)
goto fail;
strcpy (test_device->val[opt_scan_source].s, init_scan_source);
@@ -523,11 +523,11 @@ init_options (Test_Device * test_device)
"height of 10 mm per square.");
od->type = SANE_TYPE_STRING;
od->unit = SANE_UNIT_NONE;
- od->size = max_string_size (test_picture_list);
+ od->size = (SANE_Int) max_string_size (test_picture_list);
od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
od->constraint_type = SANE_CONSTRAINT_STRING_LIST;
od->constraint.string_list = test_picture_list;
- test_device->val[opt_test_picture].s = malloc (od->size);
+ test_device->val[opt_test_picture].s = malloc ((size_t) od->size);
if (!test_device->val[opt_test_picture].s)
goto fail;
strcpy (test_device->val[opt_test_picture].s, init_test_picture);
@@ -618,11 +618,11 @@ init_options (Test_Device * test_device)
"codes are for testing how the frontend handles them.");
od->type = SANE_TYPE_STRING;
od->unit = SANE_UNIT_NONE;
- od->size = max_string_size (read_status_code_list);
+ od->size = (SANE_Int) max_string_size (read_status_code_list);
od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
od->constraint_type = SANE_CONSTRAINT_STRING_LIST;
od->constraint.string_list = read_status_code_list;
- test_device->val[opt_read_status_code].s = malloc (od->size);
+ test_device->val[opt_read_status_code].s = malloc ((size_t) od->size);
if (!test_device->val[opt_read_status_code].s)
goto fail;
strcpy (test_device->val[opt_read_status_code].s, init_read_status_code);
@@ -914,8 +914,8 @@ init_options (Test_Device * test_device)
/* opt_int */
od = &test_device->opt[opt_int];
od->name = "int";
- od->title = SANE_I18N ("(1/6) Int");
- od->desc = SANE_I18N ("(1/6) Int test option with no unit and no "
+ od->title = SANE_I18N ("(1/7) Int");
+ od->desc = SANE_I18N ("(1/7) Int test option with no unit and no "
"constraint set.");
od->type = SANE_TYPE_INT;
od->unit = SANE_UNIT_NONE;
@@ -930,8 +930,8 @@ init_options (Test_Device * test_device)
/* opt_int_constraint_range */
od = &test_device->opt[opt_int_constraint_range];
od->name = "int-constraint-range";
- od->title = SANE_I18N ("(2/6) Int constraint range");
- od->desc = SANE_I18N ("(2/6) Int test option with unit pixel and "
+ od->title = SANE_I18N ("(2/7) Int constraint range");
+ od->desc = SANE_I18N ("(2/7) Int test option with unit pixel and "
"constraint range set. Minimum is 4, maximum 192, and "
"quant is 2.");
od->type = SANE_TYPE_INT;
@@ -947,8 +947,8 @@ init_options (Test_Device * test_device)
/* opt_int_constraint_word_list */
od = &test_device->opt[opt_int_constraint_word_list];
od->name = "int-constraint-word-list";
- od->title = SANE_I18N ("(3/6) Int constraint word list");
- od->desc = SANE_I18N ("(3/6) Int test option with unit bits and "
+ od->title = SANE_I18N ("(3/7) Int constraint word list");
+ od->desc = SANE_I18N ("(3/7) Int test option with unit bits and "
"constraint word list set.");
od->type = SANE_TYPE_INT;
od->unit = SANE_UNIT_BIT;
@@ -963,8 +963,8 @@ init_options (Test_Device * test_device)
/* opt_int_array */
od = &test_device->opt[opt_int_array];
od->name = "int-constraint-array";
- od->title = SANE_I18N ("(4/6) Int array");
- od->desc = SANE_I18N ("(4/6) Int test option with unit mm and using "
+ od->title = SANE_I18N ("(4/7) Int array");
+ od->desc = SANE_I18N ("(4/7) Int test option with unit mm and using "
"an array without constraints.");
od->type = SANE_TYPE_INT;
od->unit = SANE_UNIT_MM;
@@ -979,8 +979,8 @@ init_options (Test_Device * test_device)
/* opt_int_array_constraint_range */
od = &test_device->opt[opt_int_array_constraint_range];
od->name = "int-constraint-array-constraint-range";
- od->title = SANE_I18N ("(5/6) Int array constraint range");
- od->desc = SANE_I18N ("(5/6) Int test option with unit dpi and using "
+ od->title = SANE_I18N ("(5/7) Int array constraint range");
+ od->desc = SANE_I18N ("(5/7) Int test option with unit dpi and using "
"an array with a range constraint. Minimum is 4, "
"maximum 192, and quant is 2.");
od->type = SANE_TYPE_INT;
@@ -994,6 +994,40 @@ init_options (Test_Device * test_device)
test_device->val[opt_int_array_constraint_range].wa =
&int_array_constraint_range[0];
+ /* opt_int_array_constraint_word_list */
+ od = &test_device->opt[opt_int_array_constraint_word_list];
+ od->name = "int-constraint-array-constraint-word-list";
+ od->title = SANE_I18N ("(6/7) Int array constraint word list");
+ od->desc = SANE_I18N ("(6/7) Int test option with unit percent and using "
+ "an array with a word list constraint.");
+ od->type = SANE_TYPE_INT;
+ od->unit = SANE_UNIT_PERCENT;
+ od->size = 6 * sizeof (SANE_Word);
+ od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED;
+ if (init_enable_test_options == SANE_FALSE)
+ od->cap |= SANE_CAP_INACTIVE;
+ od->constraint_type = SANE_CONSTRAINT_WORD_LIST;
+ od->constraint.word_list = int_constraint_word_list;
+ test_device->val[opt_int_array_constraint_word_list].wa =
+ &int_array_constraint_word_list[0];
+
+ /* opt_int_inexact */
+ od = &test_device->opt[opt_int_inexact];
+ od->name = "int-inexact";
+ od->title = SANE_I18N ("(7/7) Int inexact");
+ od->desc = SANE_I18N ("(7/7) Int test option that modifies the value "
+ "and returns SANE_INFO_INEXACT.");
+ od->type = SANE_TYPE_INT;
+ od->unit = SANE_UNIT_NONE;
+ od->size = sizeof (SANE_Word);
+ od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED;
+ if (init_enable_test_options == SANE_FALSE)
+ od->cap |= SANE_CAP_INACTIVE;
+ od->constraint_type = SANE_CONSTRAINT_NONE;
+ od->constraint.range = 0;
+ test_device->val[opt_int_inexact].w = 67;
+
+
/* opt_gamma_red */
init_gamma_table(gamma_red, GAMMA_RED_SIZE, gamma_range.max);
od = &test_device->opt[opt_gamma_red];
@@ -1051,23 +1085,6 @@ init_options (Test_Device * test_device)
od->constraint.range = &gamma_range;
test_device->val[opt_gamma_all].wa = &gamma_all[0];
- /* opt_int_array_constraint_word_list */
- od = &test_device->opt[opt_int_array_constraint_word_list];
- od->name = "int-constraint-array-constraint-word-list";
- od->title = SANE_I18N ("(6/6) Int array constraint word list");
- od->desc = SANE_I18N ("(6/6) Int test option with unit percent and using "
- "an array with a word list constraint.");
- od->type = SANE_TYPE_INT;
- od->unit = SANE_UNIT_PERCENT;
- od->size = 6 * sizeof (SANE_Word);
- od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT | SANE_CAP_ADVANCED;
- if (init_enable_test_options == SANE_FALSE)
- od->cap |= SANE_CAP_INACTIVE;
- od->constraint_type = SANE_CONSTRAINT_WORD_LIST;
- od->constraint.word_list = int_constraint_word_list;
- test_device->val[opt_int_array_constraint_word_list].wa =
- &int_array_constraint_word_list[0];
-
/* opt_fixed_group */
od = &test_device->opt[opt_fixed_group];
od->name = "";
@@ -1150,13 +1167,13 @@ init_options (Test_Device * test_device)
od->desc = SANE_I18N ("(1/3) String test option without constraint.");
od->type = SANE_TYPE_STRING;
od->unit = SANE_UNIT_NONE;
- od->size = strlen (init_string) + 1;
+ od->size = (SANE_Int) strlen (init_string) + 1;
od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
if (init_enable_test_options == SANE_FALSE)
od->cap |= SANE_CAP_INACTIVE;
od->constraint_type = SANE_CONSTRAINT_NONE;
od->constraint.string_list = 0;
- test_device->val[opt_string].s = malloc (od->size);
+ test_device->val[opt_string].s = malloc ((size_t) od->size);
if (!test_device->val[opt_string].s)
goto fail;
strcpy (test_device->val[opt_string].s, init_string);
@@ -1169,13 +1186,13 @@ init_options (Test_Device * test_device)
"constraint.");
od->type = SANE_TYPE_STRING;
od->unit = SANE_UNIT_NONE;
- od->size = max_string_size (string_constraint_string_list);
+ od->size = (SANE_Int) max_string_size (string_constraint_string_list);
od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
if (init_enable_test_options == SANE_FALSE)
od->cap |= SANE_CAP_INACTIVE;
od->constraint_type = SANE_CONSTRAINT_STRING_LIST;
od->constraint.string_list = string_constraint_string_list;
- test_device->val[opt_string_constraint_string_list].s = malloc (od->size);
+ test_device->val[opt_string_constraint_string_list].s = malloc ((size_t) od->size);
if (!test_device->val[opt_string_constraint_string_list].s)
goto fail;
strcpy (test_device->val[opt_string_constraint_string_list].s,
@@ -1189,14 +1206,14 @@ init_options (Test_Device * test_device)
"constraint. Contains some more entries...");
od->type = SANE_TYPE_STRING;
od->unit = SANE_UNIT_NONE;
- od->size = max_string_size (string_constraint_long_string_list);
+ od->size = (SANE_Int) max_string_size (string_constraint_long_string_list);
od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
if (init_enable_test_options == SANE_FALSE)
od->cap |= SANE_CAP_INACTIVE;
od->constraint_type = SANE_CONSTRAINT_STRING_LIST;
od->constraint.string_list = string_constraint_long_string_list;
test_device->val[opt_string_constraint_long_string_list].s =
- malloc (od->size);
+ malloc ((size_t) od->size);
if (!test_device->val[opt_string_constraint_long_string_list].s)
goto fail;
strcpy (test_device->val[opt_string_constraint_long_string_list].s,
@@ -1419,7 +1436,8 @@ static SANE_Status
reader_process (Test_Device * test_device, SANE_Int fd)
{
SANE_Status status;
- SANE_Word byte_count = 0, bytes_total;
+ size_t byte_count = 0;
+ size_t bytes_total;
SANE_Byte *buffer = 0;
ssize_t bytes_written = 0;
size_t buffer_size = 0, write_count = 0;
@@ -1427,24 +1445,24 @@ reader_process (Test_Device * test_device, SANE_Int fd)
DBG (2, "(child) reader_process: test_device=%p, fd=%d\n",
(void *) test_device, fd);
- bytes_total = test_device->lines * test_device->bytes_per_line;
+ bytes_total = (size_t) test_device->lines * (size_t) test_device->bytes_per_line;
status = init_picture_buffer (test_device, &buffer, &buffer_size);
if (status != SANE_STATUS_GOOD)
return status;
DBG (2, "(child) reader_process: buffer=%p, buffersize=%lu\n",
- buffer, (u_long) buffer_size);
+ (void *) buffer, (u_long) buffer_size);
while (byte_count < bytes_total)
{
if (write_count == 0)
{
write_count = buffer_size;
- if (byte_count + (SANE_Word) write_count > bytes_total)
- write_count = bytes_total - byte_count;
+ if (byte_count + (size_t) write_count > bytes_total)
+ write_count = (size_t) bytes_total - (size_t) byte_count;
if (test_device->val[opt_read_delay].w == SANE_TRUE)
- usleep (test_device->val[opt_read_delay_duration].w);
+ usleep ((useconds_t) test_device->val[opt_read_delay_duration].w);
}
bytes_written = write (fd, buffer, write_count);
if (bytes_written < 0)
@@ -1453,17 +1471,17 @@ reader_process (Test_Device * test_device, SANE_Int fd)
strerror (errno));
return SANE_STATUS_IO_ERROR;
}
- byte_count += bytes_written;
- DBG (4, "(child) reader_process: wrote %ld bytes of %lu (%d total)\n",
- (long) bytes_written, (u_long) write_count, byte_count);
- write_count -= bytes_written;
+ byte_count += (size_t) bytes_written;
+ DBG (4, "(child) reader_process: wrote %ld bytes of %lu (%zu total)\n",
+ bytes_written, write_count, byte_count);
+ write_count -= (size_t) bytes_written;
}
free (buffer);
if (sanei_thread_is_forked ())
{
- DBG (4, "(child) reader_process: finished, wrote %d bytes, expected %d "
+ DBG (4, "(child) reader_process: finished, wrote %zu bytes, expected %zu "
"bytes, now waiting\n", byte_count, bytes_total);
while (SANE_TRUE)
sleep (10);
@@ -1472,7 +1490,7 @@ reader_process (Test_Device * test_device, SANE_Int fd)
}
else
{
- DBG (4, "(child) reader_process: finished, wrote %d bytes, expected %d "
+ DBG (4, "(child) reader_process: finished, wrote %zu bytes, expected %zu "
"bytes\n", byte_count, bytes_total);
}
return SANE_STATUS_GOOD;
@@ -1824,7 +1842,7 @@ sane_init (SANE_Int * __sane_unused__ version_code, SANE_Auth_Callback __sane_un
/* create devices */
sane_device_list =
- malloc ((init_number_of_devices + 1) * sizeof (sane_device));
+ malloc ((size_t) (init_number_of_devices + 1) * sizeof (sane_device));
if (!sane_device_list)
goto fail;
for (num = 0; num < init_number_of_devices; num++)
@@ -1862,7 +1880,7 @@ sane_init (SANE_Int * __sane_unused__ version_code, SANE_Auth_Callback __sane_un
}
test_device->next = 0;
sane_device_list[num] = 0;
- srand (time (NULL));
+ srand ((unsigned int) time (NULL));
random_factor = ((double) rand ()) / RAND_MAX + 0.5;
inited = SANE_TRUE;
return SANE_STATUS_GOOD;
@@ -2216,6 +2234,19 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
DBG (4, "sane_control_option: set option %d (%s) to %d\n",
option, test_device->opt[option].name, *(SANE_Int *) value);
break;
+ case opt_int_inexact:
+ if (test_device->val[option].w == *(SANE_Int *) value)
+ {
+ DBG (4, "sane_control_option: option %d (%s) not changed\n",
+ option, test_device->opt[option].name);
+ break;
+ }
+ *(SANE_Int *) value += 1;
+ test_device->val[option].w = *(SANE_Int *) value;
+ myinfo |= SANE_INFO_INEXACT;
+ DBG (4, "sane_control_option: set option %d (%s) to %d\n",
+ option, test_device->opt[option].name, *(SANE_Int *) value);
+ break;
case opt_fuzzy_parameters: /* Bool with parameter reloading */
if (test_device->val[option].w == *(SANE_Bool *) value)
{
@@ -2312,7 +2343,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
case opt_gamma_all:
case opt_int_array_constraint_word_list:
memcpy (test_device->val[option].wa, value,
- test_device->opt[option].size);
+ (size_t) test_device->opt[option].size);
DBG (4, "sane_control_option: set option %d (%s) to %p\n",
option, test_device->opt[option].name, (void *) value);
if (option == opt_gamma_all) {
@@ -2535,6 +2566,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
case opt_ppl_loss:
case opt_read_delay_duration:
case opt_int:
+ case opt_int_inexact:
case opt_int_constraint_range:
case opt_int_constraint_word_list:
*(SANE_Int *) value = test_device->val[option].w;
@@ -2549,7 +2581,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
case opt_gamma_all:
case opt_int_array_constraint_word_list:
memcpy (value, test_device->val[option].wa,
- test_device->opt[option].size);
+ (size_t) test_device->opt[option].size);
DBG (4, "sane_control_option: get option %d (%s), value=%p\n",
option, test_device->opt[option].name, (void *) value);
break;
@@ -2639,7 +2671,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
p->lines = test_device->lines;
if (test_device->val[opt_fuzzy_parameters].w == SANE_TRUE
&& test_device->scanning == SANE_FALSE)
- p->lines *= random_factor;
+ p->lines *= (SANE_Int) random_factor;
}
if (strcmp (mode, SANE_VALUE_SCAN_MODE_GRAY) == 0)
@@ -2674,7 +2706,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
p->pixels_per_line = (SANE_Int) (res * (br_x - tl_x) / MM_PER_INCH);
if (test_device->val[opt_fuzzy_parameters].w == SANE_TRUE
&& test_device->scanning == SANE_FALSE)
- p->pixels_per_line *= random_factor;
+ p->pixels_per_line *= (SANE_Int) random_factor;
if (p->pixels_per_line < 1)
p->pixels_per_line = 1;
@@ -2842,11 +2874,11 @@ sane_read (SANE_Handle handle, SANE_Byte * data,
SANE_Int max_scan_length;
ssize_t bytes_read;
size_t read_count;
- SANE_Int bytes_total = test_device->lines * test_device->bytes_per_line;
+ size_t bytes_total = (size_t) test_device->lines * (size_t) test_device->bytes_per_line;
DBG (4, "sane_read: handle=%p, data=%p, max_length = %d, length=%p\n",
- handle, data, max_length, (void *) length);
+ handle, (void *) data, max_length, (void *) length);
if (!inited)
{
DBG (1, "sane_read: not inited, call sane_init() first\n");
@@ -2927,11 +2959,11 @@ sane_read (SANE_Handle handle, SANE_Byte * data,
DBG (1, "sane_read: not scanning (call sane_start first)\n");
return SANE_STATUS_INVAL;
}
- read_count = max_scan_length;
+ read_count = (size_t) max_scan_length;
bytes_read = read (test_device->pipe, data, read_count);
if (bytes_read == 0
- || (bytes_read + test_device->bytes_total >= bytes_total))
+ || ((size_t) bytes_read + (size_t) test_device->bytes_total >= bytes_total))
{
SANE_Status status;
DBG (2, "sane_read: EOF reached\n");
@@ -2966,11 +2998,11 @@ sane_read (SANE_Handle handle, SANE_Byte * data,
return SANE_STATUS_IO_ERROR;
}
}
- *length = bytes_read;
- test_device->bytes_total += bytes_read;
+ *length = (SANE_Int) bytes_read;
+ test_device->bytes_total += (size_t) bytes_read;
- DBG (2, "sane_read: read %ld bytes of %d, total %d\n", (long) bytes_read,
- max_scan_length, test_device->bytes_total);
+ DBG (2, "sane_read: read %zu bytes of %zu, total %zu\n", (size_t) bytes_read,
+ (size_t) max_scan_length, (size_t) test_device->bytes_total);
return SANE_STATUS_GOOD;
}
@@ -3051,6 +3083,7 @@ sane_set_io_mode (SANE_Handle handle, SANE_Bool non_blocking)
}
else
{
+ DBG (1, "sane_set_io_mode: unsupported\n");
if (non_blocking)
return SANE_STATUS_UNSUPPORTED;
}
@@ -3089,5 +3122,6 @@ sane_get_select_fd (SANE_Handle handle, SANE_Int * fd)
*fd = test_device->pipe;
return SANE_STATUS_GOOD;
}
+ DBG(1,"sane_get_select_fd: unsupported\n");
return SANE_STATUS_UNSUPPORTED;
}