wow .. I don't even know how this fixes sound
[sdlgit/SDL_perl.git] / t / sdlgamerect.t
CommitLineData
68210590 1use Test::More tests => 87;
2use strict;
1109e28a 3use SDL;
4use SDL::App;
5use SDL::Color;
68210590 6
7use_ok( 'SDL::Game::Rect' );
8
9can_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 23my $app = SDL::App->new(-title => "Test", -width => 640, -height => 480, -init => SDL_INIT_VIDEO);
24
68210590 25my $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 37isa_ok ($rect, 'SDL::Game::Rect','new went ok');
38
39foreach 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)
46is ($rect->left(15), 15, 'left is now 15');
47is ($rect->x, 15, 'x and left point to the same place');
48is ($rect->x(12), 12, 'x is now 12');
49is ($rect->left, 12, 'left is an alias to x');
50
51is ($rect->top(132), 132, 'top is now 132');
52is ($rect->y, 132, 'y and top point to the same place');
53is ($rect->y(123), 123, 'y is now 123');
54is ($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 62is ($rect->w(54), 54, 'w is now 54');
63is ($rect->width, 54, 'w and width point to the same place');
64is ($rect->width(45), 45, 'w is now 45');
65is ($rect->w, 45, 'w is an alias to width');
66
67is ($rect->h(76), 76, 'h is now 76');
68is ($rect->height, 76, 'h and height point to the same place');
69is ($rect->height(67), 67, 'h is now 67');
70is ($rect->h, 67, 'h is an alias to height');
71
72# get alone
73is ($rect->x(), 12, 'x is 12');
74is ($rect->left(), 12, 'left is 12');
75is ($rect->y(), 123, 'y is 123');
76is ($rect->top(), 123, 'top is 123');
77is ($rect->width(), 45, 'width is 45');
78is ($rect->w(), 45, 'w is 45');
79is ($rect->height(), 67, 'height is 67');
80is ($rect->h(), 67, 'h is 67');
81
82# other helpers
83is ($rect->bottom, 190, 'bottom should be relative to heigth and top');
84is ($rect->bottom(189), 189, 'changing bottom value');
85is ($rect->bottom, 189, 'checking bottom value again');
86is ($rect->top, 122, 'top value should have been updated after bottom change');
87is ($rect->height, 67, 'height should have stayed the same');
88
89is ($rect->centery, 155, 'checking vertical center');
90is ($rect->centery(154), 154, 'changing centery value');
91is ($rect->centery, 154, 'checking centery value again');
92is ($rect->top, 121, 'top value should have been updated after centery change');
93is ($rect->height, 67, 'height should have stayed the same');
94
95is ($rect->right, 57, 'right should be relative to width and left');
96is ($rect->right(56), 56, 'changing right value');
97is ($rect->right, 56, 'checking right value again');
98is ($rect->left, 11, 'left value should have been updated after bottom change');
99is ($rect->width, 45, 'width should have stayed the same');
100
101is ($rect->centerx, 33, 'checking horizontal center');
102is ($rect->centerx(32), 32, 'changing centerx value');
103is ($rect->centerx, 32, 'checking centerx value again');
104is ($rect->left, 10, 'left value should have been updated after bottom change');
105is ($rect->width, 45, 'width should have stayed the same');
106
107# checking two-valued accessors
108can_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
122is_deeply ( [$rect->center], [32, 154], 'checking center pair');
123$rect->center(undef, undef);
124is($rect->centerx, 32, 'center() does nothing when passed undef');
125is($rect->centery, 154, 'center() does nothing when passed undef');
126$rect->center(undef, 200);
127is($rect->centerx, 32, 'center() does nothing for X when passed undef');
128is($rect->centery, 200, 'center() works on one-parameter (y)');
129$rect->center(7, undef);
130is($rect->centerx, 7, 'center() works on one-parameter (x)');
131is($rect->centery, 200, 'center() does nothing for Y when passed undef');
132$rect->center(32, 154);
133is($rect->centerx, 32, 'center() can be used as an acessor for x');
134is($rect->centery, 154, 'center() can be used as an acessor for y');
135
136is_deeply ( [$rect->topleft], [121, 10], 'checking topleft pair');
137$rect->topleft(undef, undef);
138is($rect->top, 121, 'topleft() does nothing when passed undef');
139is($rect->left, 10, 'topleft() does nothing when passed undef');
140$rect->topleft(undef, 200);
141is($rect->top, 121, 'topleft() does nothing for Y when passed undef');
142is($rect->left, 200, 'topleft() works on one-parameter (x)');
143$rect->topleft(7, undef);
144is($rect->top, 7, 'topleft() works on one-parameter (y)');
145is($rect->left, 200, 'topleft() does nothing for X when passed undef');
146$rect->topleft(121, 10);
147is($rect->top, 121, 'topleft() can be used as an acessor for y');
148is($rect->left, 10, 'topleft() can be used as an acessor for x');
149
150is_deeply ( [$rect->midleft], [154, 10], 'checking midleft pair');
151$rect->midleft(undef, undef);
152is($rect->centery, 154, 'midleft() does nothing when passed undef');
153is($rect->left, 10, 'midleft() does nothing when passed undef');
154$rect->midleft(undef, 200);
155is($rect->centery, 154, 'midleft() does nothing for Y when passed undef');
156is($rect->left, 200, 'midleft() works on one-parameter (x)');
157$rect->midleft(7, undef);
158is($rect->centery, 7, 'midleft() works on one-parameter (y)');
159is($rect->left, 200, 'midleft() does nothing for X when passed undef');
160$rect->midleft(154, 10);
161is($rect->centery, 154, 'midleft() can be used as an acessor for y');
162is($rect->left, 10, 'midleft() can be used as an acessor for x');