2016-12-10 01:45:39 +03:00
|
|
|
# coding: us-ascii
|
2017-02-07 15:49:57 +03:00
|
|
|
# frozen_string_literal: true
|
2008-06-08 16:51:25 +04:00
|
|
|
require 'test/unit'
|
2004-08-06 20:01:02 +04:00
|
|
|
require 'stringio'
|
2008-06-08 16:51:25 +04:00
|
|
|
require 'tempfile'
|
2021-03-16 20:16:27 +03:00
|
|
|
require 'tmpdir'
|
2021-06-16 01:27:57 +03:00
|
|
|
require 'securerandom'
|
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
|
2008-06-08 16:51:25 +04:00
|
|
|
class TestZlibDeflate < Test::Unit::TestCase
|
|
|
|
def test_initialize
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
s = z.deflate("foo", Zlib::FINISH)
|
|
|
|
assert_equal("foo", Zlib::Inflate.inflate(s))
|
|
|
|
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
s = z.deflate("foo")
|
|
|
|
s << z.deflate(nil, Zlib::FINISH)
|
|
|
|
assert_equal("foo", Zlib::Inflate.inflate(s))
|
|
|
|
|
|
|
|
assert_raise(Zlib::StreamError) { Zlib::Deflate.new(10000) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dup
|
|
|
|
z1 = Zlib::Deflate.new
|
|
|
|
s = z1.deflate("foo")
|
|
|
|
z2 = z1.dup
|
|
|
|
s1 = s + z1.deflate("bar", Zlib::FINISH)
|
|
|
|
s2 = s + z2.deflate("baz", Zlib::FINISH)
|
|
|
|
assert_equal("foobar", Zlib::Inflate.inflate(s1))
|
|
|
|
assert_equal("foobaz", Zlib::Inflate.inflate(s2))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_deflate
|
|
|
|
s = Zlib::Deflate.deflate("foo")
|
|
|
|
assert_equal("foo", Zlib::Inflate.inflate(s))
|
|
|
|
|
|
|
|
assert_raise(Zlib::StreamError) { Zlib::Deflate.deflate("foo", 10000) }
|
|
|
|
end
|
|
|
|
|
2012-07-10 22:28:40 +04:00
|
|
|
def test_deflate_chunked
|
2023-09-29 12:29:32 +03:00
|
|
|
original = ''.dup
|
|
|
|
chunks = []
|
|
|
|
r = Random.new 0
|
|
|
|
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
|
|
|
|
2.times do
|
|
|
|
input = r.bytes(20000)
|
|
|
|
original << input
|
|
|
|
z.deflate(input) do |chunk|
|
|
|
|
chunks << chunk
|
2012-07-10 22:28:40 +04:00
|
|
|
end
|
2023-09-29 12:29:32 +03:00
|
|
|
end
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
assert_equal [16384, 16384],
|
|
|
|
chunks.map { |chunk| chunk.length }
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
final = z.finish
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
assert_equal 7253, final.length
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
chunks << final
|
|
|
|
all = chunks.join
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
inflated = Zlib.inflate all
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
assert_equal original, inflated
|
2012-07-10 22:28:40 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_deflate_chunked_break
|
2023-09-29 12:29:32 +03:00
|
|
|
chunks = []
|
|
|
|
r = Random.new 0
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
z = Zlib::Deflate.new
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
input = r.bytes(20000)
|
|
|
|
z.deflate(input) do |chunk|
|
|
|
|
chunks << chunk
|
|
|
|
break
|
|
|
|
end
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
assert_equal [16384], chunks.map { |chunk| chunk.length }
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
final = z.finish
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
assert_equal 3632, final.length
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
all = chunks.join
|
|
|
|
all << final
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
original = Zlib.inflate all
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
assert_equal input, original
|
2012-07-10 22:28:40 +04:00
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_addstr
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
z << "foo"
|
|
|
|
s = z.deflate(nil, Zlib::FINISH)
|
|
|
|
assert_equal("foo", Zlib::Inflate.inflate(s))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_flush
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
z << "foo"
|
|
|
|
s = z.flush
|
|
|
|
z << "bar"
|
|
|
|
s << z.flush_next_in
|
|
|
|
z << "baz"
|
|
|
|
s << z.flush_next_out
|
|
|
|
s << z.deflate("qux", Zlib::FINISH)
|
|
|
|
assert_equal("foobarbazqux", Zlib::Inflate.inflate(s))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_avail
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
assert_equal(0, z.avail_in)
|
|
|
|
assert_equal(0, z.avail_out)
|
|
|
|
z << "foo"
|
|
|
|
z.avail_out += 100
|
|
|
|
z << "bar"
|
|
|
|
s = z.finish
|
|
|
|
assert_equal("foobar", Zlib::Inflate.inflate(s))
|
|
|
|
end
|
|
|
|
|
2017-05-01 05:01:38 +03:00
|
|
|
def test_expand_buffer;
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
src = "baz" * 1000
|
|
|
|
z.avail_out = 1
|
|
|
|
GC.stress = true
|
|
|
|
s = z.deflate(src, Zlib::FINISH)
|
|
|
|
GC.stress = false
|
|
|
|
assert_equal(src, Zlib::Inflate.inflate(s))
|
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_total
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
1000.times { z << "foo" }
|
|
|
|
s = z.finish
|
|
|
|
assert_equal(3000, z.total_in)
|
|
|
|
assert_operator(3000, :>, z.total_out)
|
|
|
|
assert_equal("foo" * 1000, Zlib::Inflate.inflate(s))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_data_type
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
assert([Zlib::ASCII, Zlib::BINARY, Zlib::UNKNOWN].include?(z.data_type))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_adler
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
z << "foo"
|
2011-02-03 18:15:04 +03:00
|
|
|
z.finish
|
2008-06-08 16:51:25 +04:00
|
|
|
assert_equal(0x02820145, z.adler)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_finished_p
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
assert_equal(false, z.finished?)
|
|
|
|
z << "foo"
|
|
|
|
assert_equal(false, z.finished?)
|
2011-02-03 18:15:04 +03:00
|
|
|
z.finish
|
2008-06-08 16:51:25 +04:00
|
|
|
assert_equal(true, z.finished?)
|
|
|
|
z.close
|
|
|
|
assert_raise(Zlib::Error) { z.finished? }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_closed_p
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
assert_equal(false, z.closed?)
|
|
|
|
z << "foo"
|
|
|
|
assert_equal(false, z.closed?)
|
2014-02-18 16:05:09 +04:00
|
|
|
z.finish
|
2008-06-08 16:51:25 +04:00
|
|
|
assert_equal(false, z.closed?)
|
|
|
|
z.close
|
|
|
|
assert_equal(true, z.closed?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_params
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
z << "foo"
|
|
|
|
z.params(Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY)
|
|
|
|
z << "bar"
|
|
|
|
s = z.finish
|
|
|
|
assert_equal("foobar", Zlib::Inflate.inflate(s))
|
|
|
|
|
2008-07-11 18:06:19 +04:00
|
|
|
data = ('a'..'z').to_a.join
|
|
|
|
z = Zlib::Deflate.new(Zlib::NO_COMPRESSION, Zlib::MAX_WBITS,
|
|
|
|
Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY)
|
|
|
|
z << data[0, 10]
|
|
|
|
z.params(Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY)
|
|
|
|
z << data[10 .. -1]
|
|
|
|
assert_equal(data, Zlib::Inflate.inflate(z.finish))
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
z = Zlib::Deflate.new
|
|
|
|
s = z.deflate("foo", Zlib::FULL_FLUSH)
|
|
|
|
z.avail_out = 0
|
2019-07-24 16:07:10 +03:00
|
|
|
EnvUtil.suppress_warning {z.params(Zlib::NO_COMPRESSION, Zlib::FILTERED)}
|
2008-06-08 16:51:25 +04:00
|
|
|
s << z.deflate("bar", Zlib::FULL_FLUSH)
|
|
|
|
z.avail_out = 0
|
2019-07-24 16:07:10 +03:00
|
|
|
EnvUtil.suppress_warning {z.params(Zlib::BEST_COMPRESSION, Zlib::HUFFMAN_ONLY)}
|
2008-06-08 16:51:25 +04:00
|
|
|
s << z.deflate("baz", Zlib::FINISH)
|
|
|
|
assert_equal("foobarbaz", Zlib::Inflate.inflate(s))
|
|
|
|
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
assert_raise(Zlib::StreamError) { z.params(10000, 10000) }
|
2008-07-23 05:09:50 +04:00
|
|
|
z.close # without this, outputs `zlib(finalizer): the stream was freed prematurely.'
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_dictionary
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
z.set_dictionary("foo")
|
|
|
|
s = z.deflate("foo" * 100, Zlib::FINISH)
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
assert_raise(Zlib::NeedDict) { z.inflate(s) }
|
|
|
|
z.set_dictionary("foo")
|
|
|
|
assert_equal("foo" * 100, z.inflate(s)) # ???
|
|
|
|
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
z << "foo"
|
|
|
|
assert_raise(Zlib::StreamError) { z.set_dictionary("foo") }
|
2016-12-20 19:02:22 +03:00
|
|
|
EnvUtil.suppress_warning do
|
|
|
|
z.close # without this, outputs `zlib(finalizer): the stream was freed prematurely.'
|
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_reset
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
z << "foo"
|
|
|
|
z.reset
|
|
|
|
z << "bar"
|
|
|
|
s = z.finish
|
|
|
|
assert_equal("bar", Zlib::Inflate.inflate(s))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_close
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
z.close
|
|
|
|
assert_raise(Zlib::Error) { z << "foo" }
|
|
|
|
assert_raise(Zlib::Error) { z.reset }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestZlibInflate < Test::Unit::TestCase
|
2013-08-29 00:36:21 +04:00
|
|
|
def test_class_inflate_dictionary
|
2015-06-02 05:18:44 +03:00
|
|
|
assert_raise(Zlib::NeedDict) do
|
2013-08-29 00:36:21 +04:00
|
|
|
Zlib::Inflate.inflate([0x08,0x3C,0x0,0x0,0x0,0x0].pack("c*"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_initialize
|
|
|
|
assert_raise(Zlib::StreamError) { Zlib::Inflate.new(-1) }
|
|
|
|
|
|
|
|
s = Zlib::Deflate.deflate("foo")
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
z << s << nil
|
|
|
|
assert_equal("foo", z.finish)
|
|
|
|
end
|
|
|
|
|
2012-02-11 04:37:44 +04:00
|
|
|
def test_add_dictionary
|
|
|
|
dictionary = "foo"
|
|
|
|
|
|
|
|
deflate = Zlib::Deflate.new
|
|
|
|
deflate.set_dictionary dictionary
|
|
|
|
compressed = deflate.deflate "foofoofoo", Zlib::FINISH
|
|
|
|
deflate.close
|
|
|
|
|
|
|
|
out = nil
|
|
|
|
inflate = Zlib::Inflate.new
|
|
|
|
inflate.add_dictionary "foo"
|
|
|
|
|
|
|
|
out = inflate.inflate compressed
|
|
|
|
|
|
|
|
assert_equal "foofoofoo", out
|
|
|
|
end
|
|
|
|
|
2012-07-10 22:28:40 +04:00
|
|
|
def test_finish_chunked
|
|
|
|
# zeros = Zlib::Deflate.deflate("0" * 100_000)
|
|
|
|
zeros = "x\234\355\3011\001\000\000\000\302\240J\353\237\316\032\036@" \
|
|
|
|
"\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\257\006\351\247BH"
|
|
|
|
|
|
|
|
chunks = []
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
|
|
|
|
z.inflate(zeros) do |chunk|
|
|
|
|
chunks << chunk
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
z.finish do |chunk|
|
|
|
|
chunks << chunk
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [16384, 16384, 16384, 16384, 16384, 16384, 1696],
|
|
|
|
chunks.map { |chunk| chunk.size }
|
|
|
|
|
|
|
|
assert chunks.all? { |chunk|
|
|
|
|
chunk =~ /\A0+\z/
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_inflate
|
|
|
|
s = Zlib::Deflate.deflate("foo")
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
s = z.inflate(s)
|
|
|
|
s << z.inflate(nil)
|
|
|
|
assert_equal("foo", s)
|
|
|
|
z.inflate("foo") # ???
|
|
|
|
z << "foo" # ???
|
|
|
|
end
|
|
|
|
|
2012-07-04 02:08:04 +04:00
|
|
|
def test_inflate_partial_input
|
|
|
|
deflated = Zlib::Deflate.deflate "\0"
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
|
2017-02-07 15:49:57 +03:00
|
|
|
inflated = "".dup
|
2012-07-04 02:08:04 +04:00
|
|
|
|
|
|
|
deflated.each_char do |byte|
|
|
|
|
inflated << z.inflate(byte)
|
|
|
|
end
|
|
|
|
|
|
|
|
inflated << z.finish
|
|
|
|
|
|
|
|
assert_equal "\0", inflated
|
|
|
|
end
|
|
|
|
|
2012-07-10 22:28:40 +04:00
|
|
|
def test_inflate_chunked
|
|
|
|
# s = Zlib::Deflate.deflate("0" * 100_000)
|
|
|
|
zeros = "x\234\355\3011\001\000\000\000\302\240J\353\237\316\032\036@" \
|
|
|
|
"\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\257\006\351\247BH"
|
|
|
|
|
|
|
|
chunks = []
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
|
|
|
|
z.inflate(zeros) do |chunk|
|
|
|
|
chunks << chunk
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [16384, 16384, 16384, 16384, 16384, 16384, 1696],
|
|
|
|
chunks.map { |chunk| chunk.size }
|
|
|
|
|
|
|
|
assert chunks.all? { |chunk|
|
|
|
|
chunk =~ /\A0+\z/
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-10-29 22:28:09 +03:00
|
|
|
def test_inflate_buffer
|
|
|
|
s = Zlib::Deflate.deflate("foo")
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
buf = String.new
|
|
|
|
s = z.inflate(s, buffer: buf)
|
|
|
|
assert_same(buf, s)
|
|
|
|
buf = String.new
|
|
|
|
s << z.inflate(nil, buffer: buf)
|
|
|
|
assert_equal("foo", s)
|
|
|
|
z.inflate("foo", buffer: buf) # ???
|
|
|
|
z << "foo" # ???
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_inflate_buffer_partial_input
|
|
|
|
deflated = Zlib::Deflate.deflate "\0"
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
|
|
|
|
inflated = "".dup
|
|
|
|
|
|
|
|
buf = String.new
|
|
|
|
deflated.each_char do |byte|
|
|
|
|
inflated << z.inflate(byte, buffer: buf)
|
|
|
|
end
|
|
|
|
|
|
|
|
inflated << z.finish
|
|
|
|
|
|
|
|
assert_equal "\0", inflated
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_inflate_buffer_chunked
|
|
|
|
# s = Zlib::Deflate.deflate("0" * 100_000)
|
|
|
|
zeros = "x\234\355\3011\001\000\000\000\302\240J\353\237\316\032\036@" \
|
|
|
|
"\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\257\006\351\247BH"
|
|
|
|
|
|
|
|
chunks = []
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
|
|
|
|
buf = String.new
|
|
|
|
z.inflate(zeros, buffer: buf) do |chunk|
|
|
|
|
assert_same(buf, chunk)
|
|
|
|
chunks << chunk.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal [16384, 16384, 16384, 16384, 16384, 16384, 1696],
|
|
|
|
chunks.map { |chunk| chunk.size }
|
|
|
|
|
|
|
|
assert chunks.all? { |chunk|
|
|
|
|
chunk =~ /\A0+\z/
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2012-07-10 22:28:40 +04:00
|
|
|
def test_inflate_chunked_break
|
|
|
|
# zeros = Zlib::Deflate.deflate("0" * 100_000)
|
|
|
|
zeros = "x\234\355\3011\001\000\000\000\302\240J\353\237\316\032\036@" \
|
|
|
|
"\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" \
|
|
|
|
"\000\000\000\000\000\000\000\257\006\351\247BH"
|
|
|
|
|
|
|
|
chunks = []
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
|
|
|
|
z.inflate(zeros) do |chunk|
|
|
|
|
chunks << chunk
|
|
|
|
break
|
|
|
|
end
|
|
|
|
|
|
|
|
out = z.inflate nil
|
|
|
|
|
|
|
|
assert_equal 100_000 - chunks.first.length, out.length
|
|
|
|
end
|
|
|
|
|
2012-02-11 04:29:52 +04:00
|
|
|
def test_inflate_dictionary
|
|
|
|
dictionary = "foo"
|
|
|
|
|
|
|
|
deflate = Zlib::Deflate.new
|
|
|
|
deflate.set_dictionary dictionary
|
|
|
|
compressed = deflate.deflate "foofoofoo", Zlib::FINISH
|
|
|
|
deflate.close
|
|
|
|
|
|
|
|
out = nil
|
|
|
|
inflate = Zlib::Inflate.new
|
|
|
|
|
|
|
|
begin
|
|
|
|
out = inflate.inflate compressed
|
|
|
|
|
|
|
|
flunk "Zlib::NeedDict was not raised"
|
|
|
|
rescue Zlib::NeedDict
|
|
|
|
inflate.set_dictionary dictionary
|
|
|
|
out = inflate.inflate ""
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "foofoofoo", out
|
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_sync
|
|
|
|
z = Zlib::Deflate.new
|
|
|
|
s = z.deflate("foo" * 1000, Zlib::FULL_FLUSH)
|
|
|
|
z.avail_out = 0
|
2019-07-24 16:07:10 +03:00
|
|
|
EnvUtil.suppress_warning {z.params(Zlib::NO_COMPRESSION, Zlib::FILTERED)}
|
2008-06-08 16:51:25 +04:00
|
|
|
s << z.deflate("bar" * 1000, Zlib::FULL_FLUSH)
|
|
|
|
z.avail_out = 0
|
2019-07-24 16:07:10 +03:00
|
|
|
EnvUtil.suppress_warning {z.params(Zlib::BEST_COMPRESSION, Zlib::HUFFMAN_ONLY)}
|
2008-06-08 16:51:25 +04:00
|
|
|
s << z.deflate("baz" * 1000, Zlib::FINISH)
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
assert_raise(Zlib::DataError) { z << "\0" * 100 }
|
|
|
|
assert_equal(false, z.sync(""))
|
|
|
|
assert_equal(false, z.sync_point?)
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
assert_raise(Zlib::DataError) { z << "\0" * 100 + s }
|
|
|
|
assert_equal(true, z.sync(""))
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
assert_equal(false, z.sync("\0" * 100))
|
|
|
|
assert_equal(false, z.sync_point?)
|
|
|
|
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
assert_equal(true, z.sync("\0" * 100 + s))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_dictionary
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
assert_raise(Zlib::StreamError) { z.set_dictionary("foo") }
|
|
|
|
z.close
|
|
|
|
end
|
2021-06-16 01:27:57 +03:00
|
|
|
|
|
|
|
def test_multithread_deflate
|
2023-09-21 20:55:25 +03:00
|
|
|
pend 'hangs' if RUBY_ENGINE == 'truffleruby'
|
2021-06-16 01:27:57 +03:00
|
|
|
zd = Zlib::Deflate.new
|
|
|
|
|
|
|
|
s = "x" * 10000
|
|
|
|
(0...10).map do |x|
|
|
|
|
Thread.new do
|
|
|
|
1000.times { zd.deflate(s) }
|
|
|
|
end
|
|
|
|
end.each do |th|
|
|
|
|
th.join
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
zd&.finish
|
|
|
|
zd&.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_multithread_inflate
|
2023-09-21 20:55:25 +03:00
|
|
|
pend 'hangs' if RUBY_ENGINE == 'truffleruby'
|
2021-06-16 01:27:57 +03:00
|
|
|
zi = Zlib::Inflate.new
|
|
|
|
|
|
|
|
s = Zlib.deflate("x" * 10000)
|
|
|
|
(0...10).map do |x|
|
|
|
|
Thread.new do
|
|
|
|
1000.times { zi.inflate(s) }
|
|
|
|
end
|
|
|
|
end.each do |th|
|
|
|
|
th.join
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
zi&.finish
|
|
|
|
zi&.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_recursive_deflate
|
2021-11-23 21:14:45 +03:00
|
|
|
original_gc_stress = GC.stress
|
|
|
|
GC.stress = true
|
2021-06-16 01:27:57 +03:00
|
|
|
zd = Zlib::Deflate.new
|
|
|
|
|
|
|
|
s = SecureRandom.random_bytes(1024**2)
|
2021-11-23 21:14:45 +03:00
|
|
|
assert_raise(Zlib::InProgressError) do
|
2021-06-16 01:27:57 +03:00
|
|
|
zd.deflate(s) do
|
|
|
|
zd.deflate(s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ensure
|
2021-11-23 21:14:45 +03:00
|
|
|
GC.stress = original_gc_stress
|
2021-06-16 01:27:57 +03:00
|
|
|
zd&.finish
|
|
|
|
zd&.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_recursive_inflate
|
2021-11-23 21:14:45 +03:00
|
|
|
original_gc_stress = GC.stress
|
|
|
|
GC.stress = true
|
2021-06-16 01:27:57 +03:00
|
|
|
zi = Zlib::Inflate.new
|
|
|
|
|
|
|
|
s = Zlib.deflate(SecureRandom.random_bytes(1024**2))
|
|
|
|
|
2021-11-23 21:14:45 +03:00
|
|
|
assert_raise(Zlib::InProgressError) do
|
2021-06-16 01:27:57 +03:00
|
|
|
zi.inflate(s) do
|
|
|
|
zi.inflate(s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ensure
|
2021-11-23 21:14:45 +03:00
|
|
|
GC.stress = original_gc_stress
|
2021-06-16 01:27:57 +03:00
|
|
|
zi&.close
|
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TestZlibGzipFile < Test::Unit::TestCase
|
2019-11-27 04:31:47 +03:00
|
|
|
def test_gzip_reader_zcat
|
|
|
|
Tempfile.create("test_zlib_gzip_file_to_io") {|t|
|
2021-04-08 08:22:59 +03:00
|
|
|
t.binmode
|
2019-11-27 04:31:47 +03:00
|
|
|
gz = Zlib::GzipWriter.new(t)
|
|
|
|
gz.print("foo")
|
|
|
|
gz.close
|
2021-02-03 11:34:41 +03:00
|
|
|
File.open(t.path, 'ab') do |f|
|
|
|
|
gz = Zlib::GzipWriter.new(f)
|
|
|
|
gz.print("bar")
|
|
|
|
gz.close
|
|
|
|
end
|
2019-11-27 04:31:47 +03:00
|
|
|
|
|
|
|
results = []
|
2021-02-03 11:34:41 +03:00
|
|
|
File.open(t.path, 'rb') do |f|
|
|
|
|
Zlib::GzipReader.zcat(f) do |str|
|
|
|
|
results << str
|
|
|
|
end
|
2019-11-27 04:31:47 +03:00
|
|
|
end
|
|
|
|
assert_equal(["foo", "bar"], results)
|
|
|
|
|
2021-02-03 11:34:41 +03:00
|
|
|
results = File.open(t.path, 'rb') do |f|
|
|
|
|
Zlib::GzipReader.zcat(f)
|
|
|
|
end
|
|
|
|
assert_equal("foobar", results)
|
2019-11-27 04:31:47 +03:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_to_io
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_to_io") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_kind_of(IO, f.to_io)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_crc
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_crc") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
f.read
|
|
|
|
assert_equal(0x8c736521, f.crc)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_mtime
|
|
|
|
tim = Time.now
|
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_mtime") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) do |gz|
|
|
|
|
gz.mtime = -1
|
|
|
|
gz.mtime = tim
|
|
|
|
gz.print("foo")
|
|
|
|
gz.flush
|
|
|
|
assert_raise(Zlib::GzipFile::Error) { gz.mtime = Time.now }
|
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal(tim.to_i, f.mtime.to_i)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
2019-10-26 02:15:24 +03:00
|
|
|
def test_zero_mtime
|
|
|
|
sio = StringIO.new
|
|
|
|
gz = Zlib::GzipWriter.new(sio)
|
|
|
|
gz.mtime = 0
|
|
|
|
gz.write("Hi")
|
|
|
|
gz.close
|
|
|
|
reading_io = StringIO.new(sio.string)
|
|
|
|
reader = Zlib::GzipReader.new(reading_io)
|
|
|
|
assert_equal(0, reader.mtime.to_i)
|
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_level
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_level") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal(Zlib::DEFAULT_COMPRESSION, f.level)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_os_code
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_os_code") {|t|
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal(Zlib::OS_CODE, f.os_code)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_orig_name
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_orig_name") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) do |gz|
|
|
|
|
gz.orig_name = "foobarbazqux\0quux"
|
|
|
|
gz.print("foo")
|
|
|
|
gz.flush
|
|
|
|
assert_raise(Zlib::GzipFile::Error) { gz.orig_name = "quux" }
|
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal("foobarbazqux", f.orig_name)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_comment
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_comment") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) do |gz|
|
|
|
|
gz.comment = "foobarbazqux\0quux"
|
|
|
|
gz.print("foo")
|
|
|
|
gz.flush
|
|
|
|
assert_raise(Zlib::GzipFile::Error) { gz.comment = "quux" }
|
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal("foobarbazqux", f.comment)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_lineno
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_lineno") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\nqux\n") }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal([0, "foo\n"], [f.lineno, f.gets])
|
|
|
|
assert_equal([1, "bar\n"], [f.lineno, f.gets])
|
|
|
|
f.lineno = 1000
|
|
|
|
assert_equal([1000, "baz\n"], [f.lineno, f.gets])
|
|
|
|
assert_equal([1001, "qux\n"], [f.lineno, f.gets])
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_closed_p
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_closed_p") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal(false, f.closed?)
|
|
|
|
f.read
|
|
|
|
assert_equal(false, f.closed?)
|
|
|
|
f.close
|
|
|
|
assert_equal(true, f.closed?)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_sync
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_sync") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
f.sync = true
|
|
|
|
assert_equal(true, f.sync)
|
|
|
|
f.read
|
|
|
|
f.sync = false
|
|
|
|
assert_equal(false, f.sync)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_pos
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_pos") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) do |gz|
|
|
|
|
gz.print("foo")
|
|
|
|
gz.flush
|
|
|
|
assert_equal(3, gz.tell)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
2009-04-22 20:31:06 +04:00
|
|
|
|
|
|
|
def test_path
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_file_path") {|t|
|
|
|
|
t.close
|
2009-04-22 20:31:06 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
gz = Zlib::GzipWriter.open(t.path)
|
|
|
|
gz.print("foo")
|
|
|
|
assert_equal(t.path, gz.path)
|
|
|
|
gz.close
|
|
|
|
assert_equal(t.path, gz.path)
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal(t.path, f.path)
|
|
|
|
f.close
|
|
|
|
assert_equal(t.path, f.path)
|
|
|
|
end
|
2009-04-22 20:31:06 +04:00
|
|
|
|
2017-02-07 15:49:57 +03:00
|
|
|
s = "".dup
|
2017-01-14 12:38:56 +03:00
|
|
|
sio = StringIO.new(s)
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
gz = Zlib::GzipWriter.new(sio)
|
|
|
|
gz.print("foo")
|
|
|
|
assert_raise(NoMethodError) { gz.path }
|
|
|
|
gz.close
|
2009-04-22 20:31:06 +04:00
|
|
|
|
2017-01-14 12:38:56 +03:00
|
|
|
sio = StringIO.new(s)
|
2018-04-17 09:38:08 +03:00
|
|
|
gz = Zlib::GzipReader.new(sio)
|
|
|
|
assert_raise(NoMethodError) { gz.path }
|
|
|
|
gz.close
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
}
|
2009-04-22 20:31:06 +04:00
|
|
|
end
|
2021-03-16 20:16:27 +03:00
|
|
|
|
2023-09-21 20:55:25 +03:00
|
|
|
if defined?(File::TMPFILE) and RUBY_ENGINE != 'truffleruby'
|
2021-03-16 20:16:27 +03:00
|
|
|
def test_path_tmpfile
|
|
|
|
sio = StringIO.new("".dup, 'w')
|
|
|
|
gz = Zlib::GzipWriter.new(sio)
|
|
|
|
gz.write "hi"
|
|
|
|
gz.close
|
|
|
|
|
2024-04-20 13:45:01 +03:00
|
|
|
tmpdir = Dir.mktmpdir("zlib_file_tmpfile")
|
|
|
|
File.open(tmpdir, File::RDWR | File::TMPFILE) do |io|
|
2021-03-16 20:16:27 +03:00
|
|
|
io.write sio.string
|
|
|
|
io.rewind
|
|
|
|
|
2021-03-16 20:40:43 +03:00
|
|
|
gz0 = Zlib::GzipWriter.new(io)
|
|
|
|
gz1 = Zlib::GzipReader.new(io)
|
2023-01-09 12:53:00 +03:00
|
|
|
|
|
|
|
if IO.method_defined?(:path)
|
|
|
|
assert_nil gz0.path
|
|
|
|
assert_nil gz1.path
|
|
|
|
else
|
|
|
|
assert_raise(NoMethodError) { gz0.path }
|
|
|
|
assert_raise(NoMethodError) { gz1.path }
|
|
|
|
end
|
|
|
|
|
2021-03-16 20:40:43 +03:00
|
|
|
gz0.close
|
|
|
|
gz1.close
|
2021-03-16 20:16:27 +03:00
|
|
|
end
|
2021-03-23 06:20:58 +03:00
|
|
|
rescue Errno::EINVAL
|
2022-01-11 15:26:49 +03:00
|
|
|
omit 'O_TMPFILE not supported (EINVAL)'
|
2021-03-23 06:20:58 +03:00
|
|
|
rescue Errno::EISDIR
|
2022-01-11 15:26:49 +03:00
|
|
|
omit 'O_TMPFILE not supported (EISDIR)'
|
2021-03-23 06:20:58 +03:00
|
|
|
rescue Errno::EOPNOTSUPP
|
2022-01-11 15:26:49 +03:00
|
|
|
omit 'O_TMPFILE not supported (EOPNOTSUPP)'
|
2024-04-20 13:45:01 +03:00
|
|
|
ensure
|
|
|
|
Dir.rmdir(tmpdir) if tmpdir
|
2021-03-16 20:16:27 +03:00
|
|
|
end
|
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
2007-11-18 10:18:56 +03:00
|
|
|
def test_ungetc
|
2017-02-07 15:49:57 +03:00
|
|
|
s = "".dup
|
2017-01-14 12:38:56 +03:00
|
|
|
w = Zlib::GzipWriter.new(StringIO.new(s))
|
2004-09-07 09:32:26 +04:00
|
|
|
w << (1...1000).to_a.inspect
|
|
|
|
w.close
|
2017-01-14 12:38:56 +03:00
|
|
|
r = Zlib::GzipReader.new(StringIO.new(s))
|
2004-09-07 09:32:26 +04:00
|
|
|
r.read(100)
|
|
|
|
r.ungetc ?a
|
2007-11-18 10:18:56 +03:00
|
|
|
assert_nothing_raised("[ruby-dev:24060]") {
|
2004-09-07 09:32:26 +04:00
|
|
|
r.read(100)
|
|
|
|
r.read
|
|
|
|
r.close
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2007-11-18 10:18:56 +03:00
|
|
|
def test_ungetc_paragraph
|
2017-02-07 15:49:57 +03:00
|
|
|
s = "".dup
|
2017-01-14 12:38:56 +03:00
|
|
|
w = Zlib::GzipWriter.new(StringIO.new(s))
|
2004-09-07 09:32:26 +04:00
|
|
|
w << "abc"
|
|
|
|
w.close
|
2017-01-14 12:38:56 +03:00
|
|
|
r = Zlib::GzipReader.new(StringIO.new(s))
|
2004-09-07 11:11:06 +04:00
|
|
|
r.ungetc ?\n
|
|
|
|
assert_equal("abc", r.gets(""))
|
2007-11-18 10:18:56 +03:00
|
|
|
assert_nothing_raised("[ruby-dev:24065]") {
|
2004-09-07 11:11:06 +04:00
|
|
|
r.read
|
|
|
|
r.close
|
|
|
|
}
|
2004-09-07 09:32:26 +04:00
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
|
2017-07-14 12:17:55 +03:00
|
|
|
def test_ungetc_at_start_of_file
|
|
|
|
s = "".dup
|
|
|
|
w = Zlib::GzipWriter.new(StringIO.new(s))
|
|
|
|
w << "abc"
|
|
|
|
w.close
|
|
|
|
r = Zlib::GzipReader.new(StringIO.new(s))
|
|
|
|
|
|
|
|
r.ungetc ?!
|
|
|
|
|
|
|
|
assert_equal(-1, r.pos, "[ruby-core:81488][Bug #13616]")
|
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_open
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_open") {|t|
|
|
|
|
t.close
|
|
|
|
e = assert_raise(Zlib::GzipFile::Error) {
|
|
|
|
Zlib::GzipReader.open(t.path)
|
|
|
|
}
|
|
|
|
assert_equal("not in gzip format", e.message)
|
|
|
|
assert_nil(e.input)
|
|
|
|
open(t.path, "wb") {|f| f.write("foo")}
|
|
|
|
e = assert_raise(Zlib::GzipFile::Error) {
|
|
|
|
Zlib::GzipReader.open(t.path)
|
|
|
|
}
|
|
|
|
assert_equal("not in gzip format", e.message)
|
|
|
|
assert_equal("foo", e.input)
|
|
|
|
open(t.path, "wb") {|f| f.write("foobarzothoge")}
|
|
|
|
e = assert_raise(Zlib::GzipFile::Error) {
|
|
|
|
Zlib::GzipReader.open(t.path)
|
|
|
|
}
|
|
|
|
assert_equal("not in gzip format", e.message)
|
|
|
|
assert_equal("foobarzothoge", e.input)
|
|
|
|
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
|
|
|
|
|
|
|
assert_raise(ArgumentError) { Zlib::GzipReader.open }
|
|
|
|
|
|
|
|
assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
|
|
|
|
|
|
|
f = Zlib::GzipReader.open(t.path)
|
|
|
|
begin
|
|
|
|
assert_equal("foo", f.read)
|
|
|
|
ensure
|
|
|
|
f.close
|
|
|
|
end
|
2010-07-07 06:44:04 +04:00
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rewind
|
2013-06-01 03:00:48 +04:00
|
|
|
bug8467 = '[ruby-core:55220] [Bug #8467]'
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_rewind") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal("foo", f.read)
|
|
|
|
f.rewind
|
|
|
|
assert_equal("foo", f.read)
|
2014-08-31 03:53:28 +04:00
|
|
|
|
|
|
|
f.rewind
|
|
|
|
bytes = []
|
|
|
|
f.each_byte { |b| bytes << b }
|
|
|
|
assert_equal "foo".bytes.to_a, bytes, '[Bug #10101]'
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
end
|
2013-06-01 03:00:48 +04:00
|
|
|
open(t.path, "rb") do |f|
|
|
|
|
gz = Zlib::GzipReader.new(f)
|
|
|
|
gz.rewind
|
|
|
|
assert_equal(["foo"], gz.to_a, bug8467)
|
|
|
|
end
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_unused
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_unused") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal(nil, f.unused)
|
|
|
|
assert_equal("foo", f.read(3))
|
|
|
|
assert_equal(nil, f.unused)
|
|
|
|
assert_equal("bar", f.read)
|
|
|
|
assert_equal(nil, f.unused)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
2011-02-03 12:56:52 +03:00
|
|
|
def test_unused2
|
2023-09-29 12:29:32 +03:00
|
|
|
zio = StringIO.new
|
2011-02-03 12:56:52 +03:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
io = Zlib::GzipWriter.new zio
|
|
|
|
io.write 'aaaa'
|
|
|
|
io.finish
|
2011-02-03 12:56:52 +03:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
io = Zlib::GzipWriter.new zio
|
|
|
|
io.write 'bbbb'
|
|
|
|
io.finish
|
2011-02-03 12:56:52 +03:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
zio.rewind
|
2011-02-03 12:56:52 +03:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
io = Zlib::GzipReader.new zio
|
|
|
|
assert_equal('aaaa', io.read)
|
|
|
|
unused = io.unused
|
|
|
|
assert_equal(24, unused.bytesize)
|
|
|
|
io.finish
|
2011-02-03 12:56:52 +03:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
zio.pos -= unused.length
|
2011-02-03 12:56:52 +03:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
io = Zlib::GzipReader.new zio
|
|
|
|
assert_equal('bbbb', io.read)
|
|
|
|
assert_equal(nil, io.unused)
|
|
|
|
io.finish
|
2011-02-03 12:56:52 +03:00
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_read
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_read") {|t|
|
|
|
|
t.close
|
|
|
|
str = "\u3042\u3044\u3046"
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print(str) }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path, encoding: "UTF-8") do |f|
|
|
|
|
assert_raise(ArgumentError) { f.read(-1) }
|
|
|
|
assert_equal(str, f.read)
|
|
|
|
end
|
2023-12-21 05:30:06 +03:00
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
s = "".b
|
|
|
|
|
|
|
|
assert_raise(ArgumentError) { f.read(-1, s) }
|
|
|
|
|
|
|
|
assert_same s, f.read(1, s)
|
|
|
|
assert_equal "\xE3".b, s
|
|
|
|
|
|
|
|
assert_same s, f.read(2, s)
|
|
|
|
assert_equal "\x81\x82".b, s
|
|
|
|
|
|
|
|
assert_same s, f.read(6, s)
|
|
|
|
assert_equal "\u3044\u3046".b, s
|
|
|
|
|
|
|
|
assert_nil f.read(1, s)
|
|
|
|
assert_equal "".b, s
|
|
|
|
assert_predicate f, :eof?
|
|
|
|
end
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_readpartial
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_readpartial") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert("foo".start_with?(f.readpartial(3)))
|
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
2017-02-07 15:49:57 +03:00
|
|
|
s = "".dup
|
2023-12-21 05:30:06 +03:00
|
|
|
assert_same s, f.readpartial(3, s)
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
assert("foo".start_with?(s))
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
assert_raise(ArgumentError) { f.readpartial(-1) }
|
2023-12-21 05:30:06 +03:00
|
|
|
|
|
|
|
assert_same s, f.readpartial(3, s)
|
|
|
|
|
|
|
|
assert_predicate f, :eof?
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_getc
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_getc") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
"foobar".each_char {|c| assert_equal(c, f.getc) }
|
|
|
|
assert_nil(f.getc)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
2008-10-21 13:18:34 +04:00
|
|
|
def test_getbyte
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_getbyte") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
2008-10-21 13:18:34 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
"foobar".each_byte {|c| assert_equal(c, f.getbyte) }
|
|
|
|
assert_nil(f.getbyte)
|
|
|
|
end
|
|
|
|
}
|
2008-10-21 13:18:34 +04:00
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_readchar
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_readchar") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
"foobar".each_byte {|c| assert_equal(c, f.readchar.ord) }
|
|
|
|
assert_raise(EOFError) { f.readchar }
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_each_byte
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_each_byte") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foobar") }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
a = []
|
|
|
|
f.each_byte {|c| a << c }
|
|
|
|
assert_equal("foobar".each_byte.to_a, a)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
2010-12-25 04:54:28 +03:00
|
|
|
def test_gets
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_gets") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal("foo\n", f.gets)
|
|
|
|
assert_equal("bar\n", f.gets)
|
|
|
|
assert_equal("baz\n", f.gets)
|
|
|
|
assert_nil(f.gets)
|
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal("foo\nbar\nbaz\n", f.gets(nil))
|
|
|
|
end
|
2010-12-25 05:02:55 +03:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal("foo\n", f.gets(10))
|
|
|
|
assert_equal("ba", f.gets(2))
|
|
|
|
assert_equal("r\nb", f.gets(nil, 3))
|
|
|
|
assert_equal("az\n", f.gets(nil, 10))
|
|
|
|
assert_nil(f.gets)
|
|
|
|
end
|
|
|
|
}
|
2010-12-25 05:02:55 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_gets2
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_gets2") {|t|
|
|
|
|
t.close
|
|
|
|
ustrs = %W"\u{3042 3044 3046}\n \u{304b 304d 304f}\n \u{3055 3057 3059}\n"
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print(*ustrs) }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path, encoding: "UTF-8") do |f|
|
|
|
|
assert_equal(ustrs[0], f.gets)
|
|
|
|
assert_equal(ustrs[1], f.gets)
|
|
|
|
assert_equal(ustrs[2], f.gets)
|
|
|
|
assert_nil(f.gets)
|
|
|
|
end
|
2010-12-25 05:02:55 +03:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path, encoding: "UTF-8") do |f|
|
|
|
|
assert_equal(ustrs.join(''), f.gets(nil))
|
|
|
|
end
|
2010-12-25 05:02:55 +03:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path, encoding: "UTF-8") do |f|
|
|
|
|
assert_equal(ustrs[0], f.gets(20))
|
|
|
|
assert_equal(ustrs[1][0,2], f.gets(5))
|
|
|
|
assert_equal(ustrs[1][2..-1]+ustrs[2][0,1], f.gets(nil, 5))
|
|
|
|
assert_equal(ustrs[2][1..-1], f.gets(nil, 20))
|
|
|
|
assert_nil(f.gets)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
2010-12-25 04:54:28 +03:00
|
|
|
def test_readline
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_readline") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal("foo\n", f.readline)
|
|
|
|
assert_equal("bar\n", f.readline)
|
|
|
|
assert_equal("baz\n", f.readline)
|
|
|
|
assert_raise(EOFError) { f.readline }
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_each
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_each") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
a = ["foo\n", "bar\n", "baz\n"]
|
|
|
|
f.each {|l| assert_equal(a.shift, l) }
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_readlines
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_readlines") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo\nbar\nbaz\n") }
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
assert_equal(["foo\n", "bar\n", "baz\n"], f.readlines)
|
|
|
|
end
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_reader_wrap
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_wrap") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
|
|
|
f = open(t.path)
|
|
|
|
f.binmode
|
|
|
|
assert_equal("foo", Zlib::GzipReader.wrap(f) {|gz| gz.read })
|
2015-01-15 18:26:03 +03:00
|
|
|
assert(f.closed?)
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
2011-08-23 06:36:13 +04:00
|
|
|
|
|
|
|
def test_corrupted_header
|
2017-02-07 15:49:57 +03:00
|
|
|
gz = Zlib::GzipWriter.new(StringIO.new(s = "".dup))
|
2011-08-23 06:36:13 +04:00
|
|
|
gz.orig_name = "X"
|
|
|
|
gz.comment = "Y"
|
|
|
|
gz.print("foo")
|
|
|
|
gz.finish
|
|
|
|
# 14: magic(2) + method(1) + flag(1) + mtime(4) + exflag(1) + os(1) + orig_name(2) + comment(2)
|
|
|
|
1.upto(14) do |idx|
|
|
|
|
assert_raise(Zlib::GzipFile::Error, idx) do
|
|
|
|
Zlib::GzipReader.new(StringIO.new(s[0, idx])).read
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-02-24 13:25:14 +04:00
|
|
|
|
|
|
|
def test_encoding
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_reader_encoding") {|t|
|
|
|
|
t.binmode
|
|
|
|
content = (0..255).to_a.pack('c*')
|
|
|
|
Zlib::GzipWriter.wrap(t) {|gz| gz.print(content) }
|
|
|
|
|
2015-05-10 06:43:22 +03:00
|
|
|
read_all = Zlib::GzipReader.open(t.path) do |gz|
|
|
|
|
assert_equal(Encoding.default_external, gz.external_encoding)
|
|
|
|
gz.read
|
|
|
|
end
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
assert_equal(Encoding.default_external, read_all.encoding)
|
|
|
|
|
|
|
|
# chunks are in BINARY regardless of encoding settings
|
|
|
|
read_size = Zlib::GzipReader.open(t.path) {|gz| gz.read(1024) }
|
|
|
|
assert_equal(Encoding::ASCII_8BIT, read_size.encoding)
|
|
|
|
assert_equal(content, read_size)
|
|
|
|
}
|
2012-02-24 13:25:14 +04:00
|
|
|
end
|
2015-03-08 16:52:51 +03:00
|
|
|
|
|
|
|
def test_double_close
|
|
|
|
Tempfile.create("test_zlib_gzip_reader_close") {|t|
|
|
|
|
t.binmode
|
|
|
|
content = "foo"
|
|
|
|
Zlib::GzipWriter.wrap(t) {|gz| gz.print(content) }
|
|
|
|
r = Zlib::GzipReader.open(t.path)
|
|
|
|
assert_equal(content, r.read)
|
|
|
|
assert_nothing_raised { r.close }
|
|
|
|
assert_nothing_raised { r.close }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-12-22 01:11:02 +03:00
|
|
|
# Various methods of Zlib::GzipReader failed when to reading files
|
|
|
|
# just a few bytes larger than GZFILE_READ_SIZE.
|
|
|
|
def test_gzfile_read_size_boundary
|
|
|
|
Tempfile.create("test_zlib_gzip_read_size_boundary") {|t|
|
|
|
|
t.close
|
|
|
|
# NO_COMPRESSION helps with recreating the error condition.
|
|
|
|
# The error happens on compressed files too, but it's harder to reproduce.
|
|
|
|
# For example, ~12750 bytes are needed to trigger the error using __FILE__.
|
|
|
|
# We avoid this because the test file will change over time.
|
|
|
|
Zlib::GzipWriter.open(t.path, Zlib::NO_COMPRESSION) do |gz|
|
|
|
|
gz.print("\n" * 2024) # range from 2024 to 2033 triggers the error
|
|
|
|
gz.flush
|
|
|
|
end
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
f.readpartial(1024) until f.eof?
|
|
|
|
assert_raise(EOFError) { f.readpartial(1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
f.readline until f.eof?
|
|
|
|
assert_raise(EOFError) { f.readline }
|
|
|
|
end
|
|
|
|
|
|
|
|
Zlib::GzipReader.open(t.path) do |f|
|
|
|
|
b = f.readbyte until f.eof?
|
|
|
|
f.ungetbyte(b)
|
|
|
|
f.readbyte
|
|
|
|
assert_raise(EOFError) { f.readbyte }
|
|
|
|
end
|
|
|
|
}
|
|
|
|
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
|
2007-11-18 10:18:56 +03: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-06 06:59:13 +04:00
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
|
|
|
|
def test_open
|
|
|
|
assert_raise(ArgumentError) { Zlib::GzipWriter.open }
|
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_writer_open") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
|
|
|
assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
f = Zlib::GzipWriter.open(t.path)
|
|
|
|
begin
|
|
|
|
f.print("bar")
|
|
|
|
ensure
|
|
|
|
f.close
|
|
|
|
end
|
|
|
|
assert_equal("bar", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
assert_raise(Zlib::StreamError) { Zlib::GzipWriter.open(t.path, 10000) }
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_write
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_writer_write") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print("foo") }
|
|
|
|
assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
|
|
|
|
|
|
|
o = Object.new
|
|
|
|
def o.to_s; "bar"; end
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.print(o) }
|
|
|
|
assert_equal("bar", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_putc
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_writer_putc") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.putc(?x) }
|
|
|
|
assert_equal("x", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
2008-06-08 16:51:25 +04:00
|
|
|
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
# todo: multibyte char
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
2017-10-23 10:06:12 +03:00
|
|
|
def test_puts
|
|
|
|
Tempfile.create("test_zlib_gzip_writer_puts") {|t|
|
|
|
|
t.close
|
|
|
|
Zlib::GzipWriter.open(t.path) {|gz| gz.puts("foo") }
|
|
|
|
assert_equal("foo\n", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_writer_wrap
|
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb,
test/openssl/test_config.rb, test/psych/test_encoding.rb,
test/psych/test_exception.rb, test/psych/test_psych.rb,
test/psych/test_tainted.rb, test/readline/test_readline.rb,
test/rexml/test_contrib.rb, test/ruby/test_autoload.rb,
test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb,
test/ruby/test_file.rb, test/ruby/test_io.rb,
test/ruby/test_marshal.rb, test/ruby/test_process.rb,
test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb,
test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb,
test/zlib/test_zlib.rb: Use Tempfile.create.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-21 03:03:52 +04:00
|
|
|
Tempfile.create("test_zlib_gzip_writer_wrap") {|t|
|
|
|
|
t.binmode
|
|
|
|
Zlib::GzipWriter.wrap(t) {|gz| gz.print("foo") }
|
|
|
|
assert_equal("foo", Zlib::GzipReader.open(t.path) {|gz| gz.read })
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
2015-03-08 16:52:51 +03:00
|
|
|
|
|
|
|
def test_double_close
|
|
|
|
Tempfile.create("test_zlib_gzip_reader_close") {|t|
|
|
|
|
t.binmode
|
|
|
|
w = Zlib::GzipWriter.wrap(t)
|
|
|
|
assert_nothing_raised { w.close }
|
|
|
|
assert_nothing_raised { w.close }
|
|
|
|
}
|
|
|
|
end
|
2018-12-07 10:09:31 +03:00
|
|
|
|
|
|
|
def test_zlib_writer_buffered_write
|
|
|
|
bug15356 = '[ruby-core:90346] [Bug #15356]'.freeze
|
|
|
|
fixes = 'r61631 (commit a55abcc0ca6f628fc05304f81e5a044d65ab4a68)'.freeze
|
|
|
|
ary = []
|
|
|
|
def ary.write(*args)
|
|
|
|
self.concat(args)
|
|
|
|
end
|
|
|
|
gz = Zlib::GzipWriter.new(ary)
|
|
|
|
gz.write(bug15356)
|
|
|
|
gz.write("\n")
|
|
|
|
gz.write(fixes)
|
|
|
|
gz.close
|
|
|
|
assert_not_predicate ary, :empty?
|
|
|
|
exp = [ bug15356, fixes ]
|
|
|
|
assert_equal exp, Zlib.gunzip(ary.join('')).split("\n")
|
|
|
|
end
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
class TestZlib < Test::Unit::TestCase
|
|
|
|
def test_version
|
|
|
|
assert_instance_of(String, Zlib.zlib_version)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_adler32
|
|
|
|
assert_equal(0x00000001, Zlib.adler32)
|
|
|
|
assert_equal(0x02820145, Zlib.adler32("foo"))
|
|
|
|
assert_equal(0x02820145, Zlib.adler32("o", Zlib.adler32("fo")))
|
|
|
|
assert_equal(0x8a62c964, Zlib.adler32("abc\x01\x02\x03" * 10000))
|
2022-04-02 10:06:11 +03:00
|
|
|
assert_equal(0x97d1a9f7, Zlib.adler32("p", -305419897))
|
2020-10-28 20:58:28 +03:00
|
|
|
Tempfile.create("test_zlib_gzip_file_to_io") {|t|
|
|
|
|
File.binwrite(t.path, "foo")
|
|
|
|
t.rewind
|
|
|
|
assert_equal(0x02820145, Zlib.adler32(t))
|
|
|
|
|
|
|
|
t.rewind
|
|
|
|
crc = Zlib.adler32(t.read(2))
|
|
|
|
assert_equal(0x02820145, Zlib.adler32(t, crc))
|
|
|
|
|
|
|
|
File.binwrite(t.path, "abc\x01\x02\x03" * 10000)
|
|
|
|
t.rewind
|
|
|
|
assert_equal(0x8a62c964, Zlib.adler32(t))
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
2010-01-19 03:06:04 +03:00
|
|
|
def test_adler32_combine
|
|
|
|
one = Zlib.adler32("fo")
|
|
|
|
two = Zlib.adler32("o")
|
2010-05-19 06:42:57 +04:00
|
|
|
begin
|
|
|
|
assert_equal(0x02820145, Zlib.adler32_combine(one, two, 1))
|
|
|
|
rescue NotImplementedError
|
2022-01-11 15:26:49 +03:00
|
|
|
omit "adler32_combine is not implemented"
|
2021-09-06 12:34:15 +03:00
|
|
|
rescue Test::Unit::AssertionFailedError
|
2016-03-05 01:20:56 +03:00
|
|
|
if /aix/ =~ RUBY_PLATFORM
|
2022-01-11 15:26:49 +03:00
|
|
|
omit "zconf.h in zlib does not handle _LARGE_FILES in AIX. Skip until it is fixed"
|
2016-03-05 01:20:56 +03:00
|
|
|
end
|
|
|
|
raise $!
|
2010-05-19 06:42:57 +04:00
|
|
|
end
|
2010-01-19 03:06:04 +03:00
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_crc32
|
|
|
|
assert_equal(0x00000000, Zlib.crc32)
|
|
|
|
assert_equal(0x8c736521, Zlib.crc32("foo"))
|
|
|
|
assert_equal(0x8c736521, Zlib.crc32("o", Zlib.crc32("fo")))
|
|
|
|
assert_equal(0x07f0d68f, Zlib.crc32("abc\x01\x02\x03" * 10000))
|
2022-04-02 10:06:11 +03:00
|
|
|
assert_equal(0xf136439b, Zlib.crc32("p", -305419897))
|
2020-10-28 20:58:28 +03:00
|
|
|
Tempfile.create("test_zlib_gzip_file_to_io") {|t|
|
|
|
|
File.binwrite(t.path, "foo")
|
|
|
|
t.rewind
|
|
|
|
assert_equal(0x8c736521, Zlib.crc32(t))
|
|
|
|
|
|
|
|
t.rewind
|
|
|
|
crc = Zlib.crc32(t.read(2))
|
|
|
|
assert_equal(0x8c736521, Zlib.crc32(t, crc))
|
|
|
|
|
|
|
|
File.binwrite(t.path, "abc\x01\x02\x03" * 10000)
|
|
|
|
t.rewind
|
|
|
|
assert_equal(0x07f0d68f, Zlib.crc32(t))
|
|
|
|
}
|
2008-06-08 16:51:25 +04:00
|
|
|
end
|
|
|
|
|
2010-01-19 03:06:04 +03:00
|
|
|
def test_crc32_combine
|
|
|
|
one = Zlib.crc32("fo")
|
|
|
|
two = Zlib.crc32("o")
|
2010-05-19 06:42:57 +04:00
|
|
|
begin
|
|
|
|
assert_equal(0x8c736521, Zlib.crc32_combine(one, two, 1))
|
|
|
|
rescue NotImplementedError
|
2022-01-11 15:26:49 +03:00
|
|
|
omit "crc32_combine is not implemented"
|
2021-09-06 12:34:15 +03:00
|
|
|
rescue Test::Unit::AssertionFailedError
|
2016-03-05 01:20:56 +03:00
|
|
|
if /aix/ =~ RUBY_PLATFORM
|
2022-01-11 15:26:49 +03:00
|
|
|
omit "zconf.h in zlib does not handle _LARGE_FILES in AIX. Skip until it is fixed"
|
2016-03-05 01:20:56 +03:00
|
|
|
end
|
|
|
|
raise $!
|
2010-05-19 06:42:57 +04:00
|
|
|
end
|
2010-01-19 03:06:04 +03:00
|
|
|
end
|
|
|
|
|
2008-06-08 16:51:25 +04:00
|
|
|
def test_crc_table
|
|
|
|
t = Zlib.crc_table
|
|
|
|
assert_instance_of(Array, t)
|
|
|
|
t.each {|x| assert_kind_of(Integer, x) }
|
|
|
|
end
|
2012-05-04 21:07:18 +04:00
|
|
|
|
|
|
|
def test_inflate
|
2021-02-02 14:59:04 +03:00
|
|
|
s = Zlib::Deflate.deflate("foo")
|
|
|
|
z = Zlib::Inflate.new
|
|
|
|
s = z.inflate(s)
|
|
|
|
s << z.inflate(nil)
|
|
|
|
assert_equal("foo", s)
|
|
|
|
z.inflate("foo") # ???
|
|
|
|
z << "foo" # ???
|
2012-05-04 21:07:18 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_deflate
|
2021-02-02 14:59:04 +03:00
|
|
|
s = Zlib::Deflate.deflate("foo")
|
|
|
|
assert_equal("foo", Zlib::Inflate.inflate(s))
|
|
|
|
|
|
|
|
assert_raise(Zlib::StreamError) { Zlib::Deflate.deflate("foo", 10000) }
|
2012-05-04 21:07:18 +04:00
|
|
|
end
|
2012-07-10 22:28:40 +04:00
|
|
|
|
|
|
|
def test_deflate_stream
|
2023-09-29 12:29:32 +03:00
|
|
|
r = Random.new 0
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
deflated = ''.dup
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
Zlib.deflate(r.bytes(20000)) do |chunk|
|
|
|
|
deflated << chunk
|
|
|
|
end
|
2012-07-10 22:28:40 +04:00
|
|
|
|
2023-09-29 12:29:32 +03:00
|
|
|
assert_equal 20016, deflated.length
|
2012-07-10 22:28:40 +04:00
|
|
|
end
|
|
|
|
|
2016-12-10 01:45:39 +03:00
|
|
|
def test_gzip
|
2023-09-29 12:29:32 +03:00
|
|
|
actual = Zlib.gzip("foo".freeze)
|
|
|
|
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
|
|
|
actual[9] = "\xff" # replace OS
|
|
|
|
expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*")
|
|
|
|
assert_equal expected, actual
|
2016-12-10 01:45:39 +03:00
|
|
|
|
2016-12-20 19:02:21 +03:00
|
|
|
actual = Zlib.gzip("foo".freeze, level: 0)
|
2016-12-10 01:45:39 +03:00
|
|
|
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
|
|
|
actual[9] = "\xff" # replace OS
|
|
|
|
expected = %w[1f8b08000000000000ff010300fcff666f6f2165738c03000000].pack("H*")
|
|
|
|
assert_equal expected, actual
|
|
|
|
|
2016-12-20 19:02:21 +03:00
|
|
|
actual = Zlib.gzip("foo".freeze, level: 9)
|
2016-12-10 01:45:39 +03:00
|
|
|
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
|
|
|
actual[9] = "\xff" # replace OS
|
|
|
|
expected = %w[1f8b08000000000002ff4bcbcf07002165738c03000000].pack("H*")
|
|
|
|
assert_equal expected, actual
|
|
|
|
|
2016-12-20 19:02:21 +03:00
|
|
|
actual = Zlib.gzip("foo".freeze, level: 9, strategy: Zlib::FILTERED)
|
2016-12-10 01:45:39 +03:00
|
|
|
actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
|
|
|
actual[9] = "\xff" # replace OS
|
|
|
|
expected = %w[1f8b08000000000002ff4bcbcf07002165738c03000000].pack("H*")
|
|
|
|
assert_equal expected, actual
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gunzip
|
|
|
|
src = %w[1f8b08000000000000034bcbcf07002165738c03000000].pack("H*")
|
2016-12-10 11:26:40 +03:00
|
|
|
assert_equal 'foo', Zlib.gunzip(src.freeze)
|
2016-12-10 01:45:39 +03:00
|
|
|
|
|
|
|
src = %w[1f8b08000000000000034bcbcf07002165738c03000001].pack("H*")
|
|
|
|
assert_raise(Zlib::GzipFile::LengthError){ Zlib.gunzip(src) }
|
|
|
|
|
|
|
|
src = %w[1f8b08000000000000034bcbcf07002165738d03000000].pack("H*")
|
|
|
|
assert_raise(Zlib::GzipFile::CRCError){ Zlib.gunzip(src) }
|
|
|
|
|
|
|
|
src = %w[1f8b08000000000000034bcbcf07002165738d030000].pack("H*")
|
|
|
|
assert_raise(Zlib::GzipFile::Error){ Zlib.gunzip(src) }
|
|
|
|
|
|
|
|
src = %w[1f8b08000000000000034bcbcf0700].pack("H*")
|
|
|
|
assert_raise(Zlib::GzipFile::NoFooter){ Zlib.gunzip(src) }
|
|
|
|
|
|
|
|
src = %w[1f8b080000000000000].pack("H*")
|
|
|
|
assert_raise(Zlib::GzipFile::Error){ Zlib.gunzip(src) }
|
|
|
|
end
|
2017-10-06 16:41:37 +03:00
|
|
|
|
2023-08-10 23:12:06 +03:00
|
|
|
# Zlib.gunzip input is always considered a binary string, regardless of its String#encoding.
|
|
|
|
def test_gunzip_encoding
|
|
|
|
# vvvvvvvv = mtime, but valid UTF-8 string of U+0080
|
|
|
|
src = %w[1f8b0800c28000000003cb48cdc9c9070086a6103605000000].pack("H*").force_encoding('UTF-8')
|
|
|
|
assert_equal 'hello', Zlib.gunzip(src.freeze)
|
|
|
|
end
|
|
|
|
|
2017-10-06 16:41:37 +03:00
|
|
|
def test_gunzip_no_memory_leak
|
|
|
|
assert_no_memory_leak(%[-rzlib], "#{<<~"{#"}", "#{<<~'};'}")
|
|
|
|
d = Zlib.gzip("data")
|
|
|
|
{#
|
|
|
|
10_000.times {Zlib.gunzip(d)}
|
|
|
|
};
|
|
|
|
end
|
2004-04-05 17:27:45 +04:00
|
|
|
end
|
|
|
|
end
|