Sha256: d186d5b521f6280552b272c1d53d6cba9f9eef9f5a9f00954791bf1945cf001d

Contents?: true

Size: 1.65 KB

Versions: 39

Compression:

Stored size: 1.65 KB

Contents

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

require 'test_helper'

# Provides common tests for all filter implementations.
#
# The filter object needs to be available in the @obj variable and the @all_test_cases variable
# needs to hold an array of test cases, i.e. [decoded, encoded] objects.
module CommonFilterTests

  TEST_BIG_STR = ''.b
  TEST_BIG_STR << [rand(2**32)].pack('N') while TEST_BIG_STR.length < 2**16
  TEST_BIG_STR.freeze

  def test_decodes_correctly
    @all_test_cases.each_with_index do |(result, str), index|
      assert_equal(result, collector(@obj.decoder(feeder(str.dup))), "testcase #{index}")
    end
  end

  def test_encodes_correctly
    @all_test_cases.each_with_index do |(str, result), index|
      assert_equal(result, collector(@obj.encoder(feeder(str.dup))), "testcase #{index}")
    end
  end

  def test_works_with_big_data
    assert_equal(TEST_BIG_STR, collector(@obj.decoder(@obj.encoder(feeder(TEST_BIG_STR.dup)))))
  end

  def test_decoder_returns_strings_in_binary_encoding
    assert_encodings(@obj.decoder(@obj.encoder(feeder('some test data', 1))), "decoder")
  end

  def test_encoder_returns_strings_in_binary_encoding
    assert_encodings(@obj.encoder(feeder('some test data', 1)), "encoder")
  end

  def assert_encodings(source, type)
    while source.alive? && (data = source.resume)
      assert_equal(Encoding::BINARY, data.encoding, "encoding problem in #{type}")
    end
  end

  def test_decoder_works_with_single_byte_input
    assert_equal(@decoded, collector(@obj.decoder(feeder(@encoded.dup, 1))))
  end

  def test_encoder_works_with_single_byte_input
    assert_equal(@encoded, collector(@obj.encoder(feeder(@decoded.dup, 1))))
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
hexapdf-1.2.0 test/hexapdf/filter/common.rb
hexapdf-1.1.1 test/hexapdf/filter/common.rb
hexapdf-1.1.0 test/hexapdf/filter/common.rb
hexapdf-1.0.3 test/hexapdf/filter/common.rb
hexapdf-1.0.2 test/hexapdf/filter/common.rb
hexapdf-1.0.1 test/hexapdf/filter/common.rb
hexapdf-1.0.0 test/hexapdf/filter/common.rb
hexapdf-0.47.0 test/hexapdf/filter/common.rb
hexapdf-0.46.0 test/hexapdf/filter/common.rb
hexapdf-0.45.0 test/hexapdf/filter/common.rb
hexapdf-0.44.0 test/hexapdf/filter/common.rb
hexapdf-0.41.0 test/hexapdf/filter/common.rb
hexapdf-0.40.0 test/hexapdf/filter/common.rb
hexapdf-0.39.1 test/hexapdf/filter/common.rb
hexapdf-0.39.0 test/hexapdf/filter/common.rb
hexapdf-0.38.0 test/hexapdf/filter/common.rb
hexapdf-0.37.2 test/hexapdf/filter/common.rb
hexapdf-0.37.1 test/hexapdf/filter/common.rb
hexapdf-0.37.0 test/hexapdf/filter/common.rb
hexapdf-0.36.0 test/hexapdf/filter/common.rb