2004-04-05 17:27:45 +04:00
|
|
|
require 'test/unit/testsuite'
|
|
|
|
require 'test/unit/testcase'
|
2004-08-06 20:01:02 +04:00
|
|
|
require 'stringio'
|
2004-04-05 17:27:45 +04:00
|
|
|
|
2004-04-06 06:59:13 +04:00
|
|
|
begin
|
|
|
|
require 'zlib'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2004-04-05 17:27:45 +04:00
|
|
|
|
2004-04-06 06:59:13 +04:00
|
|
|
if defined? Zlib
|
2004-08-06 20:01:02 +04:00
|
|
|
class TestZlibGzipReader < Test::Unit::TestCase
|
|
|
|
D0 = "\037\213\010\000S`\017A\000\003\003\000\000\000\000\000\000\000\000\000"
|
|
|
|
def test_read0
|
|
|
|
assert_equal("", Zlib::GzipReader.new(StringIO.new(D0)).read(0))
|
|
|
|
end
|
2004-09-07 09:32:26 +04:00
|
|
|
|
|
|
|
def test_ungetc # [ruby-dev:24060]
|
|
|
|
s = ""
|
|
|
|
w = Zlib::GzipWriter.new(StringIO.new(s))
|
|
|
|
w << (1...1000).to_a.inspect
|
|
|
|
w.close
|
|
|
|
r = Zlib::GzipReader.new(StringIO.new(s))
|
|
|
|
r.read(100)
|
|
|
|
r.ungetc ?a
|
|
|
|
assert_nothing_raised {
|
|
|
|
r.read(100)
|
|
|
|
r.read
|
|
|
|
r.close
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_ungetc_paragraph # [ruby-dev:24065]
|
|
|
|
s = ""
|
|
|
|
w = Zlib::GzipWriter.new(StringIO.new(s))
|
|
|
|
w << "abc"
|
|
|
|
w.close
|
|
|
|
r = Zlib::GzipReader.new(StringIO.new(s))
|
2004-09-07 11:03:51 +04:00
|
|
|
begin
|
|
|
|
old_rs = $/
|
|
|
|
$/ = ""
|
|
|
|
r.ungetc ?\n
|
|
|
|
assert_equal("abc", r.gets)
|
|
|
|
assert_nothing_raised {
|
|
|
|
r.read
|
|
|
|
r.close
|
|
|
|
}
|
|
|
|
ensure
|
|
|
|
$/ = old_rs
|
|
|
|
end
|
2004-09-07 09:32:26 +04:00
|
|
|
end
|
2004-08-06 20:01:02 +04:00
|
|
|
end
|
|
|
|
|
2004-04-06 06:59:13 +04:00
|
|
|
class TestZlibGzipWriter < Test::Unit::TestCase
|
2004-04-07 09:06:34 +04:00
|
|
|
def test_invalid_new
|
|
|
|
# [ruby-dev:23228]
|
2004-09-07 09:32:26 +04:00
|
|
|
assert_raise(NoMethodError) { Zlib::GzipWriter.new(nil).close }
|
2004-04-07 09:06:34 +04:00
|
|
|
# [ruby-dev:23344]
|
2004-09-07 09:32:26 +04:00
|
|
|
assert_raise(NoMethodError) { Zlib::GzipWriter.new(true).close }
|
|
|
|
assert_raise(NoMethodError) { Zlib::GzipWriter.new(0).close }
|
|
|
|
assert_raise(NoMethodError) { Zlib::GzipWriter.new(:hoge).close }
|
2004-04-06 06:59:13 +04:00
|
|
|
end
|
2004-04-05 17:27:45 +04:00
|
|
|
end
|
|
|
|
end
|