Add surface test suite; minor improvements to render suite; refactor image saving into test lib compare function; fix for Haiku build
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Wed, 26 Dec 2012 22:26:44 -0800
changeset 6773 5ebc5a9e35b4
parent 6772 5229a117ef97
child 6774 ad8522052ce6
Add surface test suite; minor improvements to render suite; refactor image saving into test lib compare function; fix for Haiku build
include/SDL_test_images.h
src/test/SDL_test_compare.c
test/Makefile.in
test/testautomation_render.c
test/testautomation_suites.h
test/testautomation_surface.c
--- a/include/SDL_test_images.h	Mon Dec 24 14:43:57 2012 -0800
+++ b/include/SDL_test_images.h	Wed Dec 26 22:26:44 2012 -0800
@@ -53,7 +53,7 @@
   int width;
   int height;
   unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ 
-  const unsigned char pixel_data[];
+  unsigned char pixel_data[];
 } SDLTest_SurfaceImage_t;
 
 /* Test images */
--- a/src/test/SDL_test_compare.c	Mon Dec 24 14:43:57 2012 -0800
+++ b/src/test/SDL_test_compare.c	Wed Dec 26 22:26:44 2012 -0800
@@ -32,7 +32,11 @@
 #include "SDL_test.h"
 
 
-int SDLTest_CompareSurfaces( SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error )
+/* Counter for _CompareSurface calls; used for filename creation when comparisons fail */
+static int _CompareSurfaceCount = 0;
+
+/* Compare surfaces */
+int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error)
 {
    int ret;
    int i,j;
@@ -41,18 +45,20 @@
    int dist;
    Uint8 R, G, B, A;
    Uint8 Rd, Gd, Bd, Ad;
+   char imageFilename[128];
+   char referenceFilename[128];
 
    /* Validate input surfaces */
    if (surface == NULL || referenceSurface == NULL) {
       return -1;
    }
 
-   /* Make surface size is the same. */
+   /* Make sure surface size is the same. */
    if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) {
       return -2;
    }
 
-   /* Sanitize input */
+   /* Sanitize input value */
    if (allowable_error<0) {
       allowable_error = 0;
    }
@@ -87,5 +93,15 @@
    SDL_UnlockSurface( surface );
    SDL_UnlockSurface( referenceSurface );
 
+   /* Save test image and reference for analysis on failures */
+   _CompareSurfaceCount++;
+   if (ret != 0) {
+      SDL_snprintf(imageFilename, 127, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount);
+      SDL_SaveBMP(surface, imageFilename);
+      SDL_snprintf(referenceFilename, 127, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount);
+      SDL_SaveBMP(referenceSurface, referenceFilename);
+      SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
+   }
+
    return ret;
 }
--- a/test/Makefile.in	Mon Dec 24 14:43:57 2012 -0800
+++ b/test/Makefile.in	Wed Dec 26 22:26:44 2012 -0800
@@ -74,7 +74,8 @@
 		      $(srcdir)/testautomation_rect.c \
 		      $(srcdir)/testautomation_render.c \
 		      $(srcdir)/testautomation_rwops.c \
-		      $(srcdir)/testautomation_audio.c
+		      $(srcdir)/testautomation_audio.c \
+		      $(srcdir)/testautomation_surface.c
 	$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS) 
 
 testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
--- a/test/testautomation_render.c	Mon Dec 24 14:43:57 2012 -0800
+++ b/test/testautomation_render.c	Wed Dec 26 22:26:44 2012 -0800
@@ -22,13 +22,14 @@
 #define ALLOWABLE_ERROR_OPAQUE	0
 #define ALLOWABLE_ERROR_BLENDED	64
 
+/* Test window and renderer */
 SDL_Window *window = NULL;
 SDL_Renderer *renderer = NULL;
 
 /* Prototypes for helper functions */
 
 static int _clearScreen (void);
-static void _compare(const char *msg, SDL_Surface *s, int allowable_error);
+static void _compare(SDL_Surface *reference, int allowable_error);
 static int _hasTexAlpha(void);
 static int _hasTexColor(void);
 static SDL_Texture *_loadTestFace(void);
@@ -53,7 +54,7 @@
   renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
   SDLTest_AssertPass("SDL_CreateRenderer()");
   SDLTest_AssertCheck(renderer != 0, "Check SDL_CreateRenderer result");
-  if (renderer == 0) {
+  if (renderer == NULL) {
       SDL_DestroyWindow(window);
       return;
   }
@@ -66,11 +67,13 @@
 {
   if (renderer != NULL) {  
      SDL_DestroyRenderer(renderer);
+     renderer = NULL;
      SDLTest_AssertPass("SDL_DestroyRenderer()");
   }
   
   if (window != NULL) {  
      SDL_DestroyWindow(window);
+     window = NULL;
      SDLTest_AssertPass("SDL_DestroyWindow");
   }
 }
@@ -106,6 +109,7 @@
    int ret;
    int x, y;
    SDL_Rect rect;
+   SDL_Surface *referenceSurface = NULL;
    int checkFailCount1;
    int checkFailCount2;
 
@@ -182,7 +186,14 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
 
    /* See if it's the same. */
-   _compare( "Primitives output not the same.", SDLTest_ImagePrimitives(), ALLOWABLE_ERROR_OPAQUE );
+   referenceSurface = SDLTest_ImagePrimitives();
+   _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
+
+   /* Clean up. */
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
 
    return TEST_COMPLETED;
 }
@@ -200,6 +211,7 @@
    int ret;
    int i, j;
    SDL_Rect rect;
+   SDL_Surface *referenceSurface = NULL;
    int checkFailCount1;
    int checkFailCount2;
    int checkFailCount3;
@@ -317,9 +329,16 @@
    SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount3);
 
    /* See if it's the same. */
-   _compare( "Blended primitives output not the same.", SDLTest_ImagePrimitivesBlend(), ALLOWABLE_ERROR_BLENDED );
+   referenceSurface = SDLTest_ImagePrimitivesBlend();
+   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
 
-    return TEST_COMPLETED;
+   /* Clean up. */
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
+
+   return TEST_COMPLETED;
 }
 
 
@@ -337,6 +356,7 @@
    int ret;
    SDL_Rect rect;
    SDL_Texture *tface;
+   SDL_Surface *referenceSurface = NULL;
    Uint32 tformat;
    int taccess, tw, th;
    int i, j, ni, nj;
@@ -374,11 +394,16 @@
    }
    SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount1);
 
+   /* See if it's the same */
+   referenceSurface = SDLTest_ImageBlit();
+   _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
+
    /* Clean up. */
    SDL_DestroyTexture( tface );
-
-   /* See if it's the same */
-   _compare( "Blit output not the same.", SDLTest_ImageBlit(), ALLOWABLE_ERROR_OPAQUE );
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
 
    return TEST_COMPLETED;
 }
@@ -398,6 +423,7 @@
    int ret;
    SDL_Rect rect;
    SDL_Texture *tface;
+   SDL_Surface *referenceSurface = NULL;
    Uint32 tformat;
    int taccess, tw, th;
    int i, j, ni, nj;
@@ -438,12 +464,16 @@
    SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
    SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
 
+   /* See if it's the same. */
+   referenceSurface = SDLTest_ImageBlitColor();
+   _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
+
    /* Clean up. */
    SDL_DestroyTexture( tface );
-
-   /* See if it's the same. */
-   _compare( "Blit output not the same (using SDL_SetTextureColorMod).",
-            SDLTest_ImageBlitColor(), ALLOWABLE_ERROR_OPAQUE );
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
 
    return TEST_COMPLETED;
 }
@@ -463,13 +493,13 @@
    int ret;
    SDL_Rect rect;
    SDL_Texture *tface;
+   SDL_Surface *referenceSurface = NULL;
    Uint32 tformat;
    int taccess, tw, th;
    int i, j, ni, nj;
    int checkFailCount1;
    int checkFailCount2;
 
-
    /* Need alpha or just skip test. */
    SDLTest_AssertCheck(_hasTexAlpha(), "_hasTexAlpha");
 
@@ -507,12 +537,16 @@
    SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount1);
    SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
 
+   /* See if it's the same. */
+   referenceSurface = SDLTest_ImageBlitAlpha();
+   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
+
    /* Clean up. */
    SDL_DestroyTexture( tface );
-
-   /* See if it's the same. */
-   _compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).",
-            SDLTest_ImageBlitAlpha(), ALLOWABLE_ERROR_BLENDED );
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
 
    return TEST_COMPLETED;
 }
@@ -584,6 +618,7 @@
    int ret;
    SDL_Rect rect;
    SDL_Texture *tface;
+   SDL_Surface *referenceSurface = NULL;
    Uint32 tformat;
    int taccess, tw, th;
    int i, j, ni, nj;
@@ -618,26 +653,39 @@
 
    /* Test None. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
-   /* See if it's the same. */
-   _compare( "Blit blending output not the same (using SDL_BLENDMODE_NONE).",
-            SDLTest_ImageBlitBlendNone(), ALLOWABLE_ERROR_OPAQUE ); 
-
-
+   referenceSurface = SDLTest_ImageBlitBlendNone();
+   _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE ); 
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
+   
    /* Test Blend. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
-   _compare( "Blit blending output not the same (using SDL_BLENDMODE_BLEND).",
-            SDLTest_ImageBlitBlend(), ALLOWABLE_ERROR_BLENDED );
-
+   referenceSurface = SDLTest_ImageBlitBlend();
+   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
 
    /* Test Add. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
-   _compare( "Blit blending output not the same (using SDL_BLENDMODE_ADD).",
-            SDLTest_ImageBlitBlendAdd(), ALLOWABLE_ERROR_BLENDED );
+   referenceSurface = SDLTest_ImageBlitBlendAdd();
+   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
 
    /* Test Mod. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
-   _compare( "Blit blending output not the same (using SDL_BLENDMODE_MOD).",
-            SDLTest_ImageBlitBlendMod(), ALLOWABLE_ERROR_BLENDED );
+   referenceSurface = SDLTest_ImageBlitBlendMod();
+   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
 
    /* Clear surface. */
    _clearScreen();
@@ -682,9 +730,13 @@
    /* Clean up. */
    SDL_DestroyTexture( tface );
 
-   /* Check to see if matches. */
-   _compare( "Blit blending output not the same (using SDL_BLENDMODE_*).",
-            SDLTest_ImageBlitBlendAll(), ALLOWABLE_ERROR_BLENDED);
+   /* Check to see if final image matches. */
+   referenceSurface = SDLTest_ImageBlitBlendAll();
+   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
+   if (referenceSurface != NULL) {
+      SDL_FreeSurface(referenceSurface);
+      referenceSurface = NULL;
+   }
 
    return TEST_COMPLETED;
 }
@@ -902,9 +954,6 @@
    return 1;
 }
 
-/* Counter for _compare calls use for filename creation when comparisons fail */
-static int _renderCompareCount = 0;
-
 /**
  * @brief Compares screen pixels with image pixels. Helper function.
  *
@@ -918,17 +967,15 @@
  * http://wiki.libsdl.org/moin.cgi/SDL_FreeSurface
  */
 static void
-_compare(const char *msg, SDL_Surface *s, int allowable_error)
+_compare(SDL_Surface *referenceSurface, int allowable_error)
 {
    int ret;
    SDL_Rect rect;
    Uint8 pix[4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H];
-   SDL_Surface *testsur;
-   char imageFilename[128];
-   char referenceFilename[128];
+   SDL_Surface *testSurface;
 
    /* Read pixels. */
-   /* Explicitly specify the rect in case the window isn't expected size... */
+   /* Explicitly specify the rect in case the window isn't the expected size... */
    rect.x = 0;
    rect.y = 0;
    rect.w = TESTRENDER_SCREEN_W;
@@ -937,26 +984,18 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", ret);
 
    /* Create surface. */
-   testsur = SDL_CreateRGBSurfaceFrom( pix, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W*4,
+   testSurface = SDL_CreateRGBSurfaceFrom( pix, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W*4,
                                        RENDER_COMPARE_RMASK, RENDER_COMPARE_GMASK, RENDER_COMPARE_BMASK, RENDER_COMPARE_AMASK);
-   SDLTest_AssertCheck(testsur != NULL, "Verify result from SDL_CreateRGBSurfaceFrom");
+   SDLTest_AssertCheck(testSurface != NULL, "Verify result from SDL_CreateRGBSurfaceFrom");
 
    /* Compare surface. */
-   ret = SDLTest_CompareSurfaces( testsur, s, allowable_error );
+   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, allowable_error );
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
-   /* Save source image and reference image for analysis */
-   _renderCompareCount++;
-   if (ret != 0) {
-      SDL_snprintf(imageFilename, 127, "compare%04d_SourceImage.bmp", _renderCompareCount);
-      SDL_SaveBMP(testsur, imageFilename);
-      SDL_snprintf(referenceFilename, 127, "compare%04d_ReferenceImage.bmp", _renderCompareCount);
-      SDL_SaveBMP(s, referenceFilename);
-      SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
+   /* Clean up. */
+   if (testSurface != NULL) {
+       SDL_FreeSurface(testSurface);
    }
-
-   /* Clean up. */
-   SDL_FreeSurface(testsur);
 }
 
 /**
--- a/test/testautomation_suites.h	Mon Dec 24 14:43:57 2012 -0800
+++ b/test/testautomation_suites.h	Wed Dec 26 22:26:44 2012 -0800
@@ -17,7 +17,7 @@
 extern SDLTest_TestSuiteReference rectTestSuite;
 extern SDLTest_TestSuiteReference renderTestSuite;
 extern SDLTest_TestSuiteReference rwopsTestSuite;
-//extern SDLTest_TestSuiteReference surfaceTestSuite;
+extern SDLTest_TestSuiteReference surfaceTestSuite;
 //extern SDLTest_TestSuiteReference syswmTestSuite;
 //extern SDLTest_TestSuiteReference videoTestSuite;
 
@@ -31,7 +31,7 @@
 	&rectTestSuite,
 	&renderTestSuite,
 	&rwopsTestSuite,
-//	&surfaceTestSuite,
+	&surfaceTestSuite,
 //	&syswmTestSuite,
 //	&videoTestSuite,
 	NULL
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testautomation_surface.c	Wed Dec 26 22:26:44 2012 -0800
@@ -0,0 +1,519 @@
+/**
+ * Original code: automated SDL surface test written by Edgar Simo "bobbens"
+ * Adapted/rewritten for test lib by Andreas Schiffler
+ */
+
+#include <stdio.h>
+#include <sys/stat.h>
+
+#include "SDL.h"
+#include "SDL_test.h"
+
+/* ================= Test Case Implementation ================== */
+
+
+/* Shared test surface */
+
+static SDL_Surface *testsurface = NULL;
+
+/* Fixture */
+
+void
+_surfaceSetUp(void *arg)
+{
+   testsurface = SDLTest_ImageBlit();
+   SDLTest_AssertCheck(testsurface != NULL, "Check that testsurface is not NULL");
+}
+
+void
+_surfaceTearDown(void *arg)
+{
+	if (testsurface != NULL) {
+		SDL_FreeSurface(testsurface);
+		testsurface = NULL;
+	}
+}
+
+/* Helper functions for the test cases */
+
+#define TEST_SURFACE_WIDTH testsurface->w
+#define TEST_SURFACE_HEIGHT testsurface->h
+
+/**
+ * Helper that clears the test surface
+ */
+void _clearTestSurface()
+{
+	int ret;
+	Uint32 color;
+	
+	/* Clear surface. */
+	color = SDL_MapRGB( testsurface->format, 0, 0, 0);
+	SDLTest_AssertPass("Call to SDL_MapRGB()");
+	ret = SDL_FillRect( testsurface, NULL, color);
+	SDLTest_AssertPass("Call to SDL_FillRect()");
+	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
+}
+
+/**
+ * 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.
+ */
+void _testBlitBlendMode(int mode)
+{
+	int ret;
+	int i, j, ni, nj;
+	SDL_Surface *face;
+	SDL_Rect rect;
+	Uint32 color;
+	int nmode;
+	int checkFailCount1;
+	int checkFailCount2;
+	int checkFailCount3;
+	int checkFailCount4;
+
+	/* Check test surface */
+	SDLTest_AssertCheck(testsurface != NULL, "Verify testsurface is not NULL");
+	if (testsurface == NULL) return;
+	
+	/* Create sample surface */
+	face = SDLTest_ImageFace();
+	SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
+	if (face == NULL) return;
+
+	/* Clear the test surface */
+        _clearTestSurface();
+        
+	/* Target rect size */
+	rect.w = face->w;
+	rect.h = face->h;
+	
+	/* Steps to take */
+	ni = testsurface->w - face->w;
+	nj = testsurface->h - face->h;
+
+	/* Optionally set blend mode. */
+	if (mode >= 0) {
+		ret = SDL_SetSurfaceBlendMode( face, (SDL_BlendMode)mode );
+		SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
+		SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret);
+	}
+	
+	/* Test blend mode. */
+	checkFailCount1 = 0;
+	checkFailCount2 = 0;
+	checkFailCount3 = 0;
+	checkFailCount4 = 0;
+	for (j=0; j <= nj; j+=4) {
+	  for (i=0; i <= ni; i+=4) {
+	  	if (mode == -2) {
+			/* Set colour mod. */
+			ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
+			if (ret != 0) checkFailCount2++;
+		}
+	  	else if (mode == -3) {
+	  		/* Set alpha mod. */
+			ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
+			if (ret != 0) checkFailCount3++;
+		}
+		else if (mode == -4) {
+			/* Crazy blending mode magic. */
+			nmode = (i/4*j/4) % 4;
+			if (nmode==0) nmode = SDL_BLENDMODE_NONE;
+			else if (nmode==1) nmode = SDL_BLENDMODE_BLEND;
+			else if (nmode==2) nmode = SDL_BLENDMODE_ADD;
+			else if (nmode==3) nmode = SDL_BLENDMODE_MOD;
+			ret = SDL_SetSurfaceBlendMode( face, nmode );		
+			if (ret != 0) checkFailCount4++;
+		}
+
+		 /* Blitting. */
+		 rect.x = i;
+		 rect.y = j;
+		 ret = SDL_BlitSurface( face, NULL, testsurface, &rect );
+		 if (ret != 0) checkFailCount1++;
+	  }
+	}
+	SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1);
+	SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", checkFailCount2);
+	SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 0, got: %i", checkFailCount3);
+	SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
+	
+	/* Clean up */
+	if (face != NULL) {
+		SDL_FreeSurface(face);
+		face = NULL;
+	}
+}
+
+/* Helper to check that a file exists */
+void
+_AssertFileExist(const char *filename)
+{
+	struct stat st;
+	int ret = stat(filename, &st);
+
+	SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
+}
+
+
+/* Test case functions */
+
+/**
+ * @brief Tests sprite saving and loading
+ */
+int
+surface_testSaveLoadBitmap(void *arg)
+{
+    int ret;
+    const char *sampleFilename = "testSaveLoadBitmap.bmp";
+    SDL_Surface *face;
+    SDL_Surface *rface;
+
+    /* Create sample surface */
+    face = SDLTest_ImageFace();
+    SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
+    if (face == NULL) return;
+
+    /* Delete test file; ignore errors */
+    unlink(sampleFilename);
+
+    /* Save a surface */
+    ret = SDL_SaveBMP(face, sampleFilename);
+    SDLTest_AssertPass("Call to SDL_SaveBMP()");
+    SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret); 
+    _AssertFileExist(sampleFilename);
+    	
+    /* Load a surface */
+    rface = SDL_LoadBMP(sampleFilename);
+    SDLTest_AssertPass("Call to SDL_LoadBMP()");
+    SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
+    if (rface != NULL) {
+	    SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
+	    SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
+    }
+
+    /* Delete test file; ignore errors */
+    unlink(sampleFilename);
+
+    /* Clean up */
+    if (face != NULL) {
+	SDL_FreeSurface(face);
+	face = NULL;
+    }
+    if (rface != NULL) {
+	SDL_FreeSurface(rface);
+	rface = NULL;
+    }
+    
+    return TEST_COMPLETED;
+}
+
+/*!
+ *  Tests surface conversion.
+ */
+int
+surface_testSurfaceConversion(void *arg)
+{
+	SDL_Surface *rface = NULL, *face = NULL;
+	int ret = 0;
+
+	/* Create sample surface */
+	face = SDLTest_ImageFace();
+	SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
+	if (face == NULL) 
+		return TEST_ABORTED;
+
+	/* Set transparent pixel as the pixel at (0,0) */
+	if (face->format->palette) {
+	   ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
+	   SDLTest_AssertPass("Call to SDL_SetColorKey()");
+	   SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
+	}
+
+	/* Convert to 32 bit to compare. */
+	rface = SDL_ConvertSurface( face, testsurface->format, 0 );
+	SDLTest_AssertPass("Call to SDL_ConvertSurface()");
+	SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
+
+	/* Compare surface. */
+	ret = SDLTest_CompareSurfaces( rface, face, 0 );
+	SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+	
+	/* Clean up. */
+	if (face != NULL) {
+		SDL_FreeSurface( face );
+		face = NULL;
+	}
+	if (rface != NULL) {
+		SDL_FreeSurface( rface );
+		rface = NULL;
+	}	
+
+	return TEST_COMPLETED;
+}
+
+
+/**
+ * @brief Tests sprite loading. A failure case.
+ */
+int
+surface_testLoadFailure(void *arg)
+{
+	SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
+	SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
+
+	return TEST_COMPLETED;
+}
+
+/**
+ * @brief Tests some blitting routines.
+ */
+int
+surface_testBlit(void *arg)
+{
+   int ret;
+   SDL_Surface *referenceSurface;
+
+   /* Basic blitting */ 
+   _testBlitBlendMode(-1);
+   
+   /* Verify result by comparing surfaces */
+   referenceSurface = SDLTest_ImageBlit();
+   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
+   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+   
+   /* Clean up. */
+   if (referenceSurface != NULL) {   
+   	SDL_FreeSurface( referenceSurface );
+   }
+
+   return TEST_COMPLETED;
+}
+
+/**
+ * @brief Tests some blitting routines with color mod
+ */
+int
+surface_testBlitColorMod(void *arg)
+{
+   int ret;
+   SDL_Surface *referenceSurface;
+
+   /* Basic blitting with color mod */ 
+   _testBlitBlendMode(-2);
+   
+   /* Verify result by comparing surfaces */
+   referenceSurface = SDLTest_ImageBlitColor();
+   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
+   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+   
+   /* Clean up. */
+   if (referenceSurface != NULL) {   
+   	SDL_FreeSurface( referenceSurface );
+   }
+
+   return TEST_COMPLETED;
+}
+
+/**
+ * @brief Tests some blitting routines with alpha mod
+ */
+int
+surface_testBlitAlphaMod(void *arg)
+{
+   int ret;
+   SDL_Surface *referenceSurface;
+
+   /* Basic blitting with alpha mod */ 
+   _testBlitBlendMode(-3);
+   
+   /* Verify result by comparing surfaces */
+   referenceSurface = SDLTest_ImageBlitAlpha();
+   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
+   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+   
+   /* Clean up. */
+   if (referenceSurface != NULL) {   
+   	SDL_FreeSurface( referenceSurface );
+   }
+
+   return TEST_COMPLETED;
+}
+
+
+/**
+ * @brief Tests some more blitting routines.
+ */
+int
+surface_testBlitBlendNone(void *arg)
+{
+   int ret;
+   SDL_Surface *referenceSurface;
+
+   /* Basic blitting */ 
+   _testBlitBlendMode(SDL_BLENDMODE_NONE);
+   
+   /* Verify result by comparing surfaces */
+   referenceSurface = SDLTest_ImageBlitBlendNone();
+   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
+   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+   
+   /* Clean up. */
+   if (referenceSurface != NULL) {   
+   	SDL_FreeSurface( referenceSurface );
+   }
+
+   return TEST_COMPLETED;
+}
+
+/**
+ * @brief Tests some more blitting routines.
+ */
+int
+surface_testBlitBlendBlend(void *arg)
+{
+   int ret;
+   SDL_Surface *referenceSurface;
+
+   /* Blend blitting */ 
+   _testBlitBlendMode(SDL_BLENDMODE_BLEND);
+   
+   /* Verify result by comparing surfaces */
+   referenceSurface = SDLTest_ImageBlitBlend();
+   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
+   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+   
+   /* Clean up. */
+   if (referenceSurface != NULL) {   
+   	SDL_FreeSurface( referenceSurface );
+   }
+
+   return TEST_COMPLETED;
+}
+
+/**
+ * @brief Tests some more blitting routines.
+ */
+int
+surface_testBlitBlendAdd(void *arg)
+{
+   int ret;
+   SDL_Surface *referenceSurface;
+
+   /* Add blitting */ 
+   _testBlitBlendMode(SDL_BLENDMODE_ADD);
+   
+   /* Verify result by comparing surfaces */
+   referenceSurface = SDLTest_ImageBlitBlendAdd();
+   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
+   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+   
+   /* Clean up. */
+   if (referenceSurface != NULL) {   
+   	SDL_FreeSurface( referenceSurface );
+   }
+
+   return TEST_COMPLETED;
+}
+
+/**
+ * @brief Tests some more blitting routines.
+ */
+int
+surface_testBlitBlendMod(void *arg)
+{
+   int ret;
+   SDL_Surface *referenceSurface;
+
+   /* Mod blitting */ 
+   _testBlitBlendMode(SDL_BLENDMODE_MOD);
+   
+   /* Verify result by comparing surfaces */
+   referenceSurface = SDLTest_ImageBlitBlendMod();
+   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
+   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+   
+   /* Clean up. */
+   if (referenceSurface != NULL) {   
+   	SDL_FreeSurface( referenceSurface );
+   }
+
+   return TEST_COMPLETED;
+}
+
+/**
+ * @brief Tests some more blitting routines with loop
+ */
+int
+surface_testBlitBlendLoop(void *arg) {
+
+   int ret;
+   SDL_Surface *referenceSurface;
+
+   /* All blitting */ 
+   _testBlitBlendMode(-4);
+   
+   /* Verify result by comparing surfaces */
+   referenceSurface = SDLTest_ImageBlitBlendAll();
+   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
+   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
+   
+   /* Clean up. */
+   if (referenceSurface != NULL) {   
+   	SDL_FreeSurface( referenceSurface );
+   }
+
+   return TEST_COMPLETED;
+
+}
+
+/* ================= Test References ================== */
+
+/* Surface test cases */
+static const SDLTest_TestCaseReference surfaceTest1 =
+		{ (SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest2 =
+		{ (SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest3 =
+		{ (SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest4 =
+		{ (SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest5 =
+		{ (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest6 =
+		{ (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest7 =
+		{ (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest8 =
+		{ (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blittin routines with verious blending modes", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest9 =
+		{ (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest10 =
+		{ (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_ENABLED};
+
+static const SDLTest_TestCaseReference surfaceTest11 =
+		{ (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
+
+/* Sequence of Surface test cases */
+static const SDLTest_TestCaseReference *surfaceTests[] =  {
+	&surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
+	&surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10, &surfaceTest11, NULL
+};
+
+/* Surface test suite (global) */
+SDLTest_TestSuiteReference surfaceTestSuite = {
+	"Surface",
+	_surfaceSetUp,
+	surfaceTests,
+	_surfaceTearDown
+
+};