testautomation_rect.c 72 KB

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