testautomation_rect.c 82 KB

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