|
12 | 12 | end
|
13 | 13 |
|
14 | 14 | if defined? Zlib
|
| 15 | + child_env = {} |
| 16 | + child_env['DFLTCC'] = '0' if RUBY_PLATFORM =~ /s390x/ |
| 17 | + Zlib::CHILD_ENV = child_env.freeze |
| 18 | + |
15 | 19 | class TestZlibDeflate < Test::Unit::TestCase
|
16 | 20 | def test_initialize
|
17 | 21 | z = Zlib::Deflate.new
|
@@ -44,59 +48,63 @@ def test_deflate
|
44 | 48 | end
|
45 | 49 |
|
46 | 50 | 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 |
| 51 | + assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;') |
| 52 | + original = ''.dup |
| 53 | + chunks = [] |
| 54 | + r = Random.new 0 |
| 55 | +
|
| 56 | + z = Zlib::Deflate.new |
| 57 | +
|
| 58 | + 2.times do |
| 59 | + input = r.bytes(20000) |
| 60 | + original << input |
| 61 | + z.deflate(input) do |chunk| |
| 62 | + chunks << chunk |
| 63 | + end |
58 | 64 | end
|
59 |
| - end |
60 | 65 |
|
61 |
| - assert_equal [16384, 16384], |
62 |
| - chunks.map { |chunk| chunk.length } |
| 66 | + assert_equal [16384, 16384], |
| 67 | + chunks.map { |chunk| chunk.length } |
63 | 68 |
|
64 |
| - final = z.finish |
| 69 | + final = z.finish |
65 | 70 |
|
66 |
| - assert_equal 7253, final.length |
| 71 | + assert_equal 7253, final.length |
67 | 72 |
|
68 |
| - chunks << final |
69 |
| - all = chunks.join |
| 73 | + chunks << final |
| 74 | + all = chunks.join |
70 | 75 |
|
71 |
| - inflated = Zlib.inflate all |
| 76 | + inflated = Zlib.inflate all |
72 | 77 |
|
73 |
| - assert_equal original, inflated |
| 78 | + assert_equal original, inflated |
| 79 | + end; |
74 | 80 | end
|
75 | 81 |
|
76 | 82 | def test_deflate_chunked_break
|
77 |
| - chunks = [] |
78 |
| - r = Random.new 0 |
| 83 | + assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;') |
| 84 | + chunks = [] |
| 85 | + r = Random.new 0 |
79 | 86 |
|
80 |
| - z = Zlib::Deflate.new |
| 87 | + z = Zlib::Deflate.new |
81 | 88 |
|
82 |
| - input = r.bytes(20000) |
83 |
| - z.deflate(input) do |chunk| |
84 |
| - chunks << chunk |
85 |
| - break |
86 |
| - end |
| 89 | + input = r.bytes(20000) |
| 90 | + z.deflate(input) do |chunk| |
| 91 | + chunks << chunk |
| 92 | + break |
| 93 | + end |
87 | 94 |
|
88 |
| - assert_equal [16384], chunks.map { |chunk| chunk.length } |
| 95 | + assert_equal [16384], chunks.map { |chunk| chunk.length } |
89 | 96 |
|
90 |
| - final = z.finish |
| 97 | + final = z.finish |
91 | 98 |
|
92 |
| - assert_equal 3632, final.length |
| 99 | + assert_equal 3632, final.length |
93 | 100 |
|
94 |
| - all = chunks.join |
95 |
| - all << final |
| 101 | + all = chunks.join |
| 102 | + all << final |
96 | 103 |
|
97 |
| - original = Zlib.inflate all |
| 104 | + original = Zlib.inflate all |
98 | 105 |
|
99 |
| - assert_equal input, original |
| 106 | + assert_equal input, original |
| 107 | + end; |
100 | 108 | end
|
101 | 109 |
|
102 | 110 | def test_addstr
|
@@ -952,30 +960,32 @@ def test_unused
|
952 | 960 | end
|
953 | 961 |
|
954 | 962 | def test_unused2
|
955 |
| - zio = StringIO.new |
| 963 | + assert_separately([Zlib::CHILD_ENV, '-rzlib', '-rstringio'], <<~'end;') |
| 964 | + zio = StringIO.new |
956 | 965 |
|
957 |
| - io = Zlib::GzipWriter.new zio |
958 |
| - io.write 'aaaa' |
959 |
| - io.finish |
| 966 | + io = Zlib::GzipWriter.new zio |
| 967 | + io.write 'aaaa' |
| 968 | + io.finish |
960 | 969 |
|
961 |
| - io = Zlib::GzipWriter.new zio |
962 |
| - io.write 'bbbb' |
963 |
| - io.finish |
| 970 | + io = Zlib::GzipWriter.new zio |
| 971 | + io.write 'bbbb' |
| 972 | + io.finish |
964 | 973 |
|
965 |
| - zio.rewind |
| 974 | + zio.rewind |
966 | 975 |
|
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 |
| 976 | + io = Zlib::GzipReader.new zio |
| 977 | + assert_equal('aaaa', io.read) |
| 978 | + unused = io.unused |
| 979 | + assert_equal(24, unused.bytesize) |
| 980 | + io.finish |
972 | 981 |
|
973 |
| - zio.pos -= unused.length |
| 982 | + zio.pos -= unused.length |
974 | 983 |
|
975 |
| - io = Zlib::GzipReader.new zio |
976 |
| - assert_equal('bbbb', io.read) |
977 |
| - assert_equal(nil, io.unused) |
978 |
| - io.finish |
| 984 | + io = Zlib::GzipReader.new zio |
| 985 | + assert_equal('bbbb', io.read) |
| 986 | + assert_equal(nil, io.unused) |
| 987 | + io.finish |
| 988 | + end; |
979 | 989 | end
|
980 | 990 |
|
981 | 991 | def test_read
|
@@ -1402,36 +1412,46 @@ def test_deflate
|
1402 | 1412 | end
|
1403 | 1413 |
|
1404 | 1414 | def test_deflate_stream
|
1405 |
| - r = Random.new 0 |
| 1415 | + assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;') |
| 1416 | + r = Random.new 0 |
1406 | 1417 |
|
1407 |
| - deflated = ''.dup |
| 1418 | + deflated = ''.dup |
1408 | 1419 |
|
1409 |
| - Zlib.deflate(r.bytes(20000)) do |chunk| |
1410 |
| - deflated << chunk |
1411 |
| - end |
| 1420 | + Zlib.deflate(r.bytes(20000)) do |chunk| |
| 1421 | + deflated << chunk |
| 1422 | + end |
1412 | 1423 |
|
1413 |
| - assert_equal 20016, deflated.length |
| 1424 | + assert_equal 20016, deflated.length |
| 1425 | + end; |
1414 | 1426 | end
|
1415 | 1427 |
|
1416 | 1428 | 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 |
| 1429 | + assert_separately([Zlib::CHILD_ENV, '-rzlib'], <<~'end;') |
| 1430 | + actual = Zlib.gzip("foo".freeze) |
| 1431 | + actual[4, 4] = "\x00\x00\x00\x00" # replace mtime |
| 1432 | + actual[9] = "\xff" # replace OS |
| 1433 | + expected = %w[1f8b08000000000000ff4bcbcf07002165738c03000000].pack("H*") |
| 1434 | + assert_equal expected, actual |
| 1435 | + end; |
| 1436 | + end |
1422 | 1437 |
|
| 1438 | + def test_gzip_level_0 |
1423 | 1439 | actual = Zlib.gzip("foo".freeze, level: 0)
|
1424 | 1440 | actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
1425 | 1441 | actual[9] = "\xff" # replace OS
|
1426 | 1442 | expected = %w[1f8b08000000000000ff010300fcff666f6f2165738c03000000].pack("H*")
|
1427 | 1443 | assert_equal expected, actual
|
| 1444 | + end |
1428 | 1445 |
|
| 1446 | + def test_gzip_level_9 |
1429 | 1447 | actual = Zlib.gzip("foo".freeze, level: 9)
|
1430 | 1448 | actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
1431 | 1449 | actual[9] = "\xff" # replace OS
|
1432 | 1450 | expected = %w[1f8b08000000000002ff4bcbcf07002165738c03000000].pack("H*")
|
1433 | 1451 | assert_equal expected, actual
|
| 1452 | + end |
1434 | 1453 |
|
| 1454 | + def test_gzip_level_9_filtered |
1435 | 1455 | actual = Zlib.gzip("foo".freeze, level: 9, strategy: Zlib::FILTERED)
|
1436 | 1456 | actual[4, 4] = "\x00\x00\x00\x00" # replace mtime
|
1437 | 1457 | actual[9] = "\xff" # replace OS
|
|
0 commit comments