Skip to content

Latest commit

 

History

History
1696 lines (1516 loc) · 65.5 KB

testautomation_rect.c

File metadata and controls

1696 lines (1516 loc) · 65.5 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* Original code: automated SDL rect test written by Edgar Simo "bobbens"
* New/updated tests: aschiffler at ferzkopp dot net
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/* ================= Test Case Implementation ================== */
/* Helper functions */
Aug 21, 2013
Aug 21, 2013
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
* \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)
{
SDLTest_AssertCheck(intersection == expectedIntersection,
"Check for correct intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)",
(expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
(intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
refRect->x, refRect->y, refRect->w, refRect->h,
x1Ref, y1Ref, x2Ref, y2Ref);
SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
"Check that source rectangle was not 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);
SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
"Check if line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
x1, y1, x2, y2,
x1Ref, y1Ref, x2Ref, y2Ref);
}
/* Test case functions */
Aug 21, 2013
Aug 21, 2013
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
* \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 = -SDLTest_RandomIntegerInRange(1, refRect.w);
int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
int yBottom = refRect.h + SDLTest_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);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
113
/* !
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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
* \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 = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
int y1Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
int x2Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
int y2Ref = SDLTest_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);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
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
* \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 = -SDLTest_RandomIntegerInRange(1, refRect.w);
int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
int yBottom = refRect.h + SDLTest_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);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
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
* \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;
refRect.x = SDLTest_RandomIntegerInRange(1, 1024);
refRect.y = SDLTest_RandomIntegerInRange(1, 1024);
refRect.w = 0;
refRect.h = 0;
x1Ref = refRect.x;
y1Ref = refRect.y;
x2Ref = SDLTest_RandomIntegerInRange(1, 1024);
y2Ref = SDLTest_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);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
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
* \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;
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
SDLTest_AssertCheck(intersected == SDL_TRUE, "Check that intersection result was SDL_TRUE");
intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, &x1, &y1, &x2, &y2);
SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
intersected = SDL_IntersectRectAndLine(&rect, (int *)NULL, &y1, &x2, &y2);
SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
intersected = SDL_IntersectRectAndLine(&rect, &x1, (int *)NULL, &x2, &y2);
SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 3rd parameter is NULL");
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, (int *)NULL, &y2);
SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 4th parameter is NULL");
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, (int *)NULL);
SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 5th parameter is NULL");
intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
305
/* !
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
* \brief Private helper to check SDL_HasIntersection results
*/
void _validateHasIntersectionResults(
SDL_bool intersection, SDL_bool expectedIntersection,
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
{
SDLTest_AssertCheck(intersection == expectedIntersection,
"Check intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)",
(expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
(intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
rectA->x, rectA->y, rectA->w, rectA->h,
rectB->x, rectB->y, rectB->w, rectB->h);
SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
"Check that source rectangle A was not 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);
SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
"Check that source rectangle B was not 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);
}
Aug 21, 2013
Aug 21, 2013
328
/* !
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
* \brief Private helper to check SDL_IntersectRect results
*/
void _validateIntersectRectResults(
SDL_bool intersection, SDL_bool expectedIntersection,
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
SDL_Rect *result, SDL_Rect *expectedResult)
{
_validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB);
if (result && expectedResult) {
SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
"Check that intersection of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was correctly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA->x, rectA->y, rectA->w, rectA->h,
rectB->x, rectB->y, rectB->w, rectB->h,
result->x, result->y, result->w, result->h,
expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
}
}
Aug 21, 2013
Aug 21, 2013
347
/* !
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
* \brief Private helper to check SDL_UnionRect results
*/
void _validateUnionRectResults(
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
SDL_Rect *result, SDL_Rect *expectedResult)
{
SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
"Check that source rectangle A was not 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);
SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
"Check that source rectangle B was not 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);
SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
"Check that union of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was correctly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
rectA->x, rectA->y, rectA->w, rectA->h,
rectB->x, rectB->y, rectB->w, rectB->h,
result->x, result->y, result->w, result->h,
expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
}
Aug 21, 2013
Aug 21, 2013
370
/* !
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
* \brief Private helper to check SDL_RectEmpty results
*/
void _validateRectEmptyResults(
SDL_bool empty, SDL_bool expectedEmpty,
SDL_Rect *rect, SDL_Rect *refRect)
{
SDLTest_AssertCheck(empty == expectedEmpty,
"Check for correct empty result: expected %s, got %s testing (%d,%d,%d,%d)",
(expectedEmpty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
(empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
rect->x, rect->y, rect->w, rect->h);
SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
"Check that source rectangle was not 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);
}
Aug 21, 2013
Aug 21, 2013
388
/* !
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
* \brief Private helper to check SDL_RectEquals results
*/
void _validateRectEqualsResults(
SDL_bool equals, SDL_bool expectedEquals,
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
{
SDLTest_AssertCheck(equals == expectedEquals,
"Check for correct equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d)",
(expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
(equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
rectA->x, rectA->y, rectA->w, rectA->h,
rectB->x, rectB->y, rectB->w, rectB->h);
SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
"Check that source rectangle A was not 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);
SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
"Check that source rectangle B was not 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);
}
Aug 21, 2013
Aug 21, 2013
411
/* !
412
413
414
415
416
417
418
419
420
421
422
423
424
425
* \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;
Aug 20, 2013
Aug 20, 2013
426
/* rectB fully contained in rectA */
427
428
429
430
431
432
433
434
435
436
437
438
refRectB.x = 0;
refRectB.y = 0;
refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.h = SDLTest_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);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
439
/* !
440
441
442
443
444
445
446
447
448
449
450
451
452
453
* \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;
Aug 20, 2013
Aug 20, 2013
454
/* rectB fully outside of rectA */
455
456
457
458
459
460
461
462
463
464
465
466
refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
refRectB.w = refRectA.w;
refRectB.h = refRectA.h;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
467
/* !
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
* \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;
Aug 20, 2013
Aug 20, 2013
483
/* rectB partially contained in rectA */
484
485
486
487
488
489
490
491
492
493
494
495
496
refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.y = SDLTest_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;
expectedResult.h = refRectA.h - refRectB.y;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
Aug 20, 2013
Aug 20, 2013
497
/* rectB right edge */
498
499
500
501
502
503
504
505
506
507
508
509
510
refRectB.x = rectA.w - 1;
refRectB.y = rectA.y;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
expectedResult.x = refRectB.x;
expectedResult.y = refRectB.y;
expectedResult.w = 1;
expectedResult.h = refRectB.h;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
Aug 20, 2013
Aug 20, 2013
511
/* rectB left edge */
512
513
514
515
516
517
518
519
520
521
522
523
524
refRectB.x = 1 - rectA.w;
refRectB.y = rectA.y;
refRectB.w = refRectA.w;
refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
expectedResult.x = 0;
expectedResult.y = refRectB.y;
expectedResult.w = 1;
expectedResult.h = refRectB.h;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
Aug 20, 2013
Aug 20, 2013
525
/* rectB bottom edge */
526
527
528
529
530
531
532
533
534
535
536
537
538
refRectB.x = rectA.x;
refRectB.y = rectA.h - 1;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
expectedResult.x = refRectB.x;
expectedResult.y = refRectB.y;
expectedResult.w = refRectB.w;
expectedResult.h = 1;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
Aug 20, 2013
Aug 20, 2013
539
/* rectB top edge */
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
refRectB.x = rectA.x;
refRectB.y = 1 - rectA.h;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = rectA.h;
rectA = refRectA;
rectB = refRectB;
expectedResult.x = refRectB.x;
expectedResult.y = 0;
expectedResult.w = refRectB.w;
expectedResult.h = 1;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
556
/* !
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
* \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;
Aug 20, 2013
Aug 20, 2013
572
/* intersecting pixels */
573
574
575
576
577
578
579
580
581
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_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);
Aug 20, 2013
Aug 20, 2013
582
/* non-intersecting pixels cases */
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
for (offsetX = -1; offsetX <= 1; offsetX++) {
for (offsetY = -1; offsetY <= 1; offsetY++) {
if (offsetX != 0 || offsetY != 0) {
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectB.x = refRectA.x;
refRectB.y = refRectA.y;
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);
}
}
}
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
603
/* !
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
* \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;
SDL_bool empty;
Aug 20, 2013
Aug 20, 2013
619
/* Rect A empty */
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
result.w = SDLTest_RandomIntegerInRange(1, 100);
result.h = SDLTest_RandomIntegerInRange(1, 100);
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
refRectA.h = SDLTest_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);
empty = (SDL_bool)SDL_RectEmpty(&result);
SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
Aug 20, 2013
Aug 20, 2013
636
/* Rect B empty */
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
result.w = SDLTest_RandomIntegerInRange(1, 100);
result.h = SDLTest_RandomIntegerInRange(1, 100);
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
refRectA.h = SDLTest_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);
empty = (SDL_bool)SDL_RectEmpty(&result);
SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
Aug 20, 2013
Aug 20, 2013
653
/* Rect A and B empty */
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
result.w = SDLTest_RandomIntegerInRange(1, 100);
result.h = SDLTest_RandomIntegerInRange(1, 100);
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
refRectA.h = SDLTest_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);
empty = (SDL_bool)SDL_RectEmpty(&result);
SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
675
/* !
676
677
678
679
680
681
682
683
684
685
686
687
* \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;
Aug 20, 2013
Aug 20, 2013
688
/* invalid parameter combinations */
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, &result);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
intersection = SDL_IntersectRect(&rectA, &rectB, (SDL_Rect *)NULL);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 3st parameter is NULL");
intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameters are NULL");
intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 3rd parameters are NULL ");
intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
705
/* !
706
707
708
709
710
711
712
713
714
715
716
717
718
* \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;
Aug 20, 2013
Aug 20, 2013
719
/* rectB fully contained in rectA */
720
721
722
723
724
725
726
727
728
729
730
731
refRectB.x = 0;
refRectB.y = 0;
refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.h = SDLTest_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);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
732
/* !
733
734
735
736
737
738
739
740
741
742
743
744
745
* \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;
Aug 20, 2013
Aug 20, 2013
746
/* rectB fully outside of rectA */
747
748
749
750
751
752
753
754
755
756
757
758
refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
refRectB.y = refRectA.y + refRectA.h + SDLTest_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);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
759
/* !
760
761
762
763
764
765
766
767
768
769
770
771
772
* \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;
Aug 20, 2013
Aug 20, 2013
773
/* rectB partially contained in rectA */
774
775
776
777
778
779
780
781
782
refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.y = SDLTest_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);
Aug 20, 2013
Aug 20, 2013
783
/* rectB right edge */
784
785
786
787
788
789
790
791
792
refRectB.x = rectA.w - 1;
refRectB.y = rectA.y;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
Aug 20, 2013
Aug 20, 2013
793
/* rectB left edge */
794
795
796
797
798
799
800
801
802
refRectB.x = 1 - rectA.w;
refRectB.y = rectA.y;
refRectB.w = refRectA.w;
refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
Aug 20, 2013
Aug 20, 2013
803
/* rectB bottom edge */
804
805
806
807
808
809
810
811
812
refRectB.x = rectA.x;
refRectB.y = rectA.h - 1;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
Aug 20, 2013
Aug 20, 2013
813
/* rectB top edge */
814
815
816
817
818
819
820
821
822
823
824
825
refRectB.x = rectA.x;
refRectB.y = 1 - rectA.h;
refRectB.w = SDLTest_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);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
826
/* !
827
828
829
830
831
832
833
834
835
836
837
838
839
840
* \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_bool intersection;
int offsetX, offsetY;
Aug 20, 2013
Aug 20, 2013
841
/* intersecting pixels */
842
843
844
845
846
847
848
849
850
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_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);
Aug 20, 2013
Aug 20, 2013
851
/* non-intersecting pixels cases */
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
for (offsetX = -1; offsetX <= 1; offsetX++) {
for (offsetY = -1; offsetY <= 1; offsetY++) {
if (offsetX != 0 || offsetY != 0) {
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectB.x = refRectA.x;
refRectB.y = refRectA.y;
refRectB.x += offsetX;
refRectB.y += offsetY;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
}
}
}
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
872
/* !
873
874
875
876
877
878
879
880
881
882
883
884
885
* \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;
Aug 20, 2013
Aug 20, 2013
886
/* Rect A empty */
887
888
889
890
891
892
893
894
895
896
897
898
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
refRectA.h = SDLTest_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);
Aug 20, 2013
Aug 20, 2013
899
/* Rect B empty */
900
901
902
903
904
905
906
907
908
909
910
911
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
refRectA.h = SDLTest_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);
Aug 20, 2013
Aug 20, 2013
912
/* Rect A and B empty */
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
refRectA.h = SDLTest_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);
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
930
/* !
931
932
933
934
935
936
937
938
939
940
941
* \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;
Aug 20, 2013
Aug 20, 2013
942
/* invalid parameter combinations */
943
944
945
946
947
948
949
950
951
952
intersection = SDL_HasIntersection((SDL_Rect *)NULL, &rectB);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
intersection = SDL_HasIntersection(&rectA, (SDL_Rect *)NULL);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
intersection = SDL_HasIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
return TEST_COMPLETED;
}
Aug 21, 2013
Aug 21, 2013
953
/* !
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
* \brief Test SDL_EnclosePoints() without clipping
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
*/
int rect_testEnclosePoints(void *arg)
{
const int numPoints = 16;
SDL_Point refPoints[16];
SDL_Point points[16];
SDL_Rect result;
SDL_bool anyEnclosed;
SDL_bool anyEnclosedNoResult;
SDL_bool expectedEnclosed = SDL_TRUE;
int newx, newy;
int minx = 0, maxx = 0, miny = 0, maxy = 0;
int i;
Aug 20, 2013
Aug 20, 2013
972
/* Create input data, tracking result */
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
for (i=0; i<numPoints; i++) {
newx = SDLTest_RandomIntegerInRange(-1024, 1024);
newy = SDLTest_RandomIntegerInRange(-1024, 1024);
refPoints[i].x = newx;
refPoints[i].y = newy;
points[i].x = newx;
points[i].y = newy;
if (i==0) {
minx = newx;
maxx = newx;
miny = newy;
maxy = newy;
} else {
if (newx < minx) minx = newx;
if (newx > maxx) maxx = newx;
if (newy < miny) miny = newy;
if (newy > maxy) maxy = newy;
}
}
Aug 20, 2013
Aug 20, 2013
993
/* Call function and validate - special case: no result requested */
994
995
996
997
998
999
1000
anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
"Check expected return value %s, got %s",
(expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
(anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
for (i=0; i<numPoints; i++) {
SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,