Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Merged Andreas' changes
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 23, 2012
2 parents 58147d4 + cd4b36e commit c9c81c5
Show file tree
Hide file tree
Showing 17 changed files with 1,748 additions and 193 deletions.
2 changes: 2 additions & 0 deletions VisualC/SDLtest/SDLtest_VS2010.vcxproj
Expand Up @@ -162,6 +162,7 @@
<ClInclude Include="..\..\include\SDL_test_md5.h" />
<ClInclude Include="..\..\include\SDL_test_random.h" />
<ClInclude Include="..\..\include\SDL_test_images.h" />
<ClInclude Include="..\..\include\SDL_test_compare.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\test\SDL_test_assert.c" />
Expand All @@ -178,6 +179,7 @@
<ClCompile Include="..\..\src\test\SDL_test_imageFace.c" />
<ClCompile Include="..\..\src\test\SDL_test_imagePrimitives.c" />
<ClCompile Include="..\..\src\test\SDL_test_imagePrimitivesBlend.c" />
<ClCompile Include="..\..\src\test\SDL_test_compare.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
2 changes: 2 additions & 0 deletions VisualC/SDLtest/SDLtest_VS2012.vcxproj
Expand Up @@ -166,6 +166,7 @@
<ClInclude Include="..\..\include\SDL_test_md5.h" />
<ClInclude Include="..\..\include\SDL_test_random.h" />
<ClInclude Include="..\..\include\SDL_test_images.h" />
<ClInclude Include="..\..\include\SDL_test_compare.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\test\SDL_test_assert.c" />
Expand All @@ -182,6 +183,7 @@
<ClCompile Include="..\..\src\test\SDL_test_imageFace.c" />
<ClCompile Include="..\..\src\test\SDL_test_imagePrimitives.c" />
<ClCompile Include="..\..\src\test\SDL_test_imagePrimitivesBlend.c" />
<ClCompile Include="..\..\src\test\SDL_test_compare.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
1 change: 1 addition & 0 deletions include/SDL_test.h
Expand Up @@ -41,6 +41,7 @@
#include "SDL_test_assert.h"
#include "SDL_test_harness.h"
#include "SDL_test_images.h"
#include "SDL_test_compare.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
Expand Down
72 changes: 72 additions & 0 deletions include/SDL_test_compare.h
@@ -0,0 +1,72 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

/**
* \file SDL_test_compare.h
*
* Include file for SDL test framework.
*
* This code is a part of the SDL2_test library, not the main SDL library.
*/

/*
Defines comparison functions (i.e. for surfaces).
*/

#ifndef _SDL_test_compare_h
#define _SDL_test_compare_h

#include "SDL.h"
#include "SDL_test_images.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

/**
* \brief Compares a surface and with reference image data for equality
*
* \param sur Surface used in comparison
* \param img Test Surface used in comparison
* \param allowable_error Allowable difference in blending accuracy
*
* \returns 0 if comparison succeeded, >0 (=number of pixels where comparison failed) if comparison failed, <0 for any other error.
*/
int SDLTest_CompareSurfaces(SDL_Surface *sur, SDL_Surface *img, int allowable_error);


/* Ends C function definitions when using C++ */
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#include "close_code.h"

#endif /* _SDL_test_compare_h */

/* vi: set ts=4 sw=4 expandtab: */
3 changes: 2 additions & 1 deletion include/SDL_test_harness.h
Expand Up @@ -105,11 +105,12 @@ typedef struct SDLTest_TestSuiteReference {
* \param testSuites Suites containing the test case.
* \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one.
* \param userExecKey Custom execution key provided by user, or 0 to autogenerate one.
* \param filter Filter specification. NULL disables. Case sensitive.
* \param testIterations Number of iterations to run each test case.
*
* \returns Test run result; 0 when all tests passed, 1 if any tests failed.
*/
int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, int testIterations);
int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, char *filter, int testIterations);


/* Ends C function definitions when using C++ */
Expand Down
27 changes: 14 additions & 13 deletions include/SDL_test_images.h
Expand Up @@ -36,6 +36,8 @@
#ifndef _SDL_test_images_h
#define _SDL_test_images_h

#include "SDL.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
Expand All @@ -44,29 +46,28 @@ extern "C" {
/* *INDENT-ON* */
#endif


/**
*Type for test images.
*/
typedef struct SDLTest_SurfaceImage_s {
int width;
int height;
unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
const unsigned char pixel_data[];
} SDLTest_SurfaceImage_t;

/* Test images */
const SDLTest_SurfaceImage_t SDLTest_imageBlit;
const SDLTest_SurfaceImage_t SDLTest_imageBlitColor;
const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha;
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd;
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend;
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod;
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone;
const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll;
const SDLTest_SurfaceImage_t SDLTest_ImageFace;
const SDLTest_SurfaceImage_t SDLTest_imagePrimitives;
const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend;
SDL_Surface *SDLTest_ImageBlit();
SDL_Surface *SDLTest_ImageBlitColor();
SDL_Surface *SDLTest_ImageBlitAlpha();
SDL_Surface *SDLTest_ImageBlitBlendAdd();
SDL_Surface *SDLTest_ImageBlitBlend();
SDL_Surface *SDLTest_ImageBlitBlendMod();
SDL_Surface *SDLTest_ImageBlitBlendNone();
SDL_Surface *SDLTest_ImageBlitBlendAll();
SDL_Surface *SDLTest_ImageFace();
SDL_Surface *SDLTest_ImagePrimitives();
SDL_Surface *SDLTest_ImagePrimitivesBlend();

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Expand Down
83 changes: 83 additions & 0 deletions src/test/SDL_test_compare.c
@@ -0,0 +1,83 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

/*
Based on automated SDL_Surface tests originally written by Edgar Simo 'bobbens'.
Rewritten for test lib by Andreas Schiffler.
*/

#include "SDL_config.h"

#include "SDL_test.h"


int SDLTest_CompareSurfaces( SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error )
{
int ret;
int i,j;
int bpp, bpp_reference;
Uint8 *p, *p_reference;
int dist;
Uint8 R, G, B, A;
Uint8 Rd, Gd, Bd, Ad;

/* Make surfacee size is the same. */
if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h))
{
return -1;
}

SDL_LockSurface( surface );
SDL_LockSurface( referenceSurface );

ret = 0;
bpp = surface->format->BytesPerPixel;
bpp_reference = referenceSurface->format->BytesPerPixel;

/* Compare image - should be same format. */
for (j=0; j<surface->h; j++) {
for (i=0; i<surface->w; i++) {
p = (Uint8 *)surface->pixels + j * surface->pitch + i * bpp;
p_reference = (Uint8 *)referenceSurface->pixels + j * referenceSurface->pitch + i * bpp_reference;
dist = 0;

SDL_GetRGBA(*(Uint32*)p, surface->format, &R, &G, &B, &A);
SDL_GetRGBA(*(Uint32*)p_reference, referenceSurface->format, &Rd, &Gd, &Bd, &Ad);

dist += (R-Rd)*(R-Rd);
dist += (G-Gd)*(G-Gd);
dist += (B-Bd)*(B-Bd);

/* Allow some difference in blending accuracy */
if (dist > allowable_error) {
ret++;
}
}
}

SDL_UnlockSurface( surface );
SDL_UnlockSurface( referenceSurface );

return ret;
}
8 changes: 4 additions & 4 deletions src/test/SDL_test_fuzzer.c
Expand Up @@ -116,8 +116,8 @@ SDLTest_RandomUint32()
Uint64
SDLTest_RandomUint64()
{
Uint64 value;
Uint32 *vp = (void*)&value;
Uint64 value = 0;
Uint32 *vp = (void *)&value;

fuzzerInvocationCounter++;

Expand All @@ -130,8 +130,8 @@ SDLTest_RandomUint64()
Sint64
SDLTest_RandomSint64()
{
Uint64 value;
Uint32 *vp = (void*)&value;
Uint64 value = 0;
Uint32 *vp = (void *)&value;

fuzzerInvocationCounter++;

Expand Down

0 comments on commit c9c81c5

Please sign in to comment.