Sha256: b66655870daff9f76450c59cd4a9b0e1a40f9a2ffc7596d2b99b1d3b40179a02

Contents?: true

Size: 1.27 KB

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
hexapdf-0.6.0 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.5.0 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.4.0 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.3.0 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.2.0 test/hexapdf/image_loader/test_pdf.rb
hexapdf-0.1.0 test/hexapdf/image_loader/test_pdf.rb