Added core test template
[sdlgit/SDL_perl.git] / t / core_video.t
index 1269749..b7cecea 100644 (file)
@@ -9,7 +9,7 @@ use Data::Dumper;
 use Test::More;
 use SDL::Rect;
 
-plan ( tests => 13 );
+plan ( tests => 17 );
 
 use_ok( 'SDL::Video' ); 
 
@@ -25,13 +25,19 @@ my @done =
        update_rects
        flip
        set_colors
+       set_palette
        /;
+
 can_ok ('SDL::Video', @done); 
 
 #testing get_video_surface
 SDL::Init(SDL_INIT_VIDEO);                                                                          
                                                                                                     
-my $display = SDL::SetVideoMode(640,480,32, SDL_SWSURFACE );
+my $display = SDL::Video::set_video_mode(640,480,32, SDL_SWSURFACE );
+
+if(!$display){
+        plan skip_all => 'Couldn\'t set video mode: '. SDL::GetError();
+    }
 
 #diag('Testing SDL::Video');
 
@@ -62,17 +68,46 @@ SDL::Video::update_rects($display, SDL::Rect->new(0, 10, 20, 20));
 my $value = SDL::Video::flip($display);
 is( ($value == 0)  ||  ($value == -1), 1,  '[flip] returns 0 or -1'  );
 
-$value = SDL::Video::set_colors($display, 0);
-is(  $value , 0,  '[set_colors] returns 0'  );
+$value = SDL::Video::set_colors($display, 0, SDL::Color->new(0,0,0));
+is(  $value , 0,  '[set_colors] returns 0 trying to write to 32 bit display'  );
+
+$value = SDL::Video::set_palette($display, SDL_LOGPAL|0x02, 0);
+
+is(  $value , 0,  '[set_palette] returns 0 trying to write to 32 bit surface'  );
+
+
+
+my @b_w_colors;
+
+for(my $i=0;$i<256;$i++){
+       $b_w_colors[$i] = SDL::Color->new($i,$i,$i);
+      }
+my $hwdisplay = SDL::Video::set_video_mode(640,480,8, SDL_HWSURFACE );
+
+if(!$hwdisplay){
+        plan skip_all => 'Couldn\'t set video mode: '. SDL::GetError();
+    }
+
+$value = SDL::Video::set_colors($hwdisplay, 0);
+is(  $value , 0,  '[set_colors] returns 0 trying to send empty colors to 8 bit surface'  );
+
+$value = SDL::Video::set_palette($hwdisplay, SDL_LOGPAL|0x02, 0);
+
+is(  $value , 0,  '[set_palette] returns 0 trying to send empty colors to 8 bit surface'  );
+
+
+$value = SDL::Video::set_colors($hwdisplay, 0, @b_w_colors);
+is( $value , 1,  '[set_colors] returns '.$value  );
+
+$value = SDL::Video::set_palette($hwdisplay, SDL_LOGPAL|0x02, 0, @b_w_colors );
+
+is(  $value , 1,  '[set_palette] returns 1'  );
+
 
-$value = SDL::Video::set_colors($display, SDL::Color->new(255,0,0) );
-is( ($value == 0)  ||  ($value == 1) , 1,  '[set_colors] returns 1 or 0'  );
 
-#TODO: check actual color in palette with get_palette
 
 
 my @left = qw/
-       set_palette
        set_gamma
        get_gamma_ramp
        set_gmmma_ramp
@@ -115,4 +150,4 @@ TODO:
        diag  $why;
 
 
-pass 'Are we still alive? Checkign for segfaults';
+pass 'Are we still alive? Checking for segfaults';