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