Sha256: ec880a72ddddcc65faf86e9de6302ed9c931fafa3780114a9838e0bab5e94d3c

Contents?: true

Size: 1.68 KB

Versions: 59

Compression:

Stored size: 1.68 KB

Contents

require 'test_helper'

class DeflaterTest < MiniTest::Test
  include CrcTest

  DEFLATER_TEST_FILE = 'test/data/generated/deflatertest.bin'
  BEST_COMP_FILE = 'test/data/generated/compressiontest_best_compression.bin'
  DEFAULT_COMP_FILE = 'test/data/generated/compressiontest_default_compression.bin'
  NO_COMP_FILE = 'test/data/generated/compressiontest_no_compression.bin'

  def test_output_operator
    txt = load_file('test/data/file2.txt')
    deflate(txt, DEFLATER_TEST_FILE)
    inflatedTxt = inflate(DEFLATER_TEST_FILE)
    assert_equal(txt, inflatedTxt)
  end

  def test_default_compression
    txt = load_file('test/data/file2.txt')

    Zip.default_compression = ::Zlib::BEST_COMPRESSION
    deflate(txt, BEST_COMP_FILE)
    Zip.default_compression = ::Zlib::DEFAULT_COMPRESSION
    deflate(txt, DEFAULT_COMP_FILE)
    Zip.default_compression = ::Zlib::NO_COMPRESSION
    deflate(txt, NO_COMP_FILE)

    best    = File.size(BEST_COMP_FILE)
    default = File.size(DEFAULT_COMP_FILE)
    no      = File.size(NO_COMP_FILE)

    assert(best < default)
    assert(best < no)
    assert(default < no)
  end

  private

  def load_file(fileName)
    txt = nil
    File.open(fileName, 'rb') { |f| txt = f.read }
  end

  def deflate(data, fileName)
    File.open(fileName, 'wb') do |file|
      deflater = ::Zip::Deflater.new(file)
      deflater << data
      deflater.finish
      assert_equal(deflater.size, data.size)
      file << 'trailing data for zlib with -MAX_WBITS'
    end
  end

  def inflate(fileName)
    txt = nil
    File.open(fileName, 'rb') do |file|
      inflater = ::Zip::Inflater.new(file)
      txt = inflater.sysread
    end
  end

  def test_crc
    run_crc_test(::Zip::Deflater)
  end
end

Version data entries

59 entries across 47 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.3/test/deflater_test.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/rubyzip-1.3.0/test/deflater_test.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/test/deflater_test.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/deflater_test.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/deflater_test.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/deflater_test.rb
rubyzip-1.3.0 test/deflater_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.2/test/deflater_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/deflater_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.4/test/deflater_test.rb
rubyzip-1.2.4 test/deflater_test.rb
rubyzip-1.2.3 test/deflater_test.rb
tdiary-5.0.13 vendor/bundle/gems/rubyzip-1.2.2/test/deflater_test.rb
tdiary-5.0.12.1 vendor/bundle/gems/rubyzip-1.2.2/test/deflater_test.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/rubyzip-1.2.2/test/deflater_test.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/deflater_test.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/deflater_test.rb
tdiary-5.0.11 vendor/bundle/gems/rubyzip-1.2.2/test/deflater_test.rb
tdiary-5.0.11 vendor/bundle/gems/rubyzip-1.2.1/test/deflater_test.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.2/test/deflater_test.rb