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