Sha256: 7afb5c2c7d5b79e333d93b25834b6eb52808f503b1e7fd188beaf53902aab563

Contents?: true

Size: 1.78 KB

Versions: 3

Compression:

Stored size: 1.78 KB

Contents

# -*- encoding: utf-8 -*-

require_relative 'common'
require 'hexapdf/filter/flate_decode'

describe HexaPDF::Filter::FlateDecode do
  include CommonFilterTests

  before do
    @obj = HexaPDF::Filter::FlateDecode
    @all_test_cases = [["abcdefg".b, "x\xDAKLJNIMK\a\x00\n\xDB\x02\xBD".b]]
    @decoded = @all_test_cases[0][0]
    @encoded = @all_test_cases[0][1]
    @encoded_predictor = "x\xDAcJdbD@\x00\x05\x8F\x00v".b
    @predictor_opts = {Predictor: 12}
  end

  describe "decoder" do
    it "works for empty input" do
      assert_equal('', collector(@obj.decoder(Fiber.new { "" })))
      assert_equal('', collector(@obj.decoder(Fiber.new {})))
    end

    it "applies the Predictor after decoding" do
      assert_equal(@decoded, collector(@obj.decoder(feeder(@encoded_predictor), @predictor_opts)))
    end

    describe "invalid input is handled as good as possible" do
      def strict_mode
        HexaPDF::GlobalConfiguration['filter.flate.on_error'] = proc { true }
        yield
      ensure
        HexaPDF::GlobalConfiguration['filter.flate.on_error'] = proc { false }
      end

      it "handles completely invalid data" do
        assert_equal('', collector(@obj.decoder(feeder("some data"))))
        assert_raises(HexaPDF::FilterError) do
          strict_mode { collector(@obj.decoder(feeder("some data"))) }
        end
      end

      it "handles missing data" do
        assert_equal('abcdefg', collector(@obj.decoder(feeder(@encoded[0..-2]))))
        assert_raises(HexaPDF::FilterError) do
          strict_mode { collector(@obj.decoder(feeder(@encoded[0..-2]))) }
        end
      end
    end
  end

  describe "encoder" do
    it "applies the Predictor before encoding" do
      assert_equal(@encoded_predictor, collector(@obj.encoder(feeder(@decoded), @predictor_opts)))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hexapdf-1.1.1 test/hexapdf/filter/test_flate_decode.rb
hexapdf-1.1.0 test/hexapdf/filter/test_flate_decode.rb
hexapdf-1.0.3 test/hexapdf/filter/test_flate_decode.rb