summaryrefslogtreecommitdiff
path: root/test/feh-scr.i
blob: a67b511dcd1d1e52f957d7869230f67de7855481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use autodie qw/:all/;

use Cwd;
use GD qw/:DEFAULT :cmp/;
use Test::More tests => 11;
use Time::HiRes qw/sleep/;
use X11::GUITest qw/:ALL/;

my ($pid_xnest, $pid_twm);
my $win;
my ($width, $height);
my $pwd = getcwd();

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;

	$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);

	return( ! ($img_one->compare($img_two) & GD_CMP_IMAGE));
}

sub check_scr {
	my ($file) = @_;

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

	ok(
		same_files("test/scr/${file}", "/tmp/feh_${$}.png"),
		"X root window is test/scr/${file}"
	);
}

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'
);
check_scr('draw_all_multi');
feh_stop();

feh_start(
	"--draw-actions --draw-filename --info 'echo foo; echo bar' "
	. '--action quux --action5 baz --action8 "nrm \'%f\'"',
	'test/bg/exact/in'
);
check_scr('draw_all_one');
feh_stop();

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

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

SendKeys('^({RIG})');
check_scr('feh_lwi_scroll_r');

SendKeys('^({DOW})');
check_scr('feh_lwi_scroll_rd');

SendKeys('^({RIG})');
check_scr('feh_lwi_scroll_rdr');

SendKeys('^({UP})');
check_scr('feh_lwi_scroll_rdru');

SendKeys('^({LEF})');
check_scr('feh_lwi_scroll_rdrul');

feh_stop();

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

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

unlink("/tmp/feh_${$}.png");