add format probes for SGI RGB, ILBM, XPM, PCX, FITS, Photoshop, EPS
[imager.git] / t / t1000files.t
CommitLineData
63e0dc02
TC
1#!perl -w
2
3# This file is for testing file functionality that is independent of
4# the file format
5
6use strict;
fe10c10a 7use lib 't';
8b302e44 8use Test::More tests => 27;
63e0dc02
TC
9use Imager;
10
11Imager::init_log("testout/t1000files.log", 1);
12
13SKIP:
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
27use Imager;
28use strict;
29my $file = shift or die "No file supplied";
30open FH, "< $file" or die "Cannot open file: $!";
31binmode FH;
32my $io = Imager::io_new_fd(fileno(FH));
33Imager::i_test_format_probe($io, -1);
34PERL
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
77157728
TC
48# test the file limit functions
49# by default the limits are zero (unlimited)
50print "# image file limits\n";
51is_deeply([ Imager->get_file_limits() ], [0, 0, 0],
52 "check defaults");
53ok(Imager->set_file_limits(width=>100), "set only width");
54is_deeply([ Imager->get_file_limits() ], [100, 0, 0 ],
55 "check width set");
56ok(Imager->set_file_limits(height=>150, bytes=>10000),
57 "set height and bytes");
58is_deeply([ Imager->get_file_limits() ], [ 100, 150, 10000 ],
59 "check all values now set");
60ok(Imager->set_file_limits(reset=>1, height => 99),
61 "set height and reset");
62is_deeply([ Imager->get_file_limits() ], [ 0, 99, 0 ],
63 "check only height is set");
64ok(Imager->set_file_limits(reset=>1),
65 "just reset");
66is_deeply([ Imager->get_file_limits() ], [ 0, 0, 0 ],
67 "check all are reset");
db7a8754
TC
68
69# check file type probe
70probe_ok("49492A41", undef, "not quite tiff");
71probe_ok("4D4D0041", undef, "not quite tiff");
72probe_ok("49492A00", "tiff", "tiff intel");
73probe_ok("4D4D002A", "tiff", "tiff motorola");
74probe_ok("474946383961", "gif", "gif 89");
75probe_ok("474946383761", "gif", "gif 87");
ea1136fc
TC
76probe_ok(<<TGA, "tga", "TGA");
7700 00 0A 00 00 00 00 00 00 00 00 00 96 00 96 00
7818 20 FF 00 00 00 95 00 00 00 FF 00 00 00 95 00
7900 00 FF 00 00 00 95 00 00 00 FF 00 00 00 95 00
8000 00 FF 00 00 00 95 00 00 00 FF 00 00 00 95 00
81TGA
82
83probe_ok(<<ICO, "ico", "Windows Icon");
8400 00 01 00 02 00 20 20 10 00 00 00 00 00 E8 02
8500 00 26 00 00 00 20 20 00 00 00 00 00 00 A8 08
8600 00 0E 03 00 00 28 00 00 00 20 00 00 00 40 00
87ICO
db7a8754 88
8b302e44
TC
89probe_ok(<<RGB, "rgb", "SGI RGB");
9001 DA 01 01 00 03 00 96 00 96 00 03 00 00 00 00
9100 00 00 FF 00 00 00 00 6E 6F 20 6E 61 6D 65 00
9200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
93RGB
94
95probe_ok(<<ILBM, "ilbm", "ILBM");
9646 4F 52 4D 00 00 60 7A 49 4C 42 4D 42 4D 48 44
9700 00 00 14 00 96 00 96 00 00 00 00 18 00 01 80
9800 00 0A 0A 00 96 00 96 42 4F 44 59 00 00 60 51
99ILBM
100
101probe_ok(<<XPM, "xpm", "XPM");
1022F 2A 20 58 50 4D 20 2A 2F 0A 73 74 61 74 69 63
10320 63 68 61 72 20 2A 6E 6F 6E 61 6D 65 5B 5D 20
1043D 20 7B 0A 2F 2A 20 77 69 64 74 68 20 68 65 69
105XPM
106
107probe_ok(<<PCX, "pcx", 'PCX');
1080A 05 01 08 00 00 00 00 95 00 95 00 96 00 96 00
10900 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
11000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
111PCX
112
113probe_ok(<<FITS, "fits", "FITS");
11453 49 4D 50 4C 45 20 20 3D 20 20 20 20 20 20 20
11520 20 20 20 20 20 20 20 20 20 20 20 20 54 20 20
11620 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
117FITS
118
119probe_ok(<<PSD, "psd", "Photoshop");
12038 42 50 53 00 01 00 00 00 00 00 00 00 06 00 00
12100 3C 00 00 00 96 00 08 00 03 00 00 00 00 00 00
1220B E6 38 42 49 4D 03 ED 00 00 00 00 00 10 00 90
123PSD
124
125probe_ok(<<EPS, "eps", "Encapsulated Postscript");
12625 21 50 53 2D 41 64 6F 62 65 2D 32 2E 30 20 45
12750 53 46 2D 32 2E 30 0A 25 25 43 72 65 61 74 6F
12872 3A 20 70 6E 6D 74 6F 70 73 0A 25 25 54 69 74
129EPS
130
db7a8754
TC
131sub probe_ok {
132 my ($packed, $exp_type, $name) = @_;
133
134 my $builder = Test::Builder->new;
ea1136fc 135 $packed =~ tr/ \r\n//d; # remove whitespace used for layout
db7a8754
TC
136 my $data = pack("H*", $packed);
137
138 my $io = Imager::io_new_buffer($data);
139 my $result = Imager::i_test_format_probe($io, -1);
140
141 return $builder->is_eq($result, $exp_type, $name)
142}