]> git.imager.perl.org - imager.git/blobdiff - t/t1000files.t
note the purpose of a complex test
[imager.git] / t / t1000files.t
index 041d5d2599245b4f7ed30a133bfa2afb03792ecb..10bbc4746a1738786eb93a5e351bcc2273c3c65c 100644 (file)
@@ -4,13 +4,17 @@
 # the file format
 
 use strict;
 # the file format
 
 use strict;
-use Test::More tests => 32;
+use Test::More tests => 43;
 use Imager;
 
 use Imager;
 
-Imager::init_log("testout/t1000files.log", 1);
+-d "testout" or mkdir "testout";
+
+Imager->open_log(log => "testout/t1000files.log");
 
 SKIP:
 {
 
 SKIP:
 {
+  # Test that i_test_format_probe() doesn't pollute stdout
+
   # Initally I tried to write this test using open to redirect files,
   # but there was a buffering problem that made it so the data wasn't
   # being written to the output file.  This external perl call avoids
   # Initally I tried to write this test using open to redirect files,
   # but there was a buffering problem that made it so the data wasn't
   # being written to the output file.  This external perl call avoids
@@ -47,10 +51,10 @@ PERL
 # test the file limit functions
 # by default the limits are zero (unlimited)
 print "# image file limits\n";
 # test the file limit functions
 # by default the limits are zero (unlimited)
 print "# image file limits\n";
-is_deeply([ Imager->get_file_limits() ], [0, 0, 0],
+is_deeply([ Imager->get_file_limits() ], [0, 0, 0x40000000 ],
          "check defaults");
 ok(Imager->set_file_limits(width=>100), "set only width");
          "check defaults");
 ok(Imager->set_file_limits(width=>100), "set only width");
-is_deeply([ Imager->get_file_limits() ], [100, 0, 0 ],
+is_deeply([ Imager->get_file_limits() ], [100, 0, 0x40000000 ],
          "check width set");
 ok(Imager->set_file_limits(height=>150, bytes=>10000),
    "set height and bytes");
          "check width set");
 ok(Imager->set_file_limits(height=>150, bytes=>10000),
    "set height and bytes");
@@ -65,6 +69,42 @@ ok(Imager->set_file_limits(reset=>1),
 is_deeply([ Imager->get_file_limits() ], [ 0, 0, 0 ],
          "check all are reset");
 
 is_deeply([ Imager->get_file_limits() ], [ 0, 0, 0 ],
          "check all are reset");
 
+# test error handling for loading file handers
+{
+  # first, no module at all
+  {
+    my $data = "abc";
+    ok(!Imager->new(data => $data, filetype => "unknown"),
+       "try to read an unknown file type");
+   like(Imager->errstr, qr(^format 'unknown' not supported - formats .* - Can't locate Imager/File/UNKNOWN.pm or Imager/File/UNKNOWNReader.pm$),
+       "check error message");
+  }
+  {
+    my $data;
+    my $im = Imager->new(xsize => 10, ysize => 10);
+    ok(!$im->write(data => \$data, type => "unknown"),
+       "try to write an unknown file type");
+   like($im->errstr, qr(^format 'unknown' not supported - formats .* - Can't locate Imager/File/UNKNOWN.pm or Imager/File/UNKNOWNWriter.pm$),
+       "check error message");
+  }
+  push @INC, "t/t1000lib";
+  {
+    my $data = "abc";
+    ok(!Imager->new(data => $data, filetype => "bad"),
+       "try to read an bad (other load failure) file type");
+   like(Imager->errstr, qr(^format 'bad' not supported - formats .* available for reading - This module fails to load$),
+       "check error message");
+  }
+  {
+    my $data;
+    my $im = Imager->new(xsize => 10, ysize => 10);
+    ok(!$im->write(data => \$data, type => "bad"),
+       "try to write an bad file type");
+   like($im->errstr, qr(^format 'bad' not supported - formats .* available for writing - This module fails to load$),
+       "check error message");
+  }
+}
+
 # check file type probe
 probe_ok("49492A41", undef, "not quite tiff");
 probe_ok("4D4D0041", undef, "not quite tiff");
 # check file type probe
 probe_ok("49492A41", undef, "not quite tiff");
 probe_ok("4D4D0041", undef, "not quite tiff");
@@ -79,6 +119,12 @@ probe_ok(<<TGA, "tga", "TGA");
 00 00 FF 00 00 00 95 00 00 00 FF 00 00 00 95 00
 TGA
 
 00 00 FF 00 00 00 95 00 00 00 FF 00 00 00 95 00
 TGA
 
+probe_ok(<<TGA, "tga", "TGA 32-bit");
+00 00 0A 00 00 00 00 00 00 00 00 00 0A 00 0A 00
+20 08 84 00 00 00 00 84 FF FF FF FF 84 00 00 00
+00 84 FF FF FF FF 84 00 00 00 00 84 FF FF FF FF
+TGA
+
 probe_ok(<<ICO, "ico", "Windows Icon");
 00 00 01 00 02 00 20 20 10 00 00 00 00 00 E8 02
 00 00 26 00 00 00 20 20 00 00 00 00 00 00 A8 08
 probe_ok(<<ICO, "ico", "Windows Icon");
 00 00 01 00 02 00 20 20 10 00 00 00 00 00 E8 02
 00 00 26 00 00 00 20 20 00 00 00 00 00 00 A8 08
@@ -161,6 +207,29 @@ FF DF EE C8 0F FF F3 FF FF FF FC FF FB B1 FF FB
 F4 07 DF D0 03 B8 03 60 31 82 05 2A 6A 06 83 20
 BZIP2
 
 F4 07 DF D0 03 B8 03 60 31 82 05 2A 6A 06 83 20
 BZIP2
 
+probe_ok(<<WEBP, "webp", "Google WEBP");
+52 49 46 46 2C 99 00 00 57 45 42 50 56 50 38 20
+20 99 00 00 70 7A 02 9D 01 2A E0 01 80 02 00 87
+08 85 85 88 85 84 88 88 83 AF E2 F7 64 1F 98 55
+1B 6A 70 F5 8A 45 09 95 0C 09 7E 25 D9 2E 46 44
+07 84 FB 01 FD 2C 8A 2F 97 CC ED DB 50 0F 11 3B
+WEBP
+
+probe_ok(<<JPEG2K, "jp2", "JPEG 2000");
+00 00 00 0C 6A 50 20 20 0D 0A 87 0A 00 00 00 14
+66 74 79 70 6A 70 32 20 00 00 00 00 6A 70 32 20
+00 00 00 2D 6A 70 32 68 00 00 00 16 69 68 64 72
+00 00 02 80 00 00 01 E0 00 03 07 07 00 00 00 00
+00 0F 63 6F 6C 72 01 00 00 00 00 00 10 00 00 00
+00 6A 70 32 63 FF 4F FF 51 00 2F 00 00 00 00 01
+JPEG2K
+
+Imager->close_log;
+
+unless ($ENV{IMAGER_KEEP_FILES}) {
+  unlink "testout/t1000files.log";
+}
+
 sub probe_ok {
   my ($packed, $exp_type, $name) = @_;
 
 sub probe_ok {
   my ($packed, $exp_type, $name) = @_;