]> git.imager.perl.org - imager.git/blobdiff - t/t1000files.t
set_file_limits(reset => 1) now resets to defaults, not zero.
[imager.git] / t / t1000files.t
index 00380a023b00d22e39affd0d573b03b5b5b3d3de..cfad2c8e4852163a55715d070125cb5022c27f93 100644 (file)
@@ -4,13 +4,17 @@
 # the file format
 
 use strict;
-use Test::More tests => 35;
+use Test::More tests => 67;
 use Imager;
 
-Imager::init_log("testout/t1000files.log", 1);
+-d "testout" or mkdir "testout";
+
+Imager->open_log(log => "testout/t1000files.log");
 
 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
@@ -47,10 +51,10 @@ PERL
 # 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");
-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");
@@ -58,13 +62,49 @@ is_deeply([ Imager->get_file_limits() ], [ 100, 150, 10000 ],
          "check all values now set");
 ok(Imager->set_file_limits(reset=>1, height => 99),
    "set height and reset");
-is_deeply([ Imager->get_file_limits() ], [ 0, 99, 0 ],
+is_deeply([ Imager->get_file_limits() ], [ 0, 99, 0x40000000 ],
          "check only height is set");
 ok(Imager->set_file_limits(reset=>1),
    "just reset");
-is_deeply([ Imager->get_file_limits() ], [ 0, 0, 0 ],
+is_deeply([ Imager->get_file_limits() ], [ 0, 0, 0x40000000 ],
          "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 loading Imager/File/BAD.pm$),
+       "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 loading Imager/File/BAD.pm$),
+       "check error message");
+  }
+}
+
 # check file type probe
 probe_ok("49492A41", undef, "not quite tiff");
 probe_ok("4D4D0041", undef, "not quite tiff");
@@ -184,6 +224,69 @@ probe_ok(<<JPEG2K, "jp2", "JPEG 2000");
 00 6A 70 32 63 FF 4F FF 51 00 2F 00 00 00 00 01
 JPEG2K
 
+{ # RT 72475
+  # check error messages from read/read_multi
+  my $data = "nothing useful";
+  my @mult_data = Imager->read_multi(data => $data);
+  is(@mult_data, 0, "read_multi with non-image input data should fail");
+  is(Imager->errstr,
+     "type parameter missing and it couldn't be determined from the file contents",
+     "check the error message");
+
+  my @mult_file = Imager->read_multi(file => "t/t1000files.t");
+  is(@mult_file, 0, "read_multi with non-image filename should fail");
+  is(Imager->errstr,
+     "type parameter missing and it couldn't be determined from the file contents or file name",
+     "check the error message");
+
+  my $im = Imager->new;
+  ok(!$im->read(data => $data), "read from non-image data should fail");
+  is($im->errstr,
+     "type parameter missing and it couldn't be determined from the file contents",
+     "check the error message");
+
+  ok(!$im->read(file => "t/t1000files.t"),
+     "read from non-image file should fail");
+  is($im->errstr,
+     "type parameter missing and it couldn't be determined from the file contents or file name",
+     "check the error message");
+}
+
+{
+  # test def_guess_type
+  my @tests =
+    (
+     pnm => "pnm",
+     GIF => "gif",
+     tif => "tiff",
+     TIFF => "tiff",
+     JPG => "jpeg",
+     rle => "utah",
+     bmp => "bmp",
+     dib => "bmp",
+     rgb => "sgi",
+     BW => "sgi",
+     TGA => "tga",
+     CUR => "cur",
+     ico => "ico",
+     ILBM => "ilbm",
+     pcx => "pcx",
+     psd => "psd",
+    );
+
+  while (my ($ext, $expect) = splice(@tests, 0, 2)) {
+    my $filename = "foo.$ext";
+    is(Imager::def_guess_type($filename), $expect,
+       "type for $filename should be $expect");
+  }
+}
+
+Imager->close_log;
+
+unless ($ENV{IMAGER_KEEP_FILES}) {
+  unlink "testout/t1000files.log";
+}
+
 sub probe_ok {
   my ($packed, $exp_type, $name) = @_;