File: sdlx_fps.t

package info (click to toggle)
libsdl-perl 2.548-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,972 kB
  • sloc: perl: 13,985; ansic: 583; makefile: 35
file content (70 lines) | stat: -rw-r--r-- 1,866 bytes parent folder | download | duplicates (6)
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
69
70
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 = 5;

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' );
# Since SDL_gfx version 2.0.24 the ticks we get are always non-zero,
# but SDL can still report 0 as $ticks_init, and then the test had failed.
cmp_ok( $fps->lastticks, '<=', ($ticks_init || 1),  '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;
}
cmp_ok( $fps->framecount, '>', 0, '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 || 1), '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;