Added automated test to validate conversion between all supported formats.
authorSam Lantinga <slouken@libsdl.org>
Sun, 07 Jul 2013 12:34:26 -0700
changeset 737429ace61fca99
parent 7373 5e6efd29b461
child 7375 c8b16b3a3c9b
Added automated test to validate conversion between all supported formats.
test/testautomation_surface.c
     1.1 --- a/test/testautomation_surface.c	Sun Jul 07 12:34:21 2013 -0700
     1.2 +++ b/test/testautomation_surface.c	Sun Jul 07 12:34:26 2013 -0700
     1.3 @@ -307,6 +307,99 @@
     1.4  }
     1.5  
     1.6  
     1.7 +/*!
     1.8 + *  Tests surface conversion across all pixel formats.
     1.9 + */
    1.10 +int
    1.11 +surface_testCompleteSurfaceConversion(void *arg)
    1.12 +{
    1.13 +    Uint32 pixel_formats[] = {
    1.14 +        SDL_PIXELFORMAT_INDEX8,
    1.15 +        SDL_PIXELFORMAT_RGB332,
    1.16 +        SDL_PIXELFORMAT_RGB444,
    1.17 +        SDL_PIXELFORMAT_RGB555,
    1.18 +        SDL_PIXELFORMAT_BGR555,
    1.19 +        SDL_PIXELFORMAT_ARGB4444,
    1.20 +        SDL_PIXELFORMAT_RGBA4444,
    1.21 +        SDL_PIXELFORMAT_ABGR4444,
    1.22 +        SDL_PIXELFORMAT_BGRA4444,
    1.23 +        SDL_PIXELFORMAT_ARGB1555,
    1.24 +        SDL_PIXELFORMAT_RGBA5551,
    1.25 +        SDL_PIXELFORMAT_ABGR1555,
    1.26 +        SDL_PIXELFORMAT_BGRA5551,
    1.27 +        SDL_PIXELFORMAT_RGB565,
    1.28 +        SDL_PIXELFORMAT_BGR565,
    1.29 +        SDL_PIXELFORMAT_RGB24,
    1.30 +        SDL_PIXELFORMAT_BGR24,
    1.31 +        SDL_PIXELFORMAT_RGB888,
    1.32 +        SDL_PIXELFORMAT_RGBX8888,
    1.33 +        SDL_PIXELFORMAT_BGR888,
    1.34 +        SDL_PIXELFORMAT_BGRX8888,
    1.35 +        SDL_PIXELFORMAT_ARGB8888,
    1.36 +        SDL_PIXELFORMAT_RGBA8888,
    1.37 +        SDL_PIXELFORMAT_ABGR8888,
    1.38 +        SDL_PIXELFORMAT_BGRA8888,
    1.39 +        SDL_PIXELFORMAT_ARGB2101010,
    1.40 +    };
    1.41 +    SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
    1.42 +    SDL_PixelFormat *fmt1, *fmt2;
    1.43 +    Uint32 rgba[4];
    1.44 +    int bpp, i, j, ret = 0;
    1.45 +
    1.46 +    /* Create sample surface */
    1.47 +    face = SDLTest_ImageFace();
    1.48 +    SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
    1.49 +    if (face == NULL)
    1.50 +        return TEST_ABORTED;
    1.51 +
    1.52 +    /* Set transparent pixel as the pixel at (0,0) */
    1.53 +    if (face->format->palette) {
    1.54 +       ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
    1.55 +       SDLTest_AssertPass("Call to SDL_SetColorKey()");
    1.56 +       SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
    1.57 +    }
    1.58 +
    1.59 +    for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
    1.60 +        for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
    1.61 +            /*printf("Converting %s -> %s\n", SDL_GetPixelFormatName(pixel_formats[i]), SDL_GetPixelFormatName(pixel_formats[j]));*/
    1.62 +
    1.63 +            fmt1 = SDL_AllocFormat(pixel_formats[i]);
    1.64 +            SDL_assert(fmt1 != NULL);
    1.65 +            cvt1 = SDL_ConvertSurface(face, fmt1, 0);
    1.66 +            SDL_assert(cvt1 != NULL);
    1.67 +
    1.68 +            fmt2 = SDL_AllocFormat(pixel_formats[j]);
    1.69 +            SDL_assert(fmt1 != NULL);
    1.70 +            cvt2 = SDL_ConvertSurface(cvt1, fmt2, 0);
    1.71 +            SDL_assert(cvt2 != NULL);
    1.72 +
    1.73 +            if ( fmt1->BytesPerPixel == face->format->BytesPerPixel &&
    1.74 +                 fmt2->BytesPerPixel == face->format->BytesPerPixel &&
    1.75 +                 (fmt1->Amask != 0) == (face->format->Amask != 0) &&
    1.76 +                 (fmt2->Amask != 0) == (face->format->Amask != 0) ) {
    1.77 +                final = SDL_ConvertSurface( cvt2, face->format, 0 );
    1.78 +                SDL_assert(final != NULL);
    1.79 +
    1.80 +                /* Compare surface. */
    1.81 +                ret = SDLTest_CompareSurfaces( face, final, 0 );
    1.82 +                SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
    1.83 +                SDL_FreeSurface(final);
    1.84 +            }
    1.85 +
    1.86 +            SDL_FreeSurface(cvt1);
    1.87 +            SDL_FreeFormat(fmt1);
    1.88 +            SDL_FreeSurface(cvt2);
    1.89 +            SDL_FreeFormat(fmt2);
    1.90 +        }
    1.91 +    }
    1.92 +
    1.93 +    /* Clean up. */
    1.94 +    SDL_FreeSurface( face );
    1.95 +
    1.96 +    return TEST_COMPLETED;
    1.97 +}
    1.98 +
    1.99 +
   1.100  /**
   1.101   * @brief Tests sprite loading. A failure case.
   1.102   */
   1.103 @@ -540,30 +633,34 @@
   1.104          { (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
   1.105  
   1.106  static const SDLTest_TestCaseReference surfaceTest6 =
   1.107 +        { (SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED};
   1.108 +
   1.109 +static const SDLTest_TestCaseReference surfaceTest7 =
   1.110          { (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
   1.111  
   1.112 -static const SDLTest_TestCaseReference surfaceTest7 =
   1.113 +static const SDLTest_TestCaseReference surfaceTest8 =
   1.114          { (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
   1.115  
   1.116  /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   1.117 -static const SDLTest_TestCaseReference surfaceTest8 =
   1.118 +static const SDLTest_TestCaseReference surfaceTest9 =
   1.119          { (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blittin routines with verious blending modes", TEST_DISABLED};
   1.120  
   1.121  /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   1.122 -static const SDLTest_TestCaseReference surfaceTest9 =
   1.123 +static const SDLTest_TestCaseReference surfaceTest10 =
   1.124          { (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED};
   1.125  
   1.126  /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   1.127 -static const SDLTest_TestCaseReference surfaceTest10 =
   1.128 +static const SDLTest_TestCaseReference surfaceTest11 =
   1.129          { (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED};
   1.130  
   1.131 -static const SDLTest_TestCaseReference surfaceTest11 =
   1.132 +static const SDLTest_TestCaseReference surfaceTest12 =
   1.133          { (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
   1.134  
   1.135  /* Sequence of Surface test cases */
   1.136  static const SDLTest_TestCaseReference *surfaceTests[] =  {
   1.137      &surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
   1.138 -    &surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10, &surfaceTest11, NULL
   1.139 +    &surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
   1.140 +    &surfaceTest11, &surfaceTest12, NULL
   1.141  };
   1.142  
   1.143  /* Surface test suite (global) */