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

Commit

Permalink
Ported common directory from automated. It contains common
Browse files Browse the repository at this point in the history
helpers functions for some test suites.
  • Loading branch information
mkauppila committed Jul 8, 2011
1 parent ff0c9a5 commit b999514
Show file tree
Hide file tree
Showing 8 changed files with 5,622 additions and 0 deletions.
110 changes: 110 additions & 0 deletions test/test-automation/common/common.c
@@ -0,0 +1,110 @@
/**
* Automated SDL_Surface test.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/


#include "SDL.h"
#include "../SDL_at.h"

#include "common.h"


/**
* @brief Compares a surface and a surface image for equality.
*/
int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img, int allowable_error )
{
int ret;
int i,j;
int bpp;
Uint8 *p, *pd;

/* Make sure size is the same. */
if ((sur->w != img->width) || (sur->h != img->height))
return -1;

SDL_LockSurface( sur );

ret = 0;
bpp = sur->format->BytesPerPixel;

/* Compare image - should be same format. */
for (j=0; j<sur->h; j++) {
for (i=0; i<sur->w; i++) {
p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp;
pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel;
switch (bpp) {
case 1:
case 2:
case 3:
ret += 1;
/*printf("%d BPP not supported yet.\n",bpp);*/
break;

case 4:
{
int dist = 0;
Uint8 R, G, B, A;

SDL_GetRGBA(*(Uint32*)p, sur->format, &R, &G, &B, &A);

if (img->bytes_per_pixel == 3) {
dist += (R-pd[0])*(R-pd[0]);
dist += (G-pd[1])*(G-pd[1]);
dist += (B-pd[2])*(B-pd[2]);
} else {
dist += (R-pd[0])*(R-pd[0]);
dist += (G-pd[1])*(G-pd[1]);
dist += (B-pd[2])*(B-pd[2]);
dist += (A-pd[3])*(A-pd[3]);
}
/* Allow some difference in blending accuracy */
if (dist > allowable_error) {
/*printf("pixel %d,%d varies by %d\n", i, j, dist);*/
++ret;
}
}
break;
}
}
}

SDL_UnlockSurface( sur );

if (ret) {
SDL_SaveBMP(sur, "fail.bmp");

SDL_LockSurface( sur );

bpp = sur->format->BytesPerPixel;

if (bpp == 4) {
for (j=0; j<sur->h; j++) {
for (i=0; i<sur->w; i++) {
Uint8 R, G, B, A;
p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp;
pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel;

R = pd[0];
G = pd[1];
B = pd[2];
if (img->bytes_per_pixel == 4) {
A = pd[3];
} else {
A = 0;
}
*(Uint32*)p = (A << 24) | (R << 16) | (G << 8) | B;
}
}
}

SDL_UnlockSurface( sur );

SDL_SaveBMP(sur, "good.bmp");
}
return ret;
}
42 changes: 42 additions & 0 deletions test/test-automation/common/common.h
@@ -0,0 +1,42 @@
/**
* Automated SDL test common framework.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/


#ifndef COMMON_H
# define COMMON_H


# define FORMAT SDL_PIXELFORMAT_ARGB8888
# define AMASK 0xff000000 /**< Alpha bit mask. */
# define RMASK 0x00ff0000 /**< Red bit mask. */
# define GMASK 0x0000ff00 /**< Green bit mask. */
# define BMASK 0x000000ff /**< Blue bit mask. */


typedef struct SurfaceImage_s {
int width;
int height;
unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
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.
*
* @param sur Surface to compare.
* @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 allowable_error );


#endif /* COMMON_H */

22 changes: 22 additions & 0 deletions test/test-automation/common/images.h
@@ -0,0 +1,22 @@


#ifndef IMAGES_H
# define IMAGES_H


#include "common.h"


/*
* Pull in images for testcases.
*/
#include "img_primitives.c"
#include "img_primitivesblend.c"
#include "img_face.c"
#include "img_blit.c"
#include "img_blitblend.c"


#endif /* IMAGES_H */


1,454 changes: 1,454 additions & 0 deletions test/test-automation/common/img_blit.c

Large diffs are not rendered by default.

2,690 changes: 2,690 additions & 0 deletions test/test-automation/common/img_blitblend.c

Large diffs are not rendered by default.

196 changes: 196 additions & 0 deletions test/test-automation/common/img_face.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b999514

Please sign in to comment.