Skip to content

Commit

Permalink
add some tests for various unsupported image files
Browse files Browse the repository at this point in the history
  • Loading branch information
yob committed Apr 24, 2009
1 parent a13f6e3 commit 51734fc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
Binary file added data/images/16bit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/dice_interlaced.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/tru256.bmp
Binary file not shown.
4 changes: 1 addition & 3 deletions lib/prawn/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ def image(file, options={})
when :png then
info = Prawn::Images::PNG.new(image_content)
build_png_object(image_content, info)
else
raise Errors::UnsupportedImageType, "image file is an unrecognised format"
end
image_registry[image_sha1] = {:obj => image_obj, :info => info}
end
Expand Down Expand Up @@ -324,7 +322,7 @@ def detect_image_format(content)
elsif top[0, 8] == "\x89PNG\x0d\x0a\x1a\x0a"
return :png
else
raise ArgumentError, "Unsupported Image Type"
raise Errors::UnsupportedImageType, "image file is an unrecognised format"
end
end

Expand Down
15 changes: 15 additions & 0 deletions spec/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@

info.height.should == 453
end

it "should raise an UnsupportedImageType if passed a BMP" do
filename = "#{Prawn::BASEDIR}/data/images/tru256.bmp"
lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
end

it "should raise an UnsupportedImageType if passed an interlaced PNG" do
filename = "#{Prawn::BASEDIR}/data/images/dice_interlaced.png"
lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
end

it "should raise an UnsupportedImageType if passed a 16 bit PNG" do
filename = "#{Prawn::BASEDIR}/data/images/16bit.png"
lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
end

describe ":fit option" do
it "should fit inside the defined constraints" do
Expand Down

0 comments on commit 51734fc

Please sign in to comment.