updates for the git tranfer
[imager-graph.git] / t / t20api.t
1 #!perl -w
2 use strict;
3 use Imager::Graph::Pie;
4 use lib 't/lib';
5 use Imager::Font::Test;
6 use Test::More;
7
8 ++$|;
9
10 use Imager qw(:handy);
11
12 plan tests => 3;
13
14 #my $fontfile = 'Im_ugly.ttf';
15 #my $font = Imager::Font->new(file=>$fontfile, type => 'ft2', aa=>1)
16 #  or plan skip_all => "Cannot create font object: ",Imager->errstr,"\n";
17 my $font = Imager::Font::Test->new();
18
19 my @data = ( 100, 180, 80, 20, 2, 1, 0.5 );
20 my @labels = qw(alpha beta gamma delta epsilon phi gi);
21
22 my $api_pie = Imager::Graph::Pie->new();
23
24 $api_pie->add_data_series(\@data, 'Demo series');
25 $api_pie->set_font($font);
26 $api_pie->set_labels(\@labels);
27 $api_pie->set_graph_size(50);
28 $api_pie->set_image_width(200);
29 $api_pie->set_image_height(200);
30 $api_pie->set_title('Test 20');
31 $api_pie->set_style('fount_rad');
32
33 my $api_img = $api_pie->draw();
34 ok($api_img);
35
36 my $data_pie = Imager::Graph::Pie->new();
37
38 my $data_img = $data_pie->draw(
39                                 data    => \@data,
40                                 labels  => \@labels,
41                                 font    => $font,
42                                 title   => { text => 'Test 20' },
43                                 style   => 'fount_rad',
44                                 size    => 50,
45                                 width   => 200,
46                                 height  => 200,
47                               );
48
49
50 ok($data_img);
51
52 my ($api_content, $data_content);
53
54 $data_img->write(data => \$data_content, type=>'raw') or die "Err: ".$data_img->errstr;
55 $api_img->write(data  => \$api_content,  type=>'raw') or die "Err: ".$api_img->errstr;
56
57 ok($data_content eq $api_content);
58
59 # These are just here to make it easy to see why the above test failed, if it did
60 $data_img->write(file=>'testout/t20_data.ppm')or die "Error: ".$data_img->errstr."\n";
61 $api_img->write(file=>'testout/t20_api.ppm')or die "Error: ".$api_img->errstr."\n";
62