From: Tobias Leich Date: Wed, 4 Nov 2009 19:25:48 +0000 (+0100) Subject: +wait_event() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=619e0bd64e778b735aa127f387c89071314617d6;p=sdlgit%2FSDL_perl.git +wait_event() --- diff --git a/src/Core/Events.xs b/src/Core/Events.xs index 1e63a6e..cbeb46a 100644 --- a/src/Core/Events.xs +++ b/src/Core/Events.xs @@ -33,9 +33,9 @@ events_peep_events( events, numevents, action, mask ) int action Uint32 mask CODE: - if(!(action & (SDL_ADDEVENT | SDL_PEEKEVENT | SDL_GETEVENT))) + if(action != (action & (SDL_ADDEVENT | SDL_PEEKEVENT | SDL_GETEVENT))) { - croak('Value of \'action\' should be SDL_ADDEVENT, SDL_PEEKEVENT or SDL_GETEVENT.'); + croak("Value of 'action' should be SDL_ADDEVENT, SDL_PEEKEVENT or SDL_GETEVENT."); } RETVAL = SDL_PeepEvents(events,numevents,action,mask); OUTPUT: @@ -48,3 +48,19 @@ events_poll_event( event ) RETVAL = SDL_PollEvent(event); OUTPUT: RETVAL + +int +events_push_event(event) + SDL_Event *event + CODE: + RETVAL = SDL_PushEvent(event); + OUTPUT: + RETVAL + +int +events_wait_event(event = NULL) + SDL_Event *event + CODE: + RETVAL = SDL_WaitEvent(event); + OUTPUT: + RETVAL \ No newline at end of file diff --git a/t/core_events.t b/t/core_events.t index 5648691..498080f 100644 --- a/t/core_events.t +++ b/t/core_events.t @@ -6,12 +6,14 @@ use SDL::Event; #use SDL::Video; use Test::More; -plan ( tests => 7 ); +plan ( tests => 14 ); my @done =qw/ pump_events peep_events poll_event +push_event +wait_event /; @@ -30,9 +32,28 @@ my $event = SDL::Event->new(); my $value = SDL::Events::poll_event($event); is(($value == 1) || ($value == 0), 1, '[poll_event] Returns 1 or 0'); +my $event2 = SDL::Event->new(); +is(SDL::Events::push_event($event2), 0, '[push_event] Returns 0 on success'); +my $event3 = SDL::Event->new(); +is(SDL::Events::push_event($event3), 0, '[push_event] Returns 0 on success'); + +my $events2 = SDL::Event->new(); +my $num_peep_events2 = SDL::Events::peep_events( $events2, 127, SDL_PEEKEVENT, SDL_ALLEVENTS); +is($num_peep_events2 > $num_peep_events, 1, '[peep_events] Size of event queue is ' . $num_peep_events2); + +my $events3 = SDL::Event->new(); +$num_peep_events = SDL::Events::peep_events( $events3, 1, SDL_ADDEVENT, SDL_ALLEVENTS); +is($num_peep_events, 1, '[peep_events] Added 1 event to the back of the queue'); + +my $events4 = SDL::Event->new(); +$num_peep_events = SDL::Events::peep_events( $events4, 1, SDL_GETEVENT, SDL_ALLEVENTS); +is($num_peep_events, 1, '[peep_events] Got 1 event from the front of the queue'); + +my $event4 = SDL::Event->new(); +is(SDL::Events::wait_event($event4), 1, '[wait_event] Returns 1 on success'); +is(SDL::Events::wait_event(), 1, '[wait_event] Returns 1 on success'); + my @left = qw/ -waitevent -pushevent seteventfilter eventstate getkeystate