Skip to content
Snippets Groups Projects
Commit fec1ed90 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

test/feh.i: Some refactoring, fix timing fuckup

parent 61fe36f9
No related branches found
No related tags found
No related merge requests found
...@@ -7,9 +7,6 @@ test: all ...@@ -7,9 +7,6 @@ test: all
@PACKAGE=${PACKAGE} VERSION=${VERSION} prove test @PACKAGE=${PACKAGE} VERSION=${VERSION} prove test
test-interactive: all test-interactive: all
@echo 'Note: X Testing sucks, and Xnest is also prone to weird behaviour.'
@echo 'If the test fails, try rerunning it one or two times.'
@echo 'If it works then, everything is fine.'
@test/run-interactive @test/run-interactive
install: install-man install-doc install-bin install-font install-img install: install-man install-doc install-bin install-font install-img
......
...@@ -4,11 +4,25 @@ use warnings; ...@@ -4,11 +4,25 @@ use warnings;
use 5.010; use 5.010;
use Test::More tests => 34; use Test::More tests => 34;
use Time::HiRes qw/sleep/;
use X11::GUITest qw/:ALL/; use X11::GUITest qw/:ALL/;
my $win; my $win;
my ($width, $height); my ($width, $height);
sub waitfor(&) {
my ($sub) = @_;
my $out;
for (1 .. 40) {
sleep(0.05);
$out = &{$sub};
if ($out) {
return $out;
}
}
return 0;
}
sub feh_start { sub feh_start {
my ($opts, $files) = @_; my ($opts, $files) = @_;
my $id; my $id;
...@@ -32,44 +46,36 @@ sub feh_start { ...@@ -32,44 +46,36 @@ sub feh_start {
sub feh_stop { sub feh_stop {
SendKeys('{ESC}'); SendKeys('{ESC}');
for (1 .. 10) { if (not waitfor { not FindWindowLike(qr{^feh}) }) {
sleep(0.1); BAIL_OUT("Unclosed feh window still open, cannot continue");
if (FindWindowLike(qr{^feh}) == 0) {
return;
}
} }
BAIL_OUT("Unclosed feh window still open, cannot continue");
} }
sub test_no_win { sub test_no_win {
my ($reason) = @_; my ($reason) = @_;
for (1 .. 10) { if (waitfor { not FindWindowLike(qr{^feh}) }) {
sleep(0.1); pass("Window closed ($reason)");
if (FindWindowLike(qr{^feh}) == 0) { }
pass("Window closed ($reason)"); else {
return; fail("Window closed ($reason)");
} BAIL_OUT("unclosed window still open, cannot continue");
} }
fail("Window closed ($reason)");
BAIL_OUT("unclosed window still open, cannot continue");
} }
sub test_win_title { sub test_win_title {
my ($win, $wtitle) = @_; my ($win, $wtitle) = @_;
my $rtitle; my $rtitle;
for (1 .. 10) { if (waitfor { GetWindowName($win) eq $wtitle }) {
sleep(0.1); pass("Window has title: $wtitle");
}
else {
$rtitle = GetWindowName($win); $rtitle = GetWindowName($win);
if ($rtitle eq $wtitle) { fail("Window has title: $wtitle");
pass("Window has title: $wtitle"); diag("expected: $wtitle");
return; diag(" got: $rtitle");
}
} }
fail("Window has title: $wtitle");
diag("expected: $wtitle");
diag(" got: $rtitle");
} }
if (FindWindowLike(qr{^feh})) { if (FindWindowLike(qr{^feh})) {
...@@ -117,15 +123,13 @@ test_no_win("--cycle-once -> window closed"); ...@@ -117,15 +123,13 @@ test_no_win("--cycle-once -> window closed");
feh_start('--cycle-once --slideshow-delay 0.5', feh_start('--cycle-once --slideshow-delay 0.5',
'test/ok.png test/ok.jpg test/ok.gif'); 'test/ok.png test/ok.jpg test/ok.gif');
sleep(1); sleep(1.5);
test_no_win('cycle-once + slideshow-delay -> window closed'); test_no_win('cycle-once + slideshow-delay -> window closed');
$win = feh_start('--cycle-once --slideshow-delay -0.01', $win = feh_start('--cycle-once --slideshow-delay -0.01',
'test/ok.png test/ok.jpg test/ok.gif'); 'test/ok.png test/ok.jpg test/ok.gif');
sleep(0.1);
test_win_title($win, 'feh [1 of 3] - test/ok.png'); test_win_title($win, 'feh [1 of 3] - test/ok.png');
SendKeys('h'); SendKeys('h');
sleep(1);
test_no_win('cycle-once + negative delay + [h]'); test_no_win('cycle-once + negative delay + [h]');
$win = feh_start(q{}, 'test/ok.png test/ok.gif test/ok.gif test/ok.jpg'); $win = feh_start(q{}, 'test/ok.png test/ok.gif test/ok.gif test/ok.jpg');
...@@ -167,6 +171,5 @@ ClickMouseButton(M_BTN1); ...@@ -167,6 +171,5 @@ ClickMouseButton(M_BTN1);
ok($win, 'Thumbnail mode: Window opened'); ok($win, 'Thumbnail mode: Window opened');
SetInputFocus($win); SetInputFocus($win);
SendKeys('x'); SendKeys('x');
sleep(0.2); ok(waitfor { not FindWindowLike(qr{^ok\.png$}) }, 'Thumbnail mode: closed');
is(FindWindowLike(qr{^ok\.png$}), 0, 'Thumbnail mode: Window closed (x)');
feh_stop(); feh_stop();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment