test/testautomation_surface.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 05 Jun 2013 22:33:10 -0700
changeset 7286 04087a99e3f4
parent 7191 75360622e65f
child 7374 29ace61fca99
permissions -rw-r--r--
Added testautomation to the Visual Studio 2008 project.
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@7191
    66
    if (referenceSurface != NULL) {
slouken@7191
    67
        SDL_FreeSurface(referenceSurface);
slouken@7191
    68
        referenceSurface = NULL;
slouken@7191
    69
    }
slouken@7191
    70
    if (testSurface != NULL) {
slouken@7191
    71
        SDL_FreeSurface(testSurface);
slouken@7191
    72
        testSurface = NULL;
slouken@7191
    73
    }
aschiffler@6773
    74
}
aschiffler@6773
    75
aschiffler@6773
    76
/**
aschiffler@6773
    77
 * Helper that clears the test surface
aschiffler@6773
    78
 */
aschiffler@6773
    79
void _clearTestSurface()
aschiffler@6773
    80
{
slouken@7191
    81
    int ret;
slouken@7191
    82
    Uint32 color;
aschiffler@6811
    83
slouken@7191
    84
    /* Clear surface. */
slouken@7191
    85
    color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
slouken@7191
    86
    SDLTest_AssertPass("Call to SDL_MapRGBA()");
slouken@7191
    87
    ret = SDL_FillRect( testSurface, NULL, color);
slouken@7191
    88
    SDLTest_AssertPass("Call to SDL_FillRect()");
slouken@7191
    89
    SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
aschiffler@6773
    90
}
aschiffler@6773
    91
aschiffler@6773
    92
/**
aschiffler@6773
    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.
aschiffler@6773
    94
 */
aschiffler@6773
    95
void _testBlitBlendMode(int mode)
aschiffler@6773
    96
{
slouken@7191
    97
    int ret;
slouken@7191
    98
    int i, j, ni, nj;
slouken@7191
    99
    SDL_Surface *face;
slouken@7191
   100
    SDL_Rect rect;
slouken@7191
   101
    int nmode;
slouken@7191
   102
    SDL_BlendMode bmode;
slouken@7191
   103
    int checkFailCount1;
slouken@7191
   104
    int checkFailCount2;
slouken@7191
   105
    int checkFailCount3;
slouken@7191
   106
    int checkFailCount4;
aschiffler@6773
   107
slouken@7191
   108
    /* Check test surface */
slouken@7191
   109
    SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL");
slouken@7191
   110
    if (testSurface == NULL) return;
aschiffler@6773
   111
slouken@7191
   112
    /* Create sample surface */
slouken@7191
   113
    face = SDLTest_ImageFace();
slouken@7191
   114
    SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
slouken@7191
   115
    if (face == NULL) return;
aschiffler@6811
   116
slouken@7191
   117
        /* Reset alpha modulation */
slouken@7191
   118
    ret = SDL_SetSurfaceAlphaMod(face, 255);
slouken@7191
   119
    SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
slouken@7191
   120
    SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
aschiffler@6811
   121
slouken@7191
   122
        /* Reset color modulation */
slouken@7191
   123
    ret = SDL_SetSurfaceColorMod(face, 255, 255, 255);
slouken@7191
   124
    SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
slouken@7191
   125
    SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
aschiffler@6811
   126
slouken@7191
   127
        /* Reset color key */
slouken@7191
   128
    ret = SDL_SetColorKey(face, SDL_FALSE, 0);
slouken@7191
   129
    SDLTest_AssertPass("Call to SDL_SetColorKey()");
slouken@7191
   130
    SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret);
slouken@7191
   131
slouken@7191
   132
    /* Clear the test surface */
aschiffler@6773
   133
        _clearTestSurface();
aschiffler@6773
   134
slouken@7191
   135
    /* Target rect size */
slouken@7191
   136
    rect.w = face->w;
slouken@7191
   137
    rect.h = face->h;
aschiffler@6773
   138
slouken@7191
   139
    /* Steps to take */
slouken@7191
   140
    ni = testSurface->w - face->w;
slouken@7191
   141
    nj = testSurface->h - face->h;
slouken@7191
   142
slouken@7191
   143
    /* Optionally set blend mode. */
slouken@7191
   144
    if (mode >= 0) {
slouken@7191
   145
        ret = SDL_SetSurfaceBlendMode( face, (SDL_BlendMode)mode );
slouken@7191
   146
        SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
slouken@7191
   147
        SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret);
slouken@7191
   148
    }
slouken@7191
   149
slouken@7191
   150
    /* Test blend mode. */
slouken@7191
   151
    checkFailCount1 = 0;
slouken@7191
   152
    checkFailCount2 = 0;
slouken@7191
   153
    checkFailCount3 = 0;
slouken@7191
   154
    checkFailCount4 = 0;
slouken@7191
   155
    for (j=0; j <= nj; j+=4) {
slouken@7191
   156
      for (i=0; i <= ni; i+=4) {
slouken@7191
   157
        if (mode == -2) {
slouken@7191
   158
            /* Set color mod. */
slouken@7191
   159
            ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
slouken@7191
   160
            if (ret != 0) checkFailCount2++;
slouken@7191
   161
        }
slouken@7191
   162
        else if (mode == -3) {
slouken@7191
   163
            /* Set alpha mod. */
slouken@7191
   164
            ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
slouken@7191
   165
            if (ret != 0) checkFailCount3++;
slouken@7191
   166
        }
slouken@7191
   167
        else if (mode == -4) {
slouken@7191
   168
            /* Crazy blending mode magic. */
slouken@7191
   169
            nmode = (i/4*j/4) % 4;
slouken@7191
   170
            if (nmode==0) {
slouken@7191
   171
                bmode = SDL_BLENDMODE_NONE;
slouken@7191
   172
            } else if (nmode==1) {
slouken@7191
   173
                bmode = SDL_BLENDMODE_BLEND;
slouken@7191
   174
            } else if (nmode==2) {
slouken@7191
   175
                bmode = SDL_BLENDMODE_ADD;
slouken@7191
   176
            } else if (nmode==3) {
slouken@7191
   177
                bmode = SDL_BLENDMODE_MOD;
slouken@7191
   178
            }
slouken@7191
   179
            ret = SDL_SetSurfaceBlendMode( face, bmode );
slouken@7191
   180
            if (ret != 0) checkFailCount4++;
slouken@7191
   181
        }
slouken@7191
   182
slouken@7191
   183
         /* Blitting. */
slouken@7191
   184
         rect.x = i;
slouken@7191
   185
         rect.y = j;
slouken@7191
   186
         ret = SDL_BlitSurface( face, NULL, testSurface, &rect );
slouken@7191
   187
         if (ret != 0) checkFailCount1++;
slouken@7191
   188
      }
slouken@7191
   189
    }
slouken@7191
   190
    SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1);
slouken@7191
   191
    SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", checkFailCount2);
slouken@7191
   192
    SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 0, got: %i", checkFailCount3);
slouken@7191
   193
    SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
slouken@7191
   194
slouken@7191
   195
    /* Clean up */
slouken@7191
   196
    if (face != NULL) {
slouken@7191
   197
        SDL_FreeSurface(face);
slouken@7191
   198
        face = NULL;
slouken@7191
   199
    }
aschiffler@6773
   200
}
aschiffler@6773
   201
aschiffler@6773
   202
/* Helper to check that a file exists */
aschiffler@6773
   203
void
aschiffler@6773
   204
_AssertFileExist(const char *filename)
aschiffler@6773
   205
{
slouken@7191
   206
    struct stat st;
slouken@7191
   207
    int ret = stat(filename, &st);
aschiffler@6773
   208
slouken@7191
   209
    SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
aschiffler@6773
   210
}
aschiffler@6773
   211
aschiffler@6773
   212
aschiffler@6773
   213
/* Test case functions */
aschiffler@6773
   214
aschiffler@6773
   215
/**
aschiffler@6773
   216
 * @brief Tests sprite saving and loading
aschiffler@6773
   217
 */
aschiffler@6773
   218
int
aschiffler@6773
   219
surface_testSaveLoadBitmap(void *arg)
aschiffler@6773
   220
{
aschiffler@6773
   221
    int ret;
aschiffler@6773
   222
    const char *sampleFilename = "testSaveLoadBitmap.bmp";
aschiffler@6773
   223
    SDL_Surface *face;
aschiffler@6773
   224
    SDL_Surface *rface;
aschiffler@6773
   225
aschiffler@6773
   226
    /* Create sample surface */
aschiffler@6773
   227
    face = SDLTest_ImageFace();
aschiffler@6773
   228
    SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
aschiffler@6779
   229
    if (face == NULL) return TEST_ABORTED;
aschiffler@6773
   230
aschiffler@6773
   231
    /* Delete test file; ignore errors */
aschiffler@6773
   232
    unlink(sampleFilename);
aschiffler@6773
   233
aschiffler@6773
   234
    /* Save a surface */
aschiffler@6773
   235
    ret = SDL_SaveBMP(face, sampleFilename);
aschiffler@6773
   236
    SDLTest_AssertPass("Call to SDL_SaveBMP()");
slouken@7191
   237
    SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret);
aschiffler@6773
   238
    _AssertFileExist(sampleFilename);
slouken@7191
   239
aschiffler@6773
   240
    /* Load a surface */
aschiffler@6773
   241
    rface = SDL_LoadBMP(sampleFilename);
aschiffler@6773
   242
    SDLTest_AssertPass("Call to SDL_LoadBMP()");
aschiffler@6773
   243
    SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
aschiffler@6773
   244
    if (rface != NULL) {
slouken@7191
   245
        SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
slouken@7191
   246
        SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
aschiffler@6773
   247
    }
aschiffler@6773
   248
aschiffler@6773
   249
    /* Delete test file; ignore errors */
aschiffler@6773
   250
    unlink(sampleFilename);
aschiffler@6773
   251
aschiffler@6773
   252
    /* Clean up */
aschiffler@6773
   253
    if (face != NULL) {
slouken@7191
   254
    SDL_FreeSurface(face);
slouken@7191
   255
    face = NULL;
aschiffler@6773
   256
    }
aschiffler@6773
   257
    if (rface != NULL) {
slouken@7191
   258
    SDL_FreeSurface(rface);
slouken@7191
   259
    rface = NULL;
aschiffler@6773
   260
    }
slouken@7191
   261
aschiffler@6773
   262
    return TEST_COMPLETED;
aschiffler@6773
   263
}
aschiffler@6773
   264
aschiffler@6773
   265
/*!
aschiffler@6773
   266
 *  Tests surface conversion.
aschiffler@6773
   267
 */
aschiffler@6773
   268
int
aschiffler@6773
   269
surface_testSurfaceConversion(void *arg)
aschiffler@6773
   270
{
slouken@7191
   271
    SDL_Surface *rface = NULL, *face = NULL;
slouken@7191
   272
    int ret = 0;
aschiffler@6773
   273
slouken@7191
   274
    /* Create sample surface */
slouken@7191
   275
    face = SDLTest_ImageFace();
slouken@7191
   276
    SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
slouken@7191
   277
    if (face == NULL)
slouken@7191
   278
        return TEST_ABORTED;
aschiffler@6773
   279
slouken@7191
   280
    /* Set transparent pixel as the pixel at (0,0) */
slouken@7191
   281
    if (face->format->palette) {
slouken@7191
   282
       ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
slouken@7191
   283
       SDLTest_AssertPass("Call to SDL_SetColorKey()");
slouken@7191
   284
       SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
slouken@7191
   285
    }
aschiffler@6773
   286
slouken@7191
   287
    /* Convert to 32 bit to compare. */
slouken@7191
   288
    rface = SDL_ConvertSurface( face, testSurface->format, 0 );
slouken@7191
   289
    SDLTest_AssertPass("Call to SDL_ConvertSurface()");
slouken@7191
   290
    SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
aschiffler@6773
   291
slouken@7191
   292
    /* Compare surface. */
slouken@7191
   293
    ret = SDLTest_CompareSurfaces( rface, face, 0 );
slouken@7191
   294
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
aschiffler@6773
   295
slouken@7191
   296
    /* Clean up. */
slouken@7191
   297
    if (face != NULL) {
slouken@7191
   298
        SDL_FreeSurface( face );
slouken@7191
   299
        face = NULL;
slouken@7191
   300
    }
slouken@7191
   301
    if (rface != NULL) {
slouken@7191
   302
        SDL_FreeSurface( rface );
slouken@7191
   303
        rface = NULL;
slouken@7191
   304
    }
slouken@7191
   305
slouken@7191
   306
    return TEST_COMPLETED;
aschiffler@6773
   307
}
aschiffler@6773
   308
aschiffler@6773
   309
aschiffler@6773
   310
/**
aschiffler@6773
   311
 * @brief Tests sprite loading. A failure case.
aschiffler@6773
   312
 */
aschiffler@6773
   313
int
aschiffler@6773
   314
surface_testLoadFailure(void *arg)
aschiffler@6773
   315
{
slouken@7191
   316
    SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
slouken@7191
   317
    SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
aschiffler@6773
   318
slouken@7191
   319
    return TEST_COMPLETED;
aschiffler@6773
   320
}
aschiffler@6773
   321
aschiffler@6773
   322
/**
aschiffler@6773
   323
 * @brief Tests some blitting routines.
aschiffler@6773
   324
 */
aschiffler@6773
   325
int
aschiffler@6773
   326
surface_testBlit(void *arg)
aschiffler@6773
   327
{
aschiffler@6773
   328
   int ret;
aschiffler@6822
   329
   SDL_Surface *compareSurface;
aschiffler@6773
   330
slouken@7191
   331
   /* Basic blitting */
aschiffler@6773
   332
   _testBlitBlendMode(-1);
slouken@7191
   333
aschiffler@6773
   334
   /* Verify result by comparing surfaces */
aschiffler@6822
   335
   compareSurface = SDLTest_ImageBlit();
aschiffler@6822
   336
   ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
aschiffler@6773
   337
   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
slouken@7191
   338
aschiffler@6773
   339
   /* Clean up. */
slouken@7191
   340
   if (compareSurface != NULL) {
slouken@7191
   341
    SDL_FreeSurface( compareSurface );
aschiffler@6773
   342
   }
aschiffler@6773
   343
aschiffler@6773
   344
   return TEST_COMPLETED;
aschiffler@6773
   345
}
aschiffler@6773
   346
aschiffler@6773
   347
/**
aschiffler@6773
   348
 * @brief Tests some blitting routines with color mod
aschiffler@6773
   349
 */
aschiffler@6773
   350
int
aschiffler@6773
   351
surface_testBlitColorMod(void *arg)
aschiffler@6773
   352
{
aschiffler@6773
   353
   int ret;
aschiffler@6822
   354
   SDL_Surface *compareSurface;
aschiffler@6773
   355
slouken@7191
   356
   /* Basic blitting with color mod */
aschiffler@6773
   357
   _testBlitBlendMode(-2);
slouken@7191
   358
aschiffler@6773
   359
   /* Verify result by comparing surfaces */
aschiffler@6822
   360
   compareSurface = SDLTest_ImageBlitColor();
aschiffler@6822
   361
   ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
aschiffler@6773
   362
   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
slouken@7191
   363
aschiffler@6773
   364
   /* Clean up. */
slouken@7191
   365
   if (compareSurface != NULL) {
slouken@7191
   366
    SDL_FreeSurface( compareSurface );
aschiffler@6773
   367
   }
aschiffler@6773
   368
aschiffler@6773
   369
   return TEST_COMPLETED;
aschiffler@6773
   370
}
aschiffler@6773
   371
aschiffler@6773
   372
/**
aschiffler@6773
   373
 * @brief Tests some blitting routines with alpha mod
aschiffler@6773
   374
 */
aschiffler@6773
   375
int
aschiffler@6773
   376
surface_testBlitAlphaMod(void *arg)
aschiffler@6773
   377
{
aschiffler@6773
   378
   int ret;
aschiffler@6822
   379
   SDL_Surface *compareSurface;
aschiffler@6773
   380
slouken@7191
   381
   /* Basic blitting with alpha mod */
aschiffler@6773
   382
   _testBlitBlendMode(-3);
slouken@7191
   383
aschiffler@6773
   384
   /* Verify result by comparing surfaces */
aschiffler@6822
   385
   compareSurface = SDLTest_ImageBlitAlpha();
aschiffler@6822
   386
   ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
aschiffler@6773
   387
   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
slouken@7191
   388
aschiffler@6773
   389
   /* Clean up. */
slouken@7191
   390
   if (compareSurface != NULL) {
slouken@7191
   391
    SDL_FreeSurface( compareSurface );
aschiffler@6773
   392
   }
aschiffler@6773
   393
aschiffler@6773
   394
   return TEST_COMPLETED;
aschiffler@6773
   395
}
aschiffler@6773
   396
aschiffler@6773
   397
aschiffler@6773
   398
/**
aschiffler@6773
   399
 * @brief Tests some more blitting routines.
aschiffler@6773
   400
 */
aschiffler@6773
   401
int
aschiffler@6773
   402
surface_testBlitBlendNone(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(SDL_BLENDMODE_NONE);
slouken@7191
   409
aschiffler@6773
   410
   /* Verify result by comparing surfaces */
aschiffler@6822
   411
   compareSurface = SDLTest_ImageBlitBlendNone();
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@7191
   416
   if (compareSurface != NULL) {
slouken@7191
   417
    SDL_FreeSurface( compareSurface );
aschiffler@6773
   418
   }
aschiffler@6773
   419
aschiffler@6773
   420
   return TEST_COMPLETED;
aschiffler@6773
   421
}
aschiffler@6773
   422
aschiffler@6773
   423
/**
aschiffler@6773
   424
 * @brief Tests some more blitting routines.
aschiffler@6773
   425
 */
aschiffler@6773
   426
int
aschiffler@6773
   427
surface_testBlitBlendBlend(void *arg)
aschiffler@6773
   428
{
aschiffler@6773
   429
   int ret;
aschiffler@6822
   430
   SDL_Surface *compareSurface;
aschiffler@6773
   431
slouken@7191
   432
   /* Blend blitting */
aschiffler@6773
   433
   _testBlitBlendMode(SDL_BLENDMODE_BLEND);
slouken@7191
   434
aschiffler@6773
   435
   /* Verify result by comparing surfaces */
aschiffler@6822
   436
   compareSurface = SDLTest_ImageBlitBlend();
aschiffler@6822
   437
   ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
aschiffler@6773
   438
   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
slouken@7191
   439
aschiffler@6773
   440
   /* Clean up. */
slouken@7191
   441
   if (compareSurface != NULL) {
slouken@7191
   442
    SDL_FreeSurface( compareSurface );
aschiffler@6773
   443
   }
aschiffler@6773
   444
aschiffler@6773
   445
   return TEST_COMPLETED;
aschiffler@6773
   446
}
aschiffler@6773
   447
aschiffler@6773
   448
/**
aschiffler@6773
   449
 * @brief Tests some more blitting routines.
aschiffler@6773
   450
 */
aschiffler@6773
   451
int
aschiffler@6773
   452
surface_testBlitBlendAdd(void *arg)
aschiffler@6773
   453
{
aschiffler@6773
   454
   int ret;
aschiffler@6822
   455
   SDL_Surface *compareSurface;
aschiffler@6773
   456
slouken@7191
   457
   /* Add blitting */
aschiffler@6773
   458
   _testBlitBlendMode(SDL_BLENDMODE_ADD);
slouken@7191
   459
aschiffler@6773
   460
   /* Verify result by comparing surfaces */
aschiffler@6822
   461
   compareSurface = SDLTest_ImageBlitBlendAdd();
aschiffler@6822
   462
   ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
aschiffler@6773
   463
   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
slouken@7191
   464
aschiffler@6773
   465
   /* Clean up. */
slouken@7191
   466
   if (compareSurface != NULL) {
slouken@7191
   467
    SDL_FreeSurface( compareSurface );
aschiffler@6773
   468
   }
aschiffler@6773
   469
aschiffler@6773
   470
   return TEST_COMPLETED;
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_testBlitBlendMod(void *arg)
aschiffler@6773
   478
{
aschiffler@6773
   479
   int ret;
aschiffler@6822
   480
   SDL_Surface *compareSurface;
aschiffler@6773
   481
slouken@7191
   482
   /* Mod blitting */
aschiffler@6773
   483
   _testBlitBlendMode(SDL_BLENDMODE_MOD);
slouken@7191
   484
aschiffler@6773
   485
   /* Verify result by comparing surfaces */
aschiffler@6822
   486
   compareSurface = SDLTest_ImageBlitBlendMod();
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@7191
   491
   if (compareSurface != NULL) {
slouken@7191
   492
      SDL_FreeSurface( compareSurface );
aschiffler@6773
   493
   }
aschiffler@6773
   494
aschiffler@6773
   495
   return TEST_COMPLETED;
aschiffler@6773
   496
}
aschiffler@6773
   497
aschiffler@6773
   498
/**
aschiffler@6773
   499
 * @brief Tests some more blitting routines with loop
aschiffler@6773
   500
 */
aschiffler@6773
   501
int
aschiffler@6773
   502
surface_testBlitBlendLoop(void *arg) {
aschiffler@6773
   503
aschiffler@6773
   504
   int ret;
aschiffler@6822
   505
   SDL_Surface *compareSurface;
aschiffler@6773
   506
slouken@7191
   507
   /* All blitting modes */
aschiffler@6773
   508
   _testBlitBlendMode(-4);
slouken@7191
   509
aschiffler@6773
   510
   /* Verify result by comparing surfaces */
aschiffler@6822
   511
   compareSurface = SDLTest_ImageBlitBlendAll();
aschiffler@6822
   512
   ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
aschiffler@6773
   513
   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
slouken@7191
   514
aschiffler@6773
   515
   /* Clean up. */
slouken@7191
   516
   if (compareSurface != NULL) {
slouken@7191
   517
     SDL_FreeSurface(compareSurface);
aschiffler@6773
   518
   }
aschiffler@6773
   519
aschiffler@6773
   520
   return TEST_COMPLETED;
aschiffler@6773
   521
aschiffler@6773
   522
}
aschiffler@6773
   523
aschiffler@6773
   524
/* ================= Test References ================== */
aschiffler@6773
   525
aschiffler@6773
   526
/* Surface test cases */
aschiffler@6773
   527
static const SDLTest_TestCaseReference surfaceTest1 =
slouken@7191
   528
        { (SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED};
aschiffler@6773
   529
aschiffler@6773
   530
static const SDLTest_TestCaseReference surfaceTest2 =
slouken@7191
   531
        { (SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED};
aschiffler@6773
   532
aschiffler@6773
   533
static const SDLTest_TestCaseReference surfaceTest3 =
slouken@7191
   534
        { (SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED};
aschiffler@6773
   535
aschiffler@6773
   536
static const SDLTest_TestCaseReference surfaceTest4 =
slouken@7191
   537
        { (SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED};
aschiffler@6773
   538
aschiffler@6773
   539
static const SDLTest_TestCaseReference surfaceTest5 =
slouken@7191
   540
        { (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
aschiffler@6773
   541
aschiffler@6773
   542
static const SDLTest_TestCaseReference surfaceTest6 =
slouken@7191
   543
        { (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
aschiffler@6773
   544
aschiffler@6773
   545
static const SDLTest_TestCaseReference surfaceTest7 =
slouken@7191
   546
        { (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
aschiffler@6773
   547
aschiffler@7172
   548
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
aschiffler@6773
   549
static const SDLTest_TestCaseReference surfaceTest8 =
slouken@7191
   550
        { (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blittin routines with verious blending modes", TEST_DISABLED};
aschiffler@6773
   551
aschiffler@7172
   552
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
aschiffler@6773
   553
static const SDLTest_TestCaseReference surfaceTest9 =
slouken@7191
   554
        { (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED};
aschiffler@6773
   555
aschiffler@7172
   556
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
aschiffler@6773
   557
static const SDLTest_TestCaseReference surfaceTest10 =
slouken@7191
   558
        { (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED};
aschiffler@6773
   559
aschiffler@6773
   560
static const SDLTest_TestCaseReference surfaceTest11 =
slouken@7191
   561
        { (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
aschiffler@6773
   562
aschiffler@6773
   563
/* Sequence of Surface test cases */
aschiffler@6773
   564
static const SDLTest_TestCaseReference *surfaceTests[] =  {
slouken@7191
   565
    &surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
slouken@7191
   566
    &surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10, &surfaceTest11, NULL
aschiffler@6773
   567
};
aschiffler@6773
   568
aschiffler@6773
   569
/* Surface test suite (global) */
aschiffler@6773
   570
SDLTest_TestSuiteReference surfaceTestSuite = {
slouken@7191
   571
    "Surface",
slouken@7191
   572
    _surfaceSetUp,
slouken@7191
   573
    surfaceTests,
slouken@7191
   574
    _surfaceTearDown
aschiffler@6773
   575
aschiffler@6773
   576
};