changeset 3477:2c07bb579922

We want to be strict on software renderer tests and opaque tests, but give a decent margin for blending inaccuracy for the blended tests.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 21 Nov 2009 07:59:19 +0000
parents ab99313951cd
children f7541260e89c
files test/automated/common/common.c test/automated/common/common.h test/automated/render/render.c test/automated/surface/surface.c
diffstat 4 files changed, 32 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/test/automated/common/common.c	Sat Nov 21 07:46:12 2009 +0000
+++ b/test/automated/common/common.c	Sat Nov 21 07:59:19 2009 +0000
@@ -16,7 +16,7 @@
 /**
  * @brief Compares a surface and a surface image for equality.
  */
-int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img )
+int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img, int allowable_error )
 {
    int ret;
    int i,j;
@@ -62,8 +62,8 @@
                      dist += (B-pd[2])*(B-pd[2]);
                      dist += (A-pd[3])*(A-pd[3]);
                   }
-                  /* Allow up to sqrt(32) difference in blending accuracy */
-                  if (dist > 64) {
+                  /* Allow some difference in blending accuracy */
+                  if (dist > allowable_error) {
                      /*printf("pixel %d,%d varies by %d\n", i, j, dist);*/
                      ++ret;
                   }
--- a/test/automated/common/common.h	Sat Nov 21 07:46:12 2009 +0000
+++ b/test/automated/common/common.h	Sat Nov 21 07:59:19 2009 +0000
@@ -25,6 +25,8 @@
    const unsigned char pixel_data[];
 } SurfaceImage_t;
 
+#define ALLOWABLE_ERROR_OPAQUE	0
+#define ALLOWABLE_ERROR_BLENDED	64
 
 /**
  * @brief Compares a surface and a surface image for equality.
@@ -33,7 +35,7 @@
  *    @param img Image to compare against.
  *    @return 0 if they are the same, -1 on error and positive if different.
  */
-int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img );
+int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img, int allowable_error );
 
 
 #endif /* COMMON_H */
--- a/test/automated/render/render.c	Sat Nov 21 07:46:12 2009 +0000
+++ b/test/automated/render/render.c	Sat Nov 21 07:59:19 2009 +0000
@@ -29,7 +29,7 @@
 /*
  * Prototypes.
  */
-static int render_compare( const char *msg, const SurfaceImage_t *s );
+static int render_compare( const char *msg, const SurfaceImage_t *s, int allowable_error );
 static int render_isSupported( int code );
 static int render_hasDrawColor (void);
 static int render_hasBlendModes (void);
@@ -53,7 +53,7 @@
  *    @param s Image to compare against.
  *    @return 0 on success.
  */
-static int render_compare( const char *msg, const SurfaceImage_t *s )
+static int render_compare( const char *msg, const SurfaceImage_t *s, int allowable_error )
 {
    (void) msg;
    (void) s;
@@ -73,7 +73,7 @@
       return 1;
 
    /* Compare surface. */
-   ret = surface_compare( testsur, s );
+   ret = surface_compare( testsur, s, allowable_error );
    if (SDL_ATassert( msg, ret==0 ))
       return 1;
 
@@ -445,7 +445,7 @@
       return -1;
 
    /* See if it's the same. */
-   if (render_compare( "Primitives output not the same.", &img_primitives ))
+   if (render_compare( "Primitives output not the same.", &img_primitives, ALLOWABLE_ERROR_OPAQUE ))
       return -1;
 
    return 0;
@@ -562,7 +562,7 @@
    }
 
    /* See if it's the same. */
-   if (render_compare( "Blended primitives output not the same.", &img_blend ))
+   if (render_compare( "Blended primitives output not the same.", &img_blend, ALLOWABLE_ERROR_BLENDED ))
       return -1;
 
    return 0;
@@ -614,7 +614,7 @@
    SDL_DestroyTexture( tface );
 
    /* See if it's the same. */
-   if (render_compare( "Blit output not the same.", &img_blit ))
+   if (render_compare( "Blit output not the same.", &img_blit, ALLOWABLE_ERROR_OPAQUE ))
       return -1;
 
    return 0;
@@ -672,7 +672,7 @@
 
    /* See if it's the same. */
    if (render_compare( "Blit output not the same (using SDL_SetTextureColorMod).",
-            &img_blitColour ))
+            &img_blitColour, ALLOWABLE_ERROR_OPAQUE ))
       return -1;
 
    return 0;
@@ -734,7 +734,7 @@
 
    /* See if it's the same. */
    if (render_compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).",
-            &img_blitAlpha ))
+            &img_blitAlpha, ALLOWABLE_ERROR_BLENDED ))
       return -1;
 
    return 0;
@@ -825,35 +825,35 @@
       return -1;
    /* See if it's the same. */
    if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_NONE).",
-            &img_blendNone ))
+            &img_blendNone, ALLOWABLE_ERROR_OPAQUE ))
       return -1;
 
    /* Test Mask. */
    if (render_testBlitBlendMode( tface, SDL_BLENDMODE_MASK ))
       return -1;
    if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_MASK).",
-            &img_blendMask ))
+            &img_blendMask, ALLOWABLE_ERROR_OPAQUE ))
       return -1;
 
    /* Test Blend. */
    if (render_testBlitBlendMode( tface, SDL_BLENDMODE_BLEND ))
       return -1;
    if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_BLEND).",
-            &img_blendBlend ))
+            &img_blendBlend, ALLOWABLE_ERROR_BLENDED ))
       return -1;
 
    /* Test Add. */
    if (render_testBlitBlendMode( tface, SDL_BLENDMODE_ADD ))
       return -1;
    if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_ADD).",
-            &img_blendAdd ))
+            &img_blendAdd, ALLOWABLE_ERROR_BLENDED ))
       return -1;
 
    /* Test Mod. */
    if (render_testBlitBlendMode( tface, SDL_BLENDMODE_MOD ))
       return -1;
    if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_MOD).",
-            &img_blendMod ))
+            &img_blendMod, ALLOWABLE_ERROR_BLENDED ))
       return -1;
 
    /* Clear surface. */
@@ -898,7 +898,7 @@
 
    /* Check to see if matches. */
    if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_*).",
-            &img_blendAll ))
+            &img_blendAll, ALLOWABLE_ERROR_BLENDED ))
       return -1;
 
    return 0;
--- a/test/automated/surface/surface.c	Sat Nov 21 07:46:12 2009 +0000
+++ b/test/automated/surface/surface.c	Sat Nov 21 07:59:19 2009 +0000
@@ -69,7 +69,7 @@
 
    /* See if it's the same. */
    if (SDL_ATassert( "Primitives output not the same.",
-            surface_compare( rface, &img_face)==0 ))
+            surface_compare( rface, &img_face, 0 )==0 ))
       return;
 
    /* Clean up. */
@@ -159,7 +159,7 @@
 
    /* See if it's the same. */
    if (SDL_ATassert( "Primitives output not the same.",
-            surface_compare( testsur, &img_primitives )==0 ))
+            surface_compare( testsur, &img_primitives, 0 )==0 ))
       return;
 
    SDL_ATend();
@@ -241,7 +241,7 @@
 
    /* See if it's the same. */
    if (SDL_ATassert( "Primitives output not the same.",
-            surface_compare( testsur, &img_blend )==0 ))
+            surface_compare( testsur, &img_blend, 0 )==0 ))
       return;
 
    SDL_ATend();
@@ -304,7 +304,7 @@
 
    /* See if it's the same. */
    if (SDL_ATassert( "Blitting output not the same (normal blit).",
-            surface_compare( testsur, &img_blit )==0 ))
+            surface_compare( testsur, &img_blit, 0 )==0 ))
       return;
 
    /* Clear surface. */
@@ -332,7 +332,7 @@
 
    /* See if it's the same. */
    if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceColorMod).",
-            surface_compare( testsur, &img_blitColour )==0 ))
+            surface_compare( testsur, &img_blitColour, 0 )==0 ))
       return;
 
    /* Clear surface. */
@@ -365,7 +365,7 @@
 
    /* See if it's the same. */
    if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceAlphaMod).",
-            surface_compare( testsur, &img_blitAlpha )==0 ))
+            surface_compare( testsur, &img_blitAlpha, 0 )==0 ))
       return;
 
    /* Clean up. */
@@ -473,35 +473,35 @@
    if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_NONE ))
       return;
    if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_NONE).",
-            surface_compare( testsur, &img_blendNone )==0 ))
+            surface_compare( testsur, &img_blendNone, 0 )==0 ))
       return;
 
    /* Test Mask. */
    if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_MASK ))
       return;
    if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MASK).",
-            surface_compare( testsur, &img_blendMask )==0 ))
+            surface_compare( testsur, &img_blendMask, 0 )==0 ))
       return;
 
    /* Test Blend. */
    if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND ))
       return;
    if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_BLEND).",
-            surface_compare( testsur, &img_blendBlend )==0 ))
+            surface_compare( testsur, &img_blendBlend, 0 )==0 ))
       return;
 
    /* Test Add. */
    if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD ))
       return;
    if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_ADD).",
-            surface_compare( testsur, &img_blendAdd )==0 ))
+            surface_compare( testsur, &img_blendAdd, 0 )==0 ))
       return;
 
    /* Test Mod. */
    if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD ))
       return;
    if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MOD).",
-            surface_compare( testsur, &img_blendMod )==0 ))
+            surface_compare( testsur, &img_blendMod, 0 )==0 ))
       return;
 
    /* Clear surface. */
@@ -545,7 +545,7 @@
 
    /* Check to see if matches. */
    if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLEND_*).",
-            surface_compare( testsur, &img_blendAll )==0 ))
+            surface_compare( testsur, &img_blendAll, 0 )==0 ))
       return;
 
    /* Clean up. */