testautomation_rect.c 92 KB

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