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