testautomation_rect.c 71 KB

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