Browse files

we can now compare SDL::Version objects like: >= 1.2.10

  • Loading branch information...
1 parent 3f51f0e commit 1a951ee57542fd904a23b7ce9d29abcc3cbe0509 @FROGGS FROGGS committed Feb 13, 2012
Showing with 27 additions and 34 deletions.
  1. +13 −0 lib/SDL/Version.pm
  2. +1 −2 t/gfx_primitives.t
  3. +2 −4 t/gfx_primitives2.t
  4. +3 −6 t/gfx_rotozoom.t
  5. +1 −2 t/image.t
  6. +2 −4 t/mixer.t
  7. +2 −4 t/mixer_music.t
  8. +2 −5 t/mixer_samples.t
  9. +1 −7 t/ttf.t
View
13 lib/SDL/Version.pm
@@ -8,6 +8,19 @@ our @ISA = qw(Exporter DynaLoader);
use SDL::Internal::Loader;
internal_load_dlls(__PACKAGE__);
+use overload '<=>' => \&my_cmp,
+ '""' => \&stringify;
+
bootstrap SDL::Version;
+sub stringify {
+ my $self = shift;
+ return sprintf "%s%s%s", chr($self->major), chr($self->minor), chr($self->patch);
+}
+
+sub my_cmp {
+ my ($left, $right) = @_;
+ return "$left" cmp "$right";
+}
+
1;
View
3 t/gfx_primitives.t
@@ -326,8 +326,7 @@ is( SDL::GFX::Primitives::filled_circle_RGBA( $surface, 555, 5, 2, 0xFF, 0xFF, 0
); # yellow
SKIP:
{
- skip( 'Version 2.0.17 needed', 2 )
- unless ( $v->major >= 2 && $v->minor >= 0 && $v->patch >= 17 );
+ skip( 'Version 2.0.17 needed', 2 ) if $v < 2.0.17;
is( SDL::GFX::Primitives::arc_color( $surface, 562, 5, 2, 5, 175, 0x00FF00FF ),
0,
'arc_color'
View
6 t/gfx_primitives2.t
@@ -168,8 +168,7 @@ is( SDL::GFX::Primitives::filled_polygon_RGBA(
); # magenta
SKIP:
{
- skip( 'Version 2.0.14 needed', 1 )
- unless ( $v->major >= 2 && $v->minor >= 0 && $v->patch >= 14 );
+ skip( 'Version 2.0.14 needed', 1 ) if $v < 2.0.14;
isnt(
SDL::GFX::Primitives::textured_polygon(
$display,
@@ -183,8 +182,7 @@ SKIP:
}
SKIP:
{
- skip( 'Version 2.0.17 needed', 3 )
- unless ( $v->major >= 2 && $v->minor >= 0 && $v->patch >= 17 );
+ skip( 'Version 2.0.17 needed', 3 ) if $v < 2.0.17;
is( SDL::GFX::Primitives::filled_polygon_color_MT(
$display,
[ 304, 308, 306, 308, 304 ],
View
9 t/gfx_rotozoom.t
@@ -65,8 +65,7 @@ is( $dest_h < 200, 1, 'surface_size, resulting height decreases at zoom 0.3' );
SKIP:
{
- skip( 'Version 2.0.13 needed', 1 )
- unless ( $v->major >= 2 && $v->minor >= 0 && $v->patch >= 13 );
+ skip( 'Version 2.0.13 needed', 1 ) if $v < 2.0.13;
isa_ok(
SDL::GFX::Rotozoom::surface_xy( $src, 1, 1, 1, 1 ),
'SDL::Surface', 'surface_xy'
@@ -108,8 +107,7 @@ is( $dest_h > 200, 1,
SKIP:
{
- skip( 'Version 2.0.14 needed', 1 )
- unless ( $v->major >= 2 && $v->minor >= 0 && $v->patch >= 14 );
+ skip( 'Version 2.0.14 needed', 1 ) if $v < 2.0.14;
isa_ok(
SDL::GFX::Rotozoom::shrink_surface( $src, 1, 1 ),
'SDL::Surface', 'shrink_surface'
@@ -119,8 +117,7 @@ SKIP:
$src = SDL::Surface->new( SDL_SWSURFACE, 100, 200, 32, 0, 0, 0, 0 );
SKIP:
{
- skip( 'Version 2.0.17 needed', 1 )
- unless ( $v->major >= 2 && $v->minor >= 0 && $v->patch >= 17 );
+ skip( 'Version 2.0.17 needed', 1 ) if $v < 2.0.17;
isa_ok(
SDL::GFX::Rotozoom::rotate_surface_90_degrees( $src, 1 ),
'SDL::Surface', 'rotate_surface_90_degrees'
View
3 t/image.t
@@ -172,8 +172,7 @@ is( IMG_INIT_TIF, 0x00000004, '[IMG_INIT_TIF] constant loaded properly' );
SKIP:
{
- skip( 'This is only for version >= 1.2.10', 2 )
- unless ( $lver->major >= 1 && $lver->minor >= 2 && $lver->patch >= 10 );
+ skip( 'This is only for version >= 1.2.10', 2 ) if $lver < 1.2.10;
SKIP:
{
skip( 'JPEG support not compiled', 1 ) unless SDL::Config->has('jpeg');
View
6 t/mixer.t
@@ -63,8 +63,7 @@ is( MIX_NO_FADING(), 0, 'MIX_NO_FADING() should also be available' );
SKIP:
{
- skip( 'Version 1.2.10 needed', 1 )
- unless ( $v->major >= 1 && $v->minor >= 2 && $v->patch >= 10 );
+ skip( 'Version 1.2.10 needed', 1 ) if $v < 1.2.10;
my @flags = ( MIX_INIT_MP3, MIX_INIT_MOD, MIX_INIT_FLAC, MIX_INIT_OGG );
my @names = qw/MP3 MOD FLAC OGG/;
foreach ( 0 ... 3 ) {
@@ -95,8 +94,7 @@ pass '[close_audio] ran';
SKIP:
{
- skip( 'Version 1.2.10 needed', 1 )
- unless ( $v->major >= 1 && $v->minor >= 2 && $v->patch >= 10 );
+ skip( 'Version 1.2.10 needed', 1 ) if $v < 1.2.10;
SDL::Mixer::quit();
pass '[quit] ran';
}
View
6 t/mixer_music.t
@@ -111,8 +111,7 @@ is( SDL::Mixer::Music::play_music( $sample_music, 0 ),
SKIP:
{
- skip( 'Version 1.2.7 needed', 2 )
- unless ( $v->major >= 1 && $v->minor >= 2 && $v->patch >= 7 );
+ skip( 'Version 1.2.7 needed', 2 ) if $v < 1.2.7;
my $rw = SDL::RWOps->new_file( $audio_test_file, "rb" );
my $sample_music_rw = SDL::Mixer::Music::load_MUS_RW( $rw );
@@ -124,8 +123,7 @@ SKIP:
SKIP:
{
- skip( 'Version 1.2.9 needed', 2 )
- unless ( $v->major >= 1 && $v->minor >= 2 && $v->patch >= 9 );
+ skip( 'Version 1.2.9 needed', 2 ) if $v < 1.2.9;
my $num_decoders = SDL::Mixer::Music::get_num_music_decoders();
is( $num_decoders >= 0,
View
7 t/mixer_samples.t
@@ -53,7 +53,7 @@ my @left = qw/
my $can_open = SDL::Mixer::open_audio( 44100, SDL::Audio::AUDIO_S16SYS, 2, 4096 );
-unless($can_open == 0)
+unless($can_open == 0)
{
plan( skip_all => 'Cannot open audio :'.SDL::get_error() );
}my $version = SDL::Mixer::linked_version();
@@ -64,10 +64,7 @@ printf(
SKIP:
{
- skip 'Need version 1.2.10', 2
- unless ( $version->major >= 1
- && $version->minor >= 2
- && $version->patch >= 10 );
+ skip 'Need version 1.2.10', 2 if $version < 1.2.10;
is( SDL::Mixer::Samples::get_num_chunk_decoders() >= 0,
1, '[get_num_chunk_decoders] passed'
View
8 t/ttf.t
@@ -137,13 +137,7 @@ is( SDL::TTF::get_font_style($font),
SKIP:
{
- skip( "Version 2.0.10 (or better) needed", 10 )
- unless $cv->major >= 2
- && $cv->minor >= 0
- && $cv->patch >= 10
- && $lv->major >= 2
- && $lv->minor >= 0
- && $lv->patch >= 10;
+ skip( "Version 2.0.10 (or better) needed", 10 ) if $cv < 2.0.10 || $lv < 2.0.10;
my $font_outline = SDL::TTF::get_font_outline($font);
ok( $font_outline >= 0, "[get_font_outline] is $font_outline" );
$font_outline++;

0 comments on commit 1a951ee

Please sign in to comment.