PageRenderTime 50ms CodeModel.GetById 35ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/t/sdlx_sprite.t

http://github.com/PerlGameDev/SDL
Unknown | 75 lines | 57 code | 18 blank | 0 comment | 0 complexity | 1e8967d5b5d8cf127216ca6aa9dd16f5 MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More;
 4use SDL;
 5use SDL::Config;
 6use SDL::Video;
 7use SDL::Color;
 8use SDLx::Sprite;
 9use lib 't/lib';
10use SDL::TestTool;
11
12my $videodriver = $ENV{SDL_VIDEODRIVER};
13$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
14
15if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
16	plan( skip_all => 'Failed to init video' );
17} elsif ( !SDL::Config->has('SDL_image') ) {
18	plan( skip_all => 'SDL_image support not compiled' );
19}
20
21
22can_ok(
23	'SDLx::Sprite', qw( new rect clip load surface x y
24		w h draw alpha_key)
25);
26
27TODO: {
28	local $TODO = 'methods not implemented yet';
29	can_ok( 'SDLx::Sprite', qw( add remove zoom ) );
30}
31
32
33my $disp = SDL::Video::set_video_mode( 300, 300, 32, SDL_ANYFORMAT );
34
35my $sprite = SDLx::Sprite->new( width => 1, height => 1 );
36
37# test initial values
38#ok($sprite, 'object defined');
39isa_ok( $sprite, 'SDLx::Sprite' );
40
41my $rect = $sprite->rect;
42ok( $rect, 'rect defined upon raw initialization' );
43isa_ok( $rect, 'SDL::Rect', 'spawned rect isa SDL::Rect' );
44is( $rect->x, 0, 'rect->x init' );
45is( $rect->y, 0, 'rect->y init' );
46is( $rect->w, 1, 'rect->w init' );
47is( $rect->h, 1, 'rect->h init' );
48
49my ( $x, $y ) = ( $sprite->x, $sprite->y );
50is( $x, 0, 'no x defined upon raw initialization' );
51is( $y, 0, 'no y defined upon raw initialization' );
52
53my ( $w, $h ) = ( $sprite->w, $sprite->h );
54is( $w, 1, 'w defined upon raw initialization' );
55is( $h, 1, 'h defined upon raw initialization' );
56
57isa_ok( $sprite->load('test/data/hero.bmp'), 'SDLx::Sprite', '[load] works' );
58
59isa_ok(
60	$sprite->alpha_key( SDL::Color->new( 0xfc, 0x00, 0xff ) ),
61	'SDLx::Sprite', '[alpha] works'
62);
63
64isa_ok( $sprite->alpha(0xcc), 'SDLx::Sprite', '[alpha] integer works ' );
65
66isa_ok( $sprite->alpha(0.3), 'SDLx::Sprite', '[alpha]  percentage works' );
67
68done_testing;
69
70#reset the old video driver
71if ($videodriver) {
72	$ENV{SDL_VIDEODRIVER} = $videodriver;
73} else {
74	delete $ENV{SDL_VIDEODRIVER};
75}