test/testautomation_surface.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 07 Jul 2013 12:34:26 -0700
changeset 7374 29ace61fca99
parent 7191 75360622e65f
child 7403 9de6ef8865a2
permissions -rw-r--r--
Added automated test to validate conversion between all supported formats.
     1 /**
     2  * Original code: automated SDL surface test written by Edgar Simo "bobbens"
     3  * Adapted/rewritten for test lib by Andreas Schiffler
     4  */
     5 
     6 /* Supress C4996 VS compiler warnings for unlink() */
     7 #define _CRT_SECURE_NO_DEPRECATE
     8 #define _CRT_NONSTDC_NO_DEPRECATE
     9 
    10 #include <stdio.h>
    11 #include <sys/stat.h>
    12 
    13 #include "SDL.h"
    14 #include "SDL_test.h"
    15 
    16 /* ================= Test Case Implementation ================== */
    17 
    18 /* Shared test surface */
    19 
    20 static SDL_Surface *referenceSurface = NULL;
    21 static SDL_Surface *testSurface = NULL;
    22 
    23 /* Helper functions for the test cases */
    24 
    25 #define TEST_SURFACE_WIDTH testSurface->w
    26 #define TEST_SURFACE_HEIGHT testSurface->h
    27 
    28 /* Fixture */
    29 
    30 /* Create a 32-bit writable surface for blitting tests */
    31 void
    32 _surfaceSetUp(void *arg)
    33 {
    34     int result;
    35     SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
    36     SDL_BlendMode currentBlendMode;
    37     Uint32 rmask, gmask, bmask, amask;
    38 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
    39     rmask = 0xff000000;
    40     gmask = 0x00ff0000;
    41     bmask = 0x0000ff00;
    42     amask = 0x000000ff;
    43 #else
    44     rmask = 0x000000ff;
    45     gmask = 0x0000ff00;
    46     bmask = 0x00ff0000;
    47     amask = 0xff000000;
    48 #endif
    49 
    50     referenceSurface = SDLTest_ImageBlit(); /* For size info */
    51     testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
    52     SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
    53     if (testSurface != NULL) {
    54       /* Disable blend mode for target surface */
    55       result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
    56       SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
    57       result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
    58       SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
    59       SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);
    60     }
    61 }
    62 
    63 void
    64 _surfaceTearDown(void *arg)
    65 {
    66     if (referenceSurface != NULL) {
    67         SDL_FreeSurface(referenceSurface);
    68         referenceSurface = NULL;
    69     }
    70     if (testSurface != NULL) {
    71         SDL_FreeSurface(testSurface);
    72         testSurface = NULL;
    73     }
    74 }
    75 
    76 /**
    77  * Helper that clears the test surface
    78  */
    79 void _clearTestSurface()
    80 {
    81     int ret;
    82     Uint32 color;
    83 
    84     /* Clear surface. */
    85     color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
    86     SDLTest_AssertPass("Call to SDL_MapRGBA()");
    87     ret = SDL_FillRect( testSurface, NULL, color);
    88     SDLTest_AssertPass("Call to SDL_FillRect()");
    89     SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
    90 }
    91 
    92 /**
    93  * Helper that blits in a specific blend mode, -1 for basic blitting, -2 for color mod, -3 for alpha mod, -4 for mixed blend modes.
    94  */
    95 void _testBlitBlendMode(int mode)
    96 {
    97     int ret;
    98     int i, j, ni, nj;
    99     SDL_Surface *face;
   100     SDL_Rect rect;
   101     int nmode;
   102     SDL_BlendMode bmode;
   103     int checkFailCount1;
   104     int checkFailCount2;
   105     int checkFailCount3;
   106     int checkFailCount4;
   107 
   108     /* Check test surface */
   109     SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL");
   110     if (testSurface == NULL) return;
   111 
   112     /* Create sample surface */
   113     face = SDLTest_ImageFace();
   114     SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
   115     if (face == NULL) return;
   116 
   117         /* Reset alpha modulation */
   118     ret = SDL_SetSurfaceAlphaMod(face, 255);
   119     SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
   120     SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
   121 
   122         /* Reset color modulation */
   123     ret = SDL_SetSurfaceColorMod(face, 255, 255, 255);
   124     SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
   125     SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
   126 
   127         /* Reset color key */
   128     ret = SDL_SetColorKey(face, SDL_FALSE, 0);
   129     SDLTest_AssertPass("Call to SDL_SetColorKey()");
   130     SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret);
   131 
   132     /* Clear the test surface */
   133         _clearTestSurface();
   134 
   135     /* Target rect size */
   136     rect.w = face->w;
   137     rect.h = face->h;
   138 
   139     /* Steps to take */
   140     ni = testSurface->w - face->w;
   141     nj = testSurface->h - face->h;
   142 
   143     /* Optionally set blend mode. */
   144     if (mode >= 0) {
   145         ret = SDL_SetSurfaceBlendMode( face, (SDL_BlendMode)mode );
   146         SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
   147         SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret);
   148     }
   149 
   150     /* Test blend mode. */
   151     checkFailCount1 = 0;
   152     checkFailCount2 = 0;
   153     checkFailCount3 = 0;
   154     checkFailCount4 = 0;
   155     for (j=0; j <= nj; j+=4) {
   156       for (i=0; i <= ni; i+=4) {
   157         if (mode == -2) {
   158             /* Set color mod. */
   159             ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
   160             if (ret != 0) checkFailCount2++;
   161         }
   162         else if (mode == -3) {
   163             /* Set alpha mod. */
   164             ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
   165             if (ret != 0) checkFailCount3++;
   166         }
   167         else if (mode == -4) {
   168             /* Crazy blending mode magic. */
   169             nmode = (i/4*j/4) % 4;
   170             if (nmode==0) {
   171                 bmode = SDL_BLENDMODE_NONE;
   172             } else if (nmode==1) {
   173                 bmode = SDL_BLENDMODE_BLEND;
   174             } else if (nmode==2) {
   175                 bmode = SDL_BLENDMODE_ADD;
   176             } else if (nmode==3) {
   177                 bmode = SDL_BLENDMODE_MOD;
   178             }
   179             ret = SDL_SetSurfaceBlendMode( face, bmode );
   180             if (ret != 0) checkFailCount4++;
   181         }
   182 
   183          /* Blitting. */
   184          rect.x = i;
   185          rect.y = j;
   186          ret = SDL_BlitSurface( face, NULL, testSurface, &rect );
   187          if (ret != 0) checkFailCount1++;
   188       }
   189     }
   190     SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1);
   191     SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", checkFailCount2);
   192     SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 0, got: %i", checkFailCount3);
   193     SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
   194 
   195     /* Clean up */
   196     if (face != NULL) {
   197         SDL_FreeSurface(face);
   198         face = NULL;
   199     }
   200 }
   201 
   202 /* Helper to check that a file exists */
   203 void
   204 _AssertFileExist(const char *filename)
   205 {
   206     struct stat st;
   207     int ret = stat(filename, &st);
   208 
   209     SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
   210 }
   211 
   212 
   213 /* Test case functions */
   214 
   215 /**
   216  * @brief Tests sprite saving and loading
   217  */
   218 int
   219 surface_testSaveLoadBitmap(void *arg)
   220 {
   221     int ret;
   222     const char *sampleFilename = "testSaveLoadBitmap.bmp";
   223     SDL_Surface *face;
   224     SDL_Surface *rface;
   225 
   226     /* Create sample surface */
   227     face = SDLTest_ImageFace();
   228     SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
   229     if (face == NULL) return TEST_ABORTED;
   230 
   231     /* Delete test file; ignore errors */
   232     unlink(sampleFilename);
   233 
   234     /* Save a surface */
   235     ret = SDL_SaveBMP(face, sampleFilename);
   236     SDLTest_AssertPass("Call to SDL_SaveBMP()");
   237     SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret);
   238     _AssertFileExist(sampleFilename);
   239 
   240     /* Load a surface */
   241     rface = SDL_LoadBMP(sampleFilename);
   242     SDLTest_AssertPass("Call to SDL_LoadBMP()");
   243     SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
   244     if (rface != NULL) {
   245         SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
   246         SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
   247     }
   248 
   249     /* Delete test file; ignore errors */
   250     unlink(sampleFilename);
   251 
   252     /* Clean up */
   253     if (face != NULL) {
   254     SDL_FreeSurface(face);
   255     face = NULL;
   256     }
   257     if (rface != NULL) {
   258     SDL_FreeSurface(rface);
   259     rface = NULL;
   260     }
   261 
   262     return TEST_COMPLETED;
   263 }
   264 
   265 /*!
   266  *  Tests surface conversion.
   267  */
   268 int
   269 surface_testSurfaceConversion(void *arg)
   270 {
   271     SDL_Surface *rface = NULL, *face = NULL;
   272     int ret = 0;
   273 
   274     /* Create sample surface */
   275     face = SDLTest_ImageFace();
   276     SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
   277     if (face == NULL)
   278         return TEST_ABORTED;
   279 
   280     /* Set transparent pixel as the pixel at (0,0) */
   281     if (face->format->palette) {
   282        ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
   283        SDLTest_AssertPass("Call to SDL_SetColorKey()");
   284        SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
   285     }
   286 
   287     /* Convert to 32 bit to compare. */
   288     rface = SDL_ConvertSurface( face, testSurface->format, 0 );
   289     SDLTest_AssertPass("Call to SDL_ConvertSurface()");
   290     SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
   291 
   292     /* Compare surface. */
   293     ret = SDLTest_CompareSurfaces( rface, face, 0 );
   294     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   295 
   296     /* Clean up. */
   297     if (face != NULL) {
   298         SDL_FreeSurface( face );
   299         face = NULL;
   300     }
   301     if (rface != NULL) {
   302         SDL_FreeSurface( rface );
   303         rface = NULL;
   304     }
   305 
   306     return TEST_COMPLETED;
   307 }
   308 
   309 
   310 /*!
   311  *  Tests surface conversion across all pixel formats.
   312  */
   313 int
   314 surface_testCompleteSurfaceConversion(void *arg)
   315 {
   316     Uint32 pixel_formats[] = {
   317         SDL_PIXELFORMAT_INDEX8,
   318         SDL_PIXELFORMAT_RGB332,
   319         SDL_PIXELFORMAT_RGB444,
   320         SDL_PIXELFORMAT_RGB555,
   321         SDL_PIXELFORMAT_BGR555,
   322         SDL_PIXELFORMAT_ARGB4444,
   323         SDL_PIXELFORMAT_RGBA4444,
   324         SDL_PIXELFORMAT_ABGR4444,
   325         SDL_PIXELFORMAT_BGRA4444,
   326         SDL_PIXELFORMAT_ARGB1555,
   327         SDL_PIXELFORMAT_RGBA5551,
   328         SDL_PIXELFORMAT_ABGR1555,
   329         SDL_PIXELFORMAT_BGRA5551,
   330         SDL_PIXELFORMAT_RGB565,
   331         SDL_PIXELFORMAT_BGR565,
   332         SDL_PIXELFORMAT_RGB24,
   333         SDL_PIXELFORMAT_BGR24,
   334         SDL_PIXELFORMAT_RGB888,
   335         SDL_PIXELFORMAT_RGBX8888,
   336         SDL_PIXELFORMAT_BGR888,
   337         SDL_PIXELFORMAT_BGRX8888,
   338         SDL_PIXELFORMAT_ARGB8888,
   339         SDL_PIXELFORMAT_RGBA8888,
   340         SDL_PIXELFORMAT_ABGR8888,
   341         SDL_PIXELFORMAT_BGRA8888,
   342         SDL_PIXELFORMAT_ARGB2101010,
   343     };
   344     SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
   345     SDL_PixelFormat *fmt1, *fmt2;
   346     Uint32 rgba[4];
   347     int bpp, i, j, ret = 0;
   348 
   349     /* Create sample surface */
   350     face = SDLTest_ImageFace();
   351     SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
   352     if (face == NULL)
   353         return TEST_ABORTED;
   354 
   355     /* Set transparent pixel as the pixel at (0,0) */
   356     if (face->format->palette) {
   357        ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
   358        SDLTest_AssertPass("Call to SDL_SetColorKey()");
   359        SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
   360     }
   361 
   362     for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
   363         for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
   364             /*printf("Converting %s -> %s\n", SDL_GetPixelFormatName(pixel_formats[i]), SDL_GetPixelFormatName(pixel_formats[j]));*/
   365 
   366             fmt1 = SDL_AllocFormat(pixel_formats[i]);
   367             SDL_assert(fmt1 != NULL);
   368             cvt1 = SDL_ConvertSurface(face, fmt1, 0);
   369             SDL_assert(cvt1 != NULL);
   370 
   371             fmt2 = SDL_AllocFormat(pixel_formats[j]);
   372             SDL_assert(fmt1 != NULL);
   373             cvt2 = SDL_ConvertSurface(cvt1, fmt2, 0);
   374             SDL_assert(cvt2 != NULL);
   375 
   376             if ( fmt1->BytesPerPixel == face->format->BytesPerPixel &&
   377                  fmt2->BytesPerPixel == face->format->BytesPerPixel &&
   378                  (fmt1->Amask != 0) == (face->format->Amask != 0) &&
   379                  (fmt2->Amask != 0) == (face->format->Amask != 0) ) {
   380                 final = SDL_ConvertSurface( cvt2, face->format, 0 );
   381                 SDL_assert(final != NULL);
   382 
   383                 /* Compare surface. */
   384                 ret = SDLTest_CompareSurfaces( face, final, 0 );
   385                 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   386                 SDL_FreeSurface(final);
   387             }
   388 
   389             SDL_FreeSurface(cvt1);
   390             SDL_FreeFormat(fmt1);
   391             SDL_FreeSurface(cvt2);
   392             SDL_FreeFormat(fmt2);
   393         }
   394     }
   395 
   396     /* Clean up. */
   397     SDL_FreeSurface( face );
   398 
   399     return TEST_COMPLETED;
   400 }
   401 
   402 
   403 /**
   404  * @brief Tests sprite loading. A failure case.
   405  */
   406 int
   407 surface_testLoadFailure(void *arg)
   408 {
   409     SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
   410     SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
   411 
   412     return TEST_COMPLETED;
   413 }
   414 
   415 /**
   416  * @brief Tests some blitting routines.
   417  */
   418 int
   419 surface_testBlit(void *arg)
   420 {
   421    int ret;
   422    SDL_Surface *compareSurface;
   423 
   424    /* Basic blitting */
   425    _testBlitBlendMode(-1);
   426 
   427    /* Verify result by comparing surfaces */
   428    compareSurface = SDLTest_ImageBlit();
   429    ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
   430    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   431 
   432    /* Clean up. */
   433    if (compareSurface != NULL) {
   434     SDL_FreeSurface( compareSurface );
   435    }
   436 
   437    return TEST_COMPLETED;
   438 }
   439 
   440 /**
   441  * @brief Tests some blitting routines with color mod
   442  */
   443 int
   444 surface_testBlitColorMod(void *arg)
   445 {
   446    int ret;
   447    SDL_Surface *compareSurface;
   448 
   449    /* Basic blitting with color mod */
   450    _testBlitBlendMode(-2);
   451 
   452    /* Verify result by comparing surfaces */
   453    compareSurface = SDLTest_ImageBlitColor();
   454    ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
   455    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   456 
   457    /* Clean up. */
   458    if (compareSurface != NULL) {
   459     SDL_FreeSurface( compareSurface );
   460    }
   461 
   462    return TEST_COMPLETED;
   463 }
   464 
   465 /**
   466  * @brief Tests some blitting routines with alpha mod
   467  */
   468 int
   469 surface_testBlitAlphaMod(void *arg)
   470 {
   471    int ret;
   472    SDL_Surface *compareSurface;
   473 
   474    /* Basic blitting with alpha mod */
   475    _testBlitBlendMode(-3);
   476 
   477    /* Verify result by comparing surfaces */
   478    compareSurface = SDLTest_ImageBlitAlpha();
   479    ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
   480    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   481 
   482    /* Clean up. */
   483    if (compareSurface != NULL) {
   484     SDL_FreeSurface( compareSurface );
   485    }
   486 
   487    return TEST_COMPLETED;
   488 }
   489 
   490 
   491 /**
   492  * @brief Tests some more blitting routines.
   493  */
   494 int
   495 surface_testBlitBlendNone(void *arg)
   496 {
   497    int ret;
   498    SDL_Surface *compareSurface;
   499 
   500    /* Basic blitting */
   501    _testBlitBlendMode(SDL_BLENDMODE_NONE);
   502 
   503    /* Verify result by comparing surfaces */
   504    compareSurface = SDLTest_ImageBlitBlendNone();
   505    ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
   506    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   507 
   508    /* Clean up. */
   509    if (compareSurface != NULL) {
   510     SDL_FreeSurface( compareSurface );
   511    }
   512 
   513    return TEST_COMPLETED;
   514 }
   515 
   516 /**
   517  * @brief Tests some more blitting routines.
   518  */
   519 int
   520 surface_testBlitBlendBlend(void *arg)
   521 {
   522    int ret;
   523    SDL_Surface *compareSurface;
   524 
   525    /* Blend blitting */
   526    _testBlitBlendMode(SDL_BLENDMODE_BLEND);
   527 
   528    /* Verify result by comparing surfaces */
   529    compareSurface = SDLTest_ImageBlitBlend();
   530    ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
   531    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   532 
   533    /* Clean up. */
   534    if (compareSurface != NULL) {
   535     SDL_FreeSurface( compareSurface );
   536    }
   537 
   538    return TEST_COMPLETED;
   539 }
   540 
   541 /**
   542  * @brief Tests some more blitting routines.
   543  */
   544 int
   545 surface_testBlitBlendAdd(void *arg)
   546 {
   547    int ret;
   548    SDL_Surface *compareSurface;
   549 
   550    /* Add blitting */
   551    _testBlitBlendMode(SDL_BLENDMODE_ADD);
   552 
   553    /* Verify result by comparing surfaces */
   554    compareSurface = SDLTest_ImageBlitBlendAdd();
   555    ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
   556    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   557 
   558    /* Clean up. */
   559    if (compareSurface != NULL) {
   560     SDL_FreeSurface( compareSurface );
   561    }
   562 
   563    return TEST_COMPLETED;
   564 }
   565 
   566 /**
   567  * @brief Tests some more blitting routines.
   568  */
   569 int
   570 surface_testBlitBlendMod(void *arg)
   571 {
   572    int ret;
   573    SDL_Surface *compareSurface;
   574 
   575    /* Mod blitting */
   576    _testBlitBlendMode(SDL_BLENDMODE_MOD);
   577 
   578    /* Verify result by comparing surfaces */
   579    compareSurface = SDLTest_ImageBlitBlendMod();
   580    ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
   581    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   582 
   583    /* Clean up. */
   584    if (compareSurface != NULL) {
   585       SDL_FreeSurface( compareSurface );
   586    }
   587 
   588    return TEST_COMPLETED;
   589 }
   590 
   591 /**
   592  * @brief Tests some more blitting routines with loop
   593  */
   594 int
   595 surface_testBlitBlendLoop(void *arg) {
   596 
   597    int ret;
   598    SDL_Surface *compareSurface;
   599 
   600    /* All blitting modes */
   601    _testBlitBlendMode(-4);
   602 
   603    /* Verify result by comparing surfaces */
   604    compareSurface = SDLTest_ImageBlitBlendAll();
   605    ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
   606    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   607 
   608    /* Clean up. */
   609    if (compareSurface != NULL) {
   610      SDL_FreeSurface(compareSurface);
   611    }
   612 
   613    return TEST_COMPLETED;
   614 
   615 }
   616 
   617 /* ================= Test References ================== */
   618 
   619 /* Surface test cases */
   620 static const SDLTest_TestCaseReference surfaceTest1 =
   621         { (SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED};
   622 
   623 static const SDLTest_TestCaseReference surfaceTest2 =
   624         { (SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED};
   625 
   626 static const SDLTest_TestCaseReference surfaceTest3 =
   627         { (SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED};
   628 
   629 static const SDLTest_TestCaseReference surfaceTest4 =
   630         { (SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED};
   631 
   632 static const SDLTest_TestCaseReference surfaceTest5 =
   633         { (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
   634 
   635 static const SDLTest_TestCaseReference surfaceTest6 =
   636         { (SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED};
   637 
   638 static const SDLTest_TestCaseReference surfaceTest7 =
   639         { (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
   640 
   641 static const SDLTest_TestCaseReference surfaceTest8 =
   642         { (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
   643 
   644 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   645 static const SDLTest_TestCaseReference surfaceTest9 =
   646         { (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blittin routines with verious blending modes", TEST_DISABLED};
   647 
   648 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   649 static const SDLTest_TestCaseReference surfaceTest10 =
   650         { (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED};
   651 
   652 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   653 static const SDLTest_TestCaseReference surfaceTest11 =
   654         { (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED};
   655 
   656 static const SDLTest_TestCaseReference surfaceTest12 =
   657         { (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
   658 
   659 /* Sequence of Surface test cases */
   660 static const SDLTest_TestCaseReference *surfaceTests[] =  {
   661     &surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
   662     &surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
   663     &surfaceTest11, &surfaceTest12, NULL
   664 };
   665 
   666 /* Surface test suite (global) */
   667 SDLTest_TestSuiteReference surfaceTestSuite = {
   668     "Surface",
   669     _surfaceSetUp,
   670     surfaceTests,
   671     _surfaceTearDown
   672 
   673 };