]> git.imager.perl.org - imager-graph.git/blame - t/x50vstyle.t
remove more test generated files
[imager-graph.git] / t / x50vstyle.t
CommitLineData
56b495c0
TC
1#!perl -w
2use strict;
3use Imager::Graph::Line;
4use lib 't/lib';
5use Imager::Font::Test;
6use Test::More;
7use Imager::Test qw(is_image_similar is_image);
8
9-d 'testout'
10 or mkdir "testout", 0700
11 or die "Could not create output directory: $!";
12
13++$|;
14
15use Imager qw(:handy);
16
17#my $fontfile = 'ImUgly.ttf';
18#my $font = Imager::Font->new(file=>$fontfile, type => 'ft2', aa=>1)
19# or plan skip_all => "Cannot create font object: ",Imager->errstr,"\n";
20my $font = Imager::Font::Test->new();
21
22my @data1 =
23 (
24 100, 180, 80, 20, 2, 1, 0.5 ,
25 );
26my @labels = qw(alpha beta gamma delta epsilon phi gi);
27
28plan tests => 29;
29
30# this may change output quality too
31print "# Imager version: $Imager::VERSION\n";
32print "# Font type: ",ref $font,"\n";
33
34{
35 my $vert = Imager::Graph::Vertical->new;
36 ok($vert, "creating chart object");
37 $vert->set_y_tics(10);
38
39 $vert->add_line_data_series(\@data1, "Test Line");
40
41 my $img1;
42 { # default outline of chart area
43 $img1 = $vert->draw
44 (
45 labels => \@labels,
46 font => $font,
47 title => "Test",
48 )
49 or print "# ", $vert->error, "\n";
50
51 ok($img1, "made the image");
52
53 ok($img1->write(file => "testout/x50line_def.ppm"),
54 "save to testout");
55
56 cmpimg($img1, "xtestimg/x50line_def.png");
57 }
58
59 { # no outline
60 my $img2 = $vert->draw
61 (
62 labels => \@labels,
63 font => $font,
64 title => "Test",
65 features => [ qw/nograph_outline/ ],
66 )
67 or print "# ", $vert->error, "\n";
68
69 isnt($img1, $img2, "make sure they're different images");
70
71 ok($img2, "made the image");
72
73 ok($img2->write(file => "testout/x50line_noout.ppm"),
74 "save to testout");
75
76 cmpimg($img2, "xtestimg/x50line_noout.png");
77
78 my $img3 = $vert->draw
79 (
80 labels => \@labels,
81 font => $font,
82 title => "Test",
83 features => "nograph_outline",
84 )
85 or print "# ", $vert->error, "\n";
86 ok($img3, "made with scalar features");
87 is_image($img3, $img2, "check that both feature mechanisms act the same");
88
89 my $img4 = $vert->draw
90 (
91 labels => \@labels,
92 font => $font,
93 title => "Test",
94 features => { "graph_outline" => 0 },
95 )
96 or print "# ", $vert->error, "\n";
97 ok($img4, "made with hashref features");
98 is_image($img4, $img2, "check that all feature mechanisms act the same");
99 }
100
101 {
102 # check no state remembered from nograph_outline
103 my $img5 = $vert->draw
104 (
105 labels => \@labels,
106 font => $font,
107 title => "Test",
108 )
109 or print "# ", $vert->error, "\n";
110 ok($img5, "make with border again to check no state held");
111 is_image($img1, $img5, "check no state held");
112 }
113
114 { # styled outline
115 my $img6 = $vert->draw
116 (
117 labels => \@labels,
118 font => $font,
119 title => "Test styled outline",
120 graph =>
121 {
122 outline =>
123 {
124 color => "#fff",
125 style => "dashed",
126 },
127 },
128 );
129 ok($img6, "make chart with dashed outline of graph area");
130 ok($img6->write(file => "testout/x50line_dashout.ppm"),
131 "save it");
132 cmpimg($img6, "xtestimg/x50line_dashout.png");
133 }
134
135 { # no outline, styled fill
136 my $img7 = $vert->draw
137 (
138 labels => \@labels,
139 font => $font,
140 title => "Test styled outline",
141 features => "nograph_outline",
142 graph =>
143 {
144 fill => { solid => "ffffffC0" },
145 },
146 )
147 or print "# ", $vert->error, "\n";
148 ok($img7, "made the image");
149 ok($img7->write(file => "testout/x50line_fill.ppm"),
150 "save it");
151 cmpimg($img7, "xtestimg/x50line_fill.png");
152 }
153
154 { # gridlines
155 my $img8 = $vert->draw
156 (
157 labels => \@labels,
158 font => $font,
159 title => "gridlines",
160 features => "horizontal_gridlines",
161 hgrid => { style => "dashed", color => "#A0A0A0" },
162 )
163 or print "# ", $vert->error, "\n";
164 ok($img8, "made the gridline image");
165 ok($img8->write(file => "testout/x50line_grid.ppm"),
166 "save it");
167 cmpimg($img8, "xtestimg/x50line_grid.png");
168
169 # default horizontal gridlines
170 my $imgb = $vert->draw
171 (
172 labels => \@labels,
173 font => $font,
174 title => "gridlines",
175 features => "horizontal_gridlines",
176 )
177 or print "# ", $vert->error, "\n";
178 ok($imgb, "made the gridline image");
179 ok($imgb->write(file => "testout/x50line_griddef.ppm"),
180 "save it");
181 cmpimg($imgb, "xtestimg/x50line_griddef.png");
182
183 }
184
185 { # gridlines (set by method)
186 my $vert2 = Imager::Graph::Vertical->new;
187 $vert2->show_horizontal_gridlines();
188 $vert2->set_horizontal_gridline_style(style => "dashed", color => "#A0A0A0");
189 $vert2->set_labels(\@labels);
190 $vert2->set_title("gridlines");
191 $vert2->add_line_data_series(\@data1, "Test Line");
192 $vert2->set_y_tics(10);
193 $vert2->set_font($font);
194
195 my $img9 = $vert2->draw
196 (
197 #labels => \@labels,
198 #font => $font,
199 #title => "gridlines",
200 #features => "horizontal_gridlines",
201 #hgrid => { style => "dashed", color => "#A0A0A0" },
202 )
203 or print "# ", $vert2->error, "\n";
204 ok($img9, "made the gridline image (set by methods)");
205 ok($img9->write(file => "testout/x50line_gridm.ppm"),
206 "save it");
207 cmpimg($img9, "xtestimg/x50line_grid.png");
208 }
209}
210
211END {
212 unless ($ENV{IMAGER_GRAPH_KEEP_FILES}) {
213 unlink "testout/x50line_def.ppm";
214 unlink "testout/x50line_noout.ppm";
215 unlink "testout/x50line_dashout.ppm";
216 unlink "testout/x50line_fill.ppm";
217 unlink "testout/x50line_grid.ppm";
523a1013 218 unlink "testout/x50line_griddef.ppm";
56b495c0
TC
219 unlink "testout/x50line_gridm.ppm";
220 }
221}
222
223sub cmpimg {
224 my ($img, $file, $limit) = @_;
225
226 $limit ||= 10000;
227
228 SKIP:
229 {
230 $Imager::formats{png}
231 or skip("No PNG support", 1);
232
233 my $cmpimg = Imager->new;
234 $cmpimg->read(file=>$file)
235 or return ok(0, "Cannot read $file: ".$cmpimg->errstr);
236 my $diff = Imager::i_img_diff($img->{IMG}, $cmpimg->{IMG});
237 is_image_similar($img, $cmpimg, $limit, "Comparison to $file ($diff)");
238 }
239}