1
0

testautomation_rect.c 69 KB

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