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