From: Kartik Thakore Date: Sat, 7 Nov 2009 22:05:54 +0000 (-0500) Subject: Made UserEvent new and code work with test. Ignore data1,data2 for now X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=73845dc71d861a40a04bce5b8fac54ca1b2e4e32;p=sdlgit%2FSDL_perl.git Made UserEvent new and code work with test. Ignore data1,data2 for now --- diff --git a/src/Core/objects/UserEvent.xs b/src/Core/objects/UserEvent.xs index bc66ab2..36dd650 100644 --- a/src/Core/objects/UserEvent.xs +++ b/src/Core/objects/UserEvent.xs @@ -23,14 +23,20 @@ SDL_UserEvent -- A user-defined event type =cut + +SDL_UserEvent * +uevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_UserEvent)); + RETVAL->type = SDL_USEREVENT; + OUTPUT: + RETVAL + Uint8 -uevent_type ( event, ... ) +uevent_type ( event ) SDL_UserEvent *event CODE: - if( items > 2) - { - event->type = SvIV(ST(1)); - } RETVAL = event->type; OUTPUT: RETVAL @@ -39,27 +45,43 @@ int uevent_code ( event, ... ) SDL_UserEvent *event CODE: - if( items > 2 ) + if( items > 1 ) { - event->code = SvIV(ST(1)); + event->code = SvIV( ST(1) ); + } - RETVAL = event->code; + RETVAL = (int)event->code; OUTPUT: RETVAL -void -uevent_data1 ( event, data ) +SV* +uevent_data1 ( event, ... ) SDL_UserEvent *event - IV data - CODE: - void * dataP = INT2PTR( void *, data); - event->data1 = dataP; + CODE: + if( items > 1 ) + { + event->data1 = (void *)SvIV(ST(1)); + } + RETVAL = event->data1; + OUTPUT: + RETVAL -void -uevent_data2 ( event, data ) +SV* +uevent_data2 ( event, ... ) SDL_UserEvent *event - IV data + CODE: + if( items > 1 ) + { + event->data1 = (void *) ST(1); + } + RETVAL = event->data1; + OUTPUT: + RETVAL + + +void +uevent_DESTROY(self) + SDL_UserEvent *self CODE: - void * dataP = INT2PTR( void *, data); - event->data2 = dataP; + safefree( (char *)self ); diff --git a/t/core_events.t b/t/core_events.t index de0403f..ee11ad9 100644 --- a/t/core_events.t +++ b/t/core_events.t @@ -19,7 +19,7 @@ use SDL::UserEvent; use SDL::Video; use Test::More; -plan ( tests => 33 ); +plan ( tests => 38 ); my @done =qw/ pump_events @@ -79,6 +79,23 @@ SDL::Video::set_video_mode(640,480,32, SDL_SWSURFACE); is(SDL::Events::pump_events(), undef, '[pump_events] Returns undef'); +my $uevent = SDL::UserEvent->new(); +$uevent->code(200 ); +isa_ok( $uevent, 'SDL::UserEvent', '[SDL::UserEvent::new] is creating a User Event'); +is( $uevent->type, 0x0018, '[SDL::UserEvent->type] returns correctly'); +is( $uevent->code, 200, '[SDL::UserEvent->code] is set correctly'); + +TODO: +{ + local $TODO = 'Try to send a Scalar Ref as an IV and return a Scalar Ref'; + +my $data1 = 'wow'; +$uevent->data1(\$data1); +$uevent->data2('notwow'); +is( $uevent->data1, 'wow', '[SDL::UserEvent->data1] is set correctly'); +is( $uevent->data2, 'notwow','[SDL::UserEvent->data2] is set correctly'); +} + =pod my $events = SDL::Event->new();