testautomation_rect.c 71 KB

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