Added automated test to validate conversion between all supported formats.
authorSam Lantinga <slouken@libsdl.org>
Sun, 07 Jul 2013 12:34:26 -0700
changeset 7374 29ace61fca99
parent 7373 5e6efd29b461
child 7375 c8b16b3a3c9b
Added automated test to validate conversion between all supported formats.
test/testautomation_surface.c
--- a/test/testautomation_surface.c	Sun Jul 07 12:34:21 2013 -0700
+++ b/test/testautomation_surface.c	Sun Jul 07 12:34:26 2013 -0700
@@ -307,6 +307,99 @@
 }
 
 
+/*!
+ *  Tests surface conversion across all pixel formats.
+ */
+int
+surface_testCompleteSurfaceConversion(void *arg)
+{
+    Uint32 pixel_formats[] = {
+        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,
+    };
+    SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
+    SDL_PixelFormat *fmt1, *fmt2;
+    Uint32 rgba[4];
+    int bpp, i, j, ret = 0;
+
+    /* Create sample surface */
+    face = SDLTest_ImageFace();
+    SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
+    if (face == NULL)
+        return TEST_ABORTED;
+
+    /* Set transparent pixel as the pixel at (0,0) */
+    if (face->format->palette) {
+       ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
+       SDLTest_AssertPass("Call to SDL_SetColorKey()");
+       SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
+    }
+
+    for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
+        for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
+            /*printf("Converting %s -> %s\n", SDL_GetPixelFormatName(pixel_formats[i]), SDL_GetPixelFormatName(pixel_formats[j]));*/
+
+            fmt1 = SDL_AllocFormat(pixel_formats[i]);
+            SDL_assert(fmt1 != NULL);
+            cvt1 = SDL_ConvertSurface(face, fmt1, 0);
+            SDL_assert(cvt1 != NULL);
+
+            fmt2 = SDL_AllocFormat(pixel_formats[j]);
+            SDL_assert(fmt1 != NULL);
+            cvt2 = SDL_ConvertSurface(cvt1, fmt2, 0);
+            SDL_assert(cvt2 != NULL);
+
+            if ( fmt1->BytesPerPixel == face->format->BytesPerPixel &&
+                 fmt2->BytesPerPixel == face->format->BytesPerPixel &&
+                 (fmt1->Amask != 0) == (face->format->Amask != 0) &&
+                 (fmt2->Amask != 0) == (face->format->Amask != 0) ) {
+                final = SDL_ConvertSurface( cvt2, face->format, 0 );
+                SDL_assert(final != NULL);
+
+                /* Compare surface. */
+                ret = SDLTest_CompareSurfaces( face, final, 0 );
+                SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+                SDL_FreeSurface(final);
+            }
+
+            SDL_FreeSurface(cvt1);
+            SDL_FreeFormat(fmt1);
+            SDL_FreeSurface(cvt2);
+            SDL_FreeFormat(fmt2);
+        }
+    }
+
+    /* Clean up. */
+    SDL_FreeSurface( face );
+
+    return TEST_COMPLETED;
+}
+
+
 /**
  * @brief Tests sprite loading. A failure case.
  */
@@ -540,30 +633,34 @@
         { (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
 
 static const SDLTest_TestCaseReference surfaceTest6 =
+        { (SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest7 =
         { (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
 
-static const SDLTest_TestCaseReference surfaceTest7 =
+static const SDLTest_TestCaseReference surfaceTest8 =
         { (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
 
 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
-static const SDLTest_TestCaseReference surfaceTest8 =
+static const SDLTest_TestCaseReference surfaceTest9 =
         { (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blittin routines with verious blending modes", TEST_DISABLED};
 
 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
-static const SDLTest_TestCaseReference surfaceTest9 =
+static const SDLTest_TestCaseReference surfaceTest10 =
         { (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED};
 
 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
-static const SDLTest_TestCaseReference surfaceTest10 =
+static const SDLTest_TestCaseReference surfaceTest11 =
         { (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED};
 
-static const SDLTest_TestCaseReference surfaceTest11 =
+static const SDLTest_TestCaseReference surfaceTest12 =
         { (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
 
 /* Sequence of Surface test cases */
 static const SDLTest_TestCaseReference *surfaceTests[] =  {
     &surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
-    &surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10, &surfaceTest11, NULL
+    &surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
+    &surfaceTest11, &surfaceTest12, NULL
 };
 
 /* Surface test suite (global) */