File: test_image_size.rb

package info (click to toggle)
libimage-size-ruby 1%3A0.1.1-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 236 kB
  • ctags: 234
  • sloc: ruby: 1,543; makefile: 11
file content (71 lines) | stat: -rwxr-xr-x 1,565 bytes parent folder | download | duplicates (4)
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
require File.dirname(__FILE__) + '/test_helper.rb'

class TestImageSize < Test::Unit::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,200],
		]
	end

	def teardown
	end

	def test_0_string
#		puts "\n" if $VERBOSE

		@files.each_index do |i|
			file = @files[i]
			result = @results[i]

			open("test/#{file}", "rb") do |fh|
				img_data = fh.read
#				puts "file  =#{file}" if $VERBOSE

				img = ImageSize.new(img_data, result[0])

				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
#		puts "\n" if $VERBOSE

		@files.each_index do |i|
			file = @files[i]
			result = @results[i]

			open("test/#{file}", "rb") do |fh|
#				puts "file  =#{file}" 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