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.)
12 use Test::More tests => 21;
14 use Imager qw(:all :handy);
15 use Imager::Test qw(test_image is_color3);
17 -d "testout" or mkdir "testout";
19 Imager::init('log'=>'testout/t70newgif.log');
21 my $green=i_color_new(0,255,0,0);
22 my $blue=i_color_new(0,0,255,0);
25 my $img = test_image();
27 ok($img->write(file=>'testout/t70newgif.gif',type=>'gif',gifplanes=>1,gifquant=>'lm',lmfixed=>[$green,$blue]))
28 or print "# failed: ",$img->{ERRSTR}, "\n";
33 # make sure the palette is loaded properly (minimal test)
34 my $im2 = Imager->new();
36 ok($im2->read(file=>'testimg/bandw.gif', colors=>\$map))
37 or skip("Can't load bandw.gif", 5);
40 or skip("No palette", 4);
42 or skip("Bad map count", 3);
43 my @sorted = sort { comp_entry($a,$b) } @$map;
44 # first entry must be #000000 and second #FFFFFF
45 is_color3($sorted[0], 0,0,0, "check first palette entry");
46 is_color3($sorted[1], 255,255,255, "check second palette entry");
50 # test the read_multi interface
51 my @imgs = Imager->read_multi();
52 ok(!@imgs, "read with no sources should fail");
53 like(Imager->errstr, qr/callback parameter missing/, "check error");
54 print "# ",Imager->errstr,"\n";
56 @imgs = Imager->read_multi(type=>'gif');
57 ok(!@imgs, "read multi no source but type should fail");
58 like(Imager->errstr, qr/file/, "check error");
62 @imgs = Imager->read_multi(type=>'gif', fh=>*NONESUCH);
63 ok(!@imgs, "read from bad fh");
64 like(Imager->errstr, qr/fh option not open/, "check message");
65 print "# ",Imager->errstr,"\n";
67 @imgs = Imager->read_multi(type=>'gif', file=>'testimg/screen2.gif');
68 is(@imgs, 2, "should read 2 images");
69 isa_ok($imgs[0], "Imager");
70 isa_ok($imgs[1], "Imager");
71 is($imgs[0]->type, "paletted");
72 is($imgs[1]->type, "paletted");
73 my @left = $imgs[0]->tags(name=>'gif_left');
75 my $left = $imgs[1]->tags(name=>'gif_left');
79 open FH, "< testimg/screen2.gif"
80 or die "Cannot open testimg/screen2.gif: $!";
85 read(FH, $tmp, $_[0]) and $tmp
87 @imgs = Imager->read_multi(type=>'gif',
90 is(@imgs, 2, "read multi from callback");
92 open FH, "< testimg/screen2.gif"
93 or die "Cannot open testimg/screen2.gif: $!";
95 my $data = do { local $/; <FH>; };
97 @imgs = Imager->read_multi(type=>'gif',
99 is(@imgs, 2, "read multi from data");
107 return $l[0] <=> $r[0]