Commit fec1ed90 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

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

parent 61fe36f9
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -7,9 +7,6 @@ test: all
	@PACKAGE=${PACKAGE} VERSION=${VERSION} prove test

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

install: install-man install-doc install-bin install-font install-img
+31 −28
Original line number Diff line number Diff line
@@ -4,11 +4,25 @@ use warnings;
use 5.010;

use Test::More tests => 34;
use Time::HiRes qw/sleep/;
use X11::GUITest qw/:ALL/;

my $win;
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 {
	my ($opts, $files) = @_;
	my $id;
@@ -32,45 +46,37 @@ sub feh_start {

sub feh_stop {
	SendKeys('{ESC}');
	for (1 .. 10) {
		sleep(0.1);
		if (FindWindowLike(qr{^feh}) == 0) {
			return;
		}
	}
	if (not waitfor { not FindWindowLike(qr{^feh}) }) {
		BAIL_OUT("Unclosed feh window still open, cannot continue");
	}
}

sub test_no_win {
	my ($reason) = @_;

	for (1 .. 10) {
		sleep(0.1);
		if (FindWindowLike(qr{^feh}) == 0) {
	if (waitfor { not FindWindowLike(qr{^feh}) }) {
		pass("Window closed ($reason)");
			return;
		}
	}
	else {
		fail("Window closed ($reason)");
		BAIL_OUT("unclosed window still open, cannot continue");
	}
}

sub test_win_title {
	my ($win, $wtitle) = @_;
	my $rtitle;

	for (1 .. 10) {
		sleep(0.1);
		$rtitle = GetWindowName($win);
		if ($rtitle eq $wtitle) {
	if (waitfor { GetWindowName($win) eq $wtitle }) {
		pass("Window has title: $wtitle");
			return;
		}
	}
	else {
		$rtitle = GetWindowName($win);
		fail("Window has title: $wtitle");
		diag("expected: $wtitle");
		diag("     got: $rtitle");
	}
}

if (FindWindowLike(qr{^feh})) {
	BAIL_OUT('It appears you have an open feh window. Please close it.');
@@ -117,15 +123,13 @@ test_no_win("--cycle-once -> window closed");

feh_start('--cycle-once --slideshow-delay 0.5',
	'test/ok.png test/ok.jpg test/ok.gif');
sleep(1);
sleep(1.5);
test_no_win('cycle-once + slideshow-delay -> window closed');

$win = feh_start('--cycle-once --slideshow-delay -0.01',
	'test/ok.png test/ok.jpg test/ok.gif');
sleep(0.1);
test_win_title($win, 'feh [1 of 3] - test/ok.png');
SendKeys('h');
sleep(1);
test_no_win('cycle-once + negative delay + [h]');

$win = feh_start(q{}, 'test/ok.png test/ok.gif test/ok.gif test/ok.jpg');
@@ -167,6 +171,5 @@ ClickMouseButton(M_BTN1);
ok($win, 'Thumbnail mode: Window opened');
SetInputFocus($win);
SendKeys('x');
sleep(0.2);
is(FindWindowLike(qr{^ok\.png$}), 0, 'Thumbnail mode: Window closed (x)');
ok(waitfor { not FindWindowLike(qr{^ok\.png$}) }, 'Thumbnail mode: closed');
feh_stop();