- Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathsdlx_rect.t
116 lines (102 loc) · 2.01 KB
/
sdlx_rect.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use strict;
use warnings;
use SDL;
use SDL::Rect;
use SDLx::Rect;
use Test::More;
use lib 't/lib';
use SDL::TestTool;
my$videodriver = $ENV{SDL_VIDEODRIVER};
$ENV{SDL_VIDEODRIVER} = 'dummy'unless$ENV{SDL_RELEASE_TESTING};
if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
plan( skip_all=>'Failed to init video' );
}
can_ok(
'SDLx::Rect', qw/
width
w
height
h
left
x
top
y
bottom
right
centerx
centery
size
topleft
midleft
bottomleft
center
topright
midright
bottomright
midtop
midbottom
new
copy
duplicate
move
move_ip
inflate
inflate_ip
clamp
clamp_ip
clip
clip_ip
union
union_ip
unionall
unionall_ip
fit
fit_ip
normalize
contains
collidepoint
colliderect
collidelist
collidelistall
collidehash
collidehashall
/
);
my ($x, $y, $w, $h) = (0, 1, 2, 3);
my$rect = SDLx::Rect->new($x, $y, $w, $h);
ok($rect, 'new');
isa_ok($rect, 'SDLx::Rect');
is($rect->width, $w, 'get width');
is($rect->w, $w, 'get w');
is($rect->height, $h, 'get height');
is($rect->h, $h, 'get h');
is($rect->left, $x, 'get left');
is($rect->x, $x, 'get x');
is($rect->top, $y, 'get top');
is($rect->y, $y, 'get y');
is($rect->bottom, $y + $h, 'get bottom');
is($rect->right, $x + $w, 'get right');
my$copy = $rect->copy();
is($copy->w, $w, 'copy (w)');
is($copy->h, $h, 'copy (h)');
is($copy->x, $x, 'copy (x)');
is($copy->y, $y, 'copy (y)');
my ($dx, $dy) = (4, 5);
my$moved = $rect->move($dx, $dy);
is($moved->w, $w, 'move (w)');
is($moved->h, $h, 'move (h)');
is($moved->x, $x + $dx, 'move (x)');
is($moved->y, $y + $dy, 'move (y)');
my ($dw, $dh) = (6, 7);
my$inflated = $rect->inflate($dw, $dh);
is($inflated->w, $w + $dw, 'inflate (w)');
is($inflated->h, $h + $dh, 'inflate (h)');
is($inflated->x, $x - $dw / 2, 'inflate (x)');
is($inflated->y, $y - $dw / 2, 'inflate (y)');
if ($videodriver) {
$ENV{SDL_VIDEODRIVER} = $videodriver;
} else {
delete$ENV{SDL_VIDEODRIVER};
}
pass 'Final SegFault test';
done_testing;