testautomation_rect.c 70 KB

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