Fixed manifest, draw is not working though with Game::Rect
[sdlgit/SDL_perl.git] / t / sdlgamerect.t
1 use Test::More tests => 87;
2 use strict;
3 use SDL;
4 use SDL::App;
5 use SDL::Color;
6
7 use_ok( 'SDL::Game::Rect' ); 
8   
9 can_ok ('SDL::Game::Rect', qw/
10         new
11         x 
12         y 
13         width 
14         height
15         w
16         h
17         top
18         left
19         centerx
20         centery
21          /);
22
23 my $app = SDL::App->new(-title => "Test", -width => 640, -height => 480, -init => SDL_INIT_VIDEO);
24
25 my $rect = SDL::Game::Rect->new();
26
27 sub draw
28 {
29         
30         
31         my $blue = SDL::Color->new(
32                 -r => 0x00,
33                 -g => 0x00,
34                 -b => 0xff,
35         );
36
37         
38         $_[0]->fill($_[1],$blue);
39         $_[0]->update($_[1]);
40         $_[0]->sync;
41         sleep(1);
42 }
43 isa_ok ($rect, 'SDL::Game::Rect','new went ok');
44
45 foreach my $attr (qw(x y top    left  width   height 
46                      w h bottom right centerx centery)
47                  ) {
48     is ($rect->$attr, 0, "$attr is 0");
49 }
50
51 # set and get at the same time (and testing method aliases)
52 is ($rect->left(15), 15, 'left is now 15');
53 is ($rect->x, 15, 'x and left point to the same place');
54 is ($rect->x(12), 12, 'x is now 12');
55 is ($rect->left, 12, 'left is an alias to x');
56
57 draw($app, $rect);
58
59 is ($rect->top(132), 132, 'top is now 132');
60 is ($rect->y, 132, 'y and top point to the same place');
61 is ($rect->y(123), 123, 'y is now 123');
62 is ($rect->top, 123, 'top is an alias to y');
63
64 draw($app, $rect);
65
66 is ($rect->w(54), 54, 'w is now 54');
67 is ($rect->width, 54, 'w and width point to the same place');
68 is ($rect->width(45), 45, 'w is now 45');
69 is ($rect->w, 45, 'w is an alias to width');
70
71 draw($app, $rect);
72
73 is ($rect->h(76), 76, 'h is now 76');
74 is ($rect->height, 76, 'h and height point to the same place');
75 is ($rect->height(67), 67, 'h is now 67');
76 is ($rect->h, 67, 'h is an alias to height');
77
78 # get alone
79 is ($rect->x(), 12, 'x is 12');
80 is ($rect->left(), 12, 'left is 12');
81 is ($rect->y(), 123, 'y is 123');
82 is ($rect->top(), 123, 'top is 123');
83 is ($rect->width(), 45, 'width is 45');
84 is ($rect->w(), 45, 'w is 45');
85 is ($rect->height(), 67, 'height is 67');
86 is ($rect->h(), 67, 'h is 67');
87
88 # other helpers
89 is ($rect->bottom, 190, 'bottom should be relative to heigth and top');
90 is ($rect->bottom(189), 189, 'changing bottom value');
91 is ($rect->bottom, 189, 'checking bottom value again');
92 is ($rect->top, 122, 'top value should have been updated after bottom change');
93 is ($rect->height, 67, 'height should have stayed the same');
94
95 is ($rect->centery, 155, 'checking vertical center');
96 is ($rect->centery(154), 154, 'changing centery value');
97 is ($rect->centery, 154, 'checking centery value again');
98 is ($rect->top, 121, 'top value should have been updated after centery change');
99 is ($rect->height, 67, 'height should have stayed the same');
100
101 is ($rect->right, 57, 'right should be relative to width and left');
102 is ($rect->right(56), 56, 'changing right value');
103 is ($rect->right, 56, 'checking right value again');
104 is ($rect->left, 11, 'left value should have been updated after bottom change');
105 is ($rect->width, 45, 'width should have stayed the same');
106
107 is ($rect->centerx, 33, 'checking horizontal center');
108 is ($rect->centerx(32), 32, 'changing centerx value');
109 is ($rect->centerx, 32, 'checking centerx value again');
110 is ($rect->left, 10, 'left value should have been updated after bottom change');
111 is ($rect->width, 45, 'width should have stayed the same');
112
113 # checking two-valued accessors
114 can_ok ('SDL::Game::Rect', qw/
115     size
116         center
117         topleft
118         midleft
119         bottomleft
120         topright
121         midright
122         bottomright
123         midtop
124         midbottom
125          /);
126
127
128 is_deeply ( [$rect->center], [32, 154], 'checking center pair');
129 $rect->center(undef, undef);
130 is($rect->centerx, 32, 'center() does nothing when passed undef');
131 is($rect->centery, 154, 'center() does nothing when passed undef');
132 $rect->center(undef, 200);
133 is($rect->centerx, 32, 'center() does nothing for X when passed undef');
134 is($rect->centery, 200, 'center() works on one-parameter (y)');
135 $rect->center(7, undef);
136 is($rect->centerx, 7, 'center() works on one-parameter (x)');
137 is($rect->centery, 200, 'center() does nothing for Y when passed undef');
138 $rect->center(32, 154);
139 is($rect->centerx, 32, 'center() can be used as an acessor for x');
140 is($rect->centery, 154, 'center() can be used as an acessor for y');
141
142 is_deeply ( [$rect->topleft], [121, 10], 'checking topleft pair');
143 $rect->topleft(undef, undef);
144 is($rect->top, 121, 'topleft() does nothing when passed undef');
145 is($rect->left, 10, 'topleft() does nothing when passed undef');
146 $rect->topleft(undef, 200);
147 is($rect->top, 121, 'topleft() does nothing for Y when passed undef');
148 is($rect->left, 200, 'topleft() works on one-parameter (x)');
149 $rect->topleft(7, undef);
150 is($rect->top, 7, 'topleft() works on one-parameter (y)');
151 is($rect->left, 200, 'topleft() does nothing for X when passed undef');
152 $rect->topleft(121, 10);
153 is($rect->top, 121, 'topleft() can be used as an acessor for y');
154 is($rect->left, 10, 'topleft() can be used as an acessor for x');
155
156 is_deeply ( [$rect->midleft], [154, 10], 'checking midleft pair');
157 $rect->midleft(undef, undef);
158 is($rect->centery, 154, 'midleft() does nothing when passed undef');
159 is($rect->left, 10, 'midleft() does nothing when passed undef');
160 $rect->midleft(undef, 200);
161 is($rect->centery, 154, 'midleft() does nothing for Y when passed undef');
162 is($rect->left, 200, 'midleft() works on one-parameter (x)');
163 $rect->midleft(7, undef);
164 is($rect->centery, 7, 'midleft() works on one-parameter (y)');
165 is($rect->left, 200, 'midleft() does nothing for X when passed undef');
166 $rect->midleft(154, 10);
167 is($rect->centery, 154, 'midleft() can be used as an acessor for y');
168 is($rect->left, 10, 'midleft() can be used as an acessor for x');