File: data.t

package info (click to toggle)
libimage-sane-perl 5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 324 kB
  • sloc: perl: 2,714; ansic: 5; makefile: 3
file content (70 lines) | stat: -rw-r--r-- 1,926 bytes parent folder | download | duplicates (3)
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
use Image::Sane ':all';
use Try::Tiny;
use Test::More;
BEGIN { use_ok('Image::Sane') }

#########################

plan skip_all => 'libsane 1.0.19 or better required'
  unless Image::Sane->get_version_scalar > 1.000018;

my $test = Image::Sane::Device->open('test');

$options = $test->get_option_descriptor(10);
is( $options->{name}, 'test-picture', 'test-picture' );

my $info = $test->set_option( 10, 'Color pattern' );

my $n = $test->get_option(0);
my $read_length_zero;
if ( $n > 52 ) {
    $options = $test->get_option_descriptor(52);
    if ( $options->{name} eq 'read-length-zero' ) {
        $read_length_zero = 1;
        $info = $test->set_option( 52, SANE_TRUE );
    }
}

$options = $test->get_option_descriptor(2);

for my $mode ( @{ $options->{constraint} } ) {
    my $info = $test->set_option( 2, $mode );

    $test->start;

    my $param = $test->get_parameters;

    if ( $param->{lines} >= 0 ) {
        my $filename = "$mode.pnm";
        open my $fh, '>', $filename;
        binmode $fh;

        $test->write_pnm_header( $fh, $param );

        my ( $data, $len, $status );
        do {
            $status = SANE_STATUS_GOOD;
            try {
                ( $data, $len ) = $test->read( $param->{bytes_per_line} );
            }
            catch {
                $status = $_->status;
                ( $data, $len ) = ( undef, 0 );
            };
            is( length($data), 0, "length-zero $mode" )
              if (  $read_length_zero
                and $len == 0
                and $status == SANE_STATUS_GOOD );
            print $fh substr( $data, 0, $len ) if ($data);
        } while ( $status == SANE_STATUS_GOOD );
        is( $status, SANE_STATUS_EOF, "EOF $mode" );
        is( $data,   undef,           "EOF data $mode" );
        is( $len,    0,               "EOF len $mode" );
        unlink $filename;

        $test->cancel;
        close $fh;
    }
}

done_testing();