Changeset 2004 for libcaca


Ignore:
Timestamp:
Nov 17, 2007, 10:25:31 AM (13 years ago)
Author:
Pascal Terjan
Message:
  • Improve type checking of arguments
Location:
libcaca/trunk/ruby
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/ruby/cucul-canvas.c

    r1995 r2004  
    203203    Check_Type(x, T_FIXNUM);
    204204    Check_Type(y, T_FIXNUM);
    205     //FIXME rather check that class is cCanvas
    206     Check_Type(src, TYPE(self));
     205
     206    if(CLASS_OF(src) != cCanvas)
     207    {
     208        rb_raise(rb_eArgError, "src is not a Cucul::Canvas");
     209    }
    207210    Data_Get_Struct(src, cucul_canvas_t, csrc);
     211
    208212    if(!NIL_P(mask))
    209213    {
    210         //FIXME rather check that class is cCanvas
    211         Check_Type(mask, TYPE(self));
     214        if(CLASS_OF(mask) != cCanvas)
     215        {
     216            rb_raise(rb_eArgError, "mask is not a Cucul::Canvas");
     217        }
    212218        Data_Get_Struct(mask, cucul_canvas_t, cmask);
    213219    }
     
    494500    VALUE b;
    495501
    496     //FIXME rather check that class is cFont
    497     Check_Type(font, TYPE(self));
     502    if(CLASS_OF(font) != cFont)
     503    {
     504        rb_raise(rb_eArgError, "First argument is not a Cucul::Font");
     505    }
    498506
    499507    buf = malloc(width*height*4);
  • libcaca/trunk/ruby/t/tc_canvas.rb

    r1995 r2004  
    5151        assert_not_nil(c.render(f, c.width*f.width, c.height*f.height, c.width*f.width*4))
    5252    end
     53    def test_fail_render
     54        c = Cucul::Canvas.new(4,4)
     55        assert_raise(ArgumentError) {
     56            c.render(nil, c.width, c.height, c.width*4)
     57        }
     58    end
    5359end
Note: See TracChangeset for help on using the changeset viewer.