-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pr-zlib is version 1.0.3, commit c1418dd1abde5c4f6bcc7073b7965eeb4c168144 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
= 1.0.3 - 3-Dec-2015 | ||
* Added a license. This library is now covered under the zlib license. | ||
* Some performance tuning. Reads are 2-3 times faster, while writes are | ||
about twenty percent faster. | ||
* This gem is now signed. | ||
* Added a pr-zlib.rb file for convenience. | ||
* Use require_relative internally where appropriate. | ||
* More stringent value and limit checking added. Thanks go to | ||
Chris Seaton for the patches. | ||
|
||
= 1.0.2 - 24-Jun-2015 | ||
* Fixed a marshalling issue. | ||
|
||
= 1.0.1 - 16-Oct-2014 | ||
* Added benchmark and profiler scripts and rake tasks. | ||
* Switched profiling scripts to use ruby-prof. | ||
* The test-unit and ruby-prof libraries are now development dependencies. | ||
* Minor updates to eliminate warnings for Ruby 1.9.3 and 2.1. | ||
* Some minor test suite updates, mostly for 1.9.3. | ||
* Updated the gemspec, removed Rubyforge references. | ||
|
||
= 1.0.0 - 12-Jun-2009 | ||
* Initial release |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CHANGES | ||
MANIFEST | ||
README | ||
pr-zlib.gemspec | ||
bin/minizip.rb | ||
certs/djberg96_pub.pem | ||
examples/example_rbzlib.rb | ||
lib/pr-zlib.rb | ||
lib/pr/rbzlib.rb | ||
lib/pr/zlib.rb | ||
test/test_rbzlib_bytef.rb | ||
test/test_rbzlib_posf.rb | ||
test/test_rbzlib.rb | ||
test/test_zlib_deflate.rb | ||
test/test_zlib_gzip_file.rb | ||
test/test_zlib_gzip_reader.rb | ||
test/test_zlib_gzip_writer.rb | ||
test/test_zlib_inflate.rb | ||
test/test_zlib_zstream.rb | ||
test/test_zlib.rb |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
= Description | ||
The pr-zlib library is a pure Ruby version of the zlib compression library. | ||
It consists of both a port of zlib.h and the Ruby zlib library that ships as | ||
part of the standard library. | ||
|
||
= Synopsis | ||
|
||
# Imitating a bit of code used in rubygems | ||
require 'pr/zlib' | ||
require 'stringio' | ||
|
||
data = StringIO.new(data) | ||
Zlib::GzipReader.new(data).read | ||
|
||
= Motivation | ||
|
||
First, building the zlib C library on MS Windows with Visual C++ is very | ||
difficult. However, certain libraries depend on zlib, most notably rubygems. | ||
By providing a pure Ruby version we eliminate any compiler or platform | ||
compatability issues. | ||
|
||
Second, even some Unix distributions, such as Debian, do not ship with | ||
the zlib library by default. By creating a pure Ruby version of the zlib | ||
library we eliminate the need to install a 3rd party C library, and | ||
eliminate a potential weak link in the dependency chain. | ||
|
||
Third, by creating pure Ruby versions of the library and the interface we | ||
are more likely to receive patches, feature requests, documentation updates, | ||
etc, from the Ruby community since not everyone who knows Ruby also knows C. | ||
|
||
Last, the zlib interface that ships as part of the stdlib is a little on the | ||
clunky side. By providing a pure Ruby version, authors can create their own | ||
interface as they see fit. | ||
|
||
= TODO | ||
|
||
More tests, and better tests, are needed for both Rbzlib and Zlib. | ||
|
||
= Caveats | ||
You cannot use both this library and the zlib standard library at the same | ||
time. If you try to use both there is a good chance you will get an allocation | ||
error of some sort. If you already have zlib, you do not need this library. | ||
|
||
= License | ||
|
||
This library is covered under the same license as zlib itself. For the text | ||
of the zlib license, please see http://zlib.net/zlib_license.html. | ||
|
||
= Authors | ||
|
||
* Park Heesob (C translation) | ||
* Daniel Berger (Testing, packaging, deployment) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
require 'rake' | ||
require 'rake/clean' | ||
require 'rake/testtask' | ||
require 'rbconfig' | ||
|
||
CLEAN.include("**/*.rbc", "**/*.gem", "**/*.txt", "**/*.gz") | ||
|
||
desc 'Install the pr-zlib library as zlib' | ||
task :install_as_zlib do | ||
install_dir = File.join(RbConfig::CONFIG['sitelibdir'], 'pr') | ||
Dir.mkdir(install_dir) unless File.exists?(install_dir) | ||
|
||
cp('lib/pr/zlib.rb', RbConfig::CONFIG['sitelibdir'], :verbose => true) | ||
cp('lib/pr/rbzlib.rb', install_dir, :verbose => true) | ||
end | ||
|
||
namespace :gem do | ||
desc 'Create the pr-zlib gem' | ||
task :create do | ||
require 'rubygems/package' | ||
spec = eval(IO.read('pr-zlib.gemspec')) | ||
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem') | ||
Gem::Package.build(spec, true) | ||
end | ||
|
||
desc 'Install the pr-zlib gem' | ||
task :install => [:create] do | ||
file = Dir["*.gem"].first | ||
sh "gem install -l #{file}" | ||
end | ||
end | ||
|
||
namespace :bench do | ||
desc "Run the zlib benchmark" | ||
task :zlib do | ||
Dir.chdir('profile'){ ruby "bench_zlib.rb" } | ||
end | ||
|
||
desc "Run the pr-zlib benchmark" | ||
task :przlib do | ||
sh "ruby -Ilib profile/bench_pr_zlib.rb" | ||
end | ||
end | ||
|
||
namespace :profile do | ||
desc "Run the profiler on the write operation" | ||
task :write do | ||
sh "ruby -Ilib profile/profile_pr_zlib_write.rb" | ||
end | ||
|
||
desc "Run the profiler on the read operation" | ||
task :read do | ||
sh "ruby -Ilib profile/profile_pr_zlib_read.rb" | ||
end | ||
end | ||
|
||
Rake::TestTask.new do |t| | ||
t.warning = true | ||
t.verbose = true | ||
end | ||
|
||
Rake::TestTask.new('test_zlib') do |t| | ||
t.warning = true | ||
t.verbose = true | ||
t.test_files = FileList['test/test_zlib.rb'] | ||
end | ||
|
||
Rake::TestTask.new('test_gzip_file') do |t| | ||
t.warning = true | ||
t.verbose = true | ||
t.test_files = FileList['test/test_zlib_gzip_file.rb'] | ||
end | ||
|
||
Rake::TestTask.new('test_gzip_reader') do |t| | ||
t.warning = true | ||
t.verbose = true | ||
t.test_files = FileList['test/test_zlib_gzip_reader.rb'] | ||
end | ||
|
||
Rake::TestTask.new('test_gzip_writer') do |t| | ||
t.warning = true | ||
t.verbose = true | ||
t.test_files = FileList['test/test_zlib_gzip_writer.rb'] | ||
end | ||
|
||
Rake::TestTask.new('test_deflate') do |t| | ||
t.warning = true | ||
t.verbose = true | ||
t.test_files = FileList['test/test_zlib_deflate.rb'] | ||
end | ||
|
||
Rake::TestTask.new('test_inflate') do |t| | ||
t.warning = true | ||
t.verbose = true | ||
t.test_files = FileList['test/test_zlib_inflate.rb'] | ||
end | ||
|
||
Rake::TestTask.new('test_rbzlib') do |t| | ||
t.warning = true | ||
t.verbose = true | ||
t.test_files = FileList['test/test_rbzlib.rb'] | ||
end | ||
|
||
Rake::TestTask.new('test_rbzlib_bytef') do |t| | ||
t.warning = true | ||
t.verbose = true | ||
t.test_files = FileList['test/test_rbzlib_bytef.rb'] | ||
end | ||
|
||
Rake::TestTask.new('test_rbzlib_posf') do |t| | ||
t.warning = true | ||
t.verbose = true | ||
t.test_files = FileList['test/test_rbzlib_posf.rb'] | ||
end | ||
|
||
task :default => :test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
# minigzip.rb -- simulate gzip using the zlib compression library | ||
# Copyright (C) 1995-2005 Jean-loup Gailly. | ||
# For conditions of distribution and use, see copyright notice in rbzlib.rb | ||
# | ||
# | ||
# | ||
# minigzip is a minimal implementation of the gzip utility. This is | ||
# only an example of using zlib and isn't meant to replace the | ||
# full-featured gzip. No attempt is made to deal with file systems | ||
# limiting names to 14 or 8+3 characters, etc... Error checking is | ||
# very limited. So use minigzip only for testing; use gzip for the | ||
# real thing. On MSDOS, use only on file names without extension | ||
# or in pipe mode. | ||
# | ||
# Ruby tralnslation By Park Heesob. | ||
|
||
require 'rbzlib' | ||
include Rbzlib | ||
|
||
GZ_SUFFIX = ".gz" | ||
SUFFIX_LEN = GZ_SUFFIX.length | ||
|
||
BUFLEN = 16384 | ||
MAX_NAME_LEN = 1024 | ||
|
||
|
||
def error(msg) | ||
puts("#{__FILE__}: #{msg}") | ||
exit(1) | ||
end | ||
|
||
def gz_compress(_in, out) | ||
while(true) | ||
begin | ||
buf = _in.read(BUFLEN) | ||
rescue | ||
raise RuntimeError,"read" | ||
end | ||
break if buf.nil? | ||
err = 0 | ||
len = buf.length | ||
if (gzwrite(out, buf, len) != len) | ||
error(gzerror(out, err)) | ||
end | ||
end | ||
_in.close | ||
error("failed gzclose") if (gzclose(out) != Z_OK) | ||
end | ||
|
||
|
||
def gz_uncompress(_in, out) | ||
buf = 0.chr * BUFLEN | ||
while true | ||
len = gzread(_in, buf, buf.length) | ||
err = 0 | ||
error(gzerror(_in, err)) if (len < 0) | ||
break if len.zero? | ||
if(out.write(buf[0,len]) != len) | ||
error("failed write") | ||
end | ||
end | ||
begin | ||
out.close | ||
rescue | ||
error("failed fclose") | ||
end | ||
|
||
error("failed gzclose") if (gzclose(_in) != Z_OK) | ||
end | ||
|
||
|
||
def file_compress(file, mode) | ||
outfile = file + GZ_SUFFIX | ||
|
||
_in = File.open(file, "rb") | ||
if _in.nil? | ||
raise RuntimeError,file | ||
end | ||
out = gzopen(outfile, mode) | ||
if out.nil? | ||
puts("#{__FILE__}: can't gzopen #{outfile}") | ||
exit(1) | ||
end | ||
gz_compress(_in, out) | ||
|
||
File.unlink(file) | ||
end | ||
|
||
|
||
def file_uncompress(file) | ||
len = file.length | ||
buf = file.dup | ||
|
||
if (file[-SUFFIX_LEN..-1] == GZ_SUFFIX) | ||
infile = file.dup | ||
outfile = buf[0..(-SUFFIX_LEN-1)] | ||
else | ||
outfile = file.dup | ||
infile = buf + GZ_SUFFIX | ||
end | ||
_in = gzopen(infile, "rb") | ||
if _in.nil? | ||
puts("#{__FILE__}: can't gzopen #{infile}") | ||
exit(1) | ||
end | ||
out = File.open(outfile, "wb") | ||
if out.nil? | ||
raise RuntimeError,file | ||
exit(1) | ||
end | ||
|
||
gz_uncompress(_in, out) | ||
|
||
File.unlink(infile) | ||
end | ||
|
||
|
||
#=========================================================================== | ||
# Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...] | ||
# -d : decompress | ||
# -f : compress with Z_FILTERED | ||
# -h : compress with Z_HUFFMAN_ONLY | ||
# -r : compress with Z_RLE | ||
# -1 to -9 : compression level | ||
# | ||
|
||
uncompr = false | ||
|
||
outmode = "wb6 " | ||
|
||
while !ARGV.empty? | ||
argv = ARGV.shift | ||
case argv | ||
when "-d" | ||
uncompr = true | ||
when "-f" | ||
outmode[3] = 'f' | ||
when "-h" | ||
outmode[3] = 'h' | ||
when "-r" | ||
outmode[3] = 'R' | ||
when "-1".."-9" | ||
outmode[2] = argv[1] | ||
else | ||
ARGV.unshift(argv) | ||
break | ||
end | ||
end | ||
if (outmode[3].chr == ' ') | ||
outmode = outmode[0,3] | ||
end | ||
if (ARGV.empty?) | ||
$stdin.binmode | ||
$stdout.binmode | ||
if (uncompr) | ||
file = gzdopen($stdin.fileno, "rb") | ||
error("can't gzdopen stdin") if file.nil? | ||
gz_uncompress(file, $stdout) | ||
else | ||
file = gzdopen($stdout.fileno, outmode) | ||
error("can't gzdopen stdout") if file.nil? | ||
gz_compress($stdin, file) | ||
end | ||
else | ||
while !ARGV.empty? | ||
if (uncompr) | ||
file_uncompress(ARGV.shift) | ||
else | ||
file_compress(ARGV.shift, outmode) | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl | ||
cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t | ||
MB4XDTE1MDkwMjIwNDkxOFoXDTE2MDkwMTIwNDkxOFowPzERMA8GA1UEAwwIZGpi | ||
ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv | ||
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyTkvXqRp6hLs9eoJOS | ||
Hmi8kRYbq9Vkf15/hMxJpotYMgJVHHWrmDcC5Dye2PbnXjTkKf266Zw0PtT9h+lI | ||
S3ts9HO+vaCFSMwFFZmnWJSpQ3CNw2RcHxjWkk9yF7imEM8Kz9ojhiDXzBetdV6M | ||
gr0lV/alUr7TNVBDngbXEfTWscyXh1qd7xZ4EcOdsDktCe5G45N/o3662tPQvJsi | ||
FOF0CM/KuBsa/HL1/eoEmF4B3EKIRfTHrQ3hu20Kv3RJ88QM4ec2+0dd97uX693O | ||
zv6981fyEg+aXLkxrkViM/tz2qR2ZE0jPhHTREPYeMEgptRkTmWSKAuLVWrJEfgl | ||
DtkCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFEwe | ||
nn6bfJADmuIDiMSOzedOrL+xMB0GA1UdEQQWMBSBEmRqYmVyZzk2QGdtYWlsLmNv | ||
bTAdBgNVHRIEFjAUgRJkamJlcmc5NkBnbWFpbC5jb20wDQYJKoZIhvcNAQEFBQAD | ||
ggEBAHmNOCWoDVD75zHFueY0viwGDVP1BNGFC+yXcb7u2GlK+nEMCORqzURbYPf7 | ||
tL+/hzmePIRz7i30UM//64GI1NLv9jl7nIwjhPpXpf7/lu2I9hOTsvwSumb5UiKC | ||
/sqBxI3sfj9pr79Wpv4MuikX1XPik7Ncb7NPsJPw06Lvyc3Hkg5X2XpPtLtS+Gr2 | ||
wKJnmzb5rIPS1cmsqv0M9LPWflzfwoZ/SpnmhagP+g05p8bRNKjZSA2iImM/GyYZ | ||
EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V | ||
tGSHgAmcLlkdGgan182qsE/4kKM= | ||
-----END CERTIFICATE----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,385 @@ | ||
# example.rb -- usage example of the zlib compression library | ||
# Copyright (C) 1995-2004 Jean-loup Gailly. | ||
# For conditions of distribution and use, see copyright notice in rbzlib.rb | ||
# | ||
# Ruby translation by Park Heesob | ||
|
||
require 'rbzlib' | ||
include Rbzlib | ||
|
||
def CHECK_ERR(err,msg) | ||
if(err != Z_OK) | ||
raise RuntimeError,"#{msg} error: #{err}" | ||
end | ||
end | ||
|
||
TESTFILE = "foo.gz" | ||
@@hello = "hello, hello!\0" | ||
|
||
@@dictionary = "hello" | ||
|
||
def test_compress(compr, comprLen, uncompr, uncomprLen) | ||
len = @@hello.length | ||
|
||
err,comprLen = compress(compr, comprLen, @@hello, len) | ||
CHECK_ERR(err, "compress") | ||
compr = compr[0,comprLen] | ||
uncompr[0,7] = "garbage" | ||
err,uncomprLen = uncompress(uncompr, uncomprLen, compr, comprLen) | ||
CHECK_ERR(err, "uncompress") | ||
uncompr = uncompr[0,uncomprLen] | ||
if uncompr != @@hello | ||
puts("bad uncompress") | ||
exit(1) | ||
else | ||
puts("uncompress(): #{uncompr}") | ||
end | ||
end | ||
|
||
def test_gzio(fname, uncompr, uncomprLen) | ||
len = @@hello.length | ||
err = 0 | ||
file = gzopen(fname, "wb") | ||
if file.nil? | ||
puts("gzopen error") | ||
exit(1) | ||
end | ||
gzputc(file, 'h') | ||
if (gzputs(file, "ello") != 4) | ||
puts("gzputs err: #{gzerror(file, err)}") | ||
exit(1) | ||
end | ||
if (gzputs(file, ", hello!") != 8) | ||
puts("gzputs err: #{gzerror(file, err)}") | ||
exit(1) | ||
end | ||
gzseek(file, 1, SEEK_CUR) | ||
gzclose(file) | ||
|
||
file = gzopen(fname, "rb") | ||
if file.nil? | ||
puts("gzopen error") | ||
exit(1) | ||
end | ||
uncompr[0,7] = "garbage" | ||
if (gzread(file, uncompr, uncomprLen) != len) | ||
puts("gzread err: #{gzerror(file, err)}") | ||
exit(1) | ||
end | ||
uncompr = uncompr[0,len] | ||
if uncompr != @@hello | ||
puts("bad gzread: #{uncompr}") | ||
exit(1) | ||
else | ||
puts("gzread(): #{uncompr}") | ||
end | ||
pos = gzseek(file, -8, SEEK_CUR) | ||
if (pos != 6 || gztell(file) != pos) | ||
puts("gzseek error, pos=#{pos}, gztell=#{gztell(file)}") | ||
exit(1) | ||
end | ||
|
||
if (gzgetc(file) != ' ') | ||
puts("gzgetc error") | ||
exit(1) | ||
end | ||
|
||
if (gzungetc(' ', file) != ' ') | ||
puts("gzungetc error") | ||
exit(1) | ||
end | ||
|
||
gzgets(file, uncompr, uncomprLen) | ||
uncompr.chop! | ||
if uncompr.length != 7 | ||
puts("gzgets err after gzseek: #{gzerror(file, err)}") | ||
exit(1) | ||
end | ||
|
||
if uncompr != @@hello[6..-2] | ||
puts("bad gzgets after gzseek") | ||
exit(1) | ||
else | ||
puts("gzgets() after gzseek: #{uncompr}") | ||
end | ||
|
||
gzclose(file) | ||
end | ||
|
||
def test_deflate(compr, comprLen) | ||
c_stream = Z_stream.new | ||
len = @@hello.length | ||
|
||
err = deflateInit(c_stream, Z_DEFAULT_COMPRESSION) | ||
CHECK_ERR(err, "deflateInit") | ||
|
||
c_stream.next_in = Bytef.new(@@hello) | ||
c_stream.next_out = Bytef.new(compr) | ||
|
||
while (c_stream.total_in != len && c_stream.total_out < comprLen) | ||
c_stream.avail_in = c_stream.avail_out = 1 | ||
err = deflate(c_stream, Z_NO_FLUSH) | ||
CHECK_ERR(err, "deflate") | ||
end | ||
while true | ||
c_stream.avail_out = 1 | ||
err = deflate(c_stream, Z_FINISH) | ||
break if (err == Z_STREAM_END) | ||
CHECK_ERR(err, "deflate") | ||
end | ||
|
||
err = deflateEnd(c_stream) | ||
CHECK_ERR(err, "deflateEnd") | ||
end | ||
|
||
def test_inflate(compr, comprLen, uncompr, uncomprLen) | ||
uncompr[0,7] = "garbage" | ||
d_stream = Z_stream.new | ||
|
||
d_stream.next_in = Bytef.new(compr) | ||
d_stream.avail_in = 0 | ||
d_stream.next_out = Bytef.new(uncompr) | ||
|
||
err = inflateInit(d_stream) | ||
CHECK_ERR(err, "inflateInit") | ||
|
||
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) | ||
d_stream.avail_in = d_stream.avail_out = 1 | ||
err = inflate(d_stream, Z_NO_FLUSH) | ||
break if (err == Z_STREAM_END) | ||
CHECK_ERR(err, "inflate") | ||
end | ||
|
||
err = inflateEnd(d_stream) | ||
CHECK_ERR(err, "inflateEnd") | ||
uncompr = uncompr[0,d_stream.total_out] | ||
if uncompr != @@hello | ||
puts("bad inflate") | ||
exit(1) | ||
else | ||
puts("inflate(): #{uncompr}") | ||
end | ||
end | ||
|
||
def test_large_deflate(compr, comprLen, uncompr, uncomprLen) | ||
c_stream = Z_stream.new | ||
err = deflateInit(c_stream, Z_BEST_SPEED) | ||
CHECK_ERR(err, "deflateInit") | ||
|
||
c_stream.next_out = Bytef.new(compr) | ||
c_stream.avail_out = comprLen | ||
c_stream.next_in = Bytef.new(uncompr) | ||
c_stream.avail_in = uncomprLen | ||
err = deflate(c_stream, Z_NO_FLUSH) | ||
CHECK_ERR(err, "deflate") | ||
if c_stream.avail_in.nonzero? | ||
puts("deflate not greedy") | ||
exit(1) | ||
end | ||
|
||
deflateParams(c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY) | ||
c_stream.next_in = Bytef.new(compr) | ||
c_stream.avail_in = comprLen/2 | ||
err = deflate(c_stream, Z_NO_FLUSH) | ||
CHECK_ERR(err, "deflate") | ||
|
||
deflateParams(c_stream, Z_BEST_COMPRESSION, Z_FILTERED) | ||
c_stream.next_in = Bytef.new(uncompr) | ||
c_stream.avail_in = uncomprLen | ||
err = deflate(c_stream, Z_NO_FLUSH) | ||
CHECK_ERR(err, "deflate") | ||
|
||
err = deflate(c_stream, Z_FINISH) | ||
if (err != Z_STREAM_END) | ||
puts("deflate should report Z_STREAM_END") | ||
exit(1) | ||
end | ||
err = deflateEnd(c_stream) | ||
CHECK_ERR(err, "deflateEnd") | ||
end | ||
|
||
def test_large_inflate(compr, comprLen, uncompr, uncomprLen) | ||
d_stream = Z_stream.new | ||
uncompr[0,7] = "garbage" | ||
|
||
d_stream.next_in = Bytef.new(compr) | ||
d_stream.avail_in = comprLen | ||
|
||
err = inflateInit(d_stream) | ||
CHECK_ERR(err, "inflateInit") | ||
|
||
while true | ||
d_stream.next_out = Bytef.new(uncompr) | ||
d_stream.avail_out = uncomprLen | ||
err = inflate(d_stream, Z_NO_FLUSH) | ||
break if (err == Z_STREAM_END) | ||
CHECK_ERR(err, "large inflate") | ||
end | ||
|
||
err = inflateEnd(d_stream) | ||
CHECK_ERR(err, "inflateEnd") | ||
|
||
if (d_stream.total_out != 2*uncomprLen + comprLen/2) | ||
puts("bad large inflate: #{d_stream.total_out}") | ||
exit(1) | ||
else | ||
puts("large_inflate(): OK") | ||
end | ||
end | ||
|
||
def test_flush(compr, comprLen) | ||
c_stream = Z_stream.new | ||
len = @@hello.length | ||
|
||
err = deflateInit(c_stream, Z_DEFAULT_COMPRESSION) | ||
CHECK_ERR(err, "deflateInit") | ||
|
||
c_stream.next_in = Bytef.new(@@hello) | ||
c_stream.next_out = Bytef.new(compr) | ||
c_stream.avail_in = 3 | ||
c_stream.avail_out = comprLen | ||
err = deflate(c_stream, Z_FULL_FLUSH) | ||
CHECK_ERR(err, "deflate") | ||
|
||
compr[3]=(compr[3].ord+1).chr | ||
c_stream.avail_in = len - 3 | ||
|
||
err = deflate(c_stream, Z_FINISH) | ||
if (err != Z_STREAM_END) | ||
CHECK_ERR(err, "deflate") | ||
end | ||
err = deflateEnd(c_stream) | ||
CHECK_ERR(err, "deflateEnd") | ||
|
||
comprLen = c_stream.total_out | ||
end | ||
|
||
def test_sync(compr, comprLen, uncompr, uncomprLen) | ||
d_stream = Z_stream.new | ||
uncompr[0,7] = "garbage" | ||
|
||
d_stream.next_in = Bytef.new(compr) | ||
d_stream.avail_in = 2 | ||
|
||
err = inflateInit(d_stream) | ||
CHECK_ERR(err, "inflateInit") | ||
|
||
d_stream.next_out = Bytef.new(uncompr) | ||
d_stream.avail_out = uncomprLen | ||
|
||
inflate(d_stream, Z_NO_FLUSH) | ||
CHECK_ERR(err, "inflate") | ||
|
||
d_stream.avail_in = comprLen-2 | ||
err = inflateSync(d_stream) | ||
CHECK_ERR(err, "inflateSync") | ||
|
||
err = inflate(d_stream, Z_FINISH) | ||
if (err != Z_DATA_ERROR) | ||
puts("inflate should report DATA_ERROR") | ||
exit(1) | ||
end | ||
err = inflateEnd(d_stream) | ||
uncompr = uncompr[0,d_stream.total_out] | ||
CHECK_ERR(err, "inflateEnd") | ||
puts("after inflateSync(): hel#{uncompr}") | ||
end | ||
|
||
def test_dict_deflate(compr, comprLen) | ||
c_stream = Z_stream.new | ||
err = deflateInit(c_stream, Z_BEST_COMPRESSION) | ||
CHECK_ERR(err, "deflateInit") | ||
|
||
err = deflateSetDictionary(c_stream,@@dictionary, @@dictionary.length) | ||
CHECK_ERR(err, "deflateSetDictionary") | ||
|
||
@@dictId = c_stream.adler | ||
c_stream.next_out = Bytef.new(compr) | ||
c_stream.avail_out = comprLen | ||
|
||
c_stream.next_in = Bytef.new(@@hello) | ||
c_stream.avail_in = @@hello.length | ||
|
||
err = deflate(c_stream, Z_FINISH) | ||
if (err != Z_STREAM_END) | ||
puts("deflate should report Z_STREAM_END") | ||
exit(1) | ||
end | ||
err = deflateEnd(c_stream) | ||
CHECK_ERR(err, "deflateEnd") | ||
end | ||
|
||
def test_dict_inflate(compr, comprLen, uncompr, uncomprLen) | ||
d_stream = Z_stream.new | ||
uncompr[0,7] = "garbage" | ||
|
||
d_stream.next_in = Bytef.new(compr) | ||
d_stream.avail_in = comprLen | ||
|
||
err = inflateInit(d_stream) | ||
CHECK_ERR(err, "inflateInit") | ||
d_stream.next_out = Bytef.new(uncompr) | ||
d_stream.avail_out = uncomprLen | ||
|
||
while true | ||
err = inflate(d_stream, Z_NO_FLUSH) | ||
break if (err == Z_STREAM_END) | ||
if (err == Z_NEED_DICT) | ||
if (d_stream.adler != @@dictId) | ||
puts("unexpected dictionary") | ||
exit(1) | ||
end | ||
err = inflateSetDictionary(d_stream, @@dictionary,@@dictionary.length) | ||
|
||
end | ||
CHECK_ERR(err, "inflate with dict") | ||
end | ||
|
||
err = inflateEnd(d_stream) | ||
CHECK_ERR(err, "inflateEnd") | ||
uncompr = uncompr[0,d_stream.total_out] | ||
if uncompr != @@hello | ||
puts("bad inflate with dict") | ||
exit(1) | ||
else | ||
puts("inflate with dictionary: #{uncompr}") | ||
end | ||
end | ||
|
||
comprLen = 10000*4 | ||
uncomprLen = comprLen | ||
myVersion = ZLIB_VERSION | ||
|
||
if (zlibVersion[0] != myVersion[0]) | ||
puts("incompatible zlib version") | ||
exit(1) | ||
elsif (zlibVersion != ZLIB_VERSION) | ||
puts("warning: different zlib version") | ||
end | ||
|
||
compr = 0.chr * comprLen | ||
uncompr = 0.chr * uncomprLen | ||
if (compr.nil? || uncompr.nil?) | ||
puts("out of memory") | ||
exit(1) | ||
end | ||
test_compress(compr, comprLen, uncompr, uncomprLen) | ||
|
||
test_gzio((ARGV.length > 0 ? ARGV[0] : TESTFILE), | ||
uncompr, uncomprLen) | ||
|
||
test_deflate(compr, comprLen) | ||
test_inflate(compr, comprLen, uncompr, uncomprLen) | ||
test_large_deflate(compr, comprLen, uncompr, uncomprLen) | ||
test_large_inflate(compr, comprLen, uncompr, uncomprLen) | ||
|
||
test_flush(compr, comprLen) | ||
|
||
test_sync(compr, comprLen, uncompr, uncomprLen) | ||
comprLen = uncomprLen | ||
|
||
test_dict_deflate(compr, comprLen) | ||
test_dict_inflate(compr, comprLen, uncompr, uncomprLen) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require_relative 'pr/zlib' |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'rubygems' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'pr-zlib' | ||
spec.version = '1.0.3' | ||
spec.authors = ['Park Heesob', 'Daniel Berger'] | ||
spec.email = 'phasis@gmail.com' | ||
spec.homepage = 'https://github.com/djberg96/pr-zlib' | ||
spec.license = 'zlib' | ||
spec.summary = 'Pure Ruby version of the zlib library' | ||
spec.test_files = Dir['test/*.rb'] | ||
spec.files = Dir["**/*"].reject{ |f| f.include?('git') } | ||
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST'] | ||
spec.cert_chain = Dir['certs/*'] | ||
|
||
spec.add_development_dependency('test-unit', '>= 2.4.0') | ||
spec.add_development_dependency('ruby-prof') | ||
|
||
spec.description = <<-EOF | ||
The pr-zlib library is a pure Ruby implementation of both the zlib C | ||
library, and the Ruby zlib interface that ships as part of the standard | ||
library. | ||
EOF | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
######################################################################## | ||
# This benchmarks the zlib library that ships as part of the Ruby | ||
# standard library. | ||
# | ||
# You can run this benchmark via the bench:przlib Rake task. | ||
######################################################################## | ||
require 'pr/zlib' | ||
require 'benchmark' | ||
|
||
print "\n\n== Running the benchmarks for pr-zlib ==\n\n" | ||
|
||
# First, let's create a ~7 MB text file. | ||
|
||
FILE_NAME = "benchmark.txt" | ||
GZ_FILE_NAME = "benchmark.txt.gz" | ||
|
||
File.open(FILE_NAME, "w") do |fh| | ||
10000.times{ |x| | ||
s = "Now is the time for #{x} good men to come to the aid of their country." | ||
fh.puts s | ||
} | ||
end | ||
|
||
Benchmark.bm do |x| | ||
x.report("write") do | ||
5.times{ | ||
Zlib::GzipWriter.open(GZ_FILE_NAME) do |gz| | ||
gz.write(File.read(FILE_NAME)) | ||
end | ||
} | ||
end | ||
|
||
x.report("read") do | ||
5.times{ | ||
Zlib::GzipReader.open(GZ_FILE_NAME) do |gz| | ||
gz.read | ||
end | ||
} | ||
end | ||
end | ||
|
||
File.delete(FILE_NAME) if File.exists?(FILE_NAME) | ||
File.delete(GZ_FILE_NAME) if File.exists?(GZ_FILE_NAME) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
######################################################################## | ||
# This benchmarks the zlib library that ships as part of the Ruby | ||
# standard library. | ||
# | ||
# You can run this benchmark via the bench-zlib Rake task. | ||
######################################################################## | ||
require 'zlib' | ||
require 'benchmark' | ||
|
||
print "\n\n== Running the benchmarks for zlib (stdlib) ==\n\n" | ||
|
||
# First, let's create a ~7 MB text file. | ||
|
||
FILE_NAME = "benchmark.txt" | ||
GZ_FILE_NAME = "benchmark.txt.gz" | ||
|
||
File.open(FILE_NAME, "w") do |fh| | ||
10000.times{ |x| | ||
s = "Now is the time for #{x} good men to come to the aid of their country." | ||
fh.puts s | ||
} | ||
end | ||
|
||
Benchmark.bm do |x| | ||
x.report("write") do | ||
5.times{ | ||
Zlib::GzipWriter.open(GZ_FILE_NAME) do |gz| | ||
gz.write(File.read(FILE_NAME)) | ||
end | ||
} | ||
end | ||
|
||
x.report("read") do | ||
5.times{ | ||
Zlib::GzipReader.open(GZ_FILE_NAME) do |gz| | ||
gz.read | ||
end | ||
} | ||
end | ||
end | ||
|
||
File.delete(FILE_NAME) if File.exists?(FILE_NAME) | ||
File.delete(GZ_FILE_NAME) if File.exists?(GZ_FILE_NAME) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'pr/zlib' | ||
|
||
FILE_NAME = 'zlib_temp.txt' | ||
GZ_FILE_NAME = 'zlib_temp.txt.gz' | ||
|
||
# Create a text file to use first. | ||
File.open(FILE_NAME, "w") do |fh| | ||
1000.times{ |x| | ||
s = "Now is the time for #{x} good men to come to the aid of their country." | ||
fh.puts s | ||
} | ||
end | ||
|
||
Zlib::GzipWriter.open(GZ_FILE_NAME){ |gz| gz.write(IO.read(FILE_NAME)) } | ||
|
||
require 'ruby-prof' | ||
|
||
result = RubyProf.profile do | ||
Zlib::GzipReader.open(GZ_FILE_NAME) do |gz| | ||
gz.read | ||
end | ||
end | ||
|
||
File.delete(FILE_NAME) if File.exists?(FILE_NAME) | ||
File.delete(GZ_FILE_NAME) if File.exists?(GZ_FILE_NAME) | ||
|
||
printer = RubyProf::FlatPrinter.new(result) | ||
printer.print(STDOUT) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'pr/zlib' | ||
|
||
FILE_NAME = 'zlib_temp.txt' | ||
GZ_FILE_NAME = 'zlib_temp.txt.gz' | ||
|
||
# Create a text file to use first. | ||
File.open(FILE_NAME, "w") do |fh| | ||
1000.times{ |x| | ||
s = "Now is the time for #{x} good men to come to the aid of their country." | ||
fh.puts s | ||
} | ||
end | ||
|
||
require 'ruby-prof' | ||
|
||
result = RubyProf.profile do | ||
Zlib::GzipWriter.open(GZ_FILE_NAME) do |gz| | ||
gz.write(File.read(FILE_NAME)) | ||
end | ||
end | ||
|
||
File.delete(FILE_NAME) if File.exists?(FILE_NAME) | ||
File.delete(GZ_FILE_NAME) if File.exists?(GZ_FILE_NAME) | ||
|
||
printer = RubyProf::FlatPrinter.new(result) | ||
printer.print(STDOUT) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
######################################################################## | ||
# test_rbzlib.rb | ||
# | ||
# Test case for the Rbzlib module. | ||
######################################################################## | ||
require 'pr/rbzlib' | ||
require 'test-unit' | ||
|
||
class TC_Rbzlib < Test::Unit::TestCase | ||
include Rbzlib | ||
|
||
def setup | ||
@fixnum = 7 | ||
@buffer = 0.chr * 16 | ||
end | ||
|
||
def test_version | ||
assert_equal('1.2.3', ZLIB_VERSION) | ||
end | ||
|
||
def test_fixnum_ord | ||
assert_respond_to(7, :ord) | ||
assert_equal(7, 7.ord) | ||
end | ||
|
||
def test_misc_constants | ||
assert_equal(9, MAX_MEM_LEVEL) | ||
assert_equal(8, DEF_MEM_LEVEL) | ||
assert_equal(15, MAX_WBITS) | ||
assert_equal(MAX_WBITS, DEF_WBITS) | ||
assert_equal(0, STORED_BLOCK) | ||
assert_equal(1, STATIC_TREES) | ||
assert_equal(2, DYN_TREES) | ||
assert_equal(3, MIN_MATCH) | ||
assert_equal(258, MAX_MATCH) | ||
assert_equal(0x20, PRESET_DICT) | ||
assert_equal(65521, BASE) | ||
assert_equal(5552, NMAX) | ||
assert_equal(0, OS_CODE) | ||
assert_equal(1, SEEK_CUR) | ||
assert_equal(2, SEEK_END) | ||
end | ||
|
||
def test_sync_contants | ||
assert_equal(0, Z_NO_FLUSH) | ||
assert_equal(1, Z_PARTIAL_FLUSH) | ||
assert_equal(2, Z_SYNC_FLUSH) | ||
assert_equal(3, Z_FULL_FLUSH) | ||
assert_equal(4, Z_FINISH) | ||
assert_equal(5, Z_BLOCK) | ||
end | ||
|
||
def test_stream_constants | ||
assert_equal(0, Z_OK) | ||
assert_equal(1, Z_STREAM_END) | ||
assert_equal(2, Z_NEED_DICT) | ||
assert_equal(-1, Z_ERRNO) | ||
assert_equal(-1, Z_EOF) | ||
assert_equal(-2, Z_STREAM_ERROR) | ||
assert_equal(-3, Z_DATA_ERROR) | ||
assert_equal(-4, Z_MEM_ERROR) | ||
assert_equal(-5, Z_BUF_ERROR) | ||
assert_equal(-6, Z_VERSION_ERROR) | ||
assert_equal(16384, Z_BUFSIZE) | ||
end | ||
|
||
def test_compression_constants | ||
assert_equal(0, Z_NO_COMPRESSION) | ||
assert_equal(1, Z_BEST_SPEED) | ||
assert_equal(9, Z_BEST_COMPRESSION) | ||
assert_equal(-1, Z_DEFAULT_COMPRESSION) | ||
assert_equal(8, Z_DEFLATED) | ||
end | ||
|
||
def test_encoding_constants | ||
assert_equal(1, Z_FILTERED) | ||
assert_equal(2, Z_HUFFMAN_ONLY) | ||
assert_equal(3, Z_RLE) | ||
assert_equal(4, Z_FIXED) | ||
assert_equal(0, Z_DEFAULT_STRATEGY) | ||
end | ||
|
||
def test_crc_constants | ||
assert_equal(0x01, ASCII_FLAG) | ||
assert_equal(0x02, HEAD_CRC) | ||
assert_equal(0x04, EXTRA_FIELD) | ||
assert_equal(0x08, ORIG_NAME) | ||
assert_equal(0x10, COMMENT_) | ||
assert_equal(0xE0, RESERVED) | ||
end | ||
|
||
def test_zError | ||
assert_respond_to(self, :zError) | ||
assert_equal('stream end', self.zError(Z_STREAM_END)) | ||
end | ||
|
||
def test_zlibVersion | ||
assert_respond_to(self, :zlibVersion) | ||
assert_equal(ZLIB_VERSION, self.zlibVersion) | ||
end | ||
|
||
def test_z_error | ||
assert_respond_to(self, :z_error) | ||
assert_raise(RuntimeError){ self.z_error('hello') } | ||
end | ||
|
||
def test_adler32 | ||
assert_respond_to(Rbzlib, :adler32) | ||
assert_equal(1, Rbzlib.adler32(32, nil)) | ||
assert_equal(0, Rbzlib.adler32(0, @buffer)) | ||
assert_equal(1048577, Rbzlib.adler32(1, @buffer)) | ||
assert_equal(10485770, Rbzlib.adler32(10, @buffer)) | ||
assert_equal(33554464, Rbzlib.adler32(32, @buffer)) | ||
end | ||
|
||
def test_adler32_expected_errors | ||
assert_raise(ArgumentError){ Rbzlib.adler32 } | ||
assert_raise(ArgumentError){ Rbzlib.adler32('test') } | ||
end | ||
|
||
def test_get_crc_table | ||
assert_respond_to(Rbzlib, :get_crc_table) | ||
end | ||
|
||
def test_gz_open | ||
assert_respond_to(Rbzlib, :gz_open) | ||
end | ||
|
||
def teardown | ||
@fixnum = 0 | ||
@buffer = nil | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
######################################################################## | ||
# test_rbzlib_bytef.rb | ||
# | ||
# Test case for the Zlib::Bytef class. | ||
######################################################################## | ||
require 'pr/rbzlib' | ||
require 'test-unit' | ||
|
||
class TC_Rbzlib_Bytef < Test::Unit::TestCase | ||
def setup | ||
@buffer = 0.chr * 32 | ||
@bytef = Rbzlib::Bytef.new(@buffer) | ||
end | ||
|
||
def test_buffer_get | ||
assert_respond_to(@bytef, :buffer) | ||
assert_equal(@buffer, @bytef.buffer) | ||
end | ||
|
||
def test_buffer_set | ||
assert_respond_to(@bytef, :buffer=) | ||
assert_nothing_raised{ @bytef.buffer = 0.chr * 8 } | ||
assert_equal(0.chr * 8, @bytef.buffer) | ||
end | ||
|
||
def test_length | ||
assert_respond_to(@bytef, :length) | ||
assert_equal(32, @bytef.length) | ||
end | ||
|
||
def test_increment | ||
assert_respond_to(@bytef, :+) | ||
assert_nothing_raised{ @bytef + 1 } | ||
assert_equal(1, @bytef.offset) | ||
end | ||
|
||
def test_decrement | ||
assert_respond_to(@bytef, :-) | ||
assert_nothing_raised{ @bytef - 1 } | ||
assert_equal(-1, @bytef.offset) | ||
end | ||
|
||
def test_aref | ||
assert_respond_to(@bytef, :[]) | ||
assert_nothing_raised{ @bytef[1] } | ||
assert_equal(0, @bytef[1]) | ||
end | ||
|
||
def test_aset | ||
assert_respond_to(@bytef, :[]=) | ||
assert_nothing_raised{ @bytef[1] = 1.chr } | ||
assert_equal(1, @bytef[1]) | ||
end | ||
|
||
def test_get | ||
assert_respond_to(@bytef, :get) | ||
assert_nothing_raised{ @bytef.get } | ||
assert_equal(0, @bytef.get) | ||
end | ||
|
||
def test_set | ||
assert_respond_to(@bytef, :set) | ||
assert_nothing_raised{ @bytef.set('a') } | ||
assert_equal(97, @bytef.get) | ||
end | ||
|
||
def test_current | ||
assert_respond_to(@bytef, :current) | ||
assert_equal(@buffer, @bytef.current) | ||
end | ||
|
||
def teardown | ||
@bytef = nil | ||
@buffer = nil | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
######################################################################## | ||
# test_rbzlib_posf.rb | ||
# | ||
# Test case for the Zlib::Posf class. | ||
######################################################################## | ||
require 'pr/rbzlib' | ||
require 'test-unit' | ||
|
||
class TC_Rbzlib_Posf < Test::Unit::TestCase | ||
def setup | ||
@buffer = 0.chr * 32 | ||
@posf = Rbzlib::Posf.new(@buffer) | ||
end | ||
|
||
def test_increment | ||
assert_respond_to(@posf, :+) | ||
assert_nothing_raised{ @posf + 4 } | ||
assert_equal(8, @posf.offset) | ||
end | ||
|
||
def test_decrement | ||
assert_respond_to(@posf, :-) | ||
assert_nothing_raised{ @posf - 4 } | ||
assert_equal(-8, @posf.offset) | ||
end | ||
|
||
def test_aref | ||
assert_respond_to(@posf, :[]) | ||
assert_nothing_raised{ @posf[2] } | ||
assert_equal(0, @posf[2]) | ||
end | ||
|
||
def test_aset | ||
assert_respond_to(@posf, :[]=) | ||
assert_nothing_raised{ @posf[2] = 7 } | ||
assert_equal(7, @posf[2]) | ||
assert_equal("\a\000", @posf.buffer[4,2]) | ||
end | ||
|
||
def test_get | ||
assert_respond_to(@posf, :get) | ||
assert_nothing_raised{ @posf.get } | ||
assert_equal(0, @posf.get) | ||
end | ||
|
||
def test_set | ||
assert_respond_to(@posf, :set) | ||
assert_nothing_raised{ @posf.set(4) } | ||
assert_equal("\004\000", @posf.buffer[0,2]) | ||
end | ||
|
||
def teardown | ||
@posf = nil | ||
@buffer = nil | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
######################################################################## | ||
# test_zlib.rb | ||
# | ||
# Test case for the Zlib module. | ||
######################################################################## | ||
require 'test-unit' | ||
require 'pr/zlib' | ||
|
||
class TC_Zlib < Test::Unit::TestCase | ||
def self.startup | ||
end | ||
|
||
def setup | ||
@zstream_funcs = Zlib::ZStreamFuncs.new | ||
end | ||
|
||
def test_ruby_zlib_version | ||
assert_equal('0.6.0', Zlib::VERSION) | ||
assert_equal('0.6.0', Zlib::RUBY_ZLIB_VERSION) | ||
end | ||
|
||
def test_zlib_version | ||
assert_equal('1.2.3', Zlib::ZLIB_VERSION) | ||
assert_equal('1.0.2', Zlib::PR_ZLIB_VERSION) | ||
end | ||
|
||
def test_zlib_included_constants | ||
assert_not_nil(Zlib::BINARY) | ||
assert_not_nil(Zlib::ASCII) | ||
assert_not_nil(Zlib::UNKNOWN) | ||
end | ||
|
||
def test_zlib_included_compression_constants | ||
assert_not_nil(Zlib::NO_COMPRESSION) | ||
assert_not_nil(Zlib::BEST_SPEED) | ||
assert_not_nil(Zlib::BEST_COMPRESSION) | ||
assert_not_nil(Zlib::DEFAULT_COMPRESSION) | ||
end | ||
|
||
def test_zlib_included_encoding_constants | ||
assert_not_nil(Zlib::FILTERED) | ||
assert_not_nil(Zlib::HUFFMAN_ONLY) | ||
assert_not_nil(Zlib::DEFAULT_STRATEGY) | ||
assert_not_nil(Zlib::MAX_WBITS) | ||
assert_not_nil(Zlib::DEF_MEM_LEVEL) | ||
assert_not_nil(Zlib::MAX_MEM_LEVEL) | ||
assert_not_nil(Zlib::NO_FLUSH) | ||
assert_not_nil(Zlib::SYNC_FLUSH) | ||
assert_not_nil(Zlib::FULL_FLUSH) | ||
assert_not_nil(Zlib::FINISH) | ||
end | ||
|
||
def test_zlib_os_constants | ||
assert_equal(0x00, Zlib::OS_MSDOS) | ||
assert_equal(0x01, Zlib::OS_AMIGA) | ||
assert_equal(0x02, Zlib::OS_VMS) | ||
assert_equal(0x03, Zlib::OS_UNIX) | ||
assert_equal(0x05, Zlib::OS_ATARI) | ||
assert_equal(0x06, Zlib::OS_OS2) | ||
assert_equal(0x07, Zlib::OS_MACOS) | ||
assert_equal(0x0a, Zlib::OS_TOPS20) | ||
assert_equal(0x0b, Zlib::OS_WIN32) | ||
end | ||
|
||
def test_zlib_zstream_flag_constants | ||
assert_equal(0x1, Zlib::ZSTREAM_FLAG_READY) | ||
assert_equal(0x2, Zlib::ZSTREAM_FLAG_IN_STREAM) | ||
assert_equal(0x4, Zlib::ZSTREAM_FLAG_FINISHED) | ||
assert_equal(0x8, Zlib::ZSTREAM_FLAG_CLOSING) | ||
assert_equal(0x10, Zlib::ZSTREAM_FLAG_UNUSED) | ||
end | ||
|
||
def test_zlib_zstream_buffer_constants | ||
assert_equal(1024, Zlib::ZSTREAM_INITIAL_BUFSIZE) | ||
assert_equal(16384, Zlib::ZSTREAM_AVAIL_OUT_STEP_MAX) | ||
assert_equal(2048, Zlib::ZSTREAM_AVAIL_OUT_STEP_MIN) | ||
end | ||
|
||
def test_zlib_version_module_function | ||
assert_respond_to(Zlib, :zlib_version) | ||
end | ||
|
||
def test_adler32_module_function_basic | ||
assert_respond_to(Zlib, :adler32) | ||
assert_nothing_raised{ Zlib.adler32 } | ||
end | ||
|
||
def test_adler32_module_function | ||
assert_equal(1, Zlib.adler32) | ||
assert_equal(73204161, Zlib.adler32('test')) | ||
assert_equal(1, Zlib.adler32(nil, 3)) | ||
assert_equal(73728451, Zlib.adler32('test', 3)) | ||
end | ||
|
||
def test_adler32_module_function_expected_errors | ||
assert_raise(RangeError){ Zlib.adler32('test', 2**128) } | ||
end | ||
|
||
def test_crc32_module_function_basic | ||
assert_respond_to(Zlib, :crc32) | ||
assert_nothing_raised{ Zlib.crc32 } | ||
end | ||
|
||
def test_crc32_module_function | ||
assert_equal(0, Zlib.crc32) | ||
assert_equal(3632233996, Zlib.crc32('test')) | ||
assert_equal(0, Zlib.crc32(nil, 3)) | ||
assert_equal(3402289634, Zlib.crc32('test', 3)) | ||
end | ||
|
||
def test_crc32_module_function_expected_errors | ||
assert_raise(RangeError){ Zlib.crc32('test', 2**128) } | ||
end | ||
|
||
def test_crc_table_module_function_basic | ||
assert_respond_to(Zlib, :crc_table) | ||
assert_nothing_raised{ Zlib.crc_table } | ||
assert_kind_of(Array, Zlib.crc_table) | ||
end | ||
|
||
def test_zstream_funcs_struct | ||
assert_kind_of(Zlib::ZStreamFuncs, @zstream_funcs) | ||
assert_respond_to(@zstream_funcs, :reset) | ||
assert_respond_to(@zstream_funcs, :end) | ||
assert_respond_to(@zstream_funcs, :run) | ||
end | ||
|
||
def test_error_class | ||
assert_not_nil(Zlib::Error) | ||
assert_kind_of(StandardError, Zlib::Error.new) | ||
end | ||
|
||
def test_stream_end_class | ||
assert_not_nil(Zlib::StreamEnd) | ||
assert_kind_of(Zlib::Error, Zlib::StreamEnd.new) | ||
end | ||
|
||
def test_need_dict_class | ||
assert_kind_of(Zlib::Error, Zlib::NeedDict.new) | ||
end | ||
|
||
def test_data_error_class | ||
assert_kind_of(Zlib::Error, Zlib::DataError.new) | ||
end | ||
|
||
def test_stream_error_class | ||
assert_kind_of(Zlib::Error, Zlib::StreamError.new) | ||
end | ||
|
||
def test_mem_error_class | ||
assert_kind_of(Zlib::Error, Zlib::MemError.new) | ||
end | ||
|
||
def test_buf_error_class | ||
assert_kind_of(Zlib::Error, Zlib::BufError.new) | ||
end | ||
|
||
def test_version_error_class | ||
assert_kind_of(Zlib::Error, Zlib::VersionError.new) | ||
end | ||
|
||
def teardown | ||
@zstream_funcs = nil | ||
end | ||
|
||
def self.shutdown | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
######################################################################## | ||
# test_zlib_deflate.rb | ||
# | ||
# Test case for the Zlib::Deflate class. | ||
######################################################################## | ||
require 'pr/zlib' | ||
require 'test-unit' | ||
|
||
class TC_Zlib_Deflate < Test::Unit::TestCase | ||
def self.startup | ||
end | ||
|
||
def setup | ||
@deflate = Zlib::Deflate.new | ||
end | ||
|
||
def test_deflate_run_singleton_basic | ||
assert_respond_to(Zlib::Deflate, :deflate_run) | ||
end | ||
|
||
def test_deflate_singleton_basic | ||
assert_respond_to(Zlib::Deflate, :deflate) | ||
end | ||
|
||
#def test_initialize_copy_basic | ||
#assert_respond_to(@deflate, :initialize_copy) | ||
#end | ||
|
||
def test_deflate_basic | ||
assert_respond_to(@deflate, :deflate) | ||
end | ||
|
||
def test_append_basic | ||
assert_respond_to(@deflate, :<<) | ||
end | ||
|
||
def test_flush_basic | ||
assert_respond_to(@deflate, :flush) | ||
end | ||
|
||
def test_params_basic | ||
assert_respond_to(@deflate, :params) | ||
end | ||
|
||
def test_set_dictionary_basic | ||
assert_respond_to(@deflate, :set_dictionary) | ||
end | ||
|
||
def teardown | ||
@deflate = nil | ||
end | ||
|
||
def self.shutdown | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
######################################################################## | ||
# test_zlib_gzip_file.rb | ||
# | ||
# Test case for the Zlib::GzipFile base class. | ||
######################################################################## | ||
require 'pr/zlib' | ||
require 'test-unit' | ||
|
||
class TC_Zlib_GzipFile < Test::Unit::TestCase | ||
def self.startup | ||
end | ||
|
||
def setup | ||
@gz_file = Zlib::GzipFile.new | ||
end | ||
|
||
def test_gzip_file_constants | ||
assert_equal(Zlib::GzipFile::GZ_MAGIC1, 0x1f) | ||
assert_equal(Zlib::GzipFile::GZ_MAGIC2, 0x8b) | ||
assert_equal(Zlib::GzipFile::GZ_METHOD_DEFLATE, 8) | ||
assert_equal(Zlib::GzipFile::GZ_FLAG_MULTIPART, 0x2) | ||
assert_equal(Zlib::GzipFile::GZ_FLAG_EXTRA, 0x4) | ||
assert_equal(Zlib::GzipFile::GZ_FLAG_ORIG_NAME, 0x8) | ||
assert_equal(Zlib::GzipFile::GZ_FLAG_COMMENT, 0x10) | ||
assert_equal(Zlib::GzipFile::GZ_FLAG_ENCRYPT, 0x20) | ||
assert_equal(Zlib::GzipFile::GZ_FLAG_UNKNOWN_MASK, 0xc0) | ||
assert_equal(Zlib::GzipFile::GZ_EXTRAFLAG_FAST, 0x4) | ||
assert_equal(Zlib::GzipFile::GZ_EXTRAFLAG_SLOW, 0x2) | ||
end | ||
|
||
def test_gzfile_is_finished | ||
assert_respond_to(@gz_file, :GZFILE_IS_FINISHED) | ||
end | ||
|
||
def test_gzfile_close_basic | ||
assert_respond_to(@gz_file, :gzfile_close) | ||
end | ||
|
||
def test_to_io_basic | ||
assert_respond_to(@gz_file, :to_io) | ||
end | ||
|
||
def test_crc_basic | ||
assert_respond_to(@gz_file, :crc) | ||
end | ||
|
||
def test_mtime_basic | ||
assert_respond_to(@gz_file, :mtime) | ||
end | ||
|
||
def test_level_basic | ||
assert_respond_to(@gz_file, :level) | ||
end | ||
|
||
def test_os_code_basic | ||
assert_respond_to(@gz_file, :os_code) | ||
end | ||
|
||
def test_orig_name_basic | ||
assert_respond_to(@gz_file, :orig_name) | ||
end | ||
|
||
def test_comment_basic | ||
assert_respond_to(@gz_file, :comment) | ||
end | ||
|
||
def test_close_basic | ||
assert_respond_to(@gz_file, :close) | ||
end | ||
|
||
def test_finish_basic | ||
assert_respond_to(@gz_file, :finish) | ||
end | ||
|
||
def test_is_closed_basic | ||
assert_respond_to(@gz_file, :closed?) | ||
end | ||
|
||
def test_sync_get_basic | ||
assert_respond_to(@gz_file, :sync) | ||
end | ||
|
||
def test_sync_set_basic | ||
assert_respond_to(@gz_file, :sync=) | ||
end | ||
|
||
def teardown | ||
@gz_file = nil | ||
end | ||
|
||
def self.shutdown | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
######################################################################## | ||
# test_zlib_gzip_reader.rb | ||
# | ||
# Tests for the GzipReader class. | ||
######################################################################## | ||
require 'test-unit' | ||
require 'fileutils' | ||
require 'pr/zlib' | ||
|
||
class TC_GzipReader < Test::Unit::TestCase | ||
def self.startup | ||
Dir.chdir('test') if File.basename(Dir.pwd) != 'test' | ||
File.open('test.txt', 'wb'){ |fh| fh.puts 'Test file' } | ||
system('gzip *.txt') | ||
@@gz_file = 'test.txt.gz' | ||
end | ||
|
||
def setup | ||
@handle = File.open(@@gz_file) | ||
@gz_reader = Zlib::GzipReader.new(@handle) | ||
end | ||
|
||
def test_constructor_expected_errors | ||
assert_raise(ArgumentError){ Zlib::GzipReader.new } | ||
assert_raise(NoMethodError){ Zlib::GzipReader.new(1) } | ||
end | ||
|
||
def test_lineno_get_basic | ||
assert_respond_to(@gz_reader, :lineno) | ||
assert_nothing_raised{ @gz_reader.lineno } | ||
end | ||
|
||
def test_lineno_get | ||
assert_kind_of(Fixnum, @gz_reader.lineno) | ||
assert_equal(0, @gz_reader.lineno) | ||
end | ||
|
||
def test_lineno_set_basic | ||
assert_respond_to(@gz_reader, :lineno=) | ||
assert_nothing_raised{ @gz_reader.lineno = 0 } | ||
end | ||
|
||
def test_lineno_set | ||
assert_kind_of(Fixnum, @gz_reader.lineno = 0) | ||
assert_equal(0, @gz_reader.lineno = 0) | ||
end | ||
|
||
def test_eof_basic | ||
assert_respond_to(@gz_reader, :eof) | ||
assert_nothing_raised{ @gz_reader.eof } | ||
end | ||
|
||
def test_pos_basic | ||
assert_respond_to(@gz_reader, :pos) | ||
assert_nothing_raised{ @gz_reader.pos } | ||
end | ||
|
||
def test_pos | ||
assert_kind_of(Fixnum, @gz_reader.pos) | ||
end | ||
|
||
def test_rewind_basic | ||
assert_respond_to(@gz_reader, :rewind) | ||
assert_nothing_raised{ @gz_reader.rewind } | ||
end | ||
|
||
def test_rewind | ||
assert_equal(0, @gz_reader.rewind) | ||
end | ||
|
||
def test_unused_basic | ||
assert_respond_to(@gz_reader, :unused) | ||
assert_nothing_raised{ @gz_reader.unused } | ||
end | ||
|
||
def test_unused | ||
assert_nil(@gz_reader.unused) | ||
end | ||
|
||
def test_read_basic | ||
assert_respond_to(@gz_reader, :read) | ||
assert_nothing_raised{ @gz_reader.read } | ||
end | ||
|
||
def test_read | ||
assert_equal("Test file\n", @gz_reader.read) | ||
end | ||
|
||
def test_read_with_length | ||
assert_equal("Test", @gz_reader.read(4)) | ||
end | ||
|
||
def test_read_expected_errors | ||
assert_raise(ArgumentError){ @gz_reader.read(-1) } | ||
end | ||
|
||
def test_getc_basic | ||
assert_respond_to(@gz_reader, :getc) | ||
assert_nothing_raised{ @gz_reader.getc } | ||
end | ||
|
||
def test_getc | ||
expected = RUBY_VERSION.to_f >= 1.9 ? 'T' : 84 | ||
assert_equal(expected, @gz_reader.getc) | ||
end | ||
|
||
def test_readchar_basic | ||
assert_respond_to(@gz_reader, :readchar) | ||
assert_nothing_raised{ @gz_reader.readchar } | ||
end | ||
|
||
def test_readchar | ||
expected = RUBY_VERSION.to_f >= 1.9 ? 'T' : 84 | ||
assert_equal(expected, @gz_reader.readchar) | ||
end | ||
|
||
def test_each_byte_basic | ||
assert_respond_to(@gz_reader, :each_byte) | ||
assert_nothing_raised{ @gz_reader.each_byte{} } | ||
end | ||
|
||
def test_each_byte | ||
assert_nil(@gz_reader.each_byte{}) | ||
end | ||
|
||
def test_ungetc_basic | ||
assert_respond_to(@gz_reader, :ungetc) | ||
assert_nothing_raised{ @gz_reader.ungetc(99) } | ||
end | ||
|
||
def test_ungetc | ||
assert_nil(@gz_reader.ungetc(99)) | ||
end | ||
|
||
def test_gets_basic | ||
assert_respond_to(@gz_reader, :gets) | ||
assert_nothing_raised{ @gz_reader.gets } | ||
end | ||
|
||
def test_gets | ||
assert_equal("Test file\n", @gz_reader.gets) | ||
omit('Skipping $_ test') | ||
assert_equal("Test file\n", $_) | ||
end | ||
|
||
def test_readline_basic | ||
assert_respond_to(@gz_reader, :readline) | ||
assert_nothing_raised{ @gz_reader.readline } | ||
end | ||
|
||
def test_readline | ||
assert_equal("Test file\n", @gz_reader.readline) | ||
end | ||
|
||
def test_each_basic | ||
assert_respond_to(@gz_reader, :each) | ||
assert_nothing_raised{ @gz_reader.each{} } | ||
end | ||
|
||
def test_each | ||
assert_not_nil(@gz_reader.each{}) | ||
end | ||
|
||
def test_readlines_basic | ||
assert_respond_to(@gz_reader, :readlines) | ||
assert_nothing_raised{ @gz_reader.readlines } | ||
end | ||
|
||
def test_readlines | ||
assert_equal(["Test file\n"], @gz_reader.readlines) | ||
end | ||
|
||
def teardown | ||
@handle.close if @handle && !@handle.closed? | ||
@handle = nil | ||
@gz_reader = nil | ||
end | ||
|
||
def self.shutdown | ||
File.delete(@@gz_file) if File.exist?(@@gz_file) | ||
@@gz_file = nil | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
######################################################################## | ||
# test_zlib_gzip_writer.rb | ||
# | ||
# Test case for the Zlib::GzipWriter class. | ||
######################################################################## | ||
require 'pr/zlib' | ||
require 'test-unit' | ||
|
||
class TC_Zlib_GzipWriter < Test::Unit::TestCase | ||
def self.startup | ||
@@file = 'gzip_writer_test.gz' | ||
end | ||
|
||
def setup | ||
@handle = File.new(@@file, 'w') | ||
@writer = Zlib::GzipWriter.new(@handle) | ||
@time = Time.now | ||
end | ||
|
||
def test_constructor | ||
assert_nothing_raised{ @writer = Zlib::GzipWriter.new(@handle) } | ||
assert_nothing_raised{ @writer = Zlib::GzipWriter.new(@handle, nil) } | ||
assert_nothing_raised{ @writer = Zlib::GzipWriter.new(@handle, nil, nil) } | ||
end | ||
|
||
def test_constructor_expected_errors | ||
assert_raise(ArgumentError){ Zlib::GzipWriter.new } | ||
end | ||
|
||
def test_level | ||
assert_respond_to(@writer, :level) | ||
assert_equal(Z_DEFAULT_COMPRESSION, @writer.level) | ||
end | ||
|
||
def test_mtime_get_basic | ||
assert_respond_to(@writer, :mtime) | ||
assert_nothing_raised{ @writer.mtime } | ||
end | ||
|
||
def test_mtime_get | ||
assert_kind_of(Time, @writer.mtime) | ||
assert_equal(Time.at(0), @writer.mtime) | ||
end | ||
|
||
def test_mtime_set_basic | ||
assert_respond_to(@writer, :mtime=) | ||
assert_nothing_raised{ @writer.mtime = @time } | ||
end | ||
|
||
def test_mtime_set | ||
assert_equal(@time, @writer.mtime = @time) | ||
end | ||
|
||
def test_orig_name_get_basic | ||
assert_respond_to(@writer, :orig_name) | ||
assert_nothing_raised{ @writer.orig_name } | ||
end | ||
|
||
def test_orig_name_get | ||
assert_nil(@writer.orig_name) | ||
end | ||
|
||
def test_orig_name_set_basic | ||
assert_respond_to(@writer, :orig_name=) | ||
assert_nothing_raised{ @writer.orig_name = 'test' } | ||
end | ||
|
||
def test_orig_name_set | ||
assert_equal('test', @writer.orig_name = 'test') | ||
assert_equal('test', @writer.orig_name) | ||
end | ||
|
||
def test_comment_get_basic | ||
assert_respond_to(@writer, :comment) | ||
assert_nothing_raised{ @writer.comment } | ||
end | ||
|
||
def test_comment_get | ||
assert_nil(@writer.comment) | ||
end | ||
|
||
def test_comment_set_basic | ||
assert_respond_to(@writer, :comment=) | ||
assert_nothing_raised{ @writer.comment = 'test' } | ||
end | ||
|
||
def test_comment_set | ||
assert_equal('test', @writer.comment = 'test') | ||
assert_equal('test', @writer.comment) | ||
end | ||
|
||
def test_pos_basic | ||
assert_respond_to(@writer, :pos) | ||
assert_nothing_raised{ @writer.pos } | ||
assert_kind_of(Fixnum, @writer.pos) | ||
end | ||
|
||
def test_pos | ||
assert_equal(0, @writer.pos) | ||
assert_nothing_raised{ @writer.write('test') } | ||
assert_equal(4, @writer.pos) | ||
end | ||
|
||
def test_tell_alias | ||
assert_alias_method(@writer, :pos, :tell) | ||
end | ||
|
||
def test_open_basic | ||
assert_respond_to(Zlib::GzipWriter, :open) | ||
assert_nothing_raised{ Zlib::GzipWriter.open(@@file){} } | ||
end | ||
|
||
def test_flush_basic | ||
assert_respond_to(@writer, :flush) | ||
assert_nothing_raised{ @writer.flush } | ||
end | ||
|
||
def test_flush | ||
assert_equal(@writer, @writer.flush) | ||
end | ||
|
||
def test_write_basic | ||
assert_respond_to(@writer, :write) | ||
assert_nothing_raised{ @writer.write('test') } | ||
end | ||
|
||
def test_write | ||
assert_equal(4, @writer.write('test')) | ||
assert_equal(3, @writer.write(999)) | ||
end | ||
|
||
def test_write_expected_errors | ||
assert_raise(ArgumentError){ @writer.write } | ||
end | ||
|
||
def test_putc_basic | ||
assert_respond_to(@writer, :putc) | ||
assert_nothing_raised{ @writer.putc(97) } | ||
end | ||
|
||
def test_putc | ||
assert_equal(97, @writer.putc(97)) | ||
end | ||
|
||
def test_putc_expected_errors | ||
assert_raise(ArgumentError){ @writer.putc } | ||
end | ||
|
||
def test_append_basic | ||
assert_respond_to(@writer, :<<) | ||
assert_nothing_raised{ @writer << 'test' } | ||
end | ||
|
||
def test_append_expected_errors | ||
assert_raise(ArgumentError){ @writer.send(:<<) } | ||
end | ||
|
||
def test_printf_basic | ||
assert_respond_to(@writer, :printf) | ||
assert_nothing_raised{ @writer.printf('%s', 'test') } | ||
end | ||
|
||
def test_printf_expected_errors | ||
assert_raise(ArgumentError){ @writer.printf } | ||
end | ||
|
||
def test_puts_basic | ||
assert_respond_to(@writer, :puts) | ||
assert_nothing_raised{ @writer.puts('test') } | ||
end | ||
|
||
def test_puts_expected_errors | ||
assert_raise(ArgumentError){ @writer.puts } | ||
assert_raise(ArgumentError){ @writer.puts('test1', 'test2') } | ||
end | ||
|
||
def teardown | ||
@handle.close if @handle && !@handle.closed? | ||
@handle = nil | ||
@time = nil | ||
end | ||
|
||
def self.shutdown | ||
File.delete(@@file) if File.exist?(@@file) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
######################################################################## | ||
# test_zlib_inflate.rb | ||
# | ||
# Test case for the Zlib::Inflate class. | ||
######################################################################## | ||
require 'pr/zlib' | ||
require 'test-unit' | ||
|
||
class TC_Zlib_Inflate < Test::Unit::TestCase | ||
def self.startup | ||
end | ||
|
||
def setup | ||
@inflate = Zlib::Inflate.new | ||
end | ||
|
||
def test_inflate_run_singleton_basic | ||
assert_respond_to(Zlib::Inflate, :inflate_run) | ||
end | ||
|
||
def test_inflate_singleton_basic | ||
assert_respond_to(Zlib::Inflate, :inflate) | ||
end | ||
|
||
#def test_initialize_copy_basic | ||
#assert_respond_to(@inflate, :initialize_copy) | ||
#end | ||
|
||
def test_inflate_basic | ||
assert_respond_to(@inflate, :inflate) | ||
end | ||
|
||
def test_append_basic | ||
assert_respond_to(@inflate, :<<) | ||
end | ||
|
||
def test_sync_basic | ||
assert_respond_to(@inflate, :sync) | ||
end | ||
|
||
def test_is_sync_point_basic | ||
assert_respond_to(@inflate, :sync_point?) | ||
end | ||
|
||
def test_set_dictionary_basic | ||
assert_respond_to(@inflate, :set_dictionary) | ||
end | ||
|
||
def teardown | ||
@inflate = nil | ||
end | ||
|
||
def self.shutdown | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
require 'test-unit' | ||
require 'pr/zlib' | ||
|
||
class TC_Zlib_Zstream < Test::Unit::TestCase | ||
def self.startup | ||
end | ||
|
||
def setup | ||
@zstream = Zlib::ZStream.new | ||
@zfunc = Zlib::ZStreamFuncs.new | ||
@zstream.zstream_init(@zfunc) | ||
@src = Array.new(128, 0.chr) | ||
end | ||
|
||
def test_flags | ||
assert_respond_to(@zstream, :flags) | ||
assert_respond_to(@zstream, :flags=) | ||
end | ||
|
||
def test_buf | ||
assert_respond_to(@zstream, :buf) | ||
assert_respond_to(@zstream, :buf=) | ||
end | ||
|
||
def test_input | ||
assert_respond_to(@zstream, :input) | ||
assert_respond_to(@zstream, :input=) | ||
end | ||
|
||
def test_stream | ||
assert_respond_to(@zstream, :stream) | ||
assert_respond_to(@zstream, :stream=) | ||
end | ||
|
||
def test_func | ||
assert_respond_to(@zstream, :func) | ||
assert_respond_to(@zstream, :func=) | ||
end | ||
|
||
def test_raise_zlib_error_basic | ||
assert_respond_to(@zstream, :raise_zlib_error) | ||
end | ||
|
||
def test_raise_zlib_error_stream_end | ||
assert_raise(Zlib::StreamEnd){ @zstream.raise_zlib_error(Z_STREAM_END, nil) } | ||
assert_raise_message('stream end'){ @zstream.raise_zlib_error(Z_STREAM_END, nil) } | ||
end | ||
|
||
def test_raise_zlib_error_need_dict | ||
assert_raise(Zlib::NeedDict){ @zstream.raise_zlib_error(Z_NEED_DICT, nil) } | ||
assert_raise_message('need dictionary'){ @zstream.raise_zlib_error(Z_NEED_DICT, nil) } | ||
end | ||
|
||
def test_raise_zlib_error_stream_error | ||
assert_raise(Zlib::StreamError){ @zstream.raise_zlib_error(Z_STREAM_ERROR, nil) } | ||
assert_raise_message('stream error'){ @zstream.raise_zlib_error(Z_STREAM_ERROR, nil) } | ||
end | ||
|
||
def test_raise_zlib_error_data_error | ||
assert_raise(Zlib::DataError){ @zstream.raise_zlib_error(Z_DATA_ERROR, nil) } | ||
assert_raise_message('data error'){ @zstream.raise_zlib_error(Z_DATA_ERROR, nil) } | ||
end | ||
|
||
def test_raise_zlib_error_buf_error | ||
assert_raise(Zlib::BufError){ @zstream.raise_zlib_error(Z_BUF_ERROR, nil) } | ||
assert_raise_message('buffer error'){ @zstream.raise_zlib_error(Z_BUF_ERROR, nil) } | ||
end | ||
|
||
def test_raise_zlib_error_version_error | ||
assert_raise(Zlib::VersionError){ @zstream.raise_zlib_error(Z_VERSION_ERROR, nil) } | ||
assert_raise_message('incompatible version'){ @zstream.raise_zlib_error(Z_VERSION_ERROR, nil) } | ||
end | ||
|
||
def test_raise_zlib_error_mem_error | ||
assert_raise(Zlib::MemError){ @zstream.raise_zlib_error(Z_MEM_ERROR, nil) } | ||
assert_raise_message('insufficient memory'){ @zstream.raise_zlib_error(Z_MEM_ERROR, nil) } | ||
end | ||
|
||
def test_raise_zlib_error_errno | ||
assert_raise(SystemCallError){ @zstream.raise_zlib_error(Z_ERRNO, nil) } | ||
assert_raise_message('unknown error - file error'){ @zstream.raise_zlib_error(Z_ERRNO, nil) } | ||
end | ||
|
||
def test_raise_zlib_error_unknown | ||
#notify('I think there might be a problem here - need to investigate') | ||
assert_raise(Zlib::Error){ @zstream.raise_zlib_error(999, nil) } | ||
assert_raise_message('unknown error - file error'){ @zstream.raise_zlib_error(Z_ERRNO, nil) } | ||
end | ||
|
||
def test_zstream_expand_buffer_basic | ||
assert_respond_to(@zstream, :zstream_expand_buffer) | ||
assert_nothing_raised{ @zstream.zstream_expand_buffer } | ||
end | ||
|
||
# @zstream.buf set after call | ||
def test_zstream_expand_buffer | ||
assert_nil(@zstream.buf) | ||
assert_nil(@zstream.zstream_expand_buffer) | ||
assert_kind_of(Bytef_str, @zstream.buf) | ||
end | ||
|
||
def test_zstream_expand_buffer_expected_errors | ||
#notify("Modify zstream_expand_buffer method to explicitly handle a nil @stream") | ||
assert_raise(ArgumentError){ @zstream.zstream_expand_buffer(1) } | ||
end | ||
|
||
def test_zstream_append_buffer_basic | ||
assert_respond_to(@zstream, :zstream_append_buffer) | ||
assert_nothing_raised{ @zstream.zstream_append_buffer(@src, @src.length) } | ||
end | ||
|
||
# @zstream.buf set after call | ||
def test_zstream_append_buffer | ||
assert_nil(@zstream.buf) | ||
assert_nil(@zstream.zstream_append_buffer(@src, @src.length)) | ||
assert_kind_of(Bytef_arr, @zstream.buf) | ||
end | ||
|
||
def test_zstream_append_buffer_expected_errors | ||
assert_raise(ArgumentError){ @zstream.zstream_append_buffer } | ||
end | ||
|
||
def test_zstream_detach_buffer_basic | ||
assert_respond_to(@zstream, :zstream_detach_buffer) | ||
assert_nothing_raised{ @zstream.zstream_detach_buffer } | ||
end | ||
|
||
def test_zstream_detach_buffer | ||
assert_kind_of(String, @zstream.zstream_detach_buffer) | ||
assert_not_nil(@zstream.buf) | ||
end | ||
|
||
def test_zstream_shift_buffer_basic | ||
@zstream.buf = Bytef.new(0.chr * Zlib::ZSTREAM_INITIAL_BUFSIZE) | ||
assert_respond_to(@zstream, :zstream_shift_buffer) | ||
assert_nothing_raised{ @zstream.zstream_shift_buffer(1) } | ||
end | ||
|
||
def teardown | ||
@zstream = nil | ||
@src = nil | ||
end | ||
|
||
def self.shutdown | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,250 +1 @@ | ||
# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This | ||
# code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
# redistribute it and/or modify it under the terms of the: | ||
# | ||
# Eclipse Public License version 1.0 | ||
# GNU General Public License version 2 | ||
# GNU Lesser General Public License version 2.1 | ||
|
||
module Zlib | ||
|
||
BINARY = 0 | ||
ASCII = 1 | ||
UNKNOWN = 2 | ||
|
||
DEF_MEM_LEVEL = 8 | ||
MAX_MEM_LEVEL = 9 | ||
|
||
OS_MSDOS = 0 | ||
OS_AMIGA = 1 | ||
OS_VMS = 2 | ||
OS_CODE = 3 | ||
OS_UNIX = 3 | ||
OS_VMCMS = 4 | ||
OS_ATARI = 5 | ||
OS_OS2 = 6 | ||
OS_MACOS = 7 | ||
OS_ZSYSTEM = 8 | ||
OS_CPM = 9 | ||
OS_TOPS20 = 10 | ||
OS_WIN32 = 11 | ||
OS_QDOS = 12 | ||
OS_RISCOS = 13 | ||
OS_UNKNOWN = 255 | ||
|
||
DEFAULT_STRATEGY = 0 | ||
FILTERED = 1 | ||
HUFFMAN_ONLY = 2 | ||
|
||
NO_FLUSH = 0 | ||
SYNC_FUSH = 2 | ||
FULL_FLUSH = 3 | ||
FINISH = 4 | ||
|
||
NO_COMPRESSION = 0 | ||
BEST_SPEED = 1 | ||
BEST_COMPRESSION = 9 | ||
DEFAULT_COMPRESSION = -1 | ||
|
||
MAX_WBITS = 15 | ||
|
||
def self.crc32(*args) | ||
Truffle::Zlib.crc32(*args) | ||
end | ||
|
||
def self.adler32(*args) | ||
Truffle::Zlib.adler32(*args) | ||
end | ||
|
||
module Deflate | ||
|
||
def self.deflate(message, level=DEFAULT_COMPRESSION) | ||
Truffle::Zlib.deflate(message, level) | ||
end | ||
|
||
end | ||
|
||
module Inflate | ||
|
||
def self.inflate(message) | ||
Truffle::Zlib.inflate(message) | ||
end | ||
|
||
end | ||
|
||
class GzipFile | ||
end | ||
|
||
class GzipWriter < GzipFile | ||
|
||
def initialize(io, level = nil, strategy = nil, options = {}) | ||
raise "not supported" | ||
end | ||
|
||
def self.open(filename, level=nil, strategy=nil) | ||
raise "not supported" | ||
end | ||
|
||
def <<(p1) | ||
raise "not supported" | ||
end | ||
|
||
def comment=(p1) | ||
raise "not supported" | ||
end | ||
|
||
def flush(flush=nil) | ||
raise "not supported" | ||
end | ||
|
||
def mtime=(p1) | ||
raise "not supported" | ||
end | ||
|
||
def orig_name=(p1) | ||
raise "not supported" | ||
end | ||
|
||
def pos() | ||
raise "not supported" | ||
end | ||
|
||
def print(*args) | ||
raise "not supported" | ||
end | ||
|
||
def printf(*args) | ||
raise "not supported" | ||
end | ||
|
||
def putc(p1) | ||
raise "not supported" | ||
end | ||
|
||
def puts(*args) | ||
raise "not supported" | ||
end | ||
|
||
def tell() | ||
raise "not supported" | ||
end | ||
|
||
def write(p1) | ||
raise "not supported" | ||
end | ||
|
||
end | ||
|
||
class GzipReader < GzipFile | ||
|
||
def initialize(io, options = {}) | ||
raise "not supported" | ||
end | ||
|
||
def self.open(filename) | ||
raise "not supported" | ||
end | ||
|
||
def bytes() | ||
raise "not supported" | ||
end | ||
|
||
def each(*args) | ||
raise "not supported" | ||
end | ||
|
||
def each_byte() | ||
raise "not supported" | ||
end | ||
|
||
def each_char() | ||
raise "not supported" | ||
end | ||
|
||
def each_line(*args) | ||
raise "not supported" | ||
end | ||
|
||
def eof() | ||
raise "not supported" | ||
end | ||
|
||
def eof?() | ||
raise "not supported" | ||
end | ||
|
||
def getbyte() | ||
raise "not supported" | ||
end | ||
|
||
def getc() | ||
raise "not supported" | ||
end | ||
|
||
def gets(*args) | ||
raise "not supported" | ||
end | ||
|
||
def lineno() | ||
raise "not supported" | ||
end | ||
|
||
def lineno=(p1) | ||
raise "not supported" | ||
end | ||
|
||
def lines(*args) | ||
raise "not supported" | ||
end | ||
|
||
def pos() | ||
raise "not supported" | ||
end | ||
|
||
def read(p1 = v1) | ||
raise "not supported" | ||
end | ||
|
||
def readbyte() | ||
raise "not supported" | ||
end | ||
|
||
def readchar() | ||
raise "not supported" | ||
end | ||
|
||
def readline(*args) | ||
raise "not supported" | ||
end | ||
|
||
def readlines(*args) | ||
raise "not supported" | ||
end | ||
|
||
def readpartial(maxlen , outbuf) | ||
raise "not supported" | ||
end | ||
|
||
def rewind() | ||
raise "not supported" | ||
end | ||
|
||
def tell() | ||
raise "not supported" | ||
end | ||
|
||
def ungetbyte(p1) | ||
raise "not supported" | ||
end | ||
|
||
def ungetc(p1) | ||
raise "not supported" | ||
end | ||
|
||
def unused() | ||
raise "not supported" | ||
end | ||
|
||
end | ||
|
||
end | ||
require_relative '../pr-zlib/lib/pr/zlib' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fails:Zlib.crc32 calculates CRC checksum for string | ||
fails:Zlib.crc32 calculates CRC checksum for string and initial CRC value | ||
fails:Zlib.crc32 calculates the CRC checksum for string and initial CRC value for Bignums |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
fails:GzipReader#each_byte calls the given block for each byte in the stream, passing the byte as an argument | ||
fails:GzipReader#each_byte increments position before calling the block |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1 @@ | ||
fails:GzipReader#read with no arguments reads the entire content of a gzip file | ||
fails:GzipReader#read with nil length argument reads the entire content of a gzip file | ||
fails:GzipReader#read reads the contents up to a certain size | ||
fails:GzipReader#read does not accept a negative length to read | ||
fails:GzipReader#read returns an empty string if a 0 length is given | ||
fails:GzipReader#read respects :external_encoding option | ||
fails:GzipReader#read at the end of data returns empty string if length prameter is not specified or 0 | ||
fails:GzipReader#read at the end of data returns nil if length prameter is positive |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
fails:GzipWriter#write writes some compressed data | ||
fails:GzipWriter#write returns the number of bytes in the input | ||
fails:GzipWriter#write handles inputs of 2^23 bytes |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,2 @@ | ||
fails:Zlib::Inflate#inflate inflates some data | ||
fails:Zlib::Inflate#inflate inflates lots of data | ||
fails:Zlib::Inflate#inflate works in pass-through mode, once finished | ||
fails:Zlib::Inflate.inflate properly handles data in chunks | ||
fails:Zlib::Inflate.inflate properly handles incomplete data | ||
fails:Zlib::Inflate.inflate properly handles excessive data, byte-by-byte | ||
fails:Zlib::Inflate.inflate properly handles excessive data, in one go |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.