testautomation_rect.c 71 KB

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