🛠️🐜 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.

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