SDL  2.0
testautomation_rect.c
Go to the documentation of this file.
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_IntersectRectAndLine results
17  */
19  SDL_bool intersection, SDL_bool expectedIntersection,
20  SDL_Rect *rect, SDL_Rect * refRect,
21  int x1, int y1, int x2, int y2,
22  int x1Ref, int y1Ref, int x2Ref, int y2Ref)
23 {
24  SDLTest_AssertCheck(intersection == expectedIntersection,
25  "Check for correct intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)",
26  (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
27  (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
28  refRect->x, refRect->y, refRect->w, refRect->h,
29  x1Ref, y1Ref, x2Ref, y2Ref);
30  SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
31  "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
32  rect->x, rect->y, rect->w, rect->h,
33  refRect->x, refRect->y, refRect->w, refRect->h);
34  SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
35  "Check if line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
36  x1, y1, x2, y2,
37  x1Ref, y1Ref, x2Ref, y2Ref);
38 }
39 
40 /* Test case functions */
41 
42 /* !
43  * \brief Tests SDL_IntersectRectAndLine() clipping cases
44  *
45  * \sa
46  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
47  */
48 int
50 {
51  SDL_Rect refRect = { 0, 0, 32, 32 };
52  SDL_Rect rect;
53  int x1, y1;
54  int x2, y2;
55  SDL_bool intersected;
56 
57  int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
58  int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
59  int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
60  int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
61 
62  x1 = xLeft;
63  y1 = 15;
64  x2 = xRight;
65  y2 = 15;
66  rect = refRect;
67  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
68  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 15, 31, 15);
69 
70  x1 = 15;
71  y1 = yTop;
72  x2 = 15;
73  y2 = yBottom;
74  rect = refRect;
75  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
76  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 15, 0, 15, 31);
77 
78  x1 = -refRect.w;
79  y1 = -refRect.h;
80  x2 = 2*refRect.w;
81  y2 = 2*refRect.h;
82  rect = refRect;
83  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
84  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 0, 31, 31);
85 
86  x1 = 2*refRect.w;
87  y1 = 2*refRect.h;
88  x2 = -refRect.w;
89  y2 = -refRect.h;
90  rect = refRect;
91  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
92  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 31, 0, 0);
93 
94  x1 = -1;
95  y1 = 32;
96  x2 = 32;
97  y2 = -1;
98  rect = refRect;
99  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
100  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 31, 31, 0);
101 
102  x1 = 32;
103  y1 = -1;
104  x2 = -1;
105  y2 = 32;
106  rect = refRect;
107  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
108  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31);
109 
110  return TEST_COMPLETED;
111 }
112 
113 /* !
114  * \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
115  *
116  * \sa
117  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
118  */
119 int
121 {
122  SDL_Rect refRect = { 0, 0, 32, 32 };
123  SDL_Rect rect;
124  int x1, y1;
125  int x2, y2;
126  SDL_bool intersected;
127 
128  int xmin = refRect.x;
129  int xmax = refRect.x + refRect.w - 1;
130  int ymin = refRect.y;
131  int ymax = refRect.y + refRect.h - 1;
132  int x1Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
133  int y1Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
134  int x2Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
135  int y2Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
136 
137  x1 = x1Ref;
138  y1 = y1Ref;
139  x2 = x2Ref;
140  y2 = y2Ref;
141  rect = refRect;
142  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
143  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
144 
145  x1 = x1Ref;
146  y1 = y1Ref;
147  x2 = xmax;
148  y2 = ymax;
149  rect = refRect;
150  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
151  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, xmax, ymax);
152 
153  x1 = xmin;
154  y1 = ymin;
155  x2 = x2Ref;
156  y2 = y2Ref;
157  rect = refRect;
158  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
159  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, x2Ref, y2Ref);
160 
161  x1 = xmin;
162  y1 = ymin;
163  x2 = xmax;
164  y2 = ymax;
165  rect = refRect;
166  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
167  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, xmax, ymax);
168 
169  x1 = xmin;
170  y1 = ymax;
171  x2 = xmax;
172  y2 = ymin;
173  rect = refRect;
174  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
175  _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymax, xmax, ymin);
176 
177  return TEST_COMPLETED;
178 }
179 
180 /* !
181  * \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
182  *
183  * \sa
184  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
185  */
186 int
188 {
189  SDL_Rect refRect = { 0, 0, 32, 32 };
190  SDL_Rect rect;
191  int x1, y1;
192  int x2, y2;
193  SDL_bool intersected;
194 
195  int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
196  int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
197  int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
198  int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
199 
200  x1 = xLeft;
201  y1 = 0;
202  x2 = xLeft;
203  y2 = 31;
204  rect = refRect;
205  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
206  _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xLeft, 0, xLeft, 31);
207 
208  x1 = xRight;
209  y1 = 0;
210  x2 = xRight;
211  y2 = 31;
212  rect = refRect;
213  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
214  _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xRight, 0, xRight, 31);
215 
216  x1 = 0;
217  y1 = yTop;
218  x2 = 31;
219  y2 = yTop;
220  rect = refRect;
221  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
222  _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yTop, 31, yTop);
223 
224  x1 = 0;
225  y1 = yBottom;
226  x2 = 31;
227  y2 = yBottom;
228  rect = refRect;
229  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
230  _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yBottom, 31, yBottom);
231 
232  return TEST_COMPLETED;
233 }
234 
235 /* !
236  * \brief Tests SDL_IntersectRectAndLine() with empty rectangle
237  *
238  * \sa
239  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
240  */
241 int
243 {
244  SDL_Rect refRect;
245  SDL_Rect rect;
246  int x1, y1, x1Ref, y1Ref;
247  int x2, y2, x2Ref, y2Ref;
248  SDL_bool intersected;
249 
250  refRect.x = SDLTest_RandomIntegerInRange(1, 1024);
251  refRect.y = SDLTest_RandomIntegerInRange(1, 1024);
252  refRect.w = 0;
253  refRect.h = 0;
254  x1Ref = refRect.x;
255  y1Ref = refRect.y;
256  x2Ref = SDLTest_RandomIntegerInRange(1, 1024);
257  y2Ref = SDLTest_RandomIntegerInRange(1, 1024);
258 
259  x1 = x1Ref;
260  y1 = y1Ref;
261  x2 = x2Ref;
262  y2 = y2Ref;
263  rect = refRect;
264  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
265  _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
266 
267  return TEST_COMPLETED;
268 }
269 
270 /* !
271  * \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
272  *
273  * \sa
274  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
275  */
276 int
278 {
279  SDL_Rect rect = { 0, 0, 32, 32 };
280  int x1 = rect.w / 2;
281  int y1 = rect.h / 2;
282  int x2 = x1;
283  int y2 = 2 * rect.h;
284  SDL_bool intersected;
285 
286  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
287  SDLTest_AssertCheck(intersected == SDL_TRUE, "Check that intersection result was SDL_TRUE");
288 
289  intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, &x1, &y1, &x2, &y2);
290  SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
291  intersected = SDL_IntersectRectAndLine(&rect, (int *)NULL, &y1, &x2, &y2);
292  SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
293  intersected = SDL_IntersectRectAndLine(&rect, &x1, (int *)NULL, &x2, &y2);
294  SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 3rd parameter is NULL");
295  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, (int *)NULL, &y2);
296  SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 4th parameter is NULL");
297  intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, (int *)NULL);
298  SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 5th parameter is NULL");
299  intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
300  SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
301 
302  return TEST_COMPLETED;
303 }
304 
305 /* !
306  * \brief Private helper to check SDL_HasIntersection results
307  */
309  SDL_bool intersection, SDL_bool expectedIntersection,
310  SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
311 {
312  SDLTest_AssertCheck(intersection == expectedIntersection,
313  "Check intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)",
314  (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
315  (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
316  rectA->x, rectA->y, rectA->w, rectA->h,
317  rectB->x, rectB->y, rectB->w, rectB->h);
318  SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
319  "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
320  rectA->x, rectA->y, rectA->w, rectA->h,
321  refRectA->x, refRectA->y, refRectA->w, refRectA->h);
322  SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
323  "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
324  rectB->x, rectB->y, rectB->w, rectB->h,
325  refRectB->x, refRectB->y, refRectB->w, refRectB->h);
326 }
327 
328 /* !
329  * \brief Private helper to check SDL_IntersectRect results
330  */
332  SDL_bool intersection, SDL_bool expectedIntersection,
333  SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
334  SDL_Rect *result, SDL_Rect *expectedResult)
335 {
336  _validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB);
337  if (result && expectedResult) {
338  SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
339  "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)",
340  rectA->x, rectA->y, rectA->w, rectA->h,
341  rectB->x, rectB->y, rectB->w, rectB->h,
342  result->x, result->y, result->w, result->h,
343  expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
344  }
345 }
346 
347 /* !
348  * \brief Private helper to check SDL_UnionRect results
349  */
351  SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
352  SDL_Rect *result, SDL_Rect *expectedResult)
353 {
354  SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
355  "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
356  rectA->x, rectA->y, rectA->w, rectA->h,
357  refRectA->x, refRectA->y, refRectA->w, refRectA->h);
358  SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
359  "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
360  rectB->x, rectB->y, rectB->w, rectB->h,
361  refRectB->x, refRectB->y, refRectB->w, refRectB->h);
362  SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
363  "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)",
364  rectA->x, rectA->y, rectA->w, rectA->h,
365  rectB->x, rectB->y, rectB->w, rectB->h,
366  result->x, result->y, result->w, result->h,
367  expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
368 }
369 
370 /* !
371  * \brief Private helper to check SDL_RectEmpty results
372  */
374  SDL_bool empty, SDL_bool expectedEmpty,
375  SDL_Rect *rect, SDL_Rect *refRect)
376 {
377  SDLTest_AssertCheck(empty == expectedEmpty,
378  "Check for correct empty result: expected %s, got %s testing (%d,%d,%d,%d)",
379  (expectedEmpty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
380  (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
381  rect->x, rect->y, rect->w, rect->h);
382  SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
383  "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
384  rect->x, rect->y, rect->w, rect->h,
385  refRect->x, refRect->y, refRect->w, refRect->h);
386 }
387 
388 /* !
389  * \brief Private helper to check SDL_RectEquals results
390  */
392  SDL_bool equals, SDL_bool expectedEquals,
393  SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
394 {
395  SDLTest_AssertCheck(equals == expectedEquals,
396  "Check for correct equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d)",
397  (expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
398  (equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
399  rectA->x, rectA->y, rectA->w, rectA->h,
400  rectB->x, rectB->y, rectB->w, rectB->h);
401  SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
402  "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
403  rectA->x, rectA->y, rectA->w, rectA->h,
404  refRectA->x, refRectA->y, refRectA->w, refRectA->h);
405  SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
406  "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
407  rectB->x, rectB->y, rectB->w, rectB->h,
408  refRectB->x, refRectB->y, refRectB->w, refRectB->h);
409 }
410 
411 /* !
412  * \brief Tests SDL_IntersectRect() with B fully inside A
413  *
414  * \sa
415  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
416  */
418 {
419  SDL_Rect refRectA = { 0, 0, 32, 32 };
420  SDL_Rect refRectB;
421  SDL_Rect rectA;
422  SDL_Rect rectB;
424  SDL_bool intersection;
425 
426  /* rectB fully contained in rectA */
427  refRectB.x = 0;
428  refRectB.y = 0;
429  refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
430  refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
431  rectA = refRectA;
432  rectB = refRectB;
433  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
434  _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB);
435 
436  return TEST_COMPLETED;
437 }
438 
439 /* !
440  * \brief Tests SDL_IntersectRect() with B fully outside A
441  *
442  * \sa
443  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
444  */
446 {
447  SDL_Rect refRectA = { 0, 0, 32, 32 };
448  SDL_Rect refRectB;
449  SDL_Rect rectA;
450  SDL_Rect rectB;
452  SDL_bool intersection;
453 
454  /* rectB fully outside of rectA */
455  refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
456  refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
457  refRectB.w = refRectA.w;
458  refRectB.h = refRectA.h;
459  rectA = refRectA;
460  rectB = refRectB;
461  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
462  _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
463 
464  return TEST_COMPLETED;
465 }
466 
467 /* !
468  * \brief Tests SDL_IntersectRect() with B partially intersecting A
469  *
470  * \sa
471  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
472  */
474 {
475  SDL_Rect refRectA = { 0, 0, 32, 32 };
476  SDL_Rect refRectB;
477  SDL_Rect rectA;
478  SDL_Rect rectB;
480  SDL_Rect expectedResult;
481  SDL_bool intersection;
482 
483  /* rectB partially contained in rectA */
484  refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
485  refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
486  refRectB.w = refRectA.w;
487  refRectB.h = refRectA.h;
488  rectA = refRectA;
489  rectB = refRectB;
490  expectedResult.x = refRectB.x;
491  expectedResult.y = refRectB.y;
492  expectedResult.w = refRectA.w - refRectB.x;
493  expectedResult.h = refRectA.h - refRectB.y;
494  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
495  _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
496 
497  /* rectB right edge */
498  refRectB.x = rectA.w - 1;
499  refRectB.y = rectA.y;
500  refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
501  refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
502  rectA = refRectA;
503  rectB = refRectB;
504  expectedResult.x = refRectB.x;
505  expectedResult.y = refRectB.y;
506  expectedResult.w = 1;
507  expectedResult.h = refRectB.h;
508  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
509  _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
510 
511  /* rectB left edge */
512  refRectB.x = 1 - rectA.w;
513  refRectB.y = rectA.y;
514  refRectB.w = refRectA.w;
515  refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
516  rectA = refRectA;
517  rectB = refRectB;
518  expectedResult.x = 0;
519  expectedResult.y = refRectB.y;
520  expectedResult.w = 1;
521  expectedResult.h = refRectB.h;
522  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
523  _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
524 
525  /* rectB bottom edge */
526  refRectB.x = rectA.x;
527  refRectB.y = rectA.h - 1;
528  refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
529  refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
530  rectA = refRectA;
531  rectB = refRectB;
532  expectedResult.x = refRectB.x;
533  expectedResult.y = refRectB.y;
534  expectedResult.w = refRectB.w;
535  expectedResult.h = 1;
536  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
537  _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
538 
539  /* rectB top edge */
540  refRectB.x = rectA.x;
541  refRectB.y = 1 - rectA.h;
542  refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
543  refRectB.h = rectA.h;
544  rectA = refRectA;
545  rectB = refRectB;
546  expectedResult.x = refRectB.x;
547  expectedResult.y = 0;
548  expectedResult.w = refRectB.w;
549  expectedResult.h = 1;
550  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
551  _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
552 
553  return TEST_COMPLETED;
554 }
555 
556 /* !
557  * \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
558  *
559  * \sa
560  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
561  */
563 {
564  SDL_Rect refRectA = { 0, 0, 1, 1 };
565  SDL_Rect refRectB = { 0, 0, 1, 1 };
566  SDL_Rect rectA;
567  SDL_Rect rectB;
569  SDL_bool intersection;
570  int offsetX, offsetY;
571 
572  /* intersecting pixels */
573  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
574  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
575  refRectB.x = refRectA.x;
576  refRectB.y = refRectA.y;
577  rectA = refRectA;
578  rectB = refRectB;
579  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
580  _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA);
581 
582  /* non-intersecting pixels cases */
583  for (offsetX = -1; offsetX <= 1; offsetX++) {
584  for (offsetY = -1; offsetY <= 1; offsetY++) {
585  if (offsetX != 0 || offsetY != 0) {
586  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
587  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
588  refRectB.x = refRectA.x;
589  refRectB.y = refRectA.y;
590  refRectB.x += offsetX;
591  refRectB.y += offsetY;
592  rectA = refRectA;
593  rectB = refRectB;
594  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
595  _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
596  }
597  }
598  }
599 
600  return TEST_COMPLETED;
601 }
602 
603 /* !
604  * \brief Tests SDL_IntersectRect() with empty rectangles
605  *
606  * \sa
607  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
608  */
610 {
611  SDL_Rect refRectA;
612  SDL_Rect refRectB;
613  SDL_Rect rectA;
614  SDL_Rect rectB;
616  SDL_bool intersection;
617  SDL_bool empty;
618 
619  /* Rect A empty */
620  result.w = SDLTest_RandomIntegerInRange(1, 100);
621  result.h = SDLTest_RandomIntegerInRange(1, 100);
622  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
623  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
624  refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
625  refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
626  refRectB = refRectA;
627  refRectA.w = 0;
628  refRectA.h = 0;
629  rectA = refRectA;
630  rectB = refRectB;
631  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
632  _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
633  empty = (SDL_bool)SDL_RectEmpty(&result);
634  SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
635 
636  /* Rect B empty */
637  result.w = SDLTest_RandomIntegerInRange(1, 100);
638  result.h = SDLTest_RandomIntegerInRange(1, 100);
639  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
640  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
641  refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
642  refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
643  refRectB = refRectA;
644  refRectB.w = 0;
645  refRectB.h = 0;
646  rectA = refRectA;
647  rectB = refRectB;
648  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
649  _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
650  empty = (SDL_bool)SDL_RectEmpty(&result);
651  SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
652 
653  /* Rect A and B empty */
654  result.w = SDLTest_RandomIntegerInRange(1, 100);
655  result.h = SDLTest_RandomIntegerInRange(1, 100);
656  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
657  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
658  refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
659  refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
660  refRectB = refRectA;
661  refRectA.w = 0;
662  refRectA.h = 0;
663  refRectB.w = 0;
664  refRectB.h = 0;
665  rectA = refRectA;
666  rectB = refRectB;
667  intersection = SDL_IntersectRect(&rectA, &rectB, &result);
668  _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
669  empty = (SDL_bool)SDL_RectEmpty(&result);
670  SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
671 
672  return TEST_COMPLETED;
673 }
674 
675 /* !
676  * \brief Negative tests against SDL_IntersectRect() with invalid parameters
677  *
678  * \sa
679  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
680  */
682 {
683  SDL_Rect rectA;
684  SDL_Rect rectB;
686  SDL_bool intersection;
687 
688  /* invalid parameter combinations */
689  intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, &result);
690  SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
691  intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
692  SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
693  intersection = SDL_IntersectRect(&rectA, &rectB, (SDL_Rect *)NULL);
694  SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 3st parameter is NULL");
695  intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
696  SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameters are NULL");
697  intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
698  SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 3rd parameters are NULL ");
699  intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
700  SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
701 
702  return TEST_COMPLETED;
703 }
704 
705 /* !
706  * \brief Tests SDL_HasIntersection() with B fully inside A
707  *
708  * \sa
709  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
710  */
712 {
713  SDL_Rect refRectA = { 0, 0, 32, 32 };
714  SDL_Rect refRectB;
715  SDL_Rect rectA;
716  SDL_Rect rectB;
717  SDL_bool intersection;
718 
719  /* rectB fully contained in rectA */
720  refRectB.x = 0;
721  refRectB.y = 0;
722  refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
723  refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
724  rectA = refRectA;
725  rectB = refRectB;
726  intersection = SDL_HasIntersection(&rectA, &rectB);
727  _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
728 
729  return TEST_COMPLETED;
730 }
731 
732 /* !
733  * \brief Tests SDL_HasIntersection() with B fully outside A
734  *
735  * \sa
736  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
737  */
739 {
740  SDL_Rect refRectA = { 0, 0, 32, 32 };
741  SDL_Rect refRectB;
742  SDL_Rect rectA;
743  SDL_Rect rectB;
744  SDL_bool intersection;
745 
746  /* rectB fully outside of rectA */
747  refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
748  refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
749  refRectB.w = refRectA.w;
750  refRectB.h = refRectA.h;
751  rectA = refRectA;
752  rectB = refRectB;
753  intersection = SDL_HasIntersection(&rectA, &rectB);
754  _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
755 
756  return TEST_COMPLETED;
757 }
758 
759 /* !
760  * \brief Tests SDL_HasIntersection() with B partially intersecting A
761  *
762  * \sa
763  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
764  */
766 {
767  SDL_Rect refRectA = { 0, 0, 32, 32 };
768  SDL_Rect refRectB;
769  SDL_Rect rectA;
770  SDL_Rect rectB;
771  SDL_bool intersection;
772 
773  /* rectB partially contained in rectA */
774  refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
775  refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
776  refRectB.w = refRectA.w;
777  refRectB.h = refRectA.h;
778  rectA = refRectA;
779  rectB = refRectB;
780  intersection = SDL_HasIntersection(&rectA, &rectB);
781  _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
782 
783  /* rectB right edge */
784  refRectB.x = rectA.w - 1;
785  refRectB.y = rectA.y;
786  refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
787  refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
788  rectA = refRectA;
789  rectB = refRectB;
790  intersection = SDL_HasIntersection(&rectA, &rectB);
791  _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
792 
793  /* rectB left edge */
794  refRectB.x = 1 - rectA.w;
795  refRectB.y = rectA.y;
796  refRectB.w = refRectA.w;
797  refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
798  rectA = refRectA;
799  rectB = refRectB;
800  intersection = SDL_HasIntersection(&rectA, &rectB);
801  _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
802 
803  /* rectB bottom edge */
804  refRectB.x = rectA.x;
805  refRectB.y = rectA.h - 1;
806  refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
807  refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
808  rectA = refRectA;
809  rectB = refRectB;
810  intersection = SDL_HasIntersection(&rectA, &rectB);
811  _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
812 
813  /* rectB top edge */
814  refRectB.x = rectA.x;
815  refRectB.y = 1 - rectA.h;
816  refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
817  refRectB.h = rectA.h;
818  rectA = refRectA;
819  rectB = refRectB;
820  intersection = SDL_HasIntersection(&rectA, &rectB);
821  _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
822 
823  return TEST_COMPLETED;
824 }
825 
826 /* !
827  * \brief Tests SDL_HasIntersection() with 1x1 pixel sized rectangles
828  *
829  * \sa
830  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
831  */
833 {
834  SDL_Rect refRectA = { 0, 0, 1, 1 };
835  SDL_Rect refRectB = { 0, 0, 1, 1 };
836  SDL_Rect rectA;
837  SDL_Rect rectB;
838  SDL_bool intersection;
839  int offsetX, offsetY;
840 
841  /* intersecting pixels */
842  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
843  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
844  refRectB.x = refRectA.x;
845  refRectB.y = refRectA.y;
846  rectA = refRectA;
847  rectB = refRectB;
848  intersection = SDL_HasIntersection(&rectA, &rectB);
849  _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
850 
851  /* non-intersecting pixels cases */
852  for (offsetX = -1; offsetX <= 1; offsetX++) {
853  for (offsetY = -1; offsetY <= 1; offsetY++) {
854  if (offsetX != 0 || offsetY != 0) {
855  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
856  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
857  refRectB.x = refRectA.x;
858  refRectB.y = refRectA.y;
859  refRectB.x += offsetX;
860  refRectB.y += offsetY;
861  rectA = refRectA;
862  rectB = refRectB;
863  intersection = SDL_HasIntersection(&rectA, &rectB);
864  _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
865  }
866  }
867  }
868 
869  return TEST_COMPLETED;
870 }
871 
872 /* !
873  * \brief Tests SDL_HasIntersection() with empty rectangles
874  *
875  * \sa
876  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
877  */
879 {
880  SDL_Rect refRectA;
881  SDL_Rect refRectB;
882  SDL_Rect rectA;
883  SDL_Rect rectB;
884  SDL_bool intersection;
885 
886  /* Rect A empty */
887  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
888  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
889  refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
890  refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
891  refRectB = refRectA;
892  refRectA.w = 0;
893  refRectA.h = 0;
894  rectA = refRectA;
895  rectB = refRectB;
896  intersection = SDL_HasIntersection(&rectA, &rectB);
897  _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
898 
899  /* Rect B empty */
900  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
901  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
902  refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
903  refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
904  refRectB = refRectA;
905  refRectB.w = 0;
906  refRectB.h = 0;
907  rectA = refRectA;
908  rectB = refRectB;
909  intersection = SDL_HasIntersection(&rectA, &rectB);
910  _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
911 
912  /* Rect A and B empty */
913  refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
914  refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
915  refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
916  refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
917  refRectB = refRectA;
918  refRectA.w = 0;
919  refRectA.h = 0;
920  refRectB.w = 0;
921  refRectB.h = 0;
922  rectA = refRectA;
923  rectB = refRectB;
924  intersection = SDL_HasIntersection(&rectA, &rectB);
925  _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
926 
927  return TEST_COMPLETED;
928 }
929 
930 /* !
931  * \brief Negative tests against SDL_HasIntersection() with invalid parameters
932  *
933  * \sa
934  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
935  */
937 {
938  SDL_Rect rectA;
939  SDL_Rect rectB;
940  SDL_bool intersection;
941 
942  /* invalid parameter combinations */
943  intersection = SDL_HasIntersection((SDL_Rect *)NULL, &rectB);
944  SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
945  intersection = SDL_HasIntersection(&rectA, (SDL_Rect *)NULL);
946  SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
947  intersection = SDL_HasIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL);
948  SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
949 
950  return TEST_COMPLETED;
951 }
952 
953 /* !
954  * \brief Test SDL_EnclosePoints() without clipping
955  *
956  * \sa
957  * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
958  */
960 {
961  const int numPoints = 16;
962  SDL_Point refPoints[16];
963  SDL_Point points[16];
965  SDL_bool anyEnclosed;
966  SDL_bool anyEnclosedNoResult;
967  SDL_bool expectedEnclosed = SDL_TRUE;
968  int newx, newy;
969  int minx = 0, maxx = 0, miny = 0, maxy = 0;
970  int i;
971 
972  /* Create input data, tracking result */
973  for (i=0; i<numPoints; i++) {
974  newx = SDLTest_RandomIntegerInRange(-1024, 1024);
975  newy = SDLTest_RandomIntegerInRange(-1024, 1024);
976  refPoints[i].x = newx;
977  refPoints[i].y = newy;
978  points[i].x = newx;
979  points[i].y = newy;
980  if (i==0) {
981  minx = newx;
982  maxx = newx;
983  miny = newy;
984  maxy = newy;
985  } else {
986  if (newx < minx) minx = newx;
987  if (newx > maxx) maxx = newx;
988  if (newy < miny) miny = newy;
989  if (newy > maxy) maxy = newy;
990  }
991  }
992 
993  /* Call function and validate - special case: no result requested */
994  anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
995  SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
996  "Check expected return value %s, got %s",
997  (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
998  (anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
999  for (i=0; i<numPoints; i++) {
1000  SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
1001  "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1002  i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1003  }
1004 
1005  /* Call function and validate */
1006  anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
1007  SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
1008  "Check return value %s, got %s",
1009  (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1010  (anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1011  for (i=0; i<numPoints; i++) {
1012  SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
1013  "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1014  i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1015  }
1016  SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
1017  "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1018  minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1019 
1020  return TEST_COMPLETED;
1021 }
1022 
1023 /* !
1024  * \brief Test SDL_EnclosePoints() with repeated input points
1025  *
1026  * \sa
1027  * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
1028  */
1030 {
1031  const int numPoints = 8;
1032  const int halfPoints = 4;
1033  SDL_Point refPoints[8];
1034  SDL_Point points[8];
1035  SDL_Rect result;
1036  SDL_bool anyEnclosed;
1037  SDL_bool anyEnclosedNoResult;
1038  SDL_bool expectedEnclosed = SDL_TRUE;
1039  int newx, newy;
1040  int minx = 0, maxx = 0, miny = 0, maxy = 0;
1041  int i;
1042 
1043  /* Create input data, tracking result */
1044  for (i=0; i<numPoints; i++) {
1045  if (i < halfPoints) {
1046  newx = SDLTest_RandomIntegerInRange(-1024, 1024);
1047  newy = SDLTest_RandomIntegerInRange(-1024, 1024);
1048  } else {
1049  newx = refPoints[i-halfPoints].x;
1050  newy = refPoints[i-halfPoints].y;
1051  }
1052  refPoints[i].x = newx;
1053  refPoints[i].y = newy;
1054  points[i].x = newx;
1055  points[i].y = newy;
1056  if (i==0) {
1057  minx = newx;
1058  maxx = newx;
1059  miny = newy;
1060  maxy = newy;
1061  } else {
1062  if (newx < minx) minx = newx;
1063  if (newx > maxx) maxx = newx;
1064  if (newy < miny) miny = newy;
1065  if (newy > maxy) maxy = newy;
1066  }
1067  }
1068 
1069  /* Call function and validate - special case: no result requested */
1070  anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
1071  SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
1072  "Check return value %s, got %s",
1073  (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1074  (anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1075  for (i=0; i<numPoints; i++) {
1076  SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
1077  "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1078  i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1079  }
1080 
1081  /* Call function and validate */
1082  anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
1083  SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
1084  "Check return value %s, got %s",
1085  (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1086  (anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1087  for (i=0; i<numPoints; i++) {
1088  SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
1089  "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1090  i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1091  }
1092  SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
1093  "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1094  minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1095 
1096  return TEST_COMPLETED;
1097 }
1098 
1099 /* !
1100  * \brief Test SDL_EnclosePoints() with clipping
1101  *
1102  * \sa
1103  * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
1104  */
1106 {
1107  const int numPoints = 16;
1108  SDL_Point refPoints[16];
1109  SDL_Point points[16];
1110  SDL_Rect refClip;
1111  SDL_Rect clip;
1112  SDL_Rect result;
1113  SDL_bool anyEnclosed;
1114  SDL_bool anyEnclosedNoResult;
1115  SDL_bool expectedEnclosed = SDL_FALSE;
1116  int newx, newy;
1117  int minx = 0, maxx = 0, miny = 0, maxy = 0;
1118  int i;
1119 
1120  /* Setup clipping rectangle */
1121  refClip.x = SDLTest_RandomIntegerInRange(-1024, 1024);
1122  refClip.y = SDLTest_RandomIntegerInRange(-1024, 1024);
1123  refClip.w = SDLTest_RandomIntegerInRange(1, 1024);
1124  refClip.h = SDLTest_RandomIntegerInRange(1, 1024);
1125 
1126  /* Create input data, tracking result */
1127  for (i=0; i<numPoints; i++) {
1128  newx = SDLTest_RandomIntegerInRange(-1024, 1024);
1129  newy = SDLTest_RandomIntegerInRange(-1024, 1024);
1130  refPoints[i].x = newx;
1131  refPoints[i].y = newy;
1132  points[i].x = newx;
1133  points[i].y = newy;
1134  if ((newx>=refClip.x) && (newx<(refClip.x + refClip.w)) &&
1135  (newy>=refClip.y) && (newy<(refClip.y + refClip.h))) {
1136  if (expectedEnclosed==SDL_FALSE) {
1137  minx = newx;
1138  maxx = newx;
1139  miny = newy;
1140  maxy = newy;
1141  } else {
1142  if (newx < minx) minx = newx;
1143  if (newx > maxx) maxx = newx;
1144  if (newy < miny) miny = newy;
1145  if (newy > maxy) maxy = newy;
1146  }
1147  expectedEnclosed = SDL_TRUE;
1148  }
1149  }
1150 
1151  /* Call function and validate - special case: no result requested */
1152  clip = refClip;
1153  anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, (SDL_Rect *)NULL);
1154  SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
1155  "Expected return value %s, got %s",
1156  (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1157  (anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1158  for (i=0; i<numPoints; i++) {
1159  SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
1160  "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1161  i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1162  }
1163  SDLTest_AssertCheck(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
1164  "Check that source clipping rectangle was not modified");
1165 
1166  /* Call function and validate */
1167  anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
1168  SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
1169  "Check return value %s, got %s",
1170  (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1171  (anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1172  for (i=0; i<numPoints; i++) {
1173  SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
1174  "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)",
1175  i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1176  }
1177  SDLTest_AssertCheck(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
1178  "Check that source clipping rectangle was not modified");
1179  if (expectedEnclosed==SDL_TRUE) {
1180  SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
1181  "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1182  minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1183  }
1184 
1185  /* Empty clipping rectangle */
1186  clip.w = 0;
1187  clip.h = 0;
1188  expectedEnclosed = SDL_FALSE;
1189  anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
1190  SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
1191  "Check return value %s, got %s",
1192  (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
1193  (anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
1194 
1195  return TEST_COMPLETED;
1196 }
1197 
1198 /* !
1199  * \brief Negative tests against SDL_EnclosePoints() with invalid parameters
1200  *
1201  * \sa
1202  * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
1203  */
1205 {
1206  SDL_Point points[1];
1207  int count;
1208  SDL_Rect clip;
1209  SDL_Rect result;
1210  SDL_bool anyEnclosed;
1211 
1212  /* invalid parameter combinations */
1213  anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 1, (const SDL_Rect *)&clip, &result);
1214  SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL");
1215  anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, 0, (const SDL_Rect *)&clip, &result);
1216  SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is 0");
1217  count = SDLTest_RandomIntegerInRange(-100, -1);
1218  anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, count, (const SDL_Rect *)&clip, &result);
1219  SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is %i (negative)", count);
1220  anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 0, (const SDL_Rect *)&clip, &result);
1221  SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL and 2nd parameter was 0");
1222 
1223  return TEST_COMPLETED;
1224 }
1225 
1226 /* !
1227  * \brief Tests SDL_UnionRect() where rect B is outside rect A
1228  *
1229  * \sa
1230  * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
1231  */
1233 {
1234  SDL_Rect refRectA, refRectB;
1235  SDL_Rect rectA, rectB;
1236  SDL_Rect expectedResult;
1237  SDL_Rect result;
1238  int minx, maxx, miny, maxy;
1239  int dx, dy;
1240 
1241  /* Union 1x1 outside */
1242  for (dx = -1; dx < 2; dx++) {
1243  for (dy = -1; dy < 2; dy++) {
1244  if ((dx != 0) || (dy != 0)) {
1245  refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1246  refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1247  refRectA.w=1;
1248  refRectA.h=1;
1249  refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024) + dx*2048;
1250  refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024) + dx*2048;
1251  refRectB.w=1;
1252  refRectB.h=1;
1253  minx = (refRectA.x<refRectB.x) ? refRectA.x : refRectB.x;
1254  maxx = (refRectA.x>refRectB.x) ? refRectA.x : refRectB.x;
1255  miny = (refRectA.y<refRectB.y) ? refRectA.y : refRectB.y;
1256  maxy = (refRectA.y>refRectB.y) ? refRectA.y : refRectB.y;
1257  expectedResult.x = minx;
1258  expectedResult.y = miny;
1259  expectedResult.w = maxx - minx + 1;
1260  expectedResult.h = maxy - miny + 1;
1261  rectA = refRectA;
1262  rectB = refRectB;
1263  SDL_UnionRect(&rectA, &rectB, &result);
1264  _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1265  }
1266  }
1267  }
1268 
1269  /* Union outside overlap */
1270  for (dx = -1; dx < 2; dx++) {
1271  for (dy = -1; dy < 2; dy++) {
1272  if ((dx != 0) || (dy != 0)) {
1273  refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1274  refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1275  refRectA.w=SDLTest_RandomIntegerInRange(256, 512);
1276  refRectA.h=SDLTest_RandomIntegerInRange(256, 512);
1277  refRectB.x=refRectA.x + 1 + dx*2;
1278  refRectB.y=refRectA.y + 1 + dy*2;
1279  refRectB.w=refRectA.w - 2;
1280  refRectB.h=refRectA.h - 2;
1281  expectedResult = refRectA;
1282  if (dx == -1) expectedResult.x--;
1283  if (dy == -1) expectedResult.y--;
1284  if ((dx == 1) || (dx == -1)) expectedResult.w++;
1285  if ((dy == 1) || (dy == -1)) expectedResult.h++;
1286  rectA = refRectA;
1287  rectB = refRectB;
1288  SDL_UnionRect(&rectA, &rectB, &result);
1289  _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1290  }
1291  }
1292  }
1293 
1294  return TEST_COMPLETED;
1295 }
1296 
1297 /* !
1298  * \brief Tests SDL_UnionRect() where rect A or rect B are empty
1299  *
1300  * \sa
1301  * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
1302  */
1304 {
1305  SDL_Rect refRectA, refRectB;
1306  SDL_Rect rectA, rectB;
1307  SDL_Rect expectedResult;
1308  SDL_Rect result;
1309 
1310  /* A empty */
1311  refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1312  refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1313  refRectA.w=0;
1314  refRectA.h=0;
1315  refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1316  refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1317  refRectB.w=SDLTest_RandomIntegerInRange(1, 1024);
1318  refRectB.h=SDLTest_RandomIntegerInRange(1, 1024);
1319  expectedResult = refRectB;
1320  rectA = refRectA;
1321  rectB = refRectB;
1322  SDL_UnionRect(&rectA, &rectB, &result);
1323  _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1324 
1325  /* B empty */
1326  refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1327  refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1328  refRectA.w=SDLTest_RandomIntegerInRange(1, 1024);
1329  refRectA.h=SDLTest_RandomIntegerInRange(1, 1024);
1330  refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1331  refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1332  refRectB.w=0;
1333  refRectB.h=0;
1334  expectedResult = refRectA;
1335  rectA = refRectA;
1336  rectB = refRectB;
1337  SDL_UnionRect(&rectA, &rectB, &result);
1338  _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1339 
1340  /* A and B empty */
1341  refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1342  refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1343  refRectA.w=0;
1344  refRectA.h=0;
1345  refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1346  refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1347  refRectB.w=0;
1348  refRectB.h=0;
1349  result.x=0;
1350  result.y=0;
1351  result.w=0;
1352  result.h=0;
1353  expectedResult = result;
1354  rectA = refRectA;
1355  rectB = refRectB;
1356  SDL_UnionRect(&rectA, &rectB, &result);
1357  _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1358 
1359  return TEST_COMPLETED;
1360 }
1361 
1362 /* !
1363  * \brief Tests SDL_UnionRect() where rect B is inside rect A
1364  *
1365  * \sa
1366  * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
1367  */
1369 {
1370  SDL_Rect refRectA, refRectB;
1371  SDL_Rect rectA, rectB;
1372  SDL_Rect expectedResult;
1373  SDL_Rect result;
1374  int dx, dy;
1375 
1376  /* Union 1x1 with itself */
1377  refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1378  refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1379  refRectA.w=1;
1380  refRectA.h=1;
1381  expectedResult = refRectA;
1382  rectA = refRectA;
1383  SDL_UnionRect(&rectA, &rectA, &result);
1384  _validateUnionRectResults(&rectA, &rectA, &refRectA, &refRectA, &result, &expectedResult);
1385 
1386  /* Union 1x1 somewhere inside */
1387  refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1388  refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1389  refRectA.w=SDLTest_RandomIntegerInRange(256, 1024);
1390  refRectA.h=SDLTest_RandomIntegerInRange(256, 1024);
1391  refRectB.x=refRectA.x + 1 + SDLTest_RandomIntegerInRange(1, refRectA.w - 2);
1392  refRectB.y=refRectA.y + 1 + SDLTest_RandomIntegerInRange(1, refRectA.h - 2);
1393  refRectB.w=1;
1394  refRectB.h=1;
1395  expectedResult = refRectA;
1396  rectA = refRectA;
1397  rectB = refRectB;
1398  SDL_UnionRect(&rectA, &rectB, &result);
1399  _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1400 
1401  /* Union inside with edges modified */
1402  for (dx = -1; dx < 2; dx++) {
1403  for (dy = -1; dy < 2; dy++) {
1404  if ((dx != 0) || (dy != 0)) {
1405  refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1406  refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1407  refRectA.w=SDLTest_RandomIntegerInRange(256, 1024);
1408  refRectA.h=SDLTest_RandomIntegerInRange(256, 1024);
1409  refRectB = refRectA;
1410  if (dx == -1) refRectB.x++;
1411  if ((dx == 1) || (dx == -1)) refRectB.w--;
1412  if (dy == -1) refRectB.y++;
1413  if ((dy == 1) || (dy == -1)) refRectB.h--;
1414  expectedResult = refRectA;
1415  rectA = refRectA;
1416  rectB = refRectB;
1417  SDL_UnionRect(&rectA, &rectB, &result);
1418  _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1419  }
1420  }
1421  }
1422 
1423  return TEST_COMPLETED;
1424 }
1425 
1426 /* !
1427  * \brief Negative tests against SDL_UnionRect() with invalid parameters
1428  *
1429  * \sa
1430  * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
1431  */
1433 {
1434  SDL_Rect rectA, rectB;
1435  SDL_Rect result;
1436 
1437  /* invalid parameter combinations */
1438  SDL_UnionRect((SDL_Rect *)NULL, &rectB, &result);
1439  SDLTest_AssertPass("Check that function returns when 1st parameter is NULL");
1440  SDL_UnionRect(&rectA, (SDL_Rect *)NULL, &result);
1441  SDLTest_AssertPass("Check that function returns when 2nd parameter is NULL");
1442  SDL_UnionRect(&rectA, &rectB, (SDL_Rect *)NULL);
1443  SDLTest_AssertPass("Check that function returns when 3rd parameter is NULL");
1444  SDL_UnionRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
1445  SDLTest_AssertPass("Check that function returns when 1st and 3rd parameter are NULL");
1446  SDL_UnionRect(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
1447  SDLTest_AssertPass("Check that function returns when 2nd and 3rd parameter are NULL");
1448  SDL_UnionRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
1449  SDLTest_AssertPass("Check that function returns when all parameters are NULL");
1450 
1451  return TEST_COMPLETED;
1452 }
1453 
1454 /* !
1455  * \brief Tests SDL_RectEmpty() with various inputs
1456  *
1457  * \sa
1458  * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
1459  */
1460 int rect_testRectEmpty(void *arg)
1461 {
1462  SDL_Rect refRect;
1463  SDL_Rect rect;
1464  SDL_bool expectedResult;
1465  SDL_bool result;
1466  int w, h;
1467 
1468  /* Non-empty case */
1469  refRect.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1470  refRect.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1471  refRect.w=SDLTest_RandomIntegerInRange(256, 1024);
1472  refRect.h=SDLTest_RandomIntegerInRange(256, 1024);
1473  expectedResult = SDL_FALSE;
1474  rect = refRect;
1475  result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
1476  _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
1477 
1478  /* Empty case */
1479  for (w=-1; w<2; w++) {
1480  for (h=-1; h<2; h++) {
1481  if ((w != 1) || (h != 1)) {
1482  refRect.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1483  refRect.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1484  refRect.w=w;
1485  refRect.h=h;
1486  expectedResult = SDL_TRUE;
1487  rect = refRect;
1488  result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
1489  _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
1490  }
1491  }
1492  }
1493 
1494  return TEST_COMPLETED;
1495 }
1496 
1497 /* !
1498  * \brief Negative tests against SDL_RectEmpty() with invalid parameters
1499  *
1500  * \sa
1501  * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
1502  */
1504 {
1505  SDL_bool result;
1506 
1507  /* invalid parameter combinations */
1508  result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)NULL);
1509  SDLTest_AssertCheck(result == SDL_TRUE, "Check that function returns TRUE when 1st parameter is NULL");
1510 
1511  return TEST_COMPLETED;
1512 }
1513 
1514 /* !
1515  * \brief Tests SDL_RectEquals() with various inputs
1516  *
1517  * \sa
1518  * http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
1519  */
1520 int rect_testRectEquals(void *arg)
1521 {
1522  SDL_Rect refRectA;
1523  SDL_Rect refRectB;
1524  SDL_Rect rectA;
1525  SDL_Rect rectB;
1526  SDL_bool expectedResult;
1527  SDL_bool result;
1528 
1529  /* Equals */
1530  refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1531  refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1532  refRectA.w=SDLTest_RandomIntegerInRange(1, 1024);
1533  refRectA.h=SDLTest_RandomIntegerInRange(1, 1024);
1534  refRectB = refRectA;
1535  expectedResult = SDL_TRUE;
1536  rectA = refRectA;
1537  rectB = refRectB;
1538  result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)&rectB);
1539  _validateRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
1540 
1541  return TEST_COMPLETED;
1542 }
1543 
1544 /* !
1545  * \brief Negative tests against SDL_RectEquals() with invalid parameters
1546  *
1547  * \sa
1548  * http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
1549  */
1551 {
1552  SDL_Rect rectA;
1553  SDL_Rect rectB;
1554  SDL_bool result;
1555 
1556  /* data setup */
1557  rectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1558  rectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1559  rectA.w=SDLTest_RandomIntegerInRange(1, 1024);
1560  rectA.h=SDLTest_RandomIntegerInRange(1, 1024);
1561  rectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
1562  rectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
1563  rectB.w=SDLTest_RandomIntegerInRange(1, 1024);
1564  rectB.h=SDLTest_RandomIntegerInRange(1, 1024);
1565 
1566  /* invalid parameter combinations */
1567  result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)&rectB);
1568  SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
1569  result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)NULL);
1570  SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
1571  result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)NULL);
1572  SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
1573 
1574  return TEST_COMPLETED;
1575 }
1576 
1577 /* ================= Test References ================== */
1578 
1579 /* Rect test cases */
1580 
1581 /* SDL_IntersectRectAndLine */
1583  { (SDLTest_TestCaseFp)rect_testIntersectRectAndLine,"rect_testIntersectRectAndLine", "Tests SDL_IntersectRectAndLine clipping cases", TEST_ENABLED };
1584 
1586  { (SDLTest_TestCaseFp)rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED };
1587 
1589  { (SDLTest_TestCaseFp)rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_IntersectRectAndLine with line fully outside of rect", TEST_ENABLED };
1590 
1592  { (SDLTest_TestCaseFp)rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_IntersectRectAndLine with empty rectangle ", TEST_ENABLED };
1593 
1595  { (SDLTest_TestCaseFp)rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_IntersectRectAndLine with invalid parameters", TEST_ENABLED };
1596 
1597 /* SDL_IntersectRect */
1599  { (SDLTest_TestCaseFp)rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED };
1600 
1602  { (SDLTest_TestCaseFp)rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED };
1603 
1605  { (SDLTest_TestCaseFp)rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED };
1606 
1608  { (SDLTest_TestCaseFp)rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED };
1609 
1611  { (SDLTest_TestCaseFp)rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_IntersectRect with empty rectangles", TEST_ENABLED };
1612 
1614  { (SDLTest_TestCaseFp)rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_IntersectRect with invalid parameters", TEST_ENABLED };
1615 
1616 /* SDL_HasIntersection */
1618  { (SDLTest_TestCaseFp)rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasIntersection with B fully contained in A", TEST_ENABLED };
1619 
1621  { (SDLTest_TestCaseFp)rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasIntersection with B fully outside of A", TEST_ENABLED };
1622 
1624  { (SDLTest_TestCaseFp)rect_testHasIntersectionPartial,"rect_testHasIntersectionPartial", "Tests SDL_HasIntersection with B partially intersecting A", TEST_ENABLED };
1625 
1627  { (SDLTest_TestCaseFp)rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasIntersection with 1x1 sized rectangles", TEST_ENABLED };
1628 
1630  { (SDLTest_TestCaseFp)rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasIntersection with empty rectangles", TEST_ENABLED };
1631 
1633  { (SDLTest_TestCaseFp)rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED };
1634 
1635 /* SDL_EnclosePoints */
1637  { (SDLTest_TestCaseFp)rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED };
1638 
1640  { (SDLTest_TestCaseFp)rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED };
1641 
1643  { (SDLTest_TestCaseFp)rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED };
1644 
1646  { (SDLTest_TestCaseFp)rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED };
1647 
1648 /* SDL_UnionRect */
1650  { (SDLTest_TestCaseFp)rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_UnionRect where rect B is inside rect A", TEST_ENABLED };
1651 
1653  { (SDLTest_TestCaseFp)rect_testUnionRectOutside, "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED };
1654 
1656  { (SDLTest_TestCaseFp)rect_testUnionRectEmpty, "rect_testUnionRectEmpty", "Tests SDL_UnionRect where rect A or rect B are empty", TEST_ENABLED };
1657 
1659  { (SDLTest_TestCaseFp)rect_testUnionRectParam, "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED };
1660 
1661 /* SDL_RectEmpty */
1663  { (SDLTest_TestCaseFp)rect_testRectEmpty, "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED };
1664 
1666  { (SDLTest_TestCaseFp)rect_testRectEmptyParam, "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED };
1667 
1668 /* SDL_RectEquals */
1669 
1671  { (SDLTest_TestCaseFp)rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectEquals with various inputs", TEST_ENABLED };
1672 
1674  { (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
1675 
1676 
1677 /* !
1678  * \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
1679  *
1680  * \sa
1681  * http://wiki.libsdl.org/moin.cgi/CategoryRect
1682  */
1687 };
1688 
1689 
1690 /* Rect test suite (global) */
1692  "Rect",
1693  NULL,
1694  rectTests,
1695  NULL
1696 };
int rect_testUnionRectParam(void *arg)
static const SDLTest_TestCaseReference rectTest21
#define SDL_UnionRect
#define SDL_HasIntersection
int rect_testIntersectRectPartial(void *arg)
int rect_testHasIntersectionParam(void *arg)
int rect_testHasIntersectionOutside(void *arg)
int rect_testEnclosePoints(void *arg)
static const SDLTest_TestCaseReference rectTest8
int rect_testUnionRectOutside(void *arg)
GLuint GLfloat GLfloat GLfloat x1
void _validateRectEmptyResults(SDL_bool empty, SDL_bool expectedEmpty, SDL_Rect *rect, SDL_Rect *refRect)
int rect_testIntersectRectAndLineInside(void *arg)
GLuint64EXT * result
int rect_testRectEqualsParam(void *arg)
SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b)
Returns true if the two rectangles are equal.
Definition: SDL_rect.h:90
static const SDLTest_TestCaseReference rectTest20
static const SDLTest_TestCaseReference rectTest13
static const SDLTest_TestCaseReference rectTest6
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max)
static const SDLTest_TestCaseReference rectTest19
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
static const SDLTest_TestCaseReference rectTest29
SDL_Rect rect
Definition: testrelative.c:27
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
static const SDLTest_TestCaseReference rectTest17
GLfloat GLfloat GLfloat GLfloat h
static const SDLTest_TestCaseReference rectTest4
GLfixed GLfixed GLfixed y2
int rect_testIntersectRectOutside(void *arg)
void _validateHasIntersectionResults(SDL_bool intersection, SDL_bool expectedIntersection, SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
The structure that defines a point.
Definition: SDL_rect.h:48
static const SDLTest_TestCaseReference rectTest22
static const SDLTest_TestCaseReference rectTest27
static const SDLTest_TestCaseReference rectTest15
static const SDLTest_TestCaseReference rectTest14
SDLTest_TestSuiteReference rectTestSuite
static const SDLTest_TestCaseReference rectTest9
#define SDL_IntersectRect
SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r)
Returns true if the rectangle has no area.
Definition: SDL_rect.h:82
GLfixed GLfixed x2
GLfixed GLfixed GLint GLint GLfixed points
GLfixed y1
int rect_testUnionRectEmpty(void *arg)
static const SDLTest_TestCaseReference * rectTests[]
void _validateRectEqualsResults(SDL_bool equals, SDL_bool expectedEquals, SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
static const SDLTest_TestCaseReference rectTest11
int x
Definition: SDL_rect.h:50
static const SDLTest_TestCaseReference rectTest7
int rect_testIntersectRectEmpty(void *arg)
int(* SDLTest_TestCaseFp)(void *arg)
static const SDLTest_TestCaseReference rectTest25
int y
Definition: SDL_rect.h:51
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
int rect_testIntersectRectParam(void *arg)
int rect_testRectEquals(void *arg)
static const SDLTest_TestCaseReference rectTest18
void _validateIntersectRectAndLineResults(SDL_bool intersection, SDL_bool expectedIntersection, SDL_Rect *rect, SDL_Rect *refRect, int x1, int y1, int x2, int y2, int x1Ref, int y1Ref, int x2Ref, int y2Ref)
static const SDLTest_TestCaseReference rectTest28
static const SDLTest_TestCaseReference rectTest26
int rect_testIntersectRectInside(void *arg)
int rect_testHasIntersectionPartial(void *arg)
static const SDLTest_TestCaseReference rectTest24
GLubyte GLubyte GLubyte GLubyte w
void _validateIntersectRectResults(SDL_bool intersection, SDL_bool expectedIntersection, SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB, SDL_Rect *result, SDL_Rect *expectedResult)
static const SDLTest_TestCaseReference rectTest5
int rect_testIntersectRectAndLineParam(void *arg)
int rect_testIntersectRectAndLineOutside(void *arg)
int rect_testHasIntersectionEmpty(void *arg)
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
int x
Definition: SDL_rect.h:66
static const SDLTest_TestCaseReference rectTest10
#define TEST_COMPLETED
int w
Definition: SDL_rect.h:67
int rect_testUnionRectInside(void *arg)
#define TEST_ENABLED
int rect_testEnclosePointsWithClipping(void *arg)
static const SDLTest_TestCaseReference rectTest3
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
int rect_testIntersectRectPoint(void *arg)
#define NULL
Definition: begin_code.h:164
SDL_bool
Definition: SDL_stdinc.h:139
static const SDLTest_TestCaseReference rectTest23
int rect_testIntersectRectAndLine(void *arg)
static const SDLTest_TestCaseReference rectTest1
static const SDLTest_TestCaseReference rectTest16
int rect_testHasIntersectionInside(void *arg)
int h
Definition: SDL_rect.h:67
int rect_testIntersectRectAndLineEmpty(void *arg)
int rect_testRectEmpty(void *arg)
int rect_testEnclosePointsRepeatedInput(void *arg)
static const SDLTest_TestCaseReference rectTest2
#define SDL_EnclosePoints
int rect_testRectEmptyParam(void *arg)
int rect_testHasIntersectionPoint(void *arg)
int rect_testEnclosePointsParam(void *arg)
#define SDL_IntersectRectAndLine
static const SDLTest_TestCaseReference rectTest12
int y
Definition: SDL_rect.h:66
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
void _validateUnionRectResults(SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB, SDL_Rect *result, SDL_Rect *expectedResult)