test/Draw.rb in rmagick-3.1.0 vs test/Draw.rb in rmagick-3.2.0

- old
+ new

@@ -1,10 +1,10 @@ #!/usr/bin/env ruby -w require 'rmagick' require 'test/unit' -require 'test/unit/ui/console/testrunner' unless RUBY_VERSION[/^1\.9|^2/] +require 'test/unit/ui/console/testrunner' class DrawUT < Test::Unit::TestCase def setup @draw = Magick::Draw.new end @@ -15,21 +15,19 @@ end assert_raise(TypeError) { @draw.affine = [1, 2, 3, 4, 5, 6] } end def test_align - assert_nothing_raised { @draw.align = Magick::UndefinedAlign } - assert_nothing_raised { @draw.align = Magick::LeftAlign } - assert_nothing_raised { @draw.align = Magick::CenterAlign } - assert_nothing_raised { @draw.align = Magick::RightAlign } + Magick::AlignType.values do |align| + assert_nothing_raised { @draw.align = align } + end end def test_decorate - assert_nothing_raised { @draw.decorate = Magick::NoDecoration } - assert_nothing_raised { @draw.decorate = Magick::UnderlineDecoration } - assert_nothing_raised { @draw.decorate = Magick::OverlineDecoration } - assert_nothing_raised { @draw.decorate = Magick::LineThroughDecoration } + Magick::DecorationType.values do |decoration| + assert_nothing_raised { @draw.decorate = decoration } + end end def test_density assert_nothing_raised { @draw.density = '90x90' } assert_nothing_raised { @draw.density = 'x90' } @@ -70,58 +68,38 @@ assert_nothing_raised { @draw.font_family = 'Arial' } assert_raise(TypeError) { @draw.font_family = 2 } end def test_font_stretch - assert_nothing_raised { @draw.font_stretch = Magick::NormalStretch } - assert_nothing_raised { @draw.font_stretch = Magick::UltraCondensedStretch } - assert_nothing_raised { @draw.font_stretch = Magick::ExtraCondensedStretch } - assert_nothing_raised { @draw.font_stretch = Magick::CondensedStretch } - assert_nothing_raised { @draw.font_stretch = Magick::SemiCondensedStretch } - assert_nothing_raised { @draw.font_stretch = Magick::SemiExpandedStretch } - assert_nothing_raised { @draw.font_stretch = Magick::ExpandedStretch } - assert_nothing_raised { @draw.font_stretch = Magick::ExtraExpandedStretch } - assert_nothing_raised { @draw.font_stretch = Magick::UltraExpandedStretch } - assert_nothing_raised { @draw.font_stretch = Magick::AnyStretch } + Magick::StretchType.values do |stretch| + assert_nothing_raised { @draw.font_stretch = stretch } + end assert_raise(TypeError) { @draw.font_stretch = 2 } end def test_font_style - assert_nothing_raised { @draw.font_style = Magick::NormalStyle } - assert_nothing_raised { @draw.font_style = Magick::ItalicStyle } - assert_nothing_raised { @draw.font_style = Magick::ObliqueStyle } - assert_nothing_raised { @draw.font_style = Magick::AnyStyle } + Magick::StyleType.values do |style| + assert_nothing_raised { @draw.font_style = style } + end assert_raise(TypeError) { @draw.font_style = 2 } end def test_font_weight - assert_nothing_raised { @draw.font_weight = Magick::AnyWeight } - assert_nothing_raised { @draw.font_weight = Magick::NormalWeight } - assert_nothing_raised { @draw.font_weight = Magick::BoldWeight } - assert_nothing_raised { @draw.font_weight = Magick::BolderWeight } - assert_nothing_raised { @draw.font_weight = Magick::LighterWeight } - assert_nothing_raised { @draw.font_weight = 200 } + Magick::WeightType.values do |weight| + assert_nothing_raised { @draw.font_weight = weight } + end assert_raise(ArgumentError) { @draw.font_weight = 99 } assert_raise(ArgumentError) { @draw.font_weight = 901 } end def test_gravity - assert_nothing_raised { @draw.gravity = Magick::UndefinedGravity } - assert_nothing_raised { @draw.gravity = Magick::ForgetGravity } - assert_nothing_raised { @draw.gravity = Magick::NorthWestGravity } - assert_nothing_raised { @draw.gravity = Magick::NorthGravity } - assert_nothing_raised { @draw.gravity = Magick::NorthEastGravity } - assert_nothing_raised { @draw.gravity = Magick::WestGravity } - assert_nothing_raised { @draw.gravity = Magick::CenterGravity } - assert_nothing_raised { @draw.gravity = Magick::EastGravity } - assert_nothing_raised { @draw.gravity = Magick::SouthWestGravity } - assert_nothing_raised { @draw.gravity = Magick::SouthGravity } - assert_nothing_raised { @draw.gravity = Magick::SouthEastGravity } - assert_nothing_raised { @draw.gravity = Magick::StaticGravity } + Magick::GravityType.values do |gravity| + assert_nothing_raised { @draw.gravity = gravity } + end assert_raise(TypeError) { @draw.gravity = 2 } end def test_interline_spacing @@ -213,10 +191,20 @@ end assert_raise(NoMethodError) { @draw.annotate('x', 0, 0, 0, 20, 'Hello world') } end + def test_annotate_stack_buffer_overflow + assert_nothing_raised do + if 1.size == 8 + # 64-bit environment can use larger value for Integer and it can causes stack buffer overflow. + img = Magick::Image.new(10, 10) + @draw.annotate(img, 2**63, 2**63, 2**62, 2**62, 'Hello world') + end + end + end + def test_dup @draw.path('M110,100 h-75 a75,75 0 1,0 75,-75 z') @draw.taint @draw.freeze dup = @draw.dup @@ -229,97 +217,25 @@ clone = @draw.clone assert_instance_of(Magick::Draw, clone) end def test_composite - composite_operators = [ - Magick::AddCompositeOp, - Magick::AtopCompositeOp, - Magick::BlendCompositeOp, - Magick::BlurCompositeOp, - Magick::BumpmapCompositeOp, - Magick::ChangeMaskCompositeOp, - Magick::ClearCompositeOp, - Magick::ColorBurnCompositeOp, - Magick::ColorDodgeCompositeOp, - Magick::ColorizeCompositeOp, - Magick::CopyBlackCompositeOp, - Magick::CopyBlueCompositeOp, - Magick::CopyCompositeOp, - Magick::CopyCyanCompositeOp, - Magick::CopyGreenCompositeOp, - Magick::CopyMagentaCompositeOp, - Magick::CopyOpacityCompositeOp, - Magick::CopyRedCompositeOp, - Magick::CopyYellowCompositeOp, - Magick::DarkenCompositeOp, - Magick::DarkenIntensityCompositeOp, - Magick::DistortCompositeOp, - Magick::DivideCompositeOp, - Magick::DivideSrcCompositeOp, - Magick::DstAtopCompositeOp, - Magick::DstCompositeOp, - Magick::DstInCompositeOp, - Magick::DstOutCompositeOp, - Magick::DstOverCompositeOp, - Magick::DifferenceCompositeOp, - Magick::DisplaceCompositeOp, - Magick::DissolveCompositeOp, - Magick::ExclusionCompositeOp, - Magick::HardLightCompositeOp, - Magick::HueCompositeOp, - Magick::InCompositeOp, - Magick::LightenCompositeOp, - Magick::LightenIntensityCompositeOp, - Magick::LinearBurnCompositeOp, - Magick::LinearDodgeCompositeOp, - Magick::LinearLightCompositeOp, - Magick::LuminizeCompositeOp, - Magick::MathematicsCompositeOp, - Magick::MinusCompositeOp, - Magick::MinusSrcCompositeOp, - Magick::ModulateCompositeOp, - Magick::MultiplyCompositeOp, - Magick::NoCompositeOp, - Magick::OutCompositeOp, - Magick::OverCompositeOp, - Magick::OverlayCompositeOp, - Magick::PegtopLightCompositeOp, - Magick::PinLightCompositeOp, - Magick::PlusCompositeOp, - Magick::ReplaceCompositeOp, - Magick::SaturateCompositeOp, - Magick::ScreenCompositeOp, - Magick::SoftLightCompositeOp, - Magick::SrcAtopCompositeOp, - Magick::SrcCompositeOp, - Magick::SrcInCompositeOp, - Magick::SrcOutCompositeOp, - Magick::SrcOverCompositeOp, - Magick::SubtractCompositeOp, - Magick::ThresholdCompositeOp, - Magick::UndefinedCompositeOp, - Magick::VividLightCompositeOp, - Magick::XorCompositeOp - ] - composite_operators << Magick::HardMixCompositeOp if Gem::Version.new('6.8.9') <= Gem::Version.new(IM_VERSION) - img = Magick::Image.new(10, 10) assert_nothing_raised { @draw.composite(0, 0, 10, 10, img) } - composite_operators.each do |op| + Magick::CompositeOperator.values do |op| assert_nothing_raised { @draw.composite(0, 0, 10, 10, img, op) } end assert_raise(TypeError) { @draw.composite('x', 0, 10, 10, img) } assert_raise(TypeError) { @draw.composite(0, 'y', 10, 10, img) } assert_raise(TypeError) { @draw.composite(0, 0, 'w', 10, img) } assert_raise(TypeError) { @draw.composite(0, 0, 10, 'h', img) } assert_raise(TypeError) { @draw.composite(0, 0, 10, 10, img, Magick::CenterAlign) } assert_raise(NoMethodError) { @draw.composite(0, 0, 10, 10, 'image') } assert_raise(ArgumentError) { @draw.composite(0, 0, 10, 10) } - assert_raise(ArgumentError) { @draw.composite(0, 0, 10, 10, img, Magick::AddCompositeOp, 'x') } + assert_raise(ArgumentError) { @draw.composite(0, 0, 10, 10, img, Magick::ModulusAddCompositeOp, 'x') } end def test_draw draw = @draw.dup @@ -408,7 +324,28 @@ Magick::Draw.new do |option| yield_obj = option end assert_instance_of(Magick::Image::DrawOptions, yield_obj) end + end + + def test_issue_604 + points = [0, 0, 1, 1, 2, 2] + + pr = Magick::Draw.new + + pr.define_clip_path('example') do + pr.polygon(*points) + end + + pr.push + pr.clip_path('example') + + composite = Magick::Image.new(10, 10) + pr.composite(0, 0, 10, 10, composite) + + pr.pop + + canvas = Magick::Image.new(10, 10) + pr.draw(canvas) end end