2 # Before `make install' is performed this script should be runnable with
3 # `make test'. After `make install' it should work as `perl test.pl'
5 ######################### We start with some black magic to print on failure.
7 # Change 1..1 below to 1..last_test_to_print .
8 # (It may become useful if the test is moved to ./t subdirectory.)
11 BEGIN { $| = 1; print "1..24\n"; }
12 END {print "not ok 1\n" unless $loaded;}
14 my $buggy_giflib_file = "buggy_giflib.txt";
16 use Imager qw(:all :handy);
21 Imager::init('log'=>'testout/t70newgif.log');
23 $green=i_color_new(0,255,0,0);
24 $blue=i_color_new(0,0,255,0);
27 $img->open(file=>'testimg/scale.ppm',type=>'pnm') || print "failed: ",$img->{ERRSTR},"\n";
31 if (i_has_format("gif")) {
32 $img->write(file=>'testout/t70newgif.gif',type=>'gif',gifplanes=>1,gifquant=>'lm',lmfixed=>[$green,$blue]) || print "failed: ",$img->{ERRSTR},"\nnot ";
35 # make sure the palette is loaded properly (minimal test)
36 my $im2 = Imager->new();
38 if ($im2->read(file=>'testimg/bandw.gif', colors=>\$map)) {
45 my @sorted = sort { comp_entry($a,$b) } @$map;
46 # first entry must be #000000 and second #FFFFFF
47 if (comp_entry($sorted[0], NC(0,0,0)) == 0) {
51 print "not ok 7 # entry should be black\n";
53 if (comp_entry($sorted[1], NC(255,255,255)) == 0) {
57 print "not ok 8 # entry should be white\n";
61 print "not ok 6 # bad map size\n";
62 print "ok 7 # skipped bad map size\n";
63 print "ok 8 # skipped bad map size\n";
67 print "not ok 5 # no map returned\n";
69 print "ok $_ # skipped no map returned\n";
74 print "not ok 4 # ",$im2->errstr,"\n";
75 print "ok 5 # skipped - couldn't load image\n";
78 # test the read_multi interface
79 my @imgs = Imager->read_multi();
80 @imgs and print "not ";
82 Imager->errstr =~ /callback parameter missing/ or print "not ";
83 print "ok 10 # ",Imager->errstr,"\n";
85 @imgs = Imager->read_multi(type=>'gif');
86 @imgs and print "not ";
88 Imager->errstr =~ /file/ or print "not ";
89 print "ok 12 # ",Imager->errstr,"\n";
92 @imgs = Imager->read_multi(type=>'gif', fh=>*NONESUCH);
93 @imgs and print "not ";
95 Imager->errstr =~ /fh option not open/ or print "not ";
96 print "ok 14 # ",Imager->errstr,"\n";
97 unless (-e $buggy_giflib_file) {
98 @imgs = Imager->read_multi(type=>'gif', file=>'testimg/screen2.gif');
99 @imgs == 2 or print "not ";
101 grep(!UNIVERSAL::isa($_, 'Imager'), @imgs) and print "not ";
103 grep($_->type eq 'direct', @imgs) and print "not ";
105 (my @left = $imgs[0]->tags(name=>'gif_left')) == 1 or print "not ";
107 my $left = $imgs[1]->tags(name=>'gif_left') or print "not ";
109 $left == 3 or print "not ";
114 print "ok $_ # skip see $buggy_giflib_file\n";
117 if (Imager::i_giflib_version() >= 4.0) {
118 unless (-e $buggy_giflib_file) {
119 open FH, "< testimg/screen2.gif"
120 or die "Cannot open testimg/screen2.gif: $!";
125 read(FH, $tmp, $_[0]) and $tmp
127 @imgs = Imager->read_multi(type=>'gif',
128 callback => $cb) or print "not ";
131 @imgs == 2 or print "not ";
134 open FH, "< testimg/screen2.gif"
135 or die "Cannot open testimg/screen2.gif: $!";
137 my $data = do { local $/; <FH>; };
139 @imgs = Imager->read_multi(type=>'gif',
140 data=>$data) or print "not ";
142 @imgs = 2 or print "not ";
147 print "ok $_ # skip see $buggy_giflib_file\n";
153 print "ok $_ # skipped - giflib3 doesn't support callbacks\n";
159 print "ok $_ # skipped: no gif support\n";
167 return $l[0] <=> $r[0]