minicomic-backend/tests/TestFilter.rb

77 lines
1.6 KiB
Ruby
Raw Normal View History

2009-05-22 13:36:08 +00:00
require 'rubygems'
require 'test/unit'
2010-01-05 12:28:52 +00:00
require 'fakefs/safe'
2009-05-22 13:36:08 +00:00
require File.dirname(__FILE__) + '/../classes/Filter.rb'
class TestFilter < Test::Unit::TestCase
def setup
2010-01-05 12:28:52 +00:00
@filter = Filter.new
2009-05-22 13:36:08 +00:00
end
def test_recalc_pixels
@filter.config = {}
assert_raise RuntimeError do
@filter.config = {'print' => true}
end
assert_raise RuntimeError do
@filter.config = {'print' => true,
'dpi' => 'test'}
end
assert_raise RuntimeError do
@filter.config = {
'print' => true,
'dpi' => 10
}
end
2010-01-05 03:55:50 +00:00
2009-05-22 13:36:08 +00:00
[ 'width', 'height' ].each do |dim|
assert_raise RuntimeError do
@filter.config = {
'print' => true,
'dpi' => 10,
'width' => 10
}
end
@filter.config = {
'width' => 10
}
assert_equal(10, @filter.config['width'])
end
2010-01-05 12:28:52 +00:00
@filter.config = {
'print' => true,
'dpi' => 10,
'width_inches' => 1,
'height_inches' => 2
}
assert_equal(10, @filter.config['width'])
assert_equal(20, @filter.config['height'])
end
def test_cleanup
@filter.cleanup = [ 'test', 'test2', 'test3' ]
FakeFS do
FileUtils.touch [ 'test', 'test3', 'test4' ]
@filter.cleanup
[ 'test', 'test2', 'test3' ].each do |file|
assert !(File.exists? file)
end
[ 'test4' ].each do |file|
assert File.exists? file
end
2010-01-11 02:54:20 +00:00
[ 'test', 'test3', 'test4' ].each { |f| FileUtils.rm f }
2010-01-05 12:28:52 +00:00
end
end
def test_get_dimensions
assert_equal [ 50, 75 ], @filter.get_dimensions(File.dirname(__FILE__) + '/data/test_dimensions.png')
2009-05-22 13:36:08 +00:00
end
2010-01-05 03:55:50 +00:00
end