testautomation_rect.c 70 KB

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