Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 180 lines (137 sloc) 4.709 kb
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
1 use strict;
2 use warnings;
3 use Test::More;
4 use SDL;
5 use SDL::Surface;
6 use SDL::Rect;
7 use SDLx::Surface;
8 use SDL::PixelFormat;
9 use SDL::Video;
7212404 @kthakore Fixed problem with get_pixels
kthakore authored
10 use Data::Dumper;
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
11 use lib 't/lib';
12 use SDL::TestTool;
13
14 my $videodriver = $ENV{SDL_VIDEODRIVER};
15 $ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
16
17 if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
4979eb1 @jtpalmer perltidy
jtpalmer authored
18 plan( skip_all => 'Failed to init video' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
19 }
20
21 my $app = SDL::Video::set_video_mode( 400, 200, 32, SDL_SWSURFACE );
22
23 my $app_x = SDLx::Surface::display();
24
4979eb1 @jtpalmer perltidy
jtpalmer authored
25 is_deeply(
26 $app_x->surface->get_pixels_ptr,
27 $app->get_pixels_ptr, '[display] works'
28 );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
29
30 my $surface = SDL::Surface->new( SDL_SWSURFACE, 400, 200, 32 );
31 my @surfs = (
4979eb1 @jtpalmer perltidy
jtpalmer authored
32 SDLx::Surface->new( surface => $surface ),
33 SDLx::Surface->new( width => 400, height => 200 ),
34 SDLx::Surface->new(
35 width => 400,
36 height => 200,
37 flags => SDL_SWSURFACE,
38 depth => 32
39 ),
40 SDLx::Surface->new(
41 width => 400,
42 height => 200,
43 flags => SDL_SWSURFACE,
44 depth => 32,
45 greenmask => 0xFF000000
46 ),
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
47 );
48
49 foreach my $a (@surfs) {
4979eb1 @jtpalmer perltidy
jtpalmer authored
50 isa_ok( $a, 'SDLx::Surface' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
51
4979eb1 @jtpalmer perltidy
jtpalmer authored
52 isa_ok( $a->surface(), 'SDL::Surface' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
53
4979eb1 @jtpalmer perltidy
jtpalmer authored
54 my $color = $a->[0][0];
55 is( $color, 0, 'Right color returned' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
56
4979eb1 @jtpalmer perltidy
jtpalmer authored
57 $a->[0][0] = 0x00FF00FF;
58 is( $a->[0][0], 0x00FF00FF, 'Right color returned' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
59
4979eb1 @jtpalmer perltidy
jtpalmer authored
60 is( @{$a}, 200, 'Correct Y value' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
61
4979eb1 @jtpalmer perltidy
jtpalmer authored
62 is( @{ $a->[0] }, 400, 'Correct X value' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
63
64 }
65
66 #my $source = SDLx::Surface->new( width=> 400, height=>200, flags=> SDL_SWSURFACE, depth=>32 ),
67
68 is( $surfs[0]->[1][2], 0, 'Checking source pixel is 0' );
69 is( $surfs[1]->[1][2], 0, 'Checking dest pixel is 0' );
70
71 $surfs[0]->[1][2] = 0x00FF00FF;
72
73 is( $surfs[0]->[1][2], 0x00FF00FF, 'Checking that source pixel got written' );
74
75 $surfs[0]->blit( $surfs[1] );
76
77 #SDL::Video::blit_surface( $surfs[0]->surface, SDL::Rect->new(0,0,400,200), $surfs[1]->surface, SDL::Rect->new(0,0,400,200));
78
79 isnt( $surfs[1]->[1][2], 0, 'Pixel blitted from one surface to another' );
80
81 $surfs[1]->blit_by( $surfs[0], undef, [ 1, 0, 0, 0 ] );
82
83 isnt( $surfs[1]->[2][2], 0, 'Pixel by_blitted to another surface with offset' );
84
91586c2 redid perltidy
Tobias Leich authored
85 push @surfs,
4979eb1 @jtpalmer perltidy
jtpalmer authored
86 SDLx::Surface->new(
87 w => 1,
88 h => 1,
89 color => 1,
90 );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
91
92 is( $surfs[-1]->[0][0], 1, 'Fill color worked' );
93
94 $surfs[1]->flip();
95
96 pass 'Fliped the surface';
97
98 $surfs[0]->update();
99 pass 'update all surface';
100 $surfs[0]->update( [ 0, 10, 30, 40 ] );
101 pass 'Single rect update';
4979eb1 @jtpalmer perltidy
jtpalmer authored
102 $surfs[0]->update( [ SDL::Rect->new( 0, 1, 2, 3 ), SDL::Rect->new( 2, 4, 5, 6 ) ] );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
103 pass 'SDL::Rect array update';
104
564c0a9 @jtpalmer SDLx::Surface::draw_rect tests
jtpalmer authored
105 my @colors = (
106 [ 255, 255, 255, 255 ],
107 [ 255, 255, 0, 255 ],
108 [ 255, 0, 255, 255 ],
109 [ 0, 255, 255, 255 ],
110 [ 255, 0, 0, 255 ],
111 [ 0, 255, 0, 255 ],
112 [ 0, 0, 255, 255 ],
113 [ 0, 0, 0, 255 ],
114 [ 32, 64, 128, 255 ],
115 [ 128, 32, 64, 255 ],
116 [ 64, 128, 32, 255 ],
117 );
118
119 foreach my $c (@colors) {
120 my $color = ( $c->[0] << 24 ) + ( $c->[1] << 16 ) + ( $c->[2] << 8 ) + $c->[3];
7212404 @kthakore Fixed problem with get_pixels
kthakore authored
121 $surfs[0]->draw_rect( [ 0, 0, 10, 20 ], $c );
564c0a9 @jtpalmer SDLx::Surface::draw_rect tests
jtpalmer authored
122
7212404 @kthakore Fixed problem with get_pixels
kthakore authored
123 my $num = sprintf('0x%08x', $color);
564c0a9 @jtpalmer SDLx::Surface::draw_rect tests
jtpalmer authored
124
7212404 @kthakore Fixed problem with get_pixels
kthakore authored
125 my $rgba = sprintf('0x%08x', $surfs[0]->[0][0] );
564c0a9 @jtpalmer SDLx::Surface::draw_rect tests
jtpalmer authored
126
7212404 @kthakore Fixed problem with get_pixels
kthakore authored
127 is( $rgba, $num, "draw_rect uses correct color ($rgba) for $num" );
564c0a9 @jtpalmer SDLx::Surface::draw_rect tests
jtpalmer authored
128 }
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
129
92b0bbc @kthakore Added draw_gfx_text to SDLx:;Surface
kthakore authored
130 SKIP:
131 {
36a0ca5 @kthakore Tidied the code
kthakore authored
132 skip( 'SDL_gfx_primitives needed', 2 ) unless SDL::Config->has('SDL_gfx_primitives');
133 $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], 0xff00ff );
134 $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], 0xff00ffff );
135 $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], 0xff00ffff, 1 );
136 $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], [ 255, 255, 0, 255 ] );
137 $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], [ 255, 255, 0, 255 ], 1 );
138 pass 'draw_line works';
139
140 $surfs[1]->draw_gfx_text( [ 0, 0 ], 0xffffffff, "fooo" );
141 $surfs[1]->draw_gfx_text( [ 10, 10 ], [ 20, 20, 20, 20 ], "fooo" );
142 my $f = '';
143 open( my $FH, '<', 'test/data/5x7.fnt' );
144 binmode($FH);
145 read( $FH, $f, 4096 );
146 close($FH);
147 my $font = { data => $f, cw => 5, ch => 7 };
148 $surfs[1]->draw_gfx_text( [ 0, 0 ], 0xffffffff, "fooo", $font );
149 pass 'draw_gfx_text works';
c4cf5b1 @kthakore Added gfx guard for sdlx_surface.t
kthakore authored
150 my $cir_color = [ 255, 0, 0, 255 ];
151 $surfs[0]->draw_circle( [ 100, 10 ], 20, $cir_color ); #no fill
152 $surfs[0]->draw_circle_filled( [ 100, 10 ], 20, $cir_color ); #fill
92b0bbc @kthakore Added draw_gfx_text to SDLx:;Surface
kthakore authored
153
c4cf5b1 @kthakore Added gfx guard for sdlx_surface.t
kthakore authored
154 isnt( $surfs[0]->[100][10], 0 );
155 pass 'draw_circle works';
156 pass 'draw_circle_filled works';
a44ce7d @jtpalmer merge
jtpalmer authored
157
c4cf5b1 @kthakore Added gfx guard for sdlx_surface.t
kthakore authored
158 }
b4dbf65 @kthakore Fixed test for surface. Added tests for circle
kthakore authored
159
a44ce7d @jtpalmer merge
jtpalmer authored
160
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
161 my $surf_dup = SDLx::Surface::duplicate( $surfs[1] );
162
163 is( $surf_dup->w, $surfs[1]->w, 'Duplicate surf has same width' );
164 is( $surf_dup->h, $surfs[1]->h, 'Duplicate surf has same flags' );
165 is( $surf_dup->flags, $surfs[1]->flags, 'Duplicate surf has same flags' );
4979eb1 @jtpalmer perltidy
jtpalmer authored
166 is( $surf_dup->format->BitsPerPixel,
167 $surfs[1]->format->BitsPerPixel,
168 'Duplicate surf has same bpp'
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
169 );
170
171 if ($videodriver) {
4979eb1 @jtpalmer perltidy
jtpalmer authored
172 $ENV{SDL_VIDEODRIVER} = $videodriver;
173 } else {
174 delete $ENV{SDL_VIDEODRIVER};
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
175 }
176
177 pass 'Final SegFault test';
178
179 done_testing;
Something went wrong with that request. Please try again.