testautomation_sdltest.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  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. #if 0 /* This test correctly triggers an asan warning: runtime error: signed integer overflow: 2147483647 + 4239 cannot be represented in type 'int' */
  913. /* Range with min at integer limit */
  914. min = long_min;
  915. max = long_max + (Sint32)SDLTest_RandomSint16();
  916. result = SDLTest_RandomIntegerInRange(min, max);
  917. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,...)");
  918. SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%" SDL_PRIs32 ",%" SDL_PRIs32 "], got: %" SDL_PRIs32, min, max, result);
  919. #endif
  920. /* Range with max at integer limit */
  921. min = long_min - (Sint32)SDLTest_RandomSint16();
  922. max = long_max;
  923. result = SDLTest_RandomIntegerInRange(min, max);
  924. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(...,SINT32_MAX)");
  925. SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%" SDL_PRIs32 ",%" SDL_PRIs32 "], got: %" SDL_PRIs32, min, max, result);
  926. /* Full integer range */
  927. min = long_min;
  928. max = long_max;
  929. result = SDLTest_RandomIntegerInRange(min, max);
  930. SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,SINT32_MAX)");
  931. SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%" SDL_PRIs32 ",%" SDL_PRIs32 "], got: %" SDL_PRIs32, min, max, result);
  932. return TEST_COMPLETED;
  933. }
  934. /**
  935. * Calls to SDLTest_RandomAsciiString
  936. */
  937. static int SDLCALL sdltest_randomAsciiString(void *arg)
  938. {
  939. char *result;
  940. size_t len;
  941. int nonAsciiCharacters;
  942. size_t i;
  943. result = SDLTest_RandomAsciiString();
  944. SDLTest_AssertPass("Call to SDLTest_RandomAsciiString()");
  945. SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
  946. if (result != NULL) {
  947. len = SDL_strlen(result);
  948. SDLTest_AssertCheck(len >= 1 && len <= 255, "Validate that result length; expected: len=[1,255], got: %d", (int)len);
  949. nonAsciiCharacters = 0;
  950. for (i = 0; i < len; i++) {
  951. if (SDL_iscntrl(result[i])) {
  952. nonAsciiCharacters++;
  953. }
  954. }
  955. SDLTest_AssertCheck(nonAsciiCharacters == 0, "Validate that result does not contain non-Ascii characters, got: %d", nonAsciiCharacters);
  956. if (nonAsciiCharacters) {
  957. SDLTest_LogError("Invalid result from generator: '%s'", result);
  958. }
  959. SDL_free(result);
  960. }
  961. return TEST_COMPLETED;
  962. }
  963. /**
  964. * Calls to SDLTest_RandomAsciiStringWithMaximumLength
  965. */
  966. static int SDLCALL sdltest_randomAsciiStringWithMaximumLength(void *arg)
  967. {
  968. const char *expectedError = "Parameter 'maxLength' is invalid";
  969. const char *lastError;
  970. char *result;
  971. size_t targetLen;
  972. size_t len;
  973. int nonAsciiCharacters;
  974. size_t i;
  975. targetLen = 16 + SDLTest_RandomUint8();
  976. result = SDLTest_RandomAsciiStringWithMaximumLength((int)targetLen);
  977. SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", (int)targetLen);
  978. SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
  979. if (result != NULL) {
  980. len = SDL_strlen(result);
  981. SDLTest_AssertCheck(len >= 1 && len <= targetLen, "Validate that result length; expected: len=[1,%d], got: %d", (int)targetLen, (int)len);
  982. nonAsciiCharacters = 0;
  983. for (i = 0; i < len; i++) {
  984. if (SDL_iscntrl(result[i])) {
  985. nonAsciiCharacters++;
  986. }
  987. }
  988. SDLTest_AssertCheck(nonAsciiCharacters == 0, "Validate that result does not contain non-Ascii characters, got: %d", nonAsciiCharacters);
  989. if (nonAsciiCharacters) {
  990. SDLTest_LogError("Invalid result from generator: '%s'", result);
  991. }
  992. SDL_free(result);
  993. }
  994. /* Negative test */
  995. targetLen = 0;
  996. result = SDLTest_RandomAsciiStringWithMaximumLength((int)targetLen);
  997. SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", (int)targetLen);
  998. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  999. lastError = SDL_GetError();
  1000. SDLTest_AssertPass("SDL_GetError()");
  1001. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  1002. "SDL_GetError(): expected message '%s', was message: '%s'",
  1003. expectedError,
  1004. lastError);
  1005. /* Clear error messages */
  1006. SDL_ClearError();
  1007. SDLTest_AssertPass("SDL_ClearError()");
  1008. return TEST_COMPLETED;
  1009. }
  1010. /**
  1011. * Calls to SDLTest_RandomAsciiStringOfSize
  1012. */
  1013. static int SDLCALL sdltest_randomAsciiStringOfSize(void *arg)
  1014. {
  1015. const char *expectedError = "Parameter 'size' is invalid";
  1016. const char *lastError;
  1017. char *result;
  1018. size_t targetLen;
  1019. size_t len;
  1020. int nonAsciiCharacters;
  1021. size_t i;
  1022. /* Positive test */
  1023. targetLen = 16 + SDLTest_RandomUint8();
  1024. result = SDLTest_RandomAsciiStringOfSize((int)targetLen);
  1025. SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", (int)targetLen);
  1026. SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
  1027. if (result != NULL) {
  1028. len = SDL_strlen(result);
  1029. SDLTest_AssertCheck(len == targetLen, "Validate that result length; expected: len=%d, got: %d", (int)targetLen, (int)len);
  1030. nonAsciiCharacters = 0;
  1031. for (i = 0; i < len; i++) {
  1032. if (SDL_iscntrl(result[i])) {
  1033. nonAsciiCharacters++;
  1034. }
  1035. }
  1036. SDLTest_AssertCheck(nonAsciiCharacters == 0, "Validate that result does not contain non-ASCII characters, got: %d", nonAsciiCharacters);
  1037. if (nonAsciiCharacters) {
  1038. SDLTest_LogError("Invalid result from generator: '%s'", result);
  1039. }
  1040. SDL_free(result);
  1041. }
  1042. /* Negative test */
  1043. targetLen = 0;
  1044. result = SDLTest_RandomAsciiStringOfSize((int)targetLen);
  1045. SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", (int)targetLen);
  1046. SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
  1047. lastError = SDL_GetError();
  1048. SDLTest_AssertPass("SDL_GetError()");
  1049. SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
  1050. "SDL_GetError(): expected message '%s', was message: '%s'",
  1051. expectedError,
  1052. lastError);
  1053. /* Clear error messages */
  1054. SDL_ClearError();
  1055. SDLTest_AssertPass("SDL_ClearError()");
  1056. return TEST_COMPLETED;
  1057. }
  1058. /* ================= Test References ================== */
  1059. /* SDL_test test cases */
  1060. static const SDLTest_TestCaseReference sdltestTest1 = {
  1061. sdltest_getFuzzerInvocationCount, "sdltest_getFuzzerInvocationCount", "Call to sdltest_GetFuzzerInvocationCount", TEST_ENABLED
  1062. };
  1063. static const SDLTest_TestCaseReference sdltestTest2 = {
  1064. sdltest_randomNumber, "sdltest_randomNumber", "Calls to random number generators", TEST_ENABLED
  1065. };
  1066. static const SDLTest_TestCaseReference sdltestTest3 = {
  1067. sdltest_randomBoundaryNumberUint8, "sdltest_randomBoundaryNumberUint8", "Calls to random boundary number generators for Uint8", TEST_ENABLED
  1068. };
  1069. static const SDLTest_TestCaseReference sdltestTest4 = {
  1070. sdltest_randomBoundaryNumberUint16, "sdltest_randomBoundaryNumberUint16", "Calls to random boundary number generators for Uint16", TEST_ENABLED
  1071. };
  1072. static const SDLTest_TestCaseReference sdltestTest5 = {
  1073. sdltest_randomBoundaryNumberUint32, "sdltest_randomBoundaryNumberUint32", "Calls to random boundary number generators for Uint32", TEST_ENABLED
  1074. };
  1075. static const SDLTest_TestCaseReference sdltestTest6 = {
  1076. sdltest_randomBoundaryNumberUint64, "sdltest_randomBoundaryNumberUint64", "Calls to random boundary number generators for Uint64", TEST_ENABLED
  1077. };
  1078. static const SDLTest_TestCaseReference sdltestTest7 = {
  1079. sdltest_randomBoundaryNumberSint8, "sdltest_randomBoundaryNumberSint8", "Calls to random boundary number generators for Sint8", TEST_ENABLED
  1080. };
  1081. static const SDLTest_TestCaseReference sdltestTest8 = {
  1082. sdltest_randomBoundaryNumberSint16, "sdltest_randomBoundaryNumberSint16", "Calls to random boundary number generators for Sint16", TEST_ENABLED
  1083. };
  1084. static const SDLTest_TestCaseReference sdltestTest9 = {
  1085. sdltest_randomBoundaryNumberSint32, "sdltest_randomBoundaryNumberSint32", "Calls to random boundary number generators for Sint32", TEST_ENABLED
  1086. };
  1087. static const SDLTest_TestCaseReference sdltestTest10 = {
  1088. sdltest_randomBoundaryNumberSint64, "sdltest_randomBoundaryNumberSint64", "Calls to random boundary number generators for Sint64", TEST_ENABLED
  1089. };
  1090. static const SDLTest_TestCaseReference sdltestTest11 = {
  1091. sdltest_randomIntegerInRange, "sdltest_randomIntegerInRange", "Calls to ranged random number generator", TEST_ENABLED
  1092. };
  1093. static const SDLTest_TestCaseReference sdltestTest12 = {
  1094. sdltest_randomAsciiString, "sdltest_randomAsciiString", "Calls to default ASCII string generator", TEST_ENABLED
  1095. };
  1096. static const SDLTest_TestCaseReference sdltestTest13 = {
  1097. sdltest_randomAsciiStringWithMaximumLength, "sdltest_randomAsciiStringWithMaximumLength", "Calls to random maximum length ASCII string generator", TEST_ENABLED
  1098. };
  1099. static const SDLTest_TestCaseReference sdltestTest14 = {
  1100. sdltest_randomAsciiStringOfSize, "sdltest_randomAsciiStringOfSize", "Calls to fixed size ASCII string generator", TEST_ENABLED
  1101. };
  1102. static const SDLTest_TestCaseReference sdltestTest15 = {
  1103. sdltest_generateRunSeed, "sdltest_generateRunSeed", "Checks internal harness function SDLTest_GenerateRunSeed", TEST_ENABLED
  1104. };
  1105. /* Sequence of SDL_test test cases */
  1106. static const SDLTest_TestCaseReference *sdltestTests[] = {
  1107. &sdltestTest1, &sdltestTest2, &sdltestTest3, &sdltestTest4, &sdltestTest5, &sdltestTest6,
  1108. &sdltestTest7, &sdltestTest8, &sdltestTest9, &sdltestTest10, &sdltestTest11, &sdltestTest12,
  1109. &sdltestTest13, &sdltestTest14, &sdltestTest15, NULL
  1110. };
  1111. /* SDL_test test suite (global) */
  1112. SDLTest_TestSuiteReference sdltestTestSuite = {
  1113. "SDLtest",
  1114. NULL,
  1115. sdltestTests,
  1116. NULL
  1117. };