]> git.imager.perl.org - imager-screenshot.git/blame - t/20x11.t
0.008 release
[imager-screenshot.git] / t / 20x11.t
CommitLineData
0ddb7051
TC
1#!perl -w
2use strict;
3use Test::More;
4
5use Imager::Screenshot 'screenshot';
6
7Imager::Screenshot->have_x11
8 or plan skip_all => "No X11 support";
9
10# can we connect to a display
11my $display = Imager::Screenshot::x11_open()
12 or plan skip_all => "Cannot connect to a display: ".Imager->errstr;
13
62b84c46 14plan tests => 16;
0ddb7051
TC
15
16{
17 # should automatically connect and grab the root window
18 my $im = screenshot(id => 0)
19 or print "# ", Imager->errstr, "\n";
20
21 ok($im, "got a root screenshot, no display");
62b84c46
TC
22
23 # check the size matches the tags
24 is($im->tags(name => 'ss_window_width'), $im->getwidth,
25 "check ss_window_width tag");
26 is($im->tags(name => 'ss_window_height'), $im->getheight,
27 "check ss_window_height tag");
28 is($im->tags(name => 'ss_left'), 0, "check ss_left tag");
29 is($im->tags(name => 'ss_top'), 0, "check ss_top tag");
30 is($im->tags(name => 'ss_type'), 'X11', "check ss_type tag");
0ddb7051
TC
31}
32
33{
34 # use our supplied display
35 my $im = screenshot(display => $display, id => 0);
36 ok($im, "got a root screenshot, supplied display");
37}
38
39{
40 # use our supplied display - as a method
41 my $im = Imager::Screenshot->screenshot(display => $display, id => 0);
42 ok($im, "got a root screenshot, supplied display (method)");
43}
44
45{
46 # supply a junk window id
47 my $im = screenshot(display => $display, id => 0xFFFFFFF)
48 or print "# ", Imager->errstr, "\n";
49 ok(!$im, "should fail to get screenshot");
50 cmp_ok(Imager->errstr, '=~', 'BadWindow',
51 "check error");
52}
53
62b84c46
TC
54
55{ # try our subimage options
56 my $im = screenshot(display => $display, id => 0,
57 left => 70, top => 30, right => -35, bottom => -17);
58 ok($im, "call with left, top, etc");
59
60 # make sure tags set as expected
61 is($im->tags(name => 'ss_left'), 70, "check left value");
62 is($im->tags(name => 'ss_top'), 30, "check top value");
63 is($im->tags(name => 'ss_type'), 'X11', "check ss_type");
64 is($im->tags(name => 'ss_window_width'), 70 + $im->getwidth + 35,
65 "check image width against window size");
66 is($im->tags(name => 'ss_window_height'), 30 + $im->getheight + 17,
67 "check image height against window size");
68}
69
0ddb7051 70Imager::Screenshot::x11_close($display);