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