From: Leon Brocard Date: Tue, 10 Nov 2009 16:05:33 +0000 (+0000) Subject: Rename core_time.t to core_timer.t, implement get_ticks, delay X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f4772b70a6e20bdab30d491c877d1cff2fbb3ff4;p=sdlgit%2FSDL_perl.git Rename core_time.t to core_timer.t, implement get_ticks, delay --- diff --git a/src/SDL.xs b/src/SDL.xs index 81e3e7c..5b8c993 100644 --- a/src/SDL.xs +++ b/src/SDL.xs @@ -366,14 +366,14 @@ delay ( ms ) SDL_Delay(ms); Uint32 -GetTicks () +get_ticks () CODE: RETVAL = SDL_GetTicks(); OUTPUT: RETVAL int -SetTimer ( interval, callback ) +set_timer ( interval, callback ) Uint32 interval SDL_TimerCallback callback CODE: diff --git a/t/core_time.t b/t/core_time.t deleted file mode 100644 index 7188427..0000000 --- a/t/core_time.t +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/perl -w -use strict; -use SDL; -use Test::More; -use Test::Trap; -use Data::Dumper; - -plan ( tests => 4 ); -my @done =qw/ none /; - -SKIP: -{ -skip 'Not implemented', 2; -use_ok( 'SDL::Time' ); -can_ok ('SDL::Time', @done); -} - -my @timerInit = trap { SDL::init(SDL_INIT_TIMER) }; - -#diag $trap->leaveby; -#diag Dumper $trap->return; -#diag @timerInit[0]; - -my @left = qw/ - add_timer - delay - get_ticks - remove_timer -/; - -my $why = '[Percentage Completion] '.int( 100 * $#done / ($#done + $#left) ) ."\% implementation. $#done / ".($#done+$#left); - -TODO: -{ - local $TODO = $why; - pass "\nThe following functions:\n".join ",", @left; -} - if( $done[0] eq 'none'){ diag '0% done 0/'.$#left } else { diag $why} - - -pass 'Are we still alive? Checking for segfaults'; diff --git a/t/core_timer.t b/t/core_timer.t new file mode 100644 index 0000000..5101b85 --- /dev/null +++ b/t/core_timer.t @@ -0,0 +1,42 @@ +#!/usr/bin/perl -w +use strict; +use SDL; +use Test::More tests => 6; + +my @done = qw/get_ticks + delay/; + +is( SDL::init(SDL_INIT_TIMER), 0, '[init] can init SDL_INIT_TIMER' ); +is( SDL::was_init(0), SDL_INIT_TIMER, '[was_init] managed to init timer' ); + +my $before = SDL::get_ticks(); +like( $before, qr/^\d+$/, '[get_ticks] returns a number' ); + +# at the moment this segfaults. i wonder why? +# my $fired = 0; +# SDL::set_timer( 100, sub { warn "hi"; $fired = 1 } ); + +SDL::delay(250); +my $after = SDL::get_ticks(); +like( $after, qr/^\d+$/, '[get_ticks] returns a number again' ); + +my $diff = $after - $before; +ok( $diff > 50 && $diff < 300, '[delay](250) delayed for around 250ms' ); + +# is( $fired, 1, '[set_timer] triggered' ); + +my @left = qw/set_timer new_timer_callback add_timer remove_timer/; + +my $why + = '[Percentage Completion] ' + . int( 100 * ( $#done + 1 ) / ( $#done + $#left + 2 ) ) + . "\% implementation. " + . ( $#done + 1 ) . " / " + . ( $#done + $#left + 2 ); + +TODO: +{ + local $TODO = $why; + pass "\nThe following functions:\n" . join ",", @left; +} +diag $why;