]> git.imager.perl.org - imager.git/blob - t/t1000files.t
added pixel type 'index' to getscanline() and setscanline() for
[imager.git] / t / t1000files.t
1 #!perl -w
2
3 # This file is for testing file functionality that is independent of
4 # the file format
5
6 use strict;
7 use lib 't';
8 use Test::More tests => 32;
9 use Imager;
10
11 Imager::init_log("testout/t1000files.log", 1);
12
13 SKIP:
14 {
15   # Initally I tried to write this test using open to redirect files,
16   # but there was a buffering problem that made it so the data wasn't
17   # being written to the output file.  This external perl call avoids
18   # that problem
19
20   my $test_script = 'testout/t1000files_probe.pl';
21
22   # build a temp test script to use
23   ok(open(SCRIPT, "> $test_script"), "open test script")
24     or skip("no test script $test_script: $!", 2);
25   print SCRIPT <<'PERL';
26 #!perl
27 use Imager;
28 use strict;
29 my $file = shift or die "No file supplied";
30 open FH, "< $file" or die "Cannot open file: $!";
31 binmode FH;
32 my $io = Imager::io_new_fd(fileno(FH));
33 Imager::i_test_format_probe($io, -1);
34 PERL
35   close SCRIPT;
36   my $perl = $^X;
37   $perl = qq/"$perl"/ if $perl =~ / /;
38   
39   print "# script: $test_script\n";
40   my $cmd = "$perl -Mblib $test_script t/t1000files.t";
41   print "# command: $cmd\n";
42
43   my $out = `$cmd`;
44   is($?, 0, "command successful");
45   is($out, '', "output should be empty");
46 }
47
48 # test the file limit functions
49 # by default the limits are zero (unlimited)
50 print "# image file limits\n";
51 is_deeply([ Imager->get_file_limits() ], [0, 0, 0],
52           "check defaults");
53 ok(Imager->set_file_limits(width=>100), "set only width");
54 is_deeply([ Imager->get_file_limits() ], [100, 0, 0 ],
55           "check width set");
56 ok(Imager->set_file_limits(height=>150, bytes=>10000),
57    "set height and bytes");
58 is_deeply([ Imager->get_file_limits() ], [ 100, 150, 10000 ],
59           "check all values now set");
60 ok(Imager->set_file_limits(reset=>1, height => 99),
61    "set height and reset");
62 is_deeply([ Imager->get_file_limits() ], [ 0, 99, 0 ],
63           "check only height is set");
64 ok(Imager->set_file_limits(reset=>1),
65    "just reset");
66 is_deeply([ Imager->get_file_limits() ], [ 0, 0, 0 ],
67           "check all are reset");
68
69 # check file type probe
70 probe_ok("49492A41", undef, "not quite tiff");
71 probe_ok("4D4D0041", undef, "not quite tiff");
72 probe_ok("49492A00", "tiff", "tiff intel");
73 probe_ok("4D4D002A", "tiff", "tiff motorola");
74 probe_ok("474946383961", "gif", "gif 89");
75 probe_ok("474946383761", "gif", "gif 87");
76 probe_ok(<<TGA, "tga", "TGA");
77 00 00 0A 00 00 00 00 00 00 00 00 00 96 00 96 00
78 18 20 FF 00 00 00 95 00 00 00 FF 00 00 00 95 00
79 00 00 FF 00 00 00 95 00 00 00 FF 00 00 00 95 00
80 00 00 FF 00 00 00 95 00 00 00 FF 00 00 00 95 00
81 TGA
82
83 probe_ok(<<ICO, "ico", "Windows Icon");
84 00 00 01 00 02 00 20 20 10 00 00 00 00 00 E8 02
85 00 00 26 00 00 00 20 20 00 00 00 00 00 00 A8 08
86 00 00 0E 03 00 00 28 00 00 00 20 00 00 00 40 00
87 ICO
88
89 probe_ok(<<ICO, "cur", "Windows Cursor");
90 00 00 02 00 02 00 20 20 10 00 00 00 00 00 E8 02
91 00 00 26 00 00 00 20 20 00 00 00 00 00 00 A8 08
92 00 00 0E 03 00 00 28 00 00 00 20 00 00 00 40 00
93 ICO
94
95 probe_ok(<<RGB, "rgb", "SGI RGB");
96 01 DA 01 01 00 03 00 96 00 96 00 03 00 00 00 00 
97 00 00 00 FF 00 00 00 00 6E 6F 20 6E 61 6D 65 00
98 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
99 RGB
100
101 probe_ok(<<ILBM, "ilbm", "ILBM");
102 46 4F 52 4D 00 00 60 7A 49 4C 42 4D 42 4D 48 44
103 00 00 00 14 00 96 00 96 00 00 00 00 18 00 01 80
104 00 00 0A 0A 00 96 00 96 42 4F 44 59 00 00 60 51
105 ILBM
106
107 probe_ok(<<XPM, "xpm", "XPM");
108 2F 2A 20 58 50 4D 20 2A 2F 0A 73 74 61 74 69 63
109 20 63 68 61 72 20 2A 6E 6F 6E 61 6D 65 5B 5D 20
110 3D 20 7B 0A 2F 2A 20 77 69 64 74 68 20 68 65 69
111 XPM
112
113 probe_ok(<<PCX, "pcx", 'PCX');
114 0A 05 01 08 00 00 00 00 95 00 95 00 96 00 96 00
115 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
116 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
117 PCX
118
119 probe_ok(<<FITS, "fits", "FITS");
120 53 49 4D 50 4C 45 20 20 3D 20 20 20 20 20 20 20 
121 20 20 20 20 20 20 20 20 20 20 20 20 20 54 20 20 
122 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 
123 FITS
124
125 probe_ok(<<PSD, "psd", "Photoshop");
126 38 42 50 53 00 01 00 00 00 00 00 00 00 06 00 00
127 00 3C 00 00 00 96 00 08 00 03 00 00 00 00 00 00
128 0B E6 38 42 49 4D 03 ED 00 00 00 00 00 10 00 90
129 PSD
130
131 probe_ok(<<EPS, "eps", "Encapsulated Postscript");
132 25 21 50 53 2D 41 64 6F 62 65 2D 32 2E 30 20 45
133 50 53 46 2D 32 2E 30 0A 25 25 43 72 65 61 74 6F
134 72 3A 20 70 6E 6D 74 6F 70 73 0A 25 25 54 69 74
135 EPS
136
137 probe_ok(<<UTAH, "utah", "Utah RLE");
138 52 CC 00 00 00 00 0A 00 0A 00 0A 03 08 00 08 00 
139 2F 00 48 49 53 54 4F 52 59 3D 70 6E 6D 74 6F 72 
140 6C 65 20 6F 6E 20 54 68 75 20 4D 61 79 20 31 31 
141 20 31 36 3A 33 35 3A 34 33 20 32 30 30 36 0A 09 
142 UTAH
143
144 probe_ok(<<XWD, "xwd", "X Window Dump");
145 00 00 00 69 00 00 00 07 00 00 00 02 00 00 00 18
146 00 00 01 E4 00 00 01 3C 00 00 00 00 00 00 00 00
147 00 00 00 20 00 00 00 00 00 00 00 20 00 00 00 20
148 00 00 07 90 00 00 00 04 00 FF 00 00 00 00 FF 00
149 XWD
150
151 probe_ok(<<GZIP, "gzip", "gzip compressed");
152 1F 8B 08 08 C2 81 BD 44 02 03 49 6D 61 67 65 72
153 2D 30 2E 35 31 5F 30 33 2E 74 61 72 00 EC 5B 09
154 40 53 C7 BA 9E 24 AC 01 D9 44 04 44 08 8B B2 8A
155 C9 C9 42 92 56 41 50 20 A0 02 41 41 01 17 48 80
156 GZIP
157
158 probe_ok(<<BZIP2, "bzip2", "bzip2 compressed");
159 42 5A 68 39 31 41 59 26 53 59 0F D8 8C 09 00 03
160 28 FF FF FF FF FB 7F FB 77 FF EF BF 6B 7F BE FF
161 FF DF EE C8 0F FF F3 FF FF FF FC FF FB B1 FF FB
162 F4 07 DF D0 03 B8 03 60 31 82 05 2A 6A 06 83 20
163 BZIP2
164
165 sub probe_ok {
166   my ($packed, $exp_type, $name) = @_;
167
168   my $builder = Test::Builder->new;
169   $packed =~ tr/ \r\n//d; # remove whitespace used for layout
170   my $data = pack("H*", $packed);
171
172   my $io = Imager::io_new_buffer($data);
173   my $result = Imager::i_test_format_probe($io, -1);
174
175   return $builder->is_eq($result, $exp_type, $name)
176 }