]> git.imager.perl.org - imager-graph.git/blob - t/t34horizontal_many_points.t
149aeec7271913ced5501452ffc5fc0d92cf6b45
[imager-graph.git] / t / t34horizontal_many_points.t
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 my @warned;
15 local $SIG{__WARN__} =
16   sub {
17     print STDERR $_[0];
18     push @warned, $_[0]
19   };
20
21
22 use Imager qw(:handy);
23
24 plan tests => 4;
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 = (1 .. 1000);
32
33 my $bar = Imager::Graph::Bar->new();
34 ok($bar, "creating bar chart object");
35
36 $bar->add_data_series(\@data);
37
38 my $img1 = $bar->draw();
39 ok($img1, "drawing bar chart");
40
41 $img1->write(file=>'testout/t34_points.ppm') or die "Can't save img1: ".$img1->errstr."\n";
42 cmpimg($img1, 'testimg/t34_points.ppm', 80_000);
43
44 unless (is(@warned, 0, "should be no warnings")) {
45   diag($_) for @warned;
46 }
47
48
49 sub cmpimg {
50   my ($img, $file, $limit) = @_;
51
52   $limit ||= 10000;
53
54   my $cmpimg = Imager->new;
55   $cmpimg->read(file=>$file)
56     or return ok(0, "Cannot read $file: ".$cmpimg->errstr);
57   my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG});
58   cmp_ok($diff, '<', $limit, "Comparison to $file ($diff)");
59 }
60