Fixed manifest, draw is not working though with Game::Rect
[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 27sub 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}
68210590 43isa_ok ($rect, 'SDL::Game::Rect','new went ok');
44
45foreach 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)
52is ($rect->left(15), 15, 'left is now 15');
53is ($rect->x, 15, 'x and left point to the same place');
54is ($rect->x(12), 12, 'x is now 12');
55is ($rect->left, 12, 'left is an alias to x');
56
1109e28a 57draw($app, $rect);
58
68210590 59is ($rect->top(132), 132, 'top is now 132');
60is ($rect->y, 132, 'y and top point to the same place');
61is ($rect->y(123), 123, 'y is now 123');
62is ($rect->top, 123, 'top is an alias to y');
63
1109e28a 64draw($app, $rect);
65
68210590 66is ($rect->w(54), 54, 'w is now 54');
67is ($rect->width, 54, 'w and width point to the same place');
68is ($rect->width(45), 45, 'w is now 45');
69is ($rect->w, 45, 'w is an alias to width');
70
1109e28a 71draw($app, $rect);
72
68210590 73is ($rect->h(76), 76, 'h is now 76');
74is ($rect->height, 76, 'h and height point to the same place');
75is ($rect->height(67), 67, 'h is now 67');
76is ($rect->h, 67, 'h is an alias to height');
77
78# get alone
79is ($rect->x(), 12, 'x is 12');
80is ($rect->left(), 12, 'left is 12');
81is ($rect->y(), 123, 'y is 123');
82is ($rect->top(), 123, 'top is 123');
83is ($rect->width(), 45, 'width is 45');
84is ($rect->w(), 45, 'w is 45');
85is ($rect->height(), 67, 'height is 67');
86is ($rect->h(), 67, 'h is 67');
87
88# other helpers
89is ($rect->bottom, 190, 'bottom should be relative to heigth and top');
90is ($rect->bottom(189), 189, 'changing bottom value');
91is ($rect->bottom, 189, 'checking bottom value again');
92is ($rect->top, 122, 'top value should have been updated after bottom change');
93is ($rect->height, 67, 'height should have stayed the same');
94
95is ($rect->centery, 155, 'checking vertical center');
96is ($rect->centery(154), 154, 'changing centery value');
97is ($rect->centery, 154, 'checking centery value again');
98is ($rect->top, 121, 'top value should have been updated after centery change');
99is ($rect->height, 67, 'height should have stayed the same');
100
101is ($rect->right, 57, 'right should be relative to width and left');
102is ($rect->right(56), 56, 'changing right value');
103is ($rect->right, 56, 'checking right value again');
104is ($rect->left, 11, 'left value should have been updated after bottom change');
105is ($rect->width, 45, 'width should have stayed the same');
106
107is ($rect->centerx, 33, 'checking horizontal center');
108is ($rect->centerx(32), 32, 'changing centerx value');
109is ($rect->centerx, 32, 'checking centerx value again');
110is ($rect->left, 10, 'left value should have been updated after bottom change');
111is ($rect->width, 45, 'width should have stayed the same');
112
113# checking two-valued accessors
114can_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
128is_deeply ( [$rect->center], [32, 154], 'checking center pair');
129$rect->center(undef, undef);
130is($rect->centerx, 32, 'center() does nothing when passed undef');
131is($rect->centery, 154, 'center() does nothing when passed undef');
132$rect->center(undef, 200);
133is($rect->centerx, 32, 'center() does nothing for X when passed undef');
134is($rect->centery, 200, 'center() works on one-parameter (y)');
135$rect->center(7, undef);
136is($rect->centerx, 7, 'center() works on one-parameter (x)');
137is($rect->centery, 200, 'center() does nothing for Y when passed undef');
138$rect->center(32, 154);
139is($rect->centerx, 32, 'center() can be used as an acessor for x');
140is($rect->centery, 154, 'center() can be used as an acessor for y');
141
142is_deeply ( [$rect->topleft], [121, 10], 'checking topleft pair');
143$rect->topleft(undef, undef);
144is($rect->top, 121, 'topleft() does nothing when passed undef');
145is($rect->left, 10, 'topleft() does nothing when passed undef');
146$rect->topleft(undef, 200);
147is($rect->top, 121, 'topleft() does nothing for Y when passed undef');
148is($rect->left, 200, 'topleft() works on one-parameter (x)');
149$rect->topleft(7, undef);
150is($rect->top, 7, 'topleft() works on one-parameter (y)');
151is($rect->left, 200, 'topleft() does nothing for X when passed undef');
152$rect->topleft(121, 10);
153is($rect->top, 121, 'topleft() can be used as an acessor for y');
154is($rect->left, 10, 'topleft() can be used as an acessor for x');
155
156is_deeply ( [$rect->midleft], [154, 10], 'checking midleft pair');
157$rect->midleft(undef, undef);
158is($rect->centery, 154, 'midleft() does nothing when passed undef');
159is($rect->left, 10, 'midleft() does nothing when passed undef');
160$rect->midleft(undef, 200);
161is($rect->centery, 154, 'midleft() does nothing for Y when passed undef');
162is($rect->left, 200, 'midleft() works on one-parameter (x)');
163$rect->midleft(7, undef);
164is($rect->centery, 7, 'midleft() works on one-parameter (y)');
165is($rect->left, 200, 'midleft() does nothing for X when passed undef');
166$rect->midleft(154, 10);
167is($rect->centery, 154, 'midleft() can be used as an acessor for y');
168is($rect->left, 10, 'midleft() can be used as an acessor for x');