Sha256: 5207406f400788ddfc7129dbc4070581c3a9883a69f0b57ef3d9136c947f0c9f

Contents?: true

Size: 1.24 KB

Versions: 44

Compression:

Stored size: 1.24 KB

Contents

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

require 'test_helper'
require 'hexapdf/document'
require 'hexapdf/image_loader/pdf'

describe HexaPDF::ImageLoader::PDF do
  before do
    @doc = HexaPDF::Document.new
    @loader = HexaPDF::ImageLoader::PDF
    @pdf = File.join(TEST_DATA_DIR, 'minimal.pdf')
  end

  describe "handles?" do
    it "works for PDF files" do
      assert(@loader.handles?(@pdf))
      File.open(@pdf, 'rb') {|file| assert(@loader.handles?(file)) }
    end
  end

  describe "load" do
    it "works for PDF files using a File object" do
      File.open(@pdf, 'rb') do |file|
        form = @loader.load(@doc, file)
        assert_equal(:Form, form[:Subtype])
      end
    end

    it "works for PDF files using a string object and use_stringio=true" do
      @doc.config['image_loader.pdf.use_stringio'] = true
      form = @loader.load(@doc, @pdf)
      assert_equal(:Form, form[:Subtype])
    end

    it "works for PDF files using a string object and use_stringio=false" do
      @doc.config['image_loader.pdf.use_stringio'] = false
      form = @loader.load(@doc, @pdf)
      assert_equal(:Form, form[:Subtype])
    ensure
      ObjectSpace.each_object(File) do |file|
        file.close if file.path == @pdf && !file.closed?
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

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