testautomation_rect.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854
  1. /**
  2. * Original code: automated SDL rect test written by Edgar Simo "bobbens"
  3. * New/updated tests: aschiffler at ferzkopp dot net
  4. */
  5. #include <SDL3/SDL.h>
  6. #include <SDL3/SDL_test.h>
  7. /* ================= Test Case Implementation ================== */
  8. /* Helper functions */
  9. /* !
  10. * \brief Private helper to check SDL_GetRectAndLineIntersection results
  11. */
  12. static void validateIntersectRectAndLineResults(
  13. SDL_bool intersection, SDL_bool expectedIntersection,
  14. SDL_Rect *rect, SDL_Rect *refRect,
  15. int x1, int y1, int x2, int y2,
  16. int x1Ref, int y1Ref, int x2Ref, int y2Ref)
  17. {
  18. SDLTest_AssertCheck(intersection == expectedIntersection,
  19. "Check for correct intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)",
  20. (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
  21. (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
  22. refRect->x, refRect->y, refRect->w, refRect->h,
  23. x1Ref, y1Ref, x2Ref, y2Ref);
  24. SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
  25. "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
  26. rect->x, rect->y, rect->w, rect->h,
  27. refRect->x, refRect->y, refRect->w, refRect->h);
  28. SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
  29. "Check if line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
  30. x1, y1, x2, y2,
  31. x1Ref, y1Ref, x2Ref, y2Ref);
  32. }
  33. /* Test case functions */
  34. /* !
  35. * \brief Tests SDL_GetRectAndLineIntersection() clipping cases
  36. *
  37. * \sa
  38. * http://wiki.libsdl.org/SDL_GetRectAndLineIntersection
  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_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
  99. * http://wiki.libsdl.org/SDL_GetRectAndLineIntersection
  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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection() non-clipping cases outside
  155. *
  156. * \sa
  157. * http://wiki.libsdl.org/SDL_GetRectAndLineIntersection
  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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection() with empty rectangle
  202. *
  203. * \sa
  204. * http://wiki.libsdl.org/SDL_GetRectAndLineIntersection
  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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection() with invalid parameters
  232. *
  233. * \sa
  234. * http://wiki.libsdl.org/SDL_GetRectAndLineIntersection
  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_GetRectAndLineIntersection(&rect, &x1, &y1, &x2, &y2);
  245. SDLTest_AssertCheck(intersected == SDL_TRUE, "Check that intersection result was SDL_TRUE");
  246. intersected = SDL_GetRectAndLineIntersection((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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection(&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_GetRectAndLineIntersection((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_HasRectIntersection results
  262. */
  263. static 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_GetRectIntersection results
  284. */
  285. static 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_GetRectUnion results
  302. */
  303. static 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. static 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_RectsEqual results
  341. */
  342. static 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_RectsEqualFloat results
  363. */
  364. static 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_GetRectIntersection() with B fully inside A
  388. *
  389. * \sa
  390. * http://wiki.libsdl.org/SDL_GetRectIntersection
  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_GetRectIntersection(&rectA, &rectB, &result);
  408. validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB);
  409. return TEST_COMPLETED;
  410. }
  411. /* !
  412. * \brief Tests SDL_GetRectIntersection() with B fully outside A
  413. *
  414. * \sa
  415. * http://wiki.libsdl.org/SDL_GetRectIntersection
  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_GetRectIntersection(&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_GetRectIntersection() with B partially intersecting A
  438. *
  439. * \sa
  440. * http://wiki.libsdl.org/SDL_GetRectIntersection
  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_GetRectIntersection(&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_GetRectIntersection(&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_GetRectIntersection(&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_GetRectIntersection(&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_GetRectIntersection(&rectA, &rectB, &result);
  515. validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  516. return TEST_COMPLETED;
  517. }
  518. /* !
  519. * \brief Tests SDL_GetRectIntersection() with 1x1 pixel sized rectangles
  520. *
  521. * \sa
  522. * http://wiki.libsdl.org/SDL_GetRectIntersection
  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_GetRectIntersection(&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_GetRectIntersection(&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_GetRectIntersection() with empty rectangles
  563. *
  564. * \sa
  565. * http://wiki.libsdl.org/SDL_GetRectIntersection
  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_GetRectIntersection(&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_GetRectIntersection(&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_GetRectIntersection(&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_GetRectIntersection() with invalid parameters
  630. *
  631. * \sa
  632. * http://wiki.libsdl.org/SDL_GetRectIntersection
  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_GetRectIntersection((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_GetRectIntersection(&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_GetRectIntersection(&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_GetRectIntersection((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_GetRectIntersection((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_GetRectIntersection((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_HasRectIntersection() with B fully inside A
  657. *
  658. * \sa
  659. * http://wiki.libsdl.org/SDL_HasRectIntersection
  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_HasRectIntersection(&rectA, &rectB);
  676. validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
  677. return TEST_COMPLETED;
  678. }
  679. /* !
  680. * \brief Tests SDL_HasRectIntersection() with B fully outside A
  681. *
  682. * \sa
  683. * http://wiki.libsdl.org/SDL_HasRectIntersection
  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_HasRectIntersection(&rectA, &rectB);
  700. validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
  701. return TEST_COMPLETED;
  702. }
  703. /* !
  704. * \brief Tests SDL_HasRectIntersection() with B partially intersecting A
  705. *
  706. * \sa
  707. * http://wiki.libsdl.org/SDL_HasRectIntersection
  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_HasRectIntersection(&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_HasRectIntersection(&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_HasRectIntersection(&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_HasRectIntersection(&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_HasRectIntersection(&rectA, &rectB);
  760. validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
  761. return TEST_COMPLETED;
  762. }
  763. /* !
  764. * \brief Tests SDL_HasRectIntersection() with 1x1 pixel sized rectangles
  765. *
  766. * \sa
  767. * http://wiki.libsdl.org/SDL_HasRectIntersection
  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_HasRectIntersection(&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_HasRectIntersection(&rectA, &rectB);
  799. validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
  800. }
  801. }
  802. }
  803. return TEST_COMPLETED;
  804. }
  805. /* !
  806. * \brief Tests SDL_HasRectIntersection() with empty rectangles
  807. *
  808. * \sa
  809. * http://wiki.libsdl.org/SDL_HasRectIntersection
  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_HasRectIntersection(&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_HasRectIntersection(&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_HasRectIntersection(&rectA, &rectB);
  855. validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
  856. return TEST_COMPLETED;
  857. }
  858. /* !
  859. * \brief Negative tests against SDL_HasRectIntersection() with invalid parameters
  860. *
  861. * \sa
  862. * http://wiki.libsdl.org/SDL_HasRectIntersection
  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_HasRectIntersection((SDL_Rect *)NULL, &rectB);
  871. SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
  872. intersection = SDL_HasRectIntersection(&rectA, (SDL_Rect *)NULL);
  873. SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL");
  874. intersection = SDL_HasRectIntersection((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_GetRectEnclosingPoints() without clipping
  880. *
  881. * \sa
  882. * http://wiki.libsdl.org/SDL_GetRectEnclosingPoints
  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_GetRectEnclosingPoints((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_GetRectEnclosingPoints((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_GetRectEnclosingPoints() with repeated input points
  953. *
  954. * \sa
  955. * http://wiki.libsdl.org/SDL_GetRectEnclosingPoints
  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_GetRectEnclosingPoints((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_GetRectEnclosingPoints((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_GetRectEnclosingPoints() with clipping
  1032. *
  1033. * \sa
  1034. * http://wiki.libsdl.org/SDL_GetRectEnclosingPoints
  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_GetRectEnclosingPoints((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_GetRectEnclosingPoints((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_GetRectEnclosingPoints((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_GetRectEnclosingPoints() with invalid parameters
  1132. *
  1133. * \sa
  1134. * http://wiki.libsdl.org/SDL_GetRectEnclosingPoints
  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_GetRectEnclosingPoints((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_GetRectEnclosingPoints((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_GetRectEnclosingPoints((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_GetRectEnclosingPoints((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_GetRectUnion() where rect B is outside rect A
  1157. *
  1158. * \sa
  1159. * http://wiki.libsdl.org/SDL_GetRectUnion
  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_GetRectUnion(&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_GetRectUnion(&rectA, &rectB, &result);
  1224. validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  1225. }
  1226. }
  1227. }
  1228. return TEST_COMPLETED;
  1229. }
  1230. /* !
  1231. * \brief Tests SDL_GetRectUnion() where rect A or rect B are empty
  1232. *
  1233. * \sa
  1234. * http://wiki.libsdl.org/SDL_GetRectUnion
  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_GetRectUnion(&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_GetRectUnion(&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_GetRectUnion(&rectA, &rectB, &result);
  1287. validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  1288. return TEST_COMPLETED;
  1289. }
  1290. /* !
  1291. * \brief Tests SDL_GetRectUnion() where rect B is inside rect A
  1292. *
  1293. * \sa
  1294. * http://wiki.libsdl.org/SDL_GetRectUnion
  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_GetRectUnion(&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_GetRectUnion(&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_GetRectUnion(&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_GetRectUnion() with invalid parameters
  1359. *
  1360. * \sa
  1361. * http://wiki.libsdl.org/SDL_GetRectUnion
  1362. */
  1363. int rect_testUnionRectParam(void *arg)
  1364. {
  1365. SDL_Rect rectA, rectB = { 0 };
  1366. SDL_Rect result;
  1367. /* invalid parameter combinations */
  1368. SDL_GetRectUnion((SDL_Rect *)NULL, &rectB, &result);
  1369. SDLTest_AssertPass("Check that function returns when 1st parameter is NULL");
  1370. SDL_GetRectUnion(&rectA, (SDL_Rect *)NULL, &result);
  1371. SDLTest_AssertPass("Check that function returns when 2nd parameter is NULL");
  1372. SDL_GetRectUnion(&rectA, &rectB, (SDL_Rect *)NULL);
  1373. SDLTest_AssertPass("Check that function returns when 3rd parameter is NULL");
  1374. SDL_GetRectUnion((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
  1375. SDLTest_AssertPass("Check that function returns when 1st and 3rd parameter are NULL");
  1376. SDL_GetRectUnion(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
  1377. SDLTest_AssertPass("Check that function returns when 2nd and 3rd parameter are NULL");
  1378. SDL_GetRectUnion((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_RectsEqual() with various inputs
  1437. *
  1438. * \sa
  1439. * http://wiki.libsdl.org/SDL_RectsEqual
  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_RectsEqual(&rectA, &rectB);
  1459. validateRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
  1460. return TEST_COMPLETED;
  1461. }
  1462. /* !
  1463. * \brief Negative tests against SDL_RectsEqual() with invalid parameters
  1464. *
  1465. * \sa
  1466. * http://wiki.libsdl.org/SDL_RectsEqual
  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_RectsEqual(NULL, &rectB);
  1484. SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
  1485. result = SDL_RectsEqual(&rectA, NULL);
  1486. SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
  1487. result = SDL_RectsEqual(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_RectsEqualFloat() with various inputs
  1493. *
  1494. * \sa
  1495. * http://wiki.libsdl.org/SDL_RectsEqualFloat
  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_RectsEqualFloat(&rectA, &rectB);
  1515. validateFRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
  1516. return TEST_COMPLETED;
  1517. }
  1518. /* !
  1519. * \brief Negative tests against SDL_RectsEqualFloat() with invalid parameters
  1520. *
  1521. * \sa
  1522. * http://wiki.libsdl.org/SDL_RectsEqualFloat
  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_RectsEqualFloat(NULL, &rectB);
  1540. SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
  1541. result = SDL_RectsEqualFloat(&rectA, NULL);
  1542. SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
  1543. result = SDL_RectsEqualFloat(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_GetRectAndLineIntersection */
  1550. static const SDLTest_TestCaseReference rectTest1 = {
  1551. (SDLTest_TestCaseFp)rect_testIntersectRectAndLine, "rect_testIntersectRectAndLine", "Tests SDL_GetRectAndLineIntersection clipping cases", TEST_ENABLED
  1552. };
  1553. static const SDLTest_TestCaseReference rectTest2 = {
  1554. (SDLTest_TestCaseFp)rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_GetRectAndLineIntersection with line fully contained in rect", TEST_ENABLED
  1555. };
  1556. static const SDLTest_TestCaseReference rectTest3 = {
  1557. (SDLTest_TestCaseFp)rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_GetRectAndLineIntersection with line fully outside of rect", TEST_ENABLED
  1558. };
  1559. static const SDLTest_TestCaseReference rectTest4 = {
  1560. (SDLTest_TestCaseFp)rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_GetRectAndLineIntersection with empty rectangle ", TEST_ENABLED
  1561. };
  1562. static const SDLTest_TestCaseReference rectTest5 = {
  1563. (SDLTest_TestCaseFp)rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_GetRectAndLineIntersection with invalid parameters", TEST_ENABLED
  1564. };
  1565. /* SDL_GetRectIntersection */
  1566. static const SDLTest_TestCaseReference rectTest6 = {
  1567. (SDLTest_TestCaseFp)rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_GetRectIntersection with B fully contained in A", TEST_ENABLED
  1568. };
  1569. static const SDLTest_TestCaseReference rectTest7 = {
  1570. (SDLTest_TestCaseFp)rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_GetRectIntersection with B fully outside of A", TEST_ENABLED
  1571. };
  1572. static const SDLTest_TestCaseReference rectTest8 = {
  1573. (SDLTest_TestCaseFp)rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_GetRectIntersection with B partially intersecting A", TEST_ENABLED
  1574. };
  1575. static const SDLTest_TestCaseReference rectTest9 = {
  1576. (SDLTest_TestCaseFp)rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_GetRectIntersection with 1x1 sized rectangles", TEST_ENABLED
  1577. };
  1578. static const SDLTest_TestCaseReference rectTest10 = {
  1579. (SDLTest_TestCaseFp)rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_GetRectIntersection with empty rectangles", TEST_ENABLED
  1580. };
  1581. static const SDLTest_TestCaseReference rectTest11 = {
  1582. (SDLTest_TestCaseFp)rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_GetRectIntersection with invalid parameters", TEST_ENABLED
  1583. };
  1584. /* SDL_HasRectIntersection */
  1585. static const SDLTest_TestCaseReference rectTest12 = {
  1586. (SDLTest_TestCaseFp)rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasRectIntersection with B fully contained in A", TEST_ENABLED
  1587. };
  1588. static const SDLTest_TestCaseReference rectTest13 = {
  1589. (SDLTest_TestCaseFp)rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasRectIntersection with B fully outside of A", TEST_ENABLED
  1590. };
  1591. static const SDLTest_TestCaseReference rectTest14 = {
  1592. (SDLTest_TestCaseFp)rect_testHasIntersectionPartial, "rect_testHasIntersectionPartial", "Tests SDL_HasRectIntersection with B partially intersecting A", TEST_ENABLED
  1593. };
  1594. static const SDLTest_TestCaseReference rectTest15 = {
  1595. (SDLTest_TestCaseFp)rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasRectIntersection with 1x1 sized rectangles", TEST_ENABLED
  1596. };
  1597. static const SDLTest_TestCaseReference rectTest16 = {
  1598. (SDLTest_TestCaseFp)rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasRectIntersection with empty rectangles", TEST_ENABLED
  1599. };
  1600. static const SDLTest_TestCaseReference rectTest17 = {
  1601. (SDLTest_TestCaseFp)rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasRectIntersection with invalid parameters", TEST_ENABLED
  1602. };
  1603. /* SDL_GetRectEnclosingPoints */
  1604. static const SDLTest_TestCaseReference rectTest18 = {
  1605. (SDLTest_TestCaseFp)rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_GetRectEnclosingPoints without clipping", TEST_ENABLED
  1606. };
  1607. static const SDLTest_TestCaseReference rectTest19 = {
  1608. (SDLTest_TestCaseFp)rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_GetRectEnclosingPoints with clipping", TEST_ENABLED
  1609. };
  1610. static const SDLTest_TestCaseReference rectTest20 = {
  1611. (SDLTest_TestCaseFp)rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_GetRectEnclosingPoints with repeated input", TEST_ENABLED
  1612. };
  1613. static const SDLTest_TestCaseReference rectTest21 = {
  1614. (SDLTest_TestCaseFp)rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_GetRectEnclosingPoints with invalid parameters", TEST_ENABLED
  1615. };
  1616. /* SDL_GetRectUnion */
  1617. static const SDLTest_TestCaseReference rectTest22 = {
  1618. (SDLTest_TestCaseFp)rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_GetRectUnion 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_GetRectUnion 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_GetRectUnion 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_GetRectUnion 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_RectsEqual */
  1637. static const SDLTest_TestCaseReference rectTest28 = {
  1638. (SDLTest_TestCaseFp)rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectsEqual with various inputs", TEST_ENABLED
  1639. };
  1640. static const SDLTest_TestCaseReference rectTest29 = {
  1641. (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectsEqual with invalid parameters", TEST_ENABLED
  1642. };
  1643. /* SDL_RectsEqualFloat */
  1644. static const SDLTest_TestCaseReference rectTest30 = {
  1645. (SDLTest_TestCaseFp)rect_testFRectEquals, "rect_testFRectEquals", "Tests SDL_RectsEqualFloat with various inputs", TEST_ENABLED
  1646. };
  1647. static const SDLTest_TestCaseReference rectTest31 = {
  1648. (SDLTest_TestCaseFp)rect_testFRectEqualsParam, "rect_testFRectEqualsParam", "Negative tests against SDL_RectsEqualFloat 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. };