267997be |
1 | #!perl -w |
2 | use strict; |
3 | use Imager::Graph::Bar; |
4 | use lib 't/lib'; |
5 | use Imager::Font::Test; |
6 | use Test::More; |
7 | |
8 | -d 'testout' |
9 | or mkdir "testout", 0700 |
10 | or die "Could not create output directory: $!"; |
11 | |
12 | ++$|; |
13 | |
14 | use Imager qw(:handy); |
15 | |
2e4f2a17 |
16 | plan tests => 4; |
267997be |
17 | |
18 | my @warned; |
19 | local $SIG{__WARN__} = |
20 | sub { |
21 | print STDERR $_[0]; |
22 | push @warned, $_[0] |
23 | }; |
24 | |
25 | |
26 | #my $fontfile = 'ImUgly.ttf'; |
27 | #my $font = Imager::Font->new(file=>$fontfile, type => 'ft2', aa=>1) |
28 | # or plan skip_all => "Cannot create font object: ",Imager->errstr,"\n"; |
29 | my $font = Imager::Font::Test->new(); |
30 | |
31 | my @data = ( 100, 180, 80, 20, 2, 1, 0.5 ); |
32 | my @labels = qw(alpha beta gamma delta epsilon phi gi); |
33 | |
34 | my $column = Imager::Graph::Bar->new(); |
35 | $column->set_font($font); |
36 | ok($column, "creating column chart object"); |
37 | |
38 | $column->add_data_series(\@data); |
39 | $column->set_labels(\@labels); |
40 | |
41 | my $img1 = $column->draw(); |
42 | ok($img1, "drawing column chart"); |
43 | |
44 | $img1->write(file=>'testout/t14_bar.ppm') or die "Can't save img1: ".$img1->errstr."\n"; |
45 | cmpimg($img1, 'testimg/t14_bar.ppm', 1); |
46 | |
47 | unless (is(@warned, 0, "should be no warnings")) { |
48 | diag($_) for @warned; |
49 | } |
50 | |
51 | sub cmpimg { |
52 | my ($img, $file, $limit) = @_; |
53 | |
54 | $limit ||= 10000; |
55 | |
56 | my $cmpimg = Imager->new; |
57 | $cmpimg->read(file=>$file) |
58 | or return ok(0, "Cannot read $file: ".$cmpimg->errstr); |
59 | my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG}); |
60 | cmp_ok($diff, '<', $limit, "Comparison to $file ($diff)"); |
61 | } |
62 | |