]> git.imager.perl.org - imager-graph.git/blob - t/t33_long_labels.t
* changed t31tic_color.t to check against different images based on the presence...
[imager-graph.git] / t / t33_long_labels.t
1 use strict;
2
3 use Imager::Graph::Line;
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 => 2;
25
26
27 my $font = Imager::Font::Test->new();
28
29 my $graph = Imager::Graph::Line->new();
30 $graph->set_image_width(900);
31 $graph->set_image_height(600);
32 $graph->set_font($font);
33
34 $graph->add_data_series([1, 2]);
35 $graph->set_labels(['AWWWWWWWWWWWWWWA', 'AWWWWWWWWWWWWWWWWWWWWWWWWWWWWWA']);
36
37 my $img = $graph->draw() || warn $graph->error;
38
39 $img->write(file=>'testout/t33_long_labels.ppm') or die "Can't save img1: ".$img->errstr."\n";
40 cmpimg($img, 'testimg/t33_long_labels.ppm', 1);
41
42 unless (is(@warned, 0, "should be no warnings")) {
43   diag($_) for @warned;
44 }
45
46
47 sub cmpimg {
48   my ($img, $file, $limit) = @_;
49
50   $limit ||= 10000;
51
52   my $cmpimg = Imager->new;
53   $cmpimg->read(file=>$file)
54     or return ok(0, "Cannot read $file: ".$cmpimg->errstr);
55   my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG});
56   cmp_ok($diff, '<', $limit, "Comparison to $file ($diff)");
57
58 }
59