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
|
require 'runit/testcase'
require 'runit/cui/testrunner'
require 'image_size'
class TestImageSize < RUNIT::TestCase
def setup
@files = ['4_1_2.gif', '2-4-7.png', 'tokyo_tower.jpg', 'bmp.bmp',
'ppm.ppm', 'pgm.pgm', 'pbm.pbm',
'cursor.xbm', 'tiff.tiff', 'test.xpm',
'tower_e.gif.psd', 'pcx.pcx', 'detect.swf']
@results = [
['GIF',668,481],
['PNG',640,532],
['JPEG',320,240],
['BMP',50,50],
['PPM',80,50],
['PGM',90,55],
['PBM',85,55],
['XBM',16,16],
['TIFF',64,64],
['XPM',32,32],
['PSD',20,20],
['PCX',70,60],
['SWF',450,450],
]
end
def teardown
end
def test_0_string
print "\n" if $VERBOSE
@files.each_index do |i|
file = @files[i]
result = @results[i]
open(file, "rb") do |fh|
img_data = fh.read
print "file =#{file}\n" if $VERBOSE
img = ImageSize.new(img_data, result[0])
print "type =#{img.get_type}\n" if $VERBOSE
print "width =#{img.get_width}\n" if $VERBOSE
print "height=#{img.get_height}\n" if $VERBOSE
assert_equal(result[1], img.get_width)
assert_equal(result[2], img.get_height)
img = ImageSize.new(img_data)
assert_equal(result[0], img.get_type)
assert_equal(result[1], img.get_width)
assert_equal(result[2], img.get_height)
end
end
end
def test_1_io
print "\n" if $VERBOSE
@files.each_index do |i|
file = @files[i]
result = @results[i]
open(file, "rb") do |fh|
print "file =#{file}\n" if $VERBOSE
img = ImageSize.new(fh)
assert_equal(result[0], img.get_type)
assert_equal(result[1], img.get_width)
assert_equal(result[2], img.get_height)
end
end
end
end
suite = TestImageSize::suite
RUNIT::CUI::TestRunner.run(suite)
|