Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
1600 lines (1452 loc) · 59.9 KB

File metadata and controls

1600 lines (1452 loc) · 59.9 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* Original code: automated SDL rect test written by Edgar Simo "bobbens"
* New/updated tests: aschiffler at ferzkopp dot net
*/
#include <stdio.h>
#include <SDL/SDL.h>
#include "../../include/SDL_test.h"
/* SDL_IntersectRectAndLine */
static const TestCaseReference test1 =
May 18, 2013
May 18, 2013
14
(TestCaseReference){ "rect_testIntersectRectAndLine", "Tests SDL_IntersectRectAndLine clipping cases", TEST_ENABLED, 0, 0 };
15
16
static const TestCaseReference test2 =
May 18, 2013
May 18, 2013
17
(TestCaseReference){ "rect_testIntersectRectAndLineInside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED, 0, 0 };
18
19
static const TestCaseReference test3 =
May 18, 2013
May 18, 2013
20
(TestCaseReference){ "rect_testIntersectRectAndLineOutside", "Tests SDL_IntersectRectAndLine with line fully outside of rect", TEST_ENABLED, 0, 0 };
21
22
static const TestCaseReference test4 =
May 18, 2013
May 18, 2013
23
(TestCaseReference){ "rect_testIntersectRectAndLineEmpty", "Tests SDL_IntersectRectAndLine with empty rectangle ", TEST_ENABLED, 0, 0 };
24
25
static const TestCaseReference test5 =
May 18, 2013
May 18, 2013
26
(TestCaseReference){ "rect_testIntersectRectAndLineParam", "Negative tests against SDL_IntersectRectAndLine with invalid parameters", TEST_ENABLED, 0, 0 };
27
28
29
/* SDL_IntersectRect */
static const TestCaseReference test6 =
May 18, 2013
May 18, 2013
30
(TestCaseReference){ "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED, 0, 0 };
31
32
static const TestCaseReference test7 =
May 18, 2013
May 18, 2013
33
(TestCaseReference){ "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED, 0, 0 };
34
35
static const TestCaseReference test8 =
May 18, 2013
May 18, 2013
36
(TestCaseReference){ "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED, 0, 0 };
37
38
static const TestCaseReference test9 =
May 18, 2013
May 18, 2013
39
(TestCaseReference){ "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED, 0, 0 };
40
41
static const TestCaseReference test10 =
May 18, 2013
May 18, 2013
42
(TestCaseReference){ "rect_testIntersectRectEmpty", "Tests SDL_IntersectRect with empty rectangles", TEST_ENABLED, 0, 0 };
43
44
static const TestCaseReference test11 =
May 18, 2013
May 18, 2013
45
(TestCaseReference){ "rect_testIntersectRectParam", "Negative tests against SDL_IntersectRect with invalid parameters", TEST_ENABLED, 0, 0 };
46
47
48
/* SDL_HasIntersection */
static const TestCaseReference test12 =
May 18, 2013
May 18, 2013
49
(TestCaseReference){ "rect_testHasIntersectionInside", "Tests SDL_HasIntersection with B fully contained in A", TEST_ENABLED, 0, 0 };
50
51
static const TestCaseReference test13 =
May 18, 2013
May 18, 2013
52
(TestCaseReference){ "rect_testHasIntersectionOutside", "Tests SDL_HasIntersection with B fully outside of A", TEST_ENABLED, 0, 0 };
53
54
static const TestCaseReference test14 =
May 18, 2013
May 18, 2013
55
(TestCaseReference){ "rect_testHasIntersectionPartial", "Tests SDL_HasIntersection with B partially intersecting A", TEST_ENABLED, 0, 0 };
56
57
static const TestCaseReference test15 =
May 18, 2013
May 18, 2013
58
(TestCaseReference){ "rect_testHasIntersectionPoint", "Tests SDL_HasIntersection with 1x1 sized rectangles", TEST_ENABLED, 0, 0 };
59
60
static const TestCaseReference test16 =
May 18, 2013
May 18, 2013
61
(TestCaseReference){ "rect_testHasIntersectionEmpty", "Tests SDL_HasIntersection with empty rectangles", TEST_ENABLED, 0, 0 };
62
63
static const TestCaseReference test17 =
May 18, 2013
May 18, 2013
64
(TestCaseReference){ "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED, 0, 0 };
65
66
67
/* SDL_EnclosePoints */
static const TestCaseReference test18 =
May 18, 2013
May 18, 2013
68
(TestCaseReference){ "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED, 0, 0 };
69
70
static const TestCaseReference test19 =
May 18, 2013
May 18, 2013
71
(TestCaseReference){ "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED, 0, 0 };
72
73
static const TestCaseReference test20 =
May 18, 2013
May 18, 2013
74
(TestCaseReference){ "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED, 0, 0 };
75
76
static const TestCaseReference test21 =
May 18, 2013
May 18, 2013
77
(TestCaseReference){ "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED, 0, 0 };
78
79
80
/* SDL_UnionRect */
static const TestCaseReference test22 =
May 18, 2013
May 18, 2013
81
(TestCaseReference){ "rect_testUnionRectInside", "Tests SDL_UnionRect where rect B is inside rect A", TEST_ENABLED, 0, 0 };
82
83
static const TestCaseReference test23 =
May 18, 2013
May 18, 2013
84
(TestCaseReference){ "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED, 0, 0 };
85
86
static const TestCaseReference test24 =
May 18, 2013
May 18, 2013
87
(TestCaseReference){ "rect_testUnionRectEmpty", "Tests SDL_UnionRect where rect A or rect B are empty", TEST_ENABLED, 0, 0 };
88
89
static const TestCaseReference test25 =
May 18, 2013
May 18, 2013
90
(TestCaseReference){ "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED, 0, 0 };
91
92
93
/* SDL_RectEmpty */
static const TestCaseReference test26 =
May 18, 2013
May 18, 2013
94
(TestCaseReference){ "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED, 0, 0 };
95
96
static const TestCaseReference test27 =
May 18, 2013
May 18, 2013
97
(TestCaseReference){ "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED, 0, 0 };
98
99
100
101
/* SDL_RectEquals */
static const TestCaseReference test28 =
May 18, 2013
May 18, 2013
102
(TestCaseReference){ "rect_testRectEquals", "Tests SDL_RectEquals with various inputs", TEST_ENABLED, 0, 0 };
103
104
static const TestCaseReference test29 =
May 18, 2013
May 18, 2013
105
(TestCaseReference){ "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED, 0, 0 };
106
107
108
109
110
111
112
113
114
/*!
* \brief Test suite for functions that handle simple rectangles including overlaps and merges.
*
* \sa
* http://wiki.libsdl.org/moin.cgi/CategoryRect
*/
extern const TestCaseReference *testSuite[] = {
May 18, 2013
May 18, 2013
115
116
117
&test1, &test2, &test3, &test4, &test5, &test6, &test7, &test8, &test9, &test10, &test11, &test12, &test13, &test14,
&test15, &test16, &test17, &test18, &test19, &test20, &test21, &test22, &test23, &test24, &test25, &test26, &test27,
&test28, &test29, NULL
118
119
120
};
TestCaseReference **QueryTestSuite() {
May 18, 2013
May 18, 2013
121
return (TestCaseReference **)testSuite;
122
123
124
125
126
127
128
129
130
131
132
}
/*!
* \brief Private helper to check SDL_IntersectRectAndLine results
*/
void _validateIntersectRectAndLineResults(
SDL_bool intersection, SDL_bool expectedIntersection,
SDL_Rect *rect, SDL_Rect * refRect,
int x1, int y1, int x2, int y2,
int x1Ref, int y1Ref, int x2Ref, int y2Ref)
{
May 18, 2013
May 18, 2013
133
AssertTrue(intersection == expectedIntersection,
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
"Incorrect intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)\n",
(expectedIntersection == SDL_TRUE) ? "true" : "false",
(intersection == SDL_TRUE) ? "true" : "false",
refRect->x, refRect->y, refRect->w, refRect->h,
x1Ref, y1Ref, x2Ref, y2Ref);
AssertTrue(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
"Source rectangle was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rect->x, rect->y, rect->w, rect->h,
refRect->x, refRect->y, refRect->w, refRect->h);
AssertTrue(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
"Line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
x1, y1, x2, y2,
x1Ref, y1Ref, x2Ref, y2Ref);
}
/*!
* \brief Tests SDL_IntersectRectAndLine() clipping cases
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
int rect_testIntersectRectAndLine (void *arg)
{
SDL_Rect refRect = { 0, 0, 32, 32 };
SDL_Rect rect;
int x1, y1;
int x2, y2;
SDL_bool intersected;
int xLeft = -RandomIntegerInRange(1, refRect.w);
int xRight = refRect.w + RandomIntegerInRange(1, refRect.w);
int yTop = -RandomIntegerInRange(1, refRect.h);
int yBottom = refRect.h + RandomIntegerInRange(1, refRect.h);
x1 = xLeft;
y1 = 15;
x2 = xRight;
y2 = 15;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 15, 31, 15);
x1 = 15;
y1 = yTop;
x2 = 15;
y2 = yBottom;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 15, 0, 15, 31);
x1 = -refRect.w;
y1 = -refRect.h;
x2 = 2*refRect.w;
y2 = 2*refRect.h;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 0, 31, 31);
x1 = 2*refRect.w;
y1 = 2*refRect.h;
x2 = -refRect.w;
y2 = -refRect.h;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 31, 0, 0);
x1 = -1;
y1 = 32;
x2 = 32;
y2 = -1;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 31, 31, 0);
x1 = 32;
y1 = -1;
x2 = -1;
y2 = 32;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31);
}
/*!
* \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
int rect_testIntersectRectAndLineInside (void *arg)
{
SDL_Rect refRect = { 0, 0, 32, 32 };
SDL_Rect rect;
int x1, y1;
int x2, y2;
SDL_bool intersected;
int xmin = refRect.x;
int xmax = refRect.x + refRect.w - 1;
int ymin = refRect.y;
int ymax = refRect.y + refRect.h - 1;
int x1Ref = RandomIntegerInRange(xmin + 1, xmax - 1);
int y1Ref = RandomIntegerInRange(ymin + 1, ymax - 1);
int x2Ref = RandomIntegerInRange(xmin + 1, xmax - 1);
int y2Ref = RandomIntegerInRange(ymin + 1, ymax - 1);
x1 = x1Ref;
y1 = y1Ref;
x2 = x2Ref;
y2 = y2Ref;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
x1 = x1Ref;
y1 = y1Ref;
x2 = xmax;
y2 = ymax;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, xmax, ymax);
x1 = xmin;
y1 = ymin;
x2 = x2Ref;
y2 = y2Ref;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, x2Ref, y2Ref);
x1 = xmin;
y1 = ymin;
x2 = xmax;
y2 = ymax;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, xmax, ymax);
x1 = xmin;
y1 = ymax;
x2 = xmax;
y2 = ymin;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymax, xmax, ymin);
}
/*!
* \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
int rect_testIntersectRectAndLineOutside (void *arg)
{
SDL_Rect refRect = { 0, 0, 32, 32 };
SDL_Rect rect;
int x1, y1;
int x2, y2;
SDL_bool intersected;
int xLeft = -RandomIntegerInRange(1, refRect.w);
int xRight = refRect.w + RandomIntegerInRange(1, refRect.w);
int yTop = -RandomIntegerInRange(1, refRect.h);
int yBottom = refRect.h + RandomIntegerInRange(1, refRect.h);
x1 = xLeft;
y1 = 0;
x2 = xLeft;
y2 = 31;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xLeft, 0, xLeft, 31);
x1 = xRight;
y1 = 0;
x2 = xRight;
y2 = 31;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xRight, 0, xRight, 31);
x1 = 0;
y1 = yTop;
x2 = 31;
y2 = yTop;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yTop, 31, yTop);
x1 = 0;
y1 = yBottom;
x2 = 31;
y2 = yBottom;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yBottom, 31, yBottom);
}
/*!
* \brief Tests SDL_IntersectRectAndLine() with empty rectangle
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
int rect_testIntersectRectAndLineEmpty (void *arg)
{
SDL_Rect refRect;
SDL_Rect rect;
int x1, y1, x1Ref, y1Ref;
int x2, y2, x2Ref, y2Ref;
SDL_bool intersected;
May 18, 2013
May 18, 2013
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
refRect.x = RandomIntegerInRange(1, 1024);
refRect.y = RandomIntegerInRange(1, 1024);
refRect.w = 0;
refRect.h = 0;
x1Ref = refRect.x;
y1Ref = refRect.y;
x2Ref = RandomIntegerInRange(1, 1024);
y2Ref = RandomIntegerInRange(1, 1024);
x1 = x1Ref;
y1 = y1Ref;
x2 = x2Ref;
y2 = y2Ref;
rect = refRect;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
_validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
}
/*!
* \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
int rect_testIntersectRectAndLineParam (void *arg)
{
SDL_Rect rect = { 0, 0, 32, 32 };
int x1 = rect.w / 2;
int y1 = rect.h / 2;
int x2 = x1;
int y2 = 2 * rect.h;
SDL_bool intersected;
May 18, 2013
May 18, 2013
380
381
382
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
AssertTrue(intersected == SDL_TRUE, "Test variables not intersected as expected");
May 18, 2013
May 18, 2013
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, &x1, &y1, &x2, &y2);
AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 1st parameter is NULL");
intersected = SDL_IntersectRectAndLine(&rect, (int *)NULL, &y1, &x2, &y2);
AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 2nd parameter is NULL");
intersected = SDL_IntersectRectAndLine(&rect, &x1, (int *)NULL, &x2, &y2);
AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 3rd parameter is NULL");
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, (int *)NULL, &y2);
AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 4th parameter is NULL");
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, (int *)NULL);
AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 5th parameter is NULL");
intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when all parameters are NULL");
}
/*!
* \brief Private helper to check SDL_HasIntersection results
*/
void _validateHasIntersectionResults(
May 18, 2013
May 18, 2013
402
SDL_bool intersection, SDL_bool expectedIntersection,
403
404
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
{
May 18, 2013
May 18, 2013
405
AssertTrue(intersection == expectedIntersection,
406
407
408
"Incorrect intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)\n",
(expectedIntersection == SDL_TRUE) ? "true" : "false",
(intersection == SDL_TRUE) ? "true" : "false",
May 18, 2013
May 18, 2013
409
rectA->x, rectA->y, rectA->w, rectA->h,
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
rectB->x, rectB->y, rectB->w, rectB->h);
AssertTrue(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
"Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA->x, rectA->y, rectA->w, rectA->h,
refRectA->x, refRectA->y, refRectA->w, refRectA->h);
AssertTrue(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
"Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectB->x, rectB->y, rectB->w, rectB->h,
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/*!
* \brief Private helper to check SDL_IntersectRect results
*/
void _validateIntersectRectResults(
May 18, 2013
May 18, 2013
425
426
SDL_bool intersection, SDL_bool expectedIntersection,
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
427
428
429
430
431
432
SDL_Rect *result, SDL_Rect *expectedResult)
{
_validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB);
if (result && expectedResult) {
AssertTrue(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
"Intersection of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was incorrectly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
May 18, 2013
May 18, 2013
433
rectA->x, rectA->y, rectA->w, rectA->h,
434
435
436
437
438
439
440
441
442
443
rectB->x, rectB->y, rectB->w, rectB->h,
result->x, result->y, result->w, result->h,
expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
}
}
/*!
* \brief Private helper to check SDL_UnionRect results
*/
void _validateUnionRectResults(
May 18, 2013
May 18, 2013
444
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
445
446
447
448
449
450
451
452
453
454
455
456
SDL_Rect *result, SDL_Rect *expectedResult)
{
AssertTrue(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
"Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA->x, rectA->y, rectA->w, rectA->h,
refRectA->x, refRectA->y, refRectA->w, refRectA->h);
AssertTrue(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
"Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectB->x, rectB->y, rectB->w, rectB->h,
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
AssertTrue(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
"Union of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was incorrectly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
May 18, 2013
May 18, 2013
457
rectA->x, rectA->y, rectA->w, rectA->h,
458
459
460
461
462
463
464
465
466
rectB->x, rectB->y, rectB->w, rectB->h,
result->x, result->y, result->w, result->h,
expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
}
/*!
* \brief Private helper to check SDL_RectEmpty results
*/
void _validateRectEmptyResults(
May 18, 2013
May 18, 2013
467
SDL_bool empty, SDL_bool expectedEmpty,
468
469
SDL_Rect *rect, SDL_Rect *refRect)
{
May 18, 2013
May 18, 2013
470
AssertTrue(empty == expectedEmpty,
471
472
473
474
475
476
477
478
479
480
481
482
483
484
"Incorrect empty result: expected %s, got %s testing (%d,%d,%d,%d)\n",
(expectedEmpty == SDL_TRUE) ? "true" : "false",
(empty == SDL_TRUE) ? "true" : "false",
rect->x, rect->y, rect->w, rect->h);
AssertTrue(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
"Source rectangle was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rect->x, rect->y, rect->w, rect->h,
refRect->x, refRect->y, refRect->w, refRect->h);
}
/*!
* \brief Private helper to check SDL_RectEquals results
*/
void _validateRectEqualsResults(
May 18, 2013
May 18, 2013
485
SDL_bool equals, SDL_bool expectedEquals,
486
487
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
{
May 18, 2013
May 18, 2013
488
AssertTrue(equals == expectedEquals,
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
"Incorrect equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d) \n",
(expectedEquals == SDL_TRUE) ? "true" : "false",
(equals == SDL_TRUE) ? "true" : "false",
rectA->x, rectA->y, rectA->w, rectA->h,
rectB->x, rectB->y, rectB->w, rectB->h);
AssertTrue(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
"Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA->x, rectA->y, rectA->w, rectA->h,
refRectA->x, refRectA->y, refRectA->w, refRectA->h);
AssertTrue(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
"Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectB->x, rectB->y, rectB->w, rectB->h,
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/*!
* \brief Tests SDL_IntersectRect() with B fully inside A
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectInside (void *arg)
{
SDL_Rect refRectA = { 0, 0, 32, 32 };
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;
// rectB fully contained in rectA
refRectB.x = 0;
refRectB.y = 0;
refRectB.w = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.h = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB);
}
/*!
* \brief Tests SDL_IntersectRect() with B fully outside A
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectOutside (void *arg)
{
SDL_Rect refRectA = { 0, 0, 32, 32 };
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;
// rectB fully outside of rectA
refRectB.x = refRectA.x + refRectA.w + RandomIntegerInRange(1, 10);
refRectB.y = refRectA.y + refRectA.h + RandomIntegerInRange(1, 10);
refRectB.w = refRectA.w;
refRectB.h = refRectA.h;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
May 18, 2013
May 18, 2013
553
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
}
/*!
* \brief Tests SDL_IntersectRect() with B partially intersecting A
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectPartial (void *arg)
{
SDL_Rect refRectA = { 0, 0, 32, 32 };
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_Rect expectedResult;
SDL_bool intersection;
// rectB partially contained in rectA
refRectB.x = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.y = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
refRectB.w = refRectA.w;
refRectB.h = refRectA.h;
rectA = refRectA;
rectB = refRectB;
expectedResult.x = refRectB.x;
expectedResult.y = refRectB.y;
expectedResult.w = refRectA.w - refRectB.x;
May 18, 2013
May 18, 2013
582
expectedResult.h = refRectA.h - refRectB.y;
583
584
585
586
587
588
589
590
591
592
593
594
595
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
// rectB right edge
refRectB.x = rectA.w - 1;
refRectB.y = rectA.y;
refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
expectedResult.x = refRectB.x;
expectedResult.y = refRectB.y;
expectedResult.w = 1;
May 18, 2013
May 18, 2013
596
expectedResult.h = refRectB.h;
597
598
599
600
601
602
603
604
605
606
607
608
609
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
// rectB left edge
refRectB.x = 1 - rectA.w;
refRectB.y = rectA.y;
refRectB.w = refRectA.w;
refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
expectedResult.x = 0;
expectedResult.y = refRectB.y;
expectedResult.w = 1;
May 18, 2013
May 18, 2013
610
expectedResult.h = refRectB.h;
611
612
613
614
615
616
617
618
619
620
621
622
623
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
// rectB bottom edge
refRectB.x = rectA.x;
refRectB.y = rectA.h - 1;
refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
expectedResult.x = refRectB.x;
expectedResult.y = refRectB.y;
expectedResult.w = refRectB.w;
May 18, 2013
May 18, 2013
624
expectedResult.h = 1;
625
626
627
628
629
630
631
632
633
634
635
636
637
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
// rectB top edge
refRectB.x = rectA.x;
refRectB.y = 1 - rectA.h;
refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = rectA.h;
rectA = refRectA;
rectB = refRectB;
expectedResult.x = refRectB.x;
expectedResult.y = 0;
expectedResult.w = refRectB.w;
May 18, 2013
May 18, 2013
638
expectedResult.h = 1;
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
}
/*!
* \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectPoint (void *arg)
{
SDL_Rect refRectA = { 0, 0, 1, 1 };
SDL_Rect refRectB = { 0, 0, 1, 1 };
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;
int offsetX, offsetY;
// intersecting pixels
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectB.x = refRectA.x;
refRectB.y = refRectA.y;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA);
// non-intersecting pixels cases
for (offsetX = -1; offsetX <= 1; offsetX++) {
for (offsetY = -1; offsetY <= 1; offsetY++) {
if (offsetX != 0 || offsetY != 0) {
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectB.x = refRectA.x;
May 18, 2013
May 18, 2013
676
refRectB.y = refRectA.y;
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
refRectB.x += offsetX;
refRectB.y += offsetY;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
}
}
}
}
/*!
* \brief Tests SDL_IntersectRect() with empty rectangles
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectEmpty (void *arg)
{
SDL_Rect refRectA;
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;
// Rect A empty
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectA.w = RandomIntegerInRange(1, 100);
refRectA.h = RandomIntegerInRange(1, 100);
refRectB = refRectA;
refRectA.w = 0;
refRectA.h = 0;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
// Rect B empty
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectA.w = RandomIntegerInRange(1, 100);
refRectA.h = RandomIntegerInRange(1, 100);
refRectB = refRectA;
refRectB.w = 0;
refRectB.h = 0;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
// Rect A and B empty
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectA.w = RandomIntegerInRange(1, 100);
refRectA.h = RandomIntegerInRange(1, 100);
refRectB = refRectA;
refRectA.w = 0;
refRectA.h = 0;
refRectB.w = 0;
refRectB.h = 0;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
}
/*!
* \brief Negative tests against SDL_IntersectRect() with invalid parameters
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
*/
int rect_testIntersectRectParam(void *arg)
{
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;
// invalid parameter combinations
intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, &result);
May 18, 2013
May 18, 2013
760
AssertTrue(intersection == SDL_FALSE, "Function did not return false when 1st parameter was NULL");
761
intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
May 18, 2013
May 18, 2013
762
AssertTrue(intersection == SDL_FALSE, "Function did not return false when 2st parameter was NULL");
763
intersection = SDL_IntersectRect(&rectA, &rectB, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
764
AssertTrue(intersection == SDL_FALSE, "Function did not return false when 3st parameter was NULL");
765
intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
May 18, 2013
May 18, 2013
766
AssertTrue(intersection == SDL_FALSE, "Function did not return false when 1st and 2nd parameters were NULL");
767
intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
768
AssertTrue(intersection == SDL_FALSE, "Function did not return false when 1st and 3rd parameters were NULL ");
769
intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
770
AssertTrue(intersection == SDL_FALSE, "Function did not return false when all parameters were NULL");
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
}
/*!
* \brief Tests SDL_HasIntersection() with B fully inside A
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
*/
int rect_testHasIntersectionInside (void *arg)
{
SDL_Rect refRectA = { 0, 0, 32, 32 };
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_bool intersection;
// rectB fully contained in rectA
refRectB.x = 0;
refRectB.y = 0;
refRectB.w = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.h = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
}
/*!
* \brief Tests SDL_HasIntersection() with B fully outside A
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
*/
int rect_testHasIntersectionOutside (void *arg)
{
SDL_Rect refRectA = { 0, 0, 32, 32 };
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_bool intersection;
// rectB fully outside of rectA
refRectB.x = refRectA.x + refRectA.w + RandomIntegerInRange(1, 10);
refRectB.y = refRectA.y + refRectA.h + RandomIntegerInRange(1, 10);
refRectB.w = refRectA.w;
refRectB.h = refRectA.h;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
}
/*!
* \brief Tests SDL_HasIntersection() with B partially intersecting A
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
*/
int rect_testHasIntersectionPartial (void *arg)
{
SDL_Rect refRectA = { 0, 0, 32, 32 };
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_bool intersection;
// rectB partially contained in rectA
refRectB.x = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.y = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
refRectB.w = refRectA.w;
refRectB.h = refRectA.h;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// rectB right edge
refRectB.x = rectA.w - 1;
refRectB.y = rectA.y;
refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// rectB left edge
refRectB.x = 1 - rectA.w;
refRectB.y = rectA.y;
refRectB.w = refRectA.w;
refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// rectB bottom edge
refRectB.x = rectA.x;
refRectB.y = rectA.h - 1;
refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// rectB top edge
refRectB.x = rectA.x;
refRectB.y = 1 - rectA.h;
refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = rectA.h;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
}
/*!
* \brief Tests SDL_HasIntersection() with 1x1 pixel sized rectangles
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
*/
int rect_testHasIntersectionPoint (void *arg)
{
SDL_Rect refRectA = { 0, 0, 1, 1 };
SDL_Rect refRectB = { 0, 0, 1, 1 };
SDL_Rect rectA;
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;
int offsetX, offsetY;
// intersecting pixels
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectB.x = refRectA.x;
refRectB.y = refRectA.y;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// non-intersecting pixels cases
for (offsetX = -1; offsetX <= 1; offsetX++) {
for (offsetY = -1; offsetY <= 1; offsetY++) {
if (offsetX != 0 || offsetY != 0) {
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectB.x = refRectA.x;
May 18, 2013
May 18, 2013
921
refRectB.y = refRectA.y;
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
refRectB.x += offsetX;
refRectB.y += offsetY;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
}
}
}
}
/*!
* \brief Tests SDL_HasIntersection() with empty rectangles
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
*/
int rect_testHasIntersectionEmpty (void *arg)
{
SDL_Rect refRectA;
SDL_Rect refRectB;
SDL_Rect rectA;
SDL_Rect rectB;
SDL_bool intersection;
// Rect A empty
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectA.w = RandomIntegerInRange(1, 100);
refRectA.h = RandomIntegerInRange(1, 100);
refRectB = refRectA;
refRectA.w = 0;
refRectA.h = 0;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
// Rect B empty
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectA.w = RandomIntegerInRange(1, 100);
refRectA.h = RandomIntegerInRange(1, 100);
refRectB = refRectA;
refRectB.w = 0;
refRectB.h = 0;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
// Rect A and B empty
refRectA.x = RandomIntegerInRange(1, 100);
refRectA.y = RandomIntegerInRange(1, 100);
refRectA.w = RandomIntegerInRange(1, 100);
refRectA.h = RandomIntegerInRange(1, 100);
refRectB = refRectA;
refRectA.w = 0;
refRectA.h = 0;
refRectB.w = 0;
refRectB.h = 0;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
}
/*!
* \brief Negative tests against SDL_HasIntersection() with invalid parameters
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
*/
int rect_testHasIntersectionParam(void *arg)
{
SDL_Rect rectA;
SDL_Rect rectB;
SDL_bool intersection;