rmagick 2.13.2 → 2.13.3.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rmagick might be problematic. Click here for more details.

Files changed (185) hide show
  1. checksums.yaml +15 -0
  2. data/LICENSE +20 -0
  3. data/README +15 -0
  4. data/README.rc +231 -0
  5. data/build_tarball.rake +1 -1
  6. data/doc/comtasks.html +2 -2
  7. data/doc/constants.html +2 -2
  8. data/doc/draw.html +2 -2
  9. data/doc/ex/PreserveAspectRatio.rb +0 -0
  10. data/doc/ex/ViewBox.rb +0 -0
  11. data/doc/ex/adaptive_threshold.rb +0 -0
  12. data/doc/ex/add_noise.rb +0 -0
  13. data/doc/ex/affine.rb +0 -0
  14. data/doc/ex/affine_transform.rb +0 -0
  15. data/doc/ex/arc.rb +0 -0
  16. data/doc/ex/arcpath.rb +0 -0
  17. data/doc/ex/average.rb +0 -0
  18. data/doc/ex/axes.rb +0 -0
  19. data/doc/ex/bilevel_channel.rb +0 -0
  20. data/doc/ex/blur_image.rb +0 -0
  21. data/doc/ex/border.rb +0 -0
  22. data/doc/ex/bounding_box.rb +0 -0
  23. data/doc/ex/cbezier1.rb +0 -0
  24. data/doc/ex/cbezier2.rb +0 -0
  25. data/doc/ex/cbezier3.rb +0 -0
  26. data/doc/ex/cbezier4.rb +0 -0
  27. data/doc/ex/cbezier5.rb +0 -0
  28. data/doc/ex/cbezier6.rb +0 -0
  29. data/doc/ex/channel.rb +0 -0
  30. data/doc/ex/charcoal.rb +0 -0
  31. data/doc/ex/chop.rb +0 -0
  32. data/doc/ex/circle.rb +0 -0
  33. data/doc/ex/clip_path.rb +0 -0
  34. data/doc/ex/coalesce.rb +0 -0
  35. data/doc/ex/color_fill_to_border.rb +0 -0
  36. data/doc/ex/color_floodfill.rb +0 -0
  37. data/doc/ex/color_histogram.rb +0 -0
  38. data/doc/ex/color_reset.rb +0 -0
  39. data/doc/ex/colorize.rb +0 -0
  40. data/doc/ex/colors.rb +0 -0
  41. data/doc/ex/composite.rb +0 -0
  42. data/doc/ex/composite_layers.rb +0 -0
  43. data/doc/ex/contrast.rb +0 -0
  44. data/doc/ex/crop.rb +0 -0
  45. data/doc/ex/cycle_colormap.rb +0 -0
  46. data/doc/ex/drawcomp.rb +0 -0
  47. data/doc/ex/drop_shadow.rb +0 -0
  48. data/doc/ex/edge.rb +0 -0
  49. data/doc/ex/ellipse.rb +0 -0
  50. data/doc/ex/emboss.rb +0 -0
  51. data/doc/ex/enhance.rb +0 -0
  52. data/doc/ex/equalize.rb +0 -0
  53. data/doc/ex/evenodd.rb +0 -0
  54. data/doc/ex/flatten_images.rb +0 -0
  55. data/doc/ex/flip.rb +0 -0
  56. data/doc/ex/flop.rb +0 -0
  57. data/doc/ex/fonts.rb +0 -0
  58. data/doc/ex/frame.rb +0 -0
  59. data/doc/ex/gaussian_blur.rb +0 -0
  60. data/doc/ex/get_pixels.rb +0 -0
  61. data/doc/ex/gradientfill.rb +0 -0
  62. data/doc/ex/grav.rb +0 -0
  63. data/doc/ex/gravity.rb +0 -0
  64. data/doc/ex/hatchfill.rb +0 -0
  65. data/doc/ex/images/logo400x83.gif +0 -0
  66. data/doc/ex/implode.rb +0 -0
  67. data/doc/ex/level.rb +0 -0
  68. data/doc/ex/line.rb +0 -0
  69. data/doc/ex/matte_fill_to_border.rb +0 -0
  70. data/doc/ex/matte_floodfill.rb +0 -0
  71. data/doc/ex/matte_replace.rb +0 -0
  72. data/doc/ex/median_filter.rb +0 -0
  73. data/doc/ex/modulate.rb +0 -0
  74. data/doc/ex/mono.rb +0 -0
  75. data/doc/ex/morph.rb +0 -0
  76. data/doc/ex/mosaic.rb +0 -0
  77. data/doc/ex/motion_blur.rb +0 -0
  78. data/doc/ex/negate.rb +0 -0
  79. data/doc/ex/nested_rvg.rb +0 -0
  80. data/doc/ex/nonzero.rb +0 -0
  81. data/doc/ex/normalize.rb +0 -0
  82. data/doc/ex/oil_paint.rb +0 -0
  83. data/doc/ex/opacity.rb +0 -0
  84. data/doc/ex/ordered_dither.rb +0 -0
  85. data/doc/ex/path.rb +0 -0
  86. data/doc/ex/pattern1.rb +0 -0
  87. data/doc/ex/pattern2.rb +0 -0
  88. data/doc/ex/polygon.rb +0 -0
  89. data/doc/ex/polyline.rb +0 -0
  90. data/doc/ex/preview.rb +0 -0
  91. data/doc/ex/qbezierpath.rb +0 -0
  92. data/doc/ex/quantize-m.rb +0 -0
  93. data/doc/ex/radial_blur.rb +0 -0
  94. data/doc/ex/raise.rb +0 -0
  95. data/doc/ex/rectangle.rb +0 -0
  96. data/doc/ex/reduce_noise.rb +0 -0
  97. data/doc/ex/roll.rb +0 -0
  98. data/doc/ex/rotate.rb +0 -0
  99. data/doc/ex/rotate_f.rb +0 -0
  100. data/doc/ex/roundrect.rb +0 -0
  101. data/doc/ex/rubyname.rb +0 -0
  102. data/doc/ex/rvg_linecap.rb +0 -0
  103. data/doc/ex/rvg_linejoin.rb +0 -0
  104. data/doc/ex/rvg_opacity.rb +0 -0
  105. data/doc/ex/rvg_stroke_dasharray.rb +0 -0
  106. data/doc/ex/segment.rb +0 -0
  107. data/doc/ex/shade.rb +0 -0
  108. data/doc/ex/shave.rb +0 -0
  109. data/doc/ex/shear.rb +0 -0
  110. data/doc/ex/sketch.rb +0 -0
  111. data/doc/ex/skewx.rb +0 -0
  112. data/doc/ex/skewy.rb +0 -0
  113. data/doc/ex/smile.rb +0 -0
  114. data/doc/ex/solarize.rb +0 -0
  115. data/doc/ex/spread.rb +0 -0
  116. data/doc/ex/stegano.rb +0 -0
  117. data/doc/ex/stroke_dasharray.rb +0 -0
  118. data/doc/ex/stroke_fill.rb +0 -0
  119. data/doc/ex/stroke_linecap.rb +0 -0
  120. data/doc/ex/stroke_linejoin.rb +0 -0
  121. data/doc/ex/stroke_width.rb +0 -0
  122. data/doc/ex/swirl.rb +0 -0
  123. data/doc/ex/text.rb +0 -0
  124. data/doc/ex/text_align.rb +0 -0
  125. data/doc/ex/text_antialias.rb +0 -0
  126. data/doc/ex/text_undercolor.rb +0 -0
  127. data/doc/ex/texture_fill_to_border.rb +0 -0
  128. data/doc/ex/texture_floodfill.rb +0 -0
  129. data/doc/ex/texturefill.rb +0 -0
  130. data/doc/ex/threshold.rb +0 -0
  131. data/doc/ex/to_blob.rb +0 -0
  132. data/doc/ex/translate.rb +0 -0
  133. data/doc/ex/transparent.rb +0 -0
  134. data/doc/ex/unsharp_mask.rb +0 -0
  135. data/doc/ex/wave.rb +0 -0
  136. data/doc/ilist.html +2 -2
  137. data/doc/image1.html +2 -2
  138. data/doc/image2.html +2 -2
  139. data/doc/image3.html +2 -2
  140. data/doc/imageattrs.html +2 -2
  141. data/doc/imusage.html +2 -2
  142. data/doc/index.html +3 -3
  143. data/doc/info.html +2 -2
  144. data/doc/magick.html +2 -2
  145. data/doc/optequiv.html +2 -2
  146. data/doc/rvg.html +2 -2
  147. data/doc/rvgclip.html +2 -2
  148. data/doc/rvggroup.html +2 -2
  149. data/doc/rvgimage.html +2 -2
  150. data/doc/rvgpattern.html +2 -2
  151. data/doc/rvgshape.html +2 -2
  152. data/doc/rvgstyle.html +2 -2
  153. data/doc/rvgtext.html +2 -2
  154. data/doc/rvgtspan.html +2 -2
  155. data/doc/rvgtut.html +2 -2
  156. data/doc/rvguse.html +2 -2
  157. data/doc/rvgxform.html +2 -2
  158. data/doc/struct.html +2 -2
  159. data/doc/usage.html +2 -2
  160. data/examples/crop_with_gravity.rb +0 -0
  161. data/examples/demo.rb +0 -0
  162. data/examples/describe.rb +0 -0
  163. data/examples/rotating_text.rb +0 -0
  164. data/ext/RMagick/extconf.rb +1 -9
  165. data/ext/RMagick/rmimage.c +1 -1
  166. data/lib/rvg/to_c.rb +103 -0
  167. data/rmagick.gemspec +5 -3
  168. data/test/Draw.rb +121 -0
  169. data/test/Image1.rb +763 -0
  170. data/test/Image2.rb +1308 -0
  171. data/test/Image3.rb +1002 -0
  172. data/test/ImageList1.rb +808 -0
  173. data/test/ImageList2.rb +389 -0
  174. data/test/Image_attributes.rb +683 -0
  175. data/test/Import_Export.rb +116 -0
  176. data/test/Info.rb +349 -0
  177. data/test/Magick.rb +364 -0
  178. data/test/Pixel.rb +120 -0
  179. data/test/Preview.rb +62 -0
  180. data/test/all_basic.rb +42 -0
  181. data/test/cmyk.icm +0 -0
  182. data/test/srgb.icm +0 -0
  183. metadata +339 -320
  184. data/README.html +0 -10
  185. data/ext/RMagick/MANIFEST +0 -358
@@ -0,0 +1,1308 @@
1
+ #! /usr/local/bin/ruby -w
2
+
3
+ require 'RMagick'
4
+ require 'test/unit'
5
+ require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
6
+
7
+ # TODO: improve exif tests - need a benchmark image with EXIF data
8
+
9
+
10
+ class Image2_UT < Test::Unit::TestCase
11
+ FreezeError = RUBY_VERSION[/^1\.9|^2/] ? RuntimeError : TypeError
12
+
13
+ def setup
14
+ @img = Magick::Image.new(20, 20)
15
+ end
16
+
17
+ def test_composite!
18
+ img1 = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
19
+ img2 = Magick::Image.read(IMAGES_DIR+'/Button_1.gif').first
20
+ assert_nothing_raised do
21
+ res = img1.composite!(img2, Magick::NorthWestGravity, Magick::OverCompositeOp)
22
+ assert_same(img1, res)
23
+ end
24
+ img1.freeze
25
+ assert_raise(FreezeError) { img1.composite!(img2, Magick::NorthWestGravity, Magick::OverCompositeOp) }
26
+ end
27
+
28
+ def test_composite_affine
29
+ affine = Magick::AffineMatrix.new(1, 0, 1, 0, 0, 0)
30
+ img1 = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
31
+ img2 = Magick::Image.read(IMAGES_DIR+'/Button_1.gif').first
32
+ assert_nothing_raised do
33
+ res = img1.composite_affine(img2, affine)
34
+ assert_instance_of(Magick::Image, res)
35
+ assert_not_same(@img, res)
36
+ end
37
+ end
38
+
39
+ def test_composite_mathematics
40
+ bg = Magick::Image.new(50, 50)
41
+ fg = Magick::Image.new(50, 50) {self.background_color = "black" }
42
+ res = nil
43
+ assert_nothing_raised { res = bg.composite_mathematics(fg, 1, 0, 0, 0, Magick::CenterGravity) }
44
+ assert_instance_of(Magick::Image, res)
45
+ assert_not_same(bg, res)
46
+ assert_not_same(fg, res)
47
+ assert_nothing_raised { res = bg.composite_mathematics(fg, 1, 0, 0, 0, 0.0, 0.0) }
48
+ assert_nothing_raised { res = bg.composite_mathematics(fg, 1, 0, 0, 0, Magick::CenterGravity, 0.0, 0.0) }
49
+
50
+ # too few arguments
51
+ assert_raise(ArgumentError) { bg.composite_mathematics(fg, 1, 0, 0, 0) }
52
+ # too many arguments
53
+ assert_raise(ArgumentError) { bg.composite_mathematics(fg, 1, 0, 0, 0, Magick::CenterGravity, 0.0, 0.0, 'x') }
54
+ end
55
+
56
+ def test_composite_tiled
57
+ bg = Magick::Image.new(200,200)
58
+ fg = Magick::Image.new(50,100) { self.background_color = "black" }
59
+ res = nil
60
+ assert_nothing_raised do
61
+ res = bg.composite_tiled(fg)
62
+ end
63
+ assert_instance_of(Magick::Image, res)
64
+ assert_not_same(bg, res)
65
+ assert_not_same(fg, res)
66
+ assert_nothing_raised { bg.composite_tiled!(fg) }
67
+ assert_nothing_raised { bg.composite_tiled(fg, Magick::AtopCompositeOp) }
68
+ assert_nothing_raised { bg.composite_tiled(fg, Magick::OverCompositeOp) }
69
+ assert_nothing_raised { bg.composite_tiled(fg, Magick::RedChannel) }
70
+ assert_nothing_raised { bg.composite_tiled(fg, Magick::RedChannel, Magick::GreenChannel) }
71
+
72
+ fg.destroy!
73
+ assert_raise(Magick::DestroyedImageError) { bg.composite_tiled(fg) }
74
+ end
75
+
76
+ def test_compress_colormap!
77
+ # DirectClass images are converted to PseudoClass
78
+ assert_equal(Magick::DirectClass, @img.class_type)
79
+ assert_nothing_raised { @img.compress_colormap! }
80
+ assert_equal(Magick::PseudoClass, @img.class_type)
81
+ img = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
82
+ assert_equal(Magick::PseudoClass, @img.class_type)
83
+ assert_nothing_raised { @img.compress_colormap! }
84
+ end
85
+
86
+ def test_contrast
87
+ assert_nothing_raised do
88
+ res = @img.contrast
89
+ assert_instance_of(Magick::Image, res)
90
+ assert_not_same(@img, res)
91
+ end
92
+ assert_nothing_raised { @img.contrast(true) }
93
+ assert_raise(ArgumentError) { @img.contrast(true, 2) }
94
+ end
95
+
96
+ def test_contrast_stretch_channel
97
+ assert_nothing_raised do
98
+ res = @img.contrast_stretch_channel(25)
99
+ assert_instance_of(Magick::Image, res)
100
+ assert_not_same(@img, res)
101
+ end
102
+ assert_nothing_raised { @img.contrast_stretch_channel(25, 50) }
103
+ assert_nothing_raised { @img.contrast_stretch_channel('10%') }
104
+ assert_nothing_raised { @img.contrast_stretch_channel('10%', '50%') }
105
+ assert_nothing_raised { @img.contrast_stretch_channel(25, 50, Magick::RedChannel) }
106
+ assert_nothing_raised { @img.contrast_stretch_channel(25, 50, Magick::RedChannel, Magick::GreenChannel) }
107
+ assert_raise(TypeError) { @img.contrast_stretch_channel(25, 50, 'x') }
108
+ assert_raise(ArgumentError) { @img.contrast_stretch_channel }
109
+ assert_raise(ArgumentError) { @img.contrast_stretch_channel('x') }
110
+ assert_raise(ArgumentError) { @img.contrast_stretch_channel(25, 'x') }
111
+
112
+ end
113
+
114
+ def test_convolve
115
+ kernel = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
116
+ order = 3
117
+ assert_nothing_raised do
118
+ res = @img.convolve(order, kernel)
119
+ assert_instance_of(Magick::Image, res)
120
+ assert_not_same(@img, res)
121
+ end
122
+ assert_raise(ArgumentError) { @img.convolve }
123
+ assert_raise(ArgumentError) { @img.convolve(order) }
124
+ assert_raise(IndexError) { @img.convolve(5, kernel) }
125
+ assert_raise(IndexError) { @img.convolve(order, "x") }
126
+ assert_raise(TypeError) { @img.convolve(3, [1.0, 1.0, 1.0, 1.0, 'x', 1.0, 1.0, 1.0, 1.0]) }
127
+ assert_raise(Magick::ImageMagickError) { @img.convolve(2, [1.0, 1.0, 1.0, 1.0]) }
128
+ end
129
+
130
+ def test_convolve_channel
131
+ assert_raise(ArgumentError) { @img.convolve_channel }
132
+ assert_raise(ArgumentError) { @img.convolve_channel(3) }
133
+ kernel = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
134
+ order = 3
135
+ assert_nothing_raised do
136
+ res = @img.convolve_channel(order, kernel, Magick::RedChannel)
137
+ assert_instance_of(Magick::Image, res)
138
+ assert_not_same(@img, res)
139
+ end
140
+
141
+ assert_nothing_raised { @img.convolve_channel(order, kernel, Magick::RedChannel, Magick:: BlueChannel) }
142
+ assert_raise(TypeError) { @img.convolve_channel(order, kernel, Magick::RedChannel, 2) }
143
+ end
144
+
145
+ def test_copy
146
+ assert_nothing_raised do
147
+ ditto = @img.copy
148
+ assert_equal(@img, ditto)
149
+ end
150
+ ditto = @img.copy
151
+ assert_equal(@img.tainted?, ditto.tainted?)
152
+ @img.taint
153
+ ditto = @img.copy
154
+ assert_equal(@img.tainted?, ditto.tainted?)
155
+ end
156
+
157
+ def test_crop
158
+ assert_raise(ArgumentError) { @img.crop }
159
+ assert_raise(ArgumentError) { @img.crop(0, 0) }
160
+ assert_nothing_raised do
161
+ res = @img.crop(0, 0, @img.columns/2, @img.rows/2)
162
+ assert_instance_of(Magick::Image, res)
163
+ assert_not_same(@img, res)
164
+ end
165
+ gravity = [
166
+ Magick::NorthEastGravity,
167
+ Magick::EastGravity,
168
+ Magick::SouthWestGravity,
169
+ Magick::SouthGravity,
170
+ Magick::SouthEastGravity]
171
+
172
+ # 3-argument form
173
+ gravity.each do |grav|
174
+ assert_nothing_raised { @img.crop(grav, @img.columns/2, @img.rows/2) }
175
+ end
176
+ assert_raise(TypeError) { @img.crop(2, @img.columns/2, @img.rows/2) }
177
+ assert_raise(TypeError) { @img.crop(Magick::NorthWestGravity, @img.columns/2, @img.rows/2, 2) }
178
+
179
+ # 4-argument form
180
+ assert_raise(TypeError) { @img.crop(0, 0, @img.columns/2, 'x') }
181
+ assert_raise(TypeError) { @img.crop(0, 0, 'x', @img.rows/2) }
182
+ assert_raise(TypeError) { @img.crop(0, 'x', @img.columns/2, @img.rows/2) }
183
+ assert_raise(TypeError) { @img.crop('x', 0, @img.columns/2, @img.rows/2) }
184
+ assert_raise(TypeError) { @img.crop(0, 0, @img.columns/2, @img.rows/2, 2) }
185
+
186
+ # 5-argument form
187
+ gravity.each do |grav|
188
+ assert_nothing_raised { @img.crop(grav, 0, 0, @img.columns/2, @img.rows/2) }
189
+ end
190
+
191
+ assert_raise(ArgumentError) { @img.crop(Magick::NorthWestGravity, 0, 0, @img.columns/2, @img.rows/2, 2) }
192
+ end
193
+
194
+ def test_crop!
195
+ assert_nothing_raised do
196
+ res = @img.crop!(0, 0, @img.columns/2, @img.rows/2)
197
+ assert_same(@img, res)
198
+ end
199
+ end
200
+
201
+ def test_cycle_colormap
202
+ assert_nothing_raised do
203
+ res = @img.cycle_colormap(5)
204
+ assert_instance_of(Magick::Image, res)
205
+ assert_not_same(@img, res)
206
+ assert_equal(Magick::PseudoClass, res.class_type)
207
+ end
208
+ end
209
+
210
+ def test_decipher # tests encipher, too.
211
+ res = res2 = nil
212
+ assert_nothing_raised do
213
+ res = @img.encipher "passphrase"
214
+ res2 = res.decipher "passphrase"
215
+ end
216
+ assert_instance_of(Magick::Image, res)
217
+ assert_not_same(@img, res)
218
+ assert_equal(@img.columns, res.columns)
219
+ assert_equal(@img.rows, res.rows)
220
+ assert_instance_of(Magick::Image, res2)
221
+ assert_not_same(@img, res2)
222
+ assert_equal(@img.columns, res2.columns)
223
+ assert_equal(@img.rows, res2.rows)
224
+ assert_equal(@img, res2)
225
+ end
226
+
227
+ def test_define
228
+ assert_nothing_raised { @img.define("deskew:auto-crop", 40) }
229
+ assert_nothing_raised { @img.undefine("deskew:auto-crop") }
230
+ end
231
+
232
+ def test_deskew
233
+ assert_nothing_raised do
234
+ res = @img.deskew
235
+ assert_instance_of(Magick::Image, res)
236
+ assert_not_same(@img, res)
237
+ end
238
+
239
+ assert_nothing_raised { @img.deskew(0.10) }
240
+ assert_nothing_raised { @img.deskew("95%") }
241
+ assert_raise(ArgumentError) { @img.deskew("x") }
242
+ assert_raise(TypeError) {@img.deskew(0.40, "x") }
243
+ assert_raise(ArgumentError) {@img.deskew(0.40, 20, [1]) }
244
+ end
245
+
246
+ def test_despeckle
247
+ assert_nothing_raised do
248
+ res = @img.despeckle
249
+ assert_instance_of(Magick::Image, res)
250
+ assert_not_same(@img, res)
251
+ end
252
+ end
253
+
254
+ # ensure methods detect destroyed images
255
+ def test_destroy
256
+ methods = Magick::Image.instance_methods(false).sort
257
+ if RUBY_VERSION[/^1\.9|^2/]
258
+ methods -= [:__display__, :destroy!, :destroyed?, :inspect, :cur_image, :marshal_load]
259
+ else
260
+ methods -= %w{ __display__ destroy! destroyed? inspect cur_image marshal_load}
261
+ end
262
+
263
+ assert_equal(false, @img.destroyed?)
264
+ @img.destroy!
265
+ assert_equal(true, @img.destroyed?)
266
+ assert_raises(Magick::DestroyedImageError) { @img.check_destroyed }
267
+
268
+ methods.each do |method|
269
+ arity = @img.method(method).arity
270
+ method = method.to_s
271
+
272
+ case
273
+ when method == "[]="
274
+ assert_raises(Magick::DestroyedImageError) { @img['foo'] = 1 }
275
+ when method == "difference"
276
+ other = Magick::Image.new(20,20)
277
+ assert_raises(Magick::DestroyedImageError) { @img.difference(other) }
278
+ when method == "get_iptc_dataset"
279
+ assert_raises(Magick::DestroyedImageError) { @img.get_iptc_dataset('x') }
280
+ when method == "profile!"
281
+ assert_raises(Magick::DestroyedImageError) { @img.profile!('x', 'y') }
282
+ when /=\Z/.match(method)
283
+ assert_raises(Magick::DestroyedImageError) { @img.send(method, 1) }
284
+ when arity == 0
285
+ assert_raises(Magick::DestroyedImageError) { @img.send(method) }
286
+ when arity < 0
287
+ args = (1..(-arity)).to_a
288
+ assert_raises(Magick::DestroyedImageError) { @img.send(method, *args) }
289
+ when arity > 0
290
+ args = (1..(arity)).to_a
291
+ assert_raises(Magick::DestroyedImageError) { @img.send(method, *args) }
292
+ else
293
+ # Don't know how to test!
294
+ flunk("don't know how to test method #{method}" )
295
+ end
296
+ end
297
+ end
298
+
299
+ # ensure destroy! works
300
+ def test_destroy2
301
+ begin # ensure Magick.trace_proc gets set to nil even if this test asserts
302
+ images = {}
303
+ GC.disable
304
+ Magick.trace_proc = Proc.new do |which, id, addr, method|
305
+ m = id.split(/ /)
306
+ name = File.basename m[0]
307
+ format = m[1]
308
+ size = m[2]
309
+ geometry = m[3]
310
+ image_class = m[4]
311
+
312
+ assert(which == :c || which == :d, "unexpected value for which: #{which}")
313
+ assert_equal(:destroy!, method) if which == :d
314
+ if which == :c
315
+ assert(!images.has_key?(addr), "duplicate image addresses")
316
+ images[addr] = name
317
+ else
318
+ assert(images.has_key?(addr), "destroying image that was not created")
319
+ assert_equal(name, images[addr])
320
+ end
321
+ end
322
+ unmapped = Magick::ImageList.new(IMAGES_DIR+"/Hot_Air_Balloons.jpg", IMAGES_DIR+"/Violin.jpg", IMAGES_DIR+"/Polynesia.jpg")
323
+ map = Magick::ImageList.new "netscape:"
324
+ mapped = unmapped.map map, false
325
+ unmapped.each {|i| i.destroy!}
326
+ map.destroy!
327
+ mapped.each {|i| i.destroy!}
328
+ ensure
329
+ GC.enable
330
+ Magick.trace_proc = nil
331
+ end
332
+ end
333
+
334
+ def test_difference
335
+ img1 = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
336
+ img2 = Magick::Image.read(IMAGES_DIR+'/Button_1.gif').first
337
+ assert_nothing_raised do
338
+ res = img1.difference(img2)
339
+ assert_instance_of(Array, res)
340
+ assert_equal(3, res.length)
341
+ assert_instance_of(Float, res[0])
342
+ assert_instance_of(Float, res[1])
343
+ assert_instance_of(Float, res[2])
344
+ end
345
+
346
+ assert_raise(NoMethodError) { img1.difference(2) }
347
+ img2.destroy!
348
+ assert_raise(Magick::DestroyedImageError) { img1.difference(img2) }
349
+ end
350
+
351
+ def test_displace
352
+ @img2 = Magick::Image.new(20,20) {self.background_color = "black"}
353
+ assert_nothing_raised { @img.displace(@img2, 25) }
354
+ res = @img.displace(@img2, 25)
355
+ assert_instance_of(Magick::Image, res)
356
+ assert_not_same(@img, res)
357
+ assert_nothing_raised { @img.displace(@img2, 25, 25) }
358
+ assert_nothing_raised { @img.displace(@img2, 25, 25, 10) }
359
+ assert_nothing_raised { @img.displace(@img2, 25, 25, 10, 10) }
360
+ assert_nothing_raised { @img.displace(@img2, 25, 25, Magick::CenterGravity) }
361
+ assert_nothing_raised { @img.displace(@img2, 25, 25, Magick::CenterGravity, 10) }
362
+ assert_nothing_raised { @img.displace(@img2, 25, 25, Magick::CenterGravity, 10, 10) }
363
+ assert_raise(ArgumentError) { @img.displace }
364
+ assert_raise(TypeError) { @img.displace(@img2, 'x') }
365
+ assert_raise(TypeError) { @img.displace(@img2, 25, []) }
366
+ assert_raise(TypeError) { @img.displace(@img2, 25, 25, 'x') }
367
+ assert_raise(TypeError) { @img.displace(@img2, 25, 25, Magick::CenterGravity, 'x') }
368
+ assert_raise(TypeError) { @img.displace(@img2, 25, 25, Magick::CenterGravity, 10, []) }
369
+
370
+ @img2.destroy!
371
+ assert_raise(Magick::DestroyedImageError) { @img.displace(@img2, 25, 25) }
372
+ end
373
+
374
+ def test_dissolve
375
+ src = Magick::Image.new(@img.columns, @img.rows)
376
+ src_list = Magick::ImageList.new
377
+ src_list << src.copy
378
+ assert_nothing_raised { @img.dissolve(src, 0.50 ) }
379
+ assert_nothing_raised { @img.dissolve(src_list, 0.50) }
380
+ assert_nothing_raised { @img.dissolve(src, '50%') }
381
+ assert_nothing_raised { @img.dissolve(src, 0.50, 0.10) }
382
+ assert_nothing_raised { @img.dissolve(src, 0.50, 0.10, 10) }
383
+ assert_nothing_raised { @img.dissolve(src, 0.50, 0.10, Magick::NorthEastGravity) }
384
+ assert_nothing_raised { @img.dissolve(src, 0.50, 0.10, Magick::NorthEastGravity, 10) }
385
+ assert_nothing_raised { @img.dissolve(src, 0.50, 0.10, Magick::NorthEastGravity, 10, 10) }
386
+
387
+ assert_raise(ArgumentError) { @img.dissolve(src, 'x') }
388
+ assert_raise(ArgumentError) { @img.dissolve(src, 0.50, 'x') }
389
+ assert_raise(TypeError) { @img.dissolve(src, 0.50, Magick::NorthEastGravity, 'x') }
390
+ assert_raise(TypeError) { @img.dissolve(src, 0.50, Magick::NorthEastGravity, 10, 'x') }
391
+
392
+ src.destroy!
393
+ assert_raise(Magick::DestroyedImageError) { @img.dissolve(src, 0.50) }
394
+ end
395
+
396
+ def test_distort
397
+ @img = Magick::Image.new(200, 200)
398
+ assert_nothing_raised { @img.distort(Magick::AffineDistortion, [2,60, 2,60, 32,60, 32,60, 2,30, 17,35]) }
399
+ assert_nothing_raised { @img.distort(Magick::AffineProjectionDistortion, [1,0,0,1,0,0]) }
400
+ assert_nothing_raised { @img.distort(Magick::BilinearDistortion, [7,40, 4,30, 4,124, 4,123, 85,122, 100,123, 85,2, 100,30]) }
401
+ assert_nothing_raised { @img.distort(Magick::PerspectiveDistortion, [7,40, 4,30, 4,124, 4,123, 85,122, 100,123, 85,2, 100,30]) }
402
+ assert_nothing_raised { @img.distort(Magick::ScaleRotateTranslateDistortion, [28,24, 0.4,0.8 -110, 37.5,60]) }
403
+ assert_raise(ArgumentError) { @img.distort }
404
+ assert_raise(ArgumentError) { @img.distort(Magick::AffineDistortion) }
405
+ assert_raise(TypeError) { @img.distort(1, [1]) }
406
+ end
407
+
408
+ def test_distortion_channel
409
+ assert_nothing_raised do
410
+ metric = @img.distortion_channel(@img, Magick::MeanAbsoluteErrorMetric)
411
+ assert_instance_of(Float, metric)
412
+ assert_equal(0.0, metric)
413
+ end
414
+ assert_nothing_raised { @img.distortion_channel(@img, Magick::MeanSquaredErrorMetric) }
415
+ assert_nothing_raised { @img.distortion_channel(@img, Magick::PeakAbsoluteErrorMetric) }
416
+ assert_nothing_raised { @img.distortion_channel(@img, Magick::PeakSignalToNoiseRatioMetric) }
417
+ assert_nothing_raised { @img.distortion_channel(@img, Magick::RootMeanSquaredErrorMetric) }
418
+ assert_nothing_raised { @img.distortion_channel(@img, Magick::MeanSquaredErrorMetric, Magick::RedChannel, Magick:: BlueChannel) }
419
+ assert_raise(TypeError) { @img.distortion_channel(@img, 2) }
420
+ assert_raise(TypeError) { @img.distortion_channel(@img, Magick::RootMeanSquaredErrorMetric, 2) }
421
+ assert_raise(ArgumentError) { @img.distortion_channel }
422
+ assert_raise(ArgumentError) { @img.distortion_channel(@img) }
423
+
424
+ img = Magick::Image.new(20,20)
425
+ img.destroy!
426
+ assert_raise(Magick::DestroyedImageError) { @img.distortion_channel(img, Magick::MeanSquaredErrorMetric) }
427
+ end
428
+
429
+ def test_dup
430
+ assert_nothing_raised do
431
+ ditto = @img.dup
432
+ assert_equal(@img, ditto)
433
+ end
434
+ ditto = @img.dup
435
+ assert_equal(@img.tainted?, ditto.tainted?)
436
+ @img.taint
437
+ ditto = @img.dup
438
+ assert_equal(@img.tainted?, ditto.tainted?)
439
+ end
440
+
441
+ def test_each_profile
442
+ @img.iptc_profile = "test profile"
443
+ assert_nothing_raised do
444
+ @img.each_profile do |name, value|
445
+ assert_equal("iptc", name)
446
+ # As of 6.3.1
447
+ assert_equal("8BIM\004\004\000\000\000\000\001\340test profile", value)
448
+ end
449
+ end
450
+ end
451
+
452
+ def test_edge
453
+ assert_nothing_raised do
454
+ res = @img.edge
455
+ assert_instance_of(Magick::Image, res)
456
+ assert_not_same(@img, res)
457
+ end
458
+ assert_nothing_raised { @img.edge(2.0) }
459
+ assert_raise(ArgumentError) { @img.edge(2.0, 2) }
460
+ assert_raise(TypeError) { @img.edge('x') }
461
+ end
462
+
463
+ def test_emboss
464
+ assert_nothing_raised do
465
+ res = @img.emboss
466
+ assert_instance_of(Magick::Image, res)
467
+ assert_not_same(@img, res)
468
+ end
469
+ assert_nothing_raised { @img.emboss(1.0) }
470
+ assert_nothing_raised { @img.emboss(1.0, 0.5) }
471
+ assert_raise(ArgumentError) { @img.emboss(1.0, 0.5, 2) }
472
+ assert_raise(TypeError) { @img.emboss(1.0, 'x') }
473
+ assert_raise(TypeError) { @img.emboss('x', 1.0) }
474
+ end
475
+
476
+ def test_enhance
477
+ assert_nothing_raised do
478
+ res = @img.enhance
479
+ assert_instance_of(Magick::Image, res)
480
+ assert_not_same(@img, res)
481
+ end
482
+ end
483
+
484
+
485
+ def test_equalize
486
+ assert_nothing_raised do
487
+ res = @img.equalize
488
+ assert_instance_of(Magick::Image, res)
489
+ assert_not_same(@img, res)
490
+ end
491
+ end
492
+
493
+ def test_equalize_channel
494
+ assert_nothing_raised do
495
+ res = @img.equalize_channel
496
+ assert_instance_of(Magick::Image, res)
497
+ assert_not_same(@img, res)
498
+ end
499
+ assert_nothing_raised { @img.equalize_channel }
500
+ assert_nothing_raised { @img.equalize_channel(Magick::RedChannel) }
501
+ assert_nothing_raised { @img.equalize_channel(Magick::RedChannel, Magick::BlueChannel) }
502
+ assert_raise(TypeError) { @img.equalize_channel(Magick::RedChannel, 2) }
503
+ end
504
+
505
+ def test_erase!
506
+ assert_nothing_raised do
507
+ res = @img.erase!
508
+ assert_same(@img, res)
509
+ end
510
+ end
511
+
512
+ def test_excerpt
513
+ res = nil
514
+ img = Magick::Image.new(200, 200)
515
+ assert_nothing_raised { res = @img.excerpt(20,20,50,100) }
516
+ assert_not_same(img, res)
517
+ assert_equal(50, res.columns)
518
+ assert_equal(100, res.rows)
519
+
520
+ assert_nothing_raised { img.excerpt!(20,20,50,100) }
521
+ assert_equal(50, img.columns)
522
+ assert_equal(100, img.rows)
523
+ end
524
+
525
+ def test_export_pixels
526
+ assert_nothing_raised do
527
+ res = @img.export_pixels
528
+ assert_instance_of(Array, res)
529
+ assert_equal(@img.columns*@img.rows*"RGB".length, res.length)
530
+ res.each do |p|
531
+ assert_kind_of(Integer, p)
532
+ end
533
+ end
534
+ assert_nothing_raised { res = @img.export_pixels(0) }
535
+ assert_nothing_raised { res = @img.export_pixels(0, 0) }
536
+ assert_nothing_raised { res = @img.export_pixels(0, 0, 10) }
537
+ assert_nothing_raised { res = @img.export_pixels(0, 0, 10, 10) }
538
+ assert_nothing_raised do
539
+ res = @img.export_pixels(0, 0, 10, 10, 'RGBA')
540
+ assert_equal(10*10*"RGBA".length, res.length)
541
+ end
542
+ assert_nothing_raised do
543
+ res = @img.export_pixels(0, 0, 10, 10, 'I')
544
+ assert_equal(10*10*"I".length, res.length)
545
+ end
546
+
547
+ # too many arguments
548
+ assert_raise(ArgumentError) { @img.export_pixels(0, 0, 10, 10, 'I', 2) }
549
+
550
+ end
551
+
552
+ def test_export_pixels_to_str
553
+ assert_nothing_raised do
554
+ res = @img.export_pixels_to_str
555
+ assert_instance_of(String, res)
556
+ assert_equal(@img.columns*@img.rows*"RGB".length, res.length)
557
+ end
558
+ assert_nothing_raised { @img.export_pixels_to_str(0) }
559
+ assert_nothing_raised { @img.export_pixels_to_str(0, 0) }
560
+ assert_nothing_raised { @img.export_pixels_to_str(0, 0, 10) }
561
+ assert_nothing_raised { @img.export_pixels_to_str(0, 0, 10, 10) }
562
+ assert_nothing_raised do
563
+ res = @img.export_pixels_to_str(0, 0, 10, 10, "RGBA")
564
+ assert_equal(10*10*"RGBA".length, res.length)
565
+ end
566
+ assert_nothing_raised do
567
+ res = @img.export_pixels_to_str(0, 0, 10, 10, "I")
568
+ assert_equal(10*10*"I".length, res.length)
569
+ end
570
+
571
+ assert_nothing_raised do
572
+ res = @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::CharPixel)
573
+ assert_equal(10*10*1, res.length)
574
+ end
575
+ assert_nothing_raised do
576
+ res = @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::ShortPixel)
577
+ assert_equal(10*10*2, res.length)
578
+ end
579
+ assert_nothing_raised do
580
+ res = @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::IntegerPixel)
581
+ assert_equal(10*10*4, res.length)
582
+ end
583
+ assert_nothing_raised do
584
+ res = @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::LongPixel)
585
+ assert_equal(10*10*8, res.length)
586
+ end
587
+ assert_nothing_raised do
588
+ res = @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::FloatPixel)
589
+ assert_equal(10*10*4, res.length)
590
+ end
591
+ assert_nothing_raised do
592
+ res = @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::DoublePixel)
593
+ assert_equal(10*10*8, res.length)
594
+ end
595
+ assert_nothing_raised { @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::QuantumPixel) }
596
+
597
+ # too many arguments
598
+ assert_raise(ArgumentError) { @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::QuantumPixel, 1) }
599
+ # last arg s/b StorageType
600
+ assert_raise(TypeError) { @img.export_pixels_to_str(0, 0, 10, 10, "I", 2) }
601
+ end
602
+
603
+ def test_extent
604
+ assert_nothing_raised { @img.extent(40, 40) }
605
+ res = @img.extent(40, 40)
606
+ assert_instance_of(Magick::Image, res)
607
+ assert_not_same(@img, res)
608
+ assert_equal(40, res.columns)
609
+ assert_equal(40, res.rows)
610
+ assert_nothing_raised { @img.extent(40, 40, 5) }
611
+ assert_nothing_raised { @img.extent(40, 40, 5, 5) }
612
+ assert_raises(ArgumentError) { @img.extent(-40, 40) }
613
+ assert_raises(ArgumentError) { @img.extent(40, -40) }
614
+ assert_raises(TypeError) { @img.extent('x', 40) }
615
+ assert_raises(TypeError) { @img.extent(40, 'x') }
616
+ assert_raises(TypeError) { @img.extent(40, 40, 'x') }
617
+ assert_raises(TypeError) { @img.extent(40, 40, 5, 'x') }
618
+ end
619
+
620
+ def test_find_similar_region
621
+ girl = Magick::Image.read(IMAGES_DIR+"/Flower_Hat.jpg").first
622
+ region = girl.crop(10, 10, 50, 50)
623
+ assert_nothing_raised do
624
+ x, y = girl.find_similar_region(region)
625
+ assert_not_nil(x)
626
+ assert_not_nil(y)
627
+ assert_equal(10, x)
628
+ assert_equal(10, y)
629
+ end
630
+ assert_nothing_raised do
631
+ x, y = girl.find_similar_region(region, 0)
632
+ assert_equal(10, x)
633
+ assert_equal(10, y)
634
+ end
635
+ assert_nothing_raised do
636
+ x, y = girl.find_similar_region(region, 0, 0)
637
+ assert_equal(10, x)
638
+ assert_equal(10, y)
639
+ end
640
+
641
+ list = Magick::ImageList.new
642
+ list << region
643
+ assert_nothing_raised do
644
+ x, y = girl.find_similar_region(list, 0, 0)
645
+ assert_equal(10, x)
646
+ assert_equal(10, y)
647
+ end
648
+
649
+
650
+ x = girl.find_similar_region(@img)
651
+ assert_nil(x)
652
+
653
+ assert_raise(ArgumentError) { girl.find_similar_region(region, 10, 10, 10) }
654
+ assert_raise(TypeError) { girl.find_similar_region(region, 10, 'x') }
655
+ assert_raise(TypeError) { girl.find_similar_region(region, 'x') }
656
+
657
+ region.destroy!
658
+ assert_raise(Magick::DestroyedImageError) { girl.find_similar_region(region) }
659
+
660
+ end
661
+
662
+ def test_flip
663
+ assert_nothing_raised do
664
+ res = @img.flip
665
+ assert_instance_of(Magick::Image, res)
666
+ assert_not_same(@img, res)
667
+ end
668
+ end
669
+
670
+ def test_flip!
671
+ assert_nothing_raised do
672
+ res = @img.flip!
673
+ assert_same(@img, res)
674
+ end
675
+ end
676
+
677
+ def test_flop
678
+ assert_nothing_raised do
679
+ res = @img.flop
680
+ assert_instance_of(Magick::Image, res)
681
+ assert_not_same(@img, res)
682
+ end
683
+ end
684
+
685
+ def test_flop!
686
+ assert_nothing_raised do
687
+ res = @img.flop!
688
+ assert_same(@img, res)
689
+ end
690
+ end
691
+
692
+ def test_frame
693
+ assert_nothing_raised do
694
+ res = @img.frame
695
+ assert_instance_of(Magick::Image, res)
696
+ assert_not_same(@img, res)
697
+ end
698
+ assert_nothing_raised { @img.frame(50) }
699
+ assert_nothing_raised { @img.frame(50, 50) }
700
+ assert_nothing_raised { @img.frame(50, 50, 25) }
701
+ assert_nothing_raised { @img.frame(50, 50, 25, 25) }
702
+ assert_nothing_raised { @img.frame(50, 50, 25, 25, 6) }
703
+ assert_nothing_raised { @img.frame(50, 50, 25, 25, 6, 6) }
704
+ assert_nothing_raised { @img.frame(50, 50, 25, 25, 6, 6, 'red') }
705
+ red = Magick::Pixel.new(Magick::QuantumRange)
706
+ assert_nothing_raised { @img.frame(50, 50, 25, 25, 6, 6, red) }
707
+ assert_raise(TypeError) { @img.frame(50, 50, 25, 25, 6, 6, 2) }
708
+ end
709
+
710
+ def test_gamma_channel
711
+ assert_nothing_raised do
712
+ res = @img.gamma_channel(0.8)
713
+ assert_instance_of(Magick::Image, res)
714
+ assert_not_same(@img, res)
715
+ end
716
+ assert_raise(ArgumentError) { @img.gamma_channel }
717
+ assert_nothing_raised { @img.gamma_channel(0.8, Magick::RedChannel) }
718
+ assert_nothing_raised { @img.gamma_channel(0.8, Magick::RedChannel, Magick::BlueChannel) }
719
+ assert_raise(TypeError) { @img.gamma_channel(0.8, Magick::RedChannel, 2) }
720
+ end
721
+
722
+ def test_function_channel
723
+ img = Magick::Image.read("gradient:") {self.size = "20x600"}
724
+ img = img.first
725
+ img.rotate!(90)
726
+ assert_nothing_raised { img.function_channel Magick::PolynomialFunction, 0.33 }
727
+ assert_nothing_raised { img.function_channel Magick::PolynomialFunction, 4, -1.5 }
728
+ assert_nothing_raised { img.function_channel Magick::PolynomialFunction, 4, -4, 1 }
729
+ assert_nothing_raised { img.function_channel Magick::PolynomialFunction, -25, 53, -36, 8.3, 0.2 }
730
+
731
+ assert_nothing_raised { img.function_channel Magick::SinusoidFunction, 1 }
732
+ assert_nothing_raised { img.function_channel Magick::SinusoidFunction, 1, 90 }
733
+ assert_nothing_raised { img.function_channel Magick::SinusoidFunction, 5, 90, 0.25, 0.75 }
734
+
735
+ assert_nothing_raised { img.function_channel Magick::ArcsinFunction, 1 }
736
+ assert_nothing_raised { img.function_channel Magick::ArcsinFunction, 0.5 }
737
+ assert_nothing_raised { img.function_channel Magick::ArcsinFunction, 0.4, 0.7 }
738
+ assert_nothing_raised { img.function_channel Magick::ArcsinFunction, 0.5, 0.5, 0.5, 0.5 }
739
+
740
+ assert_nothing_raised { img.function_channel Magick::ArctanFunction, 1 }
741
+ assert_nothing_raised { img.function_channel Magick::ArctanFunction, 10, 0.7 }
742
+ assert_nothing_raised { img.function_channel Magick::ArctanFunction, 5, 0.7, 1.2 }
743
+ assert_nothing_raised { img.function_channel Magick::ArctanFunction, 15, 0.7, 0.5, 0.75 }
744
+
745
+ # with channel args
746
+ assert_nothing_raised { img.function_channel Magick::PolynomialFunction, 0.33, Magick::RedChannel }
747
+ assert_nothing_raised { img.function_channel Magick::SinusoidFunction, 1, Magick::RedChannel, Magick::BlueChannel }
748
+
749
+ # invalid args
750
+ assert_raise(ArgumentError) { img.function_channel }
751
+ assert_raise(TypeError) { img.function_channel 1 }
752
+ assert_raise(ArgumentError) { img.function_channel Magick::PolynomialFunction }
753
+ assert_raise(TypeError) { img.function_channel Magick::PolynomialFunction, [] }
754
+ assert_raise(ArgumentError) { img.function_channel Magick::SinusoidFunction, 5, 90, 0.25, 0.75, 0.1 }
755
+ assert_raise(ArgumentError) { img.function_channel Magick::ArcsinFunction, 0.5, 0.5, 0.5, 0.5, 0.1 }
756
+ assert_raise(ArgumentError) { img.function_channel Magick::ArctanFunction, 15, 0.7, 0.5, 0.75, 0.1 }
757
+ end
758
+
759
+ def test_gramma_correct
760
+ assert_raise(ArgumentError) { @img.gamma_correct }
761
+ # All 4 arguments can't default to 1.0
762
+ assert_raise(ArgumentError) { @img.gamma_correct(1.0) }
763
+ assert_nothing_raised do
764
+ res = @img.gamma_correct(0.8)
765
+ assert_instance_of(Magick::Image, res)
766
+ assert_not_same(@img, res)
767
+ end
768
+ assert_nothing_raised { @img.gamma_correct(0.8, 0.9) }
769
+ assert_nothing_raised { @img.gamma_correct(0.8, 0.9, 1.0) }
770
+ assert_nothing_raised { @img.gamma_correct(0.8, 0.9, 1.0, 1.1) }
771
+ # too many arguments
772
+ assert_raise(ArgumentError) { @img.gamma_correct(0.8, 0.9, 1.0, 1.1, 2) }
773
+ end
774
+
775
+ def test_gaussian_blur
776
+ assert_nothing_raised do
777
+ res = @img.gaussian_blur
778
+ assert_instance_of(Magick::Image, res)
779
+ assert_not_same(@img, res)
780
+ end
781
+ assert_nothing_raised { @img.gaussian_blur(0.0) }
782
+ assert_nothing_raised { @img.gaussian_blur(0.0, 3.0) }
783
+ # sigma must be != 0.0
784
+ assert_raise(ArgumentError) { @img.gaussian_blur(1.0, 0.0) }
785
+ assert_raise(ArgumentError) { @img.gaussian_blur(1.0, 3.0, 2) }
786
+ end
787
+
788
+ def test_gaussian_blur_channel
789
+ assert_nothing_raised do
790
+ res = @img.gaussian_blur_channel
791
+ assert_instance_of(Magick::Image, res)
792
+ assert_not_same(@img, res)
793
+ end
794
+ assert_nothing_raised { @img.gaussian_blur_channel(0.0) }
795
+ assert_nothing_raised { @img.gaussian_blur_channel(0.0, 3.0) }
796
+ assert_nothing_raised { @img.gaussian_blur_channel(0.0, 3.0, Magick::RedChannel) }
797
+ assert_nothing_raised { @img.gaussian_blur_channel(0.0, 3.0, Magick::RedChannel, Magick::BlueChannel) }
798
+ assert_raise(TypeError) { @img.gaussian_blur_channel(0.0, 3.0, Magick::RedChannel, 2) }
799
+ end
800
+
801
+ def test_get_exif_by_entry
802
+ assert_nothing_raised do
803
+ res = @img.get_exif_by_entry
804
+ assert_instance_of(Array, res)
805
+ end
806
+ end
807
+
808
+ def test_get_exif_by_number
809
+ assert_nothing_raised do
810
+ res = @img.get_exif_by_number
811
+ assert_instance_of(Hash, res)
812
+ end
813
+ end
814
+
815
+ def test_get_pixels
816
+ assert_nothing_raised do
817
+ pixels = @img.get_pixels(0, 0, @img.columns, 1)
818
+ assert_instance_of(Array, pixels)
819
+ assert_equal(@img.columns, pixels.length)
820
+ assert_block do
821
+ pixels.all? { |p| p.is_a? Magick::Pixel }
822
+ end
823
+ end
824
+ assert_raise(RangeError) { @img.get_pixels( 0, 0, -1, 1) }
825
+ assert_raise(RangeError) { @img.get_pixels( 0, 0, @img.columns, -1) }
826
+ assert_raise(RangeError) { @img.get_pixels( 0, 0, @img.columns+1, 1) }
827
+ assert_raise(RangeError) { @img.get_pixels( 0, 0, @img.columns, @img.rows+1) }
828
+ end
829
+
830
+ def test_gray?
831
+ gray = Magick::Image.new(20, 20) { self.background_color = 'gray50' }
832
+ assert(gray.gray?)
833
+ red = Magick::Image.new(20, 20) { self.background_color = 'red' }
834
+ assert(!red.gray?)
835
+ end
836
+
837
+ def test_histogram?
838
+ assert_nothing_raised { @img.histogram? }
839
+ assert(@img.histogram?)
840
+ end
841
+
842
+ def test_implode
843
+ assert_nothing_raised do
844
+ res = @img.implode(0.5)
845
+ assert_instance_of(Magick::Image, res)
846
+ assert_not_same(@img, res)
847
+ end
848
+ end
849
+
850
+ def test_import_pixels
851
+ pixels = @img.export_pixels(0, 0, @img.columns, 1, "RGB")
852
+ assert_nothing_raised do
853
+ res = @img.import_pixels(0, 0, @img.columns, 1, "RGB", pixels)
854
+ assert_same(@img, res)
855
+ end
856
+ assert_raise(ArgumentError) { @img.import_pixels }
857
+ assert_raise(ArgumentError) { @img.import_pixels(0) }
858
+ assert_raise(ArgumentError) { @img.import_pixels(0, 0) }
859
+ assert_raise(ArgumentError) { @img.import_pixels(0, 0, @img.columns) }
860
+ assert_raise(ArgumentError) { @img.import_pixels(0, 0, @img.columns, 1) }
861
+ assert_raise(ArgumentError) { @img.import_pixels(0, 0, @img.columns, 1, "RGB") }
862
+ assert_raise(TypeError) { @img.import_pixels('x', 0, @img.columns, 1, "RGB", pixels) }
863
+ assert_raise(TypeError) { @img.import_pixels(0, 'x', @img.columns, 1, "RGB", pixels) }
864
+ assert_raise(TypeError) { @img.import_pixels(0, 0, 'x', 1, "RGB", pixels) }
865
+ assert_raise(TypeError) { @img.import_pixels(0, 0, @img.columns, 'x', "RGB", pixels) }
866
+ assert_raise(TypeError) { @img.import_pixels(0, 0, @img.columns, 1, [2], pixels) }
867
+ assert_raise(ArgumentError) { @img.import_pixels(-1, 0, @img.columns, 1, "RGB", pixels) }
868
+ assert_raise(ArgumentError) { @img.import_pixels(0, -1, @img.columns, 1, "RGB", pixels) }
869
+ assert_raise(ArgumentError) { @img.import_pixels(0, 0, -1, 1, "RGB", pixels) }
870
+ assert_raise(ArgumentError) { @img.import_pixels(0, 0, @img.columns, -1, "RGB", pixels) }
871
+
872
+ # pixel array is too small
873
+ assert_raise(ArgumentError) { @img.import_pixels(0, 0, @img.columns, 2, "RGB", pixels) }
874
+ # pixel array doesn't contain a multiple of the map length
875
+ pixels.shift
876
+ assert_raise(ArgumentError) { @img.import_pixels(0, 0, @img.columns, 1, "RGB", pixels) }
877
+ end
878
+
879
+ def test_level
880
+ assert_nothing_raised do
881
+ res = @img.level
882
+ assert_instance_of(Magick::Image, res)
883
+ assert_not_same(@img, res)
884
+ end
885
+ assert_nothing_raised { @img.level(0.0) }
886
+ assert_nothing_raised { @img.level(0.0, 1.0) }
887
+ assert_nothing_raised { @img.level(0.0, 1.0, Magick::QuantumRange) }
888
+ assert_raise(ArgumentError) { @img.level(0.0, 1.0, Magick::QuantumRange, 2) }
889
+ assert_raise(ArgumentError) { @img.level('x') }
890
+ assert_raise(ArgumentError) { @img.level(0.0, 'x') }
891
+ assert_raise(ArgumentError) { @img.level(0.0, 1.0, 'x') }
892
+ end
893
+
894
+ # Ensure that #level properly swaps old-style arg list
895
+ def test_level2
896
+ img1 = @img.level(10, 2, 200)
897
+ img2 = @img.level(10, 200, 2)
898
+ assert_equal(img2, img1)
899
+
900
+ # Ensure that level2 uses new arg order
901
+ img1 = @img.level2(10, 200, 2)
902
+ assert_equal(img2, img1)
903
+ end
904
+
905
+ def test_level_channel
906
+ assert_raise(ArgumentError) { @img.level_channel }
907
+ assert_nothing_raised do
908
+ res = @img.level_channel(Magick::RedChannel)
909
+ assert_instance_of(Magick::Image, res)
910
+ assert_not_same(@img, res)
911
+ end
912
+
913
+ assert_nothing_raised { @img.level_channel(Magick::RedChannel, 0.0) }
914
+ assert_nothing_raised { @img.level_channel(Magick::RedChannel, 0.0, 1.0) }
915
+ assert_nothing_raised { @img.level_channel(Magick::RedChannel, 0.0, 1.0, Magick::QuantumRange) }
916
+
917
+ assert_raise(ArgumentError) { @img.level_channel(Magick::RedChannel, 0.0, 1.0, Magick::QuantumRange, 2) }
918
+ assert_raise(TypeError) { @img.level_channel(2) }
919
+ assert_raise(TypeError) { @img.level_channel(Magick::RedChannel, 'x') }
920
+ assert_raise(TypeError) { @img.level_channel(Magick::RedChannel, 0.0, 'x') }
921
+ assert_raise(TypeError) { @img.level_channel(Magick::RedChannel, 0.0, 1.0, 'x') }
922
+ end
923
+
924
+ def level_colors
925
+ res = nil
926
+ assert_nothing_raised do
927
+ res = @img.level_colors()
928
+ end
929
+ assert_instance_of(Magick::Image, res)
930
+ assert_not_same(@img, res)
931
+
932
+ assert_nothing_raised { @img.level_colors("black") }
933
+ assert_nothing_raised { @img.level_colors("black", Pixel.new(0,0,0)) }
934
+ assert_nothing_raised { @img.level_colors(Pixel.new(0,0,0), Pixel.new(Magick::QuantumRange,Magick::QuantumRange,Magick::QuantumRange)) }
935
+ assert_nothing_raised { @img.level_colors("black", "white") }
936
+ assert_nothing_raised { @img.level_colors("black", "white", false) }
937
+ # too many arguments
938
+ assert_raises(ArgumentError) { @img.level_colors("black", "white", false, 1) }
939
+ # not a pixel or a string
940
+ assert_raises(ArgumentError) { @img.level_colors([]) }
941
+ # not a color name
942
+ assert_raises(ArgumentError) { @img.level_colors("xxx") }
943
+ end
944
+
945
+ def levelize_channel
946
+ res = nil
947
+ assert_nothing_raised do
948
+ res = @img.levelize_channel(0, Magick::QuantumRange)
949
+ end
950
+ assert_instance_of(Magick::Image, res)
951
+ assert_not_same(@img, res)
952
+
953
+ assert_nothing_raised { @img.levelize_channel(0, Magick::QuantumRange, 0.5) }
954
+ assert_nothing_raised { @img.levelize_channel(0, Magick::QuantumRange, 0.5, Magick::RedChannel) }
955
+ assert_nothing_raised { @img.levelize_channel(0, Magick::QuantumRange, 0.5, Magick::RedChannel, Magick::BlueChannel) }
956
+ # too many arguments
957
+ assert_raise(ArgumentError) { @img.levelize_channel(0, Magick::QuantumRange, 0.5, 1, Magick::RedChannel) }
958
+ # not enough arguments
959
+ assert_raise(ArgumentError) { @img.levelize_channel() }
960
+ end
961
+
962
+ =begin
963
+ def test_liquid_rescale
964
+ begin
965
+ @img.liquid_rescale(15,15)
966
+ rescue NotImplementedError
967
+ puts "liquid_rescale not implemented."
968
+ return
969
+ end
970
+
971
+ res = nil
972
+ assert_nothing_raised do
973
+ res = @img.liquid_rescale(15, 15)
974
+ end
975
+ assert_equal(15, res.columns)
976
+ assert_equal(15, res.rows)
977
+ assert_nothing_raised { @img.liquid_rescale(15, 15, 0, 0) }
978
+ assert_raise(ArgumentError) { @img.liquid_rescale(15) }
979
+ assert_raise(ArgumentError) { @img.liquid_rescale(15, 15, 0, 0, 0) }
980
+ assert_raise(TypeError) { @img.liquid_rescale([], 15) }
981
+ assert_raise(TypeError) { @img.liquid_rescale(15, []) }
982
+ assert_raise(TypeError) { @img.liquid_rescale(15, 15, []) }
983
+ assert_raise(TypeError) { @img.liquid_rescale(15, 15, 0, []) }
984
+ end
985
+ =end
986
+
987
+ def test_magnify
988
+ assert_nothing_raised do
989
+ res = @img.magnify
990
+ assert_instance_of(Magick::Image, res)
991
+ assert_not_same(@img, res)
992
+ end
993
+
994
+ res = @img.magnify!
995
+ assert_same(@img, res)
996
+ end
997
+
998
+ def test_map
999
+ map = Magick::Image.read("netscape:").first
1000
+ assert_nothing_raised do
1001
+ res = @img.map(map)
1002
+ assert_instance_of(Magick::Image, res)
1003
+ assert_not_same(@img, res)
1004
+ end
1005
+ assert_nothing_raised { @img.map(map, true) }
1006
+ assert_raise(NoMethodError) { @img.map(2) }
1007
+ assert_raise(ArgumentError) { @img.map(map, true, 2) }
1008
+ assert_raise(ArgumentError) { @img.map }
1009
+ map.destroy!
1010
+ assert_raise(Magick::DestroyedImageError) { @img.map(map, true) }
1011
+ end
1012
+
1013
+ def test_marshal
1014
+ img = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
1015
+ d = nil
1016
+ img2 = nil
1017
+ assert_nothing_raised { d = Marshal.dump(img) }
1018
+ assert_nothing_raised { img2 = Marshal.load(d) }
1019
+ assert_equal(img, img2)
1020
+ end
1021
+
1022
+ def test_mask
1023
+ cimg = Magick::Image.new(10,10)
1024
+ assert_nothing_raised { @img.mask(cimg) }
1025
+ res = nil
1026
+ assert_nothing_raised { res = @img.mask }
1027
+ assert_not_nil(res)
1028
+ assert_not_same(cimg, res)
1029
+ assert_equal(20, res.columns)
1030
+ assert_equal(20, res.rows)
1031
+
1032
+ # mask expects an Image and calls `cur_image'
1033
+ assert_raise(NoMethodError) { @img.mask = 2 }
1034
+
1035
+ img = @img.copy.freeze
1036
+ assert_raise(FreezeError) { img.mask cimg }
1037
+
1038
+ @img.destroy!
1039
+ assert_raise(Magick::DestroyedImageError) { @img.mask cimg }
1040
+ end
1041
+
1042
+ def test_matte_fill_to_border
1043
+ assert_nothing_raised do
1044
+ res = @img.matte_fill_to_border(@img.columns/2, @img.rows/2)
1045
+ assert_instance_of(Magick::Image, res)
1046
+ assert_not_same(@img, res)
1047
+ end
1048
+ assert_nothing_raised { @img.matte_fill_to_border(@img.columns, @img.rows) }
1049
+ assert_raise(ArgumentError) { @img.matte_fill_to_border(@img.columns+1, @img.rows) }
1050
+ assert_raise(ArgumentError) { @img.matte_fill_to_border(@img.columns, @img.rows+1) }
1051
+ end
1052
+
1053
+ def test_matte_floodfill
1054
+ assert_nothing_raised do
1055
+ res = @img.matte_floodfill(@img.columns/2, @img.rows/2)
1056
+ assert_instance_of(Magick::Image, res)
1057
+ assert_not_same(@img, res)
1058
+ end
1059
+ assert_nothing_raised { @img.matte_floodfill(@img.columns, @img.rows) }
1060
+ assert_raise(ArgumentError) { @img.matte_floodfill(@img.columns+1, @img.rows) }
1061
+ assert_raise(ArgumentError) { @img.matte_floodfill(@img.columns, @img.rows+1) }
1062
+ end
1063
+
1064
+ def test_matte_replace
1065
+ assert_nothing_raised do
1066
+ res = @img.matte_replace(@img.columns/2, @img.rows/2)
1067
+ assert_instance_of(Magick::Image, res)
1068
+ assert_not_same(@img, res)
1069
+ end
1070
+ end
1071
+
1072
+ def test_matte_reset!
1073
+ assert_nothing_raised do
1074
+ res = @img.matte_reset!
1075
+ assert_same(@img, res)
1076
+ end
1077
+ end
1078
+
1079
+ def test_median_filter
1080
+ assert_nothing_raised do
1081
+ res = @img.median_filter
1082
+ assert_instance_of(Magick::Image, res)
1083
+ assert_not_same(@img, res)
1084
+ end
1085
+ assert_nothing_raised { @img.median_filter(0.5) }
1086
+ assert_raise(ArgumentError) { @img.median_filter(0.5, 'x') }
1087
+ assert_raise(TypeError) { @img.median_filter('x') }
1088
+ end
1089
+
1090
+ def test_minify
1091
+ assert_nothing_raised do
1092
+ res = @img.minify
1093
+ assert_instance_of(Magick::Image, res)
1094
+ assert_not_same(@img, res)
1095
+ end
1096
+
1097
+ res = @img.minify!
1098
+ assert_same(@img, res)
1099
+ end
1100
+
1101
+ def test_modulate
1102
+ assert_nothing_raised do
1103
+ res = @img.modulate
1104
+ assert_instance_of(Magick::Image, res)
1105
+ assert_not_same(@img, res)
1106
+ end
1107
+ assert_nothing_raised { @img.modulate(0.5) }
1108
+ assert_nothing_raised { @img.modulate(0.5, 0.5) }
1109
+ assert_nothing_raised { @img.modulate(0.5, 0.5, 0.5) }
1110
+ assert_raise(ArgumentError) { @img.modulate(0.5, 0.5, 0.5, 0.5) }
1111
+ assert_raise(TypeError) { @img.modulate('x', 0.5, 0.5) }
1112
+ assert_raise(TypeError) { @img.modulate(0.5, 'x', 0.5) }
1113
+ assert_raise(TypeError) { @img.modulate(0.5, 0.5, 'x') }
1114
+ end
1115
+
1116
+ def test_monochrome?
1117
+ # assert_block { @img.monochrome? }
1118
+ @img.pixel_color(0,0, 'red')
1119
+ assert_block { ! @img.monochrome? }
1120
+ end
1121
+
1122
+ def test_motion_blur
1123
+ assert_nothing_raised do
1124
+ res = @img.motion_blur(1.0, 7.0, 180)
1125
+ assert_instance_of(Magick::Image, res)
1126
+ assert_not_same(@img, res)
1127
+ end
1128
+ assert_raise(ArgumentError) { @img.motion_blur(1.0, 0.0, 180) }
1129
+ assert_nothing_raised { @img.motion_blur(1.0, -1.0, 180) }
1130
+ end
1131
+
1132
+ def test_negate
1133
+ assert_nothing_raised do
1134
+ res = @img.negate
1135
+ assert_instance_of(Magick::Image, res)
1136
+ assert_not_same(@img, res)
1137
+ end
1138
+ assert_nothing_raised { @img.negate(true) }
1139
+ assert_raise(ArgumentError) { @img.negate(true, 2) }
1140
+ end
1141
+
1142
+ def test_negate_channel
1143
+ assert_nothing_raised do
1144
+ res = @img.negate_channel
1145
+ assert_instance_of(Magick::Image, res)
1146
+ assert_not_same(@img, res)
1147
+ end
1148
+ assert_nothing_raised { @img.negate_channel(true) }
1149
+ assert_nothing_raised { @img.negate_channel(true, Magick::RedChannel) }
1150
+ assert_nothing_raised { @img.negate_channel(true, Magick::RedChannel, Magick::BlueChannel) }
1151
+ assert_raise(TypeError) { @img.negate_channel(true, Magick::RedChannel, 2) }
1152
+ end
1153
+
1154
+ def test_normalize
1155
+ assert_nothing_raised do
1156
+ res = @img.normalize
1157
+ assert_instance_of(Magick::Image, res)
1158
+ assert_not_same(@img, res)
1159
+ end
1160
+ end
1161
+
1162
+ def test_normalize_channel
1163
+ assert_nothing_raised do
1164
+ res = @img.normalize_channel
1165
+ assert_instance_of(Magick::Image, res)
1166
+ assert_not_same(@img, res)
1167
+ end
1168
+ assert_nothing_raised { @img.normalize_channel(Magick::RedChannel) }
1169
+ assert_nothing_raised { @img.normalize_channel(Magick::RedChannel, Magick::BlueChannel) }
1170
+ assert_raise(TypeError) { @img.normalize_channel(Magick::RedChannel, 2) }
1171
+ end
1172
+
1173
+ def test_oil_paint
1174
+ assert_nothing_raised do
1175
+ res = @img.oil_paint
1176
+ assert_instance_of(Magick::Image, res)
1177
+ assert_not_same(@img, res)
1178
+ end
1179
+ assert_nothing_raised { @img.oil_paint(2.0) }
1180
+ assert_raise(ArgumentError) { @img.oil_paint(2.0, 1.0) }
1181
+ end
1182
+
1183
+ def test_opaque
1184
+ assert_nothing_raised do
1185
+ res = @img.opaque('white', 'red')
1186
+ assert_instance_of(Magick::Image, res)
1187
+ assert_not_same(@img, res)
1188
+ end
1189
+ red = Magick::Pixel.new(Magick::QuantumRange)
1190
+ blue = Magick::Pixel.new(0, 0, Magick::QuantumRange)
1191
+ assert_nothing_raised { @img.opaque(red, blue) }
1192
+ assert_raise(TypeError) { @img.opaque(red, 2) }
1193
+ assert_raise(TypeError) { @img.opaque(2, blue) }
1194
+ end
1195
+
1196
+ def test_opaque_channel
1197
+ res = nil
1198
+ assert_nothing_raised { res = @img.opaque_channel('white', 'red') }
1199
+ assert_not_nil(res)
1200
+ assert_instance_of(Magick::Image, res)
1201
+ assert_not_same(res, @img)
1202
+ assert_nothing_raised { @img.opaque_channel('red', 'blue', true) }
1203
+ assert_nothing_raised { @img.opaque_channel('red', 'blue', true, 50) }
1204
+ assert_nothing_raised { @img.opaque_channel('red', 'blue', true, 50, Magick::RedChannel) }
1205
+ assert_nothing_raised { @img.opaque_channel('red', 'blue', true, 50, Magick::RedChannel, Magick::GreenChannel) }
1206
+ assert_nothing_raised do
1207
+ @img.opaque_channel('red', 'blue', true, 50, Magick::RedChannel, Magick::GreenChannel, Magick::BlueChannel)
1208
+ end
1209
+
1210
+ assert_raise(TypeError) { @img.opaque_channel('red', 'blue', true, 50, 50) }
1211
+ assert_raise(TypeError) { @img.opaque_channel('red', 'blue', true, []) }
1212
+ assert_raise(ArgumentError) { @img.opaque_channel('red') }
1213
+ assert_raise(TypeError) { @img.opaque_channel('red', []) }
1214
+ end
1215
+
1216
+ def test_opaque?
1217
+ assert_nothing_raised do
1218
+ assert_block { @img.opaque? }
1219
+ end
1220
+ @img.opacity = Magick::TransparentOpacity
1221
+ assert_block { ! @img.opaque? }
1222
+ end
1223
+
1224
+ def test_ordered_dither
1225
+ assert_nothing_raised do
1226
+ res = @img.ordered_dither
1227
+ assert_instance_of(Magick::Image, res)
1228
+ assert_not_same(@img, res)
1229
+ end
1230
+ assert_nothing_raised { @img.ordered_dither(2) }
1231
+ assert_nothing_raised { @img.ordered_dither(3) }
1232
+ assert_nothing_raised { @img.ordered_dither(4) }
1233
+ assert_raise(ArgumentError) { @img.ordered_dither(5) }
1234
+ assert_raise(ArgumentError) { @img.ordered_dither(2, 1) }
1235
+ end
1236
+
1237
+ def test_paint_transparent
1238
+ res = nil
1239
+ assert_nothing_raised { res = @img.paint_transparent("red") }
1240
+ assert_not_nil(res)
1241
+ assert_instance_of(Magick::Image, res)
1242
+ assert_not_same(res, @img)
1243
+ assert_nothing_raised { @img.paint_transparent("red", Magick::TransparentOpacity) }
1244
+ assert_nothing_raised { @img.paint_transparent("red", Magick::TransparentOpacity, true) }
1245
+ assert_nothing_raised { @img.paint_transparent("red", Magick::TransparentOpacity, true, 50) }
1246
+
1247
+ # Too many arguments
1248
+ assert_raise(ArgumentError) { @img.paint_transparent("red", Magick::TransparentOpacity, true, 50, 50) }
1249
+ # Not enough
1250
+ assert_raise(ArgumentError) { @img.paint_transparent() }
1251
+ assert_raise(TypeError) { @img.paint_transparent("red", Magick::TransparentOpacity, true, []) }
1252
+ assert_raise(TypeError) { @img.paint_transparent("red", "blue") }
1253
+ assert_raise(TypeError) { @img.paint_transparent(50) }
1254
+ end
1255
+
1256
+ def test_palette?
1257
+ img = Magick::Image.read(IMAGES_DIR+'/Flower_Hat.jpg').first
1258
+ assert_nothing_raised do
1259
+ assert_block { ! img.palette? }
1260
+ end
1261
+ img = Magick::Image.read(IMAGES_DIR+'/Button_0.gif').first
1262
+ assert_block { img.palette? }
1263
+ end
1264
+
1265
+ def test_pixel_color
1266
+ assert_nothing_raised do
1267
+ res = @img.pixel_color(0,0)
1268
+ assert_instance_of(Magick::Pixel, res)
1269
+ end
1270
+ res = @img.pixel_color(0,0)
1271
+ assert_equal(@img.background_color, res.to_color)
1272
+ res = @img.pixel_color(0, 0, 'red')
1273
+ assert_equal('white', res.to_color)
1274
+ res = @img.pixel_color(0, 0)
1275
+ assert_equal('red', res.to_color)
1276
+
1277
+ blue = Magick::Pixel.new(0, 0, Magick::QuantumRange)
1278
+ assert_nothing_raised { @img.pixel_color(0,0, blue) }
1279
+ # If args are out-of-bounds return the background color
1280
+ img = Magick::Image.new(10, 10) { self.background_color = 'blue' }
1281
+ assert_equal('blue', img.pixel_color(50, 50).to_color)
1282
+ end
1283
+
1284
+ def test_polaroid
1285
+ assert_nothing_raised { @img.polaroid }
1286
+ assert_nothing_raised { @img.polaroid(5) }
1287
+ assert_instance_of(Magick::Image, @img.polaroid)
1288
+ assert_raises(TypeError) { @img.polaroid('x') }
1289
+ end
1290
+
1291
+ def test_posterize
1292
+ assert_nothing_raised do
1293
+ res = @img.posterize
1294
+ assert_instance_of(Magick::Image, res)
1295
+ assert_not_same(@img, res)
1296
+ end
1297
+ assert_nothing_raised { @img.posterize(5) }
1298
+ assert_nothing_raised { @img.posterize(5, true) }
1299
+ assert_raise(ArgumentError) { @img.posterize(5, true, 'x') }
1300
+ end
1301
+
1302
+ end
1303
+
1304
+ if __FILE__ == $0
1305
+ IMAGES_DIR = '../doc/ex/images'
1306
+ FILES = Dir[IMAGES_DIR+'/Button_*.gif']
1307
+ Test::Unit::UI::Console::TestRunner.run(Image2_UT) if !RUBY_VERSION[/^1\.9|^2/]
1308
+ end