Sha256: 9c9593419c586b29346bade8a9e11b2f904eb54f1bd9bd05610370dbfc9531dc

Contents?: true

Size: 1.69 KB

Versions: 72

Compression:

Stored size: 1.69 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_outputOperator
    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") {
        |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

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

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

Version data entries

72 entries across 69 versions & 20 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/rubyzip-1.1.7/test/deflater_test.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/rubyzip-1.1.7/test/deflater_test.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/rubyzip-1.1.7/test/deflater_test.rb