Fixes based on CR.
authorMarkus Kauppila
Mon, 11 Jul 2011 17:47:55 +0300
changeset 57535e8c5282cac0
parent 5752 528866846266
child 5754 2eead798346a
Fixes based on CR.
test/test-automation/testsurface/testsurface.c
     1.1 --- a/test/test-automation/testsurface/testsurface.c	Sun Jul 10 18:48:31 2011 +0300
     1.2 +++ b/test/test-automation/testsurface/testsurface.c	Mon Jul 11 17:47:55 2011 +0300
     1.3 @@ -8,10 +8,6 @@
     1.4  
     1.5  #include "../SDL_test.h"
     1.6  
     1.7 -#include "../common/common.h"
     1.8 -#include "../common/images.h"
     1.9 -
    1.10 -
    1.11  /* Test case references */
    1.12  static const TestCaseReference test1 =
    1.13  		(TestCaseReference){ "surface_testLoad", "Tests sprite loading.", TEST_ENABLED, 0, 0};
    1.14 @@ -22,10 +18,13 @@
    1.15  static const TestCaseReference test3 =
    1.16  		(TestCaseReference){ "surface_testBlitBlend", "Tests some more blitting routines.", TEST_ENABLED, 0, 0};
    1.17  
    1.18 +static const TestCaseReference test4 =
    1.19 +		(TestCaseReference){ "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED, 0, 0};
    1.20 +
    1.21  
    1.22  /* Test suite */
    1.23  extern const TestCaseReference *testSuite[] =  {
    1.24 -	&test1, &test2, &test3, NULL
    1.25 +	&test1, &test2, &test3, &test4, NULL
    1.26  };
    1.27  
    1.28  
    1.29 @@ -33,18 +32,31 @@
    1.30  	return (TestCaseReference **)testSuite;
    1.31  }
    1.32  
    1.33 -/* Test helpers */
    1.34 +/* Helper functions for the test cases */
    1.35 +
    1.36 +#define TEST_SURFACE_WIDTH 80
    1.37 +#define TEST_SURFACE_HEIGHT 60
    1.38  
    1.39  /*!
    1.40   * Creates test surface
    1.41   */
    1.42  SDL_Surface *
    1.43 -CreateTestSurface() {
    1.44 -	SDL_Surface *testsur;
    1.45 +_CreateTestSurface()
    1.46 +{
    1.47 +	SDL_Surface *testsur = NULL;
    1.48  
    1.49  	/* Create the test surface. */
    1.50 -	testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
    1.51 -		 RMASK, GMASK, BMASK, AMASK );
    1.52 +	testsur = SDL_CreateRGBSurface( 0,
    1.53 +			TEST_SURFACE_WIDTH, TEST_SURFACE_HEIGHT, 32,
    1.54 +			RMASK, GMASK, BMASK, AMASK );
    1.55 +
    1.56 +	if(testsur->w != TEST_SURFACE_WIDTH) {
    1.57 +		AssertFail("Test surface width doesn't match");
    1.58 +	}
    1.59 +
    1.60 +	if(testsur->h != TEST_SURFACE_HEIGHT) {
    1.61 +		AssertFail("Test surface height doesn't match");
    1.62 +	}
    1.63  
    1.64  	AssertTrue(testsur != NULL, "SDL_CreateRGBSurface");
    1.65  
    1.66 @@ -54,17 +66,19 @@
    1.67  /**
    1.68   * @brief Tests a blend mode.
    1.69   */
    1.70 -int testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
    1.71 +int _testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
    1.72  {
    1.73  	int ret;
    1.74  	int i, j, ni, nj;
    1.75  	SDL_Rect rect;
    1.76  
    1.77 +	AssertTrue(testsur != NULL, "testsur != NULL");
    1.78 +	AssertTrue(face != NULL, "face != NULL");
    1.79 +
    1.80  	/* Clear surface. */
    1.81  	ret = SDL_FillRect( testsur, NULL,
    1.82  		 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
    1.83 -	if(ret == 0)
    1.84 -		return 1;
    1.85 +	 AssertTrue(ret != 0, "SDL_FillRect");
    1.86  
    1.87  	/* Steps to take. */
    1.88  	ni     = testsur->w - face->w;
    1.89 @@ -79,16 +93,14 @@
    1.90  	  for (i=0; i <= ni; i+=4) {
    1.91  		 /* Set blend mode. */
    1.92  		 ret = SDL_SetSurfaceBlendMode( face, mode );
    1.93 -		 if (ret == 0)
    1.94 -			return 1;
    1.95 +		 AssertTrue(ret != 0, "SDL_SetSurfaceBlendMode");
    1.96  
    1.97  		 /* Blitting. */
    1.98  		 rect.x = i;
    1.99  		 rect.y = j;
   1.100 +		 // TODO Add pixel level validation, SDL_BlitSurface might be no-op
   1.101  		 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
   1.102 -		 if(ret == 0)
   1.103 -			return 1;
   1.104 -	  }
   1.105 +		 AssertTrue(ret != 0, "SDL_BlitSurface");	  }
   1.106  	}
   1.107  
   1.108  	return 0;
   1.109 @@ -106,7 +118,7 @@
   1.110  	ret = SDL_Init(SDL_INIT_VIDEO);
   1.111  	AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
   1.112  
   1.113 -	SDL_Surface *testsur = CreateTestSurface();
   1.114 +	SDL_Surface *testsur = _CreateTestSurface();
   1.115  
   1.116     /* Clear surface. */
   1.117     ret = SDL_FillRect( testsur, NULL,
   1.118 @@ -147,6 +159,22 @@
   1.119  
   1.120  
   1.121  /**
   1.122 + * @brief Tests sprite loading. A failure case.
   1.123 + */
   1.124 +void surface_testLoadFailure(void *arg)
   1.125 +{
   1.126 +	int ret = SDL_Init(SDL_INIT_VIDEO);
   1.127 +	AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
   1.128 +
   1.129 +	SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
   1.130 +
   1.131 +	AssertTrue(face == NULL, "SDL_CreateLoadBmp");
   1.132 +
   1.133 +	SDL_Quit();
   1.134 +}
   1.135 +
   1.136 +
   1.137 +/**
   1.138   * @brief Tests some blitting routines.
   1.139   */
   1.140  void surface_testBlit(void *arg)
   1.141 @@ -159,7 +187,7 @@
   1.142  	ret = SDL_Init(SDL_INIT_VIDEO);
   1.143  	AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
   1.144  
   1.145 -   SDL_Surface *testsur = CreateTestSurface();
   1.146 +   SDL_Surface *testsur = _CreateTestSurface();
   1.147  
   1.148     /* Clear surface. */
   1.149     ret = SDL_FillRect( testsur, NULL,
   1.150 @@ -196,6 +224,7 @@
   1.151           /* Blitting. */
   1.152           rect.x = i;
   1.153           rect.y = j;
   1.154 +         // TODO Add pixel level validation, SDL_BlitSurface might be no-op
   1.155           ret = SDL_BlitSurface( face, NULL, testsur, &rect );
   1.156  
   1.157           AssertTrue(ret == 0, "SDL_BlitSurface");
   1.158 @@ -221,6 +250,7 @@
   1.159           /* Blitting. */
   1.160           rect.x = i;
   1.161           rect.y = j;
   1.162 +         // TODO Add pixel level validation, SDL_BlitSurface might be no-op
   1.163           ret = SDL_BlitSurface( face, NULL, testsur, &rect );
   1.164  
   1.165           AssertTrue(ret == 0, "SDL_BlitSurface");
   1.166 @@ -250,6 +280,7 @@
   1.167           /* Blitting. */
   1.168           rect.x = i;
   1.169           rect.y = j;
   1.170 +         // TODO Add pixel level validation, SDL_BlitSurface might be no-op
   1.171           ret = SDL_BlitSurface( face, NULL, testsur, &rect );
   1.172           AssertTrue(ret == 0, "SDL_BlitSurface");
   1.173        }
   1.174 @@ -280,7 +311,7 @@
   1.175  	ret = SDL_Init(SDL_INIT_VIDEO);
   1.176  	AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");
   1.177  
   1.178 -   SDL_Surface *testsur = CreateTestSurface();
   1.179 +   SDL_Surface *testsur = _CreateTestSurface();
   1.180  
   1.181     /* Clear surface. */
   1.182     ret = SDL_FillRect( testsur, NULL,
   1.183 @@ -306,6 +337,7 @@
   1.184     AssertTrue(face != NULL, "SDL_CreateRGBSurfaceFrom");
   1.185  
   1.186     /* Set alpha mod. */
   1.187 +   // TODO alpha value could be generated by fuzzer
   1.188     ret = SDL_SetSurfaceAlphaMod( face, 100 );
   1.189     AssertTrue(ret == 0, "SDL_SetSurfaceAlphaMod");
   1.190  
   1.191 @@ -313,31 +345,31 @@
   1.192     ni     = testsur->w - face->w;
   1.193     nj     = testsur->h - face->h;
   1.194  
   1.195 +   AssertTrue(ni != 0, "ni != 0");
   1.196 +   AssertTrue(nj != 0, "nj != 0");
   1.197 +
   1.198     /* Constant values. */
   1.199     rect.w = face->w;
   1.200     rect.h = face->h;
   1.201  
   1.202     /* Test None. */
   1.203 -   if (testBlitBlendMode( testsur, face, SDL_BLENDMODE_NONE ))
   1.204 -      return;
   1.205 +  _testBlitBlendMode( testsur, face, SDL_BLENDMODE_NONE );
   1.206 +
   1.207     AssertTrue(surface_compare( testsur, &img_blendNone, 0 ) == 0,
   1.208     		   "Comparing blitting blending output (using SDL_BLENDMODE_NONE).");
   1.209  
   1.210     /* Test Blend. */
   1.211 -   if (testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND ))
   1.212 -      return;
   1.213 +   _testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND );
   1.214     AssertTrue(surface_compare( testsur, &img_blendBlend, 0 ) == 0,
   1.215     		   "Comparing blitting blending output (using SDL_BLENDMODE_BLEND).");
   1.216  
   1.217     /* Test Add. */
   1.218 -   if (testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD ))
   1.219 -      return;
   1.220 +   _testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD );
   1.221     AssertTrue(surface_compare( testsur, &img_blendAdd, 0 ) == 0,
   1.222     		      "Comparing blitting blending output (using SDL_BLENDMODE_ADD).");
   1.223  
   1.224     /* Test Mod. */
   1.225 -   if (testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD ))
   1.226 -      return;
   1.227 +   _testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD );
   1.228     AssertTrue(surface_compare( testsur, &img_blendMod, 0 ) == 0,
   1.229     		      "Comparing blitting blending output not the same (using SDL_BLENDMODE_MOD).");
   1.230