File: 03_Scanner_Profile.t

package info (click to toggle)
gscan2pdf 2.13.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,700 kB
  • sloc: perl: 22,713; xml: 81; makefile: 6
file content (160 lines) | stat: -rw-r--r-- 4,504 bytes parent folder | download | duplicates (6)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
use warnings;
use strict;
use Test::More tests => 29;
use Image::Sane ':all';    # For enums
BEGIN { use_ok('Gscan2pdf::Scanner::Profile') }

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

is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms(SANE_NAME_PAGE_HEIGHT),
    [ SANE_NAME_PAGE_HEIGHT, 'pageheight' ],
    'synonyms for SANE_NAME_PAGE_HEIGHT'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms('pageheight'),
    [ SANE_NAME_PAGE_HEIGHT, 'pageheight' ],
    'synonyms for pageheight'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms(SANE_NAME_PAGE_WIDTH),
    [ SANE_NAME_PAGE_WIDTH, 'pagewidth' ],
    'synonyms for SANE_NAME_PAGE_WIDTH'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms('pagewidth'),
    [ SANE_NAME_PAGE_WIDTH, 'pagewidth' ],
    'synonyms for pagewidth'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms(SANE_NAME_SCAN_TL_X),
    [ SANE_NAME_SCAN_TL_X, 'l' ],
    'synonyms for SANE_NAME_SCAN_TL_X'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms('l'),
    [ SANE_NAME_SCAN_TL_X, 'l' ],
    'synonyms for l'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms(SANE_NAME_SCAN_TL_Y),
    [ SANE_NAME_SCAN_TL_Y, 't' ],
    'synonyms for SANE_NAME_SCAN_TL_Y'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms('t'),
    [ SANE_NAME_SCAN_TL_Y, 't' ],
    'synonyms for t'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms(SANE_NAME_SCAN_BR_X),
    [ SANE_NAME_SCAN_BR_X, 'x' ],
    'synonyms for SANE_NAME_SCAN_BR_X'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms('x'),
    [ SANE_NAME_SCAN_BR_X, 'x' ],
    'synonyms for x'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms(SANE_NAME_SCAN_BR_Y),
    [ SANE_NAME_SCAN_BR_Y, 'y' ],
    'synonyms for SANE_NAME_SCAN_BR_Y'
);
is_deeply(
    Gscan2pdf::Scanner::Profile::_synonyms('y'),
    [ SANE_NAME_SCAN_BR_Y, 'y' ],
    'synonyms for y'
);

my $profile = Gscan2pdf::Scanner::Profile->new;
isa_ok( $profile, 'Gscan2pdf::Scanner::Profile' );
$profile->add_backend_option( 'y', '297' );
is_deeply(
    $profile->get_data,
    { backend => [ { 'y' => '297' } ] },
    'basic functionality add_backend_option'
);

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

$profile->add_backend_option( 'br-y', '297' );
is_deeply(
    $profile->get_data,
    { backend => [ { 'br-y' => '297' } ] },
    'pruned duplicate'
);

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

$profile->add_frontend_option( 'num_pages', 0 );
is_deeply(
    $profile->get_data,
    { backend => [ { 'br-y' => '297' } ], frontend => { 'num_pages' => 0 } },
    'basic functionality add_frontend_option'
);

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

$profile = Gscan2pdf::Scanner::Profile->new_from_data(
    { backend => [ { 'br-x' => '297' } ], frontend => { 'num_pages' => 1 } } );
is_deeply(
    $profile->get_data,
    { backend => [ { 'br-x' => '297' } ], frontend => { 'num_pages' => 1 } },
    'basic functionality new_from_data'
);

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

my $iter = $profile->each_frontend_option;
is( $iter->(), 'num_pages', 'basic functionality each_frontend_option' );
is( $profile->get_frontend_option('num_pages'),
    1, 'basic functionality get_frontend_option' );
is( $iter->(), undef, 'each_frontend_option returns undef when finished' );

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

$profile = Gscan2pdf::Scanner::Profile->new_from_data(
    { backend => [ { l => 1 }, { y => 50 }, { x => 50 }, { t => 2 } ] } );
is_deeply(
    $profile->get_data,
    {
        backend => [
            { 'tl-x' => 1 },
            { 'br-y' => 52 },
            { 'br-x' => 51 },
            { 'tl-y' => 2 }
        ]
    },
    'basic functionality map_from_cli'
);

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

$iter = $profile->each_backend_option;
is( $iter->(), 1, 'basic functionality each_backend_option' );
is_deeply(
    [ $profile->get_backend_option_by_index(1) ],
    [ 'tl-x', 1 ],
    'basic functionality get_backend_option_by_index'
);
is( $iter->(0), 1, 'no iteration' );
for ( 1 .. 3 ) { $iter->() }
is( $iter->(), undef, 'each_backend_option returns undef when finished' );

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

$iter = $profile->each_backend_option(1);
is( $iter->(), 4, 'basic functionality each_backend_option reverse' );
for ( 1 .. 3 ) { $iter->() }
is( $iter->(), undef,
    'each_backend_option reverse returns undef when finished' );

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

$profile->remove_backend_option_by_name('tl-x');
is_deeply(
    $profile->get_data,
    { backend => [ { 'br-y' => 52 }, { 'br-x' => 51 }, { 'tl-y' => 2 } ] },
    'basic functionality remove_backend_option_by_name'
);