/t/core_palette.t
Perl | 67 lines | 47 code | 19 blank | 1 comment | 4 complexity | c840f5fcaf5da3b1d9a794214bddea79 MD5 | raw file
1#!perl 2use strict; 3use warnings; 4use Test::More; 5 6use SDL; 7use SDL::Surface; 8use SDL::PixelFormat; 9use SDL::Video; 10 11use lib 't/lib'; 12use SDL::TestTool; 13 14my $videodriver = $ENV{SDL_VIDEODRIVER}; 15$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING}; 16 17if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) { 18 plan( skip_all => 'Failed to init video' ); 19} else { 20 plan( tests => 10 ); 21} 22 23use_ok('SDL::Palette'); 24 25can_ok( 'SDL::Palette', qw/ ncolors colors color_index / ); 26 27my $display = SDL::Video::set_video_mode( 640, 480, 32, SDL_SWSURFACE ); 28 29isa_ok( $display->format, 'SDL::PixelFormat', 'Are we a SDL::PixelFormat?' ); 30 31ok( !defined $display->format->palette, 32 'Palette is not defined as BitPerPixels is greater then 8' 33); 34 35my $disp = SDL::Video::set_video_mode( 640, 480, 8, SDL_SWSURFACE ); 36 37SKIP: 38{ 39 40 skip( 'Cannot open display: ' . SDL::get_error(), 4 ) unless ($disp); 41 isa_ok( $disp->format, 'SDL::PixelFormat', 'Are we a SDL::PixelFormat?' ); 42 43 isa_ok( 44 $disp->format->palette, 'SDL::Palette', 45 'Palette is SDL::Palette when BitPerPixels is 8 ' 46 ); 47 48 is( $disp->format->palette->ncolors, 256, '256 colors in palette' ); 49 50 my $colors = $disp->format->palette->colors(); 51 isa_ok( $colors, 'ARRAY', 'Palette->colors is an array' ); 52 53 isa_ok( $colors->[0], 'SDL::Color', 'Palette->colors[x] is an SDL::Color' ); 54 55 isa_ok( 56 $disp->format->palette->color_index(23), 57 'SDL::Color', 'Palette->color_index() is a SDL::Color' 58 ); 59} 60 61if ($videodriver) { 62 $ENV{SDL_VIDEODRIVER} = $videodriver; 63} else { 64 delete $ENV{SDL_VIDEODRIVER}; 65} 66 67sleep(2);