-
Notifications
You must be signed in to change notification settings - Fork 28
/
sdlx_fps.t
68 lines (51 loc) · 1.67 KB
/
sdlx_fps.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use strict;
use warnings;
use Test::More;
use SDL;
use SDL::Config;
use SDL::Video;
use SDLx::FPS;
use lib 't/lib';
use SDL::TestTool;
my $videodriver = $ENV{SDL_VIDEODRIVER};
$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
plan( skip_all => 'Failed to init video' );
} elsif ( !SDL::Config->has('SDL_image') ) {
plan( skip_all => 'SDL_image support not compiled' );
}
can_ok( 'SDLx::FPS', qw( new set get delay framecount rateticks lastticks rate ) );
my $_fps = 25;
my $ticks_start = SDL::get_ticks();
my $fps = SDLx::FPS->new( fps => $_fps );
my $ticks_init = SDL::get_ticks();
isa_ok( $fps, 'SDLx::FPS' );
is( $fps->get, $_fps, 'fps->get' );
is( $fps->rate, $_fps, 'fps->rate' );
cmp_ok( $fps->lastticks, '>=', $ticks_start, 'fps->lastticks' );
cmp_ok( $fps->lastticks, '<=', $ticks_init, 'fps->lastticks' );
# rateticks is Uint32, so precision differs
ok( $fps->rateticks - 1000 / $_fps < 0.000001, 'fps->rateticks' );
my $count = 10;
for ( 1 .. $count ) {
$fps->delay;
}
is( $fps->framecount, $count, 'fps->framecount' );
$_fps = 20;
$fps->set($_fps);
is( $fps->get, $_fps, 'fps->get after fps->set' );
my $ticks_pre_delay = SDL::get_ticks();
$fps->delay;
my $ticks_post_delay = SDL::get_ticks();
cmp_ok( $fps->lastticks, '>=', $ticks_pre_delay, 'fps->lastticks after fps->delay' );
cmp_ok( $fps->lastticks, '<=', $ticks_post_delay, 'fps->lastticks after fps->delay' );
$fps = SDLx::FPS->new();
is( $fps->get, 30, 'fps->get default value' );
#reset the old video driver
if ($videodriver) {
$ENV{SDL_VIDEODRIVER} = $videodriver;
} else {
delete $ENV{SDL_VIDEODRIVER};
}
pass 'Final SegFault test';
done_testing;