Debian Codegraph @

test/testautomation_rect.c

raw
1 /**
2 * Original code: automated SDL rect test written by Edgar Simo "bobbens"
3 * New/updated tests: aschiffler at ferzkopp dot net
4 */
5
6 #include <stdio.h>
7
8 #include "SDL.h"
9 #include "SDL_test.h"
10
11 /* ================= Test Case Implementation ================== */
12
13 /* Helper functions */
14
15 /* !
16 * \brief Private helper to check SDL_FRect equality
17 */
18 static SDL_bool IsFRectEqual(const SDL_FRect *r1, const SDL_FRect *r2) {
19 static const float MAX_DELTA = 1e-5f;
20 SDL_FRect delta;
21 delta.x = r1->x - r2->x;
22 delta.y = r1->y - r2->y;
23 delta.w = r1->w - r2->w;
24 delta.h = r1->h - r2->h;
25
26 return -MAX_DELTA <= delta.x && delta.x <= MAX_DELTA
27 && -MAX_DELTA <= delta.y && delta.y <= MAX_DELTA
28 && -MAX_DELTA <= delta.w && delta.w <= MAX_DELTA
29 && -MAX_DELTA <= delta.w && delta.h <= MAX_DELTA;
30 }
31
32 /* !
33 * \brief Private helper to check SDL_FPoint equality
34 */
35 static SDL_bool IsFPointEqual(const SDL_FPoint *p1, const SDL_FPoint *p2) {
36 static const float MAX_DELTA = 1e-5f;
37 SDL_FPoint delta;
38 delta.x = p1->x - p2->x;
39 delta.y = p1->y - p2->y;
40
41 return -MAX_DELTA <= delta.x && delta.x <= MAX_DELTA
42 && -MAX_DELTA <= delta.y && delta.y <= MAX_DELTA;
43 }
44
45 /* Helper functions */
46
47 /* !
48 * \brief Private helper to check SDL_IntersectRectAndLine results
49 */
50 void _validateIntersectRectAndLineResults(
51 SDL_bool intersection, SDL_bool expectedIntersection,
52 SDL_Rect *rect, SDL_Rect *refRect,
53 int x1, int y1, int x2, int y2,
54 int x1Ref, int y1Ref, int x2Ref, int y2Ref)
55 {
56 SDLTest_AssertCheck(intersection == expectedIntersection,
57 "Check for correct intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)",
58 (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
59 (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
60 refRect->x, refRect->y, refRect->w, refRect->h,
61 x1Ref, y1Ref, x2Ref, y2Ref);
62 SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
63 "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
64 rect->x, rect->y, rect->w, rect->h,
65 refRect->x, refRect->y, refRect->w, refRect->h);
66 SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
67 "Check if line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
68 x1, y1, x2, y2,
69 x1Ref, y1Ref, x2Ref, y2Ref);
70 }
71
72 /* Test case functions */
73
74 /* !
75 * \brief Tests SDL_IntersectRectAndLine() clipping cases
76 *
77 * \sa
78 * http://wiki.libsdl.org/SDL_IntersectRectAndLine
79 */
80 int rect_testIntersectRectAndLine(void *arg)
81 {
82 SDL_Rect refRect = { 0, 0, 32, 32 };
83 SDL_Rect rect;
84 int x1, y1;
85 int x2, y2;
86 SDL_bool intersected;
87
88 int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
89 int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
90 int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
91 int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
92
93 x1 = xLeft;
94 y1 = 15;
95 x2 = xRight;
96 y2 = 15;
97 rect = refRect;
98 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
99 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 15, 31, 15);
100
101 x1 = 15;
102 y1 = yTop;
103 x2 = 15;
104 y2 = yBottom;
105 rect = refRect;
106 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
107 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 15, 0, 15, 31);
108
109 x1 = -refRect.w;
110 y1 = -refRect.h;
111 x2 = 2 * refRect.w;
112 y2 = 2 * refRect.h;
113 rect = refRect;
114 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
115 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 0, 31, 31);
116
117 x1 = 2 * refRect.w;
118 y1 = 2 * refRect.h;
119 x2 = -refRect.w;
120 y2 = -refRect.h;
121 rect = refRect;
122 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
123 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 31, 0, 0);
124
125 x1 = -1;
126 y1 = 32;
127 x2 = 32;
128 y2 = -1;
129 rect = refRect;
130 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
131 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 31, 31, 0);
132
133 x1 = 32;
134 y1 = -1;
135 x2 = -1;
136 y2 = 32;
137 rect = refRect;
138 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
139 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31);
140
141 return TEST_COMPLETED;
142 }
143
144 /* !
145 * \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
146 *
147 * \sa
148 * http://wiki.libsdl.org/SDL_IntersectRectAndLine
149 */
150 int rect_testIntersectRectAndLineInside(void *arg)
151 {
152 SDL_Rect refRect = { 0, 0, 32, 32 };
153 SDL_Rect rect;
154 int x1, y1;
155 int x2, y2;
156 SDL_bool intersected;
157
158 int xmin = refRect.x;
159 int xmax = refRect.x + refRect.w - 1;
160 int ymin = refRect.y;
161 int ymax = refRect.y + refRect.h - 1;
162 int x1Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
163 int y1Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
164 int x2Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
165 int y2Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
166
167 x1 = x1Ref;
168 y1 = y1Ref;
169 x2 = x2Ref;
170 y2 = y2Ref;
171 rect = refRect;
172 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
173 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
174
175 x1 = x1Ref;
176 y1 = y1Ref;
177 x2 = xmax;
178 y2 = ymax;
179 rect = refRect;
180 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
181 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, xmax, ymax);
182
183 x1 = xmin;
184 y1 = ymin;
185 x2 = x2Ref;
186 y2 = y2Ref;
187 rect = refRect;
188 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
189 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, x2Ref, y2Ref);
190
191 x1 = xmin;
192 y1 = ymin;
193 x2 = xmax;
194 y2 = ymax;
195 rect = refRect;
196 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
197 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, xmax, ymax);
198
199 x1 = xmin;
200 y1 = ymax;
201 x2 = xmax;
202 y2 = ymin;
203 rect = refRect;
204 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
205 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymax, xmax, ymin);
206
207 return TEST_COMPLETED;
208 }
209
210 /* !
211 * \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
212 *
213 * \sa
214 * http://wiki.libsdl.org/SDL_IntersectRectAndLine
215 */
216 int rect_testIntersectRectAndLineOutside(void *arg)
217 {
218 SDL_Rect refRect = { 0, 0, 32, 32 };
219 SDL_Rect rect;
220 int x1, y1;
221 int x2, y2;
222 SDL_bool intersected;
223
224 int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
225 int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
226 int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
227 int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
228
229 x1 = xLeft;
230 y1 = 0;
231 x2 = xLeft;
232 y2 = 31;
233 rect = refRect;
234 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
235 _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xLeft, 0, xLeft, 31);
236
237 x1 = xRight;
238 y1 = 0;
239 x2 = xRight;
240 y2 = 31;
241 rect = refRect;
242 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
243 _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xRight, 0, xRight, 31);
244
245 x1 = 0;
246 y1 = yTop;
247 x2 = 31;
248 y2 = yTop;
249 rect = refRect;
250 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
251 _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yTop, 31, yTop);
252
253 x1 = 0;
254 y1 = yBottom;
255 x2 = 31;
256 y2 = yBottom;
257 rect = refRect;
258 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
259 _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yBottom, 31, yBottom);
260
261 return TEST_COMPLETED;
262 }
263
264 /* !
265 * \brief Tests SDL_IntersectRectAndLine() with empty rectangle
266 *
267 * \sa
268 * http://wiki.libsdl.org/SDL_IntersectRectAndLine
269 */
270 int rect_testIntersectRectAndLineEmpty(void *arg)
271 {
272 SDL_Rect refRect;
273 SDL_Rect rect;
274 int x1, y1, x1Ref, y1Ref;
275 int x2, y2, x2Ref, y2Ref;
276 SDL_bool intersected;
277
278 refRect.x = SDLTest_RandomIntegerInRange(1, 1024);
279 refRect.y = SDLTest_RandomIntegerInRange(1, 1024);
280 refRect.w = 0;
281 refRect.h = 0;
282 x1Ref = refRect.x;
283 y1Ref = refRect.y;
284 x2Ref = SDLTest_RandomIntegerInRange(1, 1024);
285 y2Ref = SDLTest_RandomIntegerInRange(1, 1024);
286
287 x1 = x1Ref;
288 y1 = y1Ref;
289 x2 = x2Ref;
290 y2 = y2Ref;
291 rect = refRect;
292 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
293 _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
294
295 return TEST_COMPLETED;
296 }
297
298 /* !
299 * \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
300 *
301 * \sa
302 * http://wiki.libsdl.org/SDL_IntersectRectAndLine
303 */
304 int rect_testIntersectRectAndLineParam(void *arg)
305 {
306 SDL_Rect rect = { 0, 0, 32, 32 };
307 int x1 = rect.w / 2;
308 int y1 = rect.h / 2;
309 int x2 = x1;
310 int y2 = 2 * rect.h;
311 SDL_bool intersected;
312
313 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
314 SDLTest_AssertCheck(intersected == SDL_TRUE, "Check that intersection result was SDL_TRUE");
315
316 intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, &x1, &y1, &x2, &y2);
317 SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
318 intersected = SDL_IntersectRectAndLine(&rect, (int *)NULL, &y1, &x2, &y2);
319 SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
320 intersected = SDL_IntersectRectAndLine(&rect, &x1, (int *)NULL, &x2, &y2);
321 SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 3rd parameter is NULL");
322 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, (int *)NULL, &y2);
323 SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 4th parameter is NULL");
324 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, (int *)NULL);
325 SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 5th parameter is NULL");
326 intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
327 SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
328
329 return TEST_COMPLETED;
330 }
331
332 /* !
333 * \brief Private helper to check SDL_HasIntersection results
334 */
335 void _validateHasIntersectionResults(
336 SDL_bool intersection, SDL_bool expectedIntersection,
337 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
338 {
339 SDLTest_AssertCheck(intersection == expectedIntersection,
340 "Check intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)",
341 (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
342 (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
343 rectA->x, rectA->y, rectA->w, rectA->h,
344 rectB->x, rectB->y, rectB->w, rectB->h);
345 SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
346 "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
347 rectA->x, rectA->y, rectA->w, rectA->h,
348 refRectA->x, refRectA->y, refRectA->w, refRectA->h);
349 SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
350 "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
351 rectB->x, rectB->y, rectB->w, rectB->h,
352 refRectB->x, refRectB->y, refRectB->w, refRectB->h);
353 }
354
355 /* !
356 * \brief Private helper to check SDL_IntersectRect results
357 */
358 void _validateIntersectRectResults(
359 SDL_bool intersection, SDL_bool expectedIntersection,
360 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
361 SDL_Rect *result, SDL_Rect *expectedResult)
362 {
363 _validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB);
364 if (result && expectedResult) {
365 SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
366 "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)",
367 rectA->x, rectA->y, rectA->w, rectA->h,
368 rectB->x, rectB->y, rectB->w, rectB->h,
369 result->x, result->y, result->w, result->h,
370 expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
371 }
372 }
373
374 /* !
375 * \brief Private helper to check SDL_UnionRect results
376 */
377 void _validateUnionRectResults(
378 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
379 SDL_Rect *result, SDL_Rect *expectedResult)
380 {
381 SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
382 "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
383 rectA->x, rectA->y, rectA->w, rectA->h,
384 refRectA->x, refRectA->y, refRectA->w, refRectA->h);
385 SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
386 "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
387 rectB->x, rectB->y, rectB->w, rectB->h,
388 refRectB->x, refRectB->y, refRectB->w, refRectB->h);
389 SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
390 "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)",
391 rectA->x, rectA->y, rectA->w, rectA->h,
392 rectB->x, rectB->y, rectB->w, rectB->h,
393 result->x, result->y, result->w, result->h,
394 expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
395 }
396
397 /* !
398 * \brief Private helper to check SDL_RectEmpty results
399 */
400 void _validateRectEmptyResults(
401 SDL_bool empty, SDL_bool expectedEmpty,
402 SDL_Rect *rect, SDL_Rect *refRect)
403 {
404 SDLTest_AssertCheck(empty == expectedEmpty,
405 "Check for correct empty result: expected %s, got %s testing (%d,%d,%d,%d)",
406 (expectedEmpty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
407 (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
408 rect->x, rect->y, rect->w, rect->h);
409 SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
410 "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
411 rect->x, rect->y, rect->w, rect->h,
412 refRect->x, refRect->y, refRect->w, refRect->h);
413 }
414
415 /* !
416 * \brief Private helper to check SDL_RectEquals results
417 */
418 void _validateRectEqualsResults(
419 SDL_bool equals, SDL_bool expectedEquals,
420 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
421 {
422 SDLTest_AssertCheck(equals == expectedEquals,
423 "Check for correct equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d)",
424 (expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
425 (equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
426 rectA->x, rectA->y, rectA->w, rectA->h,
427 rectB->x, rectB->y, rectB->w, rectB->h);
428 SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
429 "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
430 rectA->x, rectA->y, rectA->w, rectA->h,
431 refRectA->x, refRectA->y, refRectA->w, refRectA->h);
432 SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
433 "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
434 rectB->x, rectB->y, rectB->w, rectB->h,
435 refRectB->x, refRectB->y, refRectB->w, refRectB->h);
436 }
437
438 /* !
439 * \brief Private helper to check SDL_FRectEquals results
440 */
441 void _validateFRectEqualsResults(
442 SDL_bool equals, SDL_bool expectedEquals,
443 SDL_FRect *rectA, SDL_FRect *rectB, SDL_FRect *refRectA, SDL_FRect *refRectB)
444 {
445 int cmpRes;
446 SDLTest_AssertCheck(equals == expectedEquals,
447 "Check for correct equals result: expected %s, got %s testing (%f,%f,%f,%f) and (%f,%f,%f,%f)",
448 (expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
449 (equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
450 rectA->x, rectA->y, rectA->w, rectA->h,
451 rectB->x, rectB->y, rectB->w, rectB->h);
452 cmpRes = SDL_memcmp(rectA, refRectA, sizeof(*rectA));
453 SDLTest_AssertCheck(cmpRes == 0,
454 "Check that source rectangle A was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
455 rectA->x, rectA->y, rectA->w, rectA->h,
456 refRectA->x, refRectA->y, refRectA->w, refRectA->h);
457 cmpRes = SDL_memcmp(rectB, refRectB, sizeof(*rectB));
458 SDLTest_AssertCheck(cmpRes == 0,
459 "Check that source rectangle B was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
460 rectB->x, rectB->y, rectB->w, rectB->h,
461 refRectB->x, refRectB->y, refRectB->w, refRectB->h);
462 }
463
464 /* !
465 * \brief Tests SDL_IntersectRect() with B fully inside A
466 *
467 * \sa
468 * http://wiki.libsdl.org/SDL_IntersectRect
469 */
470 int rect_testIntersectRectInside(void *arg)
471 {
472 SDL_Rect refRectA = { 0, 0, 32, 32 };
473 SDL_Rect refRectB;
474 SDL_Rect rectA;
475 SDL_Rect rectB;
476 SDL_Rect result;
477 SDL_bool intersection;
478
479 /* rectB fully contained in rectA */
480 refRectB.x = 0;
481 refRectB.y = 0;
482 refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
483 refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
484 rectA = refRectA;
485 rectB = refRectB;
486 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
487 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB);
488
489 return TEST_COMPLETED;
490 }
491
492 /* !
493 * \brief Tests SDL_IntersectRect() with B fully outside A
494 *
495 * \sa
496 * http://wiki.libsdl.org/SDL_IntersectRect
497 */
498 int rect_testIntersectRectOutside(void *arg)
499 {
500 SDL_Rect refRectA = { 0, 0, 32, 32 };
501 SDL_Rect refRectB;
502 SDL_Rect rectA;
503 SDL_Rect rectB;
504 SDL_Rect result;
505 SDL_bool intersection;
506
507 /* rectB fully outside of rectA */
508 refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
509 refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
510 refRectB.w = refRectA.w;
511 refRectB.h = refRectA.h;
512 rectA = refRectA;
513 rectB = refRectB;
514 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
515 _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
516
517 return TEST_COMPLETED;
518 }
519
520 /* !
521 * \brief Tests SDL_IntersectRect() with B partially intersecting A
522 *
523 * \sa
524 * http://wiki.libsdl.org/SDL_IntersectRect
525 */
526 int rect_testIntersectRectPartial(void *arg)
527 {
528 SDL_Rect refRectA = { 0, 0, 32, 32 };
529 SDL_Rect refRectB;
530 SDL_Rect rectA;
531 SDL_Rect rectB;
532 SDL_Rect result;
533 SDL_Rect expectedResult;
534 SDL_bool intersection;
535
536 /* rectB partially contained in rectA */
537 refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
538 refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
539 refRectB.w = refRectA.w;
540 refRectB.h = refRectA.h;
541 rectA = refRectA;
542 rectB = refRectB;
543 expectedResult.x = refRectB.x;
544 expectedResult.y = refRectB.y;
545 expectedResult.w = refRectA.w - refRectB.x;
546 expectedResult.h = refRectA.h - refRectB.y;
547 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
548 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
549
550 /* rectB right edge */
551 refRectB.x = rectA.w - 1;
552 refRectB.y = rectA.y;
553 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
554 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
555 rectA = refRectA;
556 rectB = refRectB;
557 expectedResult.x = refRectB.x;
558 expectedResult.y = refRectB.y;
559 expectedResult.w = 1;
560 expectedResult.h = refRectB.h;
561 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
562 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
563
564 /* rectB left edge */
565 refRectB.x = 1 - rectA.w;
566 refRectB.y = rectA.y;
567 refRectB.w = refRectA.w;
568 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
569 rectA = refRectA;
570 rectB = refRectB;
571 expectedResult.x = 0;
572 expectedResult.y = refRectB.y;
573 expectedResult.w = 1;
574 expectedResult.h = refRectB.h;
575 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
576 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
577
578 /* rectB bottom edge */
579 refRectB.x = rectA.x;
580 refRectB.y = rectA.h - 1;
581 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
582 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
583 rectA = refRectA;
584 rectB = refRectB;
585 expectedResult.x = refRectB.x;
586 expectedResult.y = refRectB.y;
587 expectedResult.w = refRectB.w;
588 expectedResult.h = 1;
589 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
590 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
591
592 /* rectB top edge */
593 refRectB.x = rectA.x;
594 refRectB.y = 1 - rectA.h;
595 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
596 refRectB.h = rectA.h;
597 rectA = refRectA;
598 rectB = refRectB;
599 expectedResult.x = refRectB.x;
600 expectedResult.y = 0;
601 expectedResult.w = refRectB.w;
602 expectedResult.h = 1;
603 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
604 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
605
606 return TEST_COMPLETED;
607 }
608
609 /* !
610 * \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
611 *
612 * \sa
613 * http://wiki.libsdl.org/SDL_IntersectRect
614 */
615 int rect_testIntersectRectPoint(void *arg)
616 {
617 SDL_Rect refRectA = { 0, 0, 1, 1 };
618 SDL_Rect refRectB = { 0, 0, 1, 1 };
619 SDL_Rect rectA;
620 SDL_Rect rectB;
621 SDL_Rect result;
622 SDL_bool intersection;
623 int offsetX, offsetY;
624
625 /* intersecting pixels */
626 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
627 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
628 refRectB.x = refRectA.x;
629 refRectB.y = refRectA.y;
630 rectA = refRectA;
631 rectB = refRectB;
632 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
633 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA);
634
635 /* non-intersecting pixels cases */
636 for (offsetX = -1; offsetX <= 1; offsetX++) {
637 for (offsetY = -1; offsetY <= 1; offsetY++) {
638 if (offsetX != 0 || offsetY != 0) {
639 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
640 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
641 refRectB.x = refRectA.x;
642 refRectB.y = refRectA.y;
643 refRectB.x += offsetX;
644 refRectB.y += offsetY;
645 rectA = refRectA;
646 rectB = refRectB;
647 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
648 _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
649 }
650 }
651 }
652
653 return TEST_COMPLETED;
654 }
655
656 /* !
657 * \brief Tests SDL_IntersectRect() with empty rectangles
658 *
659 * \sa
660 * http://wiki.libsdl.org/SDL_IntersectRect
661 */
662 int rect_testIntersectRectEmpty(void *arg)
663 {
664 SDL_Rect refRectA;
665 SDL_Rect refRectB;
666 SDL_Rect rectA;
667 SDL_Rect rectB;
668 SDL_Rect result;
669 SDL_bool intersection;
670 SDL_bool empty;
671
672 /* Rect A empty */
673 result.w = SDLTest_RandomIntegerInRange(1, 100);
674 result.h = SDLTest_RandomIntegerInRange(1, 100);
675 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
676 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
677 refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
678 refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
679 refRectB = refRectA;
680 refRectA.w = 0;
681 refRectA.h = 0;
682 rectA = refRectA;
683 rectB = refRectB;
684 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
685 _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
686 empty = SDL_RectEmpty(&result);
687 SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
688
689 /* Rect B empty */
690 result.w = SDLTest_RandomIntegerInRange(1, 100);
691 result.h = SDLTest_RandomIntegerInRange(1, 100);
692 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
693 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
694 refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
695 refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
696 refRectB = refRectA;
697 refRectB.w = 0;
698 refRectB.h = 0;
699 rectA = refRectA;
700 rectB = refRectB;
701 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
702 _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
703 empty = SDL_RectEmpty(&result);
704 SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
705
706 /* Rect A and B empty */
707 result.w = SDLTest_RandomIntegerInRange(1, 100);
708 result.h = SDLTest_RandomIntegerInRange(1, 100);
709 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
710 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
711 refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
712 refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
713 refRectB = refRectA;
714 refRectA.w = 0;
715 refRectA.h = 0;
716 refRectB.w = 0;
717 refRectB.h = 0;
718 rectA = refRectA;
719 rectB = refRectB;
720 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
721 _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
722 empty = SDL_RectEmpty(&result);
723 SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
724
725 return TEST_COMPLETED;
726 }
727
728 /* !
729 * \brief Negative tests against SDL_IntersectRect() with invalid parameters
730 *
731 * \sa
732 * http://wiki.libsdl.org/SDL_IntersectRect
733 */
734 int rect_testIntersectRectParam(void *arg)
735 {
736 const SDL_Rect rectA = { 0, 0, 32, 32 };
737 const SDL_Rect rectB = { 0, 0, 32, 32 };
738 SDL_Rect result;
739 SDL_bool intersection;
740
741 /* invalid parameter combinations */
742 intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, &result);
743 SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
744 intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
745 SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
746 intersection = SDL_IntersectRect(&rectA, &rectB, (SDL_Rect *)NULL);
747 SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 3st parameter is NULL");
748 intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
749 SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameters are NULL");
750 intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
751 SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 3rd parameters are NULL ");
752 intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
753 SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
754
755 return TEST_COMPLETED;
756 }
757
758 /* !
759 * \brief Tests SDL_HasIntersection() with B fully inside A
760 *
761 * \sa
762 * http://wiki.libsdl.org/SDL_HasIntersection
763 */
764 int rect_testHasIntersectionInside(void *arg)
765 {
766 SDL_Rect refRectA = { 0, 0, 32, 32 };
767 SDL_Rect refRectB;
768 SDL_Rect rectA;
769 SDL_Rect rectB;
770 SDL_bool intersection;
771
772 /* rectB fully contained in rectA */
773 refRectB.x = 0;
774 refRectB.y = 0;
775 refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
776 refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
777 rectA = refRectA;
778 rectB = refRectB;
779 intersection = SDL_HasIntersection(&rectA, &rectB);
780 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
781
782 return TEST_COMPLETED;
783 }
784
785 /* !
786 * \brief Tests SDL_HasIntersection() with B fully outside A
787 *
788 * \sa
789 * http://wiki.libsdl.org/SDL_HasIntersection
790 */
791 int rect_testHasIntersectionOutside(void *arg)
792 {
793 SDL_Rect refRectA = { 0, 0, 32, 32 };
794 SDL_Rect refRectB;
795 SDL_Rect rectA;
796 SDL_Rect rectB;
797 SDL_bool intersection;
798
799 /* rectB fully outside of rectA */
800 refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
801 refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
802 refRectB.w = refRectA.w;
803 refRectB.h = refRectA.h;
804 rectA = refRectA;
805 rectB = refRectB;
806 intersection = SDL_HasIntersection(&rectA, &rectB);
807 _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
808
809 return TEST_COMPLETED;
810 }
811
812 /* !
813 * \brief Tests SDL_HasIntersection() with B partially intersecting A
814 *
815 * \sa
816 * http://wiki.libsdl.org/SDL_HasIntersection
817 */
818 int rect_testHasIntersectionPartial(void *arg)
819 {
820 SDL_Rect refRectA = { 0, 0, 32, 32 };
821 SDL_Rect refRectB;
822 SDL_Rect rectA;
823 SDL_Rect rectB;
824 SDL_bool intersection;
825
826 /* rectB partially contained in rectA */
827 refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
828 refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
829 refRectB.w = refRectA.w;
830 refRectB.h = refRectA.h;
831 rectA = refRectA;
832 rectB = refRectB;
833 intersection = SDL_HasIntersection(&rectA, &rectB);
834 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
835
836 /* rectB right edge */
837 refRectB.x = rectA.w - 1;
838 refRectB.y = rectA.y;
839 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
840 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
841 rectA = refRectA;
842 rectB = refRectB;
843 intersection = SDL_HasIntersection(&rectA, &rectB);
844 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
845
846 /* rectB left edge */
847 refRectB.x = 1 - rectA.w;
848 refRectB.y = rectA.y;
849 refRectB.w = refRectA.w;
850 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
851 rectA = refRectA;
852 rectB = refRectB;
853 intersection = SDL_HasIntersection(&rectA, &rectB);
854 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
855
856 /* rectB bottom edge */
857 refRectB.x = rectA.x;
858 refRectB.y = rectA.h - 1;
859 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
860 refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
861 rectA = refRectA;
862 rectB = refRectB;
863 intersection = SDL_HasIntersection(&rectA, &rectB);
864 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
865
866 /* rectB top edge */
867 refRectB.x = rectA.x;
868 refRectB.y = 1 - rectA.h;
869 refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
870 refRectB.h = rectA.h;
871 rectA = refRectA;
872 rectB = refRectB;
873 intersection = SDL_HasIntersection(&rectA, &rectB);
874 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
875
876 return TEST_COMPLETED;
877 }
878
879 /* !
880 * \brief Tests SDL_HasIntersection() with 1x1 pixel sized rectangles
881 *
882 * \sa
883 * http://wiki.libsdl.org/SDL_HasIntersection
884 */
885 int rect_testHasIntersectionPoint(void *arg)
886 {
887 SDL_Rect refRectA = { 0, 0, 1, 1 };
888 SDL_Rect refRectB = { 0, 0, 1, 1 };
889 SDL_Rect rectA;
890 SDL_Rect rectB;
891 SDL_bool intersection;
892 int offsetX, offsetY;
893
894 /* intersecting pixels */
895 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
896 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
897 refRectB.x = refRectA.x;
898 refRectB.y = refRectA.y;
899 rectA = refRectA;
900 rectB = refRectB;
901 intersection = SDL_HasIntersection(&rectA, &rectB);
902 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
903
904 /* non-intersecting pixels cases */
905 for (offsetX = -1; offsetX <= 1; offsetX++) {
906 for (offsetY = -1; offsetY <= 1; offsetY++) {
907 if (offsetX != 0 || offsetY != 0) {
908 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
909 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
910 refRectB.x = refRectA.x;
911 refRectB.y = refRectA.y;
912 refRectB.x += offsetX;
913 refRectB.y += offsetY;
914 rectA = refRectA;
915 rectB = refRectB;
916 intersection = SDL_HasIntersection(&rectA, &rectB);
917 _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
918 }
919 }
920 }
921
922 return TEST_COMPLETED;
923 }
924
925 /* !
926 * \brief Tests SDL_HasIntersection() with empty rectangles
927 *
928 * \sa
929 * http://wiki.libsdl.org/SDL_HasIntersection
930 */
931 int rect_testHasIntersectionEmpty(void *arg)
932 {
933 SDL_Rect refRectA;
934 SDL_Rect refRectB;
935 SDL_Rect rectA;
936 SDL_Rect rectB;
937 SDL_bool intersection;
938
939 /* Rect A empty */
940 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
941 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
942 refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
943 refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
944 refRectB = refRectA;
945 refRectA.w = 0;
946 refRectA.h = 0;
947 rectA = refRectA;
948 rectB = refRectB;
949 intersection = SDL_HasIntersection(&rectA, &rectB);
950 _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
951
952 /* Rect B empty */
953 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
954 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
955 refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
956 refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
957 refRectB = refRectA;
958 refRectB.w = 0;
959 refRectB.h = 0;
960 rectA = refRectA;
961 rectB = refRectB;
962 intersection = SDL_HasIntersection(&rectA, &rectB);
963 _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
964
965 /* Rect A and B empty */
966 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
967 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
968 refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
969 refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
970 refRectB = refRectA;
971 refRectA.w = 0;
972 refRectA.h = 0;
973 refRectB.w = 0;
974 refRectB.h = 0;
975 rectA = refRectA;
976 rectB = refRectB;
977 intersection = SDL_HasIntersection(&rectA, &rectB);
978 _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
979
980 return TEST_COMPLETED;
981 }
982
983 /* !
984 * \brief Negative tests against SDL_HasIntersection() with invalid parameters
985 *
986 * \sa
987 * http://wiki.libsdl.org/SDL_HasIntersection
988 */
989 int rect_testHasIntersectionParam(void *arg)
990 {
991 const SDL_Rect rectA = { 0, 0, 32, 32 };
992 const SDL_Rect rectB = { 0, 0, 32, 32 };
993 SDL_bool intersection;
994
995 /* invalid parameter combinations */
996 intersection = SDL_HasIntersection((SDL_Rect *)NULL, &rectB);
997 SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
998 intersection = SDL_HasIntersection(&rectA, (SDL_Rect *)NULL);
999 SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
1000 intersection = SDL_HasIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL);
1001 SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
1002
1003 return TEST_COMPLETED;
1004 }
1005
1006 /* !
1007 * \brief Test SDL_EnclosePoints() without clipping
1008 *
1009 * \sa
1010 * http://wiki.libsdl.org/SDL_EnclosePoints
1011 */
1012 int rect_testEnclosePoints(void *arg)
1013 {
1014 const int numPoints = 16;
1015 SDL_Point refPoints[16];
1016 SDL_Point points[16];
1017 SDL_Rect result;
1018 SDL_bool anyEnclosed;
1019 SDL_bool anyEnclosedNoResult;
1020 SDL_bool expectedEnclosed = SDL_TRUE;
1021 int newx, newy;
1022 int minx = 0, maxx = 0, miny = 0, maxy = 0;
1023 int i;
1024
1025 /* Create input data, tracking result */
1026 for (i = 0; i < numPoints; i++) {
1027 newx = SDLTest_RandomIntegerInRange(-1024, 1024);
1028 newy = SDLTest_RandomIntegerInRange(-1024, 1024);
1029 refPoints[i].x = newx;
1030 refPoints[i].y = newy;
1031 points[i].x = newx;
1032 points[i].y = newy;
1033 if (i == 0) {
1034 minx = newx;
1035 maxx = newx;
1036 miny = newy;
1037 maxy = newy;
1038 } else {
1039 if (newx < minx) {
1040 minx = newx;
1041 }
1042 if (newx > maxx) {
1043 maxx = newx;
1044 }
1045 if (newy < miny) {
1046 miny = newy;
1047 }
1048 if (newy > maxy) {
1049 maxy = newy;
1050 }
1051 }
1052 }
1053
1054 /* Call function and validate - special case: no result requested */
1055 anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
1056 SDLTest_AssertCheck(expectedEnclosed == anyEnclosedNoResult,
1057 "Check expected return value %s, got %s",
1058 (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1059 (anyEnclosedNoResult == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1060 for (i = 0; i < numPoints; i++) {
1061 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1062 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1063 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1064 }
1065
1066 /* Call function and validate */
1067 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
1068 SDLTest_AssertCheck(expectedEnclosed == anyEnclosed,
1069 "Check return value %s, got %s",
1070 (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1071 (anyEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1072 for (i = 0; i < numPoints; i++) {
1073 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1074 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1075 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1076 }
1077 SDLTest_AssertCheck(result.x == minx && result.y == miny && result.w == (maxx - minx + 1) && result.h == (maxy - miny + 1),
1078 "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1079 minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1080
1081 return TEST_COMPLETED;
1082 }
1083
1084 /* !
1085 * \brief Test SDL_EnclosePoints() with repeated input points
1086 *
1087 * \sa
1088 * http://wiki.libsdl.org/SDL_EnclosePoints
1089 */
1090 int rect_testEnclosePointsRepeatedInput(void *arg)
1091 {
1092 const int numPoints = 8;
1093 const int halfPoints = 4;
1094 SDL_Point refPoints[8];
1095 SDL_Point points[8];
1096 SDL_Rect result;
1097 SDL_bool anyEnclosed;
1098 SDL_bool anyEnclosedNoResult;
1099 SDL_bool expectedEnclosed = SDL_TRUE;
1100 int newx, newy;
1101 int minx = 0, maxx = 0, miny = 0, maxy = 0;
1102 int i;
1103
1104 /* Create input data, tracking result */
1105 for (i = 0; i < numPoints; i++) {
1106 if (i < halfPoints) {
1107 newx = SDLTest_RandomIntegerInRange(-1024, 1024);
1108 newy = SDLTest_RandomIntegerInRange(-1024, 1024);
1109 } else {
1110 newx = refPoints[i - halfPoints].x;
1111 newy = refPoints[i - halfPoints].y;
1112 }
1113 refPoints[i].x = newx;
1114 refPoints[i].y = newy;
1115 points[i].x = newx;
1116 points[i].y = newy;
1117 if (i == 0) {
1118 minx = newx;
1119 maxx = newx;
1120 miny = newy;
1121 maxy = newy;
1122 } else {
1123 if (newx < minx) {
1124 minx = newx;
1125 }
1126 if (newx > maxx) {
1127 maxx = newx;
1128 }
1129 if (newy < miny) {
1130 miny = newy;
1131 }
1132 if (newy > maxy) {
1133 maxy = newy;
1134 }
1135 }
1136 }
1137
1138 /* Call function and validate - special case: no result requested */
1139 anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
1140 SDLTest_AssertCheck(expectedEnclosed == anyEnclosedNoResult,
1141 "Check return value %s, got %s",
1142 (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1143 (anyEnclosedNoResult == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1144 for (i = 0; i < numPoints; i++) {
1145 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1146 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1147 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1148 }
1149
1150 /* Call function and validate */
1151 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
1152 SDLTest_AssertCheck(expectedEnclosed == anyEnclosed,
1153 "Check return value %s, got %s",
1154 (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1155 (anyEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1156 for (i = 0; i < numPoints; i++) {
1157 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1158 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1159 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1160 }
1161 SDLTest_AssertCheck(result.x == minx && result.y == miny && result.w == (maxx - minx + 1) && result.h == (maxy - miny + 1),
1162 "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1163 minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1164
1165 return TEST_COMPLETED;
1166 }
1167
1168 /* !
1169 * \brief Test SDL_EnclosePoints() with clipping
1170 *
1171 * \sa
1172 * http://wiki.libsdl.org/SDL_EnclosePoints
1173 */
1174 int rect_testEnclosePointsWithClipping(void *arg)
1175 {
1176 const int numPoints = 16;
1177 SDL_Point refPoints[16];
1178 SDL_Point points[16];
1179 SDL_Rect refClip;
1180 SDL_Rect clip;
1181 SDL_Rect result;
1182 SDL_bool anyEnclosed;
1183 SDL_bool anyEnclosedNoResult;
1184 SDL_bool expectedEnclosed = SDL_FALSE;
1185 int newx, newy;
1186 int minx = 0, maxx = 0, miny = 0, maxy = 0;
1187 int i;
1188
1189 /* Setup clipping rectangle */
1190 refClip.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1191 refClip.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1192 refClip.w = SDLTest_RandomIntegerInRange(1, 1024);
1193 refClip.h = SDLTest_RandomIntegerInRange(1, 1024);
1194
1195 /* Create input data, tracking result */
1196 for (i = 0; i < numPoints; i++) {
1197 newx = SDLTest_RandomIntegerInRange(-1024, 1024);
1198 newy = SDLTest_RandomIntegerInRange(-1024, 1024);
1199 refPoints[i].x = newx;
1200 refPoints[i].y = newy;
1201 points[i].x = newx;
1202 points[i].y = newy;
1203 if ((newx >= refClip.x) && (newx < (refClip.x + refClip.w)) &&
1204 (newy >= refClip.y) && (newy < (refClip.y + refClip.h))) {
1205 if (expectedEnclosed == SDL_FALSE) {
1206 minx = newx;
1207 maxx = newx;
1208 miny = newy;
1209 maxy = newy;
1210 } else {
1211 if (newx < minx) {
1212 minx = newx;
1213 }
1214 if (newx > maxx) {
1215 maxx = newx;
1216 }
1217 if (newy < miny) {
1218 miny = newy;
1219 }
1220 if (newy > maxy) {
1221 maxy = newy;
1222 }
1223 }
1224 expectedEnclosed = SDL_TRUE;
1225 }
1226 }
1227
1228 /* Call function and validate - special case: no result requested */
1229 clip = refClip;
1230 anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, (SDL_Rect *)NULL);
1231 SDLTest_AssertCheck(expectedEnclosed == anyEnclosedNoResult,
1232 "Expected return value %s, got %s",
1233 (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1234 (anyEnclosedNoResult == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1235 for (i = 0; i < numPoints; i++) {
1236 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1237 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1238 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1239 }
1240 SDLTest_AssertCheck(refClip.x == clip.x && refClip.y == clip.y && refClip.w == clip.w && refClip.h == clip.h,
1241 "Check that source clipping rectangle was not modified");
1242
1243 /* Call function and validate */
1244 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
1245 SDLTest_AssertCheck(expectedEnclosed == anyEnclosed,
1246 "Check return value %s, got %s",
1247 (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1248 (anyEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1249 for (i = 0; i < numPoints; i++) {
1250 SDLTest_AssertCheck(refPoints[i].x == points[i].x && refPoints[i].y == points[i].y,
1251 "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1252 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1253 }
1254 SDLTest_AssertCheck(refClip.x == clip.x && refClip.y == clip.y && refClip.w == clip.w && refClip.h == clip.h,
1255 "Check that source clipping rectangle was not modified");
1256 if (expectedEnclosed == SDL_TRUE) {
1257 SDLTest_AssertCheck(result.x == minx && result.y == miny && result.w == (maxx - minx + 1) && result.h == (maxy - miny + 1),
1258 "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1259 minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1260 }
1261
1262 /* Empty clipping rectangle */
1263 clip.w = 0;
1264 clip.h = 0;
1265 expectedEnclosed = SDL_FALSE;
1266 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
1267 SDLTest_AssertCheck(expectedEnclosed == anyEnclosed,
1268 "Check return value %s, got %s",
1269 (expectedEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1270 (anyEnclosed == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1271
1272 return TEST_COMPLETED;
1273 }
1274
1275 /* !
1276 * \brief Negative tests against SDL_EnclosePoints() with invalid parameters
1277 *
1278 * \sa
1279 * http://wiki.libsdl.org/SDL_EnclosePoints
1280 */
1281 int rect_testEnclosePointsParam(void *arg)
1282 {
1283 SDL_Point points[1];
1284 int count;
1285 SDL_Rect clip = { 0 };
1286 SDL_Rect result;
1287 SDL_bool anyEnclosed;
1288
1289 /* invalid parameter combinations */
1290 anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 1, (const SDL_Rect *)&clip, &result);
1291 SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL");
1292 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, 0, (const SDL_Rect *)&clip, &result);
1293 SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is 0");
1294 count = SDLTest_RandomIntegerInRange(-100, -1);
1295 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, count, (const SDL_Rect *)&clip, &result);
1296 SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is %i (negative)", count);
1297 anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 0, (const SDL_Rect *)&clip, &result);
1298 SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL and 2nd parameter was 0");
1299
1300 return TEST_COMPLETED;
1301 }
1302
1303 /* !
1304 * \brief Tests SDL_UnionRect() where rect B is outside rect A
1305 *
1306 * \sa
1307 * http://wiki.libsdl.org/SDL_UnionRect
1308 */
1309 int rect_testUnionRectOutside(void *arg)
1310 {
1311 SDL_Rect refRectA, refRectB;
1312 SDL_Rect rectA, rectB;
1313 SDL_Rect expectedResult;
1314 SDL_Rect result;
1315 int minx, maxx, miny, maxy;
1316 int dx, dy;
1317
1318 /* Union 1x1 outside */
1319 for (dx = -1; dx < 2; dx++) {
1320 for (dy = -1; dy < 2; dy++) {
1321 if ((dx != 0) || (dy != 0)) {
1322 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1323 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1324 refRectA.w = 1;
1325 refRectA.h = 1;
1326 refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024) + dx * 2048;
1327 refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024) + dx * 2048;
1328 refRectB.w = 1;
1329 refRectB.h = 1;
1330 minx = (refRectA.x < refRectB.x) ? refRectA.x : refRectB.x;
1331 maxx = (refRectA.x > refRectB.x) ? refRectA.x : refRectB.x;
1332 miny = (refRectA.y < refRectB.y) ? refRectA.y : refRectB.y;
1333 maxy = (refRectA.y > refRectB.y) ? refRectA.y : refRectB.y;
1334 expectedResult.x = minx;
1335 expectedResult.y = miny;
1336 expectedResult.w = maxx - minx + 1;
1337 expectedResult.h = maxy - miny + 1;
1338 rectA = refRectA;
1339 rectB = refRectB;
1340 SDL_UnionRect(&rectA, &rectB, &result);
1341 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1342 }
1343 }
1344 }
1345
1346 /* Union outside overlap */
1347 for (dx = -1; dx < 2; dx++) {
1348 for (dy = -1; dy < 2; dy++) {
1349 if ((dx != 0) || (dy != 0)) {
1350 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1351 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1352 refRectA.w = SDLTest_RandomIntegerInRange(256, 512);
1353 refRectA.h = SDLTest_RandomIntegerInRange(256, 512);
1354 refRectB.x = refRectA.x + 1 + dx * 2;
1355 refRectB.y = refRectA.y + 1 + dy * 2;
1356 refRectB.w = refRectA.w - 2;
1357 refRectB.h = refRectA.h - 2;
1358 expectedResult = refRectA;
1359 if (dx == -1) {
1360 expectedResult.x--;
1361 }
1362 if (dy == -1) {
1363 expectedResult.y--;
1364 }
1365 if ((dx == 1) || (dx == -1)) {
1366 expectedResult.w++;
1367 }
1368 if ((dy == 1) || (dy == -1)) {
1369 expectedResult.h++;
1370 }
1371 rectA = refRectA;
1372 rectB = refRectB;
1373 SDL_UnionRect(&rectA, &rectB, &result);
1374 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1375 }
1376 }
1377 }
1378
1379 return TEST_COMPLETED;
1380 }
1381
1382 /* !
1383 * \brief Tests SDL_UnionRect() where rect A or rect B are empty
1384 *
1385 * \sa
1386 * http://wiki.libsdl.org/SDL_UnionRect
1387 */
1388 int rect_testUnionRectEmpty(void *arg)
1389 {
1390 SDL_Rect refRectA, refRectB;
1391 SDL_Rect rectA, rectB;
1392 SDL_Rect expectedResult;
1393 SDL_Rect result;
1394
1395 /* A empty */
1396 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1397 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1398 refRectA.w = 0;
1399 refRectA.h = 0;
1400 refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1401 refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1402 refRectB.w = SDLTest_RandomIntegerInRange(1, 1024);
1403 refRectB.h = SDLTest_RandomIntegerInRange(1, 1024);
1404 expectedResult = refRectB;
1405 rectA = refRectA;
1406 rectB = refRectB;
1407 SDL_UnionRect(&rectA, &rectB, &result);
1408 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1409
1410 /* B empty */
1411 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1412 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1413 refRectA.w = SDLTest_RandomIntegerInRange(1, 1024);
1414 refRectA.h = SDLTest_RandomIntegerInRange(1, 1024);
1415 refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1416 refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1417 refRectB.w = 0;
1418 refRectB.h = 0;
1419 expectedResult = refRectA;
1420 rectA = refRectA;
1421 rectB = refRectB;
1422 SDL_UnionRect(&rectA, &rectB, &result);
1423 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1424
1425 /* A and B empty */
1426 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1427 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1428 refRectA.w = 0;
1429 refRectA.h = 0;
1430 refRectB.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1431 refRectB.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1432 refRectB.w = 0;
1433 refRectB.h = 0;
1434 result.x = 0;
1435 result.y = 0;
1436 result.w = 0;
1437 result.h = 0;
1438 expectedResult = result;
1439 rectA = refRectA;
1440 rectB = refRectB;
1441 SDL_UnionRect(&rectA, &rectB, &result);
1442 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1443
1444 return TEST_COMPLETED;
1445 }
1446
1447 /* !
1448 * \brief Tests SDL_UnionRect() where rect B is inside rect A
1449 *
1450 * \sa
1451 * http://wiki.libsdl.org/SDL_UnionRect
1452 */
1453 int rect_testUnionRectInside(void *arg)
1454 {
1455 SDL_Rect refRectA, refRectB;
1456 SDL_Rect rectA, rectB;
1457 SDL_Rect expectedResult;
1458 SDL_Rect result;
1459 int dx, dy;
1460
1461 /* Union 1x1 with itself */
1462 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1463 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1464 refRectA.w = 1;
1465 refRectA.h = 1;
1466 expectedResult = refRectA;
1467 rectA = refRectA;
1468 SDL_UnionRect(&rectA, &rectA, &result);
1469 _validateUnionRectResults(&rectA, &rectA, &refRectA, &refRectA, &result, &expectedResult);
1470
1471 /* Union 1x1 somewhere inside */
1472 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1473 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1474 refRectA.w = SDLTest_RandomIntegerInRange(256, 1024);
1475 refRectA.h = SDLTest_RandomIntegerInRange(256, 1024);
1476 refRectB.x = refRectA.x + 1 + SDLTest_RandomIntegerInRange(1, refRectA.w - 2);
1477 refRectB.y = refRectA.y + 1 + SDLTest_RandomIntegerInRange(1, refRectA.h - 2);
1478 refRectB.w = 1;
1479 refRectB.h = 1;
1480 expectedResult = refRectA;
1481 rectA = refRectA;
1482 rectB = refRectB;
1483 SDL_UnionRect(&rectA, &rectB, &result);
1484 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1485
1486 /* Union inside with edges modified */
1487 for (dx = -1; dx < 2; dx++) {
1488 for (dy = -1; dy < 2; dy++) {
1489 if ((dx != 0) || (dy != 0)) {
1490 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1491 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1492 refRectA.w = SDLTest_RandomIntegerInRange(256, 1024);
1493 refRectA.h = SDLTest_RandomIntegerInRange(256, 1024);
1494 refRectB = refRectA;
1495 if (dx == -1) {
1496 refRectB.x++;
1497 }
1498 if ((dx == 1) || (dx == -1)) {
1499 refRectB.w--;
1500 }
1501 if (dy == -1) {
1502 refRectB.y++;
1503 }
1504 if ((dy == 1) || (dy == -1)) {
1505 refRectB.h--;
1506 }
1507 expectedResult = refRectA;
1508 rectA = refRectA;
1509 rectB = refRectB;
1510 SDL_UnionRect(&rectA, &rectB, &result);
1511 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1512 }
1513 }
1514 }
1515
1516 return TEST_COMPLETED;
1517 }
1518
1519 /* !
1520 * \brief Negative tests against SDL_UnionRect() with invalid parameters
1521 *
1522 * \sa
1523 * http://wiki.libsdl.org/SDL_UnionRect
1524 */
1525 int rect_testUnionRectParam(void *arg)
1526 {
1527 const SDL_Rect rectA = { 0, 0, 32, 32 };
1528 const SDL_Rect rectB = { 0, 0, 32, 32 };
1529 SDL_Rect result;
1530
1531 /* invalid parameter combinations */
1532 SDL_UnionRect((SDL_Rect *)NULL, &rectB, &result);
1533 SDLTest_AssertPass("Check that function returns when 1st parameter is NULL");
1534 SDL_UnionRect(&rectA, (SDL_Rect *)NULL, &result);
1535 SDLTest_AssertPass("Check that function returns when 2nd parameter is NULL");
1536 SDL_UnionRect(&rectA, &rectB, (SDL_Rect *)NULL);
1537 SDLTest_AssertPass("Check that function returns when 3rd parameter is NULL");
1538 SDL_UnionRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
1539 SDLTest_AssertPass("Check that function returns when 1st and 3rd parameter are NULL");
1540 SDL_UnionRect(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
1541 SDLTest_AssertPass("Check that function returns when 2nd and 3rd parameter are NULL");
1542 SDL_UnionRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
1543 SDLTest_AssertPass("Check that function returns when all parameters are NULL");
1544
1545 return TEST_COMPLETED;
1546 }
1547
1548 /* !
1549 * \brief Tests SDL_RectEmpty() with various inputs
1550 *
1551 * \sa
1552 * http://wiki.libsdl.org/SDL_RectEmpty
1553 */
1554 int rect_testRectEmpty(void *arg)
1555 {
1556 SDL_Rect refRect;
1557 SDL_Rect rect;
1558 SDL_bool expectedResult;
1559 SDL_bool result;
1560 int w, h;
1561
1562 /* Non-empty case */
1563 refRect.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1564 refRect.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1565 refRect.w = SDLTest_RandomIntegerInRange(256, 1024);
1566 refRect.h = SDLTest_RandomIntegerInRange(256, 1024);
1567 expectedResult = SDL_FALSE;
1568 rect = refRect;
1569 result = SDL_RectEmpty(&rect);
1570 _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
1571
1572 /* Empty case */
1573 for (w = -1; w < 2; w++) {
1574 for (h = -1; h < 2; h++) {
1575 if ((w != 1) || (h != 1)) {
1576 refRect.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1577 refRect.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1578 refRect.w = w;
1579 refRect.h = h;
1580 expectedResult = SDL_TRUE;
1581 rect = refRect;
1582 result = SDL_RectEmpty(&rect);
1583 _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
1584 }
1585 }
1586 }
1587
1588 return TEST_COMPLETED;
1589 }
1590
1591 /* !
1592 * \brief Negative tests against SDL_RectEmpty() with invalid parameters
1593 *
1594 * \sa
1595 * http://wiki.libsdl.org/SDL_RectEmpty
1596 */
1597 int rect_testRectEmptyParam(void *arg)
1598 {
1599 SDL_bool result;
1600
1601 /* invalid parameter combinations */
1602 result = SDL_RectEmpty(NULL);
1603 SDLTest_AssertCheck(result == SDL_TRUE, "Check that function returns TRUE when 1st parameter is NULL");
1604
1605 return TEST_COMPLETED;
1606 }
1607
1608 /* !
1609 * \brief Tests SDL_RectEquals() with various inputs
1610 *
1611 * \sa
1612 * http://wiki.libsdl.org/SDL_RectEquals
1613 */
1614 int rect_testRectEquals(void *arg)
1615 {
1616 SDL_Rect refRectA;
1617 SDL_Rect refRectB;
1618 SDL_Rect rectA;
1619 SDL_Rect rectB;
1620 SDL_bool expectedResult;
1621 SDL_bool result;
1622
1623 /* Equals */
1624 refRectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1625 refRectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1626 refRectA.w = SDLTest_RandomIntegerInRange(1, 1024);
1627 refRectA.h = SDLTest_RandomIntegerInRange(1, 1024);
1628 refRectB = refRectA;
1629 expectedResult = SDL_TRUE;
1630 rectA = refRectA;
1631 rectB = refRectB;
1632 result = SDL_RectEquals(&rectA, &rectB);
1633 _validateRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
1634
1635 return TEST_COMPLETED;
1636 }
1637
1638 /* !
1639 * \brief Negative tests against SDL_RectEquals() with invalid parameters
1640 *
1641 * \sa
1642 * http://wiki.libsdl.org/SDL_RectEquals
1643 */
1644 int rect_testRectEqualsParam(void *arg)
1645 {
1646 SDL_Rect rectA;
1647 SDL_Rect rectB;
1648 SDL_bool result;
1649
1650 /* data setup */
1651 rectA.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1652 rectA.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1653 rectA.w = SDLTest_RandomIntegerInRange(1, 1024);
1654 rectA.h = SDLTest_RandomIntegerInRange(1, 1024);
1655 rectB.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1656 rectB.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1657 rectB.w = SDLTest_RandomIntegerInRange(1, 1024);
1658 rectB.h = SDLTest_RandomIntegerInRange(1, 1024);
1659
1660 /* invalid parameter combinations */
1661 result = SDL_RectEquals(NULL, &rectB);
1662 SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
1663 result = SDL_RectEquals(&rectA, NULL);
1664 SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
1665 result = SDL_RectEquals(NULL, NULL);
1666 SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
1667
1668 return TEST_COMPLETED;
1669 }
1670
1671 /* !
1672 * \brief Tests SDL_FRectEquals() with various inputs
1673 *
1674 * \sa
1675 * http://wiki.libsdl.org/SDL_FRectEquals
1676 */
1677 int rect_testFRectEquals(void *arg)
1678 {
1679 SDL_FRect refRectA;
1680 SDL_FRect refRectB;
1681 SDL_FRect rectA;
1682 SDL_FRect rectB;
1683 SDL_bool expectedResult;
1684 SDL_bool result;
1685
1686 /* Equals */
1687 refRectA.x = (float)SDLTest_RandomIntegerInRange(-1024, 1024);
1688 refRectA.y = (float)SDLTest_RandomIntegerInRange(-1024, 1024);
1689 refRectA.w = (float)SDLTest_RandomIntegerInRange(1, 1024);
1690 refRectA.h = (float)SDLTest_RandomIntegerInRange(1, 1024);
1691 refRectB = refRectA;
1692 expectedResult = SDL_TRUE;
1693 rectA = refRectA;
1694 rectB = refRectB;
1695 result = SDL_FRectEquals(&rectA, &rectB);
1696 _validateFRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
1697
1698 return TEST_COMPLETED;
1699 }
1700
1701 /* !
1702 * \brief Negative tests against SDL_FRectEquals() with invalid parameters
1703 *
1704 * \sa
1705 * http://wiki.libsdl.org/SDL_FRectEquals
1706 */
1707 int rect_testFRectEqualsParam(void *arg)
1708 {
1709 SDL_FRect rectA;
1710 SDL_FRect rectB;
1711 SDL_bool result;
1712
1713 /* data setup -- For the purpose of this test, the values don't matter. */
1714 rectA.x = SDLTest_RandomFloat();
1715 rectA.y = SDLTest_RandomFloat();
1716 rectA.w = SDLTest_RandomFloat();
1717 rectA.h = SDLTest_RandomFloat();
1718 rectB.x = SDLTest_RandomFloat();
1719 rectB.y = SDLTest_RandomFloat();
1720 rectB.w = SDLTest_RandomFloat();
1721 rectB.h = SDLTest_RandomFloat();
1722
1723 /* invalid parameter combinations */
1724 result = SDL_FRectEquals(NULL, &rectB);
1725 SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
1726 result = SDL_FRectEquals(&rectA, NULL);
1727 SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
1728 result = SDL_FRectEquals(NULL, NULL);
1729 SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
1730
1731 return TEST_COMPLETED;
1732 }
1733
1734 /* !
1735 * \brief Test SDL_HasIntersectionF
1736 *
1737 * \sa
1738 * http://wiki.libsdl.org/SDL2/SDL_HasIntersectionF
1739 */
1740 int rect_testHasIntersectionF(void *arg)
1741 {
1742 const struct {
1743 SDL_FRect r1;
1744 SDL_FRect r2;
1745 SDL_bool expected;
1746 } cases[] = {
1747 { { 0, 0, 0, 0 }, {0, 0, 0, 0}, SDL_FALSE },
1748 { { 0, 0, -200, 200 }, {0, 0, -200, 200}, SDL_FALSE },
1749 { { 0, 0, 10, 10 }, {-5, 5, 10, 2}, SDL_TRUE },
1750 { { 0, 0, 10, 10 }, {-5, -5, 10, 2}, SDL_FALSE },
1751 { { 0, 0, 10, 10 }, {-5, -5, 2, 10}, SDL_FALSE },
1752 { { 0, 0, 10, 10 }, {-5, -5, 5, 5}, SDL_FALSE },
1753 { { 0, 0, 10, 10 }, {-5, -5, 5.1f, 5.1f}, SDL_TRUE },
1754 { { 0, 0, 10, 10 }, {-4.99f, -4.99f, 5, 5}, SDL_TRUE },
1755 };
1756 size_t i;
1757
1758 for (i = 0; i < SDL_arraysize(cases); i++) {
1759 SDL_bool result;
1760 SDLTest_AssertPass("About to call SDL_HasIntersectionF(&{ %g, %g, %g, %g }, &{ %g, %g, %g, %g })",
1761 cases[i].r1.x, cases[i].r1.y, cases[i].r1.w, cases[i].r1.h,
1762 cases[i].r2.x, cases[i].r2.y, cases[i].r2.w, cases[i].r2.h
1763 );
1764 result = SDL_HasIntersectionF(&cases[i].r1, &cases[i].r2);
1765 SDLTest_AssertCheck(result == cases[i].expected, "Got %d, expected %d", result, cases[i].expected);
1766 }
1767 return TEST_COMPLETED;
1768 }
1769
1770 /* !
1771 * \brief Test SDL_IntersectFRect
1772 *
1773 * \sa
1774 * http://wiki.libsdl.org/SDL2/SDL_IntersectFRect
1775 */
1776 int rect_testIntersectFRect(void *arg)
1777 {
1778 const struct {
1779 SDL_FRect r1;
1780 SDL_FRect r2;
1781 SDL_bool result;
1782 SDL_FRect intersect;
1783 } cases[] = {
1784 { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, SDL_FALSE },
1785 { { 0, 0, -200, 200 }, { 0, 0, -200, 200 }, SDL_FALSE },
1786 { { 0, 0, 10, 10 }, { -5, 5, 9.9f, 2 }, SDL_TRUE, { 0, 5, 4.9f, 2 } },
1787 { { 0, 0, 10, 10 }, { -5, -5, 10, 2 }, SDL_FALSE},
1788 { { 0, 0, 10, 10 }, { -5, -5, 2, 10 }, SDL_FALSE},
1789 { { 0, 0, 10, 10 }, { -5, -5, 5, 5 }, SDL_FALSE},
1790 { { 0, 0, 10, 10 }, { -5, -5, 5.5f, 6 }, SDL_TRUE, { 0, 0, 0.5f, 1 } }
1791 };
1792 size_t i;
1793
1794 for (i = 0; i < SDL_arraysize(cases); i++) {
1795 SDL_bool result;
1796 SDL_FRect intersect;
1797 SDLTest_AssertPass("About to call SDL_IntersectFRect(&{ %g, %g, %g, %g }, &{ %g, %g, %g, %g })",
1798 cases[i].r1.x, cases[i].r1.y, cases[i].r1.w, cases[i].r1.h,
1799 cases[i].r2.x, cases[i].r2.y, cases[i].r2.w, cases[i].r2.h
1800 );
1801 result = SDL_IntersectFRect(&cases[i].r1, &cases[i].r2, &intersect);
1802 SDLTest_AssertCheck(result == cases[i].result, "Got %d, expected %d", result, cases[i].result);
1803 if (cases[i].result) {
1804 SDLTest_AssertCheck(IsFRectEqual(&intersect, &cases[i].intersect),
1805 "Got { %g, %g, %g, %g }, expected { %g, %g, %g, %g }",
1806 intersect.x, intersect.y, intersect.w, intersect.h,
1807 cases[i].intersect.x, cases[i].intersect.y, cases[i].intersect.w, cases[i].intersect.h);
1808 }
1809 }
1810 return TEST_COMPLETED;
1811 }
1812
1813 /* !
1814 * \brief Test SDL_UnionFRect
1815 *
1816 * \sa
1817 * http://wiki.libsdl.org/SDL2/SDL_UnionFRect
1818 */
1819 int rect_testUnionFRect(void *arg)
1820 {
1821 const struct {
1822 SDL_FRect r1;
1823 SDL_FRect r2;
1824 SDL_FRect expected;
1825 } cases[] = {
1826 { { 0, 0, 10, 10 }, { 19.9f, 20, 10, 10 }, { 0, 0, 29.9f, 30 } },
1827 { { 0, 0, 0, 0 }, { 20, 20.1f, 10.1f, 10 }, { 20, 20.1f, 10.1f, 10 } },
1828 { { -200, -4.5f, 450, 33 }, { 20, 20, 10, 10 }, { -200, -4.5f, 450, 34.5f } },
1829 { { 0, 0, 15, 16.5f }, { 20, 20, 0, 0 }, { 0, 0, 15, 16.5f } }
1830 };
1831 size_t i;
1832
1833 for (i = 0; i < SDL_arraysize(cases); i++) {
1834 SDL_FRect result;
1835 SDLTest_AssertPass("About to call SDL_UnionFRect(&{ %g, %g, %g, %g }, &{ %g, %g, %g, %g })",
1836 cases[i].r1.x, cases[i].r1.y, cases[i].r1.w, cases[i].r1.h,
1837 cases[i].r2.x, cases[i].r2.y, cases[i].r2.w, cases[i].r2.h
1838 );
1839 SDL_UnionFRect(&cases[i].r1, &cases[i].r2, &result);
1840 SDLTest_AssertCheck(IsFRectEqual(&result, &cases[i].expected),
1841 "Got { %g, %g, %g, %g }, expected { %g, %g, %g, %g }",
1842 result.x, result.y, result.w, result.h,
1843 cases[i].expected.x, cases[i].expected.y, cases[i].expected.w, cases[i].expected.h);
1844 }
1845 return TEST_COMPLETED;
1846 }
1847
1848 /* !
1849 * \brief Test SDL_EncloseFPointsUnionFRect
1850 *
1851 * \sa
1852 * http://wiki.libsdl.org/SDL2/SDL_EncloseFPoints
1853 */
1854 int rect_testEncloseFPoints(void *arg)
1855 {
1856 const struct {
1857 SDL_bool with_clip;
1858 SDL_FRect clip;
1859 SDL_bool result;
1860 SDL_FRect enclosing;
1861 } cases[] = {
1862 { SDL_TRUE, { 0, 0, 10, 10 }, SDL_TRUE, { 0.5f, 0.1f, 6, 8 }},
1863 { SDL_TRUE, { 1.2f, 1, 10, 10 }, SDL_TRUE, { 1.5f, 1.1f, 5, 7 }},
1864 { SDL_TRUE, { -10, -10, 3, 3 }, SDL_FALSE },
1865 { SDL_FALSE, { 0 }, SDL_TRUE, { 0.5, 0.1f, 6, 8 }}
1866 };
1867 const SDL_FPoint points[] = {
1868 { 0.5f, 0.1f },
1869 { 5.5f, 7.1f },
1870 { 1.5f, 1.1f }
1871 };
1872 char points_str[256];
1873 size_t i;
1874
1875 SDL_strlcpy(points_str, "{", sizeof(points_str));
1876 for (i = 0; i < SDL_arraysize(points); i++) {
1877 char point_str[32];
1878 SDL_snprintf(point_str, sizeof(point_str), "{ %g, %g }, ", points[i].x, points[i].y);
1879 SDL_strlcat(points_str, point_str, sizeof(points_str));
1880 }
1881 SDL_strlcat(points_str, "}", sizeof(points_str));
1882 for (i = 0; i < SDL_arraysize(cases); i++) {
1883 char clip_str[64];
1884 SDL_bool result;
1885 SDL_FRect enclosing;
1886 const SDL_FRect* clip_ptr = NULL;
1887 if (cases[i].with_clip) {
1888 SDL_snprintf(clip_str, sizeof(clip_str), "&{ %g, %g, %g, %g }",
1889 cases[i].clip.x, cases[i].clip.y, cases[i].clip.w, cases[i].clip.h);
1890 clip_ptr = &cases[i].clip;
1891 } else {
1892 SDL_strlcpy(clip_str, "NULL", sizeof(clip_str));
1893 }
1894 SDLTest_AssertPass("About to call SDL_EncloseFPoints(&%s, %d, %s)", points_str, (int)SDL_arraysize(points), clip_str);
1895 result = SDL_EncloseFPoints(points, SDL_arraysize(points), clip_ptr, &enclosing);
1896 SDLTest_AssertCheck(result == cases[i].result, "Got %d, expected %d", result, cases[i].result);
1897 if (cases[i].result) {
1898 SDLTest_AssertCheck(IsFRectEqual(&enclosing, &cases[i].enclosing),
1899 "Got { %g, %g, %g, %g }, expected { %g, %g, %g, %g }",
1900 enclosing.x, enclosing.y, enclosing.w, enclosing.h,
1901 cases[i].enclosing.x, cases[i].enclosing.y, cases[i].enclosing.w, cases[i].enclosing.h);
1902 }
1903 }
1904 return TEST_COMPLETED;
1905 }
1906
1907 /* !
1908 * \brief Test SDL_IntersectFRectAndLine
1909 *
1910 * \sa
1911 * http://wiki.libsdl.org/SDL2/SDL_IntersectFRectAndLine
1912 */
1913 int rect_testIntersectFRectAndLine(void *arg)
1914 {
1915 const struct {
1916 SDL_FRect rect;
1917 SDL_FPoint p1;
1918 SDL_FPoint p2;
1919 SDL_bool result;
1920 SDL_FPoint expected1;
1921 SDL_FPoint expected2;
1922 } cases[] = {
1923 { { 0, 0, 0, 0 }, { -4.8f, -4.8f }, { 5.2f, 5.2f }, SDL_FALSE },
1924 { { 0, 0, 2, 2 }, { -1, -1 }, { 3.5f, 3.5f }, SDL_TRUE, { 0, 0 }, { 1, 1 } },
1925 { { -4, -4, 14, 14 }, { 8, 22 }, { 8, 33}, SDL_FALSE }
1926
1927 };
1928 size_t i;
1929
1930 for (i = 0; i < SDL_arraysize(cases); i++) {
1931 SDL_bool result;
1932 SDL_FPoint p1 = cases[i].p1;
1933 SDL_FPoint p2 = cases[i].p2;
1934
1935 SDLTest_AssertPass("About to call SDL_IntersectFRectAndLine(&{%g, %g, %g, %g}, &%g, &%g, &%g, &%g)",
1936 cases[i].rect.x, cases[i].rect.y, cases[i].rect.w, cases[i].rect.h,
1937 p1.x, p1.y, p2.x, p2.y);
1938 result = SDL_IntersectFRectAndLine(&cases[i].rect, &p1.x, &p1.y, &p2.x, &p2.y);
1939 SDLTest_AssertCheck(result == cases[i].result, "Got %d, expected %d", result, cases[i].result);
1940 if (cases[i].result) {
1941 SDLTest_AssertCheck(IsFPointEqual(&p1, &cases[i].expected1),
1942 "Got p1={ %g, %g }, expected p1={ %g, %g }",
1943 p1.x, p1.y,
1944 cases[i].expected1.x, cases[i].expected1.y);
1945 SDLTest_AssertCheck(IsFPointEqual(&p2, &cases[i].expected2),
1946 "Got p2={ %g, %g }, expected p2={ %g, %g }",
1947 p2.x, p2.y,
1948 cases[i].expected2.x, cases[i].expected2.y);
1949 }
1950 }
1951 return TEST_COMPLETED;
1952 }
1953
1954 /* ================= Test References ================== */
1955
1956 /* Rect test cases */
1957
1958 /* SDL_IntersectRectAndLine */
1959 static const SDLTest_TestCaseReference rectTest1 = {
1960 (SDLTest_TestCaseFp)rect_testIntersectRectAndLine, "rect_testIntersectRectAndLine", "Tests SDL_IntersectRectAndLine clipping cases", TEST_ENABLED
1961 };
1962
1963 static const SDLTest_TestCaseReference rectTest2 = {
1964 (SDLTest_TestCaseFp)rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED
1965 };
1966
1967 static const SDLTest_TestCaseReference rectTest3 = {
1968 (SDLTest_TestCaseFp)rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_IntersectRectAndLine with line fully outside of rect", TEST_ENABLED
1969 };
1970
1971 static const SDLTest_TestCaseReference rectTest4 = {
1972 (SDLTest_TestCaseFp)rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_IntersectRectAndLine with empty rectangle ", TEST_ENABLED
1973 };
1974
1975 static const SDLTest_TestCaseReference rectTest5 = {
1976 (SDLTest_TestCaseFp)rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_IntersectRectAndLine with invalid parameters", TEST_ENABLED
1977 };
1978
1979 /* SDL_IntersectRect */
1980 static const SDLTest_TestCaseReference rectTest6 = {
1981 (SDLTest_TestCaseFp)rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED
1982 };
1983
1984 static const SDLTest_TestCaseReference rectTest7 = {
1985 (SDLTest_TestCaseFp)rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED
1986 };
1987
1988 static const SDLTest_TestCaseReference rectTest8 = {
1989 (SDLTest_TestCaseFp)rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED
1990 };
1991
1992 static const SDLTest_TestCaseReference rectTest9 = {
1993 (SDLTest_TestCaseFp)rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED
1994 };
1995
1996 static const SDLTest_TestCaseReference rectTest10 = {
1997 (SDLTest_TestCaseFp)rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_IntersectRect with empty rectangles", TEST_ENABLED
1998 };
1999
2000 static const SDLTest_TestCaseReference rectTest11 = {
2001 (SDLTest_TestCaseFp)rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_IntersectRect with invalid parameters", TEST_ENABLED
2002 };
2003
2004 /* SDL_HasIntersection */
2005 static const SDLTest_TestCaseReference rectTest12 = {
2006 (SDLTest_TestCaseFp)rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasIntersection with B fully contained in A", TEST_ENABLED
2007 };
2008
2009 static const SDLTest_TestCaseReference rectTest13 = {
2010 (SDLTest_TestCaseFp)rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasIntersection with B fully outside of A", TEST_ENABLED
2011 };
2012
2013 static const SDLTest_TestCaseReference rectTest14 = {
2014 (SDLTest_TestCaseFp)rect_testHasIntersectionPartial, "rect_testHasIntersectionPartial", "Tests SDL_HasIntersection with B partially intersecting A", TEST_ENABLED
2015 };
2016
2017 static const SDLTest_TestCaseReference rectTest15 = {
2018 (SDLTest_TestCaseFp)rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasIntersection with 1x1 sized rectangles", TEST_ENABLED
2019 };
2020
2021 static const SDLTest_TestCaseReference rectTest16 = {
2022 (SDLTest_TestCaseFp)rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasIntersection with empty rectangles", TEST_ENABLED
2023 };
2024
2025 static const SDLTest_TestCaseReference rectTest17 = {
2026 (SDLTest_TestCaseFp)rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED
2027 };
2028
2029 /* SDL_EnclosePoints */
2030 static const SDLTest_TestCaseReference rectTest18 = {
2031 (SDLTest_TestCaseFp)rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED
2032 };
2033
2034 static const SDLTest_TestCaseReference rectTest19 = {
2035 (SDLTest_TestCaseFp)rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED
2036 };
2037
2038 static const SDLTest_TestCaseReference rectTest20 = {
2039 (SDLTest_TestCaseFp)rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED
2040 };
2041
2042 static const SDLTest_TestCaseReference rectTest21 = {
2043 (SDLTest_TestCaseFp)rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED
2044 };
2045
2046 /* SDL_UnionRect */
2047 static const SDLTest_TestCaseReference rectTest22 = {
2048 (SDLTest_TestCaseFp)rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_UnionRect where rect B is inside rect A", TEST_ENABLED
2049 };
2050
2051 static const SDLTest_TestCaseReference rectTest23 = {
2052 (SDLTest_TestCaseFp)rect_testUnionRectOutside, "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED
2053 };
2054
2055 static const SDLTest_TestCaseReference rectTest24 = {
2056 (SDLTest_TestCaseFp)rect_testUnionRectEmpty, "rect_testUnionRectEmpty", "Tests SDL_UnionRect where rect A or rect B are empty", TEST_ENABLED
2057 };
2058
2059 static const SDLTest_TestCaseReference rectTest25 = {
2060 (SDLTest_TestCaseFp)rect_testUnionRectParam, "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED
2061 };
2062
2063 /* SDL_RectEmpty */
2064 static const SDLTest_TestCaseReference rectTest26 = {
2065 (SDLTest_TestCaseFp)rect_testRectEmpty, "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED
2066 };
2067
2068 static const SDLTest_TestCaseReference rectTest27 = {
2069 (SDLTest_TestCaseFp)rect_testRectEmptyParam, "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED
2070 };
2071
2072 /* SDL_RectEquals */
2073
2074 static const SDLTest_TestCaseReference rectTest28 = {
2075 (SDLTest_TestCaseFp)rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectEquals with various inputs", TEST_ENABLED
2076 };
2077
2078 static const SDLTest_TestCaseReference rectTest29 = {
2079 (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED
2080 };
2081
2082 /* SDL_FRectEquals */
2083
2084 static const SDLTest_TestCaseReference rectTest30 = {
2085 (SDLTest_TestCaseFp)rect_testFRectEquals, "rect_testFRectEquals", "Tests SDL_FRectEquals with various inputs", TEST_ENABLED
2086 };
2087
2088 static const SDLTest_TestCaseReference rectTest31 = {
2089 (SDLTest_TestCaseFp)rect_testFRectEqualsParam, "rect_testFRectEqualsParam", "Negative tests against SDL_FRectEquals with invalid parameters", TEST_ENABLED
2090 };
2091
2092 static const SDLTest_TestCaseReference rectTest32 = {
2093 (SDLTest_TestCaseFp)rect_testHasIntersectionF, "rect_testHasIntersectionF", "Tests SDL_HasIntersectionF", TEST_ENABLED
2094 };
2095
2096 static const SDLTest_TestCaseReference rectTest33 = {
2097 (SDLTest_TestCaseFp)rect_testIntersectFRect, "rect_testIntersectFRect", "Tests SDL_IntersectFRect", TEST_ENABLED
2098 };
2099
2100 static const SDLTest_TestCaseReference rectTest34 = {
2101 (SDLTest_TestCaseFp)rect_testUnionFRect, "rect_testUnionFRect", "Tests SDL_UnionFRect", TEST_ENABLED
2102 };
2103
2104 static const SDLTest_TestCaseReference rectTest35 = {
2105 (SDLTest_TestCaseFp)rect_testEncloseFPoints, "rect_testEncloseFPoints", "Tests SDL_EncloseFPoints", TEST_ENABLED
2106 };
2107
2108 static const SDLTest_TestCaseReference rectTest36 = {
2109 (SDLTest_TestCaseFp)rect_testIntersectFRectAndLine, "rect_testIntersectFRectAndLine", "Tests SDL_IntersectFRectAndLine", TEST_ENABLED
2110 };
2111
2112 /* !
2113 * \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
2114 *
2115 * \sa
2116 * http://wiki.libsdl.org/CategoryRect
2117 */
2118 static const SDLTest_TestCaseReference *rectTests[] = {
2119 &rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14,
2120 &rectTest15, &rectTest16, &rectTest17, &rectTest18, &rectTest19, &rectTest20, &rectTest21, &rectTest22, &rectTest23, &rectTest24, &rectTest25, &rectTest26, &rectTest27,
2121 &rectTest28, &rectTest29, &rectTest30, &rectTest31, &rectTest32, &rectTest33, &rectTest34, &rectTest35, &rectTest36, NULL
2122 };
2123
2124 /* Rect test suite (global) */
2125 SDLTest_TestSuiteReference rectTestSuite = {
2126 "Rect",
2127 NULL,
2128 rectTests,
2129 NULL
2130 };