3 use Test::More tests => 20;
5 BEGIN { use_ok(Imager => ':all') };
7 init_log("testout/t07iolayer.log", 1);
10 # start by testing io buffer
12 my $data="P2\n2 2\n255\n 255 0\n0 255\n";
13 my $IO = Imager::io_new_buffer($data);
14 my $im = Imager::i_readpnm_wiol($IO, -1);
16 ok($im, "read from data io");
18 open(FH, ">testout/t07.ppm") or die $!;
21 my $IO2 = Imager::io_new_fd( $fd );
22 Imager::i_writeppm_wiol($im, $IO2);
26 open(FH, "<testimg/penguin-base.ppm");
30 my $IO3 = Imager::io_new_buffer($data);
32 $im = Imager::i_readpnm_wiol($IO3, -1);
34 ok($im, "read from buffer, for compare");
37 open(FH, "<testimg/penguin-base.ppm") or die $!;
40 my $IO4 = Imager::io_new_fd( $fd );
41 my $im2 = Imager::i_readpnm_wiol($IO4, -1);
45 ok($im2, "read from file, for compare");
47 is(i_img_diff($im, $im2), 0, "compare images");
50 my $IO5 = Imager::io_new_bufchain();
51 Imager::i_writeppm_wiol($im, $IO5);
52 my $data2 = Imager::io_slurp($IO5);
55 ok($data2, "check we got data from bufchain");
57 my $IO6 = Imager::io_new_buffer($data2);
58 my $im3 = Imager::i_readpnm_wiol($IO6, -1);
60 is(Imager::i_img_diff($im, $im3), 0, "read from buffer");
65 my ($size, $maxread) = @_;
66 my $out = substr($work, $pos, $maxread);
71 my ($size, $maxread) = @_;
72 my $out = substr($work, $pos, $maxread);
76 my $IO7 = Imager::io_new_cb(undef, \&io_reader, undef, undef);
77 ok($IO7, "making readcb object");
78 my $im4 = Imager::i_readpnm_wiol($IO7, -1);
79 ok($im4, "read from cb");
80 ok(Imager::i_img_diff($im, $im4) == 0, "read from cb image match");
83 $IO7 = Imager::io_new_cb(undef, \&io_reader2, undef, undef);
84 ok($IO7, "making short readcb object");
85 my $im5 = Imager::i_readpnm_wiol($IO7, -1);
86 ok($im4, "read from cb2");
87 is(Imager::i_img_diff($im, $im5), 0, "read from cb2 image match");
91 substr($work, $pos, $pos+length $what) = $what;
102 my $IO8 = Imager::io_new_cb(\&io_writer, undef, undef, \&io_close);
103 ok($IO8, "making writecb object");
106 ok(Imager::i_writeppm_wiol($im, $IO8), "write to cb");
107 # I originally compared this to $data, but that doesn't include the
109 ok($work eq $data2, "write image match");
110 ok($did_close, "did close");
112 # with a short buffer, no closer
113 my $IO9 = Imager::io_new_cb(\&io_writer, undef, undef, undef, 1);
114 ok($IO9, "making short writecb object");
117 ok(Imager::i_writeppm_wiol($im, $IO9), "write to short cb");
118 ok($work eq $data2, "short write image match");