~ubuntu-branches/debian/sid/gscan2pdf/sid

« back to all changes in this revision

Viewing changes to t/08_Frontend_CLI.t

  • Committer: Package Import Robot
  • Author(s): Jeffrey Ratcliffe
  • Date: 2013-10-08 09:38:10 UTC
  • mfrom: (1.3.11)
  • Revision ID: package-import@ubuntu.com-20131008093810-dhoer6ktpjentiox
Tags: 1.1.3-1
* New upstream release
  Closes: #723784 (gscan2pdf: New upstream version available)
* Removed all patches
  Removed Build-Depends: quilt
  Updated rules not to use quilt
* Bumped standards to 3.9.4 (no changes required)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use warnings;
 
2
use strict;
 
3
use Test::More tests => 27;
 
4
 
 
5
BEGIN {
 
6
 use_ok('Gscan2pdf::Frontend::CLI');
 
7
}
 
8
 
 
9
#########################
 
10
 
 
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);
 
16
 
 
17
#########################
 
18
 
 
19
my $output = <<'END';
 
20
'0','test:0','Noname','frontend-tester','virtual device'
 
21
'1','test:1','Noname','frontend-tester','virtual device'
 
22
END
 
23
 
 
24
is_deeply(
 
25
 Gscan2pdf::Frontend::CLI->parse_device_list($output),
 
26
 [
 
27
  {
 
28
   'name'   => 'test:0',
 
29
   'model'  => 'frontend-tester',
 
30
   'type'   => 'virtual device',
 
31
   'vendor' => 'Noname'
 
32
  },
 
33
  {
 
34
   'name'   => 'test:1',
 
35
   'model'  => 'frontend-tester',
 
36
   'type'   => 'virtual device',
 
37
   'vendor' => 'Noname'
 
38
  }
 
39
 ],
 
40
 "basic parse_device_list functionality"
 
41
);
 
42
 
 
43
#########################
 
44
 
 
45
is_deeply( Gscan2pdf::Frontend::CLI->parse_device_list(''),
 
46
 [], "parse_device_list no devices" );
 
47
 
 
48
#########################
 
49
 
 
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' );
 
55
 },
 
56
 out_callback => sub {
 
57
  my ($output) = @_;
 
58
  is( $output, "hello stdout\n", 'stdout watching only stdout' );
 
59
 },
 
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' );
 
64
  $loop->quit;
 
65
 }
 
66
);
 
67
$loop->run;
 
68
 
 
69
#########################
 
70
 
 
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' );
 
76
 },
 
77
 err_callback => sub {
 
78
  my ($output) = @_;
 
79
  is( $output, "hello stderr\n", 'stderr watching only stderr' );
 
80
 },
 
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' );
 
85
  $loop->quit;
 
86
 }
 
87
);
 
88
$loop->run;
 
89
 
 
90
#########################
 
91
 
 
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' );
 
97
 },
 
98
 out_callback => sub {
 
99
  my ($output) = @_;
 
100
  is( $output, "hello stdout\n", 'stdout watching stdout and stderr' );
 
101
 },
 
102
 err_callback => sub {
 
103
  my ($output) = @_;
 
104
  is( $output, "hello stderr\n", 'stderr watching stdout and stderr' );
 
105
 },
 
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' );
 
110
  $loop->quit;
 
111
 }
 
112
);
 
113
$loop->run;
 
114
 
 
115
#########################
 
116
 
 
117
$loop = Glib::MainLoop->new;
 
118
my $cmd = 'cat scanners/*';
 
119
Gscan2pdf::Frontend::CLI::_watch_cmd(
 
120
 cmd              => $cmd,
 
121
 started_callback => sub {
 
122
  ok( 1, 'started watching large amounts of stdout' );
 
123
 },
 
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' );
 
129
  $loop->quit;
 
130
 }
 
131
);
 
132
$loop->run;
 
133
 
 
134
#########################
 
135
 
 
136
$loop = Glib::MainLoop->new;
 
137
Gscan2pdf::Frontend::CLI->find_scan_options(
 
138
 device            => 'test',
 
139
 finished_callback => sub {
 
140
  my ($output) = @_;
 
141
  like( $output, qr/mode/xi,   'find_scan_options beginning' );
 
142
  like( $output, qr/button/xi, 'find_scan_options end' );
 
143
  $loop->quit;
 
144
 }
 
145
);
 
146
$loop->run;
 
147
 
 
148
#########################
 
149
 
 
150
$loop = Glib::MainLoop->new;
 
151
Gscan2pdf::Frontend::CLI->scan_pages(
 
152
 frontend         => 'scanimage',
 
153
 device           => 'test',
 
154
 npages           => 1,
 
155
 started_callback => sub {
 
156
  ok( 1, 'scanimage starts' );
 
157
 },
 
158
 new_page_callback => sub {
 
159
  my ($path) = @_;
 
160
  ok( -e $path, 'scanimage scans' );
 
161
  unlink $path;
 
162
 },
 
163
 finished_callback => sub {
 
164
  ok( 1, 'scanimage finishes' );
 
165
  $loop->quit;
 
166
 },
 
167
);
 
168
$loop->run;
 
169
 
 
170
#########################
 
171
 
 
172
$loop = Glib::MainLoop->new;
 
173
Gscan2pdf::Frontend::CLI->scan_pages(
 
174
 frontend         => 'scanadf',
 
175
 device           => 'test',
 
176
 npages           => 1,
 
177
 started_callback => sub {
 
178
  ok( 1, 'scanadf starts' );
 
179
 },
 
180
 new_page_callback => sub {
 
181
  my ($path) = @_;
 
182
  ok( -e $path, 'scanadf scans' );
 
183
  unlink $path;
 
184
 },
 
185
 finished_callback => sub {
 
186
  ok( 1, 'scanadf finishes' );
 
187
  $loop->quit;
 
188
 },
 
189
);
 
190
$loop->run;
 
191
 
 
192
#########################
 
193
 
 
194
__END__