4 @INC = ("../lib", "lib/compress");
8 use lib qw(t t/compress);
19 # use Test::NoWarnings, if available
22 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 };
24 plan tests => 841 + $extra ;
28 use IO::Compress::Bzip2 qw($Bzip2Error) ;
29 use IO::Uncompress::Bunzip2 qw($Bunzip2Error) ;
32 my $CompressClass = 'IO::Compress::Bzip2';
33 my $UncompressClass = getInverse($CompressClass);
34 my $Error = getErrorRef($CompressClass);
35 my $UnError = getErrorRef($UncompressClass);
39 my $filename = shift ;
43 my $fil = new $UncompressClass $filename,
49 $data = $init if defined $init ;
50 1 while $fil->read($data) > 0;
59 title "Testing $CompressClass Errors";
63 for my $value (undef, -1, 'fred')
65 my $stringValue = defined $value ? $value : 'undef';
66 title "BlockSize100K => $stringValue";
67 my $err = "Parameter 'BlockSize100K' must be an unsigned int, got '$stringValue'";
69 eval { $bz = new IO::Compress::Bzip2(\$buffer, BlockSize100K => $value) };
70 like $@, mkErr("IO::Compress::Bzip2: $err"),
71 " value $stringValue is bad";
72 is $Bzip2Error, "IO::Compress::Bzip2: $err",
73 " value $stringValue is bad";
74 ok ! $bz, " no bz object";
77 for my $value (0, 10, 99999)
79 my $stringValue = defined $value ? $value : 'undef';
80 title "BlockSize100K => $stringValue";
81 my $err = "Parameter 'BlockSize100K' not between 1 and 9, got $stringValue";
83 eval { $bz = new IO::Compress::Bzip2(\$buffer, BlockSize100K => $value) };
84 like $@, mkErr("IO::Compress::Bzip2: $err"),
85 " value $stringValue is bad";
86 is $Bzip2Error, "IO::Compress::Bzip2: $err",
87 " value $stringValue is bad";
88 ok ! $bz, " no bz object";
91 for my $value (undef, -1, 'fred')
93 my $stringValue = defined $value ? $value : 'undef';
94 title "WorkFactor => $stringValue";
95 my $err = "Parameter 'WorkFactor' must be an unsigned int, got '$stringValue'";
97 eval { $bz = new IO::Compress::Bzip2(\$buffer, WorkFactor => $value) };
98 like $@, mkErr("IO::Compress::Bzip2: $err"),
99 " value $stringValue is bad";
100 is $Bzip2Error, "IO::Compress::Bzip2: $err",
101 " value $stringValue is bad";
102 ok ! $bz, " no bz object";
105 for my $value (251, 99999)
107 my $stringValue = defined $value ? $value : 'undef';
108 title "WorkFactor => $stringValue";
109 my $err = "Parameter 'WorkFactor' not between 0 and 250, got $stringValue";
111 eval { $bz = new IO::Compress::Bzip2(\$buffer, WorkFactor => $value) };
112 like $@, mkErr("IO::Compress::Bzip2: $err"),
113 " value $stringValue is bad";
114 is $Bzip2Error, "IO::Compress::Bzip2: $err",
115 " value $stringValue is bad";
116 ok ! $bz, " no bz object";
123 title "Testing $UncompressClass Errors";
127 for my $value (-1, 'fred')
129 my $stringValue = defined $value ? $value : 'undef';
130 title "Small => $stringValue";
131 my $err = "Parameter 'Small' must be an int, got '$stringValue'";
133 eval { $bz = new IO::Uncompress::Bunzip2(\$buffer, Small => $value) };
134 like $@, mkErr("IO::Uncompress::Bunzip2: $err"),
135 " value $stringValue is bad";
136 is $Bunzip2Error, "IO::Uncompress::Bunzip2: $err",
137 " value $stringValue is bad";
138 ok ! $bz, " no bz object";
144 title "Testing $CompressClass and $UncompressClass";
151 for my $value ( 1 .. 9 )
153 title "$CompressClass - BlockSize100K => $value";
154 my $lex = new LexFile my $name ;
156 $bz = new IO::Compress::Bzip2($name, BlockSize100K => $value)
157 or diag $IO::Compress::Bzip2::Bzip2Error ;
158 ok $bz, " bz object ok";
162 is myBZreadFile($name), $hello, " got expected content";
165 for my $value ( 0 .. 250 )
167 title "$CompressClass - WorkFactor => $value";
168 my $lex = new LexFile my $name ;
170 $bz = new IO::Compress::Bzip2($name, WorkFactor => $value);
171 ok $bz, " bz object ok";
175 is myBZreadFile($name), $hello, " got expected content";
178 for my $value ( 0 .. 1 )
180 title "$UncompressClass - Small => $value";
181 my $lex = new LexFile my $name ;
183 $bz = new IO::Compress::Bzip2($name);
184 ok $bz, " bz object ok";
188 my $fil = new $UncompressClass $name,
193 1 while $fil->read($data) > 0;
197 is $data, $hello, " got expected";