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