Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 763 lines (686 sloc) 33.528 kB
281c16e New
rmagick authored
1 #! /usr/local/bin/ruby -w
2
3 require 'RMagick'
4 require 'test/unit'
95bba79 Update to work with new test/unit in 1.9.1
rmagick authored
5 require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
281c16e New
rmagick authored
6
d98e8e3 Make work with Ruby 1.9.0
rmagick authored
7
281c16e New
rmagick authored
8 class Image1_UT < Test::Unit::TestCase
95bba79 Update to work with new test/unit in 1.9.1
rmagick authored
9 FreezeError = RUBY_VERSION == '1.9.1' ? RuntimeError : TypeError
61e898a Test Image#add_noise_channel
rmagick authored
10
281c16e New
rmagick authored
11 def setup
12 @img = Magick::Image.new(20, 20)
13 end
61e898a Test Image#add_noise_channel
rmagick authored
14
281c16e New
rmagick authored
15 # Test [], []=, and #properties
16 def test_properties
17 assert_nothing_raised do
18 @img['a'] = 'string1'
19 @img['b'] = 'string2'
20 @img['c'] = 'string3'
21 end
22 assert_equal('string1', @img['a'])
23 assert_equal('string2', @img['b'])
24 assert_equal('string3', @img['c'])
25 assert_nil(@img['d'])
26 assert_nothing_raised do
27 props = @img.properties
28 assert_equal(3, props.length)
29 assert_equal('string1', props['a'])
30 assert_equal('string2', props['b'])
31 assert_equal('string3', props['c'])
32 end
61e898a Test Image#add_noise_channel
rmagick authored
33
281c16e New
rmagick authored
34 known = {'a'=>'string1', 'b'=>'string2', 'c'=>'string3'}
35 @img.properties do |name, value|
36 assert(known.has_key?(name))
37 assert_equal(known[name], value)
38 end
61e898a Test Image#add_noise_channel
rmagick authored
39
d98e8e3 Make work with Ruby 1.9.0
rmagick authored
40 assert_raise(FreezeError) do
47c38aa Last tests for this file
rmagick authored
41 @img.freeze
42 @img['d'] = 'string4'
43 end
281c16e New
rmagick authored
44 end
61e898a Test Image#add_noise_channel
rmagick authored
45
01cc1f8 Test Image#blue_shift
rmagick authored
46 def test_blue_shift
47 img = Magick::Image.read(IMAGES_DIR+'/Button_0.gif')[0]
48 res = nil
49 assert_nothing_raised { res = img.blue_shift }
50 assert_instance_of(Magick::Image, res)
51 assert_not_same(img, res)
52 assert_nothing_raised { img.blue_shift(2) }
53 assert_raise(ArgumentError) { img.blue_shift(2, 3) }
54 end
55
dbbffd5 More tests
rmagick authored
56 # test constitute and dispatch
57 def test_constitute
58 @img = Magick::Image.read(IMAGES_DIR+'/Button_0.gif')[0]
59 assert_nothing_raised do
60 pixels = @img.dispatch(0, 0, @img.columns, @img.rows, 'RGBA')
61 res = Magick::Image.constitute(@img.columns, @img.rows, 'RGBA', pixels)
62 # The constituted image is in MIFF format so we
63 # can't compare it directly to the original image.
64 assert_equal(@img.columns, res.columns)
65 assert_equal(@img.rows, res.rows)
fca6c01 Replace MaxRGB with QuantumRange
rmagick authored
66 assert_block { pixels.all? { |v| 0 <= v && v <= Magick::QuantumRange } }
dbbffd5 More tests
rmagick authored
67 end
61e898a Test Image#add_noise_channel
rmagick authored
68
dbbffd5 More tests
rmagick authored
69 pixels = @img.dispatch(0, 0, @img.columns, @img.rows, 'RGBA', true)
70 assert_block { pixels.all? { |v| 0.0 <= v && v <= 1.0 } }
61e898a Test Image#add_noise_channel
rmagick authored
71
dbbffd5 More tests
rmagick authored
72 # dispatch wants exactly 5 or exactly 6 arguments
73 assert_raise(ArgumentError) { @img.dispatch }
74 assert_raise(ArgumentError) { @img.dispatch(0) }
75 assert_raise(ArgumentError) { @img.dispatch(0, 0) }
76 assert_raise(ArgumentError) { @img.dispatch(0, 0, @img.columns) }
77 assert_raise(ArgumentError) { @img.dispatch(0, 0, @img.columns, @img.rows) }
78 assert_raise(ArgumentError) { @img.dispatch(0, 0, 20, 20, 'RGBA', false, false) }
79 end
61e898a Test Image#add_noise_channel
rmagick authored
80
dbbffd5 More tests
rmagick authored
81 # test from_blob and to_blob
82 def test_from_blob
83 img = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
84 blob = nil
85 res = nil
86 assert_nothing_raised { blob = img.to_blob }
87 assert_instance_of(String, blob)
88 assert_nothing_raised { res = Magick::Image.from_blob(blob) }
89 assert_instance_of(Array, res)
90 assert_instance_of(Magick::Image, res[0])
91 assert_equal(img, res[0])
92 end
61e898a Test Image#add_noise_channel
rmagick authored
93
dbbffd5 More tests
rmagick authored
94 def test_ping
95 res = Magick::Image.ping(IMAGES_DIR+'/Button_0.gif')
96 assert_instance_of(Array, res)
97 assert_instance_of(Magick::Image, res[0])
98 assert_equal('GIF', res[0].format)
99 assert_equal(127, res[0].columns)
100 assert_equal(120, res[0].rows)
101 assert_match(/Button_0.gif/, res[0].filename)
102 end
61e898a Test Image#add_noise_channel
rmagick authored
103
dbbffd5 More tests
rmagick authored
104 def test_read_inline
105 img = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
106 blob = img.to_blob
53c9181 Don't use base64 library
rmagick authored
107 encoded = [blob].pack("m*")
dbbffd5 More tests
rmagick authored
108 res = Magick::Image.read_inline(encoded)
109 assert_instance_of(Array, res)
110 assert_instance_of(Magick::Image, res[0])
111 assert_equal(img, res[0])
112 end
61e898a Test Image#add_noise_channel
rmagick authored
113
dbbffd5 More tests
rmagick authored
114 def test_spaceship
115 img0 = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
116 img1 = Magick::Image.read(IMAGES_DIR+'/Button_1.gif').first
117 sig0 = img0.signature
118 sig1 = img1.signature
119 # since <=> is based on the signature, the images should
120 # have the same relationship to each other as their
121 # signatures have to each other.
122 assert_equal(sig0 <=> sig1, img0 <=> img1)
123 assert_equal(sig1 <=> sig0, img1 <=> img0)
124 assert_equal(img0, img0)
125 assert_not_equal(img0, img1)
126 end
61e898a Test Image#add_noise_channel
rmagick authored
127
f784d81 New tests
rmagick authored
128 def test_adaptive_blur
129 assert_nothing_raised do
130 res = @img.adaptive_blur
131 assert_instance_of(Magick::Image, res)
132 end
133 assert_nothing_raised { @img.adaptive_blur(2) }
134 assert_nothing_raised { @img.adaptive_blur(3, 2) }
135 assert_raise(ArgumentError) { @img.adaptive_blur(3, 2, 2) }
136 end
137
138 def test_adaptive_blur_channel
139 assert_nothing_raised do
140 res = @img.adaptive_blur_channel
141 assert_instance_of(Magick::Image, res)
142 end
143 assert_nothing_raised { @img.adaptive_blur_channel(2) }
144 assert_nothing_raised { @img.adaptive_blur_channel(3, 2) }
145 assert_nothing_raised { @img.adaptive_blur_channel(3, 2, Magick::RedChannel) }
146 assert_nothing_raised { @img.adaptive_blur_channel(3, 2, Magick::RedChannel, Magick::BlueChannel) }
147 assert_raise(ArgumentError) { @img.adaptive_blur(3, 2, 2) }
148 end
149
150 def test_adaptive_resize
151 assert_nothing_raised do
152 res = @img.adaptive_resize(10,10)
153 assert_instance_of(Magick::Image, res)
154 end
155 assert_nothing_raised { @img.adaptive_resize(2) }
156 assert_raise(ArgumentError) { @img.adaptive_resize(10,10,10) }
157 assert_raise(ArgumentError) { @img.adaptive_resize }
158 end
159
160 def test_adaptive_sharpen
161 assert_nothing_raised do
162 res = @img.adaptive_sharpen
163 assert_instance_of(Magick::Image, res)
164 end
165 assert_nothing_raised { @img.adaptive_sharpen(2) }
166 assert_nothing_raised { @img.adaptive_sharpen(3, 2) }
167 assert_raise(ArgumentError) { @img.adaptive_sharpen(3, 2, 2) }
168 end
169
170 def test_adaptive_sharpen_channel
171 assert_nothing_raised do
172 res = @img.adaptive_sharpen_channel
173 assert_instance_of(Magick::Image, res)
174 end
175 assert_nothing_raised { @img.adaptive_sharpen_channel(2) }
176 assert_nothing_raised { @img.adaptive_sharpen_channel(3, 2) }
177 assert_nothing_raised { @img.adaptive_sharpen_channel(3, 2, Magick::RedChannel) }
178 assert_nothing_raised { @img.adaptive_sharpen_channel(3, 2, Magick::RedChannel, Magick::BlueChannel) }
179 assert_raise(ArgumentError) { @img.adaptive_sharpen(3, 2, 2) }
180 end
181
dbbffd5 More tests
rmagick authored
182 def test_adaptive_threshold
f784d81 New tests
rmagick authored
183 assert_nothing_raised do
184 res = @img.adaptive_threshold
185 assert_instance_of(Magick::Image, res)
186 end
dbbffd5 More tests
rmagick authored
187 assert_nothing_raised { @img.adaptive_threshold(2) }
188 assert_nothing_raised { @img.adaptive_threshold(2,4) }
189 assert_nothing_raised { @img.adaptive_threshold(2,4,1) }
190 assert_raise(ArgumentError) { @img.adaptive_threshold(2,4,1,2) }
191 end
61e898a Test Image#add_noise_channel
rmagick authored
192
a701d54 test add_compose_mask, delete_compose_mask
rmagick authored
193 def test_add_compose_mask
194 mask = Magick::Image.new(20,20)
195 assert_nothing_raised { @img.add_compose_mask(mask) }
196 assert_nothing_raised { @img.delete_compose_mask() }
197 assert_nothing_raised { @img.add_compose_mask(mask) }
198 assert_nothing_raised { @img.add_compose_mask(mask) }
199 assert_nothing_raised { @img.delete_compose_mask() }
200 assert_nothing_raised { @img.delete_compose_mask() }
201 end
202
dbbffd5 More tests
rmagick authored
203 def test_add_noise
204 assert_nothing_raised { @img.add_noise(Magick::UniformNoise) }
205 assert_nothing_raised { @img.add_noise(Magick::GaussianNoise) }
206 assert_nothing_raised { @img.add_noise(Magick::MultiplicativeGaussianNoise) }
207 assert_nothing_raised { @img.add_noise(Magick::ImpulseNoise) }
208 assert_nothing_raised { @img.add_noise(Magick::LaplacianNoise) }
209 assert_nothing_raised { @img.add_noise(Magick::PoissonNoise) }
210 assert_raise(TypeError) { @img.add_noise(0) }
211 end
61e898a Test Image#add_noise_channel
rmagick authored
212
213 def test_add_noise_channel
214 assert_nothing_raised { @img.add_noise_channel(Magick::UniformNoise) }
215 assert_nothing_raised { @img.add_noise_channel(Magick::UniformNoise, Magick::RedChannel) }
216 assert_nothing_raised { @img.add_noise_channel(Magick::GaussianNoise, Magick::BlueChannel) }
217 assert_nothing_raised { @img.add_noise_channel(Magick::ImpulseNoise, Magick::GreenChannel) }
218 assert_nothing_raised { @img.add_noise_channel(Magick::LaplacianNoise, Magick::RedChannel, Magick::GreenChannel) }
219 assert_nothing_raised { @img.add_noise_channel(Magick::PoissonNoise, Magick::RedChannel, Magick::GreenChannel, Magick::BlueChannel) }
220
221 # Not a NoiseType
222 assert_raise(TypeError) { @img.add_noise_channel(1) }
223 # Not a ChannelType
224 assert_raise(TypeError) { @img.add_noise_channel(Magick::UniformNoise, Magick::RedChannel, 1) }
225 # Too few arguments
226 assert_raise(ArgumentError) { @img.add_noise_channel }
227 end
228
26c0ec6 add profile tests
rmagick authored
229 def add_delete_profile
230 img = Magick::Image.read("cmyk.jpg"),first
231 assert_nothing_raised { img.add_profile("cmyk.icm") }
232 assert_nothing_raised { img.add_profile("srgb.icm") }
233 img.each_profile { |name, value| assert_equal("icc", name) }
234 assert_nothing_raised { img.delete_profile("icc") }
235 end
236
dbbffd5 More tests
rmagick authored
237 def test_affine_matrix
238 affine = Magick::AffineMatrix.new(1, Math::PI/6, Math::PI/6, 1, 0, 0)
239 assert_nothing_raised { @img.affine_transform(affine) }
240 assert_raise(TypeError) { @img.affine_transform(0) }
6b088bd More tests
rmagick authored
241 res = @img.affine_transform(affine)
242 assert_instance_of(Magick::Image, res)
dbbffd5 More tests
rmagick authored
243 end
61e898a Test Image#add_noise_channel
rmagick authored
244
6b98e6e Add backward compatiblity test for Image#alpha
rmagick authored
245 # test alpha backward compatibility. Image#alpha w/o arguments acts like alpha?
246 def test_alpha_compat
247 assert_nothing_raised { @img.alpha }
248 assert !@img.alpha
249 assert_nothing_raised { @img.alpha Magick::ActivateAlphaChannel }
250 assert @img.alpha
251 end
252
6d78312 Move tests for #mask and #alpha to their new files. Update tests.
rmagick authored
253 def test_alpha
254 assert_nothing_raised { @img.alpha? }
255 assert !@img.alpha?
256 assert_nothing_raised { @img.alpha Magick::ActivateAlphaChannel }
257 assert @img.alpha?
258 assert_nothing_raised { @img.alpha Magick::DeactivateAlphaChannel }
259 assert !@img.alpha?
260 assert_nothing_raised { @img.alpha Magick::ResetAlphaChannel }
261 assert_nothing_raised { @img.alpha Magick::SetAlphaChannel }
c1d3ee2 Fix nits and add a few tests.
rmagick authored
262 @img.freeze
263 assert_raise(FreezeError) { @img.alpha Magick::SetAlphaChannel }
6d78312 Move tests for #mask and #alpha to their new files. Update tests.
rmagick authored
264 end
265
46334dd Test Image#auto_gamma_channel, #auto_level_channel
rmagick authored
266 def test_auto_gamma
267 res = nil
268 assert_nothing_raised { res = @img.auto_gamma_channel }
269 assert_instance_of(Magick::Image, res)
270 assert_not_same(@img, res)
271 assert_nothing_raised { res = @img.auto_gamma_channel Magick::RedChannel }
272 assert_nothing_raised { res = @img.auto_gamma_channel Magick::RedChannel, Magick::BlueChannel }
273 assert_raise(TypeError) { @img.auto_gamma_channel(1) }
274 end
275
276
277 def test_auto_level
278 res = nil
279 assert_nothing_raised { res = @img.auto_level_channel }
280 assert_instance_of(Magick::Image, res)
281 assert_not_same(@img, res)
282 assert_nothing_raised { res = @img.auto_level_channel Magick::RedChannel }
283 assert_nothing_raised { res = @img.auto_level_channel Magick::RedChannel, Magick::BlueChannel }
284 assert_raise(TypeError) { @img.auto_level_channel(1) }
285 end
286
f784d81 New tests
rmagick authored
287 def test_auto_orient
26c0ec6 add profile tests
rmagick authored
288 assert_nothing_raised do
289 res = @img.auto_orient
290 assert_instance_of(Magick::Image, res)
291 assert_not_same(@img, res)
292 end
f784d81 New tests
rmagick authored
293
26c0ec6 add profile tests
rmagick authored
294 assert_nothing_raised do
295 res = @img.auto_orient!
296 # When not changed, returns nil
297 assert_nil(res)
298 end
f784d81 New tests
rmagick authored
299 end
300
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
301 def test_bilevel_channel
302 assert_raise(ArgumentError) { @img.bilevel_channel }
303 assert_nothing_raised { @img.bilevel_channel(100) }
304 assert_nothing_raised { @img.bilevel_channel(100, Magick::RedChannel) }
305 assert_nothing_raised { @img.bilevel_channel(100, Magick::RedChannel, Magick::BlueChannel, Magick::GreenChannel, Magick::OpacityChannel) }
306 assert_nothing_raised { @img.bilevel_channel(100, Magick::CyanChannel, Magick::MagentaChannel, Magick::YellowChannel, Magick::BlackChannel) }
307 assert_nothing_raised { @img.bilevel_channel(100, Magick::GrayChannel) }
308 assert_nothing_raised { @img.bilevel_channel(100, Magick::AllChannels) }
cb5ecfe Assert TypeError raised when ChannelType arg expected but not received
rmagick authored
309 assert_raise(TypeError) { @img.bilevel_channel(100, 2) }
6b088bd More tests
rmagick authored
310 res = @img.bilevel_channel(100)
311 assert_instance_of(Magick::Image, res)
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
312 end
61e898a Test Image#add_noise_channel
rmagick authored
313
56ea702 Merge new tests
rmagick authored
314 def test_blend
315 @img2 = Magick::Image.new(20,20) {self.background_color = "black"}
316 assert_nothing_raised { @img.blend(@img2, 0.25) }
317 res = @img.blend(@img2, 0.25)
318 assert_instance_of(Magick::Image, res)
319 assert_nothing_raised { @img.blend(@img2, '25%') }
320 assert_nothing_raised { @img.blend(@img2, 0.25, 0.75) }
321 assert_nothing_raised { @img.blend(@img2, '25%', '75%') }
322 assert_nothing_raised { @img.blend(@img2, 0.25, 0.75, Magick::CenterGravity) }
323 assert_nothing_raised { @img.blend(@img2, 0.25, 0.75, Magick::CenterGravity, 10) }
324 assert_nothing_raised { @img.blend(@img2, 0.25, 0.75, Magick::CenterGravity, 10, 10) }
325 assert_raise(ArgumentError) { @img.blend }
326 assert_raise(ArgumentError) { @img.blend(@img2, 'x') }
327 assert_raise(TypeError) { @img.blend(@img2, 0.25, []) }
328 assert_raise(TypeError) { @img.blend(@img2, 0.25, 0.75, 'x') }
329 assert_raise(TypeError) { @img.blend(@img2, 0.25, 0.75, Magick::CenterGravity, 'x') }
330 assert_raise(TypeError) { @img.blend(@img2, 0.25, 0.75, Magick::CenterGravity, 10, []) }
bec1e09 Add tests for image arguments that have been destroyed
rmagick authored
331
332 @img2.destroy!
333 assert_raise(Magick::DestroyedImageError) { @img.blend(@img2, '25%') }
56ea702 Merge new tests
rmagick authored
334 end
335
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
336 def test_blur_channel
337 assert_nothing_raised { @img.blur_channel }
338 assert_nothing_raised { @img.blur_channel(1) }
339 assert_nothing_raised { @img.blur_channel(1,2) }
340 assert_nothing_raised { @img.blur_channel(1,2, Magick::RedChannel) }
341 assert_nothing_raised { @img.blur_channel(1,2, Magick::RedChannel, Magick::BlueChannel, Magick::GreenChannel, Magick::OpacityChannel) }
342 assert_nothing_raised { @img.blur_channel(1,2, Magick::CyanChannel, Magick::MagentaChannel, Magick::YellowChannel, Magick::BlackChannel) }
343 assert_nothing_raised { @img.blur_channel(1,2, Magick::GrayChannel) }
344 assert_nothing_raised { @img.blur_channel(1,2, Magick::AllChannels) }
cb5ecfe Assert TypeError raised when ChannelType arg expected but not received
rmagick authored
345 assert_raise(TypeError) { @img.blur_channel(1,2,2) }
6b088bd More tests
rmagick authored
346 res = @img.blur_channel
347 assert_instance_of(Magick::Image, res)
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
348 end
61e898a Test Image#add_noise_channel
rmagick authored
349
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
350 def test_blur_image
351 assert_nothing_raised { @img.blur_image }
352 assert_nothing_raised { @img.blur_image(1) }
353 assert_nothing_raised { @img.blur_image(1,2) }
354 assert_raise(ArgumentError) { @img.blur_image(1,2,3) }
6b088bd More tests
rmagick authored
355 res = @img.blur_image
356 assert_instance_of(Magick::Image, res)
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
357 end
358
359 def test_black_threshold
360 assert_raise(ArgumentError) { @img.black_threshold }
361 assert_nothing_raised { @img.black_threshold(50) }
362 assert_nothing_raised { @img.black_threshold(50, 50) }
363 assert_nothing_raised { @img.black_threshold(50, 50, 50) }
364 assert_nothing_raised { @img.black_threshold(50, 50, 50, 50) }
365 assert_raise(ArgumentError) { @img.black_threshold(50, 50, 50, 50, 50) }
6b088bd More tests
rmagick authored
366 res = @img.black_threshold(50)
367 assert_instance_of(Magick::Image, res)
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
368 end
61e898a Test Image#add_noise_channel
rmagick authored
369
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
370 def test_border
371 assert_nothing_raised { @img.border(2, 2, 'red') }
372 assert_nothing_raised { @img.border!(2, 2, 'red') }
6b088bd More tests
rmagick authored
373 res = @img.border(2,2, 'red')
374 assert_instance_of(Magick::Image, res)
47c38aa Last tests for this file
rmagick authored
375 @img.freeze
d98e8e3 Make work with Ruby 1.9.0
rmagick authored
376 assert_raise(FreezeError) { @img.border!(2,2, 'red') }
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
377 end
61e898a Test Image#add_noise_channel
rmagick authored
378
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
379 def test_change_geometry
38e236f Fix change_geometry test
rmagick authored
380 assert_raise(ArgumentError) { @img.change_geometry("sss") }
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
381 assert_raise(LocalJumpError) { @img.change_geometry("100x100") }
382 assert_nothing_raised do
383 res = @img.change_geometry("100x100") { 1 }
384 assert_equal(1, res)
385 end
38e236f Fix change_geometry test
rmagick authored
386 assert_raise(ArgumentError) { @img.change_geometry([]) }
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
387 end
61e898a Test Image#add_noise_channel
rmagick authored
388
bde3db3 Fix Image_bilevel_channel to properly raise ArgumentError when no arg…
rmagick authored
389 def test_changed?
47c38aa Last tests for this file
rmagick authored
390 # assert_block { !@img.changed? }
391 # @img.pixel_color(0,0,'red')
392 # assert_block { @img.changed? }
6b088bd More tests
rmagick authored
393 end
61e898a Test Image#add_noise_channel
rmagick authored
394
6b088bd More tests
rmagick authored
395 def test_channel
396 assert_nothing_raised { @img.channel(Magick::RedChannel) }
397 assert_nothing_raised { @img.channel(Magick::BlueChannel) }
398 assert_nothing_raised { @img.channel(Magick::GreenChannel) }
399 assert_nothing_raised { @img.channel(Magick::OpacityChannel) }
400 assert_nothing_raised { @img.channel(Magick::MagentaChannel) }
401 assert_nothing_raised { @img.channel(Magick::CyanChannel) }
402 assert_nothing_raised { @img.channel(Magick::YellowChannel) }
403 assert_nothing_raised { @img.channel(Magick::BlackChannel) }
404 assert_nothing_raised { @img.channel(Magick::GrayChannel) }
64b6cba Add new ChannelType values to test_channel
rmagick authored
405 assert_nothing_raised { @img.channel(Magick::AlphaChannel) }
406 assert_nothing_raised { @img.channel(Magick::DefaultChannels) }
407 assert_nothing_raised { @img.channel(Magick::HueChannel) }
408 assert_nothing_raised { @img.channel(Magick::LuminosityChannel) }
409 assert_nothing_raised { @img.channel(Magick::SaturationChannel) }
61e898a Test Image#add_noise_channel
rmagick authored
410 assert_instance_of(Magick::Image, @img.channel(Magick::RedChannel))
6b088bd More tests
rmagick authored
411 assert_raise(TypeError) { @img.channel(2) }
412 end
61e898a Test Image#add_noise_channel
rmagick authored
413
6b088bd More tests
rmagick authored
414 def test_channel_depth
415 assert_nothing_raised { @img.channel_depth }
416 assert_nothing_raised { @img.channel_depth(Magick::RedChannel) }
417 assert_nothing_raised { @img.channel_depth(Magick::RedChannel, Magick::BlueChannel) }
418 assert_nothing_raised { @img.channel_depth(Magick::GreenChannel, Magick::OpacityChannel) }
419 assert_nothing_raised { @img.channel_depth(Magick::MagentaChannel, Magick::CyanChannel) }
420 assert_nothing_raised { @img.channel_depth(Magick::CyanChannel, Magick::BlackChannel) }
421 assert_nothing_raised { @img.channel_depth(Magick::GrayChannel) }
cb5ecfe Assert TypeError raised when ChannelType arg expected but not received
rmagick authored
422 assert_raise(TypeError) { @img.channel_depth(2) }
6b088bd More tests
rmagick authored
423 assert_instance_of(Fixnum, @img.channel_depth(Magick::RedChannel))
424 end
61e898a Test Image#add_noise_channel
rmagick authored
425
47c38aa Last tests for this file
rmagick authored
426 def test_channel_extrema
427 assert_nothing_raised do
428 res = @img.channel_extrema
429 assert_instance_of(Array, res)
430 assert_equal(2, res.length)
44f5b56 Fix test to handle 32-bit quantum depth
rmagick authored
431 assert_kind_of(Integer, res[0])
432 assert_kind_of(Integer, res[1])
47c38aa Last tests for this file
rmagick authored
433 end
434 assert_nothing_raised { @img.channel_extrema(Magick::RedChannel) }
435 assert_nothing_raised { @img.channel_extrema(Magick::RedChannel, Magick::BlueChannel) }
436 assert_nothing_raised { @img.channel_extrema(Magick::GreenChannel, Magick::OpacityChannel) }
437 assert_nothing_raised { @img.channel_extrema(Magick::MagentaChannel, Magick::CyanChannel) }
438 assert_nothing_raised { @img.channel_extrema(Magick::CyanChannel, Magick::BlackChannel) }
439 assert_nothing_raised { @img.channel_extrema(Magick::GrayChannel) }
cb5ecfe Assert TypeError raised when ChannelType arg expected but not received
rmagick authored
440 assert_raise(TypeError) { @img.channel_extrema(2) }
47c38aa Last tests for this file
rmagick authored
441 end
61e898a Test Image#add_noise_channel
rmagick authored
442
47c38aa Last tests for this file
rmagick authored
443 def test_channel_mean
444 assert_nothing_raised do
445 res = @img.channel_mean
446 assert_instance_of(Array, res)
447 assert_equal(2, res.length)
448 assert_instance_of(Float, res[0])
449 assert_instance_of(Float, res[1])
450 end
451 assert_nothing_raised { @img.channel_mean(Magick::RedChannel) }
452 assert_nothing_raised { @img.channel_mean(Magick::RedChannel, Magick::BlueChannel) }
453 assert_nothing_raised { @img.channel_mean(Magick::GreenChannel, Magick::OpacityChannel) }
454 assert_nothing_raised { @img.channel_mean(Magick::MagentaChannel, Magick::CyanChannel) }
455 assert_nothing_raised { @img.channel_mean(Magick::CyanChannel, Magick::BlackChannel) }
456 assert_nothing_raised { @img.channel_mean(Magick::GrayChannel) }
cb5ecfe Assert TypeError raised when ChannelType arg expected but not received
rmagick authored
457 assert_raise(TypeError) { @img.channel_mean(2) }
47c38aa Last tests for this file
rmagick authored
458 end
61e898a Test Image#add_noise_channel
rmagick authored
459
47c38aa Last tests for this file
rmagick authored
460 def test_charcoal
461 assert_nothing_raised do
462 res = @img.charcoal
463 assert_instance_of(Magick::Image, res)
464 end
465 assert_nothing_raised { @img.charcoal(1.0) }
466 assert_nothing_raised { @img.charcoal(1.0, 2.0) }
467 assert_raise(ArgumentError) { @img.charcoal(1.0, 2.0, 3.0) }
468 end
61e898a Test Image#add_noise_channel
rmagick authored
469
47c38aa Last tests for this file
rmagick authored
470 def test_chop
471 assert_nothing_raised do
472 res = @img.chop(10, 10, 10, 10)
473 assert_instance_of(Magick::Image, res)
474 end
475 end
61e898a Test Image#add_noise_channel
rmagick authored
476
47c38aa Last tests for this file
rmagick authored
477 def test_clone
478 assert_nothing_raised do
479 res = @img.clone
480 assert_instance_of(Magick::Image, res)
481 assert_equal(res, @img)
482 end
483 res = @img.clone
484 assert_equal(res.frozen?, @img.frozen?)
485 @img.freeze
486 res = @img.clone
487 assert_equal(res.frozen?, @img.frozen?)
488 end
61e898a Test Image#add_noise_channel
rmagick authored
489
9378160 Test Image#clut_channel
rmagick authored
490 def test_clut_channel
491 img = Magick::Image.new(20,20) {self.colorspace = Magick::GRAYColorspace}
492 clut = Magick::Image.new(20,1) {self.background_color = 'red'}
493 res = nil
494 assert_nothing_raised {res = img.clut_channel(clut)}
495 assert_same(res, img)
496 assert_nothing_raised { img.clut_channel(clut, Magick::RedChannel) }
497 assert_nothing_raised { img.clut_channel(clut, Magick::RedChannel, Magick::BlueChannel) }
498 assert_raises(ArgumentError) { img.clut_channel(clut, 1, Magick::RedChannel) }
499 end
500
47c38aa Last tests for this file
rmagick authored
501 def test_color_fill_to_border
502 assert_raise(ArgumentError) { @img.color_fill_to_border(-1, 1, 'red') }
503 assert_raise(ArgumentError) { @img.color_fill_to_border(1, 100, 'red') }
504 assert_nothing_raised do
505 res = @img.color_fill_to_border(@img.columns/2, @img.rows/2, 'red')
506 assert_instance_of(Magick::Image, res)
507 end
fca6c01 Replace MaxRGB with QuantumRange
rmagick authored
508 pixel = Magick::Pixel.new(Magick::QuantumRange)
47c38aa Last tests for this file
rmagick authored
509 assert_nothing_raised { @img.color_fill_to_border(@img.columns/2, @img.rows/2, pixel) }
510 end
61e898a Test Image#add_noise_channel
rmagick authored
511
47c38aa Last tests for this file
rmagick authored
512 def test_color_floodfill
513 assert_raise(ArgumentError) { @img.color_floodfill(-1, 1, 'red') }
514 assert_raise(ArgumentError) { @img.color_floodfill(1, 100, 'red') }
515 assert_nothing_raised do
516 res = @img.color_floodfill(@img.columns/2, @img.rows/2, 'red')
517 assert_instance_of(Magick::Image, res)
518 end
fca6c01 Replace MaxRGB with QuantumRange
rmagick authored
519 pixel = Magick::Pixel.new(Magick::QuantumRange)
47c38aa Last tests for this file
rmagick authored
520 assert_nothing_raised { @img.color_floodfill(@img.columns/2, @img.rows/2, pixel) }
521 end
61e898a Test Image#add_noise_channel
rmagick authored
522
47c38aa Last tests for this file
rmagick authored
523 def test_color_histogram
524 assert_nothing_raised do
525 res = @img.color_histogram
526 assert_instance_of(Hash, res)
527 end
528 end
61e898a Test Image#add_noise_channel
rmagick authored
529
47c38aa Last tests for this file
rmagick authored
530 def test_colorize
531 assert_nothing_raised do
532 res = @img.colorize(0.25, 0.25, 0.25, 'red')
533 assert_instance_of(Magick::Image, res)
534 end
535 assert_nothing_raised { @img.colorize(0.25, 0.25, 0.25, 0.25, 'red') }
fca6c01 Replace MaxRGB with QuantumRange
rmagick authored
536 pixel = Magick::Pixel.new(Magick::QuantumRange)
47c38aa Last tests for this file
rmagick authored
537 assert_nothing_raised { @img.colorize(0.25, 0.25, 0.25, pixel) }
538 assert_nothing_raised { @img.colorize(0.25, 0.25, 0.25, 0.25, pixel) }
539 assert_raise(ArgumentError) { @img.colorize }
540 assert_raise(ArgumentError) { @img.colorize(0.25) }
541 assert_raise(ArgumentError) { @img.colorize(0.25, 0.25) }
542 assert_raise(ArgumentError) { @img.colorize(0.25, 0.25, 0.25) }
543 assert_raise(ArgumentError) { @img.colorize(0.25, 0.25, 0.25, 'X') }
544 # last argument must be a color name or pixel
545 assert_raise(TypeError) { @img.colorize(0.25, 0.25, 0.25, 0.25) }
546 assert_raise(ArgumentError) { @img.colorize(0.25, 0.25, 0.25, 0.25, 'X') }
547 assert_raise(TypeError) { @img.colorize(0.25, 0.25, 0.25, 0.25, [2]) }
548 end
61e898a Test Image#add_noise_channel
rmagick authored
549
47c38aa Last tests for this file
rmagick authored
550 def test_colormap
551 # IndexError b/c @img is DirectClass
552 assert_raise(IndexError) { @img.colormap(0) }
553 # Read PseudoClass image
554 pc_img = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
555 assert_nothing_raised { pc_img.colormap(0) }
556 ncolors = pc_img.colors
557 assert_raise(IndexError) { pc_img.colormap(ncolors+1) }
558 assert_raise(IndexError) { pc_img.colormap(-1) }
559 assert_nothing_raised { pc_img.colormap(ncolors-1) }
560 res = pc_img.colormap(0)
561 assert_instance_of(String, res)
61e898a Test Image#add_noise_channel
rmagick authored
562
47c38aa Last tests for this file
rmagick authored
563 #test 'set' operation
564 assert_nothing_raised do
565 old_color = pc_img.colormap(0)
566 res = pc_img.colormap(0, 'red')
567 assert_equal(old_color, res)
568 res = pc_img.colormap(0)
569 assert_equal('red', res)
570 end
fca6c01 Replace MaxRGB with QuantumRange
rmagick authored
571 pixel = Magick::Pixel.new(Magick::QuantumRange)
47c38aa Last tests for this file
rmagick authored
572 assert_nothing_raised { pc_img.colormap(0, pixel) }
573 assert_raise(TypeError) { pc_img.colormap(0, [2]) }
574 pc_img.freeze
d98e8e3 Make work with Ruby 1.9.0
rmagick authored
575 assert_raise(FreezeError) { pc_img.colormap(0, 'red') }
47c38aa Last tests for this file
rmagick authored
576 end
61e898a Test Image#add_noise_channel
rmagick authored
577
47c38aa Last tests for this file
rmagick authored
578 def test_color_point
579 assert_nothing_raised do
580 res = @img.color_point(0, 0, 'red')
581 assert_instance_of(Magick::Image, res)
582 assert_not_same(@img, res)
583 end
fca6c01 Replace MaxRGB with QuantumRange
rmagick authored
584 pixel = Magick::Pixel.new(Magick::QuantumRange)
47c38aa Last tests for this file
rmagick authored
585 assert_nothing_raised { @img.color_point(0, 0, pixel) }
586 end
61e898a Test Image#add_noise_channel
rmagick authored
587
47c38aa Last tests for this file
rmagick authored
588 def test_color_reset!
589 assert_nothing_raised do
590 res = @img.color_reset!('red')
591 assert_same(@img, res)
592 end
fca6c01 Replace MaxRGB with QuantumRange
rmagick authored
593 pixel = Magick::Pixel.new(Magick::QuantumRange)
47c38aa Last tests for this file
rmagick authored
594 assert_nothing_raised { @img.color_reset!(pixel) }
595 assert_raise(TypeError) { @img.color_reset!([2]) }
596 assert_raise(ArgumentError) { @img.color_reset!('x') }
597 @img.freeze
d98e8e3 Make work with Ruby 1.9.0
rmagick authored
598 assert_raise(FreezeError) { @img.color_reset!('red') }
47c38aa Last tests for this file
rmagick authored
599 end
61e898a Test Image#add_noise_channel
rmagick authored
600
56ea702 Merge new tests
rmagick authored
601 def test_combine
602 r = Magick::Image.new(20,20) { self.background_color = 'red' }
603 g = Magick::Image.new(20,20) { self.background_color = 'green' }
604 b = Magick::Image.new(20,20) { self.background_color = 'blue' }
605 a = Magick::Image.new(20,20) { self.background_color = 'transparent' }
606 assert_nothing_raised { Magick::Image.combine(r) }
607 assert_nothing_raised { Magick::Image.combine(r, g) }
608 assert_nothing_raised { Magick::Image.combine(r, g, b) }
609 assert_nothing_raised { Magick::Image.combine(r, g, b, a) }
610 assert_nothing_raised { Magick::Image.combine(nil, g) }
611 assert_nothing_raised { Magick::Image.combine(r, nil, b) }
612 assert_nothing_raised { Magick::Image.combine(r, g, nil, a) }
613 assert_nothing_raised { Magick::Image.combine(r, g, b, nil) }
614 res = Magick::Image.combine(r, g, b)
615 assert_instance_of(Magick::Image, res)
616 assert_raise(ArgumentError) { Magick::Image.combine() }
617 assert_raise(ArgumentError) { Magick::Image.combine(nil) }
618 assert_raise(ArgumentError) { Magick::Image.combine(r, g, b, a, r) }
619 assert_raise(TypeError) { Magick::Image.combine(1, g, b, a) }
620 end
621
47c38aa Last tests for this file
rmagick authored
622 def test_compare_channel
623 img1 = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
624 img2 = Magick::Image.read(IMAGES_DIR+'/Button_1.gif').first
625 assert_nothing_raised { img1.compare_channel(img2, Magick::MeanAbsoluteErrorMetric) }
626 assert_nothing_raised { img1.compare_channel(img2, Magick::MeanSquaredErrorMetric) }
627 assert_nothing_raised { img1.compare_channel(img2, Magick::PeakAbsoluteErrorMetric) }
628 assert_nothing_raised { img1.compare_channel(img2, Magick::PeakSignalToNoiseRatioMetric) }
629 assert_nothing_raised { img1.compare_channel(img2, Magick::RootMeanSquaredErrorMetric) }
630 assert_raise(TypeError) { img1.compare_channel(img2, 2) }
631 assert_raise(ArgumentError) { img1.compare_channel }
61e898a Test Image#add_noise_channel
rmagick authored
632
47c38aa Last tests for this file
rmagick authored
633 ilist = Magick::ImageList.new
634 ilist << img2
61e898a Test Image#add_noise_channel
rmagick authored
635 assert_nothing_raised { img1.compare_channel(ilist, Magick::MeanAbsoluteErrorMetric) }
636
47c38aa Last tests for this file
rmagick authored
637 assert_nothing_raised { img1.compare_channel(img2, Magick::MeanAbsoluteErrorMetric, Magick::RedChannel) }
638 assert_nothing_raised { img1.compare_channel(img2, Magick::MeanAbsoluteErrorMetric, Magick::RedChannel, Magick::BlueChannel) }
cb5ecfe Assert TypeError raised when ChannelType arg expected but not received
rmagick authored
639 assert_raise(TypeError) { img1.compare_channel(img2, Magick::MeanAbsoluteErrorMetric, 2) }
640 assert_raise(TypeError) { img1.compare_channel(img2, Magick::MeanAbsoluteErrorMetric, Magick::RedChannel, 2) }
61e898a Test Image#add_noise_channel
rmagick authored
641
47c38aa Last tests for this file
rmagick authored
642 res = img1.compare_channel(img2, Magick::MeanAbsoluteErrorMetric)
643 assert_instance_of(Array, res)
644 assert_instance_of(Magick::Image, res[0])
645 assert_instance_of(Float, res[1])
bec1e09 Add tests for image arguments that have been destroyed
rmagick authored
646
647 img2.destroy!
648 assert_raise(Magick::DestroyedImageError) { img1.compare_channel(img2, Magick::MeanAbsoluteErrorMetric) }
47c38aa Last tests for this file
rmagick authored
649 end
61e898a Test Image#add_noise_channel
rmagick authored
650
47c38aa Last tests for this file
rmagick authored
651 def test_composite
652 img1 = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
653 img2 = Magick::Image.read(IMAGES_DIR+'/Button_1.gif').first
61e898a Test Image#add_noise_channel
rmagick authored
654
47c38aa Last tests for this file
rmagick authored
655 assert_raise(ArgumentError) { img1.composite }
656 assert_raise(ArgumentError) { img1.composite(img2) }
657 assert_raise(ArgumentError) { img1.composite(img2, Magick::NorthWestGravity) }
658 assert_raise(ArgumentError) { img1.composite(2) }
659 assert_raise(ArgumentError) { img1.composite(img2, 2) }
61e898a Test Image#add_noise_channel
rmagick authored
660
47c38aa Last tests for this file
rmagick authored
661 composite_ops = [
662 Magick::UndefinedCompositeOp,
663 Magick::NoCompositeOp,
664 Magick::AddCompositeOp,
665 Magick::AtopCompositeOp,
666 Magick::BumpmapCompositeOp,
667 Magick::ClearCompositeOp,
668 Magick::ColorizeCompositeOp,
669 Magick::CopyBlueCompositeOp,
670 Magick::CopyCompositeOp,
671 Magick::CopyGreenCompositeOp,
672 Magick::CopyOpacityCompositeOp,
673 Magick::CopyRedCompositeOp,
674 Magick::CopyCyanCompositeOp,
675 Magick::CopyMagentaCompositeOp,
676 Magick::CopyYellowCompositeOp,
677 Magick::CopyBlackCompositeOp,
678 Magick::DarkenCompositeOp,
679 Magick::DifferenceCompositeOp,
680 Magick::DisplaceCompositeOp,
681 Magick::DissolveCompositeOp,
61e898a Test Image#add_noise_channel
rmagick authored
682 Magick::DstAtopCompositeOp,
47c38aa Last tests for this file
rmagick authored
683 Magick::DstCompositeOp,
684 Magick::DstInCompositeOp,
685 Magick::DstOutCompositeOp,
686 Magick::DstOverCompositeOp,
687 Magick::HueCompositeOp,
688 Magick::InCompositeOp,
689 Magick::LightenCompositeOp,
690 Magick::LuminizeCompositeOp,
691 Magick::MinusCompositeOp,
692 Magick::ModulateCompositeOp,
693 Magick::MultiplyCompositeOp,
694 Magick::OutCompositeOp,
695 Magick::OverCompositeOp,
696 Magick::OverlayCompositeOp,
697 Magick::PlusCompositeOp,
61e898a Test Image#add_noise_channel
rmagick authored
698 Magick::ReplaceCompositeOp,
47c38aa Last tests for this file
rmagick authored
699 Magick::SaturateCompositeOp,
700 Magick::ScreenCompositeOp,
701 Magick::SrcAtopCompositeOp,
702 Magick::SrcCompositeOp,
703 Magick::SrcInCompositeOp,
704 Magick::SrcOutCompositeOp,
705 Magick::SrcOverCompositeOp,
706 Magick::SubtractCompositeOp,
707 Magick::ThresholdCompositeOp,
708 Magick::XorCompositeOp,
709 Magick::BlendCompositeOp,
710 Magick::ColorBurnCompositeOp,
711 Magick::ColorDodgeCompositeOp,
712 Magick::ExclusionCompositeOp,
713 Magick::HardLightCompositeOp,
714 Magick::SoftLightCompositeOp]
715 gravity = [
716 Magick::NorthEastGravity,
717 Magick::EastGravity,
718 Magick::SouthWestGravity,
719 Magick::SouthGravity,
720 Magick::SouthEastGravity]
61e898a Test Image#add_noise_channel
rmagick authored
721
722 # 4 argument form
723 assert_nothing_raised { img1.composite(img2, 0, 0, Magick::OverCompositeOp) }
47c38aa Last tests for this file
rmagick authored
724 # there's way too many CompositeOperators to test them all, so just try few representative ops
725 composite_ops.each do |op|
726 assert_nothing_raised { img1.composite(img2, 0, 0, op) }
61e898a Test Image#add_noise_channel
rmagick authored
727 end
47c38aa Last tests for this file
rmagick authored
728 res = img1.composite(img2, 0, 0, Magick::OverCompositeOp)
729 assert_instance_of(Magick::Image, res)
730 assert_raise(TypeError) { img1.composite(img2, 0, 0, 2) }
61e898a Test Image#add_noise_channel
rmagick authored
731
47c38aa Last tests for this file
rmagick authored
732 # 3 argument form
733 composite_ops.each do |op|
734 gravity.each do |grav|
735 assert_nothing_raised { img1.composite(img2, grav, op) }
736 end
737 end
738 assert_raise(TypeError) { img1.composite(img2, 2, Magick::OverCompositeOp) }
61e898a Test Image#add_noise_channel
rmagick authored
739
47c38aa Last tests for this file
rmagick authored
740 # 5-argument form
741 composite_ops.each do |op|
742 gravity.each do |grav|
743 assert_nothing_raised { img1.composite(img2, grav, 0, 0, op) }
744 end
745 end
746 assert_raise(TypeError) { img1.composite(img2, 0, 0, 2, Magick::OverCompositeOp) }
bec1e09 Add tests for image arguments that have been destroyed
rmagick authored
747
bda43d7 composite method raises exception for negative offsets
rmagick authored
748 # negative offsets raise an exception
749 assert_raise(Magick::ImageMagickError) { img1.composite(img2, -10, -10, Magick::OverCompositeOp) }
750
bec1e09 Add tests for image arguments that have been destroyed
rmagick authored
751 img2.destroy!
752 assert_raise(Magick::DestroyedImageError) { img1.composite(img2, Magick::CenterGravity, Magick::OverCompositeOp) }
47c38aa Last tests for this file
rmagick authored
753 end
61e898a Test Image#add_noise_channel
rmagick authored
754
755
281c16e New
rmagick authored
756 end
757
758 if __FILE__ == $0
759 IMAGES_DIR = '../doc/ex/images'
760 FILES = Dir[IMAGES_DIR+'/Button_*.gif']
95bba79 Update to work with new test/unit in 1.9.1
rmagick authored
761 Test::Unit::UI::Console::TestRunner.run(Image1_UT) if RUBY_VERSION != '1.9.1'
281c16e New
rmagick authored
762 end
Something went wrong with that request. Please try again.