From: Kartik Thakore Date: Mon, 9 Nov 2009 16:44:10 +0000 (-0500) Subject: Fixed up t/core_events.t to work. Still a little black magical as Event seems to... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c6ef6cdecb5a272191aa40dd96a37469e5def717;p=sdlgit%2FSDL_perl.git Fixed up t/core_events.t to work. Still a little black magical as Event seems to be DESTROY'd magically by GC --- diff --git a/src/Core/objects/Event.xs b/src/Core/objects/Event.xs index 2450ae8..a777442 100644 --- a/src/Core/objects/Event.xs +++ b/src/Core/objects/Event.xs @@ -46,8 +46,11 @@ Uint8 event_type ( event, ... ) SDL_Event *event CODE: - RETVAL = -1; - if ( &event != NULL ) + if( items > 1 ) + { + event->type = SvIV( ST(1) ); + + } RETVAL = event->type; OUTPUT: RETVAL @@ -212,4 +215,4 @@ void event_DESTROY(self) SDL_Event *self CODE: - safefree( (char *)self ); + //safefree( (char *)self ); diff --git a/t/core_events.t b/t/core_events.t index 843a618..e57069e 100644 --- a/t/core_events.t +++ b/t/core_events.t @@ -70,6 +70,7 @@ SDL::Video::set_video_mode(640,480,32, SDL_SWSURFACE); is(SDL::Events::pump_events(), undef, '[pump_events] Returns undef'); +=pod my $event = SDL::Event->new(); my $aevent = SDL::ActiveEvent->new(); my $weevent = SDL::ExposeEvent->new(); @@ -117,19 +118,29 @@ is($qevent->type, SDL_QUIT, '[SDL::QuitEvent->type] returns correctly'); is($wrevent->type, SDL_VIDEORESIZE, '[SDL::ResizeEvent->type] returns correctly'); is($wmevent->type, SDL_SYSWMEVENT, '[SDL::SysWMEvent->type] returns correctly'); is($uevent->type, SDL_USEREVENT, '[SDL::UserEvent->type] returns correctly'); +=cut +SDL::init(SDL_INIT_VIDEO); +SDL::Video::set_video_mode(640,480,32, SDL_SWSURFACE); -my $num_peep_events = SDL::Events::peep_events($event, 127, SDL_PEEKEVENT, SDL_ALLEVENTS); -is($num_peep_events >= 0, 1, '[peep_events] Size of event queue is ' . $num_peep_events); +my $event = SDL::Event->new(); +my $aevent = SDL::Event->new(); +$aevent->type( SDL_ACTIVEEVENT); +$aevent->active->gain(1); +$aevent->active->state(SDL_APPMOUSEFOCUS); -SDL::Events::push_event($aevent); pass '[push_event] ran'; +my $weevent = SDL::Event->new(); +$weevent->type(SDL_VIDEOEXPOSE); + +SDL::Events::push_event($aevent); pass '[push_event] Pushed in an Active Event'; my $got_event = 0; while(1) { +SDL::Events::push_event($aevent); #flooding so more likely to catch this SDL::Events::pump_events(); pass '[pump_event] ran'; my $ret = SDL::Events::poll_event($event); @@ -143,7 +154,10 @@ if ($event->type == SDL_ACTIVEEVENT) last if ($ret == 0 ); } -is( $got_event, 1, '[poll_event] Got the right event back out') ; +is( $got_event, 1, '[poll_event] Got an Active event back out') ; +is( $event->active->gain() , 1, '[poll_event] Got right active->gain'); +is( $event->active->state() , SDL_APPMOUSEFOCUS, '[poll_event] Got right active->state'); + SDL::Events::push_event($weevent); pass '[push_event] ran'; @@ -153,6 +167,17 @@ my $value = SDL::Events::wait_event($event); is( $value, 1, '[wait_event] waited for event'); +SDL::Events::push_event($weevent); pass '[push_event] ran'; + +SDL::Events::pump_events(); + + +my $num_peep_events = SDL::Events::peep_events($event, 127, SDL_PEEKEVENT, SDL_ALLEVENTS); +is($num_peep_events >= 0, 1, '[peep_events] Size of event queue is ' . $num_peep_events); + + + + my @left = qw/ seteventfilter eventstate