testautomation_sdltest.c 59 KB

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