XS for redtable done for set_gamma_ramp
[sdlgit/SDL_perl.git] / t / core_video.t
1 #!/usr/bin/perl -w
2 use strict;
3 use SDL;
4 use SDL::Color;
5 use SDL::Surface;
6 use SDL::Config;
7 use Devel::Peek;
8 use Data::Dumper;
9 use Test::More;
10 use SDL::Rect;
11
12 plan ( tests => 19 );
13
14 use_ok( 'SDL::Video' ); 
15
16 my @done =
17         qw/ 
18         get_video_surface
19         get_video_info
20         video_driver_name
21         list_modes
22         set_video_mode
23         video_mode_ok
24         update_rect
25         update_rects
26         flip
27         set_colors
28         set_palette
29         set_gamma
30         /;
31
32 can_ok ('SDL::Video', @done); 
33
34 #testing get_video_surface
35 SDL::Init(SDL_INIT_VIDEO);                                                                          
36                                                                                                     
37 my $display = SDL::Video::set_video_mode(640,480,32, SDL_SWSURFACE );
38
39 if(!$display){
40          plan skip_all => 'Couldn\'t set video mode: '. SDL::GetError();
41     }
42
43 #diag('Testing SDL::Video');
44
45 isa_ok(SDL::Video::get_video_surface(), 'SDL::Surface', '[get_video_surface] Checking if we get a surface ref back'); 
46
47 isa_ok(SDL::Video::get_video_info(), 'SDL::VideoInfo', '[get_video_info] Checking if we get videoinfo ref back');
48
49 my $driver_name = SDL::Video::video_driver_name();
50
51 pass '[video_driver_name] This is your driver name: '.$driver_name;
52
53
54
55 is( ref( SDL::Video::list_modes( $display->format , SDL_SWSURFACE )), 'ARRAY', '[list_modes] Returned an ARRAY! ');
56
57 cmp_ok(SDL::Video::video_mode_ok( 100, 100, 16, SDL_SWSURFACE), '>=', 0, "[video_mode_ok] Checking if an integer was return");
58
59 isa_ok(SDL::Video::set_video_mode( 100, 100 ,16, SDL_SWSURFACE), 'SDL::Surface', '[set_video_more] Checking if we get a surface ref back'); 
60
61
62 #TODO: Write to surface and check inf pixel in that area got updated.
63
64 SDL::Video::update_rect($display, 0, 0, 0, 0);
65
66 #TODO: Write to surface and check inf pixel in that area got updated.
67 SDL::Video::update_rects($display, SDL::Rect->new(0, 10, 20, 20));
68
69 my $value = SDL::Video::flip($display);
70 is( ($value == 0)  ||  ($value == -1), 1,  '[flip] returns 0 or -1'  );
71
72 $value = SDL::Video::set_colors($display, 0, SDL::Color->new(0,0,0));
73 is(  $value , 0,  '[set_colors] returns 0 trying to write to 32 bit display'  );
74
75 $value = SDL::Video::set_palette($display, SDL_LOGPAL|SDL_PHYSPAL, 0);
76
77 is(  $value , 0,  '[set_palette] returns 0 trying to write to 32 bit surface'  );
78
79 my @redtable = (0,0,0,0);
80
81 SDL::Video::set_gamma_ramp( \@redtable , [0,1,2,3], [2,3,4,5]); pass '[set_gamma_ramp] ran';
82
83 SDL::Video::set_gamma( 1.0, 1.0, 1.0 ); pass '[set_gamma] ran ';
84
85 my @b_w_colors;
86
87 for(my $i=0;$i<256;$i++){
88         $b_w_colors[$i] = SDL::Color->new($i,$i,$i);
89       }
90 my $hwdisplay = SDL::Video::set_video_mode(640,480,8, SDL_HWSURFACE );
91
92 if(!$hwdisplay){
93          plan skip_all => 'Couldn\'t set video mode: '. SDL::GetError();
94     }
95
96 $value = SDL::Video::set_colors($hwdisplay, 0);
97 is(  $value , 0,  '[set_colors] returns 0 trying to send empty colors to 8 bit surface'  );
98
99 $value = SDL::Video::set_palette($hwdisplay, SDL_LOGPAL|SDL_PHYSPAL, 0);
100
101 is(  $value , 0,  '[set_palette] returns 0 trying to send empty colors to 8 bit surface'  );
102
103
104 $value = SDL::Video::set_colors($hwdisplay, 0, @b_w_colors);
105 is( $value , 1,  '[set_colors] returns '.$value  );
106
107 $value = SDL::Video::set_palette($hwdisplay, SDL_LOGPAL|SDL_PHYSPAL, 0, @b_w_colors );
108
109 is(  $value , 1,  '[set_palette] returns 1'  );
110
111
112
113
114
115 my @left = qw/
116         get_gamma_ramp
117         set_gmmma_ramp
118         map_RGB
119         map_RGBA
120         get_RGB
121         get_RGBA
122         create_RGB_surface_from
123         lock_surface
124         unlock_surface
125         convert_surface
126         display_format
127         display_format_alpha
128         load_BMP
129         save_BMP
130         set_color_key
131         set_alpha
132         set_clip_rect
133         get_clip_rect
134         blit_surface
135         fill_rect
136         GL_load_library
137         GL_get_proc_address
138         GL_get_attribute
139         GL_set_attribute
140         GL_swap_buffers
141         GL_attr
142         lock_YUV_overlay
143         unlock_YUV_overlay
144         display_YUV_overlay
145         /;
146
147 my $why = '[Percentage Completion] '.int( 100 * $#done / ($#done + $#left) ) ."\% implementation. $#done / ".($#done+$#left); 
148
149 TODO:
150 {
151         local $TODO = $why;
152         pass "\nThe following functions:\n".join ",", @left; 
153 }
154         diag  $why;
155
156
157 pass 'Are we still alive? Checking for segfaults';