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

Latest commit

 

History

History
1696 lines (1516 loc) · 65.3 KB

testautomation_rect.c

File metadata and controls

1696 lines (1516 loc) · 65.3 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* 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 */
/*!
* \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
24
SDLTest_AssertCheck(intersection == expectedIntersection,
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"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 */
/*!
* \brief Tests SDL_IntersectRectAndLine() clipping cases
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
May 18, 2013
May 18, 2013
48
int
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
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);
May 18, 2013
May 18, 2013
110
return TEST_COMPLETED;
111
112
113
114
115
116
117
118
}
/*!
* \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
May 18, 2013
May 18, 2013
119
int
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
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);
May 18, 2013
May 18, 2013
177
return TEST_COMPLETED;
178
179
180
181
182
183
184
185
}
/*!
* \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
May 18, 2013
May 18, 2013
186
int
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
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);
May 18, 2013
May 18, 2013
232
return TEST_COMPLETED;
233
234
235
236
237
238
239
240
}
/*!
* \brief Tests SDL_IntersectRectAndLine() with empty rectangle
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
May 18, 2013
May 18, 2013
241
int
242
243
244
245
246
247
248
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
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);
May 18, 2013
May 18, 2013
267
return TEST_COMPLETED;
268
269
270
271
272
273
274
275
}
/*!
* \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
*/
May 18, 2013
May 18, 2013
276
int
277
278
279
280
281
282
283
284
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
285
286
287
intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
SDLTest_AssertCheck(intersected == SDL_TRUE, "Check that intersection result was SDL_TRUE");
May 18, 2013
May 18, 2013
288
289
290
291
292
293
294
295
296
297
298
299
300
301
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");
May 18, 2013
May 18, 2013
302
return TEST_COMPLETED;
303
304
305
306
307
308
}
/*!
* \brief Private helper to check SDL_HasIntersection results
*/
void _validateHasIntersectionResults(
May 18, 2013
May 18, 2013
309
SDL_bool intersection, SDL_bool expectedIntersection,
310
311
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
{
May 18, 2013
May 18, 2013
312
SDLTest_AssertCheck(intersection == expectedIntersection,
313
314
315
"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",
May 18, 2013
May 18, 2013
316
rectA->x, rectA->y, rectA->w, rectA->h,
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
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);
}
/*!
* \brief Private helper to check SDL_IntersectRect results
*/
void _validateIntersectRectResults(
May 18, 2013
May 18, 2013
332
333
SDL_bool intersection, SDL_bool expectedIntersection,
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
334
335
336
337
338
339
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)",
May 18, 2013
May 18, 2013
340
rectA->x, rectA->y, rectA->w, rectA->h,
341
342
343
344
345
346
347
348
349
350
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
351
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
352
353
354
355
356
357
358
359
360
361
362
363
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)",
May 18, 2013
May 18, 2013
364
rectA->x, rectA->y, rectA->w, rectA->h,
365
366
367
368
369
370
371
372
373
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
374
SDL_bool empty, SDL_bool expectedEmpty,
375
376
SDL_Rect *rect, SDL_Rect *refRect)
{
May 18, 2013
May 18, 2013
377
SDLTest_AssertCheck(empty == expectedEmpty,
378
379
380
381
382
383
384
385
386
387
388
389
390
391
"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);
}
/*!
* \brief Private helper to check SDL_RectEquals results
*/
void _validateRectEqualsResults(
May 18, 2013
May 18, 2013
392
SDL_bool equals, SDL_bool expectedEquals,
393
394
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
{
May 18, 2013
May 18, 2013
395
SDLTest_AssertCheck(equals == expectedEquals,
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
"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);
}
/*!
* \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 = 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);
May 18, 2013
May 18, 2013
436
return TEST_COMPLETED;
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
}
/*!
* \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 + 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);
May 18, 2013
May 18, 2013
462
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
464
return TEST_COMPLETED;
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
}
/*!
* \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 = 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;
May 18, 2013
May 18, 2013
493
expectedResult.h = refRectA.h - refRectB.y;
494
495
496
497
498
499
500
501
502
503
504
505
506
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 = 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;
May 18, 2013
May 18, 2013
507
expectedResult.h = refRectB.h;
508
509
510
511
512
513
514
515
516
517
518
519
520
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 = SDLTest_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
521
expectedResult.h = refRectB.h;
522
523
524
525
526
527
528
529
530
531
532
533
534
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 = 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;
May 18, 2013
May 18, 2013
535
expectedResult.h = 1;
536
537
538
539
540
541
542
543
544
545
546
547
548
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 = 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;
May 18, 2013
May 18, 2013
549
expectedResult.h = 1;
550
551
552
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
May 18, 2013
May 18, 2013
553
return TEST_COMPLETED;
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
582
583
584
585
586
587
588
}
/*!
* \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 = 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);
// non-intersecting pixels cases
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;
May 18, 2013
May 18, 2013
589
refRectB.y = refRectA.y;
590
591
592
593
594
595
596
597
598
599
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);
}
}
}
May 18, 2013
May 18, 2013
600
return TEST_COMPLETED;
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
}
/*!
* \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;
Apr 17, 2013
Apr 17, 2013
617
SDL_bool empty;
Apr 17, 2013
Apr 17, 2013
620
621
result.w = SDLTest_RandomIntegerInRange(1, 100);
result.h = SDLTest_RandomIntegerInRange(1, 100);
622
623
624
625
626
627
628
629
630
631
632
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);
Apr 17, 2013
Apr 17, 2013
633
634
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");
May 18, 2013
May 18, 2013
635
Apr 17, 2013
Apr 17, 2013
637
638
result.w = SDLTest_RandomIntegerInRange(1, 100);
result.h = SDLTest_RandomIntegerInRange(1, 100);
639
640
641
642
643
644
645
646
647
648
649
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);
Apr 17, 2013
Apr 17, 2013
650
651
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");
652
653
// Rect A and B empty
Apr 17, 2013
Apr 17, 2013
654
655
result.w = SDLTest_RandomIntegerInRange(1, 100);
result.h = SDLTest_RandomIntegerInRange(1, 100);
656
657
658
659
660
661
662
663
664
665
666
667
668
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);
Apr 17, 2013
Apr 17, 2013
669
670
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");
Apr 17, 2013
Apr 17, 2013
672
return TEST_COMPLETED;
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
}
/*!
* \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
690
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
691
intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
May 18, 2013
May 18, 2013
692
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
693
intersection = SDL_IntersectRect(&rectA, &rectB, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
694
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 3st parameter is NULL");
695
intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
May 18, 2013
May 18, 2013
696
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameters are NULL");
697
intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
698
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 3rd parameters are NULL ");
699
intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
700
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
May 18, 2013
May 18, 2013
702
return TEST_COMPLETED;
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
}
/*!
* \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 = 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);
May 18, 2013
May 18, 2013
729
return TEST_COMPLETED;
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
}
/*!
* \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 + 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);
May 18, 2013
May 18, 2013
756
return TEST_COMPLETED;
757
758
759
760
761
762
763
764
765
766
767
768
769
770
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
}
/*!
* \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 = 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);
// rectB right edge
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);
// rectB left edge
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);
// rectB bottom edge
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);
// rectB top edge
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);
May 18, 2013
May 18, 2013
823
return TEST_COMPLETED;
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
}
/*!
* \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;
// intersecting pixels
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);
// non-intersecting pixels cases
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;
May 18, 2013
May 18, 2013
858
refRectB.y = refRectA.y;
859
860
861
862
863
864
865
866
867
868
refRectB.x += offsetX;
refRectB.y += offsetY;
rectA = refRectA;
rectB = refRectB;
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
}
}
}
May 18, 2013
May 18, 2013
869
return TEST_COMPLETED;
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
921
922
923
924
925
926
}
/*!
* \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 = 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);
// Rect B empty
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);
// Rect A and B empty
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);
May 18, 2013
May 18, 2013
927
return TEST_COMPLETED;
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
}
/*!
* \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;
// invalid parameter combinations
intersection = SDL_HasIntersection((SDL_Rect *)NULL, &rectB);
May 18, 2013
May 18, 2013
944
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
945
intersection = SDL_HasIntersection(&rectA, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
946
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
947
intersection = SDL_HasIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
948
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
May 18, 2013
May 18, 2013
950
return TEST_COMPLETED;
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
}
/*!
* \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;
Dec 24, 2012
Dec 24, 2012
969
int minx = 0, maxx = 0, miny = 0, maxy = 0;
Dec 24, 2012
Dec 24, 2012
971
972
// Create input data, tracking result
973
974
975
976
977
978
979
980
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) {
Dec 24, 2012
Dec 24, 2012
981
982
983
984
minx = newx;
maxx = newx;
miny = newy;
maxy = newy;
Dec 24, 2012
Dec 24, 2012
986
987
988
989
if (newx < minx) minx = newx;
if (newx > maxx) maxx = newx;
if (newy < miny) miny = newy;
if (newy > maxy) maxy = newy;
May 18, 2013
May 18, 2013
992
993
994
// Call function and validate - special case: no result requested
anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
May 18, 2013
May 18, 2013
995
996
997
998
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");
999
1000
for (i=0; i<numPoints; i++) {
SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,