1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
use Image::Sane ':all';
use Try::Tiny;
use Test::More tests => 14;
BEGIN { use_ok('Image::Sane') }
#########################
SKIP: {
skip "libsane 1.0.19 or better required", 13
unless Image::Sane->get_version_scalar > 1.000018;
my ( $test, $info, $param, $fd );
try {
$test = Image::Sane::Device->open('test');
pass 'opening test backend';
}
catch {
fail 'opening test backend';
};
$options = $test->get_option_descriptor(10);
is( $options->{name}, 'test-picture', 'test-picture' );
try {
$info = $test->set_option( 10, 'Color pattern' );
pass 'Color pattern';
}
catch {
fail 'Color pattern';
};
try {
$info = $test->set_option( 19, SANE_TRUE );
pass 'non-blocking';
}
catch {
fail 'non-blocking';
};
try {
$info = $test->set_option( 20, SANE_TRUE );
pass 'fd option';
}
catch {
fail 'fd option';
};
try {
$test->start;
pass 'start';
}
catch {
fail 'start';
};
try {
$test->set_io_mode(SANE_TRUE);
pass 'non-blocking';
}
catch {
fail 'non-blocking';
};
try {
$fd = $test->get_select_fd;
pass 'fd option';
}
catch {
fail 'fd option';
};
try {
$param = $test->get_parameters;
pass 'get_parameters';
}
catch {
fail 'get_parameters';
};
if ( $param->{lines} >= 0 ) {
my $filename = 'fd.pnm';
open my $fh, '>', $filename;
binmode $fh;
my ( $data, $len );
my $rin = '';
my $rout = '';
vec( $rin, $fd, 1 ) = 1;
my $i = 1;
my $status = SANE_STATUS_GOOD;
do {
select( $rout = $rin, undef, undef, undef );
try {
( $data, $len ) = $test->read( $param->{bytes_per_line} );
}
catch {
$status = $_->status;
( $data, $len ) = ( undef, 0 );
};
print $fh substr( $data, 0, $len ) if ($data);
} while ( $status == SANE_STATUS_GOOD );
is( $status, SANE_STATUS_EOF, 'EOF' );
is( $data, undef, 'EOF data' );
is( $len, 0, 'EOF len' );
$test->cancel;
close $fh;
is( -s $filename, $param->{bytes_per_line} * $param->{lines},
'image size' );
unlink $filename;
}
}
|