Newer
Older
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use autodie qw/:all/;
use Cwd;
use GD qw/:DEFAULT :cmp/;
use Time::HiRes qw/sleep/;
use X11::GUITest qw/:ALL/;
my ($pid_xnest, $pid_twm);
my $win;
my ($width, $height);
my $pwd = getcwd();
Birte Kristina Friesel
committed
$ENV{HOME} = 'test';
sub waitfor(&) {
my ($sub) = @_;
my $out;
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
sleep(0.05);
$out = &{$sub};
if ($out) {
return $out;
}
}
return 0;
}
sub feh_start {
my ($opts, $files) = @_;
my $id;
$opts //= q{};
$files //= 'test/ok/png';
StartApp("feh ${opts} ${files}");
($id) = WaitWindowViewable(qr{^feh});
if (not $id) {
BAIL_OUT("Unable to start feh ${opts} ${files}");
}
if (not SetInputFocus($id)) {
BAIL_OUT("Unable to focus window");
}
return $id;
}
sub feh_stop {
SendKeys('{ESC}');
if (not waitfor { not FindWindowLike(qr{^feh}) }) {
BAIL_OUT("Unclosed feh window still open, cannot continue");
}
}
sub same_files {
my ($one, $two) = @_;
my $img_one = GD::Image->new($one);
my $img_two = GD::Image->new($two);
if (not defined $img_one or not defined $img_two) {
return 0;
}
return( ! ($img_one->compare($img_two) & GD_CMP_IMAGE));
}
sub check_scr {
my ($file) = @_;
system("import -silent -window root /tmp/feh_${$}.png");
return same_files("test/scr/${file}", "/tmp/feh_${$}.png");
}
sub test_scr {
my ($file) = @_;
my $msg = "X root window is test/scr/${file}";
$test_id++;
if (waitfor { check_scr($file) }) {
pass($msg);
}
else {
fail($msg);
rename("/tmp/feh_${$}.png", "/tmp/feh_${$}_${test_id}_${file}.png");
}
}
if (FindWindowLike(qr{^feh})) {
BAIL_OUT('It appears you have an open feh window. Please close it.');
}
feh_start(
"--draw-actions --draw-filename --info 'echo foo; echo bar' "
. '--action quux --action5 baz --action8 "nrm \'%f\'"',
'test/bg/exact/in test/bg/large/w/in test/bg/large/h/in'
);
feh_stop();
feh_start(
"--draw-actions --draw-filename --info 'echo foo; echo bar' "
. '--action quux --action5 baz --action8 "nrm \'%f\'"',
'test/bg/exact/in'
);
feh_stop();
feh_start(
'--fullscreen',
'test/bg/large/w/in'
);
feh_stop();
feh_start(
q{},
'test/bg/large/w/in'
);
test_scr('feh_lwi_scroll_rdru');
test_scr('feh_lwi_scroll_rdrul');
feh_stop();
feh_start(
'--scale-down',
'test/bg/large/w/in'
);
feh_stop();
feh_start(
'--thumbnails',
'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm'
);
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
test_scr('thumbnail_default');
feh_stop();
feh_start(
'--caption-path .tc',
'test/bg/exact/in'
);
test_scr('caption_none');
SendKeys('c');
test_scr('caption_new');
SendKeys('Picknick im Zenit metaphysischen Wiederscheins der astralen Kuhglocke');
test_scr('caption_while');
SendKeys('~');
test_scr('caption_done');
SendKeys('c');
test_scr('caption_while');
SendKeys('{BKS}' x 80);
test_scr('caption_new');
SendKeys('~');
test_scr('caption_none');
SendKeys('cfoobar{ESC}');
test_scr('caption_none');
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
feh_start(
'--draw-actions --action8 "nrm \'%f\'"',
'test/bg/exact/in'
);
test_scr('draw_action');
feh_stop();
feh_start(
'--draw-filename',
'test/bg/exact/in'
);
test_scr('draw_filename');
feh_stop();
feh_start(
'--draw-filename --draw-actions --action8 "nrm \'%f\'"',
'test/bg/exact/in'
);
test_scr('draw_filename_action');
feh_stop();
feh_start(
'--action8 "nrm \'%f\'"',
'test/bg/exact/in'
);
test_scr('draw_nothing');
SendKeys('d');
test_scr('draw_filename');
SendKeys('da');
test_scr('draw_action');
SendKeys('d');
test_scr('draw_filename_action');
SendKeys('da');
test_scr('draw_nothing');
feh_stop();
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
feh_start(q{}, 'test/bg/large/h/in');
test_scr('feh_lhi');
SendKeys('{UP}');
test_scr('feh_lhi_i');
SendKeys('{UP}');
test_scr('feh_lhi_ii');
SendKeys('^({RIG})');
test_scr('feh_lhi_iir');
SendKeys('^({RIG})');
test_scr('feh_lhi_iirr');
SendKeys('{UP}');
test_scr('feh_lhi_iirri');
SendKeys('{DOW}');
test_scr('feh_lhi_iirrio');
feh_stop();
feh_start(q{}, 'test/bg/large/h/in');
test_scr('feh_lhi');
SendKeys('{DOW}');
test_scr('feh_lhi_o');
SendKeys('{DOW}');
test_scr('feh_lhi_oo');
SendKeys('{DOW}');
test_scr('feh_lhi_ooo');
feh_stop();
feh_start(q{}, 'test/bg/transparency');
test_scr('feh_ibg_default');
feh_stop();
feh_start('--image-bg default', 'test/bg/transparency');
test_scr('feh_ibg_default');
feh_stop();
feh_start('--image-bg black', 'test/bg/transparency');
test_scr('feh_ibg_black');
feh_stop();
feh_start('--image-bg white', 'test/bg/transparency');
test_scr('feh_ibg_white');
feh_stop();
unlink('test/bg/exact/.tc/in.txt');
rmdir('test/bg/exact/.tc');