annotate test/automated/common/common.c @ 3728:97e9704fc267 gsoc2009_unit_tests

Using common infrastructure.
author Edgar Simo <bobbens@gmail.com>
date Sat, 11 Jul 2009 19:21:48 +0000
parents
children 0acec8c9f5c9
rev   line source
3728
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
1 /**
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
2 * Automated SDL_Surface test.
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
3 *
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
4 * Written by Edgar Simo "bobbens"
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
5 *
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
6 * Released under Public Domain.
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
7 */
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
8
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
9
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
10 #include "SDL.h"
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
11 #include "SDL_at.h"
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
12
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
13 #include "common/common.h"
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
14
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
15
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
16 /**
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
17 * @brief Compares a surface and a surface image for equality.
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
18 */
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
19 int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img )
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
20 {
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
21 int ret;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
22 int i,j;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
23 int bpp;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
24 Uint8 *p, *pd;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
25
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
26 /* Make sure size is the same. */
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
27 if ((sur->w != img->width) || (sur->h != img->height))
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
28 return -1;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
29
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
30 SDL_LockSurface( sur );
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
31
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
32 ret = 0;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
33 bpp = sur->format->BytesPerPixel;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
34
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
35 /* Compare image - should be same format. */
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
36 for (j=0; j<sur->h; j++) {
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
37 for (i=0; i<sur->w; i++) {
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
38 p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
39 pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
40 switch (bpp) {
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
41 case 1:
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
42 case 2:
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
43 case 3:
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
44 ret += 1;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
45 printf("%d BPP not supported yet.\n",bpp);
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
46 break;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
47
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
48 case 4:
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
49 ret += !( (p[0] == pd[0]) &&
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
50 (p[1] == pd[1]) &&
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
51 (p[2] == pd[2]) );
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
52 break;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
53 }
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
54 }
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
55 }
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
56
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
57 SDL_UnlockSurface( sur );
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
58
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
59 return ret;
97e9704fc267 Using common infrastructure.
Edgar Simo <bobbens@gmail.com>
parents:
diff changeset
60 }