PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/t/core_timer.t

http://github.com/PerlGameDev/SDL
Perl | 66 lines | 51 code | 14 blank | 1 comment | 4 complexity | 91d4821cd3f261d191d4293e9560b468 MD5 | raw file
 1#!/usr/bin/perl -w
 2BEGIN { # http://wiki.cpantesters.org/wiki/CPANAuthorNotes
 3	use Config;
 4	if ( !$Config{'useithreads'} ) {
 5		print("1..0 # Skip: Perl not compiled with 'useithreads'\n");
 6		exit(0);
 7	}
 8}
 9use threads;
10use threads::shared;
11use strict;
12use warnings;
13use SDL;
14use Test::More;
15use SDL::Time;
16use Config;
17
18use lib 't/lib';
19use SDL::TestTool;
20
21if ( !SDL::TestTool->init(SDL_INIT_TIMER) ) {
22	plan( skip_all => 'Failed to init timer' );
23} else {
24	plan( tests => 6 );
25}
26
27my @done = qw/get_ticks
28	delay/;
29
30my $before = SDL::get_ticks();
31like( $before, qr/^\d+$/, '[get_ticks] returns a number' );
32
33SDL::delay(250);
34my $after = SDL::get_ticks();
35like( $after, qr/^\d+$/, '[get_ticks] returns a number again' );
36
37my $diff = $after - $before;
38ok( $diff > 100 && $diff < 400, '[delay](250) delayed for ' . $diff . 'ms' );
39
40my $fired : shared = 0;
41
42sub fire { $fired++; return 100 }
43
44my $id = SDL::Time::add_timer( 101, 'main::fire' );
45
46sleep(2);
47is( SDL::Time::remove_timer($id), 1, "[remove_timer] removed $id timer" );
48isnt( $fired, 0, '[add_timer] ran ' . $fired );
49
50my @left = qw/set_timer new_timer_callback add_timer remove_timer/;
51
52my $why =
53	  '[Percentage Completion] '
54	. int( 100 * ( $#done + 1 ) / ( $#done + $#left + 2 ) )
55	. "\% implementation. "
56	. ( $#done + 1 ) . " / "
57	. ( $#done + $#left + 2 );
58
59TODO:
60{
61	local $TODO = $why;
62	pass "\nThe following functions:\n" . join ",", @left;
63}
64print "$why\n";
65
66sleep(2);