Commit 013b068c authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

test re-organization and code cleanup

parent f74385de
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -12,11 +12,11 @@ build-applications:
	@${MAKE} -C share/applications

test: all
	@PACKAGE=${PACKAGE} prove test
	@PACKAGE=${PACKAGE} prove test/feh.t test/mandoc.t

test-x11: all
	test/run-interactive
	prove test/feh-bg.i
	prove test/feh-bg-i.t

install: install-man install-doc install-bin install-font install-img
install: install-examples install-applications
+19 −16
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ use GD qw/:DEFAULT :cmp/;
use Test::More tests => 70;
use Time::HiRes qw/sleep/;

my $scr_dir = '/tmp/feh-test-scr';
my ( $pid_xnest, $pid_twm );

$ENV{HOME} = 'test';
@@ -33,12 +34,14 @@ sub same_files {
sub check_bg {
	my ($file) = @_;

	system("import -silent -window root /tmp/feh_${$}.png");
	system("import -silent -window root ${scr_dir}/feh_${$}.png");

	ok(
		same_files("test/bg/${file}", "/tmp/feh_${$}.png"),
		"Wallpaper is test/bg/${file}"
	);
	ok( same_files( "test/bg/${file}", "${scr_dir}/feh_${$}.png" ),
		"Wallpaper is test/bg/${file}" );
}

if ( not -d $scr_dir ) {
	mkdir($scr_dir);
}

if ( ( $pid_xnest = fork() ) == 0 ) {
@@ -75,5 +78,5 @@ sleep(0.2);
kill( 15, $pid_xnest );
sleep(0.2);

unlink("/tmp/feh_${$}.png");
unlink("${scr_dir}/feh_${$}.png");
unlink('test/.fehbg');
+461 −0
Original line number Diff line number Diff line
@@ -142,13 +142,17 @@ for (1 .. 2) {
}
test_no_win("--cycle-once -> window closed");

feh_start('--cycle-once --slideshow-delay 0.5',
	'test/ok/png test/ok/jpg test/ok/gif');
feh_start(
	'--cycle-once --slideshow-delay 0.5',
	'test/ok/png test/ok/jpg test/ok/gif'
);
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');
$win = feh_start(
	'--cycle-once --slideshow-delay -0.01',
	'test/ok/png test/ok/jpg test/ok/gif'
);

test_win_title( $win, 'feh [1 of 3] - test/ok/png [Paused]' );

@@ -174,7 +178,8 @@ test_win_title($win, 'feh [2 of 4] - test/ok/gif');

feh_stop();

$win = feh_start('--slideshow-delay 1', 'test/ok/png test/ok/gif test/ok/jpg');
$win
  = feh_start( '--slideshow-delay 1', 'test/ok/png test/ok/gif test/ok/jpg' );
sleep(1.7);
test_win_title( $win, 'feh [3 of 3] - test/ok/jpg' );
SendKeys('h');
@@ -188,8 +193,8 @@ test_win_title($win, 'feh [2 of 3] - test/ok/gif');
feh_stop();

$win = feh_start(
	'--action3 ";echo foo" --action7 "echo foo" ' .
	'--action8 ";touch feh_test_%u_%l" --action9 "rm feh_test_%u_%l"',
	'--action3 ";echo foo" --action7 "echo foo" '
	  . '--action8 ";touch feh_test_%u_%l" --action9 "rm feh_test_%u_%l"',
	'test/ok/png test/ok/gif test/ok/jpg'
);
test_win_title( $win, 'feh [1 of 3] - test/ok/png' );
@@ -199,22 +204,22 @@ SendKeys('7');
test_win_title( $win, 'feh [2 of 3] - test/ok/gif' );
SendKeys('8');
test_win_title( $win, 'feh [2 of 3] - test/ok/gif' );
ok(-e 'feh_test_2_3', 'feh action created file with correct format specifiers');
ok( -e 'feh_test_2_3',
	'feh action created file with correct format specifiers' );
SendKeys('9');
ok( waitfor { not -e 'feh_test_2_3' }, 'feh action removed file' );
test_win_title( $win, 'feh [3 of 3] - test/ok/jpg' );
feh_stop();


# .config/feh/keys
# Action Unbinding + non-conflicting none/shift/control/meta modifiers

$ENV{XDG_CONFIG_HOME} = 'test/config/keys';

$win = feh_start(
	'--action1 "touch a1" --action2 "touch a2" ' .
	'--action3 "touch a3" --action4 "touch a4" ' .
	'--action5 "touch a5" --action6 "touch a6" ',
	'--action1 "touch a1" --action2 "touch a2" '
	  . '--action3 "touch a3" --action4 "touch a4" '
	  . '--action5 "touch a5" --action6 "touch a6" ',
	'test/ok/png test/ok/jpg test/ok/pnm'
);
test_win_title( $win, 'feh [1 of 3] - test/ok/png' );
@@ -246,6 +251,7 @@ SendKeys('^(X)');
ok( waitfor { -e 'a4' }, 'action 4 = Ctrl+Shift+X ok' );
SendKeys('%(x)');
ok( waitfor { -e 'a5' }, 'action 5 = Alt+X ok' );

for my $f (qw(a1 a2 a3 a4 a5)) {
	unlink($f);
}
@@ -253,28 +259,20 @@ feh_stop();

$ENV{XDG_CONFIG_HOME} = 'test/config/themes';

$win = feh_start(
	'-Ttest_general',
	'test/ok/png test/ok/jpg'
);
$win = feh_start( '-Ttest_general', 'test/ok/png test/ok/jpg' );
SendKeys('1');
ok( waitfor { -e 'a1' }, 'theme: action 1 okay' );
unlink('a1');
feh_stop();

$win = feh_start(
	'-Ttest_general --action1 "touch c1"',
	'test/ok/png test/ok/jpg'
);
$win = feh_start( '-Ttest_general --action1 "touch c1"',
	'test/ok/png test/ok/jpg' );
SendKeys('1');
ok( waitfor { -e 'c1' }, 'theme: commandline overrides theme' );
unlink('c1');
feh_stop();

$win = feh_start(
	'-Ttest_multiline',
	'test/ok/png test/ok/jpg'
);
$win = feh_start( '-Ttest_multiline', 'test/ok/png test/ok/jpg' );
SendKeys('1');
ok( waitfor { -e 'a1' }, 'multiline theme: first line ok' );
SendKeys('2');
@@ -288,7 +286,6 @@ feh_stop();

delete $ENV{XDG_CONFIG_HOME};


$win = feh_start( q{}, 'test/ok/png ' x 100 );
test_win_title( $win, 'feh [1 of 100] - test/ok/png' );
SendKeys('{PGD}');
@@ -350,7 +347,8 @@ SetInputFocus($win);
SendKeys('x');
test_no_win('all multiwindows closed');

$win = feh_start('--start-at test/ok/jpg', 'test/ok/png test/ok/gif test/ok/jpg');
$win = feh_start( '--start-at test/ok/jpg',
	'test/ok/png test/ok/gif test/ok/jpg' );
test_win_title( $win, 'feh [3 of 3] - test/ok/jpg' );
SendKeys('{RIG}');
test_win_title( $win, 'feh [1 of 3] - test/ok/png' );
@@ -360,16 +358,22 @@ feh_start('--caption-path .captions', 'test/ok/png');
SendKeys('cFoo Bar Quux Moep~');
feh_stop();
ok( -d 'test/ok/.captions', 'autocreated captions directory' );
is(slurp('test/ok/.captions/png.txt'), 'Foo Bar Quux Moep',
	'Correct caption saved');
is(
	slurp('test/ok/.captions/png.txt'),
	'Foo Bar Quux Moep',
	'Correct caption saved'
);

feh_start( '--caption-path .captions', 'test/ok/png' );
SendKeys('c');
SendKeys( '{BKS}' x length('Foo Bar Quux Moep') );
SendKeys('Foo Bar^(~)miep~');
feh_stop();
is(slurp('test/ok/.captions/png.txt'), "Foo Bar\nmiep",
	'Caption with newline + correct backspace');
is(
	slurp('test/ok/.captions/png.txt'),
	"Foo Bar\nmiep",
	'Caption with newline + correct backspace'
);

unlink('test/ok/.captions/png.txt');
rmdir('test/ok/.captions');
@@ -423,7 +427,7 @@ ResizeWindow($win, 25, 30);

SKIP: {
	if ( not( [ $width, $height ] ~~ [ 25, 30 ] ) ) {
		skip('ResizeWindow failed', 2)
		skip( 'ResizeWindow failed', 2 );
	}
	PressKey('w');
	ok( waitfor { [ ( GetWindowPos($win) )[ 2, 3 ] ] ~~ [ 16, 16 ] },
@@ -432,18 +436,22 @@ SKIP: {
feh_stop();

$win = feh_start( q{}, 'test/huge.png' );
ok(waitfor {
ok(
	waitfor {
		( GetWindowPos($win) )[2] == ( GetScreenRes() )[0]
		|| (GetWindowPos($win))[3] == (GetScreenRes())[1]
		  || ( GetWindowPos($win) )[3] == ( GetScreenRes() )[1];
	},
	'Large window limited to screen size');
	'Large window limited to screen size'
);
feh_stop();

$win = feh_start( '--no-screen-clip', 'test/huge.png' );
ok(waitfor {
		[(GetWindowPos($win))[2, 3]] ~~ [4000, 3000]
ok(
	waitfor {
		[ ( GetWindowPos($win) )[ 2, 3 ] ] ~~ [ 4000, 3000 ];
	},
	'disabled screen clip');
	'disabled screen clip'
);
feh_stop();

# GH-35 "Custom window title crashes feh on unloadable files"
+61 −106
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ my $win;
my ( $width, $height );
my $pwd     = getcwd();
my $test_id = 0;
my $scr_dir = '/tmp/feh-test-scr';

$ENV{HOME} = 'test';

@@ -75,9 +76,9 @@ sub same_files {
sub check_scr {
	my ($file) = @_;

	system("import -silent -window root /tmp/feh_${$}.png");
	system("import -silent -window root ${scr_dir}/feh_${$}.png");

	return same_files("test/scr/${file}", "/tmp/feh_${$}.png");
	return same_files( "test/scr/${file}", "${scr_dir}/feh_${$}.png" );
}

sub test_scr {
@@ -91,7 +92,8 @@ sub test_scr {
	}
	else {
		fail($msg);
		rename("/tmp/feh_${$}.png", "/tmp/feh_${$}_${test_id}_${file}.png");
		rename( "${scr_dir}/feh_${$}.png",
			"${scr_dir}/feh_${$}_${test_id}_${file}.png" );
	}
}

@@ -99,6 +101,10 @@ if (FindWindowLike(qr{^feh})) {
	BAIL_OUT('It appears you have an open feh window. Please close it.');
}

if ( not -d $scr_dir ) {
	mkdir($scr_dir);
}

feh_start(
	"--draw-actions --draw-filename --info 'echo foo; echo bar' "
	  . '--action quux --action5 baz --action8 "nrm \'%f\'"',
@@ -115,17 +121,11 @@ feh_start(
test_scr('draw_all_one');
feh_stop();

feh_start(
	'--fullscreen',
	'test/bg/large/w/in'
);
feh_start( '--fullscreen', 'test/bg/large/w/in' );
test_scr('feh_full_lwi');
feh_stop();

feh_start(
	q{},
	'test/bg/large/w/in'
);
feh_start( q{}, 'test/bg/large/w/in' );
test_scr('feh_lwi');

SendKeys('^({RIG})');
@@ -145,31 +145,21 @@ test_scr('feh_lwi_scroll_rdrul');

feh_stop();

feh_start(
	'--scale-down',
	'test/bg/large/w/in'
);
feh_start( '--scale-down', 'test/bg/large/w/in' );
test_scr('feh_scaledown_lwi');
feh_stop();

feh_start(
	'--thumbnails',
	'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm'
);
feh_start( '--thumbnails', 'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm' );
test_scr('thumbnail_default');
feh_stop();

feh_start(
	'--index --limit-width 400',
	'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm'
);
feh_start( '--index --limit-width 400',
	'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm' );
test_scr('index_w400');
feh_stop();

feh_start(
	'--fullindex --limit-width 400',
	'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm'
);
feh_start( '--fullindex --limit-width 400',
	'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm' );
test_scr('index_full_w400');
feh_stop();

@@ -180,37 +170,28 @@ feh_start(
test_scr('index_full_w400');
feh_stop();

feh_start(
	'--index --limit-height 400',
	'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm'
);
feh_start( '--index --limit-height 400',
	'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm' );
test_scr('index_h400');
feh_stop();

feh_start(
	'--fullindex --limit-height 400',
	'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm'
);
feh_start( '--fullindex --limit-height 400',
	'test/ok/gif test/ok/jpg test/ok/png test/ok/pnm' );
test_scr('index_full_h400');
feh_stop();

feh_start(
	'--geometry +10+20',
	'test/ok/png'
);
feh_start( '--geometry +10+20', 'test/ok/png' );
test_scr('geometry_offset_only');
feh_stop();

feh_start(
	'--caption-path .tc',
	'test/bg/exact/in'
);
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');
SendKeys(
	'Picknick im Zenit metaphysischen Wiederscheins der astralen Kuhglocke');
test_scr('caption_while');

SendKeys('~');
@@ -230,66 +211,43 @@ test_scr('caption_none');

feh_stop();

feh_start(
	'--info "echo \'%f\n%wx%h\'"',
	'test/bg/exact/in'
);
feh_start( '--info "echo \'%f\n%wx%h\'"', 'test/bg/exact/in' );
test_scr('draw_info');
feh_stop();

feh_start(
	'--info "echo \'%f\n%wx%h\'" --draw-tinted',
	'test/bg/exact/in'
);
feh_start( '--info "echo \'%f\n%wx%h\'" --draw-tinted', 'test/bg/exact/in' );
test_scr('draw_info_tinted');
feh_stop();

feh_start(
	'--draw-actions --action8 "nrm \'%f\'"',
	'test/bg/exact/in'
);
feh_start( '--draw-actions --action8 "nrm \'%f\'"', 'test/bg/exact/in' );
test_scr('draw_action');
feh_stop();

feh_start(
	'--draw-actions --action8 "nrm \'%f\'" --draw-tinted',
	'test/bg/exact/in'
);
feh_start( '--draw-actions --action8 "nrm \'%f\'" --draw-tinted',
	'test/bg/exact/in' );
test_scr('draw_action_tinted');
feh_stop();

feh_start(
	'--draw-filename',
	'test/bg/exact/in'
);
feh_start( '--draw-filename', 'test/bg/exact/in' );
test_scr('draw_filename');
feh_stop();

feh_start(
	'--draw-filename --draw-tinted',
	'test/bg/exact/in'
);
feh_start( '--draw-filename --draw-tinted', 'test/bg/exact/in' );
test_scr('draw_filename_tinted');
feh_stop();

feh_start(
	'--draw-filename --draw-actions --action8 "nrm \'%f\'"',
	'test/bg/exact/in'
);
feh_start( '--draw-filename --draw-actions --action8 "nrm \'%f\'"',
	'test/bg/exact/in' );
test_scr('draw_filename_action');
feh_stop();

feh_start(
	'--draw-filename --draw-actions --action8 "nrm \'%f\'" --draw-tinted',
	'test/bg/exact/in'
);
	'test/bg/exact/in' );
test_scr('draw_filename_action_tinted');
feh_stop();

feh_start(
	'--action8 "nrm \'%f\'"',
	'test/bg/exact/in'
);
feh_start( '--action8 "nrm \'%f\'"', 'test/bg/exact/in' );
test_scr('draw_nothing');

SendKeys('d');
@@ -306,10 +264,7 @@ test_scr('draw_nothing');

feh_stop();

feh_start(
	'--draw-tinted',
	'test/bg/exact/in'
);
feh_start( '--draw-tinted', 'test/bg/exact/in' );
test_scr('draw_nothing');
feh_stop();

@@ -368,4 +323,4 @@ feh_stop();

unlink('test/bg/exact/.tc/in.txt');
rmdir('test/bg/exact/.tc');
unlink("/tmp/feh_${$}.png");
unlink("${scr_dir}/feh_${$}.png");
+35 −35
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ if ($version =~ m{ Compile-time \s switches : \s .* help }ox) {
	$has_help = 1;
}

my $re_warning =
	qr{${feh_name} WARNING: test/fail/... \- No Imlib2 loader for that file format\n};
my $re_warning
  = qr{${feh_name} WARNING: test/fail/... \- No Imlib2 loader for that file format\n};
my $re_loadable    = qr{test/ok/...};
my $re_unloadable  = qr{test/fail/...};
my $re_list_action = qr{test/ok/... 16x16};
@@ -57,32 +57,28 @@ $cmd->stdout_like($re_loadable);
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(
	cmd => "$feh --loadable --action 'echo touch %f' $images"
);
	cmd => "$feh --loadable --action 'echo touch %f' $images" );

$cmd->exit_is_num(1);
$cmd->stdout_is_file('test/nx_action/loadable_action');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(
	cmd => "$feh --loadable --action ';echo touch %f' $images"
);
	cmd => "$feh --loadable --action ';echo touch %f' $images" );

$cmd->exit_is_num(1);
$cmd->stdout_is_file('test/nx_action/loadable_naction');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(
	cmd => "$feh --unloadable --action 'echo rm %f' $images"
);
	cmd => "$feh --unloadable --action 'echo rm %f' $images" );

$cmd->exit_is_num(1);
$cmd->stdout_is_file('test/nx_action/unloadable_action');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(
	cmd => "$feh --unloadable --action ';echo rm %f' $images"
);
	cmd => "$feh --unloadable --action ';echo rm %f' $images" );

$cmd->exit_is_num(1);
$cmd->stdout_is_file('test/nx_action/unloadable_naction');
@@ -108,15 +104,15 @@ for my $sort (qw/name filename width height pixels size format/) {
	$cmd->stderr_like($re_warning);
}

$cmd = Test::Command->new(cmd => "$feh --list $images --sort format --reverse");
$cmd
  = Test::Command->new( cmd => "$feh --list $images --sort format --reverse" );

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/format_reverse');
$cmd->stderr_like($re_warning);

$cmd = Test::Command->new(
	cmd => "$feh --list --recursive --sort filename test/ok"
);
	cmd => "$feh --list --recursive --sort filename test/ok" );

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/filename_recursive');
@@ -134,14 +130,15 @@ $cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(cmd =>
	"$feh --quiet --list --action 'echo \"%f %wx%h\" >&2' $images");
$cmd = Test::Command->new(
	cmd => "$feh --quiet --list --action 'echo \"%f %wx%h\" >&2' $images" );

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
$cmd->stderr_like($re_list_action);

$cmd = Test::Command->new(cmd => "$feh --list --min-dimension 20x20 $images_ok");
$cmd
  = Test::Command->new( cmd => "$feh --list --min-dimension 20x20 $images_ok" );

$cmd->exit_is_num(1);
$cmd->stdout_is_eq('');
@@ -152,7 +149,8 @@ else {
	$cmd->stderr_is_file('test/no-loadable-files');
}

$cmd = Test::Command->new(cmd => "$feh --list --max-dimension 10x10 $images_ok");
$cmd
  = Test::Command->new( cmd => "$feh --list --max-dimension 10x10 $images_ok" );

$cmd->exit_is_num(1);
$cmd->stdout_is_eq('');
@@ -163,13 +161,15 @@ else {
	$cmd->stderr_is_file('test/no-loadable-files');
}

$cmd = Test::Command->new(cmd => "$feh --list --min-dimension 16x16 $images_ok");
$cmd
  = Test::Command->new( cmd => "$feh --list --min-dimension 16x16 $images_ok" );

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
$cmd->stderr_is_eq('');

$cmd = Test::Command->new(cmd => "$feh --list --max-dimension 16x16 $images_ok");
$cmd
  = Test::Command->new( cmd => "$feh --list --max-dimension 16x16 $images_ok" );

$cmd->exit_is_num(0);
$cmd->stdout_is_file('test/list/default');
Loading