test/test-automation/testsurface/testsurface.c
author Markus Kauppila
Tue, 12 Jul 2011 23:53:57 +0300
changeset 5757 a97102f40230
parent 5756 3581346510f3
child 5760 735407c0bda3
permissions -rw-r--r--
Plain logger logs the used command line options.
markus@5750
     1
/**
markus@5750
     2
 * Original code: automated SDL surface test written by Edgar Simo "bobbens"
markus@5750
     3
 */
markus@5750
     4
markus@5750
     5
#include <stdio.h>
markus@5750
     6
markus@5750
     7
#include <SDL/SDL.h>
markus@5750
     8
markus@5750
     9
#include "../SDL_test.h"
markus@5750
    10
markus@5756
    11
#include <sys/stat.h>
markus@5756
    12
markus@5750
    13
/* Test case references */
markus@5750
    14
static const TestCaseReference test1 =
markus@5750
    15
		(TestCaseReference){ "surface_testLoad", "Tests sprite loading.", TEST_ENABLED, 0, 0};
markus@5750
    16
markus@5750
    17
static const TestCaseReference test2 =
markus@5750
    18
		(TestCaseReference){ "surface_testBlit", "Tests some blitting routines.", TEST_ENABLED, 0, 0};
markus@5750
    19
markus@5750
    20
static const TestCaseReference test3 =
markus@5757
    21
		(TestCaseReference){ "surface_testBlitBlendNone", "Tests blitting routines with none blending.", TEST_ENABLED, 0, 0};
markus@5750
    22
markus@5753
    23
static const TestCaseReference test4 =
markus@5753
    24
		(TestCaseReference){ "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED, 0, 0};
markus@5753
    25
markus@5756
    26
static const TestCaseReference test5 =
markus@5756
    27
		(TestCaseReference){ "surface_testConversion", "Tests sprite conversion.", TEST_ENABLED, 0, 0};
markus@5756
    28
markus@5756
    29
static const TestCaseReference test6 =
markus@5756
    30
		(TestCaseReference){ "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED, 0, 0};
markus@5756
    31
markus@5756
    32
static const TestCaseReference test7 =
markus@5756
    33
		(TestCaseReference){ "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED, 0, 0};
markus@5756
    34
markus@5756
    35
static const TestCaseReference test8 =
markus@5756
    36
		(TestCaseReference){ "surface_testBlitBlendLoop", "Test blittin routines with blending", TEST_ENABLED, 0, 0};
markus@5756
    37
markus@5756
    38
static const TestCaseReference test9 =
markus@5757
    39
		(TestCaseReference){ "surface_testBlitBlendBlend", "Tests blitting routines with blend blending.", TEST_ENABLED, 0, 0};
markus@5756
    40
markus@5756
    41
static const TestCaseReference test10 =
markus@5757
    42
		(TestCaseReference){ "surface_testBlitBlendAdd", "Tests blitting routines with add blending.", TEST_ENABLED, 0, 0};
markus@5756
    43
markus@5756
    44
static const TestCaseReference test11 =
markus@5757
    45
		(TestCaseReference){ "surface_testBlitBlendMod", "Tests blitting routines with modblending.", TEST_ENABLED, 0, 0};
markus@5750
    46
markus@5750
    47
/* Test suite */
markus@5750
    48
extern const TestCaseReference *testSuite[] =  {
markus@5756
    49
	&test1, &test2, &test3, &test4, &test5,
markus@5756
    50
	&test6, &test7, &test8, &test9, &test10, &test11, NULL
markus@5750
    51
};
markus@5750
    52
markus@5750
    53
markus@5750
    54
TestCaseReference **QueryTestSuite() {
markus@5750
    55
	return (TestCaseReference **)testSuite;
markus@5750
    56
}
markus@5750
    57
markus@5755
    58
/* Function prototypes */
markus@5755
    59
SDL_Surface *_CreateTestSurface();
markus@5755
    60
markus@5755
    61
markus@5755
    62
/* Create test fixture */
markus@5755
    63
markus@5755
    64
static SDL_Surface *testsur = NULL;
markus@5755
    65
markus@5755
    66
markus@5755
    67
void
markus@5755
    68
SetUp(void *arg)
markus@5755
    69
{
markus@5755
    70
	int ret = SDL_Init(SDL_INIT_VIDEO);
markus@5755
    71
	AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
markus@5755
    72
markus@5755
    73
	testsur = _CreateTestSurface();
markus@5755
    74
	AssertTrue(testsur != NULL, "SDL_Init(SDL_INIT_VIDEO)");
markus@5755
    75
}
markus@5755
    76
markus@5755
    77
void
markus@5755
    78
TearDown(void *arg)
markus@5755
    79
{
markus@5755
    80
	SDL_FreeSurface( testsur );
markus@5755
    81
markus@5755
    82
	SDL_Quit();
markus@5755
    83
}
markus@5755
    84
markus@5753
    85
/* Helper functions for the test cases */
markus@5753
    86
markus@5753
    87
#define TEST_SURFACE_WIDTH 80
markus@5753
    88
#define TEST_SURFACE_HEIGHT 60
markus@5750
    89
markus@5755
    90
markus@5750
    91
/*!
markus@5750
    92
 * Creates test surface
markus@5750
    93
 */
markus@5750
    94
SDL_Surface *
markus@5753
    95
_CreateTestSurface()
markus@5753
    96
{
markus@5753
    97
	SDL_Surface *testsur = NULL;
markus@5750
    98
markus@5750
    99
	/* Create the test surface. */
markus@5753
   100
	testsur = SDL_CreateRGBSurface( 0,
markus@5753
   101
			TEST_SURFACE_WIDTH, TEST_SURFACE_HEIGHT, 32,
markus@5753
   102
			RMASK, GMASK, BMASK, AMASK );
markus@5753
   103
markus@5753
   104
	if(testsur->w != TEST_SURFACE_WIDTH) {
markus@5753
   105
		AssertFail("Test surface width doesn't match");
markus@5753
   106
	}
markus@5753
   107
markus@5753
   108
	if(testsur->h != TEST_SURFACE_HEIGHT) {
markus@5753
   109
		AssertFail("Test surface height doesn't match");
markus@5753
   110
	}
markus@5750
   111
markus@5750
   112
	AssertTrue(testsur != NULL, "SDL_CreateRGBSurface");
markus@5750
   113
markus@5750
   114
	return testsur;
markus@5750
   115
}
markus@5750
   116
markus@5756
   117
/*!
markus@5756
   118
 * Create test surface from in-memory image
markus@5756
   119
 */
markus@5756
   120
SDL_Surface *
markus@5756
   121
_createTestSurfaceFromMemory()
markus@5756
   122
{
markus@5756
   123
	SDL_Surface *face = NULL;
markus@5756
   124
markus@5756
   125
	/* Create face surface. */
markus@5756
   126
	face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
markus@5756
   127
		  img_face.width, img_face.height, 32, img_face.width*4,
markus@5756
   128
	#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
markus@5756
   129
		  0xff000000, /* Red bit mask. */
markus@5756
   130
		  0x00ff0000, /* Green bit mask. */
markus@5756
   131
		  0x0000ff00, /* Blue bit mask. */
markus@5756
   132
		  0x000000ff /* Alpha bit mask. */
markus@5756
   133
	#else
markus@5756
   134
		  0x000000ff, /* Red bit mask. */
markus@5756
   135
		  0x0000ff00, /* Green bit mask. */
markus@5756
   136
		  0x00ff0000, /* Blue bit mask. */
markus@5756
   137
		  0xff000000 /* Alpha bit mask. */
markus@5756
   138
	#endif
markus@5756
   139
		  );
markus@5756
   140
	AssertTrue(face != NULL, "SDL_CreateRGBSurfaceFrom");
markus@5756
   141
markus@5756
   142
	return face;
markus@5756
   143
}
markus@5756
   144
markus@5751
   145
/**
markus@5751
   146
 * @brief Tests a blend mode.
markus@5751
   147
 */
markus@5755
   148
void _testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
markus@5750
   149
{
markus@5750
   150
	int ret;
markus@5750
   151
	int i, j, ni, nj;
markus@5750
   152
	SDL_Rect rect;
markus@5750
   153
markus@5753
   154
	AssertTrue(testsur != NULL, "testsur != NULL");
markus@5753
   155
	AssertTrue(face != NULL, "face != NULL");
markus@5753
   156
markus@5750
   157
	/* Clear surface. */
markus@5750
   158
	ret = SDL_FillRect( testsur, NULL,
markus@5750
   159
		 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5753
   160
	 AssertTrue(ret != 0, "SDL_FillRect");
markus@5750
   161
markus@5750
   162
	/* Steps to take. */
markus@5750
   163
	ni     = testsur->w - face->w;
markus@5750
   164
	nj     = testsur->h - face->h;
markus@5750
   165
markus@5750
   166
	/* Constant values. */
markus@5750
   167
	rect.w = face->w;
markus@5750
   168
	rect.h = face->h;
markus@5750
   169
markus@5750
   170
	/* Test blend mode. */
markus@5750
   171
	for (j=0; j <= nj; j+=4) {
markus@5750
   172
	  for (i=0; i <= ni; i+=4) {
markus@5750
   173
		 /* Set blend mode. */
markus@5750
   174
		 ret = SDL_SetSurfaceBlendMode( face, mode );
markus@5753
   175
		 AssertTrue(ret != 0, "SDL_SetSurfaceBlendMode");
markus@5750
   176
markus@5750
   177
		 /* Blitting. */
markus@5750
   178
		 rect.x = i;
markus@5750
   179
		 rect.y = j;
markus@5753
   180
		 // TODO Add pixel level validation, SDL_BlitSurface might be no-op
markus@5750
   181
		 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
markus@5753
   182
		 AssertTrue(ret != 0, "SDL_BlitSurface");	  }
markus@5750
   183
	}
markus@5750
   184
}
markus@5750
   185
markus@5756
   186
int
markus@5756
   187
_AssertFileExist(const char *filename)
markus@5756
   188
{
markus@5756
   189
	struct stat st;
markus@5756
   190
	int ret = stat(filename, &st);
markus@5756
   191
markus@5756
   192
	AssertTrue(ret == 0, "Does file %s exist", filename);
markus@5756
   193
}
markus@5756
   194
markus@5750
   195
/* Test case functions */
markus@5750
   196
/**
markus@5756
   197
 * @brief Tests sprite loading
markus@5750
   198
 */
markus@5750
   199
void surface_testLoad(void *arg)
markus@5750
   200
{
markus@5750
   201
	int ret;
markus@5750
   202
    SDL_Surface *face, *rface;
markus@5750
   203
markus@5755
   204
    /* Clear surface. */
markus@5756
   205
    /*
markus@5755
   206
    ret = SDL_FillRect( testsur, NULL,
markus@5750
   207
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5750
   208
	AssertTrue(ret == 0,  "SDL_FillRect");
markus@5756
   209
	*/
markus@5750
   210
markus@5750
   211
   /* Create the blit surface. */
markus@5756
   212
	const char *filename = "icon.bmp";
markus@5756
   213
	_AssertFileExist(filename);
markus@5750
   214
markus@5756
   215
	face = SDL_LoadBMP(filename);
markus@5750
   216
	AssertTrue(face != NULL, "SDL_CreateLoadBmp");
markus@5750
   217
markus@5756
   218
	AssertTrue(face->w == 32, "testing icon width");
markus@5756
   219
	AssertTrue(face->h == 32, "testing icon height");
markus@5756
   220
}
markus@5756
   221
markus@5756
   222
/*!
markus@5756
   223
 *  Tests sprite conversion.
markus@5756
   224
 */
markus@5756
   225
void surface_testConversion(void *arg)
markus@5756
   226
{
markus@5756
   227
	SDL_Surface *rface = NULL, *face = NULL;
markus@5756
   228
	int ret = 0;
markus@5756
   229
markus@5756
   230
	const char *filename = "icon.bmp";
markus@5756
   231
	_AssertFileExist(filename);
markus@5750
   232
markus@5756
   233
	face = SDL_LoadBMP(filename);
markus@5756
   234
	AssertTrue(face != NULL, "SDL_CreateLoadBmp");
markus@5750
   235
markus@5756
   236
	/* Set transparent pixel as the pixel at (0,0) */
markus@5756
   237
	if (face->format->palette) {
markus@5756
   238
	  ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
markus@5756
   239
	  AssertTrue(ret == 0, "SDL_SetColorKey");
markus@5756
   240
	}
markus@5756
   241
markus@5756
   242
	/* Convert to 32 bit to compare. */
markus@5756
   243
	rface = SDL_ConvertSurface( face, testsur->format, 0 );
markus@5756
   244
	AssertTrue(rface != NULL, "SDL_ConvertSurface");
markus@5756
   245
markus@5756
   246
	/* See if it's the same. */
markus@5756
   247
	AssertTrue(surface_compare( rface, &img_face, 0 ) == 0,
markus@5752
   248
		   "Comparing primitives output.");
markus@5750
   249
markus@5756
   250
	/* Clean up. */
markus@5756
   251
	SDL_FreeSurface( rface );
markus@5756
   252
	SDL_FreeSurface( face );
markus@5750
   253
}
markus@5750
   254
markus@5750
   255
markus@5750
   256
/**
markus@5753
   257
 * @brief Tests sprite loading. A failure case.
markus@5753
   258
 */
markus@5753
   259
void surface_testLoadFailure(void *arg)
markus@5753
   260
{
markus@5753
   261
	SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
markus@5753
   262
	AssertTrue(face == NULL, "SDL_CreateLoadBmp");
markus@5753
   263
}
markus@5753
   264
markus@5753
   265
/**
markus@5750
   266
 * @brief Tests some blitting routines.
markus@5750
   267
 */
markus@5750
   268
void surface_testBlit(void *arg)
markus@5750
   269
{
markus@5750
   270
   int ret;
markus@5750
   271
   SDL_Rect rect;
markus@5750
   272
   SDL_Surface *face;
markus@5750
   273
   int i, j, ni, nj;
markus@5750
   274
markus@5750
   275
   /* Clear surface. */
markus@5756
   276
markus@5750
   277
   ret = SDL_FillRect( testsur, NULL,
markus@5750
   278
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5750
   279
markus@5750
   280
   AssertTrue(ret == 0, "SDL_FillRect");
markus@5750
   281
markus@5756
   282
   face = _createTestSurfaceFromMemory();
markus@5750
   283
markus@5750
   284
   /* Constant values. */
markus@5750
   285
   rect.w = face->w;
markus@5750
   286
   rect.h = face->h;
markus@5750
   287
   ni     = testsur->w - face->w;
markus@5750
   288
   nj     = testsur->h - face->h;
markus@5750
   289
markus@5750
   290
   /* Loop blit. */
markus@5750
   291
   for (j=0; j <= nj; j+=4) {
markus@5750
   292
      for (i=0; i <= ni; i+=4) {
markus@5750
   293
         /* Blitting. */
markus@5750
   294
         rect.x = i;
markus@5750
   295
         rect.y = j;
markus@5753
   296
         // TODO Add pixel level validation, SDL_BlitSurface might be no-op
markus@5750
   297
         ret = SDL_BlitSurface( face, NULL, testsur, &rect );
markus@5750
   298
markus@5750
   299
         AssertTrue(ret == 0, "SDL_BlitSurface");
markus@5750
   300
      }
markus@5750
   301
   }
markus@5750
   302
markus@5750
   303
   /* See if it's the same. */
markus@5750
   304
   AssertTrue(surface_compare( testsur, &img_blit, 0 ) == 0,
markus@5752
   305
		   "Comparing blitting output (normal blit).");
markus@5750
   306
markus@5756
   307
   /* Clean up. */
markus@5756
   308
   SDL_FreeSurface( face );
markus@5756
   309
}
markus@5756
   310
markus@5756
   311
/**
markus@5756
   312
 * @brief Tests some blitting routines with color mod
markus@5756
   313
 */
markus@5756
   314
void surface_testBlitColorMod(void *arg)
markus@5756
   315
{
markus@5756
   316
   int ret;
markus@5756
   317
   SDL_Rect rect;
markus@5756
   318
   SDL_Surface *face;
markus@5756
   319
   int i, j, ni, nj;
markus@5756
   320
markus@5750
   321
   /* Clear surface. */
markus@5756
   322
markus@5750
   323
   ret = SDL_FillRect( testsur, NULL,
markus@5750
   324
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5756
   325
markus@5750
   326
   AssertTrue(ret == 0, "SDL_FillRect");
markus@5750
   327
markus@5756
   328
   face = _createTestSurfaceFromMemory();
markus@5756
   329
markus@5756
   330
   /* Constant values. */
markus@5756
   331
   rect.w = face->w;
markus@5756
   332
   rect.h = face->h;
markus@5756
   333
   ni     = testsur->w - face->w;
markus@5756
   334
   nj     = testsur->h - face->h;
markus@5756
   335
markus@5756
   336
   /* Clear surface. */
markus@5756
   337
    ret = SDL_FillRect( testsur, NULL,
markus@5756
   338
          SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5756
   339
    AssertTrue(ret == 0, "SDL_FillRect");
markus@5756
   340
markus@5756
   341
    /* Test blitting with colour mod. */
markus@5756
   342
    for (j=0; j <= nj; j+=4) {
markus@5756
   343
       for (i=0; i <= ni; i+=4) {
markus@5756
   344
          /* Set colour mod. */
markus@5756
   345
          ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
markus@5756
   346
          AssertTrue(ret == 0, "SDL_SetSurfaceColorMod");
markus@5756
   347
markus@5756
   348
          /* Blitting. */
markus@5756
   349
          rect.x = i;
markus@5756
   350
          rect.y = j;
markus@5756
   351
          // TODO Add pixel level validation, SDL_BlitSurface might be no-op
markus@5756
   352
          ret = SDL_BlitSurface( face, NULL, testsur, &rect );
markus@5756
   353
markus@5756
   354
          AssertTrue(ret == 0, "SDL_BlitSurface");
markus@5756
   355
       }
markus@5756
   356
    }
markus@5750
   357
markus@5756
   358
    /* See if it's the same. */
markus@5756
   359
    AssertTrue(surface_compare( testsur, &img_blitColour, 0 ) == 0,
markus@5756
   360
 		   "Comparing blitting output (using SDL_SetSurfaceColorMod).");
markus@5756
   361
markus@5756
   362
   /* Clean up. */
markus@5756
   363
   SDL_FreeSurface( face );
markus@5756
   364
}
markus@5750
   365
markus@5756
   366
/**
markus@5756
   367
 * @brief Tests some blitting routines with alpha mod
markus@5756
   368
 */
markus@5756
   369
void surface_testBlitAlphaMod(void *arg)
markus@5756
   370
{
markus@5756
   371
   int ret;
markus@5756
   372
   SDL_Rect rect;
markus@5756
   373
   SDL_Surface *face;
markus@5756
   374
   int i, j, ni, nj;
markus@5756
   375
markus@5756
   376
   /* Clear surface. */
markus@5750
   377
markus@5756
   378
   ret = SDL_FillRect( testsur, NULL,
markus@5756
   379
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5756
   380
markus@5756
   381
   AssertTrue(ret == 0, "SDL_FillRect");
markus@5756
   382
markus@5756
   383
   face = _createTestSurfaceFromMemory();
markus@5756
   384
markus@5756
   385
   /* Constant values. */
markus@5756
   386
   rect.w = face->w;
markus@5756
   387
   rect.h = face->h;
markus@5756
   388
   ni     = testsur->w - face->w;
markus@5756
   389
   nj     = testsur->h - face->h;
markus@5750
   390
markus@5750
   391
   /* Clear surface. */
markus@5750
   392
   ret = SDL_FillRect( testsur, NULL,
markus@5750
   393
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5750
   394
   AssertTrue(ret == 0, "SDL_FillRect");
markus@5750
   395
markus@5750
   396
   /* Restore colour. */
markus@5750
   397
   ret = SDL_SetSurfaceColorMod( face, 255, 255, 255 );
markus@5750
   398
   AssertTrue(ret == 0, "SDL_SetSurfaceColorMod");
markus@5750
   399
markus@5750
   400
   /* Test blitting with colour mod. */
markus@5750
   401
   for (j=0; j <= nj; j+=4) {
markus@5750
   402
      for (i=0; i <= ni; i+=4) {
markus@5750
   403
         /* Set alpha mod. */
markus@5750
   404
         ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
markus@5750
   405
         AssertTrue(ret == 0, "SDL_SetSurfaceAlphaMod");
markus@5750
   406
markus@5750
   407
         /* Blitting. */
markus@5750
   408
         rect.x = i;
markus@5750
   409
         rect.y = j;
markus@5753
   410
         // TODO Add pixel level validation, SDL_BlitSurface might be no-op
markus@5750
   411
         ret = SDL_BlitSurface( face, NULL, testsur, &rect );
markus@5750
   412
         AssertTrue(ret == 0, "SDL_BlitSurface");
markus@5750
   413
      }
markus@5750
   414
   }
markus@5750
   415
markus@5750
   416
   /* See if it's the same. */
markus@5750
   417
   AssertTrue(surface_compare( testsur, &img_blitAlpha, 0 ) == 0,
markus@5752
   418
		   "Comparing blitting output (using SDL_SetSurfaceAlphaMod).");
markus@5750
   419
markus@5750
   420
   /* Clean up. */
markus@5750
   421
   SDL_FreeSurface( face );
markus@5750
   422
}
markus@5750
   423
markus@5756
   424
markus@5750
   425
/**
markus@5750
   426
 * @brief Tests some more blitting routines.
markus@5750
   427
 */
markus@5756
   428
void surface_testBlitBlendNone(void *arg)
markus@5750
   429
{
markus@5750
   430
   int ret;
markus@5750
   431
   SDL_Rect rect;
markus@5750
   432
   SDL_Surface *face;
markus@5750
   433
   int i, j, ni, nj;
markus@5750
   434
   int mode;
markus@5750
   435
markus@5750
   436
   /* Clear surface. */
markus@5750
   437
   ret = SDL_FillRect( testsur, NULL,
markus@5750
   438
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5750
   439
   AssertTrue(ret == 0, "SDL_FillRect");
markus@5750
   440
markus@5756
   441
   face = _createTestSurfaceFromMemory();
markus@5756
   442
markus@5756
   443
   /* Set alpha mod. */
markus@5756
   444
   // TODO alpha value could be generated by fuzzer
markus@5756
   445
   ret = SDL_SetSurfaceAlphaMod( face, 100 );
markus@5756
   446
   AssertTrue(ret == 0, "SDL_SetSurfaceAlphaMod");
markus@5756
   447
markus@5756
   448
   /* Steps to take. */
markus@5756
   449
   ni     = testsur->w - face->w;
markus@5756
   450
   nj     = testsur->h - face->h;
markus@5756
   451
markus@5756
   452
   AssertTrue(ni != 0, "ni != 0");
markus@5756
   453
   AssertTrue(nj != 0, "nj != 0");
markus@5756
   454
markus@5756
   455
   /* Constant values. */
markus@5756
   456
   rect.w = face->w;
markus@5756
   457
   rect.h = face->h;
markus@5756
   458
   /* Test None. */
markus@5756
   459
  _testBlitBlendMode( testsur, face, SDL_BLENDMODE_NONE );
markus@5756
   460
   AssertTrue(surface_compare( testsur, &img_blendNone, 0 ) == 0,
markus@5756
   461
   		   "Comparing blitting blending output (using SDL_BLENDMODE_NONE).");
markus@5756
   462
markus@5756
   463
   /* Test Blend. */
markus@5756
   464
   _testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND );
markus@5756
   465
   AssertTrue(surface_compare( testsur, &img_blendBlend, 0 ) == 0,
markus@5756
   466
   		   "Comparing blitting blending output (using SDL_BLENDMODE_BLEND).");
markus@5756
   467
markus@5756
   468
   /* Test Add. */
markus@5756
   469
   _testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD );
markus@5756
   470
   AssertTrue(surface_compare( testsur, &img_blendAdd, 0 ) == 0,
markus@5756
   471
   		      "Comparing blitting blending output (using SDL_BLENDMODE_ADD).");
markus@5756
   472
markus@5756
   473
   /* Test Mod. */
markus@5756
   474
   _testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD );
markus@5756
   475
   AssertTrue(surface_compare( testsur, &img_blendMod, 0 ) == 0,
markus@5756
   476
   		      "Comparing blitting blending output not the same (using SDL_BLENDMODE_MOD).");
markus@5756
   477
}
markus@5756
   478
markus@5756
   479
/**
markus@5756
   480
 * @brief Tests some more blitting routines.
markus@5756
   481
 */
markus@5756
   482
void surface_testBlitBlendBlend(void *arg)
markus@5756
   483
{
markus@5756
   484
   int ret;
markus@5756
   485
   SDL_Rect rect;
markus@5756
   486
   SDL_Surface *face;
markus@5756
   487
   int i, j, ni, nj;
markus@5756
   488
   int mode;
markus@5756
   489
markus@5756
   490
   /* Clear surface. */
markus@5756
   491
   ret = SDL_FillRect( testsur, NULL,
markus@5756
   492
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5756
   493
   AssertTrue(ret == 0, "SDL_FillRect");
markus@5756
   494
markus@5756
   495
   face = _createTestSurfaceFromMemory();
markus@5750
   496
markus@5750
   497
   /* Set alpha mod. */
markus@5753
   498
   // TODO alpha value could be generated by fuzzer
markus@5750
   499
   ret = SDL_SetSurfaceAlphaMod( face, 100 );
markus@5750
   500
   AssertTrue(ret == 0, "SDL_SetSurfaceAlphaMod");
markus@5750
   501
markus@5750
   502
   /* Steps to take. */
markus@5750
   503
   ni     = testsur->w - face->w;
markus@5750
   504
   nj     = testsur->h - face->h;
markus@5750
   505
markus@5753
   506
   AssertTrue(ni != 0, "ni != 0");
markus@5753
   507
   AssertTrue(nj != 0, "nj != 0");
markus@5753
   508
markus@5750
   509
   /* Constant values. */
markus@5750
   510
   rect.w = face->w;
markus@5750
   511
   rect.h = face->h;
markus@5750
   512
markus@5750
   513
   /* Test Blend. */
markus@5753
   514
   _testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND );
markus@5750
   515
   AssertTrue(surface_compare( testsur, &img_blendBlend, 0 ) == 0,
markus@5752
   516
   		   "Comparing blitting blending output (using SDL_BLENDMODE_BLEND).");
markus@5756
   517
}
markus@5756
   518
markus@5756
   519
/**
markus@5756
   520
 * @brief Tests some more blitting routines.
markus@5756
   521
 */
markus@5756
   522
void surface_testBlitBlendAdd(void *arg)
markus@5756
   523
{
markus@5756
   524
   int ret;
markus@5756
   525
   SDL_Rect rect;
markus@5756
   526
   SDL_Surface *face;
markus@5756
   527
   int i, j, ni, nj;
markus@5756
   528
   int mode;
markus@5756
   529
markus@5756
   530
   /* Clear surface. */
markus@5756
   531
   ret = SDL_FillRect( testsur, NULL,
markus@5756
   532
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5756
   533
   AssertTrue(ret == 0, "SDL_FillRect");
markus@5756
   534
markus@5756
   535
   face = _createTestSurfaceFromMemory();
markus@5756
   536
markus@5756
   537
   /* Set alpha mod. */
markus@5756
   538
   // TODO alpha value could be generated by fuzzer
markus@5756
   539
   ret = SDL_SetSurfaceAlphaMod( face, 100 );
markus@5756
   540
   AssertTrue(ret == 0, "SDL_SetSurfaceAlphaMod");
markus@5756
   541
markus@5756
   542
   /* Steps to take. */
markus@5756
   543
   ni     = testsur->w - face->w;
markus@5756
   544
   nj     = testsur->h - face->h;
markus@5756
   545
markus@5756
   546
   AssertTrue(ni != 0, "ni != 0");
markus@5756
   547
   AssertTrue(nj != 0, "nj != 0");
markus@5756
   548
markus@5756
   549
   /* Constant values. */
markus@5756
   550
   rect.w = face->w;
markus@5756
   551
   rect.h = face->h;
markus@5750
   552
markus@5750
   553
   /* Test Add. */
markus@5753
   554
   _testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD );
markus@5750
   555
   AssertTrue(surface_compare( testsur, &img_blendAdd, 0 ) == 0,
markus@5752
   556
   		      "Comparing blitting blending output (using SDL_BLENDMODE_ADD).");
markus@5756
   557
}
markus@5756
   558
markus@5756
   559
/**
markus@5756
   560
 * @brief Tests some more blitting routines.
markus@5756
   561
 */
markus@5756
   562
void surface_testBlitBlendMod(void *arg)
markus@5756
   563
{
markus@5756
   564
   int ret;
markus@5756
   565
   SDL_Rect rect;
markus@5756
   566
   SDL_Surface *face;
markus@5756
   567
   int i, j, ni, nj;
markus@5756
   568
   int mode;
markus@5756
   569
markus@5756
   570
   /* Clear surface. */
markus@5756
   571
   ret = SDL_FillRect( testsur, NULL,
markus@5756
   572
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5756
   573
   AssertTrue(ret == 0, "SDL_FillRect");
markus@5756
   574
markus@5756
   575
   face = _createTestSurfaceFromMemory();
markus@5756
   576
markus@5756
   577
   /* Set alpha mod. */
markus@5756
   578
   // TODO alpha value could be generated by fuzzer
markus@5756
   579
   ret = SDL_SetSurfaceAlphaMod( face, 100 );
markus@5756
   580
   AssertTrue(ret == 0, "SDL_SetSurfaceAlphaMod");
markus@5756
   581
markus@5756
   582
   /* Steps to take. */
markus@5756
   583
   ni     = testsur->w - face->w;
markus@5756
   584
   nj     = testsur->h - face->h;
markus@5756
   585
markus@5756
   586
   AssertTrue(ni != 0, "ni != 0");
markus@5756
   587
   AssertTrue(nj != 0, "nj != 0");
markus@5756
   588
markus@5756
   589
   /* Constant values. */
markus@5756
   590
   rect.w = face->w;
markus@5756
   591
   rect.h = face->h;
markus@5756
   592
   /* Test None. */
markus@5750
   593
markus@5750
   594
   /* Test Mod. */
markus@5753
   595
   _testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD );
markus@5750
   596
   AssertTrue(surface_compare( testsur, &img_blendMod, 0 ) == 0,
markus@5756
   597
   		      "Comparing blitting blending output (using SDL_BLENDMODE_MOD).");
markus@5756
   598
}
markus@5756
   599
markus@5756
   600
/**
markus@5756
   601
 * @brief Tests some more blitting routines with loop
markus@5756
   602
 */
markus@5756
   603
void surface_testBlitBlendLoop(void *arg) {
markus@5756
   604
	int ret;
markus@5756
   605
	SDL_Rect rect;
markus@5756
   606
	SDL_Surface *face;
markus@5756
   607
	int i, j, ni, nj;
markus@5756
   608
	int mode;
markus@5756
   609
markus@5756
   610
	/* Clear surface. */
markus@5756
   611
	ret = SDL_FillRect( testsur, NULL,
markus@5756
   612
		 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5756
   613
	AssertTrue(ret == 0, "SDL_FillRect");
markus@5756
   614
markus@5756
   615
	face = _createTestSurfaceFromMemory();
markus@5756
   616
markus@5756
   617
	/* Set alpha mod. */
markus@5756
   618
	// TODO alpha value could be generated by fuzzer
markus@5756
   619
	ret = SDL_SetSurfaceAlphaMod( face, 100 );
markus@5756
   620
	AssertTrue(ret == 0, "SDL_SetSurfaceAlphaMod");
markus@5756
   621
markus@5756
   622
	/* Steps to take. */
markus@5756
   623
	ni     = testsur->w - face->w;
markus@5756
   624
	nj     = testsur->h - face->h;
markus@5756
   625
markus@5756
   626
	AssertTrue(ni != 0, "ni != 0");
markus@5756
   627
	AssertTrue(nj != 0, "nj != 0");
markus@5756
   628
markus@5756
   629
	/* Constant values. */
markus@5756
   630
	rect.w = face->w;
markus@5756
   631
	rect.h = face->h;
markus@5750
   632
markus@5750
   633
   /* Clear surface. */
markus@5750
   634
   ret = SDL_FillRect( testsur, NULL,
markus@5750
   635
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
markus@5750
   636
markus@5750
   637
   AssertTrue(ret == 0, "SDL_FillRect");
markus@5750
   638
markus@5750
   639
   /* Loop blit. */
markus@5750
   640
   for (j=0; j <= nj; j+=4) {
markus@5750
   641
      for (i=0; i <= ni; i+=4) {
markus@5750
   642
markus@5750
   643
         /* Set colour mod. */
markus@5750
   644
         ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
markus@5750
   645
         AssertTrue(ret == 0, "SDL_SetSurfaceColorMod");
markus@5750
   646
markus@5750
   647
         /* Set alpha mod. */
markus@5750
   648
         ret = SDL_SetSurfaceAlphaMod( face, (100/ni)*i );
markus@5750
   649
         AssertTrue(ret == 0, "SDL_SetSurfaceAlphaMod");
markus@5750
   650
markus@5750
   651
         /* Crazy blending mode magic. */
markus@5750
   652
         mode = (i/4*j/4) % 4;
markus@5750
   653
         if (mode==0) mode = SDL_BLENDMODE_NONE;
markus@5750
   654
         else if (mode==1) mode = SDL_BLENDMODE_BLEND;
markus@5750
   655
         else if (mode==2) mode = SDL_BLENDMODE_ADD;
markus@5750
   656
         else if (mode==3) mode = SDL_BLENDMODE_MOD;
markus@5750
   657
         ret = SDL_SetSurfaceBlendMode( face, mode );
markus@5750
   658
markus@5750
   659
         AssertTrue(ret == 0, "SDL_SetSurfaceBlendMode");
markus@5750
   660
markus@5750
   661
         /* Blitting. */
markus@5750
   662
         rect.x = i;
markus@5750
   663
         rect.y = j;
markus@5750
   664
         ret = SDL_BlitSurface( face, NULL, testsur, &rect );
markus@5750
   665
         AssertTrue(ret == 0, "SDL_BlitSurface");
markus@5750
   666
      }
markus@5750
   667
   }
markus@5750
   668
markus@5750
   669
   /* Check to see if matches. */
markus@5750
   670
   AssertTrue(surface_compare( testsur, &img_blendAll, 0 ) == 0,
markus@5752
   671
		      "Surface comparison (surface_compare).");
markus@5750
   672
markus@5750
   673
   /* Clean up. */
markus@5750
   674
   SDL_FreeSurface( face );
markus@5750
   675
}