SDL  2.0
testautomation_pixels.c File Reference
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
+ Include dependency graph for testautomation_pixels.c:

Go to the source code of this file.

Functions

int pixels_allocFreeFormat (void *arg)
 Call to SDL_AllocFormat and SDL_FreeFormat.
int pixels_getPixelFormatName (void *arg)
 Call to SDL_GetPixelFormatName.
int pixels_allocFreePalette (void *arg)
 Call to SDL_AllocPalette and SDL_FreePalette.
int pixels_calcGammaRamp (void *arg)
 Call to SDL_CalculateGammaRamp.

Variables

const int _numRGBPixelFormats = 30
Uint32 _RGBPixelFormats []
char * _RGBPixelFormatsVerbose []
const int _numNonRGBPixelFormats = 7
Uint32 _nonRGBPixelFormats []
char * _nonRGBPixelFormatsVerbose []
const int _numInvalidPixelFormats = 2
Uint32 _invalidPixelFormats []
char * _invalidPixelFormatsVerbose []
static const
SDLTest_TestCaseReference 
pixelsTest1
static const
SDLTest_TestCaseReference 
pixelsTest2
static const
SDLTest_TestCaseReference 
pixelsTest3
static const
SDLTest_TestCaseReference 
pixelsTest4
static const
SDLTest_TestCaseReference
pixelsTests []
SDLTest_TestSuiteReference pixelsTestSuite

Function Documentation

int pixels_allocFreeFormat ( void arg)

Call to SDL_AllocFormat and SDL_FreeFormat.

See Also
http://wiki.libsdl.org/moin.fcg/SDL_AllocFormat
http://wiki.libsdl.org/moin.fcg/SDL_FreeFormat

Definition at line 126 of file testautomation_pixels.c.

References _invalidPixelFormats, _nonRGBPixelFormats, _nonRGBPixelFormatsVerbose, _numInvalidPixelFormats, _numNonRGBPixelFormats, _numRGBPixelFormats, _RGBPixelFormats, _RGBPixelFormatsVerbose, SDL_PixelFormat::Amask, SDL_PixelFormat::BitsPerPixel, SDL_PixelFormat::Bmask, SDL_PixelFormat::BytesPerPixel, SDL_PixelFormat::format, SDL_PixelFormat::Gmask, i, NULL, SDL_PixelFormat::palette, SDL_PixelFormat::Rmask, SDL_AllocFormat, SDL_ClearError, SDL_FreeFormat, SDL_GetError, SDL_strcmp, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_Log(), and TEST_COMPLETED.

{
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *expectedError = "Parameter 'format' is invalid";
const char *error;
int i;
Uint32 masks;
/* Blank/unknown format */
format = 0;
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
/* Allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
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);
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);
/* Deallocate again */
SDL_FreeFormat(result);
SDLTest_AssertPass("Call to SDL_FreeFormat()");
}
/* RGB formats */
for (i = 0; i < _numRGBPixelFormats; i++) {
format = _RGBPixelFormats[i];
SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
/* Allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
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) {
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);
}
/* Deallocate again */
SDL_FreeFormat(result);
SDLTest_AssertPass("Call to SDL_FreeFormat()");
}
}
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
/* Try to allocate format */
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat()");
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
}
/* Negative cases */
/* Invalid Formats */
for (i = 0; i < _numInvalidPixelFormats; i++) {
SDLTest_AssertPass("Call to SDL_ClearError()");
result = SDL_AllocFormat(format);
SDLTest_AssertPass("Call to SDL_AllocFormat(%u)", format);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
}
/* Invalid free pointer */
SDLTest_AssertPass("Call to SDL_ClearError()");
SDLTest_AssertPass("Call to SDL_FreeFormat(NULL)");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
}
int pixels_allocFreePalette ( void arg)

Call to SDL_AllocPalette and SDL_FreePalette.

See Also
http://wiki.libsdl.org/moin.fcg/SDL_AllocPalette
http://wiki.libsdl.org/moin.fcg/SDL_FreePalette

Definition at line 317 of file testautomation_pixels.c.

References SDL_Color::b, SDL_Palette::colors, SDL_Color::g, i, SDL_Palette::ncolors, NULL, SDL_Color::r, SDL_AllocPalette, SDL_ClearError, SDL_FreePalette, SDL_GetError, SDL_strcmp, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), and TEST_COMPLETED.

{
const char *expectedError1 = "Parameter 'ncolors' is invalid";
const char *expectedError2 = "Parameter 'palette' is invalid";
const char *error;
int variation;
int i;
int ncolors;
/* Allocate palette */
for (variation = 1; variation <= 3; variation++) {
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);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result->ncolors == ncolors, "Verify value of result.ncolors; expected: %u, got %u", ncolors, result->ncolors);
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++) {
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);
}
}
}
/* Deallocate again */
SDL_FreePalette(result);
SDLTest_AssertPass("Call to SDL_FreePalette()");
}
}
/* Negative cases */
/* Invalid number of colors */
for (ncolors = 0; ncolors > -3; ncolors--) {
SDLTest_AssertPass("Call to SDL_ClearError()");
result = SDL_AllocPalette(ncolors);
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError1, error);
}
}
/* Invalid free pointer */
SDLTest_AssertPass("Call to SDL_ClearError()");
SDLTest_AssertPass("Call to SDL_FreePalette(NULL)");
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError2, error);
}
}
int pixels_calcGammaRamp ( void arg)

Call to SDL_CalculateGammaRamp.

See Also
http://wiki.libsdl.org/moin.fcg/SDL_CalculateGammaRamp

Definition at line 406 of file testautomation_pixels.c.

References i, NULL, SDL_CalculateGammaRamp, SDL_ClearError, SDL_free, SDL_GetError, SDL_malloc, SDL_strcmp, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_RandomIntegerInRange(), SDLTest_RandomUnitFloat(), TEST_ABORTED, and TEST_COMPLETED.

{
const char *expectedError1 = "Parameter 'gamma' is invalid";
const char *expectedError2 = "Parameter 'ramp' is invalid";
const char *error;
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;
/* Make call with different gamma values */
for (variation = 0; variation < 4; variation++) {
switch (variation) {
/* gamma = 0 all black */
case 0:
gamma = 0.0f;
break;
/* gamma = 1 identity */
case 1:
gamma = 1.0f;
break;
/* gamma = [0.2,0.8] normal range */
case 2:
gamma = 0.2f + 0.8f * SDLTest_RandomUnitFloat();
break;
/* gamma = >1.1 non-standard range */
case 3:
gamma = 1.1f + SDLTest_RandomUnitFloat();
break;
}
/* Make call and check that values were updated */
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 */
switch (variation) {
case 0:
SDLTest_AssertCheck(ramp[i] == 0, "Validate value at position %d; expected: 0, got: %d", i, ramp[i]);
break;
case 1:
SDLTest_AssertCheck(ramp[i] == ((i << 8) | i), "Validate value at position %d; expected: %d, got: %d", i, (i << 8) | i, ramp[i]);
break;
case 2:
case 3:
SDLTest_AssertCheck(ramp[i] > 0, "Validate value at position %d; expected: >0, got: %d", i, ramp[i]);
break;
}
}
/* Negative cases */
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) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
"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);
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) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError2, error);
}
/* Cleanup */
SDL_free(ramp);
}
int pixels_getPixelFormatName ( void arg)

Call to SDL_GetPixelFormatName.

See Also
http://wiki.libsdl.org/moin.fcg/SDL_GetPixelFormatName

Definition at line 232 of file testautomation_pixels.c.

References _invalidPixelFormats, _invalidPixelFormatsVerbose, _nonRGBPixelFormats, _nonRGBPixelFormatsVerbose, _numInvalidPixelFormats, _numNonRGBPixelFormats, _numRGBPixelFormats, _RGBPixelFormats, _RGBPixelFormatsVerbose, i, NULL, SDL_ClearError, SDL_GetError, SDL_GetPixelFormatName, SDL_strcmp, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_Log(), and TEST_COMPLETED.

{
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
const char *error;
int i;
char* result;
/* Blank/undefined format */
format = 0;
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
/* Get name of format */
result = (char *)SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, unknownFormat) == 0,
"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);
/* Get name of format */
result = (char *)SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
"Verify result text; expected: %s, got %s", _RGBPixelFormatsVerbose[i], result);
}
}
/* Non-RGB formats */
for (i = 0; i < _numNonRGBPixelFormats; i++) {
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
/* Get name of format */
result = (char *)SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
"Verify result text; expected: %s, got %s", _nonRGBPixelFormatsVerbose[i], result);
}
}
/* Negative cases */
/* Invalid Formats */
SDLTest_AssertPass("Call to SDL_ClearError()");
for (i = 0; i < _numInvalidPixelFormats; i++) {
result = (char *)SDL_GetPixelFormatName(format);
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%u)", format);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(result[0] != '\0',
"Verify result is non-empty; got: %s", result);
"Validate name is UNKNOWN, expected: '%s', got: '%s'", _invalidPixelFormatsVerbose[i], result);
}
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error == NULL || error[0] == '\0', "Validate that error message is empty");
}
}

Variable Documentation

Uint32 _invalidPixelFormats[]
Initial value:
{
0xfffffffe,
0xffffffff
}

Definition at line 106 of file testautomation_pixels.c.

Referenced by pixels_allocFreeFormat(), and pixels_getPixelFormatName().

char* _invalidPixelFormatsVerbose[]
Initial value:
{
"SDL_PIXELFORMAT_UNKNOWN",
"SDL_PIXELFORMAT_UNKNOWN"
}

Definition at line 111 of file testautomation_pixels.c.

Referenced by pixels_getPixelFormatName().

char* _nonRGBPixelFormatsVerbose[]
Initial value:
{
"SDL_PIXELFORMAT_YV12",
"SDL_PIXELFORMAT_IYUV",
"SDL_PIXELFORMAT_YUY2",
"SDL_PIXELFORMAT_UYVY",
"SDL_PIXELFORMAT_YVYU",
"SDL_PIXELFORMAT_NV12",
"SDL_PIXELFORMAT_NV21"
}

Definition at line 93 of file testautomation_pixels.c.

Referenced by pixels_allocFreeFormat(), and pixels_getPixelFormatName().

const int _numInvalidPixelFormats = 2

Definition at line 105 of file testautomation_pixels.c.

Referenced by pixels_allocFreeFormat(), and pixels_getPixelFormatName().

const int _numNonRGBPixelFormats = 7

Definition at line 82 of file testautomation_pixels.c.

Referenced by pixels_allocFreeFormat(), and pixels_getPixelFormatName().

const int _numRGBPixelFormats = 30

Pixels test suite

Definition at line 13 of file testautomation_pixels.c.

Referenced by pixels_allocFreeFormat(), and pixels_getPixelFormatName().

Uint32 _RGBPixelFormats[]

Definition at line 14 of file testautomation_pixels.c.

Referenced by pixels_allocFreeFormat(), and pixels_getPixelFormatName().

char* _RGBPixelFormatsVerbose[]

Definition at line 47 of file testautomation_pixels.c.

Referenced by pixels_allocFreeFormat(), and pixels_getPixelFormatName().

const SDLTest_TestCaseReference pixelsTest1
static
Initial value:
{ (SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED }

Definition at line 506 of file testautomation_pixels.c.

const SDLTest_TestCaseReference pixelsTest2
static
Initial value:
{ (SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED }

Definition at line 509 of file testautomation_pixels.c.

const SDLTest_TestCaseReference pixelsTest3
static
Initial value:
{ (SDLTest_TestCaseFp)pixels_calcGammaRamp, "pixels_calcGammaRamp", "Call to SDL_CalculateGammaRamp", TEST_ENABLED }

Definition at line 512 of file testautomation_pixels.c.

const SDLTest_TestCaseReference pixelsTest4
static
Initial value:
{ (SDLTest_TestCaseFp)pixels_getPixelFormatName, "pixels_getPixelFormatName", "Call to SDL_GetPixelFormatName", TEST_ENABLED }

Definition at line 515 of file testautomation_pixels.c.

const SDLTest_TestCaseReference* pixelsTests[]
static
Initial value:

Definition at line 519 of file testautomation_pixels.c.

SDLTest_TestSuiteReference pixelsTestSuite
Initial value:
{
"Pixels",
}

Definition at line 524 of file testautomation_pixels.c.