]> git.imager.perl.org - imager.git/blob - ICO/t/t30cursor.t
the PERL_INITIALIZE_IMAGER_PERL_CALLBACKS was checking the wrong version number
[imager.git] / ICO / t / t30cursor.t
1 #!perl -w
2 use strict;
3 use Test::More tests => 25;
4
5 BEGIN { use_ok('Imager::File::CUR'); }
6
7 -d 'testout' or mkdir 'testout', 0777;
8
9 my $im = Imager->new;
10
11 ok($im->read(file => 'testimg/pal43232.cur', type=>'cur'),
12    "read 4 bit");
13 is($im->getwidth, 32, "check width");
14 is($im->getheight, 32, "check width");
15 is($im->type, 'paletted', "check type");
16 is($im->tags(name => 'cur_bits'), 4, "check cur_bits tag");
17 is($im->tags(name => 'i_format'), 'cur', "check i_format tag");
18 is($im->tags(name => 'cur_hotspotx'), 1, "check cur_hotspotx tag");
19 is($im->tags(name => 'cur_hotspoty'), 18, "check cur_hotspoty tag");
20 my $mask = ".*" . ("\n" . "." x 32) x 32;
21 is($im->tags(name => 'cur_mask'), $mask, "check cur_mask tag");
22
23 # these should get pushed back into range on saving
24 $im->settag(name => 'cur_hotspotx', value => 32);
25 $im->settag(name => 'cur_hotspoty', value => -1);
26 ok($im->write(file=>'testout/hotspot.cur', type=>'cur'),
27    "save with oor hotspot")
28   or print "# ",$im->errstr, "\n";
29 {
30   my $im2 = Imager->new;
31   ok($im2->read(file=>'testout/hotspot.cur', type=>'cur'),
32      "re-read the hotspot set cursor")
33     or print "# ", $im->errstr, "\n";
34   is($im2->tags(name => 'cur_hotspotx'), 31, "check cur_hotspotx tag");
35   is($im2->tags(name => 'cur_hotspoty'), 0, "check cur_hotspoty tag");
36 }
37
38 $im->settag(name => 'cur_hotspotx', value => -1);
39 $im->settag(name => 'cur_hotspoty', value => 32);
40 ok($im->write(file=>'testout/hotspot2.cur', type=>'cur'),
41    "save with oor hotspot")
42   or print "# ",$im->errstr, "\n";
43
44 {
45   my $im2 = Imager->new;
46   ok($im2->read(file=>'testout/hotspot2.cur', type=>'cur'),
47      "re-read the hotspot set cursor")
48     or print "# ", $im->errstr, "\n";
49   is($im2->tags(name => 'cur_hotspotx'), 0, "check cur_hotspotx tag");
50   is($im2->tags(name => 'cur_hotspoty'), 31, "check cur_hotspoty tag");
51 }
52
53 {
54   my $data = '';
55   ok($im->write(data => \$data, type => 'cur'),
56      "write single to data");
57   print "# ", length $data, " bytes written\n";
58   my $im2 = Imager->new;
59   ok($im2->read(data => $data), "read back in");
60   is(Imager::i_img_diff($im->{IMG}, $im2->{IMG}), 0, "check image");
61 }
62
63 {
64   my $data = '';
65   ok(Imager->write_multi({ type => 'cur', data => \$data }, $im, $im),
66      "write multiple images");
67   print "# ", length $data, " bytes written\n";
68   my @im = Imager->read_multi(type => 'cur', data => $data)
69     or print "# ", Imager->errstr, "\n";
70   is(@im, 2, "read them back in");
71   is(Imager::i_img_diff($im->{IMG}, $im[0]{IMG}), 0, "check first image");
72   is(Imager::i_img_diff($im->{IMG}, $im[1]{IMG}), 0, "check second image");
73 }