|
12 | 12 | end
|
13 | 13 |
|
14 | 14 | if defined? Zlib
|
15 |
| - class TestZlibDeflate < Test::Unit::TestCase |
| 15 | + class Zlib::TestCase < Test::Unit::TestCase |
| 16 | + def child_env |
| 17 | + return @child_env unless @child_env.nil? |
| 18 | + |
| 19 | + child_env = {} |
| 20 | + child_env['DFLTCC'] = '0' if RUBY_PLATFORM =~ /s390x/ |
| 21 | + @child_env = child_env |
| 22 | + @child_env |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + class TestZlibDeflate < Zlib::TestCase |
16 | 27 | def test_initialize
|
17 | 28 | z = Zlib::Deflate.new
|
18 | 29 | s = z.deflate("foo", Zlib::FINISH)
|
@@ -44,59 +55,63 @@ def test_deflate
|
44 | 55 | end
|
45 | 56 |
|
46 | 57 | def test_deflate_chunked
|
47 |
| - original = ''.dup |
48 |
| - chunks = [] |
49 |
| - r = Random.new 0 |
50 |
| - |
51 |
| - z = Zlib::Deflate.new |
52 |
| - |
53 |
| - 2.times do |
54 |
| - input = r.bytes(20000) |
55 |
| - original << input |
56 |
| - z.deflate(input) do |chunk| |
57 |
| - chunks << chunk |
| 58 | + assert_separately([child_env, '-rzlib'], <<~'end;') |
| 59 | + original = ''.dup |
| 60 | + chunks = [] |
| 61 | + r = Random.new 0 |
| 62 | +
|
| 63 | + z = Zlib::Deflate.new |
| 64 | +
|
| 65 | + 2.times do |
| 66 | + input = r.bytes(20000) |
| 67 | + original << input |
| 68 | + z.deflate(input) do |chunk| |
| 69 | + chunks << chunk |
| 70 | + end |
58 | 71 | end
|
59 |
| - end |
60 | 72 |
|
61 |
| - assert_equal [16384, 16384], |
62 |
| - chunks.map { |chunk| chunk.length } |
| 73 | + assert_equal [16384, 16384], |
| 74 | + chunks.map { |chunk| chunk.length } |
63 | 75 |
|
64 |
| - final = z.finish |
| 76 | + final = z.finish |
65 | 77 |
|
66 |
| - assert_equal 7253, final.length |
| 78 | + assert_equal 7253, final.length |
67 | 79 |
|
68 |
| - chunks << final |
69 |
| - all = chunks.join |
| 80 | + chunks << final |
| 81 | + all = chunks.join |
70 | 82 |
|
71 |
| - inflated = Zlib.inflate all |
| 83 | + inflated = Zlib.inflate all |
72 | 84 |
|
73 |
| - assert_equal original, inflated |
| 85 | + assert_equal original, inflated |
| 86 | + end; |
74 | 87 | end
|
75 | 88 |
|
76 | 89 | def test_deflate_chunked_break
|
77 |
| - chunks = [] |
78 |
| - r = Random.new 0 |
| 90 | + assert_separately([child_env, '-rzlib'], <<~'end;') |
| 91 | + chunks = [] |
| 92 | + r = Random.new 0 |
79 | 93 |
|
80 |
| - z = Zlib::Deflate.new |
| 94 | + z = Zlib::Deflate.new |
81 | 95 |
|
82 |
| - input = r.bytes(20000) |
83 |
| - z.deflate(input) do |chunk| |
84 |
| - chunks << chunk |
85 |
| - break |
86 |
| - end |
| 96 | + input = r.bytes(20000) |
| 97 | + z.deflate(input) do |chunk| |
| 98 | + chunks << chunk |
| 99 | + break |
| 100 | + end |
87 | 101 |
|
88 |
| - assert_equal [16384], chunks.map { |chunk| chunk.length } |
| 102 | + assert_equal [16384], chunks.map { |chunk| chunk.length } |
89 | 103 |
|
90 |
| - final = z.finish |
| 104 | + final = z.finish |
91 | 105 |
|
92 |
| - assert_equal 3632, final.length |
| 106 | + assert_equal 3632, final.length |
93 | 107 |
|
94 |
| - all = chunks.join |
95 |
| - all << final |
| 108 | + all = chunks.join |
| 109 | + all << final |
96 | 110 |
|
97 |
| - original = Zlib.inflate all |
| 111 | + original = Zlib.inflate all |
98 | 112 |
|
99 |
| - assert_equal input, original |
| 113 | + assert_equal input, original |
| 114 | + end; |
100 | 115 | end
|
101 | 116 |
|
102 | 117 | def test_addstr
|
@@ -247,7 +262,7 @@ def test_close
|
247 | 262 | end
|
248 | 263 | end
|
249 | 264 |
|
250 |
| - class TestZlibInflate < Test::Unit::TestCase |
| 265 | + class TestZlibInflate < Zlib::TestCase |
251 | 266 | def test_class_inflate_dictionary
|
252 | 267 | assert_raise(Zlib::NeedDict) do
|
253 | 268 | Zlib::Inflate.inflate([0x08,0x3C,0x0,0x0,0x0,0x0].pack("c*"))
|
@@ -574,7 +589,7 @@ def test_recursive_inflate
|
574 | 589 | end
|
575 | 590 | end
|
576 | 591 |
|
577 |
| - class TestZlibGzipFile < Test::Unit::TestCase |
| 592 | + class TestZlibGzipFile < Zlib::TestCase |
578 | 593 | def test_gzip_reader_zcat
|
579 | 594 | Tempfile.create("test_zlib_gzip_file_to_io") {|t|
|
580 | 595 | t.binmode
|
@@ -829,7 +844,7 @@ def test_path_tmpfile
|
829 | 844 | end
|
830 | 845 | end
|
831 | 846 |
|
832 |
| - class TestZlibGzipReader < Test::Unit::TestCase |
| 847 | + class TestZlibGzipReader < Zlib::TestCase |
833 | 848 | D0 = "\037\213\010\000S`\017A\000\003\003\000\000\000\000\000\000\000\000\000"
|
834 | 849 | def test_read0
|
835 | 850 | assert_equal("", Zlib::GzipReader.new(StringIO.new(D0)).read(0))
|
@@ -952,30 +967,32 @@ def test_unused
|
952 | 967 | end
|
953 | 968 |
|
954 | 969 | def test_unused2
|
955 |
| - zio = StringIO.new |
| 970 | + assert_separately([child_env, '-rzlib', '-rstringio'], <<~'end;') |
| 971 | + zio = StringIO.new |
956 | 972 |
|
957 |
| - io = Zlib::GzipWriter.new zio |
958 |
| - io.write 'aaaa' |
959 |
| - io.finish |
| 973 | + io = Zlib::GzipWriter.new zio |
| 974 | + io.write 'aaaa' |
| 975 | + io.finish |
960 | 976 |
|
961 |
| - io = Zlib::GzipWriter.new zio |
962 |
| - io.write 'bbbb' |
963 |
| - io.finish |
| 977 | + io = Zlib::GzipWriter.new zio |
| 978 | + io.write 'bbbb' |
| 979 | + io.finish |
964 | 980 |
|
965 |
| - zio.rewind |
| 981 | + zio.rewind |
966 | 982 |
|
967 |
| - io = Zlib::GzipReader.new zio |
968 |
| - assert_equal('aaaa', io.read) |
969 |
| - unused = io.unused |
970 |
| - assert_equal(24, unused.bytesize) |
971 |
| - io.finish |
| 983 | + io = Zlib::GzipReader.new zio |
| 984 | + assert_equal('aaaa', io.read) |
| 985 | + unused = io.unused |
| 986 | + assert_equal(24, unused.bytesize) |
| 987 | + io.finish |
972 | 988 |
|
973 |
| - zio.pos -= unused.length |
| 989 | + zio.pos -= unused.length |
974 | 990 |
|
975 |
| - io = Zlib::GzipReader.new zio |
976 |
| - assert_equal('bbbb', io.read) |
977 |
| - assert_equal(nil, io.unused) |
978 |
| - io.finish |
| 991 | + io = Zlib::GzipReader.new zio |
| 992 | + assert_equal('bbbb', io.read) |
| 993 | + assert_equal(nil, io.unused) |
| 994 | + io.finish |
| 995 | + end; |
979 | 996 | end
|
980 | 997 |
|
981 | 998 | def test_read
|
@@ -1207,7 +1224,7 @@ def test_double_close
|
1207 | 1224 |
|
1208 | 1225 | end
|
1209 | 1226 |
|
1210 |
| - class TestZlibGzipWriter < Test::Unit::TestCase |
| 1227 | + class TestZlibGzipWriter < Zlib::TestCase |
1211 | 1228 | def test_invalid_new
|
1212 | 1229 | assert_raise(NoMethodError, "[ruby-dev:23228]") { Zlib::GzipWriter.new(nil).close }
|
1213 | 1230 | assert_raise(NoMethodError, "[ruby-dev:23344]") { Zlib::GzipWriter.new(true).close }
|
@@ -1301,7 +1318,7 @@ def ary.write(*args)
|
1301 | 1318 | end
|
1302 | 1319 | end
|
1303 | 1320 |
|
1304 |
| - class TestZlib < Test::Unit::TestCase |
| 1321 | + class TestZlib < Zlib::TestCase |
1305 | 1322 | def test_version
|
1306 | 1323 | assert_instance_of(String, Zlib.zlib_version)
|
1307 | 1324 | end
|
@@ -1402,36 +1419,46 @@ def test_deflate
|
1402 | 1419 | end
|
1403 | 1420 |
|
1404 | 1421 | def test_deflate_stream
|
1405 |
| - r = Random.new 0 |
| 1422 | + assert_separately([child_env, '-rzlib'], <<~'end;') |
| 1423 | + r = Random.new 0 |
1406 | 1424 |
|
1407 |
| - deflated = ''.dup |
| 1425 | + deflated = ''.dup |
1408 | 1426 |
|
1409 |
| - Zlib.deflate(r.bytes(20000)) do |chunk| |
1410 |
| - deflated << chunk |
1411 |
| - end |
| 1427 | + Zlib.deflate(r.bytes(20000)) do |chunk| |
| 1428 | + deflated << chunk |
| 1429 | + end |
1412 | 1430 |
|
1413 |
| - assert_equal 20016, deflated.length |
| 1431 | + assert_equal 20016, deflated.length |
| 1432 | + end; |
1414 | 1433 | end
|
1415 | 1434 |
|
1416 | 1435 | def test_gzip
|
1417 |
| - actual = Zlib.gzip("foo".freeze) |
1418 |
| - actual[4, 4] = "\x00\x00\x00\x00" # replace mtime |
1419 |
| - actual[9] = "\xff" # replace OS |
1420 |
| - expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*") |
1421 |
| - assert_equal expected, actual |
| 1436 | + assert_separately([child_env, '-rzlib'], <<~'end;') |
| 1437 | + actual = Zlib.gzip("foo".freeze) |
| 1438 | + actual[4, 4] = "\x00\x00\x00\x00" # replace mtime |
| 1439 | + actual[9] = "\xff" # replace OS |
| 1440 | + expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*") |
| 1441 | + assert_equal expected, actual |
| 1442 | + end; |
| 1443 | + end |
1422 | 1444 |
|
| 1445 | + def test_gzip_level_0 |
1423 | 1446 | actual = Zlib.gzip("foo".freeze, level: 0)
|
1424 | 1447 | actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
1425 | 1448 | actual[9] = "\xff" # replace OS
|
1426 | 1449 | expected = %w[1f8b08000000000000ff010300fcff666f6f2165738c03000000].pack("H*")
|
1427 | 1450 | assert_equal expected, actual
|
| 1451 | + end |
1428 | 1452 |
|
| 1453 | + def test_gzip_level_9 |
1429 | 1454 | actual = Zlib.gzip("foo".freeze, level: 9)
|
1430 | 1455 | actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
1431 | 1456 | actual[9] = "\xff" # replace OS
|
1432 | 1457 | expected = %w[1f8b08000000000002ff4bcbcf07002165738c03000000].pack("H*")
|
1433 | 1458 | assert_equal expected, actual
|
| 1459 | + end |
1434 | 1460 |
|
| 1461 | + def test_gzip_level_9_filtered |
1435 | 1462 | actual = Zlib.gzip("foo".freeze, level: 9, strategy: Zlib::FILTERED)
|
1436 | 1463 | actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
1437 | 1464 | actual[9] = "\xff" # replace OS
|
|
0 commit comments