testautomation_sdltest.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. /**
  2. * SDL_test test suite
  3. */
  4. /* Visual Studio 2008 doesn't have stdint.h */
  5. #if defined(_MSC_VER) && _MSC_VER <= 1500
  6. #define UINT8_MAX ~(Uint8)0
  7. #define UINT16_MAX ~(Uint16)0
  8. #define UINT32_MAX ~(Uint32)0
  9. #define UINT64_MAX ~(Uint64)0
  10. #else
  11. #include <stdint.h>
  12. #endif
  13. #include <stdio.h>
  14. #include <limits.h>
  15. #include <float.h>
  16. #include <ctype.h>
  17. #include "SDL.h"
  18. #include "SDL_test.h"
  19. /* Test case functions */
  20. /* Forward declarations for internal harness functions */
  21. extern char *SDLTest_GenerateRunSeed(const int length);
  22. /**
  23. * @brief Calls to SDLTest_GenerateRunSeed()
  24. */
  25. int
  26. sdltest_generateRunSeed(void *arg)
  27. {
  28. char* result;
  29. int i, l;
  30. for (i = 1; i <= 10; i += 3) {
  31. result = SDLTest_GenerateRunSeed((const int)i);
  32. SDLTest_AssertPass("Call to SDLTest_GenerateRunSeed()");
  33. SDLTest_AssertCheck(result != NULL, "Verify returned value is not NULL");
  34. if (result != NULL) {
  35. l = SDL_strlen(result);
  36. SDLTest_AssertCheck(l == i, "Verify length of returned value is %d, got: %d", i, l);
  37. SDL_free(result);
  38. }
  39. }
  40. /* Negative cases */
  41. for (i = -2; i <= 0; i++) {
  42. result = SDLTest_GenerateRunSeed((const int)i);
  43. SDLTest_AssertPass("Call to SDLTest_GenerateRunSeed()");
  44. SDLTest_AssertCheck(result == NULL, "Verify returned value is not NULL");
  45. }
  46. return TEST_COMPLETED;
  47. }
  48. /**
  49. * @brief Calls to SDLTest_GetFuzzerInvocationCount()
  50. */
  51. int
  52. sdltest_getFuzzerInvocationCount(void *arg)
  53. {
  54. Uint8 result;
  55. int fuzzerCount1, fuzzerCount2;
  56. fuzzerCount1 = SDLTest_GetFuzzerInvocationCount();
  57. SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()");
  58. SDLTest_AssertCheck(fuzzerCount1 >= 0, "Verify returned value, expected: >=0, got: %d", fuzzerCount1);
  59. result = SDLTest_RandomUint8();
  60. SDLTest_AssertPass("Call to SDLTest_RandomUint8(), returned %d", result);
  61. fuzzerCount2 = SDLTest_GetFuzzerInvocationCount();
  62. SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()");
  63. SDLTest_AssertCheck(fuzzerCount2 > fuzzerCount1, "Verify returned value, expected: >%d, got: %d", fuzzerCount1, fuzzerCount2);
  64. return TEST_COMPLETED;
  65. }
  66. /**
  67. * @brief Calls to random number generators
  68. */
  69. int
  70. sdltest_randomNumber(void *arg)
  71. {
  72. Sint64 result;
  73. Uint64 uresult;
  74. double dresult;
  75. Uint64 umax;
  76. Sint64 min, max;
  77. result = (Sint64)SDLTest_RandomUint8();
  78. umax = (1 << 8) - 1;
  79. SDLTest_AssertPass("Call to SDLTest_RandomUint8");
  80. SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
  81. result = (Sint64)SDLTest_RandomSint8();
  82. min = 0 - (1 << 7);
  83. max = (1 << 7) - 1;
  84. SDLTest_AssertPass("Call to SDLTest_RandomSint8");
  85. SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
  86. result = (Sint64)SDLTest_RandomUint16();
  87. umax = (1 << 16) - 1;
  88. SDLTest_AssertPass("Call to SDLTest_RandomUint16");
  89. SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
  90. result = (Sint64)SDLTest_RandomSint16();
  91. min = 0 - (1 << 15);
  92. max = (1 << 15) - 1;
  93. SDLTest_AssertPass("Call to SDLTest_RandomSint16");
  94. SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
  95. result = (Sint64)SDLTest_RandomUint32();
  96. umax = ((Uint64)1 << 32) - 1;
  97. SDLTest_AssertPass("Call to SDLTest_RandomUint32");
  98. SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
  99. result = (Sint64)SDLTest_RandomSint32();
  100. min = 0 - ((Sint64)1 << 31);
  101. max = ((Sint64)1 << 31) - 1;
  102. SDLTest_AssertPass("Call to SDLTest_RandomSint32");
  103. SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
  104. uresult = SDLTest_RandomUint64();
  105. SDLTest_AssertPass("Call to SDLTest_RandomUint64");
  106. result = SDLTest_RandomSint64();
  107. SDLTest_AssertPass("Call to SDLTest_RandomSint64");
  108. dresult = (double)SDLTest_RandomUnitFloat();
  109. SDLTest_AssertPass("Call to SDLTest_RandomUnitFloat");
  110. SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult);
  111. dresult = (double)SDLTest_RandomFloat();
  112. SDLTest_AssertPass("Call to SDLTest_RandomFloat");
  113. SDLTest_AssertCheck(dresult >= (double)(-FLT_MAX) && dresult <= (double)FLT_MAX, "Verify result value, expected: [%e,%e], got: %e", (double)(-FLT_MAX), (double)FLT_MAX, dresult);
  114. dresult = (double)SDLTest_RandomUnitDouble();
  115. SDLTest_AssertPass("Call to SDLTest_RandomUnitDouble");
  116. SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult);
  117. dresult = SDLTest_RandomDouble();
  118. SDLTest_AssertPass("Call to SDLTest_RandomDouble");
  119. return TEST_COMPLETED;
  120. }
  121. /*
  122. * @brief Calls to random boundary number generators for Uint8
  123. */
  124. int
  125. sdltest_randomBoundaryNumberUint8(void *arg)
  126. {
  127. const char *expectedError = "That operation is not supported";
  128. char *lastError;
  129. Uint64 uresult;
  130. /* Clean error messages */
  131. SDL_ClearError();
  132. SDLTest_AssertPass("SDL_ClearError()");
  133. /* RandomUintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */
  134. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 10, SDL_TRUE);
  135. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  136. SDLTest_AssertCheck(
  137. uresult == 10,
  138. "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult);
  139. /* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
  140. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 11, SDL_TRUE);
  141. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  142. SDLTest_AssertCheck(
  143. uresult == 10 || uresult == 11,
  144. "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult);
  145. /* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
  146. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 12, SDL_TRUE);
  147. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  148. SDLTest_AssertCheck(
  149. uresult == 10 || uresult == 11 || uresult == 12,
  150. "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult);
  151. /* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
  152. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 13, SDL_TRUE);
  153. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  154. SDLTest_AssertCheck(
  155. uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13,
  156. "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult);
  157. /* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
  158. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 20, SDL_TRUE);
  159. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  160. SDLTest_AssertCheck(
  161. uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
  162. "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
  163. /* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
  164. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(20, 10, SDL_TRUE);
  165. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  166. SDLTest_AssertCheck(
  167. uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
  168. "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
  169. /* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
  170. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(1, 20, SDL_FALSE);
  171. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  172. SDLTest_AssertCheck(
  173. uresult == 0 || uresult == 21,
  174. "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult);
  175. /* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */
  176. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(0, 99, SDL_FALSE);
  177. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  178. SDLTest_AssertCheck(
  179. uresult == 100,
  180. "Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult);
  181. /* RandomUintXBoundaryValue(1, 0xff, SDL_FALSE) returns 0 (no error) */
  182. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(1, 255, SDL_FALSE);
  183. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  184. SDLTest_AssertCheck(
  185. uresult == 0,
  186. "Validate result value for parameters (1,255,SDL_FALSE); expected: 0, got: %lld", uresult);
  187. lastError = (char *)SDL_GetError();
  188. SDLTest_AssertPass("SDL_GetError()");
  189. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  190. /* RandomUintXBoundaryValue(0, 0xfe, SDL_FALSE) returns 0xff (no error) */
  191. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(0, 254, SDL_FALSE);
  192. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  193. SDLTest_AssertCheck(
  194. uresult == 0xff,
  195. "Validate result value for parameters (0,254,SDL_FALSE); expected: 0xff, got: %lld", uresult);
  196. lastError = (char *)SDL_GetError();
  197. SDLTest_AssertPass("SDL_GetError()");
  198. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  199. /* RandomUintXBoundaryValue(0, 0xff, SDL_FALSE) returns 0 (sets error) */
  200. uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(0, 255, SDL_FALSE);
  201. SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
  202. SDLTest_AssertCheck(
  203. uresult == 0,
  204. "Validate result value for parameters(0,255,SDL_FALSE); expected: 0, got: %lld", uresult);
  205. lastError = (char *)SDL_GetError();
  206. SDLTest_AssertPass("SDL_GetError()");
  207. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  208. "SDL_GetError(): expected message '%s', was message: '%s'",
  209. expectedError,
  210. lastError);
  211. /* Clear error messages */
  212. SDL_ClearError();
  213. SDLTest_AssertPass("SDL_ClearError()");
  214. return TEST_COMPLETED;
  215. }
  216. /*
  217. * @brief Calls to random boundary number generators for Uint16
  218. */
  219. int
  220. sdltest_randomBoundaryNumberUint16(void *arg)
  221. {
  222. const char *expectedError = "That operation is not supported";
  223. char *lastError;
  224. Uint64 uresult;
  225. /* Clean error messages */
  226. SDL_ClearError();
  227. SDLTest_AssertPass("SDL_ClearError()");
  228. /* RandomUintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */
  229. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 10, SDL_TRUE);
  230. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  231. SDLTest_AssertCheck(
  232. uresult == 10,
  233. "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult);
  234. /* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
  235. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 11, SDL_TRUE);
  236. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  237. SDLTest_AssertCheck(
  238. uresult == 10 || uresult == 11,
  239. "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult);
  240. /* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
  241. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 12, SDL_TRUE);
  242. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  243. SDLTest_AssertCheck(
  244. uresult == 10 || uresult == 11 || uresult == 12,
  245. "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult);
  246. /* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
  247. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 13, SDL_TRUE);
  248. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  249. SDLTest_AssertCheck(
  250. uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13,
  251. "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult);
  252. /* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
  253. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 20, SDL_TRUE);
  254. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  255. SDLTest_AssertCheck(
  256. uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
  257. "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
  258. /* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
  259. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(20, 10, SDL_TRUE);
  260. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  261. SDLTest_AssertCheck(
  262. uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
  263. "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
  264. /* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
  265. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(1, 20, SDL_FALSE);
  266. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  267. SDLTest_AssertCheck(
  268. uresult == 0 || uresult == 21,
  269. "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult);
  270. /* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */
  271. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(0, 99, SDL_FALSE);
  272. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  273. SDLTest_AssertCheck(
  274. uresult == 100,
  275. "Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult);
  276. /* RandomUintXBoundaryValue(1, 0xffff, SDL_FALSE) returns 0 (no error) */
  277. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(1, 0xffff, SDL_FALSE);
  278. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  279. SDLTest_AssertCheck(
  280. uresult == 0,
  281. "Validate result value for parameters (1,0xffff,SDL_FALSE); expected: 0, got: %lld", uresult);
  282. lastError = (char *)SDL_GetError();
  283. SDLTest_AssertPass("SDL_GetError()");
  284. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  285. /* RandomUintXBoundaryValue(0, 0xfffe, SDL_FALSE) returns 0xffff (no error) */
  286. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(0, 0xfffe, SDL_FALSE);
  287. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  288. SDLTest_AssertCheck(
  289. uresult == 0xffff,
  290. "Validate result value for parameters (0,0xfffe,SDL_FALSE); expected: 0xffff, got: %lld", uresult);
  291. lastError = (char *)SDL_GetError();
  292. SDLTest_AssertPass("SDL_GetError()");
  293. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  294. /* RandomUintXBoundaryValue(0, 0xffff, SDL_FALSE) returns 0 (sets error) */
  295. uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(0, 0xffff, SDL_FALSE);
  296. SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
  297. SDLTest_AssertCheck(
  298. uresult == 0,
  299. "Validate result value for parameters(0,0xffff,SDL_FALSE); expected: 0, got: %lld", uresult);
  300. lastError = (char *)SDL_GetError();
  301. SDLTest_AssertPass("SDL_GetError()");
  302. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  303. "SDL_GetError(): expected message '%s', was message: '%s'",
  304. expectedError,
  305. lastError);
  306. /* Clear error messages */
  307. SDL_ClearError();
  308. SDLTest_AssertPass("SDL_ClearError()");
  309. return TEST_COMPLETED;
  310. }
  311. /*
  312. * @brief Calls to random boundary number generators for Uint32
  313. */
  314. int
  315. sdltest_randomBoundaryNumberUint32(void *arg)
  316. {
  317. const char *expectedError = "That operation is not supported";
  318. char *lastError;
  319. Uint64 uresult;
  320. /* Clean error messages */
  321. SDL_ClearError();
  322. SDLTest_AssertPass("SDL_ClearError()");
  323. /* RandomUintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */
  324. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 10, SDL_TRUE);
  325. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  326. SDLTest_AssertCheck(
  327. uresult == 10,
  328. "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult);
  329. /* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
  330. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 11, SDL_TRUE);
  331. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  332. SDLTest_AssertCheck(
  333. uresult == 10 || uresult == 11,
  334. "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult);
  335. /* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
  336. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 12, SDL_TRUE);
  337. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  338. SDLTest_AssertCheck(
  339. uresult == 10 || uresult == 11 || uresult == 12,
  340. "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult);
  341. /* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
  342. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 13, SDL_TRUE);
  343. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  344. SDLTest_AssertCheck(
  345. uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13,
  346. "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult);
  347. /* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
  348. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 20, SDL_TRUE);
  349. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  350. SDLTest_AssertCheck(
  351. uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
  352. "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
  353. /* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
  354. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(20, 10, SDL_TRUE);
  355. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  356. SDLTest_AssertCheck(
  357. uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
  358. "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
  359. /* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
  360. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(1, 20, SDL_FALSE);
  361. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  362. SDLTest_AssertCheck(
  363. uresult == 0 || uresult == 21,
  364. "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult);
  365. /* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */
  366. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(0, 99, SDL_FALSE);
  367. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  368. SDLTest_AssertCheck(
  369. uresult == 100,
  370. "Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult);
  371. /* RandomUintXBoundaryValue(1, 0xffffffff, SDL_FALSE) returns 0 (no error) */
  372. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(1, 0xffffffff, SDL_FALSE);
  373. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  374. SDLTest_AssertCheck(
  375. uresult == 0,
  376. "Validate result value for parameters (1,0xffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
  377. lastError = (char *)SDL_GetError();
  378. SDLTest_AssertPass("SDL_GetError()");
  379. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  380. /* RandomUintXBoundaryValue(0, 0xfffffffe, SDL_FALSE) returns 0xffffffff (no error) */
  381. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(0, 0xfffffffe, SDL_FALSE);
  382. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  383. SDLTest_AssertCheck(
  384. uresult == 0xffffffff,
  385. "Validate result value for parameters (0,0xfffffffe,SDL_FALSE); expected: 0xffffffff, got: %lld", uresult);
  386. lastError = (char *)SDL_GetError();
  387. SDLTest_AssertPass("SDL_GetError()");
  388. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  389. /* RandomUintXBoundaryValue(0, 0xffffffff, SDL_FALSE) returns 0 (sets error) */
  390. uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(0, 0xffffffff, SDL_FALSE);
  391. SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
  392. SDLTest_AssertCheck(
  393. uresult == 0,
  394. "Validate result value for parameters(0,0xffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
  395. lastError = (char *)SDL_GetError();
  396. SDLTest_AssertPass("SDL_GetError()");
  397. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  398. "SDL_GetError(): expected message '%s', was message: '%s'",
  399. expectedError,
  400. lastError);
  401. /* Clear error messages */
  402. SDL_ClearError();
  403. SDLTest_AssertPass("SDL_ClearError()");
  404. return TEST_COMPLETED;
  405. }
  406. /*
  407. * @brief Calls to random boundary number generators for Uint64
  408. */
  409. int
  410. sdltest_randomBoundaryNumberUint64(void *arg)
  411. {
  412. const char *expectedError = "That operation is not supported";
  413. char *lastError;
  414. Uint64 uresult;
  415. /* Clean error messages */
  416. SDL_ClearError();
  417. SDLTest_AssertPass("SDL_ClearError()");
  418. /* RandomUintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */
  419. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 10, SDL_TRUE);
  420. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  421. SDLTest_AssertCheck(
  422. uresult == 10,
  423. "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult);
  424. /* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
  425. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 11, SDL_TRUE);
  426. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  427. SDLTest_AssertCheck(
  428. uresult == 10 || uresult == 11,
  429. "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult);
  430. /* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
  431. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 12, SDL_TRUE);
  432. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  433. SDLTest_AssertCheck(
  434. uresult == 10 || uresult == 11 || uresult == 12,
  435. "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult);
  436. /* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
  437. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 13, SDL_TRUE);
  438. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  439. SDLTest_AssertCheck(
  440. uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13,
  441. "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult);
  442. /* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
  443. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 20, SDL_TRUE);
  444. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  445. SDLTest_AssertCheck(
  446. uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
  447. "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
  448. /* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
  449. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(20, 10, SDL_TRUE);
  450. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  451. SDLTest_AssertCheck(
  452. uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
  453. "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
  454. /* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
  455. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(1, 20, SDL_FALSE);
  456. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  457. SDLTest_AssertCheck(
  458. uresult == 0 || uresult == 21,
  459. "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult);
  460. /* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */
  461. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(0, 99, SDL_FALSE);
  462. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  463. SDLTest_AssertCheck(
  464. uresult == 100,
  465. "Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult);
  466. /* RandomUintXBoundaryValue(1, 0xffffffffffffffff, SDL_FALSE) returns 0 (no error) */
  467. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(1, (Uint64)0xffffffffffffffffULL, SDL_FALSE);
  468. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  469. SDLTest_AssertCheck(
  470. uresult == 0,
  471. "Validate result value for parameters (1,0xffffffffffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
  472. lastError = (char *)SDL_GetError();
  473. SDLTest_AssertPass("SDL_GetError()");
  474. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  475. /* RandomUintXBoundaryValue(0, 0xfffffffffffffffe, SDL_FALSE) returns 0xffffffffffffffff (no error) */
  476. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(0, (Uint64)0xfffffffffffffffeULL, SDL_FALSE);
  477. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  478. SDLTest_AssertCheck(
  479. uresult == (Uint64)0xffffffffffffffffULL,
  480. "Validate result value for parameters (0,0xfffffffffffffffe,SDL_FALSE); expected: 0xffffffffffffffff, got: %lld", uresult);
  481. lastError = (char *)SDL_GetError();
  482. SDLTest_AssertPass("SDL_GetError()");
  483. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  484. /* RandomUintXBoundaryValue(0, 0xffffffffffffffff, SDL_FALSE) returns 0 (sets error) */
  485. uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(0, (Uint64)0xffffffffffffffffULL, SDL_FALSE);
  486. SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
  487. SDLTest_AssertCheck(
  488. uresult == 0,
  489. "Validate result value for parameters(0,0xffffffffffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
  490. lastError = (char *)SDL_GetError();
  491. SDLTest_AssertPass("SDL_GetError()");
  492. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  493. "SDL_GetError(): expected message '%s', was message: '%s'",
  494. expectedError,
  495. lastError);
  496. /* Clear error messages */
  497. SDL_ClearError();
  498. SDLTest_AssertPass("SDL_ClearError()");
  499. return TEST_COMPLETED;
  500. }
  501. /*
  502. * @brief Calls to random boundary number generators for Sint8
  503. */
  504. int
  505. sdltest_randomBoundaryNumberSint8(void *arg)
  506. {
  507. const char *expectedError = "That operation is not supported";
  508. char *lastError;
  509. Sint64 sresult;
  510. /* Clean error messages */
  511. SDL_ClearError();
  512. SDLTest_AssertPass("SDL_ClearError()");
  513. /* RandomSintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */
  514. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 10, SDL_TRUE);
  515. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  516. SDLTest_AssertCheck(
  517. sresult == 10,
  518. "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult);
  519. /* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
  520. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 11, SDL_TRUE);
  521. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  522. SDLTest_AssertCheck(
  523. sresult == 10 || sresult == 11,
  524. "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult);
  525. /* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
  526. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 12, SDL_TRUE);
  527. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  528. SDLTest_AssertCheck(
  529. sresult == 10 || sresult == 11 || sresult == 12,
  530. "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult);
  531. /* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
  532. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 13, SDL_TRUE);
  533. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  534. SDLTest_AssertCheck(
  535. sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13,
  536. "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult);
  537. /* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
  538. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 20, SDL_TRUE);
  539. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  540. SDLTest_AssertCheck(
  541. sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
  542. "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
  543. /* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
  544. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(20, 10, SDL_TRUE);
  545. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  546. SDLTest_AssertCheck(
  547. sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
  548. "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
  549. /* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
  550. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(1, 20, SDL_FALSE);
  551. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  552. SDLTest_AssertCheck(
  553. sresult == 0 || sresult == 21,
  554. "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult);
  555. /* RandomSintXBoundaryValue(SCHAR_MIN, 99, SDL_FALSE) returns 100 */
  556. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN, 99, SDL_FALSE);
  557. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  558. SDLTest_AssertCheck(
  559. sresult == 100,
  560. "Validate result value for parameters (SCHAR_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult);
  561. /* RandomSintXBoundaryValue(SCHAR_MIN + 1, SCHAR_MAX, SDL_FALSE) returns SCHAR_MIN (no error) */
  562. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN + 1, SCHAR_MAX, SDL_FALSE);
  563. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  564. SDLTest_AssertCheck(
  565. sresult == SCHAR_MIN,
  566. "Validate result value for parameters (SCHAR_MIN + 1,SCHAR_MAX,SDL_FALSE); expected: %d, got: %lld", SCHAR_MIN, sresult);
  567. lastError = (char *)SDL_GetError();
  568. SDLTest_AssertPass("SDL_GetError()");
  569. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  570. /* RandomSintXBoundaryValue(SCHAR_MIN, SCHAR_MAX - 1, SDL_FALSE) returns SCHAR_MAX (no error) */
  571. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN, SCHAR_MAX -1, SDL_FALSE);
  572. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  573. SDLTest_AssertCheck(
  574. sresult == SCHAR_MAX,
  575. "Validate result value for parameters (SCHAR_MIN,SCHAR_MAX - 1,SDL_FALSE); expected: %d, got: %lld", SCHAR_MAX, sresult);
  576. lastError = (char *)SDL_GetError();
  577. SDLTest_AssertPass("SDL_GetError()");
  578. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  579. /* RandomSintXBoundaryValue(SCHAR_MIN, SCHAR_MAX, SDL_FALSE) returns SCHAR_MIN (sets error) */
  580. sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN, SCHAR_MAX, SDL_FALSE);
  581. SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
  582. SDLTest_AssertCheck(
  583. sresult == SCHAR_MIN,
  584. "Validate result value for parameters(SCHAR_MIN,SCHAR_MAX,SDL_FALSE); expected: %d, got: %lld", SCHAR_MIN, sresult);
  585. lastError = (char *)SDL_GetError();
  586. SDLTest_AssertPass("SDL_GetError()");
  587. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  588. "SDL_GetError(): expected message '%s', was message: '%s'",
  589. expectedError,
  590. lastError);
  591. /* Clear error messages */
  592. SDL_ClearError();
  593. SDLTest_AssertPass("SDL_ClearError()");
  594. return TEST_COMPLETED;
  595. }
  596. /*
  597. * @brief Calls to random boundary number generators for Sint16
  598. */
  599. int
  600. sdltest_randomBoundaryNumberSint16(void *arg)
  601. {
  602. const char *expectedError = "That operation is not supported";
  603. char *lastError;
  604. Sint64 sresult;
  605. /* Clean error messages */
  606. SDL_ClearError();
  607. SDLTest_AssertPass("SDL_ClearError()");
  608. /* RandomSintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */
  609. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 10, SDL_TRUE);
  610. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  611. SDLTest_AssertCheck(
  612. sresult == 10,
  613. "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult);
  614. /* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
  615. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 11, SDL_TRUE);
  616. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  617. SDLTest_AssertCheck(
  618. sresult == 10 || sresult == 11,
  619. "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult);
  620. /* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
  621. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 12, SDL_TRUE);
  622. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  623. SDLTest_AssertCheck(
  624. sresult == 10 || sresult == 11 || sresult == 12,
  625. "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult);
  626. /* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
  627. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 13, SDL_TRUE);
  628. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  629. SDLTest_AssertCheck(
  630. sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13,
  631. "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult);
  632. /* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
  633. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 20, SDL_TRUE);
  634. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  635. SDLTest_AssertCheck(
  636. sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
  637. "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
  638. /* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
  639. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(20, 10, SDL_TRUE);
  640. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  641. SDLTest_AssertCheck(
  642. sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
  643. "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
  644. /* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
  645. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(1, 20, SDL_FALSE);
  646. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  647. SDLTest_AssertCheck(
  648. sresult == 0 || sresult == 21,
  649. "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult);
  650. /* RandomSintXBoundaryValue(SHRT_MIN, 99, SDL_FALSE) returns 100 */
  651. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN, 99, SDL_FALSE);
  652. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  653. SDLTest_AssertCheck(
  654. sresult == 100,
  655. "Validate result value for parameters (SHRT_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult);
  656. /* RandomSintXBoundaryValue(SHRT_MIN + 1, SHRT_MAX, SDL_FALSE) returns SHRT_MIN (no error) */
  657. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN + 1, SHRT_MAX, SDL_FALSE);
  658. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  659. SDLTest_AssertCheck(
  660. sresult == SHRT_MIN,
  661. "Validate result value for parameters (SHRT_MIN+1,SHRT_MAX,SDL_FALSE); expected: %d, got: %lld", SHRT_MIN, sresult);
  662. lastError = (char *)SDL_GetError();
  663. SDLTest_AssertPass("SDL_GetError()");
  664. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  665. /* RandomSintXBoundaryValue(SHRT_MIN, SHRT_MAX - 1, SDL_FALSE) returns SHRT_MAX (no error) */
  666. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN, SHRT_MAX - 1, SDL_FALSE);
  667. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  668. SDLTest_AssertCheck(
  669. sresult == SHRT_MAX,
  670. "Validate result value for parameters (SHRT_MIN,SHRT_MAX - 1,SDL_FALSE); expected: %d, got: %lld", SHRT_MAX, sresult);
  671. lastError = (char *)SDL_GetError();
  672. SDLTest_AssertPass("SDL_GetError()");
  673. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  674. /* RandomSintXBoundaryValue(SHRT_MIN, SHRT_MAX, SDL_FALSE) returns 0 (sets error) */
  675. sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN, SHRT_MAX, SDL_FALSE);
  676. SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
  677. SDLTest_AssertCheck(
  678. sresult == SHRT_MIN,
  679. "Validate result value for parameters(SHRT_MIN,SHRT_MAX,SDL_FALSE); expected: %d, got: %lld", SHRT_MIN, sresult);
  680. lastError = (char *)SDL_GetError();
  681. SDLTest_AssertPass("SDL_GetError()");
  682. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  683. "SDL_GetError(): expected message '%s', was message: '%s'",
  684. expectedError,
  685. lastError);
  686. /* Clear error messages */
  687. SDL_ClearError();
  688. SDLTest_AssertPass("SDL_ClearError()");
  689. return TEST_COMPLETED;
  690. }
  691. /*
  692. * @brief Calls to random boundary number generators for Sint32
  693. */
  694. int
  695. sdltest_randomBoundaryNumberSint32(void *arg)
  696. {
  697. const char *expectedError = "That operation is not supported";
  698. char *lastError;
  699. Sint64 sresult;
  700. #if ((ULONG_MAX) == (UINT_MAX))
  701. Sint32 long_min = LONG_MIN;
  702. Sint32 long_max = LONG_MAX;
  703. #else
  704. Sint32 long_min = INT_MIN;
  705. Sint32 long_max = INT_MAX;
  706. #endif
  707. /* Clean error messages */
  708. SDL_ClearError();
  709. SDLTest_AssertPass("SDL_ClearError()");
  710. /* RandomSintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */
  711. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 10, SDL_TRUE);
  712. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  713. SDLTest_AssertCheck(
  714. sresult == 10,
  715. "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult);
  716. /* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
  717. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 11, SDL_TRUE);
  718. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  719. SDLTest_AssertCheck(
  720. sresult == 10 || sresult == 11,
  721. "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult);
  722. /* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
  723. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 12, SDL_TRUE);
  724. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  725. SDLTest_AssertCheck(
  726. sresult == 10 || sresult == 11 || sresult == 12,
  727. "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult);
  728. /* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
  729. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 13, SDL_TRUE);
  730. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  731. SDLTest_AssertCheck(
  732. sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13,
  733. "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult);
  734. /* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
  735. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 20, SDL_TRUE);
  736. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  737. SDLTest_AssertCheck(
  738. sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
  739. "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
  740. /* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
  741. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(20, 10, SDL_TRUE);
  742. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  743. SDLTest_AssertCheck(
  744. sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
  745. "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
  746. /* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
  747. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(1, 20, SDL_FALSE);
  748. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  749. SDLTest_AssertCheck(
  750. sresult == 0 || sresult == 21,
  751. "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult);
  752. /* RandomSintXBoundaryValue(LONG_MIN, 99, SDL_FALSE) returns 100 */
  753. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min, 99, SDL_FALSE);
  754. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  755. SDLTest_AssertCheck(
  756. sresult == 100,
  757. "Validate result value for parameters (LONG_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult);
  758. /* RandomSintXBoundaryValue(LONG_MIN + 1, LONG_MAX, SDL_FALSE) returns LONG_MIN (no error) */
  759. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min + 1, long_max, SDL_FALSE);
  760. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  761. SDLTest_AssertCheck(
  762. sresult == long_min,
  763. "Validate result value for parameters (LONG_MIN+1,LONG_MAX,SDL_FALSE); expected: %d, got: %lld", long_min, sresult);
  764. lastError = (char *)SDL_GetError();
  765. SDLTest_AssertPass("SDL_GetError()");
  766. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  767. /* RandomSintXBoundaryValue(LONG_MIN, LONG_MAX - 1, SDL_FALSE) returns LONG_MAX (no error) */
  768. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min, long_max - 1, SDL_FALSE);
  769. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  770. SDLTest_AssertCheck(
  771. sresult == long_max,
  772. "Validate result value for parameters (LONG_MIN,LONG_MAX - 1,SDL_FALSE); expected: %d, got: %lld", long_max, sresult);
  773. lastError = (char *)SDL_GetError();
  774. SDLTest_AssertPass("SDL_GetError()");
  775. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  776. /* RandomSintXBoundaryValue(LONG_MIN, LONG_MAX, SDL_FALSE) returns 0 (sets error) */
  777. sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min, long_max, SDL_FALSE);
  778. SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
  779. SDLTest_AssertCheck(
  780. sresult == long_min,
  781. "Validate result value for parameters(LONG_MIN,LONG_MAX,SDL_FALSE); expected: %d, got: %lld", long_min, sresult);
  782. lastError = (char *)SDL_GetError();
  783. SDLTest_AssertPass("SDL_GetError()");
  784. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  785. "SDL_GetError(): expected message '%s', was message: '%s'",
  786. expectedError,
  787. lastError);
  788. /* Clear error messages */
  789. SDL_ClearError();
  790. SDLTest_AssertPass("SDL_ClearError()");
  791. return TEST_COMPLETED;
  792. }
  793. /*
  794. * @brief Calls to random boundary number generators for Sint64
  795. */
  796. int
  797. sdltest_randomBoundaryNumberSint64(void *arg)
  798. {
  799. const char *expectedError = "That operation is not supported";
  800. char *lastError;
  801. Sint64 sresult;
  802. /* Clean error messages */
  803. SDL_ClearError();
  804. SDLTest_AssertPass("SDL_ClearError()");
  805. /* RandomSintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */
  806. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 10, SDL_TRUE);
  807. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  808. SDLTest_AssertCheck(
  809. sresult == 10,
  810. "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult);
  811. /* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
  812. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 11, SDL_TRUE);
  813. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  814. SDLTest_AssertCheck(
  815. sresult == 10 || sresult == 11,
  816. "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult);
  817. /* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
  818. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 12, SDL_TRUE);
  819. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  820. SDLTest_AssertCheck(
  821. sresult == 10 || sresult == 11 || sresult == 12,
  822. "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult);
  823. /* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
  824. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 13, SDL_TRUE);
  825. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  826. SDLTest_AssertCheck(
  827. sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13,
  828. "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult);
  829. /* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
  830. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 20, SDL_TRUE);
  831. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  832. SDLTest_AssertCheck(
  833. sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
  834. "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
  835. /* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
  836. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(20, 10, SDL_TRUE);
  837. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  838. SDLTest_AssertCheck(
  839. sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
  840. "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
  841. /* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
  842. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(1, 20, SDL_FALSE);
  843. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  844. SDLTest_AssertCheck(
  845. sresult == 0 || sresult == 21,
  846. "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult);
  847. /* RandomSintXBoundaryValue(LLONG_MIN, 99, SDL_FALSE) returns 100 */
  848. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, 99, SDL_FALSE);
  849. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  850. SDLTest_AssertCheck(
  851. sresult == 100,
  852. "Validate result value for parameters (LLONG_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult);
  853. /* RandomSintXBoundaryValue(LLONG_MIN + 1, LLONG_MAX, SDL_FALSE) returns LLONG_MIN (no error) */
  854. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN + 1, LLONG_MAX, SDL_FALSE);
  855. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  856. SDLTest_AssertCheck(
  857. sresult == LLONG_MIN,
  858. "Validate result value for parameters (LLONG_MIN+1,LLONG_MAX,SDL_FALSE); expected: %lld, got: %lld", LLONG_MIN, sresult);
  859. lastError = (char *)SDL_GetError();
  860. SDLTest_AssertPass("SDL_GetError()");
  861. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  862. /* RandomSintXBoundaryValue(LLONG_MIN, LLONG_MAX - 1, SDL_FALSE) returns LLONG_MAX (no error) */
  863. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, LLONG_MAX - 1, SDL_FALSE);
  864. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  865. SDLTest_AssertCheck(
  866. sresult == LLONG_MAX,
  867. "Validate result value for parameters (LLONG_MIN,LLONG_MAX - 1,SDL_FALSE); expected: %lld, got: %lld", LLONG_MAX, sresult);
  868. lastError = (char *)SDL_GetError();
  869. SDLTest_AssertPass("SDL_GetError()");
  870. SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
  871. /* RandomSintXBoundaryValue(LLONG_MIN, LLONG_MAX, SDL_FALSE) returns 0 (sets error) */
  872. sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, LLONG_MAX, SDL_FALSE);
  873. SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
  874. SDLTest_AssertCheck(
  875. sresult == LLONG_MIN,
  876. "Validate result value for parameters(LLONG_MIN,LLONG_MAX,SDL_FALSE); expected: %lld, got: %lld", LLONG_MIN, sresult);
  877. lastError = (char *)SDL_GetError();
  878. SDLTest_AssertPass("SDL_GetError()");
  879. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  880. "SDL_GetError(): expected message '%s', was message: '%s'",
  881. expectedError,
  882. lastError);
  883. /* Clear error messages */
  884. SDL_ClearError();
  885. SDLTest_AssertPass("SDL_ClearError()");
  886. return TEST_COMPLETED;
  887. }
  888. /**
  889. * @brief Calls to SDLTest_RandomIntegerInRange
  890. */
  891. int
  892. sdltest_randomIntegerInRange(void *arg)
  893. {
  894. Sint32 min, max;
  895. Sint32 result;
  896. #if ((ULONG_MAX) == (UINT_MAX))
  897. Sint32 long_min = LONG_MIN;
  898. Sint32 long_max = LONG_MAX;
  899. #else
  900. Sint32 long_min = INT_MIN;
  901. Sint32 long_max = INT_MAX;
  902. #endif
  903. /* Standard range */
  904. min = (Sint32)SDLTest_RandomSint16();
  905. max = min + (Sint32)SDLTest_RandomUint8() + 2;
  906. result = SDLTest_RandomIntegerInRange(min, max);
  907. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(min,max)");
  908. SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result);
  909. /* One Range */
  910. min = (Sint32)SDLTest_RandomSint16();
  911. max = min + 1;
  912. result = SDLTest_RandomIntegerInRange(min, max);
  913. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(min,min+1)");
  914. SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result);
  915. /* Zero range */
  916. min = (Sint32)SDLTest_RandomSint16();
  917. max = min;
  918. result = SDLTest_RandomIntegerInRange(min, max);
  919. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(min,min)");
  920. SDLTest_AssertCheck(min == result, "Validated returned value; expected: %d, got: %d", min, result);
  921. /* Zero range at zero */
  922. min = 0;
  923. max = 0;
  924. result = SDLTest_RandomIntegerInRange(min, max);
  925. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(0,0)");
  926. SDLTest_AssertCheck(result == 0, "Validated returned value; expected: 0, got: %d", min, max, result);
  927. /* Swapped min-max */
  928. min = (Sint32)SDLTest_RandomSint16();
  929. max = min + (Sint32)SDLTest_RandomUint8() + 2;
  930. result = SDLTest_RandomIntegerInRange(max, min);
  931. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(max,min)");
  932. SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result);
  933. /* Range with min at integer limit */
  934. min = long_min;
  935. max = long_max + (Sint32)SDLTest_RandomSint16();
  936. result = SDLTest_RandomIntegerInRange(min, max);
  937. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,...)");
  938. SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result);
  939. /* Range with max at integer limit */
  940. min = long_min - (Sint32)SDLTest_RandomSint16();;
  941. max = long_max;
  942. result = SDLTest_RandomIntegerInRange(min, max);
  943. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(...,SINT32_MAX)");
  944. SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result);
  945. /* Full integer range */
  946. min = long_min;
  947. max = long_max;
  948. result = SDLTest_RandomIntegerInRange(min, max);
  949. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,SINT32_MAX)");
  950. SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result);
  951. return TEST_COMPLETED;
  952. }
  953. /**
  954. * @brief Calls to SDLTest_RandomAsciiString
  955. */
  956. int
  957. sdltest_randomAsciiString(void *arg)
  958. {
  959. char* result;
  960. int len;
  961. int nonAsciiCharacters;
  962. int i;
  963. result = SDLTest_RandomAsciiString();
  964. SDLTest_AssertPass("Call to SDLTest_RandomAsciiString()");
  965. SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
  966. if (result != NULL) {
  967. len = SDL_strlen(result);
  968. SDLTest_AssertCheck(len >= 0 && len <= 255, "Validate that result length; expected: len=[1,255], got: %d", len);
  969. nonAsciiCharacters = 0;
  970. for (i=0; i<len; i++) {
  971. if (iscntrl(result[i])) {
  972. nonAsciiCharacters++;
  973. }
  974. }
  975. SDLTest_AssertCheck(nonAsciiCharacters == 0, "Validate that result does not contain non-Ascii characters, got: %d", nonAsciiCharacters);
  976. if (nonAsciiCharacters) {
  977. SDLTest_LogError("Invalid result from generator: '%s'", result);
  978. }
  979. SDL_free(result);
  980. }
  981. return TEST_COMPLETED;
  982. }
  983. /**
  984. * @brief Calls to SDLTest_RandomAsciiStringWithMaximumLength
  985. */
  986. int
  987. sdltest_randomAsciiStringWithMaximumLength(void *arg)
  988. {
  989. const char* expectedError = "Parameter 'maxLength' is invalid";
  990. char* lastError;
  991. char* result;
  992. int targetLen;
  993. int len;
  994. int nonAsciiCharacters;
  995. int i;
  996. targetLen = 16 + SDLTest_RandomUint8();
  997. result = SDLTest_RandomAsciiStringWithMaximumLength(targetLen);
  998. SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", targetLen);
  999. SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
  1000. if (result != NULL) {
  1001. len = SDL_strlen(result);
  1002. SDLTest_AssertCheck(len >= 0 && len <= targetLen, "Validate that result length; expected: len=[1,%d], got: %d", targetLen, len);
  1003. nonAsciiCharacters = 0;
  1004. for (i=0; i<len; i++) {
  1005. if (iscntrl(result[i])) {
  1006. nonAsciiCharacters++;
  1007. }
  1008. }
  1009. SDLTest_AssertCheck(nonAsciiCharacters == 0, "Validate that result does not contain non-Ascii characters, got: %d", nonAsciiCharacters);
  1010. if (nonAsciiCharacters) {
  1011. SDLTest_LogError("Invalid result from generator: '%s'", result);
  1012. }
  1013. SDL_free(result);
  1014. }
  1015. /* Negative test */
  1016. targetLen = 0;
  1017. result = SDLTest_RandomAsciiStringWithMaximumLength(targetLen);
  1018. SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", targetLen);
  1019. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1020. lastError = (char *)SDL_GetError();
  1021. SDLTest_AssertPass("SDL_GetError()");
  1022. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  1023. "SDL_GetError(): expected message '%s', was message: '%s'",
  1024. expectedError,
  1025. lastError);
  1026. /* Clear error messages */
  1027. SDL_ClearError();
  1028. SDLTest_AssertPass("SDL_ClearError()");
  1029. return TEST_COMPLETED;
  1030. }
  1031. /**
  1032. * @brief Calls to SDLTest_RandomAsciiStringOfSize
  1033. */
  1034. int
  1035. sdltest_randomAsciiStringOfSize(void *arg)
  1036. {
  1037. const char* expectedError = "Parameter 'size' is invalid";
  1038. char* lastError;
  1039. char* result;
  1040. int targetLen;
  1041. int len;
  1042. int nonAsciiCharacters;
  1043. int i;
  1044. /* Positive test */
  1045. targetLen = 16 + SDLTest_RandomUint8();
  1046. result = SDLTest_RandomAsciiStringOfSize(targetLen);
  1047. SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", targetLen);
  1048. SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
  1049. if (result != NULL) {
  1050. len = SDL_strlen(result);
  1051. SDLTest_AssertCheck(len == targetLen, "Validate that result length; expected: len=%d, got: %d", targetLen, len);
  1052. nonAsciiCharacters = 0;
  1053. for (i=0; i<len; i++) {
  1054. if (iscntrl(result[i])) {
  1055. nonAsciiCharacters++;
  1056. }
  1057. }
  1058. SDLTest_AssertCheck(nonAsciiCharacters == 0, "Validate that result does not contain non-ASCII characters, got: %d", nonAsciiCharacters);
  1059. if (nonAsciiCharacters) {
  1060. SDLTest_LogError("Invalid result from generator: '%s'", result);
  1061. }
  1062. SDL_free(result);
  1063. }
  1064. /* Negative test */
  1065. targetLen = 0;
  1066. result = SDLTest_RandomAsciiStringOfSize(targetLen);
  1067. SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", targetLen);
  1068. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1069. lastError = (char *)SDL_GetError();
  1070. SDLTest_AssertPass("SDL_GetError()");
  1071. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  1072. "SDL_GetError(): expected message '%s', was message: '%s'",
  1073. expectedError,
  1074. lastError);
  1075. /* Clear error messages */
  1076. SDL_ClearError();
  1077. SDLTest_AssertPass("SDL_ClearError()");
  1078. return TEST_COMPLETED;
  1079. }
  1080. /* ================= Test References ================== */
  1081. /* SDL_test test cases */
  1082. static const SDLTest_TestCaseReference sdltestTest1 =
  1083. { (SDLTest_TestCaseFp)sdltest_getFuzzerInvocationCount, "sdltest_getFuzzerInvocationCount", "Call to sdltest_GetFuzzerInvocationCount", TEST_ENABLED };
  1084. static const SDLTest_TestCaseReference sdltestTest2 =
  1085. { (SDLTest_TestCaseFp)sdltest_randomNumber, "sdltest_randomNumber", "Calls to random number generators", TEST_ENABLED };
  1086. static const SDLTest_TestCaseReference sdltestTest3 =
  1087. { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberUint8, "sdltest_randomBoundaryNumberUint8", "Calls to random boundary number generators for Uint8", TEST_ENABLED };
  1088. static const SDLTest_TestCaseReference sdltestTest4 =
  1089. { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberUint16, "sdltest_randomBoundaryNumberUint16", "Calls to random boundary number generators for Uint16", TEST_ENABLED };
  1090. static const SDLTest_TestCaseReference sdltestTest5 =
  1091. { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberUint32, "sdltest_randomBoundaryNumberUint32", "Calls to random boundary number generators for Uint32", TEST_ENABLED };
  1092. static const SDLTest_TestCaseReference sdltestTest6 =
  1093. { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberUint64, "sdltest_randomBoundaryNumberUint64", "Calls to random boundary number generators for Uint64", TEST_ENABLED };
  1094. static const SDLTest_TestCaseReference sdltestTest7 =
  1095. { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberSint8, "sdltest_randomBoundaryNumberSint8", "Calls to random boundary number generators for Sint8", TEST_ENABLED };
  1096. static const SDLTest_TestCaseReference sdltestTest8 =
  1097. { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberSint16, "sdltest_randomBoundaryNumberSint16", "Calls to random boundary number generators for Sint16", TEST_ENABLED };
  1098. static const SDLTest_TestCaseReference sdltestTest9 =
  1099. { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberSint32, "sdltest_randomBoundaryNumberSint32", "Calls to random boundary number generators for Sint32", TEST_ENABLED };
  1100. static const SDLTest_TestCaseReference sdltestTest10 =
  1101. { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberSint64, "sdltest_randomBoundaryNumberSint64", "Calls to random boundary number generators for Sint64", TEST_ENABLED };
  1102. static const SDLTest_TestCaseReference sdltestTest11 =
  1103. { (SDLTest_TestCaseFp)sdltest_randomIntegerInRange, "sdltest_randomIntegerInRange", "Calls to ranged random number generator", TEST_ENABLED };
  1104. static const SDLTest_TestCaseReference sdltestTest12 =
  1105. { (SDLTest_TestCaseFp)sdltest_randomAsciiString, "sdltest_randomAsciiString", "Calls to default ASCII string generator", TEST_ENABLED };
  1106. static const SDLTest_TestCaseReference sdltestTest13 =
  1107. { (SDLTest_TestCaseFp)sdltest_randomAsciiStringWithMaximumLength, "sdltest_randomAsciiStringWithMaximumLength", "Calls to random maximum length ASCII string generator", TEST_ENABLED };
  1108. static const SDLTest_TestCaseReference sdltestTest14 =
  1109. { (SDLTest_TestCaseFp)sdltest_randomAsciiStringOfSize, "sdltest_randomAsciiStringOfSize", "Calls to fixed size ASCII string generator", TEST_ENABLED };
  1110. static const SDLTest_TestCaseReference sdltestTest15 =
  1111. { (SDLTest_TestCaseFp)sdltest_generateRunSeed, "sdltest_generateRunSeed", "Checks internal harness function SDLTest_GenerateRunSeed", TEST_ENABLED };
  1112. /* Sequence of SDL_test test cases */
  1113. static const SDLTest_TestCaseReference *sdltestTests[] = {
  1114. &sdltestTest1, &sdltestTest2, &sdltestTest3, &sdltestTest4, &sdltestTest5, &sdltestTest6,
  1115. &sdltestTest7, &sdltestTest8, &sdltestTest9, &sdltestTest10, &sdltestTest11, &sdltestTest12,
  1116. &sdltestTest13, &sdltestTest14, &sdltestTest15, NULL
  1117. };
  1118. /* SDL_test test suite (global) */
  1119. SDLTest_TestSuiteReference sdltestTestSuite = {
  1120. "SDLtest",
  1121. NULL,
  1122. sdltestTests,
  1123. NULL
  1124. };