Added io_buffer for reading from scalars. Also added test cases. Added
[imager.git] / t / t07iolayer.t
CommitLineData
4dfa5522
AMH
1BEGIN { $|=1; print "1..7\n"; }
2END { print "not ok 1\n" unless $loaded; };
3use Imager qw(:all);
4++$loaded;
5print "ok 1\n";
6init_log("testout/t07iolayer.log", 1);
7
8
9undef($/);
10# start by testing io buffer
11
12$data="P2\n2 2\n255\n 255 0\n0 255\n";
13$IO = Imager::io_new_buffer($data);
14$im = Imager::i_readpnm_wiol($IO, -1);
15
16print "ok 2\n";
17
18
19open(FH, ">testout/t07.ppm") or die $!;
20binmode(FH);
21$fd = fileno(FH);
22$IO2 = Imager::io_new_fd( $fd );
23Imager::i_writeppm_wiol($im, $IO2);
24close(FH);
25undef($im);
26
27
28
29open(FH, "<testimg/penguin-base.ppm");
30$data = <FH>;
31close(FH);
32$IO3 = Imager::io_new_buffer($data);
33#undef($data);
34$im = Imager::i_readpnm_wiol($IO3, -1);
35
36print "ok 3\n";
37
38
39open(FH, "<testimg/penguin-base.ppm") or die $!;
40binmode(FH);
41$fd = fileno(FH);
42$IO4 = Imager::io_new_fd( $fd );
43$im2 = Imager::i_readpnm_wiol($IO4, -1);
44close(FH);
45undef($IO4);
46
47print "ok 4\n";
48
49Imager::i_img_diff($im, $im2) ? print "not ok 5\n" : print "ok 5\n";
50undef($im2);
51
52
53$IO5 = Imager::io_new_bufchain();
54Imager::i_writeppm_wiol($im, $IO5);
55$data2 = Imager::io_slurp($IO5);
56undef($IO5);
57
58print "ok 6\n";
59
60$IO6 = Imager::io_new_buffer($data2);
61$im3 = Imager::i_readpnm_wiol($IO6, -1);
62
63Imager::i_img_diff($im, $im3) ? print "not ok 7\n" : print "ok 7\n";
64
65
66
67