test/testautomation_pixels.c
changeset 7134 09ee216e6a25
child 7142 f4a670e51cde
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testautomation_pixels.c	Wed May 01 22:14:29 2013 -0700
     1.3 @@ -0,0 +1,168 @@
     1.4 +/**
     1.5 + * Pixels test suite
     1.6 + */
     1.7 +
     1.8 +#include <stdio.h>
     1.9 +
    1.10 +#include "SDL.h"
    1.11 +#include "SDL_test.h"
    1.12 +
    1.13 +/* Test case functions */
    1.14 +
    1.15 +/* Definition of all RGB formats used to test pixel conversions */
    1.16 +const int _numRGBPixelFormats = 30;
    1.17 +Uint32 _RGBPixelFormats[] = 
    1.18 +  {
    1.19 +    SDL_PIXELFORMAT_INDEX1LSB,
    1.20 +    SDL_PIXELFORMAT_INDEX1MSB,
    1.21 +    SDL_PIXELFORMAT_INDEX4LSB,
    1.22 +    SDL_PIXELFORMAT_INDEX4MSB,
    1.23 +    SDL_PIXELFORMAT_INDEX8,
    1.24 +    SDL_PIXELFORMAT_RGB332,
    1.25 +    SDL_PIXELFORMAT_RGB444,
    1.26 +    SDL_PIXELFORMAT_RGB555,
    1.27 +    SDL_PIXELFORMAT_BGR555,
    1.28 +    SDL_PIXELFORMAT_ARGB4444,
    1.29 +    SDL_PIXELFORMAT_RGBA4444,
    1.30 +    SDL_PIXELFORMAT_ABGR4444,
    1.31 +    SDL_PIXELFORMAT_BGRA4444,
    1.32 +    SDL_PIXELFORMAT_ARGB1555,
    1.33 +    SDL_PIXELFORMAT_RGBA5551,
    1.34 +    SDL_PIXELFORMAT_ABGR1555,
    1.35 +    SDL_PIXELFORMAT_BGRA5551,
    1.36 +    SDL_PIXELFORMAT_RGB565,
    1.37 +    SDL_PIXELFORMAT_BGR565,
    1.38 +    SDL_PIXELFORMAT_RGB24,
    1.39 +    SDL_PIXELFORMAT_BGR24,
    1.40 +    SDL_PIXELFORMAT_RGB888,
    1.41 +    SDL_PIXELFORMAT_RGBX8888,
    1.42 +    SDL_PIXELFORMAT_BGR888,
    1.43 +    SDL_PIXELFORMAT_BGRX8888,
    1.44 +    SDL_PIXELFORMAT_ARGB8888,
    1.45 +    SDL_PIXELFORMAT_RGBA8888,
    1.46 +    SDL_PIXELFORMAT_ABGR8888,
    1.47 +    SDL_PIXELFORMAT_BGRA8888,
    1.48 +    SDL_PIXELFORMAT_ARGB2101010
    1.49 +  };
    1.50 +char* _RGBPixelFormatsVerbose[] = 
    1.51 +  {
    1.52 +    "SDL_PIXELFORMAT_INDEX1LSB",
    1.53 +    "SDL_PIXELFORMAT_INDEX1MSB",
    1.54 +    "SDL_PIXELFORMAT_INDEX4LSB",
    1.55 +    "SDL_PIXELFORMAT_INDEX4MSB",
    1.56 +    "SDL_PIXELFORMAT_INDEX8",
    1.57 +    "SDL_PIXELFORMAT_RGB332",
    1.58 +    "SDL_PIXELFORMAT_RGB444",
    1.59 +    "SDL_PIXELFORMAT_RGB555",
    1.60 +    "SDL_PIXELFORMAT_BGR555",
    1.61 +    "SDL_PIXELFORMAT_ARGB4444",
    1.62 +    "SDL_PIXELFORMAT_RGBA4444",
    1.63 +    "SDL_PIXELFORMAT_ABGR4444",
    1.64 +    "SDL_PIXELFORMAT_BGRA4444",
    1.65 +    "SDL_PIXELFORMAT_ARGB1555",
    1.66 +    "SDL_PIXELFORMAT_RGBA5551",
    1.67 +    "SDL_PIXELFORMAT_ABGR1555",
    1.68 +    "SDL_PIXELFORMAT_BGRA5551",
    1.69 +    "SDL_PIXELFORMAT_RGB565",
    1.70 +    "SDL_PIXELFORMAT_BGR565",
    1.71 +    "SDL_PIXELFORMAT_RGB24",
    1.72 +    "SDL_PIXELFORMAT_BGR24",
    1.73 +    "SDL_PIXELFORMAT_RGB888",
    1.74 +    "SDL_PIXELFORMAT_RGBX8888",
    1.75 +    "SDL_PIXELFORMAT_BGR888",
    1.76 +    "SDL_PIXELFORMAT_BGRX8888",
    1.77 +    "SDL_PIXELFORMAT_ARGB8888",
    1.78 +    "SDL_PIXELFORMAT_RGBA8888",
    1.79 +    "SDL_PIXELFORMAT_ABGR8888",
    1.80 +    "SDL_PIXELFORMAT_BGRA8888",
    1.81 +    "SDL_PIXELFORMAT_ARGB2101010"
    1.82 +  };
    1.83 +
    1.84 +/* Definition of all Non-RGB formats used to test pixel conversions */
    1.85 +const int _numNonRGBPixelFormats = 5;
    1.86 +Uint32 _nonRGBPixelFormats[] = 
    1.87 +  {
    1.88 +    SDL_PIXELFORMAT_YV12,
    1.89 +    SDL_PIXELFORMAT_IYUV,
    1.90 +    SDL_PIXELFORMAT_YUY2,
    1.91 +    SDL_PIXELFORMAT_UYVY,
    1.92 +    SDL_PIXELFORMAT_YVYU 
    1.93 +  };
    1.94 +char* _nonRGBPixelFormatsVerbose[] = 
    1.95 +  {
    1.96 +    "SDL_PIXELFORMAT_YV12",
    1.97 +    "SDL_PIXELFORMAT_IYUV",
    1.98 +    "SDL_PIXELFORMAT_YUY2",
    1.99 +    "SDL_PIXELFORMAT_UYVY",
   1.100 +    "SDL_PIXELFORMAT_YVYU" 
   1.101 +  };
   1.102 +
   1.103 +/* Test case functions */
   1.104 +
   1.105 +/**
   1.106 + * @brief Call to SDL_AllocFormat and SDL_FreeFormat
   1.107 + */
   1.108 +int
   1.109 +pixels_allocFreeFormat(void *arg)
   1.110 +{
   1.111 +  int i;
   1.112 +  Uint32 format;
   1.113 +  Uint32 masks;
   1.114 +  SDL_PixelFormat* result;
   1.115 +
   1.116 +  /* RGB formats */
   1.117 +  for (i = 0; i < _numRGBPixelFormats; i++) {
   1.118 +    format = _RGBPixelFormats[i];
   1.119 +    SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
   1.120 +  
   1.121 +    /* Allocate format */
   1.122 +    result = SDL_AllocFormat(format);
   1.123 +    SDLTest_AssertPass("Call to SDL_AllocFormat()");
   1.124 +    SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");  
   1.125 +    if (result != NULL) {
   1.126 +      SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %u, got %u", format, result->format);  
   1.127 +      SDLTest_AssertCheck(result->BitsPerPixel > 0, "Verify value of result.BitsPerPixel; expected: >0, got %u", result->BitsPerPixel);  
   1.128 +      SDLTest_AssertCheck(result->BytesPerPixel > 0, "Verify value of result.BytesPerPixel; expected: >0, got %u", result->BytesPerPixel);  
   1.129 +      if (result->palette != NULL) {      
   1.130 +         masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
   1.131 +         SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %u", masks);
   1.132 +      }
   1.133 +      
   1.134 +      /* Deallocate again */
   1.135 +      SDL_FreeFormat(result);
   1.136 +      SDLTest_AssertPass("Call to SDL_FreeFormat()");          
   1.137 +    }
   1.138 +  }
   1.139 +
   1.140 +  /* Non-RGB formats */
   1.141 +  for (i = 0; i < _numNonRGBPixelFormats; i++) {
   1.142 +    format = _nonRGBPixelFormats[i];
   1.143 +    SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
   1.144 +  
   1.145 +    /* Try to allocate format */
   1.146 +    result = SDL_AllocFormat(format);
   1.147 +    SDLTest_AssertPass("Call to SDL_AllocFormat()");
   1.148 +    SDLTest_AssertCheck(result == NULL, "Verify result is NULL");  
   1.149 +  }
   1.150 +  
   1.151 +  return TEST_COMPLETED;
   1.152 +}
   1.153 +
   1.154 +/* ================= Test References ================== */
   1.155 +
   1.156 +/* SysWM test cases */
   1.157 +static const SDLTest_TestCaseReference pixelsTest1 =
   1.158 +		{ (SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED };
   1.159 +
   1.160 +/* Sequence of Pixels test cases */
   1.161 +static const SDLTest_TestCaseReference *pixelsTests[] =  {
   1.162 +	&pixelsTest1, NULL
   1.163 +};
   1.164 +
   1.165 +/* Pixels test suite (global) */
   1.166 +SDLTest_TestSuiteReference pixelsTestSuite = {
   1.167 +	"Pixels",
   1.168 +	NULL,
   1.169 +	pixelsTests,
   1.170 +	NULL
   1.171 +};