Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 113 lines (95 sloc) 3.614 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

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

require 'RMagick'
require 'test/unit'
require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'

class Magick::Draw
  def self._dummy_img_
    @@_dummy_img_
  end
end

class Draw_UT < Test::Unit::TestCase

    def setup
        @draw = Magick::Draw.new
    end

    # Ensure @@_dummy_img_ class var is working properly
    def test_dummy_img
      # initially this variable is not defined.
      assert_raise(NameError) do
        Magick::Draw._dummy_img_
      end

      # cause it to become defined. save the object id.
      @draw.get_type_metrics("ABCDEF")
      dummy = nil
      assert_nothing_raised do
        dummy = Magick::Draw._dummy_img_
      end

      assert_instance_of(Magick::Image, dummy)

      # ensure that it is always the same object
      @draw.get_type_metrics("ABCDEF")
      dummy2 = nil
      assert_nothing_raised do
        dummy2 = Magick::Draw._dummy_img_
      end
      assert_same(dummy, dummy2)
    end

    def test_kerning
        assert_nothing_raised { @draw.kerning = 1 }
        assert_nothing_raised { @draw.kerning(1) }
        assert_raise(ArgumentError) { @draw.kerning("a") }
        assert_raise(TypeError) { @draw.kerning([]) }
    end

    def test_interword_spacing
        assert_nothing_raised { @draw.interword_spacing = 1 }
        assert_nothing_raised { @draw.interword_spacing(1) }
        assert_raise(ArgumentError) { @draw.interword_spacing("a") }
        assert_raise(TypeError) { @draw.interword_spacing([]) }
    end

    def assert_marshal
       rose = Magick::Image.read("rose:").first
       granite = Magick::Image.read("granite:").first
       s = granite.to_blob {self.format="miff"}
       granite = Magick::Image.from_blob(s).first
       blue_stroke = Magick::Image.new(20,20) {self.background_color = "blue"}
       s = blue_stroke.to_blob {self.format="miff"}
       blue_stroke = Magick::Image.from_blob(s).first

       @draw.affine = Magick::AffineMatrix.new(1, 2, 3, 4, 5, 6)
       @draw.decorate = Magick::LineThroughDecoration
       @draw.encoding = "AdobeCustom"
       @draw.gravity = Magick::CenterGravity
       @draw.fill = Magick::Pixel.from_color("red")
       @draw.stroke = Magick::Pixel.from_color("blue")
       @draw.stroke_width = 5
       @draw.fill_pattern = granite
       @draw.stroke_pattern = blue_stroke
       @draw.text_antialias = true
       @draw.font = "Arial-Bold"
       @draw.font_family = "arial"
       @draw.font_style = Magick::ItalicStyle
       @draw.font_stretch = Magick::CondensedStretch
       @draw.font_weight = Magick::BoldWeight
       @draw.pointsize = 12
       @draw.density = "72x72"
       @draw.align = Magick::CenterAlign
       @draw.undercolor = Magick::Pixel.from_color("green")
       @draw.kerning = 10.5
       @draw.interword_spacing = 3.75

       @draw.circle(20, 25, 20, 28)
       dumped = nil
       assert_nothing_raised { dumped = Marshal.dump(@draw) }
       assert_nothing_raised { Marshal.load(dumped) }
    end

    def test_patterns
        img = Magick::Image.new(20,20)
        assert_nothing_raised { @draw.fill_pattern = img }
        assert_nothing_raised { @draw.stroke_pattern = img }

        ilist = Magick::ImageList.new
        ilist << img
        assert_nothing_raised { @draw.fill_pattern = ilist }
        assert_nothing_raised { @draw.stroke_pattern = ilist }

        assert_raise(NoMethodError) { @draw.fill_pattern = 1 }
        assert_raise(NoMethodError) { @draw.stroke_pattern = 1 }
    end
end

if __FILE__ == $0
Test::Unit::UI::Console::TestRunner.run(Draw_UT) if RUBY_VERSION != '1.9.1'
end
Something went wrong with that request. Please try again.