testautomation_rect.c 72 KB

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