testautomation_rect.c 81 KB

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