🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1318 lines
59 KiB

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