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