test/testautomation_pixels.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Wed, 01 May 2013 22:14:29 -0700
changeset 7134 09ee216e6a25
child 7142 f4a670e51cde
permissions -rw-r--r--
Add pixels test suite; add a test to pixel suite; minor updates to test code to make VisualStudio happy
     1 /**
     2  * Pixels test suite
     3  */
     4 
     5 #include <stdio.h>
     6 
     7 #include "SDL.h"
     8 #include "SDL_test.h"
     9 
    10 /* Test case functions */
    11 
    12 /* Definition of all RGB formats used to test pixel conversions */
    13 const int _numRGBPixelFormats = 30;
    14 Uint32 _RGBPixelFormats[] = 
    15   {
    16     SDL_PIXELFORMAT_INDEX1LSB,
    17     SDL_PIXELFORMAT_INDEX1MSB,
    18     SDL_PIXELFORMAT_INDEX4LSB,
    19     SDL_PIXELFORMAT_INDEX4MSB,
    20     SDL_PIXELFORMAT_INDEX8,
    21     SDL_PIXELFORMAT_RGB332,
    22     SDL_PIXELFORMAT_RGB444,
    23     SDL_PIXELFORMAT_RGB555,
    24     SDL_PIXELFORMAT_BGR555,
    25     SDL_PIXELFORMAT_ARGB4444,
    26     SDL_PIXELFORMAT_RGBA4444,
    27     SDL_PIXELFORMAT_ABGR4444,
    28     SDL_PIXELFORMAT_BGRA4444,
    29     SDL_PIXELFORMAT_ARGB1555,
    30     SDL_PIXELFORMAT_RGBA5551,
    31     SDL_PIXELFORMAT_ABGR1555,
    32     SDL_PIXELFORMAT_BGRA5551,
    33     SDL_PIXELFORMAT_RGB565,
    34     SDL_PIXELFORMAT_BGR565,
    35     SDL_PIXELFORMAT_RGB24,
    36     SDL_PIXELFORMAT_BGR24,
    37     SDL_PIXELFORMAT_RGB888,
    38     SDL_PIXELFORMAT_RGBX8888,
    39     SDL_PIXELFORMAT_BGR888,
    40     SDL_PIXELFORMAT_BGRX8888,
    41     SDL_PIXELFORMAT_ARGB8888,
    42     SDL_PIXELFORMAT_RGBA8888,
    43     SDL_PIXELFORMAT_ABGR8888,
    44     SDL_PIXELFORMAT_BGRA8888,
    45     SDL_PIXELFORMAT_ARGB2101010
    46   };
    47 char* _RGBPixelFormatsVerbose[] = 
    48   {
    49     "SDL_PIXELFORMAT_INDEX1LSB",
    50     "SDL_PIXELFORMAT_INDEX1MSB",
    51     "SDL_PIXELFORMAT_INDEX4LSB",
    52     "SDL_PIXELFORMAT_INDEX4MSB",
    53     "SDL_PIXELFORMAT_INDEX8",
    54     "SDL_PIXELFORMAT_RGB332",
    55     "SDL_PIXELFORMAT_RGB444",
    56     "SDL_PIXELFORMAT_RGB555",
    57     "SDL_PIXELFORMAT_BGR555",
    58     "SDL_PIXELFORMAT_ARGB4444",
    59     "SDL_PIXELFORMAT_RGBA4444",
    60     "SDL_PIXELFORMAT_ABGR4444",
    61     "SDL_PIXELFORMAT_BGRA4444",
    62     "SDL_PIXELFORMAT_ARGB1555",
    63     "SDL_PIXELFORMAT_RGBA5551",
    64     "SDL_PIXELFORMAT_ABGR1555",
    65     "SDL_PIXELFORMAT_BGRA5551",
    66     "SDL_PIXELFORMAT_RGB565",
    67     "SDL_PIXELFORMAT_BGR565",
    68     "SDL_PIXELFORMAT_RGB24",
    69     "SDL_PIXELFORMAT_BGR24",
    70     "SDL_PIXELFORMAT_RGB888",
    71     "SDL_PIXELFORMAT_RGBX8888",
    72     "SDL_PIXELFORMAT_BGR888",
    73     "SDL_PIXELFORMAT_BGRX8888",
    74     "SDL_PIXELFORMAT_ARGB8888",
    75     "SDL_PIXELFORMAT_RGBA8888",
    76     "SDL_PIXELFORMAT_ABGR8888",
    77     "SDL_PIXELFORMAT_BGRA8888",
    78     "SDL_PIXELFORMAT_ARGB2101010"
    79   };
    80 
    81 /* Definition of all Non-RGB formats used to test pixel conversions */
    82 const int _numNonRGBPixelFormats = 5;
    83 Uint32 _nonRGBPixelFormats[] = 
    84   {
    85     SDL_PIXELFORMAT_YV12,
    86     SDL_PIXELFORMAT_IYUV,
    87     SDL_PIXELFORMAT_YUY2,
    88     SDL_PIXELFORMAT_UYVY,
    89     SDL_PIXELFORMAT_YVYU 
    90   };
    91 char* _nonRGBPixelFormatsVerbose[] = 
    92   {
    93     "SDL_PIXELFORMAT_YV12",
    94     "SDL_PIXELFORMAT_IYUV",
    95     "SDL_PIXELFORMAT_YUY2",
    96     "SDL_PIXELFORMAT_UYVY",
    97     "SDL_PIXELFORMAT_YVYU" 
    98   };
    99 
   100 /* Test case functions */
   101 
   102 /**
   103  * @brief Call to SDL_AllocFormat and SDL_FreeFormat
   104  */
   105 int
   106 pixels_allocFreeFormat(void *arg)
   107 {
   108   int i;
   109   Uint32 format;
   110   Uint32 masks;
   111   SDL_PixelFormat* result;
   112 
   113   /* RGB formats */
   114   for (i = 0; i < _numRGBPixelFormats; i++) {
   115     format = _RGBPixelFormats[i];
   116     SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
   117   
   118     /* Allocate format */
   119     result = SDL_AllocFormat(format);
   120     SDLTest_AssertPass("Call to SDL_AllocFormat()");
   121     SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");  
   122     if (result != NULL) {
   123       SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %u, got %u", format, result->format);  
   124       SDLTest_AssertCheck(result->BitsPerPixel > 0, "Verify value of result.BitsPerPixel; expected: >0, got %u", result->BitsPerPixel);  
   125       SDLTest_AssertCheck(result->BytesPerPixel > 0, "Verify value of result.BytesPerPixel; expected: >0, got %u", result->BytesPerPixel);  
   126       if (result->palette != NULL) {      
   127          masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
   128          SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %u", masks);
   129       }
   130       
   131       /* Deallocate again */
   132       SDL_FreeFormat(result);
   133       SDLTest_AssertPass("Call to SDL_FreeFormat()");          
   134     }
   135   }
   136 
   137   /* Non-RGB formats */
   138   for (i = 0; i < _numNonRGBPixelFormats; i++) {
   139     format = _nonRGBPixelFormats[i];
   140     SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
   141   
   142     /* Try to allocate format */
   143     result = SDL_AllocFormat(format);
   144     SDLTest_AssertPass("Call to SDL_AllocFormat()");
   145     SDLTest_AssertCheck(result == NULL, "Verify result is NULL");  
   146   }
   147   
   148   return TEST_COMPLETED;
   149 }
   150 
   151 /* ================= Test References ================== */
   152 
   153 /* SysWM test cases */
   154 static const SDLTest_TestCaseReference pixelsTest1 =
   155 		{ (SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED };
   156 
   157 /* Sequence of Pixels test cases */
   158 static const SDLTest_TestCaseReference *pixelsTests[] =  {
   159 	&pixelsTest1, NULL
   160 };
   161 
   162 /* Pixels test suite (global) */
   163 SDLTest_TestSuiteReference pixelsTestSuite = {
   164 	"Pixels",
   165 	NULL,
   166 	pixelsTests,
   167 	NULL
   168 };