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
|
#!perl
use strict;
use warnings;
use Test::More;
use SDL;
use SDL::Surface;
use SDL::PixelFormat;
use SDL::Video;
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' );
} else {
plan( tests => 10 );
}
use_ok('SDL::Palette');
can_ok( 'SDL::Palette', qw/ ncolors colors color_index / );
my $display = SDL::Video::set_video_mode( 640, 480, 32, SDL_SWSURFACE );
isa_ok( $display->format, 'SDL::PixelFormat', 'Are we a SDL::PixelFormat?' );
ok( !defined $display->format->palette,
'Palette is not defined as BitPerPixels is greater then 8'
);
my $disp = SDL::Video::set_video_mode( 640, 480, 8, SDL_SWSURFACE );
SKIP:
{
skip( 'Cannot open display: ' . SDL::get_error(), 4 ) unless ($disp);
isa_ok( $disp->format, 'SDL::PixelFormat', 'Are we a SDL::PixelFormat?' );
isa_ok(
$disp->format->palette, 'SDL::Palette',
'Palette is SDL::Palette when BitPerPixels is 8 '
);
is( $disp->format->palette->ncolors, 256, '256 colors in palette' );
my $colors = $disp->format->palette->colors();
isa_ok( $colors, 'ARRAY', 'Palette->colors is an array' );
isa_ok( $colors->[0], 'SDL::Color', 'Palette->colors[x] is an SDL::Color' );
isa_ok(
$disp->format->palette->color_index(23),
'SDL::Color', 'Palette->color_index() is a SDL::Color'
);
}
if ($videodriver) {
$ENV{SDL_VIDEODRIVER} = $videodriver;
} else {
delete $ENV{SDL_VIDEODRIVER};
}
sleep(2);
|