1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
require 'test_helper'
class RbpdfTest < Test::Unit::TestCase
test "Image basic func extension test" do
pdf = RBPDF.new
type = pdf.get_image_file_type("/tmp/rbpdf_logo.gif")
assert_equal type, "gif"
type = pdf.get_image_file_type("/tmp/rbpdf_logo.PNG")
assert_equal type, "png"
type = pdf.get_image_file_type("/tmp/rbpdf_logo.jpg")
assert_equal type, "jpeg"
type = pdf.get_image_file_type("/tmp/rbpdf_logo.jpeg")
assert_equal type, "jpeg"
type = pdf.get_image_file_type("/tmp/rbpdf_logo")
assert_equal type, ""
type = pdf.get_image_file_type("")
assert_equal type, ""
type = pdf.get_image_file_type(nil)
assert_equal type, ""
end
test "Image basic func mime type test" do
pdf = RBPDF.new
type = pdf.get_image_file_type(nil, {})
assert_equal type, ''
type = pdf.get_image_file_type(nil, {'mime' => 'image/gif'})
assert_equal type, 'gif'
type = pdf.get_image_file_type(nil, {'mime' => 'image/jpeg'})
assert_equal type, 'jpeg'
type = pdf.get_image_file_type('/tmp/rbpdf_logo.gif', {'mime' => 'image/png'})
assert_equal type, 'png'
type = pdf.get_image_file_type('/tmp/rbpdf_logo.gif', {})
assert_equal type, 'gif'
type = pdf.get_image_file_type(nil, {'mime' => 'text/html'})
assert_equal type, ''
type = pdf.get_image_file_type(nil, [])
assert_equal type, ''
end
test "Image basic filename test" do
pdf = RBPDF.new
err = assert_raises(RuntimeError) {
pdf.image(nil)
}
assert_equal( err.message, 'RBPDF error: Image filename is empty.')
err = assert_raises(RuntimeError) {
pdf.image('')
}
assert_equal( err.message, 'RBPDF error: Image filename is empty.')
err = assert_raises(RuntimeError) {
pdf.image('foo.png')
}
assert_equal( err.message, 'RBPDF error: Missing image file: foo.png')
end
test "Image basic test" do
pdf = RBPDF.new
pdf.add_page
img_file = File.join(File.dirname(__FILE__), '..', 'logo_example.png')
result_img = pdf.image(img_file, 50, 0, 0, '', '', '', '', false, 300, '', true)
no = pdf.get_num_pages
assert_equal no, 1
end
test "Image fitonpage test 1" do
pdf = RBPDF.new
pdf.add_page
img_file = File.join(File.dirname(__FILE__), '..', 'logo_example.png')
result_img = pdf.image(img_file, 50, 140, 100, '', '', '', '', false, 300, '', true, false, 0, false, false, true)
no = pdf.get_num_pages
assert_equal no, 1
end
test "Image fitonpage test 2" do
pdf = RBPDF.new
pdf.add_page
img_file = File.join(File.dirname(__FILE__), '..', 'logo_example.png')
y = 100
w = pdf.get_page_width * 2
h = pdf.get_page_height
result_img = pdf.image(img_file, '', y, w, h, '', '', '', false, 300, '', true, false, 0, false, false, true)
no = pdf.get_num_pages
assert_equal no, 1
end
end
|