]> git.imager.perl.org - imager.git/blob - t/t05error.t
improved thread safety for Imager
[imager.git] / t / t05error.t
1 #!perl -w
2 use strict;
3 use Test::More tests => 7;
4 BEGIN { use_ok("Imager", ":all") }
5
6 -d "testout" or mkdir "testout";
7
8 Imager->open_log(log => "testout/t05error.log");
9
10 # try to read an invalid pnm file
11 open FH, "< testimg/junk.ppm"
12   or die "Cannot open testin/junk: $!";
13 binmode(FH);
14 my $IO = Imager::io_new_fd(fileno(FH));
15 my $im = i_readpnm_wiol($IO, -1);
16 SKIP:{
17   ok(!$im, "read of junk.ppm should have failed")
18     or skip("read didn't fail!", 5);
19
20   my @errors = Imager::i_errors();
21
22   is(scalar @errors, 1, "got the errors")
23     or skip("no errors to check", 4);
24
25  SKIP:
26   {
27     my $error0 = $errors[0];
28     is(ref $error0, "ARRAY", "entry 0 is an array ref")
29       or skip("entry 0 not an array", 3);
30
31     is(scalar @$error0, 2, "entry 0 has 2 elements")
32       or skip("entry 0 doesn't have enough elements", 2);
33
34     is($error0->[0], "while skipping to height", "check message");
35     is($error0->[1], "0", "error code should be 0");
36   }
37 }
38
39 Imager->close_log;
40
41 unless ($ENV{IMAGER_KEEP_FILES}) {
42   unlink "testout/t05error.log";
43 }