Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 349 lines (283 sloc) 10.469 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349

#! /usr/local/bin/ruby -w

require 'RMagick'
require 'test/unit'
require 'test/unit/ui/console/testrunner'


class Info_UT < Test::Unit::TestCase

    def setup
        @info = Magick::Image::Info.new
    end

    def test_options

        # 1-argument form
        assert_nothing_raised { @info['fill'] }
        assert_nil(@info['fill'])

        assert_nothing_raised { @info['fill'] = 'red' }
        assert_equal("red", @info['fill'])

        assert_nothing_raised { @info['fill'] = nil }
        assert_nil(@info['fill'])

        # 2-argument form
        assert_nothing_raised { @info['tiff', 'bits-per-sample'] = 2 }
        assert_equal("2", @info['tiff', 'bits-per-sample'])

        # define and undefine
        assert_nothing_raised { @info.define('tiff', 'bits-per-sample', 4) }
        assert_equal("4", @info['tiff', 'bits-per-sample'])

        assert_nothing_raised { @info.undefine('tiff', 'bits-per-sample') }
        assert_nil(@info['tiff', 'bits-per-sample'])
    end

    def test_antialias
      assert @info.antialias
      assert_nothing_raised { @info.antialias = false }
      assert !@info.antialias
    end

    def test_attenuate
        assert_nothing_raised { @info.attenuate = 10 }
        assert_equal(10, @info.attenuate)
        assert_nothing_raised { @info.attenuate = 5.25 }
        assert_equal(5.25, @info.attenuate)
        assert_nothing_raised { @info.attenuate = nil }
        assert_equal(nil, @info.attenuate)
    end

    def test_authenticate
      assert_nothing_raised { @info.authenticate = "string" }
      assert_equal("string", @info.authenticate)
    end

    def test_background_color
      assert_nothing_raised { @info.background_color = "red" }
      red = Magick::Pixel.new(Magick::MaxRGB)
      assert_nothing_raised { @info.background_color = red }
      assert_equal("red", @info.background_color)
      img = Magick::Image.new(20,20) { self.background_color = "red" }
      assert_equal("red", img.background_color)
    end

    def test_border_color
      assert_nothing_raised { @info.border_color = "red" }
      red = Magick::Pixel.new(Magick::MaxRGB)
      assert_nothing_raised { @info.border_color = red }
      assert_equal("red", @info.border_color)
      img = Magick::Image.new(20,20) { self.border_color = "red" }
      assert_equal("red", img.border_color)
    end

    def caption
      assert_nothing_raised { @info.caption = "string" }
      assert_equal("string", @info.caption)
      img = Magick::Image.new(20,20) { self.caption = "string" }
      assert_equal("string", img.caption)
    end

    def test_channel
        assert_nothing_raised { @info.channel(Magick::RedChannel) }
        assert_nothing_raised { @info.channel(Magick::RedChannel, Magick::BlueChannel) }
        assert_raise(TypeError) { @info.channel(1) }
        assert_raise(TypeError) { @info.channel(Magick::RedChannel, 1) }
    end

    def test_colorspace
      Magick::ColorspaceType.values.each do |cs|
        assert_nothing_raised {@info.colorspace = cs}
        assert_equal(cs, @info.colorspace)
      end
    end

    def test_comment
      assert_nothing_raised { @info.comment = "comment" }
      assert_equal("comment", @info.comment)
    end

    def test_compression
      Magick::CompressionType.values.each do |v|
        assert_nothing_raised { @info.compression = v }
        assert_equal(v, @info.compression)
      end
    end

    def test_define
      assert_nothing_raised { @info.define("tiff", "bits-per-sample", 2) }
      assert_nothing_raised { @info.undefine("tiff", "bits-per-sample") }
    end

    def test_density
      assert_nothing_raised { @info.density = "72x72" }
      assert_equal("72x72", @info.density)
      assert_nothing_raised { @info.density = Magick::Geometry.new(72, 72) }
      assert_equal("72x72", @info.density)
    end

    def test_delay
      assert_nothing_raised { @info.delay = 60 }
      assert_equal(60, @info.delay)
    end

    def test_depth
      assert_nothing_raised { @info.depth = 8 }
      assert_equal(8, @info.depth)
      assert_nothing_raised { @info.depth = 16 }
      assert_equal(16, @info.depth)
      assert_raise(ArgumentError) { @info.depth = 32 }
    end

    def test_dispose
      Magick::DisposeType.values.each do |v|
        assert_nothing_raised { @info.dispose = v }
        assert_equal(v, @info.dispose)
      end
    end

    def test_dither
      assert_nothing_raised { @info.dither = true }
      assert_equal(true, @info.dither)
      assert_nothing_raised { @info.dither = false }
      assert_equal(false, @info.dither)
    end

    def test_extract
        assert_nothing_raised { @info.extract = "100x100" }
        assert_equal("100x100", @info.extract)
        assert_nothing_raised { @info.extract = Magick::Geometry.new(100, 100) }
        assert_equal("100x100", @info.extract)
    end

    def test_filename
      assert_nothing_raised { @info.filename = "string" }
      assert_equal("string", @info.filename)
    end

    def test_fill
        assert_nothing_raised { @info.fill }
        assert_nil(@info.fill)

        assert_nothing_raised { @info.fill = 'white' }
        assert_equal("white", @info.fill)

        assert_nothing_raised { @info.fill = nil }
        assert_nil(@info.fill)

        assert_raise(ArgumentError) { @info.fill = 'xxx' }
    end

    def test_font
      assert_nothing_raised { @info.font = "Arial" }
      assert_equal("Arial", @info.font)
    end

    def test_format
      assert_nothing_raised { @info.format = "GIF" }
      assert_equal("GIF", @info.format)
    end

    def test_fuzz
      assert_nothing_raised { @info.fuzz = 50 }
      assert_equal(50, @info.fuzz)
      assert_nothing_raised { @info.fuzz = "50%" }
      assert_equal(Magick::MaxRGB * 0.5, @info.fuzz)
    end

    def test_gravity
      Magick::GravityType.values.each do |v|
        assert_nothing_raised { @info.gravity = v }
        assert_equal(v, @info.gravity)
      end
    end

    def test_image_type
      Magick::ImageType.values.each do |v|
        assert_nothing_raised { @info.image_type = v }
        assert_equal(v, @info.image_type)
      end
    end

    def test_interlace
      Magick::InterlaceType.values.each do |v|
        assert_nothing_raised { @info.interlace = v }
        assert_equal(v, @info.interlace)
      end
    end

    def test_label
      assert_nothing_raised { @info.label = "string" }
      assert_equal("string", @info.label)
    end

    def test_matte_color
      assert_nothing_raised { @info.matte_color = "red" }
      red = Magick::Pixel.new(Magick::MaxRGB)
      assert_nothing_raised { @info.matte_color = red }
      assert_equal("red", @info.matte_color)
      img = Magick::Image.new(20,20) { self.matte_color = "red" }
      assert_equal("red", img.matte_color)
    end

    def test_monitor
      assert_nothing_raised { @info.monitor = lambda {} }
      monitor = Proc.new do |mth, q, s|
        assert_equal("resize!", mth)
        assert_instance_of(Fixnum, q)
        assert_instance_of(Fixnum, s)
        true
      end
      img = Magick::Image.new(2000, 2000) { self.monitor = monitor }
      img.resize!(20, 20)
      img.monitor = nil
    end

    def test_monochrome
      assert_nothing_raised { @info.monochrome = true }
      assert @info.monochrome
    end

    def test_orientation
      Magick::OrientationType.values.each do |v|
        assert_nothing_raised { @info.orientation = v }
        assert_equal(v, @info.orientation)
      end
    end

    def test_origin
      assert_nothing_raised { @info.origin = "+10+10" }
      assert_equal("+10+10", @info.origin)
      assert_nothing_raised { @info.origin = Magick::Geometry.new(nil, nil, 10, 10) }
      assert_equal("+10+10", @info.origin)
    end

    def test_page
      assert_nothing_raised { @info.page = "612x792>" }
      assert_equal("612x792>", @info.page)
    end

    def test_pointsize
      assert_nothing_raised { @info.pointsize = 12 }
      assert_equal(12, @info.pointsize)
    end

    def test_quality
      assert_nothing_raised { @info.quality = 75 }
      assert_equal(75, @info.quality)
    end

    def test_sampling_factor
      assert_nothing_raised { @info.sampling_factor = "2x1" }
      assert_equal("2x1", @info.sampling_factor)
    end

    def test_server_name
      assert_nothing_raised { @info.server_name = "foo" }
      assert_equal("foo", @info.server_name)
    end

    def test_size
      assert_nothing_raised { @info.size = "200x100" }
      assert_equal("200x100", @info.size)
      assert_nothing_raised { @info.size = Magick::Geometry.new(100,200) }
      assert_equal("100x200", @info.size)
    end

    def test_stroke
        assert_nothing_raised { @info.stroke }
        assert_nil(@info.stroke)

        assert_nothing_raised { @info.stroke = 'white' }
        assert_equal("white", @info.stroke)

        assert_nothing_raised { @info.stroke = nil }
        assert_nil(@info.stroke)

        assert_raise(ArgumentError) { @info.stroke = 'xxx' }
    end

    def test_stroke_width
        assert_nothing_raised { @info.stroke_width = 10 }
        assert_equal(10, @info.stroke_width)
        assert_nothing_raised { @info.stroke_width = 5.25 }
        assert_equal(5.25, @info.stroke_width)
        assert_nothing_raised { @info.stroke_width = nil }
        assert_equal(nil, @info.stroke_width)
    end

    def test_texture
      img = Magick::Image.read("granite:") {self.size = "20x20" }
      assert_nothing_raised { @info.texture = img.first }
    end

    def test_tile_offset
      assert_nothing_raised { @info.tile_offset = "200x100" }
      assert_equal("200x100", @info.tile_offset)
      assert_nothing_raised { @info.tile_offset = Magick::Geometry.new(100,200) }
      assert_equal("100x200", @info.tile_offset)
    end

    def test_undercolor
      assert_nothing_raised { @info.undercolor }
      assert_nil(@info.undercolor)

      assert_nothing_raised { @info.undercolor = 'white' }
      assert_equal("white", @info.undercolor)

      assert_nothing_raised { @info.undercolor = nil }
      assert_nil(@info.undercolor)

      assert_raise(ArgumentError) { @info.undercolor = 'xxx' }
    end

    def test_units
      Magick::ResolutionType.values.each do |v|
        assert_nothing_raised { @info.units = v }
        assert_equal(v, @info.units)
      end
    end

    def test_view
      assert_nothing_raised { @info.view = "string" }
      assert_equal("string", @info.view)
    end

end
Something went wrong with that request. Please try again.