- reading a raw image no longer exits on a short read or read error,
[imager.git] / t / t103raw.t
index b565cbf730e31da7cfb8047ebd083991b399cca1..94996ff3fb928bd25b02cdc640d7d558b18074ff 100644 (file)
@@ -1,7 +1,7 @@
 #!perl -w
 use strict;
 use lib 't';
-use Test::More tests => 17;
+use Test::More tests => 23;
 use Imager qw(:all);
 init_log("testout/t103raw.log",1);
 
@@ -152,6 +152,33 @@ SKIP:
   }
 }
 
+{ # error handling checks
+  # should get an error writing to a open for read file
+  # make a empty file
+  open RAW, "> testout/t103_empty.raw"
+    or die "Cannot create testout/t103_empty.raw: $!";
+  close RAW;
+  open RAW, "< testout/t103_empty.raw"
+    or die "Cannot open testout/t103_empty.raw: $!";
+  my $im = Imager->new(xsize => 50, ysize=>50);
+  ok(!$im->write(fh => \*RAW, type => 'raw'),
+     "write to open for read handle");
+  cmp_ok($im->errstr, '=~', '^Could not write to file: write\(\) failure', 
+        "check error message");
+  close RAW;
+
+  # should get an error reading an empty file
+  ok(!$im->read(file => 'testout/t103_empty.raw', xsize => 50, ysize=>50, type=>'raw'),
+     'read an empty file');
+  is($im->errstr, 'premature end of file', "check message");
+  open RAW, "> testout/t103_empty.raw"
+    or die "Cannot create testout/t103_empty.raw: $!";
+  ok(!$im->read(fh => \*RAW, , xsize => 50, ysize=>50, type=>'raw'),
+     'read a file open for write');
+  cmp_ok($im->errstr, '=~', '^error reading file: read\(\) failure', "check message");
+  
+}
+
 sub read_test {
   my ($in, $xsize, $ysize, $data, $store, $intrl, $base) = @_;
   open FH, $in or die "Cannot open $in: $!";