Sha256: 4cd37cf48bbd48fb7fd3e5ed00b64d312377bfc7390f30d7343379e7358769ad
Contents?: true
Size: 1.9 KB
Versions: 25
Compression:
Stored size: 1.9 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".force_encoding(Encoding::BINARY), "x\xDAKLJNIMK\a\x00\n\xDB\x02\xBD".force_encoding(Encoding::BINARY)]] @decoded = @all_test_cases[0][0] @encoded = @all_test_cases[0][1] @encoded_predictor = "x\xDAcJdbD@\x00\x05\x8F\x00v".force_encoding(Encoding::BINARY) @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
25 entries across 25 versions & 1 rubygems