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

Latest commit

 

History

History
525 lines (470 loc) · 17.7 KB

testautomation_pixels.c

File metadata and controls

525 lines (470 loc) · 17.7 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* Pixels test suite
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/* Test case functions */
/* Definition of all RGB formats used to test pixel conversions */
const int _numRGBPixelFormats = 30;
May 18, 2013
May 18, 2013
14
Uint32 _RGBPixelFormats[] =
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
{
SDL_PIXELFORMAT_INDEX1LSB,
SDL_PIXELFORMAT_INDEX1MSB,
SDL_PIXELFORMAT_INDEX4LSB,
SDL_PIXELFORMAT_INDEX4MSB,
SDL_PIXELFORMAT_INDEX8,
SDL_PIXELFORMAT_RGB332,
SDL_PIXELFORMAT_RGB444,
SDL_PIXELFORMAT_RGB555,
SDL_PIXELFORMAT_BGR555,
SDL_PIXELFORMAT_ARGB4444,
SDL_PIXELFORMAT_RGBA4444,
SDL_PIXELFORMAT_ABGR4444,
SDL_PIXELFORMAT_BGRA4444,
SDL_PIXELFORMAT_ARGB1555,
SDL_PIXELFORMAT_RGBA5551,
SDL_PIXELFORMAT_ABGR1555,
SDL_PIXELFORMAT_BGRA5551,
SDL_PIXELFORMAT_RGB565,
SDL_PIXELFORMAT_BGR565,
SDL_PIXELFORMAT_RGB24,
SDL_PIXELFORMAT_BGR24,
SDL_PIXELFORMAT_RGB888,
SDL_PIXELFORMAT_RGBX8888,
SDL_PIXELFORMAT_BGR888,
SDL_PIXELFORMAT_BGRX8888,
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_ARGB2101010
};
May 18, 2013
May 18, 2013
47
char* _RGBPixelFormatsVerbose[] =
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
{
"SDL_PIXELFORMAT_INDEX1LSB",
"SDL_PIXELFORMAT_INDEX1MSB",
"SDL_PIXELFORMAT_INDEX4LSB",
"SDL_PIXELFORMAT_INDEX4MSB",
"SDL_PIXELFORMAT_INDEX8",
"SDL_PIXELFORMAT_RGB332",
"SDL_PIXELFORMAT_RGB444",
"SDL_PIXELFORMAT_RGB555",
"SDL_PIXELFORMAT_BGR555",
"SDL_PIXELFORMAT_ARGB4444",
"SDL_PIXELFORMAT_RGBA4444",
"SDL_PIXELFORMAT_ABGR4444",
"SDL_PIXELFORMAT_BGRA4444",
"SDL_PIXELFORMAT_ARGB1555",
"SDL_PIXELFORMAT_RGBA5551",
"SDL_PIXELFORMAT_ABGR1555",
"SDL_PIXELFORMAT_BGRA5551",
"SDL_PIXELFORMAT_RGB565",
"SDL_PIXELFORMAT_BGR565",
"SDL_PIXELFORMAT_RGB24",
"SDL_PIXELFORMAT_BGR24",
"SDL_PIXELFORMAT_RGB888",
"SDL_PIXELFORMAT_RGBX8888",
"SDL_PIXELFORMAT_BGR888",
"SDL_PIXELFORMAT_BGRX8888",
"SDL_PIXELFORMAT_ARGB8888",
"SDL_PIXELFORMAT_RGBA8888",
"SDL_PIXELFORMAT_ABGR8888",
"SDL_PIXELFORMAT_BGRA8888",
"SDL_PIXELFORMAT_ARGB2101010"
};
/* Definition of all Non-RGB formats used to test pixel conversions */
const int _numNonRGBPixelFormats = 5;
May 18, 2013
May 18, 2013
83
Uint32 _nonRGBPixelFormats[] =
84
85
86
87
88
{
SDL_PIXELFORMAT_YV12,
SDL_PIXELFORMAT_IYUV,
SDL_PIXELFORMAT_YUY2,
SDL_PIXELFORMAT_UYVY,
May 18, 2013
May 18, 2013
89
SDL_PIXELFORMAT_YVYU
May 18, 2013
May 18, 2013
91
char* _nonRGBPixelFormatsVerbose[] =
92
93
94
95
96
{
"SDL_PIXELFORMAT_YV12",
"SDL_PIXELFORMAT_IYUV",
"SDL_PIXELFORMAT_YUY2",
"SDL_PIXELFORMAT_UYVY",
May 18, 2013
May 18, 2013
97
"SDL_PIXELFORMAT_YVYU"
May 6, 2013
May 6, 2013
100
101
/* Definition of some invalid formats for negative tests */
const int _numInvalidPixelFormats = 2;
May 18, 2013
May 18, 2013
102
Uint32 _invalidPixelFormats[] =
May 6, 2013
May 6, 2013
103
104
105
106
{
0xfffffffe,
0xffffffff
};
May 18, 2013
May 18, 2013
107
char* _invalidPixelFormatsVerbose[] =
May 6, 2013
May 6, 2013
108
109
110
111
112
{
"SDL_PIXELFORMAT_UNKNOWN",
"SDL_PIXELFORMAT_UNKNOWN"
};
113
114
115
116
/* Test case functions */
/**
* @brief Call to SDL_AllocFormat and SDL_FreeFormat
May 4, 2013
May 4, 2013
117
118
*
* @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocFormat
May 18, 2013
May 18, 2013
119
* @sa http://wiki.libsdl.org/moin.fcg/SDL_FreeFormat
120
121
122
123
*/
int
pixels_allocFreeFormat(void *arg)
{
May 6, 2013
May 6, 2013
124
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
May 5, 2013
May 5, 2013
125
const char *expectedError = "Parameter 'format' is invalid";
May 18, 2013
May 18, 2013
126
const char *error;
127
128
129
130
131
int i;
Uint32 format;
Uint32 masks;
SDL_PixelFormat* result;
May 6, 2013
May 6, 2013
132
133
134
/* Blank/unknown format */
format = 0;
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
May 18, 2013
May 18, 2013
135
May 6, 2013
May 6, 2013
136
137
138
/* Allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
May 18, 2013
May 18, 2013
139
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
May 6, 2013
May 6, 2013
140
if (result != NULL) {
May 18, 2013
May 18, 2013
141
142
143
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %u, got %u", format, result->format);
SDLTest_AssertCheck(result->BitsPerPixel == 0, "Verify value of result.BitsPerPixel; expected: 0, got %u", result->BitsPerPixel);
SDLTest_AssertCheck(result->BytesPerPixel == 0, "Verify value of result.BytesPerPixel; expected: 0, got %u", result->BytesPerPixel);
May 6, 2013
May 6, 2013
144
145
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
SDLTest_AssertCheck(masks == 0, "Verify value of result.[RGBA]mask combined; expected: 0, got %u", masks);
May 18, 2013
May 18, 2013
146
May 6, 2013
May 6, 2013
147
148
/* Deallocate again */
SDL_FreeFormat(result);
May 18, 2013
May 18, 2013
149
SDLTest_AssertPass("Call to SDL_FreeFormat()");
May 6, 2013
May 6, 2013
150
151
}
152
153
154
155
/* RGB formats */
for (i = 0; i < _numRGBPixelFormats; i++) {
format = _RGBPixelFormats[i];
SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
May 18, 2013
May 18, 2013
156
157
158
159
/* Allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
May 18, 2013
May 18, 2013
160
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
May 18, 2013
May 18, 2013
162
163
164
165
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %u, got %u", format, result->format);
SDLTest_AssertCheck(result->BitsPerPixel > 0, "Verify value of result.BitsPerPixel; expected: >0, got %u", result->BitsPerPixel);
SDLTest_AssertCheck(result->BytesPerPixel > 0, "Verify value of result.BytesPerPixel; expected: >0, got %u", result->BytesPerPixel);
if (result->palette != NULL) {
166
167
168
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %u", masks);
}
May 18, 2013
May 18, 2013
169
170
171
/* Deallocate again */
SDL_FreeFormat(result);
May 18, 2013
May 18, 2013
172
SDLTest_AssertPass("Call to SDL_FreeFormat()");
173
174
175
176
177
178
179
}
}
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
format = _nonRGBPixelFormats[i];
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
May 18, 2013
May 18, 2013
180
181
182
183
/* Try to allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
May 18, 2013
May 18, 2013
184
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
May 18, 2013
May 18, 2013
186
May 4, 2013
May 4, 2013
187
/* Negative cases */
May 18, 2013
May 18, 2013
188
189
/* Invalid Formats */
May 6, 2013
May 6, 2013
190
191
192
193
194
195
for (i = 0; i < _numInvalidPixelFormats; i++) {
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
format = _invalidPixelFormats[i];
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat(%u)", format);
May 18, 2013
May 18, 2013
196
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
May 6, 2013
May 6, 2013
197
198
199
200
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
May 18, 2013
May 18, 2013
201
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
May 5, 2013
May 5, 2013
202
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
May 6, 2013
May 6, 2013
203
}
May 5, 2013
May 5, 2013
204
}
May 4, 2013
May 4, 2013
205
May 5, 2013
May 5, 2013
206
207
208
/* Invalid free pointer */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
May 4, 2013
May 4, 2013
209
210
SDL_FreeFormat(NULL);
SDLTest_AssertPass("Call to SDL_FreeFormat(NULL)");
May 5, 2013
May 5, 2013
211
212
213
214
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
May 18, 2013
May 18, 2013
215
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
May 5, 2013
May 5, 2013
216
217
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
May 18, 2013
May 18, 2013
218
May 4, 2013
May 4, 2013
219
220
221
return TEST_COMPLETED;
}
May 6, 2013
May 6, 2013
222
223
224
225
226
227
228
229
230
/**
* @brief Call to SDL_GetPixelFormatName
*
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetPixelFormatName
*/
int
pixels_getPixelFormatName(void *arg)
{
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
May 18, 2013
May 18, 2013
231
const char *error;
May 6, 2013
May 6, 2013
232
233
234
235
236
237
238
int i;
Uint32 format;
char* result;
/* Blank/undefined format */
format = 0;
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
May 18, 2013
May 18, 2013
239
May 6, 2013
May 6, 2013
240
241
242
/* Get name of format */
result = (char *)SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
May 18, 2013
May 18, 2013
243
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
May 6, 2013
May 6, 2013
244
245
if (result != NULL) {
SDLTest_AssertCheck(SDL_strlen(result) > 0, "Verify result is non-empty");
May 18, 2013
May 18, 2013
246
SDLTest_AssertCheck(SDL_strcmp(result, unknownFormat) == 0,
May 6, 2013
May 6, 2013
247
248
249
250
251
252
253
"Verify result text; expected: %s, got %s", unknownFormat, result);
}
/* RGB formats */
for (i = 0; i < _numRGBPixelFormats; i++) {
format = _RGBPixelFormats[i];
SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
May 18, 2013
May 18, 2013
254
May 6, 2013
May 6, 2013
255
256
257
/* Get name of format */
result = (char *)SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
May 18, 2013
May 18, 2013
258
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
May 6, 2013
May 6, 2013
259
260
if (result != NULL) {
SDLTest_AssertCheck(SDL_strlen(result) > 0, "Verify result is non-empty");
May 18, 2013
May 18, 2013
261
SDLTest_AssertCheck(SDL_strcmp(result, _RGBPixelFormatsVerbose[i]) == 0,
May 6, 2013
May 6, 2013
262
263
264
265
266
267
268
269
"Verify result text; expected: %s, got %s", _RGBPixelFormatsVerbose[i], result);
}
}
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
format = _nonRGBPixelFormats[i];
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
May 18, 2013
May 18, 2013
270
May 6, 2013
May 6, 2013
271
272
273
/* Get name of format */
result = (char *)SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
May 18, 2013
May 18, 2013
274
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
May 6, 2013
May 6, 2013
275
276
if (result != NULL) {
SDLTest_AssertCheck(SDL_strlen(result) > 0, "Verify result is non-empty");
May 18, 2013
May 18, 2013
277
SDLTest_AssertCheck(SDL_strcmp(result, _nonRGBPixelFormatsVerbose[i]) == 0,
May 6, 2013
May 6, 2013
278
279
280
"Verify result text; expected: %s, got %s", _nonRGBPixelFormatsVerbose[i], result);
}
}
May 18, 2013
May 18, 2013
281
May 6, 2013
May 6, 2013
282
/* Negative cases */
May 18, 2013
May 18, 2013
283
284
/* Invalid Formats */
May 6, 2013
May 6, 2013
285
286
287
288
289
290
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
for (i = 0; i < _numInvalidPixelFormats; i++) {
format = _invalidPixelFormats[i];
result = (char *)SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%u)", format);
May 18, 2013
May 18, 2013
291
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
May 6, 2013
May 6, 2013
292
if (result != NULL) {
May 18, 2013
May 18, 2013
293
SDLTest_AssertCheck(SDL_strlen(result) > 0,
May 6, 2013
May 6, 2013
294
295
296
297
298
299
300
301
302
303
304
305
"Verify result is non-empty; got: %s", result);
SDLTest_AssertCheck(SDL_strcmp(result, _invalidPixelFormatsVerbose[i]) == 0,
"Validate name is UNKNOWN, expected: '%s', got: '%s'", _invalidPixelFormatsVerbose[i], result);
}
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL && SDL_strlen(error) == 0, "Validate that error message is empty");
}
return TEST_COMPLETED;
}
May 4, 2013
May 4, 2013
306
307
308
309
310
311
312
313
314
/**
* @brief Call to SDL_AllocPalette and SDL_FreePalette
*
* @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocPalette
* @sa http://wiki.libsdl.org/moin.fcg/SDL_FreePalette
*/
int
pixels_allocFreePalette(void *arg)
{
May 5, 2013
May 5, 2013
315
316
const char *expectedError1 = "Parameter 'ncolors' is invalid";
const char *expectedError2 = "Parameter 'palette' is invalid";
May 18, 2013
May 18, 2013
317
const char *error;
May 4, 2013
May 4, 2013
318
319
320
321
322
323
int variation;
int i;
int ncolors;
SDL_Palette* result;
/* Allocate palette */
May 18, 2013
May 18, 2013
324
for (variation = 1; variation <= 3; variation++) {
May 4, 2013
May 4, 2013
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
switch (variation) {
/* Just one color */
case 1:
ncolors = 1;
break;
/* Two colors */
case 2:
ncolors = 2;
break;
/* More than two colors */
case 3:
ncolors = SDLTest_RandomIntegerInRange(8, 16);
break;
}
result = SDL_AllocPalette(ncolors);
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
May 18, 2013
May 18, 2013
342
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
May 4, 2013
May 4, 2013
343
if (result != NULL) {
May 18, 2013
May 18, 2013
344
SDLTest_AssertCheck(result->ncolors == ncolors, "Verify value of result.ncolors; expected: %u, got %u", ncolors, result->ncolors);
May 4, 2013
May 4, 2013
345
346
347
348
if (result->ncolors > 0) {
SDLTest_AssertCheck(result->colors != NULL, "Verify value of result.colors is not NULL");
if (result->colors != NULL) {
for(i = 0; i < result->ncolors; i++) {
May 18, 2013
May 18, 2013
349
350
351
SDLTest_AssertCheck(result->colors[i].r == 255, "Verify value of result.colors[%d].r; expected: 255, got %u", i, result->colors[i].r);
SDLTest_AssertCheck(result->colors[i].g == 255, "Verify value of result.colors[%d].g; expected: 255, got %u", i, result->colors[i].g);
SDLTest_AssertCheck(result->colors[i].b == 255, "Verify value of result.colors[%d].b; expected: 255, got %u", i, result->colors[i].b);
May 4, 2013
May 4, 2013
352
}
May 18, 2013
May 18, 2013
353
}
May 4, 2013
May 4, 2013
354
}
May 18, 2013
May 18, 2013
355
May 4, 2013
May 4, 2013
356
357
/* Deallocate again */
SDL_FreePalette(result);
May 18, 2013
May 18, 2013
358
SDLTest_AssertPass("Call to SDL_FreePalette()");
May 4, 2013
May 4, 2013
359
360
361
362
}
}
/* Negative cases */
May 18, 2013
May 18, 2013
363
May 5, 2013
May 5, 2013
364
/* Invalid number of colors */
May 4, 2013
May 4, 2013
365
for (ncolors = 0; ncolors > -3; ncolors--) {
May 5, 2013
May 5, 2013
366
367
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
May 4, 2013
May 4, 2013
368
369
370
result = SDL_AllocPalette(ncolors);
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
May 5, 2013
May 5, 2013
371
372
373
374
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
May 18, 2013
May 18, 2013
375
SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
May 5, 2013
May 5, 2013
376
377
"Validate error message, expected: '%s', got: '%s'", expectedError1, error);
}
May 4, 2013
May 4, 2013
378
379
}
May 5, 2013
May 5, 2013
380
381
382
/* Invalid free pointer */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
May 4, 2013
May 4, 2013
383
384
SDL_FreePalette(NULL);
SDLTest_AssertPass("Call to SDL_FreePalette(NULL)");
May 5, 2013
May 5, 2013
385
386
387
388
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
May 18, 2013
May 18, 2013
389
SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
May 5, 2013
May 5, 2013
390
391
"Validate error message, expected: '%s', got: '%s'", expectedError2, error);
}
May 18, 2013
May 18, 2013
392
May 5, 2013
May 5, 2013
393
394
395
396
397
398
399
400
401
402
403
404
405
return TEST_COMPLETED;
}
/**
* @brief Call to SDL_CalculateGammaRamp
*
* @sa http://wiki.libsdl.org/moin.fcg/SDL_CalculateGammaRamp
*/
int
pixels_calcGammaRamp(void *arg)
{
const char *expectedError1 = "Parameter 'gamma' is invalid";
const char *expectedError2 = "Parameter 'ramp' is invalid";
May 18, 2013
May 18, 2013
406
const char *error;
May 5, 2013
May 5, 2013
407
408
409
410
411
412
413
414
415
416
417
float gamma;
Uint16 *ramp;
int variation;
int i;
int changed;
Uint16 magic = 0xbeef;
/* Allocate temp ramp array and fill with some value*/
ramp = (Uint16 *)SDL_malloc(256 * sizeof(Uint16));
SDLTest_AssertCheck(ramp != NULL, "Validate temp ramp array could be allocated");
if (ramp == NULL) return TEST_ABORTED;
May 18, 2013
May 18, 2013
418
May 5, 2013
May 5, 2013
419
420
421
422
/* Make call with different gamma values */
for (variation = 0; variation < 4; variation++) {
switch (variation) {
/* gamma = 0 all black */
May 18, 2013
May 18, 2013
423
case 0:
May 5, 2013
May 5, 2013
424
425
426
427
428
429
gamma = 0.0f;
break;
/* gamma = 1 identity */
case 1:
gamma = 1.0f;
break;
May 18, 2013
May 18, 2013
430
/* gamma = [0.2,0.8] normal range */
May 5, 2013
May 5, 2013
431
case 2:
May 6, 2013
May 6, 2013
432
gamma = 0.2f + 0.8f * SDLTest_RandomUnitFloat();
May 5, 2013
May 5, 2013
433
break;
May 18, 2013
May 18, 2013
434
/* gamma = >1.1 non-standard range */
May 5, 2013
May 5, 2013
435
case 3:
May 6, 2013
May 6, 2013
436
gamma = 1.1f + SDLTest_RandomUnitFloat();
May 5, 2013
May 5, 2013
437
438
439
break;
}
May 18, 2013
May 18, 2013
440
/* Make call and check that values were updated */
May 5, 2013
May 5, 2013
441
442
443
444
445
446
447
448
449
450
451
452
453
454
for (i = 0; i < 256; i++) ramp[i] = magic;
SDL_CalculateGammaRamp(gamma, ramp);
SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
changed = 0;
for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
SDLTest_AssertCheck(changed > 250, "Validate that ramp was calculated; expected: >250 values changed, got: %d values changed", changed);
/* Additional value checks for some cases */
i = SDLTest_RandomIntegerInRange(64,192);
switch (variation) {
case 0:
SDLTest_AssertCheck(ramp[i] == 0, "Validate value at position %d; expected: 0, got: %d", i, ramp[i]);
break;
case 1:
May 10, 2013
May 10, 2013
455
SDLTest_AssertCheck(ramp[i] == ((i << 8) | i), "Validate value at position %d; expected: %d, got: %d", i, (i << 8) | i, ramp[i]);
May 5, 2013
May 5, 2013
456
457
458
459
460
461
462
break;
case 2:
case 3:
SDLTest_AssertCheck(ramp[i] > 0, "Validate value at position %d; expected: >0, got: %d", i, ramp[i]);
break;
}
}
May 18, 2013
May 18, 2013
463
May 5, 2013
May 5, 2013
464
465
466
467
468
469
470
471
472
473
474
/* Negative cases */
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
gamma = -1;
for (i=0; i<256; i++) ramp[i] = magic;
SDL_CalculateGammaRamp(gamma, ramp);
SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
May 18, 2013
May 18, 2013
475
SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
May 5, 2013
May 5, 2013
476
477
478
479
480
481
482
483
484
485
486
487
"Validate error message, expected: '%s', got: '%s'", expectedError1, error);
}
changed = 0;
for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
SDLTest_AssertCheck(changed ==0, "Validate that ramp unchanged; expected: 0 values changed got: %d values changed", changed);
SDL_CalculateGammaRamp(0.5f, NULL);
SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(0.5,NULL)");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
May 18, 2013
May 18, 2013
488
SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
May 5, 2013
May 5, 2013
489
490
"Validate error message, expected: '%s', got: '%s'", expectedError2, error);
}
May 18, 2013
May 18, 2013
491
May 5, 2013
May 5, 2013
492
493
/* Cleanup */
SDL_free(ramp);
May 18, 2013
May 18, 2013
494
495
496
497
498
499
500
return TEST_COMPLETED;
}
/* ================= Test References ================== */
May 4, 2013
May 4, 2013
501
/* Pixels test cases */
502
static const SDLTest_TestCaseReference pixelsTest1 =
May 18, 2013
May 18, 2013
503
{ (SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED };
May 4, 2013
May 4, 2013
505
static const SDLTest_TestCaseReference pixelsTest2 =
May 18, 2013
May 18, 2013
506
{ (SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED };
May 4, 2013
May 4, 2013
507
May 5, 2013
May 5, 2013
508
static const SDLTest_TestCaseReference pixelsTest3 =
May 18, 2013
May 18, 2013
509
{ (SDLTest_TestCaseFp)pixels_calcGammaRamp, "pixels_calcGammaRamp", "Call to SDL_CalculateGammaRamp", TEST_ENABLED };
May 5, 2013
May 5, 2013
510
May 6, 2013
May 6, 2013
511
static const SDLTest_TestCaseReference pixelsTest4 =
May 18, 2013
May 18, 2013
512
{ (SDLTest_TestCaseFp)pixels_getPixelFormatName, "pixels_getPixelFormatName", "Call to SDL_GetPixelFormatName", TEST_ENABLED };
May 6, 2013
May 6, 2013
513
514
515
/* Sequence of Pixels test cases */
static const SDLTest_TestCaseReference *pixelsTests[] = {
May 18, 2013
May 18, 2013
516
&pixelsTest1, &pixelsTest2, &pixelsTest3, &pixelsTest4, NULL
517
518
519
520
};
/* Pixels test suite (global) */
SDLTest_TestSuiteReference pixelsTestSuite = {
May 18, 2013
May 18, 2013
521
522
523
524
"Pixels",
NULL,
pixelsTests,
NULL