xref: /openbsd-src/gnu/usr.bin/perl/cpan/IO-Zlib/t/basic.t (revision f2a19305cfc49ea4d1a5feb55cd6c283c6f1e031)
1use strict;
2use warnings;
3
4use IO::Zlib;
5
6sub ok
7{
8    my ($no, $ok) = @_ ;
9    print "ok $no\n" if $ok ;
10    print "not ok $no\n" unless $ok ;
11}
12
13my $name = "test_basic_$$.gz";
14
15print "1..17\n";
16
17my $hello = <<EOM ;
18hello world
19this is a test
20EOM
21
22my $file;
23
24ok(1, $file = IO::Zlib->new($name, "wb"));
25ok(2, $file->print($hello));
26ok(3, $file->opened());
27ok(4, $file->close());
28ok(5, !$file->opened());
29
30my $uncomp;
31
32ok(6, $file = IO::Zlib->new());
33ok(7, $file->open($name, "rb"));
34ok(8, !$file->eof());
35ok(9, $file->read($uncomp, 1024) == length($hello));
36ok(10, $uncomp eq $hello);
37ok(11, $file->eof());
38ok(12, $file->opened());
39ok(13, $file->close());
40ok(14, !$file->opened());
41
42$file = IO::Zlib->new($name, "rb");
43ok(15, $file->read($uncomp, 1024, length($uncomp)) == length($hello));
44ok(16, $uncomp eq $hello . $hello);
45$file->close();
46
47unlink($name);
48
49ok(17, !defined(IO::Zlib->new($name, "rb")));
50