testautomation_sdltest.c 60 KB

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