From: Tobias Leich Date: Sat, 7 Nov 2009 23:10:19 +0000 (+0100) Subject: added new() methods and their tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7bcf8bea77e33403c18bfb6734887fc819bfd8f1;p=sdlgit%2FSDL_perl.git added new() methods and their tests --- diff --git a/src/Core/objects/ActiveEvent.xs b/src/Core/objects/ActiveEvent.xs index 3721798..bb2b333 100644 --- a/src/Core/objects/ActiveEvent.xs +++ b/src/Core/objects/ActiveEvent.xs @@ -23,6 +23,15 @@ SDL_ActiveEvent -- Application visibility event structure =cut +SDL_ActiveEvent * +aevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_ActiveEvent)); + RETVAL->type = SDL_ACTIVEEVENT; + OUTPUT: + RETVAL + Uint8 aevent_type ( event, ... ) SDL_ActiveEvent *event diff --git a/src/Core/objects/ExposeEvent.xs b/src/Core/objects/ExposeEvent.xs index 8692875..1ba38e2 100644 --- a/src/Core/objects/ExposeEvent.xs +++ b/src/Core/objects/ExposeEvent.xs @@ -21,6 +21,15 @@ SDL_ExposeEvent -- Window expose event =cut +SDL_ExposeEvent * +weevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_ExposeEvent)); + RETVAL->type = SDL_VIDEOEXPOSE; + OUTPUT: + RETVAL + Uint8 weevent_type ( event, ... ) SDL_ExposeEvent *event diff --git a/src/Core/objects/JoyAxisEvent.xs b/src/Core/objects/JoyAxisEvent.xs index 53b04c7..b19b9f6 100644 --- a/src/Core/objects/JoyAxisEvent.xs +++ b/src/Core/objects/JoyAxisEvent.xs @@ -24,6 +24,15 @@ SDL_JoyAxisEvent -- Joystick axis motion event structure =cut +SDL_JoyAxisEvent * +jaevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_JoyAxisEvent)); + RETVAL->type = SDL_JOYAXISMOTION; + OUTPUT: + RETVAL + Uint8 jaevent_type ( event, ... ) SDL_JoyAxisEvent *event diff --git a/src/Core/objects/JoyBallEvent.xs b/src/Core/objects/JoyBallEvent.xs index 1601596..7ef2a02 100644 --- a/src/Core/objects/JoyBallEvent.xs +++ b/src/Core/objects/JoyBallEvent.xs @@ -24,6 +24,15 @@ SDL_JoyBallEvent -- Joystick trackball motion event structure =cut +SDL_JoyBallEvent * +jtevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_JoyBallEvent)); + RETVAL->type = SDL_JOYBALLMOTION; + OUTPUT: + RETVAL + Uint8 jtevent_type ( event, ... ) SDL_JoyBallEvent *event diff --git a/src/Core/objects/JoyButtonEvent.xs b/src/Core/objects/JoyButtonEvent.xs index d966672..3727e81 100644 --- a/src/Core/objects/JoyButtonEvent.xs +++ b/src/Core/objects/JoyButtonEvent.xs @@ -24,6 +24,15 @@ SDL_JoyButtonEvent -- Joystick button event structure =cut +SDL_JoyButtonEvent * +jbevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_JoyButtonEvent)); + RETVAL->type = SDL_JOYBUTTONDOWN | SDL_JOYBUTTONUP; + OUTPUT: + RETVAL + Uint8 jbevent_type ( event ) diff --git a/src/Core/objects/JoyHatEvent.xs b/src/Core/objects/JoyHatEvent.xs index fd3ff11..394bc16 100644 --- a/src/Core/objects/JoyHatEvent.xs +++ b/src/Core/objects/JoyHatEvent.xs @@ -24,6 +24,15 @@ SDL_JoyHatEvent -- Joystick hat position change event structure =cut +SDL_JoyHatEvent * +jhevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_JoyHatEvent)); + RETVAL->type = SDL_JOYHATMOTION; + OUTPUT: + RETVAL + Uint8 jhevent_type ( event, ... ) SDL_JoyHatEvent *event diff --git a/src/Core/objects/KeyboardEvent.xs b/src/Core/objects/KeyboardEvent.xs index 94ad8c6..d069662 100644 --- a/src/Core/objects/KeyboardEvent.xs +++ b/src/Core/objects/KeyboardEvent.xs @@ -23,6 +23,15 @@ SDL_KeyboardEvent --Keyboard event structure =cut +SDL_KeyboardEvent * +kbevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_KeyboardEvent)); + RETVAL->type = SDL_KEYDOWN | SDL_KEYUP; + OUTPUT: + RETVAL + Uint8 kbevent_type ( event, ... ) SDL_KeyboardEvent *event diff --git a/src/Core/objects/MouseButtonEvent.xs b/src/Core/objects/MouseButtonEvent.xs index f15cbc3..9b8e3b3 100644 --- a/src/Core/objects/MouseButtonEvent.xs +++ b/src/Core/objects/MouseButtonEvent.xs @@ -25,6 +25,15 @@ SDL_MouseButtonEvent -- Mouse button event structure =cut +SDL_MouseButtonEvent * +mbevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_MouseButtonEvent)); + RETVAL->type = SDL_MOUSEBUTTONDOWN | SDL_MOUSEBUTTONUP; + OUTPUT: + RETVAL + Uint8 mbevent_type ( event, ... ) SDL_MouseButtonEvent *event diff --git a/src/Core/objects/MouseMotionEvent.xs b/src/Core/objects/MouseMotionEvent.xs index 3441108..4836df8 100644 --- a/src/Core/objects/MouseMotionEvent.xs +++ b/src/Core/objects/MouseMotionEvent.xs @@ -24,6 +24,15 @@ SDL_MouseMotionEvent -- Mouse motion event structure =cut +SDL_MouseMotionEvent * +mmevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_MouseMotionEvent)); + RETVAL->type = SDL_MOUSEMOTION; + OUTPUT: + RETVAL + Uint8 mmevent_type ( event, ... ) SDL_MouseMotionEvent *event diff --git a/src/Core/objects/QuitEvent.xs b/src/Core/objects/QuitEvent.xs index b33ccbb..2e11418 100644 --- a/src/Core/objects/QuitEvent.xs +++ b/src/Core/objects/QuitEvent.xs @@ -21,6 +21,15 @@ SDL_QuitEvent -- Quit requested event =cut +SDL_QuitEvent * +qevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_QuitEvent)); + RETVAL->type = SDL_QUIT; + OUTPUT: + RETVAL + Uint8 qevent_type ( event, ... ) SDL_QuitEvent *event diff --git a/src/Core/objects/ResizeEvent.xs b/src/Core/objects/ResizeEvent.xs index c6cedd0..4ce2b18 100644 --- a/src/Core/objects/ResizeEvent.xs +++ b/src/Core/objects/ResizeEvent.xs @@ -22,6 +22,15 @@ SDL_ResizeEvent -- Window resize event structure =cut +SDL_ResizeEvent * +wrevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_ResizeEvent)); + RETVAL->type = SDL_VIDEORESIZE; + OUTPUT: + RETVAL + Uint8 wrevent_type ( event, ... ) SDL_ResizeEvent *event diff --git a/src/Core/objects/SysWMEvent.xs b/src/Core/objects/SysWMEvent.xs index 5f7354b..7e91b56 100644 --- a/src/Core/objects/SysWMEvent.xs +++ b/src/Core/objects/SysWMEvent.xs @@ -23,6 +23,15 @@ see also: L =cut +SDL_SysWMEvent * +wmevent_new ( CLASS ) + char* CLASS + CODE: + RETVAL = safemalloc(sizeof(SDL_SysWMEvent)); + RETVAL->type = SDL_SYSWMEVENT; + OUTPUT: + RETVAL + Uint8 wmevent_type ( event, ... ) SDL_SysWMEvent *event diff --git a/t/core_events.t b/t/core_events.t index ee11ad9..9866d98 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 => 38 ); +plan ( tests => 51 ); my @done =qw/ pump_events @@ -79,12 +79,44 @@ 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'); +my $event = SDL::Event->new(); +my $aevent = SDL::ActiveEvent->new(); +my $weevent = SDL::ExposeEvent->new(); +my $jaevent = SDL::JoyAxisEvent->new(); +my $jtevent = SDL::JoyBallEvent->new(); +my $jbevent = SDL::JoyButtonEvent->new(); +my $jhevent = SDL::JoyHatEvent->new(); +my $kbevent = SDL::KeyboardEvent->new(); +my $mbevent = SDL::MouseButtonEvent->new(); +my $mmevent = SDL::MouseMotionEvent->new(); +my $qevent = SDL::QuitEvent->new(); +my $wrevent = SDL::ResizeEvent->new(); +my $wmevent = SDL::SysWMEvent->new(); +my $uevent = SDL::UserEvent->new(); + +#isa_ok( $event, 'SDL::Event', '[SDL::Event::new] is creating an Event'); +isa_ok( $aevent, 'SDL::ActiveEvent', '[SDL::ActiveEvent::new] is creating an ActiveEvent'); +isa_ok( $weevent, 'SDL::ExposeEvent', '[SDL::ExposeEvent::new] is creating an ExposeEvent'); +isa_ok( $jaevent, 'SDL::JoyAxisEvent', '[SDL::JoyAxisEvent::new] is creating an JoyAxisEvent'); +isa_ok( $jtevent, 'SDL::JoyBallEvent', '[SDL::JoyBallEvent::new] is creating an JoyBallEvent'); +isa_ok( $jbevent, 'SDL::JoyButtonEvent', '[SDL::JoyButtonEvent::new] is creating an JoyButtonEvent'); +isa_ok( $jhevent, 'SDL::JoyHatEvent', '[SDL::JoyHatEvent::new] is creating an JoyHatEvent'); +isa_ok( $kbevent, 'SDL::KeyboardEvent', '[SDL::KeyboardEvent::new] is creating an KeyboardEvent'); +isa_ok( $mbevent, 'SDL::MouseButtonEvent', '[SDL::MouseButtonEvent::new] is creating an MouseButtonEvent'); +isa_ok( $mmevent, 'SDL::MouseMotionEvent', '[SDL::MouseMotionEvent::new] is creating an MouseMotionEvent'); +isa_ok( $qevent, 'SDL::QuitEvent', '[SDL::QuitEvent::new] is creating an QuitEvent'); +isa_ok( $wrevent, 'SDL::ResizeEvent', '[SDL::ResizeEvent::new] is creating an ResizeEvent'); +isa_ok( $wmevent, 'SDL::SysWMEvent', '[SDL::SysWMEvent::new] is creating an SysWMEvent'); +isa_ok( $uevent, 'SDL::UserEvent', '[SDL::UserEvent::new] is creating an UserEvent'); + is( $uevent->type, 0x0018, '[SDL::UserEvent->type] returns correctly'); + +$uevent->code(200); is( $uevent->code, 200, '[SDL::UserEvent->code] is set correctly'); +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); + TODO: { local $TODO = 'Try to send a Scalar Ref as an IV and return a Scalar Ref'; @@ -99,7 +131,7 @@ is( $uevent->data2, 'notwow','[SDL::UserEvent->data2] is set correctly'); =pod my $events = SDL::Event->new(); -my $num_peep_events = SDL::Events::peep_events( $events, 127, SDL_PEEKEVENT, SDL_ALLEVENTS); +my $num_peep_events = SDL::Events::peep_events( SDL::Event->new(), 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();