test/testautomation_surface.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 18 Dec 2014 00:19:52 -0500
changeset 9278 8900afb78a19
parent 9218 74b8ddd028c7
child 9281 85246fbeeac1
permissions -rw-r--r--
Initial merge of Emscripten port!

With this commit, you can compile SDL2 with Emscripten
( http://emscripten.org/ ), and make your SDL-based C/C++ program
into a web app.

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