Sha256: 5bb811f4b683e09957536886fb7742b4804c47da0b7f5d80a6c315ac0b9cd2e2

Contents?: true

Size: 1.27 KB

Versions: 50

Compression:

Stored size: 1.27 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
      begin
        @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
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
hexapdf-0.20.4 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.20.3 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.20.2 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.20.1 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.20.0 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.19.3 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.19.2 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.19.1 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.19.0 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.18.0 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.17.3 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.17.2 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.16.0 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.15.9 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.15.8 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.15.7 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.15.6 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.15.5 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.15.4 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.15.3 test/hexapdf/image_loader/test_pdf.rb