added event tests
Tobias Leich [Fri, 6 Nov 2009 17:40:46 +0000 (18:40 +0100)]
lib/SDL/Game/Event.pm [new file with mode: 0644]
t/core_events.t
t/eventpm.t

diff --git a/lib/SDL/Game/Event.pm b/lib/SDL/Game/Event.pm
new file mode 100644 (file)
index 0000000..34e109b
--- /dev/null
@@ -0,0 +1,194 @@
+#!/usr/bin/env perl
+#
+# Event.pm
+#
+# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
+#
+# ------------------------------------------------------------------------------
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+# 
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+# 
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# ------------------------------------------------------------------------------
+#
+# Please feel free to send questions, suggestions or improvements to:
+#
+#      David J. Goehrig
+#      dgoehrig@cpan.org
+#
+
+package SDL::Game::Event;
+
+use strict;
+use warnings;
+use Carp;
+
+use SDL;
+
+sub new {
+       my $proto = shift;
+       my $class = ref($proto) || $proto;
+       my $self;
+       $self = \SDL::NewEvent();
+       bless $self, $class;
+       return $self;
+}
+
+sub DESTROY {
+       my $self = shift;
+       SDL::FreeEvent($$self);
+}
+
+sub type {
+       my $self = shift;
+       if (@_) {
+               SDL::SetEventType($$self,$_[0]);
+       }
+       return SDL::EventType($$self);
+}
+
+sub pump {
+       SDL::PumpEvents();
+}
+
+sub poll {
+       my $self = shift;
+       return SDL::PollEvent($$self);
+}
+
+sub push {
+       my $self = shift;
+       return SDL::PushEvent($$self);
+}
+
+sub wait {
+       my $self = shift;
+       return SDL::WaitEvent($$self);
+}
+
+sub set { 
+       my $self = shift;
+       my $state = shift;
+       return SDL::EventState($self->type(),$state);
+}
+
+sub set_unicode {
+       my $self = shift;
+       my $toggle = shift;
+       return SDL::EnableUnicode($toggle);
+}
+
+sub set_key_repeat {
+       my $self = shift;
+       my $delay = shift;
+       my $interval = shift;
+       return SDL::EnableKeyRepeat($delay,$interval);
+}
+
+sub active_gain {
+       my $self = shift;
+       return SDL::ActiveEventGain($$self);
+}
+
+sub active_state {
+       my $self = shift;
+       return SDL::ActiveEventState($$self);
+}
+
+sub key_state {
+       my $self = shift;
+       return SDL::KeyEventState($$self);
+}
+
+sub key_sym {
+       my $self = shift;
+       return SDL::KeyEventSym($$self);
+}
+
+sub key_name {
+       my $self = shift;
+       return SDL::GetKeyName(SDL::KeyEventSym($$self));
+}
+
+sub key_mod {
+       my $self = shift;
+       return SDL::KeyEventMod($$self);
+}
+
+sub key_unicode {
+       my $self = shift;
+       return SDL::KeyEventUnicode($$self);
+}
+
+sub key_scancode {
+       my $self = shift;
+       return SDL::KeyEventScanCode($$self);
+}
+
+sub motion_state {
+       my $self = shift;
+       return SDL::MouseMotionState($$self);
+}
+
+sub motion_x {
+       my $self = shift;
+       return SDL::MouseMotionX($$self);
+}
+
+sub motion_y {
+       my $self = shift;
+       return SDL::MouseMotionY($$self);
+}
+
+sub motion_xrel {
+       my $self = shift;
+       return SDL::MouseMotionXrel($$self);
+}
+
+sub motion_yrel {
+       my $self = shift;
+       return SDL::MouseMotionYrel($$self);
+}
+
+sub button_state {
+       my $self = shift;
+       return SDL::MouseButtonState($$self);
+}
+
+sub button_x {
+       my $self = shift;
+       return SDL::MouseButtonX($$self);
+}
+
+sub button_y {
+       my $self = shift;
+       return SDL::MouseButtonY($$self);
+}
+
+sub button {
+       my $self = shift;
+       return SDL::MouseButton($$self);
+}
+
+sub resize_w {
+       my $self = shift;
+       SDL::ResizeEventW($$self);
+}
+
+sub resize_h {
+       my $self = shift;
+       SDL::ResizeEventH($$self);
+}
+
+1;
index c179845..de0403f 100644 (file)
@@ -2,19 +2,76 @@
 use strict;
 use SDL;
 use SDL::Event;
-#use SDL::Surface;
+use SDL::Events;
+use SDL::ActiveEvent;
+use SDL::ExposeEvent;
+use SDL::JoyAxisEvent;
+use SDL::JoyBallEvent;
+use SDL::JoyButtonEvent;
+use SDL::JoyHatEvent;
+use SDL::KeyboardEvent;
+use SDL::MouseButtonEvent;
+use SDL::MouseMotionEvent;
+use SDL::QuitEvent;
+use SDL::ResizeEvent;
+use SDL::SysWMEvent;
+use SDL::UserEvent;
 use SDL::Video;
 use Test::More;
 
-plan ( tests => 5);
+plan ( tests => 33 );
 
 my @done =qw/
 pump_events 
 /;
 
+my @done_event =qw/
+type
+active
+key
+motion
+button
+jaxis
+jball
+jhat
+jbutton
+resize
+expose
+quit
+user
+syswm
+/;
 
 use_ok( 'SDL::Events' ); 
-can_ok ('SDL::Events', @done); 
+use_ok( 'SDL::Event' ); 
+use_ok( 'SDL::ActiveEvent' ); 
+use_ok( 'SDL::ExposeEvent' ); 
+use_ok( 'SDL::JoyAxisEvent' ); 
+use_ok( 'SDL::JoyBallEvent' ); 
+use_ok( 'SDL::JoyButtonEvent' ); 
+use_ok( 'SDL::JoyHatEvent' ); 
+use_ok( 'SDL::KeyboardEvent' ); 
+use_ok( 'SDL::MouseButtonEvent' ); 
+use_ok( 'SDL::MouseMotionEvent' ); 
+use_ok( 'SDL::QuitEvent' ); 
+use_ok( 'SDL::ResizeEvent' ); 
+use_ok( 'SDL::SysWMEvent' ); 
+use_ok( 'SDL::UserEvent' ); 
+can_ok( 'SDL::Events',           @done); 
+can_ok( 'SDL::Event',            @done_event);
+can_ok( 'SDL::ActiveEvent',      qw/type gain state/);
+can_ok( 'SDL::ExposeEvent',      qw/type/);
+can_ok( 'SDL::JoyAxisEvent',     qw/type which axis value/);
+can_ok( 'SDL::JoyBallEvent',     qw/type which ball xrel yrel/);
+can_ok( 'SDL::JoyButtonEvent',   qw/type which button state/);
+can_ok( 'SDL::JoyHatEvent',      qw/type which hat value/);
+can_ok( 'SDL::KeyboardEvent',    qw/type state keysym/);
+can_ok( 'SDL::MouseButtonEvent', qw/type which button state x y/);
+can_ok( 'SDL::MouseMotionEvent', qw/type state x y xrel yrel/);
+can_ok( 'SDL::QuitEvent',        qw/type/);
+can_ok( 'SDL::ResizeEvent',      qw/type w h/);
+can_ok( 'SDL::SysWMEvent',       qw/type msg/);
+can_ok( 'SDL::UserEvent',        qw/type code data1 data2/);
 
 SDL::init(SDL_INIT_VIDEO);                                                                          
 
index 3dca888..eeec62e 100644 (file)
@@ -29,7 +29,7 @@
 #      dgoehrig\@cpan.org
 #
 #
-# basic testing of SDL::Event
+# basic testing of SDL::Game::Event
 
 BEGIN {
        unshift @INC, 'blib/lib','blib/arch';
@@ -41,9 +41,9 @@ use Test::More;
 
 plan ( tests => 2 );
 
-use_ok( 'SDL::Event' ); 
+use_ok( 'SDL::Game::Event' ); 
   
-can_ok ('SDL::Event', qw/
+can_ok ('SDL::Game::Event', qw/
        new 
        type 
        pump