added new() methods and their tests
Tobias Leich [Sat, 7 Nov 2009 23:10:19 +0000 (00:10 +0100)]
13 files changed:
src/Core/objects/ActiveEvent.xs
src/Core/objects/ExposeEvent.xs
src/Core/objects/JoyAxisEvent.xs
src/Core/objects/JoyBallEvent.xs
src/Core/objects/JoyButtonEvent.xs
src/Core/objects/JoyHatEvent.xs
src/Core/objects/KeyboardEvent.xs
src/Core/objects/MouseButtonEvent.xs
src/Core/objects/MouseMotionEvent.xs
src/Core/objects/QuitEvent.xs
src/Core/objects/ResizeEvent.xs
src/Core/objects/SysWMEvent.xs
t/core_events.t

index 3721798..bb2b333 100644 (file)
@@ -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
index 8692875..1ba38e2 100644 (file)
@@ -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
index 53b04c7..b19b9f6 100644 (file)
@@ -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
index 1601596..7ef2a02 100644 (file)
@@ -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
index d966672..3727e81 100644 (file)
@@ -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 )
 
index fd3ff11..394bc16 100644 (file)
@@ -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
index 94ad8c6..d069662 100644 (file)
@@ -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
index f15cbc3..9b8e3b3 100644 (file)
@@ -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
index 3441108..4836df8 100644 (file)
@@ -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
index b33ccbb..2e11418 100644 (file)
@@ -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
index c6cedd0..4ce2b18 100644 (file)
@@ -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
index 5f7354b..7e91b56 100644 (file)
@@ -23,6 +23,15 @@ see also: L<SDL::WindowManagement::sys_WM_event>
 
 =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
index ee11ad9..9866d98 100644 (file)
@@ -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();