Skip to content
This repository
Newer
Older
100644 113 lines (95 sloc) 3.614 kb
95590df0 » rmagick
2007-02-18 Add initial tests for Draw class
1
2 #! /usr/local/bin/ruby -w
3
4 require 'RMagick'
5 require 'test/unit'
95bba790 » rmagick
2009-01-02 Update to work with new test/unit in 1.9.1
6 require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
95590df0 » rmagick
2007-02-18 Add initial tests for Draw class
7
68fe6540 » rmagick
2008-03-29 Test @@_dummy_img_
8 class Magick::Draw
9 def self._dummy_img_
10 @@_dummy_img_
11 end
12 end
13
95590df0 » rmagick
2007-02-18 Add initial tests for Draw class
14 class Draw_UT < Test::Unit::TestCase
15
16 def setup
17 @draw = Magick::Draw.new
18 end
19
68fe6540 » rmagick
2008-03-29 Test @@_dummy_img_
20 # Ensure @@_dummy_img_ class var is working properly
21 def test_dummy_img
22 # initially this variable is not defined.
23 assert_raise(NameError) do
24 Magick::Draw._dummy_img_
25 end
26
27 # cause it to become defined. save the object id.
28 @draw.get_type_metrics("ABCDEF")
29 dummy = nil
30 assert_nothing_raised do
31 dummy = Magick::Draw._dummy_img_
32 end
33
34 assert_instance_of(Magick::Image, dummy)
35
36 # ensure that it is always the same object
37 @draw.get_type_metrics("ABCDEF")
38 dummy2 = nil
39 assert_nothing_raised do
40 dummy2 = Magick::Draw._dummy_img_
41 end
42 assert_same(dummy, dummy2)
43 end
44
e714c902 » rmagick
2009-01-01 Add kerning=, kerning, interword_spacing=, interword_spacing, marshal…
45 def test_kerning
46 assert_nothing_raised { @draw.kerning = 1 }
47 assert_nothing_raised { @draw.kerning(1) }
48 assert_raise(ArgumentError) { @draw.kerning("a") }
49 assert_raise(TypeError) { @draw.kerning([]) }
50 end
51
52 def test_interword_spacing
53 assert_nothing_raised { @draw.interword_spacing = 1 }
54 assert_nothing_raised { @draw.interword_spacing(1) }
55 assert_raise(ArgumentError) { @draw.interword_spacing("a") }
56 assert_raise(TypeError) { @draw.interword_spacing([]) }
57 end
58
59 def assert_marshal
60 rose = Magick::Image.read("rose:").first
61 granite = Magick::Image.read("granite:").first
62 s = granite.to_blob {self.format="miff"}
63 granite = Magick::Image.from_blob(s).first
64 blue_stroke = Magick::Image.new(20,20) {self.background_color = "blue"}
65 s = blue_stroke.to_blob {self.format="miff"}
66 blue_stroke = Magick::Image.from_blob(s).first
67
68 @draw.affine = Magick::AffineMatrix.new(1, 2, 3, 4, 5, 6)
69 @draw.decorate = Magick::LineThroughDecoration
70 @draw.encoding = "AdobeCustom"
71 @draw.gravity = Magick::CenterGravity
72 @draw.fill = Magick::Pixel.from_color("red")
73 @draw.stroke = Magick::Pixel.from_color("blue")
74 @draw.stroke_width = 5
75 @draw.fill_pattern = granite
76 @draw.stroke_pattern = blue_stroke
77 @draw.text_antialias = true
78 @draw.font = "Arial-Bold"
79 @draw.font_family = "arial"
80 @draw.font_style = Magick::ItalicStyle
81 @draw.font_stretch = Magick::CondensedStretch
82 @draw.font_weight = Magick::BoldWeight
83 @draw.pointsize = 12
84 @draw.density = "72x72"
85 @draw.align = Magick::CenterAlign
86 @draw.undercolor = Magick::Pixel.from_color("green")
87 @draw.kerning = 10.5
88 @draw.interword_spacing = 3.75
89
90 @draw.circle(20, 25, 20, 28)
91 dumped = nil
92 assert_nothing_raised { dumped = Marshal.dump(@draw) }
93 assert_nothing_raised { Marshal.load(dumped) }
94 end
95
95590df0 » rmagick
2007-02-18 Add initial tests for Draw class
96 def test_patterns
97 img = Magick::Image.new(20,20)
98 assert_nothing_raised { @draw.fill_pattern = img }
99 assert_nothing_raised { @draw.stroke_pattern = img }
100
101 ilist = Magick::ImageList.new
102 ilist << img
103 assert_nothing_raised { @draw.fill_pattern = ilist }
104 assert_nothing_raised { @draw.stroke_pattern = ilist }
105
106 assert_raise(NoMethodError) { @draw.fill_pattern = 1 }
107 assert_raise(NoMethodError) { @draw.stroke_pattern = 1 }
108 end
109 end
110
111 if __FILE__ == $0
95bba790 » rmagick
2009-01-02 Update to work with new test/unit in 1.9.1
112 Test::Unit::UI::Console::TestRunner.run(Draw_UT) if RUBY_VERSION != '1.9.1'
95590df0 » rmagick
2007-02-18 Add initial tests for Draw class
113 end
114
Something went wrong with that request. Please try again.