3
use Test::More tests => 27;
6
use_ok('Gscan2pdf::Frontend::CLI');
9
#########################
11
Glib::set_application_name('gscan2pdf');
12
use Log::Log4perl qw(:easy);
13
Log::Log4perl->easy_init($WARN);
14
my $logger = Log::Log4perl::get_logger;
15
Gscan2pdf::Frontend::CLI->setup($logger);
17
#########################
20
'0','test:0','Noname','frontend-tester','virtual device'
21
'1','test:1','Noname','frontend-tester','virtual device'
25
Gscan2pdf::Frontend::CLI->parse_device_list($output),
29
'model' => 'frontend-tester',
30
'type' => 'virtual device',
35
'model' => 'frontend-tester',
36
'type' => 'virtual device',
40
"basic parse_device_list functionality"
43
#########################
45
is_deeply( Gscan2pdf::Frontend::CLI->parse_device_list(''),
46
[], "parse_device_list no devices" );
48
#########################
50
my $loop = Glib::MainLoop->new;
51
Gscan2pdf::Frontend::CLI::_watch_cmd(
52
cmd => 'echo hello stdout',
53
started_callback => sub {
54
ok( 1, 'started watching only stdout' );
58
is( $output, "hello stdout\n", 'stdout watching only stdout' );
60
finished_callback => sub {
61
my ( $output, $error ) = @_;
62
is( $output, "hello stdout\n", 'stdout finished watching only stdout' );
63
is( $error, undef, 'stderr finished watching only stdout' );
69
#########################
71
$loop = Glib::MainLoop->new;
72
Gscan2pdf::Frontend::CLI::_watch_cmd(
73
cmd => 'echo hello stderr 1>&2',
74
started_callback => sub {
75
ok( 1, 'started watching only stderr' );
79
is( $output, "hello stderr\n", 'stderr watching only stderr' );
81
finished_callback => sub {
82
my ( $output, $error ) = @_;
83
is( $output, undef, 'stdout finished watching only stderr' );
84
is( $error, "hello stderr\n", 'stderr finished watching only stderr' );
90
#########################
92
$loop = Glib::MainLoop->new;
93
Gscan2pdf::Frontend::CLI::_watch_cmd(
94
cmd => 'echo hello stdout; echo hello stderr 1>&2',
95
started_callback => sub {
96
ok( 1, 'started watching stdout and stderr' );
100
is( $output, "hello stdout\n", 'stdout watching stdout and stderr' );
102
err_callback => sub {
104
is( $output, "hello stderr\n", 'stderr watching stdout and stderr' );
106
finished_callback => sub {
107
my ( $output, $error ) = @_;
108
is( $output, "hello stdout\n", 'stdout finished watching stdout and stderr' );
109
is( $error, "hello stderr\n", 'stderr finished watching stdout and stderr' );
115
#########################
117
$loop = Glib::MainLoop->new;
118
my $cmd = 'cat scanners/*';
119
Gscan2pdf::Frontend::CLI::_watch_cmd(
121
started_callback => sub {
122
ok( 1, 'started watching large amounts of stdout' );
124
finished_callback => sub {
125
my ( $output, $error ) = @_;
126
is( length($output) . "\n",
127
`$cmd | wc -c`, 'stdout finished watching large amounts of stdout' );
128
is( $error, undef, 'stderr finished watching large amounts of stdout' );
134
#########################
136
$loop = Glib::MainLoop->new;
137
Gscan2pdf::Frontend::CLI->find_scan_options(
139
finished_callback => sub {
141
like( $output, qr/mode/xi, 'find_scan_options beginning' );
142
like( $output, qr/button/xi, 'find_scan_options end' );
148
#########################
150
$loop = Glib::MainLoop->new;
151
Gscan2pdf::Frontend::CLI->scan_pages(
152
frontend => 'scanimage',
155
started_callback => sub {
156
ok( 1, 'scanimage starts' );
158
new_page_callback => sub {
160
ok( -e $path, 'scanimage scans' );
163
finished_callback => sub {
164
ok( 1, 'scanimage finishes' );
170
#########################
172
$loop = Glib::MainLoop->new;
173
Gscan2pdf::Frontend::CLI->scan_pages(
174
frontend => 'scanadf',
177
started_callback => sub {
178
ok( 1, 'scanadf starts' );
180
new_page_callback => sub {
182
ok( -e $path, 'scanadf scans' );
185
finished_callback => sub {
186
ok( 1, 'scanadf finishes' );
192
#########################