Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
567 lines (481 loc) · 18 KB

testautomation_video.c

File metadata and controls

567 lines (481 loc) · 18 KB
 
1
2
3
4
5
6
7
8
9
/**
* Video test suite
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
Feb 25, 2013
Feb 25, 2013
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Private helpers */
/*
* Create a test window
*/
SDL_Window *_createVideoSuiteTestWindow(const char *title)
{
SDL_Window* window;
int x, y, w, h;
SDL_WindowFlags flags;
/* Standard window */
x = SDLTest_RandomIntegerInRange(1, 100);
y = SDLTest_RandomIntegerInRange(1, 100);
w = SDLTest_RandomIntegerInRange(320, 1024);
h = SDLTest_RandomIntegerInRange(320, 768);
flags = SDL_WINDOW_SHOWN;
window = SDL_CreateWindow(title, x, y, w, h, flags);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
return window;
}
/*
* Destroy test window
*/
void _destroyVideoSuiteTestWindow(SDL_Window *window)
{
if (window != NULL) {
SDL_DestroyWindow(window);
window = NULL;
SDLTest_AssertPass("Call to SDL_DestroyWindow");
}
}
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Test case functions */
/**
* @brief Enable and disable screensaver while checking state
*/
int
video_enableDisableScreensaver(void *arg)
{
SDL_bool initialResult;
SDL_bool result;
/* Get current state and proceed according to current state */
initialResult = SDL_IsScreenSaverEnabled();
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
if (initialResult == SDL_TRUE) {
/* Currently enabled: disable first, then enable again */
/* Disable screensaver and check */
SDL_DisableScreenSaver();
SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
result = SDL_IsScreenSaverEnabled();
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
/* Enable screensaver and check */
SDL_EnableScreenSaver();
SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
result = SDL_IsScreenSaverEnabled();
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
} else {
/* Currently disabled: enable first, then disable again */
/* Enable screensaver and check */
SDL_EnableScreenSaver();
SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
result = SDL_IsScreenSaverEnabled();
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
/* Disable screensaver and check */
SDL_DisableScreenSaver();
SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");
result = SDL_IsScreenSaverEnabled();
SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
}
return TEST_COMPLETED;
}
Feb 17, 2013
Feb 17, 2013
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
* @brief Tests the functionality of the SDL_CreateWindow function using different positions
*/
int
video_createWindowVariousPositions(void *arg)
{
SDL_Window* window;
const char* title = "video_createWindowVariousPositions Test Window";
int x, y, w, h;
int xVariation, yVariation;
for (xVariation = 0; xVariation < 6; xVariation++) {
for (yVariation = 0; yVariation < 6; yVariation++) {
switch(xVariation) {
case 0:
/* Zero X Position */
x = 0;
break;
case 1:
/* Random X position inside screen */
x = SDLTest_RandomIntegerInRange(1, 100);
break;
case 2:
/* Random X position outside screen (positive) */
x = SDLTest_RandomIntegerInRange(10000, 11000);
break;
case 3:
/* Random X position outside screen (negative) */
x = SDLTest_RandomIntegerInRange(-1000, -100);
break;
case 4:
/* Centered X position */
x = SDL_WINDOWPOS_CENTERED;
break;
case 5:
/* Undefined X position */
x = SDL_WINDOWPOS_UNDEFINED;
break;
}
switch(yVariation) {
case 0:
/* Zero X Position */
y = 0;
break;
case 1:
/* Random X position inside screen */
y = SDLTest_RandomIntegerInRange(1, 100);
break;
case 2:
/* Random X position outside screen (positive) */
y = SDLTest_RandomIntegerInRange(10000, 11000);
break;
case 3:
/* Random Y position outside screen (negative) */
y = SDLTest_RandomIntegerInRange(-1000, -100);
break;
case 4:
/* Centered Y position */
y = SDL_WINDOWPOS_CENTERED;
break;
case 5:
/* Undefined Y position */
y = SDL_WINDOWPOS_UNDEFINED;
break;
}
w = SDLTest_RandomIntegerInRange(32, 96);
h = SDLTest_RandomIntegerInRange(32, 96);
window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
Feb 25, 2013
Feb 25, 2013
173
174
175
/* Clean up */
_destroyVideoSuiteTestWindow(window);
Feb 17, 2013
Feb 17, 2013
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
}
}
return TEST_COMPLETED;
}
/**
* @brief Tests the functionality of the SDL_CreateWindow function using different sizes
*/
int
video_createWindowVariousSizes(void *arg)
{
SDL_Window* window;
const char* title = "video_createWindowVariousSizes Test Window";
int x, y, w, h;
int wVariation, hVariation;
x = SDLTest_RandomIntegerInRange(1, 100);
y = SDLTest_RandomIntegerInRange(1, 100);
for (wVariation = 0; wVariation < 3; wVariation++) {
for (hVariation = 0; hVariation < 3; hVariation++) {
switch(wVariation) {
case 0:
/* Width of 1 */
w = 1;
break;
case 1:
/* Random "normal" width */
w = SDLTest_RandomIntegerInRange(320, 1920);
break;
case 2:
/* Random "large" width */
w = SDLTest_RandomIntegerInRange(2048, 4095);
break;
}
switch(hVariation) {
case 0:
/* Height of 1 */
h = 1;
break;
case 1:
/* Random "normal" height */
h = SDLTest_RandomIntegerInRange(320, 1080);
break;
case 2:
/* Random "large" height */
h = SDLTest_RandomIntegerInRange(2048, 4095);
break;
}
window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
Feb 25, 2013
Feb 25, 2013
230
231
232
/* Clean up */
_destroyVideoSuiteTestWindow(window);
Feb 17, 2013
Feb 17, 2013
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
}
}
return TEST_COMPLETED;
}
/**
* @brief Tests the functionality of the SDL_CreateWindow function using different flags
*/
int
video_createWindowVariousFlags(void *arg)
{
SDL_Window* window;
const char* title = "video_createWindowVariousFlags Test Window";
int x, y, w, h;
int fVariation;
SDL_WindowFlags flags;
/* Standard window */
x = SDLTest_RandomIntegerInRange(1, 100);
y = SDLTest_RandomIntegerInRange(1, 100);
w = SDLTest_RandomIntegerInRange(320, 1024);
h = SDLTest_RandomIntegerInRange(320, 768);
for (fVariation = 0; fVariation < 13; fVariation++) {
switch(fVariation) {
case 0:
flags = SDL_WINDOW_FULLSCREEN;
/* Skip - blanks screen; comment out next line to run test */
continue;
break;
case 1:
flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
/* Skip - blanks screen; comment out next line to run test */
continue;
break;
case 2:
flags = SDL_WINDOW_OPENGL;
break;
case 3:
flags = SDL_WINDOW_SHOWN;
break;
case 4:
flags = SDL_WINDOW_HIDDEN;
break;
case 5:
flags = SDL_WINDOW_BORDERLESS;
break;
case 6:
flags = SDL_WINDOW_RESIZABLE;
break;
case 7:
flags = SDL_WINDOW_MINIMIZED;
break;
case 8:
flags = SDL_WINDOW_MAXIMIZED;
break;
case 9:
flags = SDL_WINDOW_INPUT_GRABBED;
break;
case 10:
flags = SDL_WINDOW_INPUT_FOCUS;
break;
case 11:
flags = SDL_WINDOW_MOUSE_FOCUS;
break;
case 12:
flags = SDL_WINDOW_FOREIGN;
break;
}
window = SDL_CreateWindow(title, x, y, w, h, flags);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
Feb 25, 2013
Feb 25, 2013
307
308
309
310
/* Clean up */
_destroyVideoSuiteTestWindow(window);
Feb 17, 2013
Feb 17, 2013
311
312
313
314
315
}
return TEST_COMPLETED;
}
Feb 25, 2013
Feb 25, 2013
316
Feb 17, 2013
Feb 17, 2013
317
318
319
320
321
322
323
324
325
326
327
/**
* @brief Tests the functionality of the SDL_GetWindowFlags function
*/
int
video_getWindowFlags(void *arg)
{
SDL_Window* window;
const char* title = "video_getWindowFlags Test Window";
SDL_WindowFlags flags;
Uint32 actualFlags;
Feb 25, 2013
Feb 25, 2013
328
/* Reliable flag set always set in test window */
Feb 17, 2013
Feb 17, 2013
329
330
flags = SDL_WINDOW_SHOWN;
Feb 25, 2013
Feb 25, 2013
331
332
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
Feb 17, 2013
Feb 17, 2013
333
334
335
336
if (window != NULL) {
actualFlags = SDL_GetWindowFlags(window);
SDLTest_AssertPass("Call to SDL_GetWindowFlags");
SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
Feb 25, 2013
Feb 25, 2013
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
}
/* Clean up */
_destroyVideoSuiteTestWindow(window);
return TEST_COMPLETED;
}
/**
* @brief Tests the functionality of the SDL_GetNumDisplayModes function
*/
int
video_getNumDisplayModes(void *arg)
{
int result;
int displayNum;
int i;
/* Get number of displays */
displayNum = SDL_GetNumVideoDisplays();
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
/* Make call for each display */
for (i=0; i<displayNum; i++) {
result = SDL_GetNumDisplayModes(i);
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
Feb 17, 2013
Feb 17, 2013
364
365
366
367
368
}
return TEST_COMPLETED;
}
Feb 25, 2013
Feb 25, 2013
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/**
* @brief Tests negative call to SDL_GetNumDisplayModes function
*/
int
video_getNumDisplayModesNegative(void *arg)
{
int result;
int displayNum;
int displayIndex;
/* Get number of displays */
displayNum = SDL_GetNumVideoDisplays();
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
/* Invalid boundary values */
displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE);
result = SDL_GetNumDisplayModes(displayIndex);
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex);
SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
/* Large (out-of-bounds) display index */
displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000);
result = SDL_GetNumDisplayModes(displayIndex);
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex);
SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
displayIndex = SDLTest_RandomIntegerInRange(1000, 2000);
result = SDL_GetNumDisplayModes(displayIndex);
SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex);
SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);
return TEST_COMPLETED;
}
/**
* @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
*/
int
video_getClosestDisplayModeCurrentResolution(void *arg)
{
int result;
SDL_DisplayMode current;
SDL_DisplayMode target;
SDL_DisplayMode closest;
SDL_DisplayMode* dResult;
int displayNum;
int i;
int variation;
/* Get number of displays */
displayNum = SDL_GetNumVideoDisplays();
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
/* Make calls for each display */
for (i=0; i<displayNum; i++) {
SDLTest_Log("Testing against display: %d", i);
/* Get first display mode to get a sane resolution; this should always work */
result = SDL_GetDisplayMode(i, 0, &current);
SDLTest_AssertPass("Call to SDL_GetDisplayMode");
SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
if (result != 0) {
return TEST_ABORTED;
}
/* Set the desired resolution equals to current resolution */
target.w = current.w;
target.h = current.h;
for (variation = 0; variation < 8; variation ++) {
/* Vary constraints on other query parameters */
target.format = (variation & 1) ? current.format : 0;
target.refresh_rate = (variation & 2) ? current.refresh_rate : 0;
target.driverdata = (variation & 4) ? current.driverdata : 0;
/* Make call */
dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
SDLTest_AssertCheck(dResult != NULL, "Verify returned value is not NULL");
/* Check that one gets the current resolution back again */
SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w);
SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h);
SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w);
SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h);
}
}
return TEST_COMPLETED;
}
/**
* @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
*/
int
video_getClosestDisplayModeRandomResolution(void *arg)
{
SDL_DisplayMode target;
SDL_DisplayMode closest;
SDL_DisplayMode* dResult;
int displayNum;
int i;
int variation;
/* Get number of displays */
displayNum = SDL_GetNumVideoDisplays();
SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
/* Make calls for each display */
for (i=0; i<displayNum; i++) {
SDLTest_Log("Testing against display: %d", i);
for (variation = 0; variation < 16; variation ++) {
/* Set random constraints */
target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0;
target.driverdata = 0;
/* Make call; may or may not find anything, so don't validate any further */
dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
}
}
return TEST_COMPLETED;
}
/**
* @brief Tests call to SDL_GetWindowBrightness
*/
int
video_getWindowBrightness(void *arg)
{
SDL_Window* window;
const char* title = "video_getWindowBrightness Test Window";
float result;
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window != NULL) {
result = SDL_GetWindowBrightness(window);
SDLTest_AssertPass("Call to SDL_GetWindowBrightness");
SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result);
}
/* Clean up */
_destroyVideoSuiteTestWindow(window);
return TEST_COMPLETED;
}
522
523
524
525
526
527
/* ================= Test References ================== */
/* Video test cases */
static const SDLTest_TestCaseReference videoTest1 =
{ (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver", "Enable and disable screenaver while checking state", TEST_ENABLED };
Feb 17, 2013
Feb 17, 2013
528
529
530
531
532
533
534
535
536
537
static const SDLTest_TestCaseReference videoTest2 =
{ (SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions", "Create windows at various locations", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest3 =
{ (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes", "Create windows with various sizes", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest4 =
{ (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest5 =
Feb 25, 2013
Feb 25, 2013
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
{ (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest6 =
{ (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest7 =
{ (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest8 =
{ (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest9 =
{ (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest10 =
{ (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED };
Feb 17, 2013
Feb 17, 2013
554
555
556
/* Sequence of Video test cases */
static const SDLTest_TestCaseReference *videoTests[] = {
Feb 25, 2013
Feb 25, 2013
557
558
&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
&videoTest7, &videoTest8, &videoTest9, &videoTest10, NULL
559
560
561
562
563
564
565
566
567
};
/* Video test suite (global) */
SDLTest_TestSuiteReference videoTestSuite = {
"Video",
NULL,
videoTests,
NULL
};