2004-04-05 09:27:45 -04:00
|
|
|
require 'test/unit/testsuite'
|
|
|
|
require 'test/unit/testcase'
|
2004-08-06 12:01:02 -04:00
|
|
|
require 'stringio'
|
2004-04-05 09:27:45 -04:00
|
|
|
|
2004-04-05 22:59:13 -04:00
|
|
|
begin
|
|
|
|
require 'zlib'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2004-04-05 09:27:45 -04:00
|
|
|
|
2004-04-05 22:59:13 -04:00
|
|
|
if defined? Zlib
|
2004-08-06 12: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 01:32:26 -04:00
|
|
|
|
2007-11-18 02:18:56 -05:00
|
|
|
def test_ungetc
|
2004-09-07 01:32:26 -04:00
|
|
|
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
|
2007-11-18 02:18:56 -05:00
|
|
|
assert_nothing_raised("[ruby-dev:24060]") {
|
2004-09-07 01:32:26 -04:00
|
|
|
r.read(100)
|
|
|
|
r.read
|
|
|
|
r.close
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2007-11-18 02:18:56 -05:00
|
|
|
def test_ungetc_paragraph
|
2004-09-07 01:32:26 -04:00
|
|
|
s = ""
|
|
|
|
w = Zlib::GzipWriter.new(StringIO.new(s))
|
|
|
|
w << "abc"
|
|
|
|
w.close
|
|
|
|
r = Zlib::GzipReader.new(StringIO.new(s))
|
2004-09-07 03:11:06 -04:00
|
|
|
r.ungetc ?\n
|
|
|
|
assert_equal("abc", r.gets(""))
|
2007-11-18 02:18:56 -05:00
|
|
|
assert_nothing_raised("[ruby-dev:24065]") {
|
2004-09-07 03:11:06 -04:00
|
|
|
r.read
|
|
|
|
r.close
|
|
|
|
}
|
2004-09-07 01:32:26 -04:00
|
|
|
end
|
2004-08-06 12:01:02 -04:00
|
|
|
end
|
|
|
|
|
2004-04-05 22:59:13 -04:00
|
|
|
class TestZlibGzipWriter < Test::Unit::TestCase
|
2004-04-07 01:06:34 -04:00
|
|
|
def test_invalid_new
|
2007-11-18 02:18:56 -05:00
|
|
|
assert_raise(NoMethodError, "[ruby-dev:23228]") { Zlib::GzipWriter.new(nil).close }
|
|
|
|
assert_raise(NoMethodError, "[ruby-dev:23344]") { Zlib::GzipWriter.new(true).close }
|
|
|
|
assert_raise(NoMethodError, "[ruby-dev:23344]") { Zlib::GzipWriter.new(0).close }
|
|
|
|
assert_raise(NoMethodError, "[ruby-dev:23344]") { Zlib::GzipWriter.new(:hoge).close }
|
2004-04-05 22:59:13 -04:00
|
|
|
end
|
2004-04-05 09:27:45 -04:00
|
|
|
end
|
|
|
|
end
|