Browse Source

Fix args type checks in Caca::Display.new

tags/v0.99.beta14
Pascal Terjan pterjan 16 years ago
parent
commit
cdab8ff469
2 changed files with 14 additions and 7 deletions
  1. +3
    -3
      ruby/caca-display.c
  2. +11
    -4
      ruby/t/tc_display.rb

+ 3
- 3
ruby/caca-display.c View File

@@ -53,15 +53,15 @@ static VALUE display_initialize(int argc, VALUE* argv, VALUE self)
cv = arg2;
}

if(CLASS_OF(arg1) == T_STRING)
if(TYPE(arg1) == T_STRING)
{
driver = StringValuePtr(arg1);
if(CLASS_OF(arg2) == T_STRING)
if(TYPE(arg2) == T_STRING)
{
rb_raise(rb_eArgError, "Only one argument can be a string");
}
}
else if(CLASS_OF(arg2) == T_STRING)
else if(TYPE(arg2) == T_STRING)
{
driver = StringValuePtr(arg2);
}


+ 11
- 4
ruby/t/tc_display.rb View File

@@ -3,18 +3,25 @@ require 'caca'

class TC_Canvas < Test::Unit::TestCase
def test_create
d = Caca::Display.new
d = Caca::Display.new
assert_not_nil(d, 'Display creation failed')
end
def test_create_with_driver
d = Caca::Display.new(nil, Caca::Display.driver_list[0])
d = Caca::Display.new(Caca::Display.driver_list[0])
assert_not_nil(d, 'Display creation failed')
end
def test_create_wrong_args
assert_raise(RuntimeError){Caca::Display.new("plop")}
driver = Caca::Display.driver_list[0]
assert_raise(ArgumentError){Caca::Display.new(driver, driver)}
c = Cucul::Canvas.new(3, 3)
assert_raise(ArgumentError){Caca::Display.new(c, c)}
end
def test_create_from_canvas
c = Cucul::Canvas.new(3, 3)
d = Caca::Display.new(c)
d = Caca::Display.new(c)
assert_not_nil(d, 'Display creation failed')
assert_equal(d.canvas, c, 'Wrong canvas')
assert_equal(d.canvas, c, 'Wrong canvas')
end
def test_set_title
c = Cucul::Canvas.new(3, 3)


Loading…
Cancel
Save