+{ # read error reporting
+ my $im = Imager->new;
+ ok(!$im->read(file => "testimg/badcrc.png", type => "png"),
+ "read png with bad CRC chunk should fail");
+ is($im->errstr, "IHDR: CRC error", "check error message");
+}
+
+{ # write error reporting
+ my $im = test_image();
+ ok(!$im->write(type => "png", callback => limited_write(1), buffered => 0),
+ "write limited to 1 byte should fail");
+ is($im->errstr, "Write error on an iolayer source.: limit reached",
+ "check error message");
+}
+
+sub limited_write {
+ my ($limit) = @_;
+
+ return
+ sub {
+ my ($data) = @_;
+ $limit -= length $data;
+ if ($limit >= 0) {
+ print "# write of ", length $data, " bytes successful ($limit left)\n" if $debug_writes;
+ return 1;
+ }
+ else {
+ print "# write of ", length $data, " bytes failed\n";
+ Imager::i_push_error(0, "limit reached");
+ return;
+ }
+ };
+}