Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 141 lines (104 sloc) 3.536 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;
10 use lib 't/lib';
11 use SDL::TestTool;
12
13 my $videodriver = $ENV{SDL_VIDEODRIVER};
14 $ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
15
16 if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
4979eb1 @jtpalmer perltidy
jtpalmer authored
17 plan( skip_all => 'Failed to init video' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
18 }
19
20 my $app = SDL::Video::set_video_mode( 400, 200, 32, SDL_SWSURFACE );
21
22 my $app_x = SDLx::Surface::display();
23
4979eb1 @jtpalmer perltidy
jtpalmer authored
24 is_deeply(
25 $app_x->surface->get_pixels_ptr,
26 $app->get_pixels_ptr, '[display] works'
27 );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
28
29 my $surface = SDL::Surface->new( SDL_SWSURFACE, 400, 200, 32 );
30 my @surfs = (
4979eb1 @jtpalmer perltidy
jtpalmer authored
31 SDLx::Surface->new( surface => $surface ),
32 SDLx::Surface->new( width => 400, height => 200 ),
33 SDLx::Surface->new(
34 width => 400,
35 height => 200,
36 flags => SDL_SWSURFACE,
37 depth => 32
38 ),
39 SDLx::Surface->new(
40 width => 400,
41 height => 200,
42 flags => SDL_SWSURFACE,
43 depth => 32,
44 greenmask => 0xFF000000
45 ),
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
46 );
47
48 foreach my $a (@surfs) {
4979eb1 @jtpalmer perltidy
jtpalmer authored
49 isa_ok( $a, 'SDLx::Surface' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
50
4979eb1 @jtpalmer perltidy
jtpalmer authored
51 isa_ok( $a->surface(), 'SDL::Surface' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
52
4979eb1 @jtpalmer perltidy
jtpalmer authored
53 my $color = $a->[0][0];
54 is( $color, 0, 'Right color returned' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
55
4979eb1 @jtpalmer perltidy
jtpalmer authored
56 $a->[0][0] = 0x00FF00FF;
57 is( $a->[0][0], 0x00FF00FF, 'Right color returned' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
58
4979eb1 @jtpalmer perltidy
jtpalmer authored
59 is( @{$a}, 200, 'Correct Y value' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
60
4979eb1 @jtpalmer perltidy
jtpalmer authored
61 is( @{ $a->[0] }, 400, 'Correct X value' );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
62
63 }
64
65 #my $source = SDLx::Surface->new( width=> 400, height=>200, flags=> SDL_SWSURFACE, depth=>32 ),
66
67 is( $surfs[0]->[1][2], 0, 'Checking source pixel is 0' );
68 is( $surfs[1]->[1][2], 0, 'Checking dest pixel is 0' );
69
70 $surfs[0]->[1][2] = 0x00FF00FF;
71
72 is( $surfs[0]->[1][2], 0x00FF00FF, 'Checking that source pixel got written' );
73
74 $surfs[0]->blit( $surfs[1] );
75
76 #SDL::Video::blit_surface( $surfs[0]->surface, SDL::Rect->new(0,0,400,200), $surfs[1]->surface, SDL::Rect->new(0,0,400,200));
77
78 isnt( $surfs[1]->[1][2], 0, 'Pixel blitted from one surface to another' );
79
80 $surfs[1]->blit_by( $surfs[0], undef, [ 1, 0, 0, 0 ] );
81
82 isnt( $surfs[1]->[2][2], 0, 'Pixel by_blitted to another surface with offset' );
83
91586c2 redid perltidy
Tobias Leich authored
84 push @surfs,
4979eb1 @jtpalmer perltidy
jtpalmer authored
85 SDLx::Surface->new(
86 w => 1,
87 h => 1,
88 color => 1,
89 );
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
90
91 is( $surfs[-1]->[0][0], 1, 'Fill color worked' );
92
93 $surfs[1]->flip();
94
95 pass 'Fliped the surface';
96
97 $surfs[0]->update();
98 pass 'update all surface';
99 $surfs[0]->update( [ 0, 10, 30, 40 ] );
100 pass 'Single rect update';
4979eb1 @jtpalmer perltidy
jtpalmer authored
101 $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
102 pass 'SDL::Rect array update';
103
104 $surfs[0]->draw_rect( [ 0, 0, 10, 20 ], 0xFF00FFFF );
105 pass 'draw_rect works';
106
107 $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], 0xff00ffff );
108 $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], 0xff00ffff, 1 );
109 $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], [ 255, 255, 0, 255 ] );
110 $surfs[1]->draw_line( [ 0, 10 ], [ 20, 10 ], [ 255, 255, 0, 255 ], 1 );
111 pass 'draw_line works';
112
a44ce7d @jtpalmer merge
jtpalmer authored
113
114 TODO:
115 {
116 local $TODO = 'Draw_Circle is not done yet';
117 my $cir_color = 0xCCCCCCFF;
118 $surfs[0]->draw_circle( [ 100, 10 ], 20, $cir_color ); #no fill
119 is( $surfs[0]->[120][10], $cir_color );
120 }
121
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
122 my $surf_dup = SDLx::Surface::duplicate( $surfs[1] );
123
124 is( $surf_dup->w, $surfs[1]->w, 'Duplicate surf has same width' );
125 is( $surf_dup->h, $surfs[1]->h, 'Duplicate surf has same flags' );
126 is( $surf_dup->flags, $surfs[1]->flags, 'Duplicate surf has same flags' );
4979eb1 @jtpalmer perltidy
jtpalmer authored
127 is( $surf_dup->format->BitsPerPixel,
128 $surfs[1]->format->BitsPerPixel,
129 'Duplicate surf has same bpp'
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
130 );
131
132 if ($videodriver) {
4979eb1 @jtpalmer perltidy
jtpalmer authored
133 $ENV{SDL_VIDEODRIVER} = $videodriver;
134 } else {
135 delete $ENV{SDL_VIDEODRIVER};
d90ee1b @Blaizer Misc stuff for SDLx::Surface. Pod and test too ^_^
Blaizer authored
136 }
137
138 pass 'Final SegFault test';
139
140 done_testing;
Something went wrong with that request. Please try again.