Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 122 lines (101 sloc) 3.914 kb
95590df Add initial tests for Draw class
rmagick authored
1
2 #! /usr/local/bin/ruby -w
3
4 require 'RMagick'
5 require 'test/unit'
962d56c @mmaiza fixing tests to run with newer versions of ruby
mmaiza authored
6 require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
95590df Add initial tests for Draw class
rmagick authored
7
68fe654 Test @@_dummy_img_
rmagick authored
8 class Magick::Draw
9 def self._dummy_img_
10 @@_dummy_img_
11 end
12 end
13
95590df Add initial tests for Draw class
rmagick authored
14 class Draw_UT < Test::Unit::TestCase
15
16 def setup
17 @draw = Magick::Draw.new
18 end
19
68fe654 Test @@_dummy_img_
rmagick authored
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
e714c90 Add kerning=, kerning, interword_spacing=, interword_spacing, marshal_du...
rmagick authored
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
34ecd01 test interline_spacing
rmagick authored
52 def test_interline_spacing
53 assert_nothing_raised { @draw.interline_spacing = 1 }
54 assert_nothing_raised { @draw.interline_spacing(1) }
55 assert_raise(ArgumentError) { @draw.interline_spacing("a") }
56 assert_raise(TypeError) { @draw.interline_spacing([]) }
57 end
58
e714c90 Add kerning=, kerning, interword_spacing=, interword_spacing, marshal_du...
rmagick authored
59 def test_interword_spacing
60 assert_nothing_raised { @draw.interword_spacing = 1 }
61 assert_nothing_raised { @draw.interword_spacing(1) }
62 assert_raise(ArgumentError) { @draw.interword_spacing("a") }
63 assert_raise(TypeError) { @draw.interword_spacing([]) }
64 end
65
66 def assert_marshal
67 rose = Magick::Image.read("rose:").first
68 granite = Magick::Image.read("granite:").first
69 s = granite.to_blob {self.format="miff"}
70 granite = Magick::Image.from_blob(s).first
71 blue_stroke = Magick::Image.new(20,20) {self.background_color = "blue"}
72 s = blue_stroke.to_blob {self.format="miff"}
73 blue_stroke = Magick::Image.from_blob(s).first
74
75 @draw.affine = Magick::AffineMatrix.new(1, 2, 3, 4, 5, 6)
76 @draw.decorate = Magick::LineThroughDecoration
77 @draw.encoding = "AdobeCustom"
78 @draw.gravity = Magick::CenterGravity
79 @draw.fill = Magick::Pixel.from_color("red")
80 @draw.stroke = Magick::Pixel.from_color("blue")
81 @draw.stroke_width = 5
82 @draw.fill_pattern = granite
83 @draw.stroke_pattern = blue_stroke
84 @draw.text_antialias = true
85 @draw.font = "Arial-Bold"
86 @draw.font_family = "arial"
87 @draw.font_style = Magick::ItalicStyle
88 @draw.font_stretch = Magick::CondensedStretch
89 @draw.font_weight = Magick::BoldWeight
90 @draw.pointsize = 12
91 @draw.density = "72x72"
92 @draw.align = Magick::CenterAlign
93 @draw.undercolor = Magick::Pixel.from_color("green")
94 @draw.kerning = 10.5
95 @draw.interword_spacing = 3.75
96
97 @draw.circle(20, 25, 20, 28)
98 dumped = nil
99 assert_nothing_raised { dumped = Marshal.dump(@draw) }
100 assert_nothing_raised { Marshal.load(dumped) }
101 end
102
95590df Add initial tests for Draw class
rmagick authored
103 def test_patterns
104 img = Magick::Image.new(20,20)
105 assert_nothing_raised { @draw.fill_pattern = img }
106 assert_nothing_raised { @draw.stroke_pattern = img }
107
108 ilist = Magick::ImageList.new
109 ilist << img
110 assert_nothing_raised { @draw.fill_pattern = ilist }
111 assert_nothing_raised { @draw.stroke_pattern = ilist }
112
113 assert_raise(NoMethodError) { @draw.fill_pattern = 1 }
114 assert_raise(NoMethodError) { @draw.stroke_pattern = 1 }
115 end
116 end
117
118 if __FILE__ == $0
962d56c @mmaiza fixing tests to run with newer versions of ruby
mmaiza authored
119 Test::Unit::UI::Console::TestRunner.run(Draw_UT) if !RUBY_VERSION[/^1\.9|^2/]
95590df Add initial tests for Draw class
rmagick authored
120 end
121
Something went wrong with that request. Please try again.