SDL  2.0
testautomation_surface.c File Reference
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include "SDL.h"
#include "SDL_test.h"
+ Include dependency graph for testautomation_surface.c:

Go to the source code of this file.

Macros

#define _CRT_SECURE_NO_DEPRECATE
 
#define _CRT_NONSTDC_NO_DEPRECATE
 
#define TEST_SURFACE_WIDTH   testSurface->w
 
#define TEST_SURFACE_HEIGHT   testSurface->h
 

Functions

void _surfaceSetUp (void *arg)
 
void _surfaceTearDown (void *arg)
 
void _clearTestSurface ()
 
void _testBlitBlendMode (int mode)
 
void _AssertFileExist (const char *filename)
 
int surface_testSaveLoadBitmap (void *arg)
 Tests sprite saving and loading. More...
 
int surface_testSurfaceConversion (void *arg)
 
int surface_testCompleteSurfaceConversion (void *arg)
 
int surface_testLoadFailure (void *arg)
 Tests sprite loading. A failure case. More...
 
int surface_testBlit (void *arg)
 Tests some blitting routines. More...
 
int surface_testBlitColorMod (void *arg)
 Tests some blitting routines with color mod. More...
 
int surface_testBlitAlphaMod (void *arg)
 Tests some blitting routines with alpha mod. More...
 
int surface_testBlitBlendNone (void *arg)
 Tests some more blitting routines. More...
 
int surface_testBlitBlendBlend (void *arg)
 Tests some more blitting routines. More...
 
int surface_testBlitBlendAdd (void *arg)
 Tests some more blitting routines. More...
 
int surface_testBlitBlendMod (void *arg)
 Tests some more blitting routines. More...
 
int surface_testBlitBlendLoop (void *arg)
 Tests some more blitting routines with loop. More...
 

Variables

static SDL_SurfacereferenceSurface = NULL
 
static SDL_SurfacetestSurface = NULL
 
static const SDLTest_TestCaseReference surfaceTest1
 
static const SDLTest_TestCaseReference surfaceTest2
 
static const SDLTest_TestCaseReference surfaceTest3
 
static const SDLTest_TestCaseReference surfaceTest4
 
static const SDLTest_TestCaseReference surfaceTest5
 
static const SDLTest_TestCaseReference surfaceTest6
 
static const SDLTest_TestCaseReference surfaceTest7
 
static const SDLTest_TestCaseReference surfaceTest8
 
static const SDLTest_TestCaseReference surfaceTest9
 
static const SDLTest_TestCaseReference surfaceTest10
 
static const SDLTest_TestCaseReference surfaceTest11
 
static const SDLTest_TestCaseReference surfaceTest12
 
static const SDLTest_TestCaseReferencesurfaceTests []
 
SDLTest_TestSuiteReference surfaceTestSuite
 

Macro Definition Documentation

◆ _CRT_NONSTDC_NO_DEPRECATE

#define _CRT_NONSTDC_NO_DEPRECATE

Definition at line 8 of file testautomation_surface.c.

◆ _CRT_SECURE_NO_DEPRECATE

#define _CRT_SECURE_NO_DEPRECATE

Original code: automated SDL surface test written by Edgar Simo "bobbens" Adapted/rewritten for test lib by Andreas Schiffler

Definition at line 7 of file testautomation_surface.c.

◆ TEST_SURFACE_HEIGHT

#define TEST_SURFACE_HEIGHT   testSurface->h

Definition at line 33 of file testautomation_surface.c.

◆ TEST_SURFACE_WIDTH

#define TEST_SURFACE_WIDTH   testSurface->w

Definition at line 32 of file testautomation_surface.c.

Function Documentation

◆ _AssertFileExist()

void _AssertFileExist ( const char *  filename)

Definition at line 205 of file testautomation_surface.c.

206 {
207  struct stat st;
208  int ret = stat(filename, &st);
209 
210  SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
211 }
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(2)
Assert for test cases that logs but does not break execution flow on failures. Updates assertion coun...
set set set set set set set set set set set set set set set set set set set set *set set set macro pixldst op &r &cond WK op &r &cond WK op &r &cond WK else op &m &cond &ia op &r &cond WK else op &m &cond &ia elseif elseif else error unsupported base if elseif elseif else error unsupported unaligned pixldst unaligned endm macro pixst base base else pixldst st

References sort_controllers::filename, SDLTest_AssertCheck(), and st.

Referenced by surface_testSaveLoadBitmap().

◆ _clearTestSurface()

void _clearTestSurface ( )

Helper that clears the test surface

Definition at line 82 of file testautomation_surface.c.

83 {
84  int ret;
85  Uint32 color;
86 
87  /* Clear surface. */
88  color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
89  SDLTest_AssertPass("Call to SDL_MapRGBA()");
91  SDLTest_AssertPass("Call to SDL_FillRect()");
92  SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
93 }
#define SDL_MapRGBA
#define SDL_FillRect
GLuint color
uint32_t Uint32
Definition: SDL_stdinc.h:209
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,...) SDL_PRINTF_VARARG_FUNC(1)
Explicitly pass without checking an assertion condition. Updates assertion counter.
#define NULL
Definition: begin_code.h:163
SDL_PixelFormat * format
Definition: SDL_surface.h:73
static SDL_Surface * testSurface

References SDL_Surface::format, NULL, SDL_FillRect, SDL_MapRGBA, SDLTest_AssertCheck(), SDLTest_AssertPass(), and testSurface.

Referenced by _testBlitBlendMode().

◆ _surfaceSetUp()

void _surfaceSetUp ( void arg)

Definition at line 39 of file testautomation_surface.c.

40 {
41  int result;
43  SDL_BlendMode currentBlendMode;
44  Uint32 rmask, gmask, bmask, amask;
45 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
46  rmask = 0xff000000;
47  gmask = 0x00ff0000;
48  bmask = 0x0000ff00;
49  amask = 0x000000ff;
50 #else
51  rmask = 0x000000ff;
52  gmask = 0x0000ff00;
53  bmask = 0x00ff0000;
54  amask = 0xff000000;
55 #endif
56 
57  referenceSurface = SDLTest_ImageBlit(); /* For size info */
58  testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
59  SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
60  if (testSurface != NULL) {
61  /* Disable blend mode for target surface */
63  SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
64  result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
65  SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
66  SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);
67  }
68 }
SDL_BlendMode
The blend mode used in SDL_RenderCopy() and drawing operations.
Definition: SDL_blendmode.h:41
@ SDL_BLENDMODE_NONE
Definition: SDL_blendmode.h:42
#define SDL_GetSurfaceBlendMode
#define SDL_SetSurfaceBlendMode
#define SDL_CreateRGBSurface
GLuint64EXT * result
#define SDL_SWSURFACE
Definition: SDL_surface.h:52
SDL_Surface * SDLTest_ImageBlit(void)
Returns the Blit test image as SDL_Surface.
static SDL_Surface * referenceSurface
static SDL_BlendMode blendMode
Definition: testdraw2.c:34

References blendMode, SDL_Surface::h, NULL, referenceSurface, SDL_BLENDMODE_NONE, SDL_CreateRGBSurface, SDL_GetSurfaceBlendMode, SDL_SetSurfaceBlendMode, SDL_SWSURFACE, SDLTest_AssertCheck(), SDLTest_ImageBlit(), testSurface, and SDL_Surface::w.

◆ _surfaceTearDown()

void _surfaceTearDown ( void arg)

Definition at line 71 of file testautomation_surface.c.

References NULL, referenceSurface, SDL_FreeSurface, and testSurface.

◆ _testBlitBlendMode()

void _testBlitBlendMode ( int  mode)

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.

Definition at line 98 of file testautomation_surface.c.

99 {
100  int ret;
101  int i, j, ni, nj;
102  SDL_Surface *face;
103  SDL_Rect rect;
104  int nmode;
105  SDL_BlendMode bmode;
106  int checkFailCount1;
107  int checkFailCount2;
108  int checkFailCount3;
109  int checkFailCount4;
110 
111  /* Check test surface */
112  SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL");
113  if (testSurface == NULL) return;
114 
115  /* Create sample surface */
117  SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
118  if (face == NULL) return;
119 
120  /* Reset alpha modulation */
121  ret = SDL_SetSurfaceAlphaMod(face, 255);
122  SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
123  SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
124 
125  /* Reset color modulation */
126  ret = SDL_SetSurfaceColorMod(face, 255, 255, 255);
127  SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
128  SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
129 
130  /* Reset color key */
131  ret = SDL_SetColorKey(face, SDL_FALSE, 0);
132  SDLTest_AssertPass("Call to SDL_SetColorKey()");
133  SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret);
134 
135  /* Clear the test surface */
137 
138  /* Target rect size */
139  rect.w = face->w;
140  rect.h = face->h;
141 
142  /* Steps to take */
143  ni = testSurface->w - face->w;
144  nj = testSurface->h - face->h;
145 
146  /* Optionally set blend mode. */
147  if (mode >= 0) {
149  SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
150  SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret);
151  }
152 
153  /* Test blend mode. */
154  checkFailCount1 = 0;
155  checkFailCount2 = 0;
156  checkFailCount3 = 0;
157  checkFailCount4 = 0;
158  for (j=0; j <= nj; j+=4) {
159  for (i=0; i <= ni; i+=4) {
160  if (mode == -2) {
161  /* Set color mod. */
162  ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
163  if (ret != 0) checkFailCount2++;
164  }
165  else if (mode == -3) {
166  /* Set alpha mod. */
167  ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
168  if (ret != 0) checkFailCount3++;
169  }
170  else if (mode == -4) {
171  /* Crazy blending mode magic. */
172  nmode = (i/4*j/4) % 4;
173  if (nmode==0) {
174  bmode = SDL_BLENDMODE_NONE;
175  } else if (nmode==1) {
176  bmode = SDL_BLENDMODE_BLEND;
177  } else if (nmode==2) {
178  bmode = SDL_BLENDMODE_ADD;
179  } else if (nmode==3) {
180  bmode = SDL_BLENDMODE_MOD;
181  }
182  ret = SDL_SetSurfaceBlendMode( face, bmode );
183  if (ret != 0) checkFailCount4++;
184  }
185 
186  /* Blitting. */
187  rect.x = i;
188  rect.y = j;
190  if (ret != 0) checkFailCount1++;
191  }
192  }
193  SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1);
194  SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", checkFailCount2);
195  SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 0, got: %i", checkFailCount3);
196  SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
197 
198  /* Clean up */
200  face = NULL;
201 }
@ SDL_BLENDMODE_ADD
Definition: SDL_blendmode.h:47
@ SDL_BLENDMODE_BLEND
Definition: SDL_blendmode.h:44
@ SDL_BLENDMODE_MOD
Definition: SDL_blendmode.h:50
#define SDL_SetColorKey
#define SDL_SetSurfaceColorMod
#define SDL_SetSurfaceAlphaMod
GLenum mode
GLenum GLuint GLint GLenum face
@ SDL_FALSE
Definition: SDL_stdinc.h:169
#define SDL_BlitSurface
Definition: SDL_surface.h:493
SDL_Surface * SDLTest_ImageFace(void)
Returns the Face test image as SDL_Surface.
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
int h
Definition: SDL_rect.h:80
int w
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
int x
Definition: SDL_rect.h:79
A collection of pixels used in software blitting.
Definition: SDL_surface.h:71
void _clearTestSurface()
SDL_Rect rect
Definition: testrelative.c:27

References _clearTestSurface(), SDL_Rect::h, SDL_Surface::h, i, j, NULL, rect, SDL_BLENDMODE_ADD, SDL_BLENDMODE_BLEND, SDL_BLENDMODE_MOD, SDL_BLENDMODE_NONE, SDL_BlitSurface, SDL_FALSE, SDL_FreeSurface, SDL_SetColorKey, SDL_SetSurfaceAlphaMod, SDL_SetSurfaceBlendMode, SDL_SetSurfaceColorMod, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_ImageFace(), testSurface, SDL_Rect::w, SDL_Surface::w, SDL_Rect::x, and SDL_Rect::y.

Referenced by surface_testBlit(), surface_testBlitAlphaMod(), surface_testBlitBlendAdd(), surface_testBlitBlendBlend(), surface_testBlitBlendLoop(), surface_testBlitBlendMod(), surface_testBlitBlendNone(), and surface_testBlitColorMod().

◆ surface_testBlit()

int surface_testBlit ( void arg)

Tests some blitting routines.

Definition at line 410 of file testautomation_surface.c.

411 {
412  int ret;
413  SDL_Surface *compareSurface;
414 
415  /* Basic blitting */
416  _testBlitBlendMode(-1);
417 
418  /* Verify result by comparing surfaces */
419  compareSurface = SDLTest_ImageBlit();
420  ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
421  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
422 
423  /* Clean up. */
424  SDL_FreeSurface(compareSurface);
425 
426  return TEST_COMPLETED;
427 }
int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error)
Compares a surface and with reference image data for equality.
#define TEST_COMPLETED
void _testBlitBlendMode(int mode)

References _testBlitBlendMode(), SDL_FreeSurface, SDLTest_AssertCheck(), SDLTest_CompareSurfaces(), SDLTest_ImageBlit(), TEST_COMPLETED, and testSurface.

◆ surface_testBlitAlphaMod()

int surface_testBlitAlphaMod ( void arg)

Tests some blitting routines with alpha mod.

Definition at line 456 of file testautomation_surface.c.

457 {
458  int ret;
459  SDL_Surface *compareSurface;
460 
461  /* Basic blitting with alpha mod */
462  _testBlitBlendMode(-3);
463 
464  /* Verify result by comparing surfaces */
465  compareSurface = SDLTest_ImageBlitAlpha();
466  ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
467  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
468 
469  /* Clean up. */
470  SDL_FreeSurface(compareSurface);
471 
472  return TEST_COMPLETED;
473 }
SDL_Surface * SDLTest_ImageBlitAlpha(void)
Returns the BlitAlpha test image as SDL_Surface.

References _testBlitBlendMode(), SDL_FreeSurface, SDLTest_AssertCheck(), SDLTest_CompareSurfaces(), SDLTest_ImageBlitAlpha(), TEST_COMPLETED, and testSurface.

◆ surface_testBlitBlendAdd()

int surface_testBlitBlendAdd ( void arg)

Tests some more blitting routines.

Definition at line 526 of file testautomation_surface.c.

527 {
528  int ret;
529  SDL_Surface *compareSurface;
530 
531  /* Add blitting */
533 
534  /* Verify result by comparing surfaces */
535  compareSurface = SDLTest_ImageBlitBlendAdd();
536  ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
537  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
538 
539  /* Clean up. */
540  SDL_FreeSurface(compareSurface);
541 
542  return TEST_COMPLETED;
543 }
SDL_Surface * SDLTest_ImageBlitBlendAdd(void)
Returns the BlitBlendAdd test image as SDL_Surface.

References _testBlitBlendMode(), SDL_BLENDMODE_ADD, SDL_FreeSurface, SDLTest_AssertCheck(), SDLTest_CompareSurfaces(), SDLTest_ImageBlitBlendAdd(), TEST_COMPLETED, and testSurface.

◆ surface_testBlitBlendBlend()

int surface_testBlitBlendBlend ( void arg)

Tests some more blitting routines.

Definition at line 503 of file testautomation_surface.c.

504 {
505  int ret;
506  SDL_Surface *compareSurface;
507 
508  /* Blend blitting */
510 
511  /* Verify result by comparing surfaces */
512  compareSurface = SDLTest_ImageBlitBlend();
513  ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
514  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
515 
516  /* Clean up. */
517  SDL_FreeSurface(compareSurface);
518 
519  return TEST_COMPLETED;
520 }
SDL_Surface * SDLTest_ImageBlitBlend(void)
Returns the BlitBlend test image as SDL_Surface.

References _testBlitBlendMode(), SDL_BLENDMODE_BLEND, SDL_FreeSurface, SDLTest_AssertCheck(), SDLTest_CompareSurfaces(), SDLTest_ImageBlitBlend(), TEST_COMPLETED, and testSurface.

◆ surface_testBlitBlendLoop()

int surface_testBlitBlendLoop ( void arg)

Tests some more blitting routines with loop.

Definition at line 572 of file testautomation_surface.c.

572  {
573 
574  int ret;
575  SDL_Surface *compareSurface;
576 
577  /* All blitting modes */
578  _testBlitBlendMode(-4);
579 
580  /* Verify result by comparing surfaces */
581  compareSurface = SDLTest_ImageBlitBlendAll();
582  ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
583  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
584 
585  /* Clean up. */
586  SDL_FreeSurface(compareSurface);
587 
588  return TEST_COMPLETED;
589 
590 }
SDL_Surface * SDLTest_ImageBlitBlendAll(void)
Returns the BlitBlendAll test image as SDL_Surface.

References _testBlitBlendMode(), SDL_FreeSurface, SDLTest_AssertCheck(), SDLTest_CompareSurfaces(), SDLTest_ImageBlitBlendAll(), TEST_COMPLETED, and testSurface.

◆ surface_testBlitBlendMod()

int surface_testBlitBlendMod ( void arg)

Tests some more blitting routines.

Definition at line 549 of file testautomation_surface.c.

550 {
551  int ret;
552  SDL_Surface *compareSurface;
553 
554  /* Mod blitting */
556 
557  /* Verify result by comparing surfaces */
558  compareSurface = SDLTest_ImageBlitBlendMod();
559  ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
560  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
561 
562  /* Clean up. */
563  SDL_FreeSurface(compareSurface);
564 
565  return TEST_COMPLETED;
566 }
SDL_Surface * SDLTest_ImageBlitBlendMod(void)
Returns the BlitBlendMod test image as SDL_Surface.

References _testBlitBlendMode(), SDL_BLENDMODE_MOD, SDL_FreeSurface, SDLTest_AssertCheck(), SDLTest_CompareSurfaces(), SDLTest_ImageBlitBlendMod(), TEST_COMPLETED, and testSurface.

◆ surface_testBlitBlendNone()

int surface_testBlitBlendNone ( void arg)

Tests some more blitting routines.

Definition at line 480 of file testautomation_surface.c.

481 {
482  int ret;
483  SDL_Surface *compareSurface;
484 
485  /* Basic blitting */
487 
488  /* Verify result by comparing surfaces */
489  compareSurface = SDLTest_ImageBlitBlendNone();
490  ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
491  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
492 
493  /* Clean up. */
494  SDL_FreeSurface(compareSurface);
495 
496  return TEST_COMPLETED;
497 }
SDL_Surface * SDLTest_ImageBlitBlendNone(void)
Returns the BlitBlendNone test image as SDL_Surface.

References _testBlitBlendMode(), SDL_BLENDMODE_NONE, SDL_FreeSurface, SDLTest_AssertCheck(), SDLTest_CompareSurfaces(), SDLTest_ImageBlitBlendNone(), TEST_COMPLETED, and testSurface.

◆ surface_testBlitColorMod()

int surface_testBlitColorMod ( void arg)

Tests some blitting routines with color mod.

Definition at line 433 of file testautomation_surface.c.

434 {
435  int ret;
436  SDL_Surface *compareSurface;
437 
438  /* Basic blitting with color mod */
439  _testBlitBlendMode(-2);
440 
441  /* Verify result by comparing surfaces */
442  compareSurface = SDLTest_ImageBlitColor();
443  ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
444  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
445 
446  /* Clean up. */
447  SDL_FreeSurface(compareSurface);
448 
449  return TEST_COMPLETED;
450 }
SDL_Surface * SDLTest_ImageBlitColor(void)
Returns the BlitColor test image as SDL_Surface.

References _testBlitBlendMode(), SDL_FreeSurface, SDLTest_AssertCheck(), SDLTest_CompareSurfaces(), SDLTest_ImageBlitColor(), TEST_COMPLETED, and testSurface.

◆ surface_testCompleteSurfaceConversion()

int surface_testCompleteSurfaceConversion ( void arg)

Definition at line 307 of file testautomation_surface.c.

308 {
309  Uint32 pixel_formats[] = {
337  };
338  SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
339  SDL_PixelFormat *fmt1, *fmt2;
340  int i, j, ret = 0;
341 
342  /* Create sample surface */
344  SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
345  if (face == NULL)
346  return TEST_ABORTED;
347 
348  /* Set transparent pixel as the pixel at (0,0) */
349  if (face->format->palette) {
350  ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
351  SDLTest_AssertPass("Call to SDL_SetColorKey()");
352  SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
353  }
354 
355  for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
356  for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
357  fmt1 = SDL_AllocFormat(pixel_formats[i]);
358  SDL_assert(fmt1 != NULL);
359  cvt1 = SDL_ConvertSurface(face, fmt1, 0);
360  SDL_assert(cvt1 != NULL);
361 
362  fmt2 = SDL_AllocFormat(pixel_formats[j]);
363  SDL_assert(fmt1 != NULL);
364  cvt2 = SDL_ConvertSurface(cvt1, fmt2, 0);
365  SDL_assert(cvt2 != NULL);
366 
367  if ( fmt1->BytesPerPixel == face->format->BytesPerPixel &&
368  fmt2->BytesPerPixel == face->format->BytesPerPixel &&
369  (fmt1->Amask != 0) == (face->format->Amask != 0) &&
370  (fmt2->Amask != 0) == (face->format->Amask != 0) ) {
371  final = SDL_ConvertSurface( cvt2, face->format, 0 );
372  SDL_assert(final != NULL);
373 
374  /* Compare surface. */
375  ret = SDLTest_CompareSurfaces( face, final, 0 );
376  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
377  SDL_FreeSurface(final);
378  }
379 
380  SDL_FreeSurface(cvt1);
381  SDL_FreeFormat(fmt1);
382  SDL_FreeSurface(cvt2);
383  SDL_FreeFormat(fmt2);
384  }
385  }
386 
387  /* Clean up. */
389 
390  return TEST_COMPLETED;
391 }
#define SDL_assert(condition)
Definition: SDL_assert.h:171
#define SDL_FreeFormat
#define SDL_AllocFormat
#define SDL_ConvertSurface
@ SDL_PIXELFORMAT_BGR565
Definition: SDL_pixels.h:234
@ SDL_PIXELFORMAT_RGB332
Definition: SDL_pixels.h:188
@ SDL_PIXELFORMAT_BGR444
Definition: SDL_pixels.h:198
@ SDL_PIXELFORMAT_ABGR4444
Definition: SDL_pixels.h:213
@ SDL_PIXELFORMAT_BGRA4444
Definition: SDL_pixels.h:216
@ SDL_PIXELFORMAT_BGR24
Definition: SDL_pixels.h:240
@ SDL_PIXELFORMAT_RGB555
Definition: SDL_pixels.h:202
@ SDL_PIXELFORMAT_RGB444
Definition: SDL_pixels.h:194
@ SDL_PIXELFORMAT_RGBA8888
Definition: SDL_pixels.h:260
@ SDL_PIXELFORMAT_RGBA5551
Definition: SDL_pixels.h:222
@ SDL_PIXELFORMAT_ARGB1555
Definition: SDL_pixels.h:219
@ SDL_PIXELFORMAT_INDEX8
Definition: SDL_pixels.h:186
@ SDL_PIXELFORMAT_BGR888
Definition: SDL_pixels.h:253
@ SDL_PIXELFORMAT_BGRX8888
Definition: SDL_pixels.h:254
@ SDL_PIXELFORMAT_RGB24
Definition: SDL_pixels.h:237
@ SDL_PIXELFORMAT_RGB888
Definition: SDL_pixels.h:246
@ SDL_PIXELFORMAT_ABGR8888
Definition: SDL_pixels.h:263
@ SDL_PIXELFORMAT_BGRA8888
Definition: SDL_pixels.h:266
@ SDL_PIXELFORMAT_ABGR1555
Definition: SDL_pixels.h:225
@ SDL_PIXELFORMAT_ARGB8888
Definition: SDL_pixels.h:257
@ SDL_PIXELFORMAT_ARGB4444
Definition: SDL_pixels.h:207
@ SDL_PIXELFORMAT_RGBX8888
Definition: SDL_pixels.h:247
@ SDL_PIXELFORMAT_BGRA5551
Definition: SDL_pixels.h:228
@ SDL_PIXELFORMAT_RGB565
Definition: SDL_pixels.h:231
@ SDL_PIXELFORMAT_ARGB2101010
Definition: SDL_pixels.h:269
@ SDL_PIXELFORMAT_BGR555
Definition: SDL_pixels.h:206
@ SDL_PIXELFORMAT_RGBA4444
Definition: SDL_pixels.h:210
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:121
uint8_t Uint8
Definition: SDL_stdinc.h:185
#define SDL_RLEACCEL
Definition: SDL_surface.h:54
#define TEST_ABORTED
Uint8 BytesPerPixel
Definition: SDL_pixels.h:329

References SDL_PixelFormat::Amask, SDL_PixelFormat::BytesPerPixel, i, j, NULL, SDL_AllocFormat, SDL_arraysize, SDL_assert, SDL_ConvertSurface, SDL_FreeFormat, SDL_FreeSurface, SDL_PIXELFORMAT_ABGR1555, SDL_PIXELFORMAT_ABGR4444, SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB1555, SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ARGB4444, SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR24, SDL_PIXELFORMAT_BGR444, SDL_PIXELFORMAT_BGR555, SDL_PIXELFORMAT_BGR565, SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGRA4444, SDL_PIXELFORMAT_BGRA5551, SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGRX8888, SDL_PIXELFORMAT_INDEX8, SDL_PIXELFORMAT_RGB24, SDL_PIXELFORMAT_RGB332, SDL_PIXELFORMAT_RGB444, SDL_PIXELFORMAT_RGB555, SDL_PIXELFORMAT_RGB565, SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGBA4444, SDL_PIXELFORMAT_RGBA5551, SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGBX8888, SDL_RLEACCEL, SDL_SetColorKey, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_CompareSurfaces(), SDLTest_ImageFace(), TEST_ABORTED, and TEST_COMPLETED.

◆ surface_testLoadFailure()

int surface_testLoadFailure ( void arg)

Tests sprite loading. A failure case.

Definition at line 398 of file testautomation_surface.c.

399 {
400  SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
401  SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
402 
403  return TEST_COMPLETED;
404 }
#define SDL_LoadBMP(file)
Definition: SDL_surface.h:203

References NULL, SDL_LoadBMP, SDLTest_AssertCheck(), and TEST_COMPLETED.

◆ surface_testSaveLoadBitmap()

int surface_testSaveLoadBitmap ( void arg)

Tests sprite saving and loading.

Definition at line 220 of file testautomation_surface.c.

221 {
222  int ret;
223  const char *sampleFilename = "testSaveLoadBitmap.bmp";
224  SDL_Surface *face;
225  SDL_Surface *rface;
226 
227  /* Create sample surface */
229  SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
230  if (face == NULL) return TEST_ABORTED;
231 
232  /* Delete test file; ignore errors */
233  unlink(sampleFilename);
234 
235  /* Save a surface */
236  ret = SDL_SaveBMP(face, sampleFilename);
237  SDLTest_AssertPass("Call to SDL_SaveBMP()");
238  SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret);
239  _AssertFileExist(sampleFilename);
240 
241  /* Load a surface */
242  rface = SDL_LoadBMP(sampleFilename);
243  SDLTest_AssertPass("Call to SDL_LoadBMP()");
244  SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
245  if (rface != NULL) {
246  SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
247  SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
248  }
249 
250  /* Delete test file; ignore errors */
251  unlink(sampleFilename);
252 
253  /* Clean up */
255  face = NULL;
256  SDL_FreeSurface(rface);
257  rface = NULL;
258 
259  return TEST_COMPLETED;
260 }
#define SDL_SaveBMP(surface, file)
Definition: SDL_surface.h:226
void _AssertFileExist(const char *filename)

References _AssertFileExist(), SDL_Surface::h, NULL, SDL_FreeSurface, SDL_LoadBMP, SDL_SaveBMP, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_ImageFace(), TEST_ABORTED, TEST_COMPLETED, and SDL_Surface::w.

◆ surface_testSurfaceConversion()

int surface_testSurfaceConversion ( void arg)

Definition at line 266 of file testautomation_surface.c.

267 {
268  SDL_Surface *rface = NULL, *face = NULL;
269  int ret = 0;
270 
271  /* Create sample surface */
273  SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
274  if (face == NULL)
275  return TEST_ABORTED;
276 
277  /* Set transparent pixel as the pixel at (0,0) */
278  if (face->format->palette) {
279  ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
280  SDLTest_AssertPass("Call to SDL_SetColorKey()");
281  SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
282  }
283 
284  /* Convert to 32 bit to compare. */
285  rface = SDL_ConvertSurface( face, testSurface->format, 0 );
286  SDLTest_AssertPass("Call to SDL_ConvertSurface()");
287  SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
288 
289  /* Compare surface. */
290  ret = SDLTest_CompareSurfaces( rface, face, 0 );
291  SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
292 
293  /* Clean up. */
295  face = NULL;
296  SDL_FreeSurface(rface);
297  rface = NULL;
298 
299  return TEST_COMPLETED;
300 }

References SDL_Surface::format, NULL, SDL_ConvertSurface, SDL_FreeSurface, SDL_RLEACCEL, SDL_SetColorKey, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_CompareSurfaces(), SDLTest_ImageFace(), TEST_ABORTED, TEST_COMPLETED, and testSurface.

Variable Documentation

◆ referenceSurface

◆ surfaceTest1

const SDLTest_TestCaseReference surfaceTest1
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED}
#define TEST_ENABLED
int(* SDLTest_TestCaseFp)(void *arg)
int surface_testSaveLoadBitmap(void *arg)
Tests sprite saving and loading.

Definition at line 595 of file testautomation_surface.c.

◆ surfaceTest10

const SDLTest_TestCaseReference surfaceTest10
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED}
#define TEST_DISABLED
int surface_testBlitBlendBlend(void *arg)
Tests some more blitting routines.

Definition at line 624 of file testautomation_surface.c.

◆ surfaceTest11

const SDLTest_TestCaseReference surfaceTest11
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED}
int surface_testBlitBlendAdd(void *arg)
Tests some more blitting routines.

Definition at line 628 of file testautomation_surface.c.

◆ surfaceTest12

const SDLTest_TestCaseReference surfaceTest12
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED}
int surface_testBlitBlendMod(void *arg)
Tests some more blitting routines.

Definition at line 631 of file testautomation_surface.c.

◆ surfaceTest2

const SDLTest_TestCaseReference surfaceTest2
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED}
int surface_testBlit(void *arg)
Tests some blitting routines.

Definition at line 598 of file testautomation_surface.c.

◆ surfaceTest3

const SDLTest_TestCaseReference surfaceTest3
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED}
int surface_testBlitBlendNone(void *arg)
Tests some more blitting routines.

Definition at line 601 of file testautomation_surface.c.

◆ surfaceTest4

const SDLTest_TestCaseReference surfaceTest4
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED}
int surface_testLoadFailure(void *arg)
Tests sprite loading. A failure case.

Definition at line 604 of file testautomation_surface.c.

◆ surfaceTest5

const SDLTest_TestCaseReference surfaceTest5
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED}
int surface_testSurfaceConversion(void *arg)

Definition at line 607 of file testautomation_surface.c.

◆ surfaceTest6

const SDLTest_TestCaseReference surfaceTest6
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED}
int surface_testCompleteSurfaceConversion(void *arg)

Definition at line 610 of file testautomation_surface.c.

◆ surfaceTest7

const SDLTest_TestCaseReference surfaceTest7
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED}
int surface_testBlitColorMod(void *arg)
Tests some blitting routines with color mod.

Definition at line 613 of file testautomation_surface.c.

◆ surfaceTest8

const SDLTest_TestCaseReference surfaceTest8
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED}
int surface_testBlitAlphaMod(void *arg)
Tests some blitting routines with alpha mod.

Definition at line 616 of file testautomation_surface.c.

◆ surfaceTest9

const SDLTest_TestCaseReference surfaceTest9
static
Initial value:
=
{ (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blitting routines with various blending modes", TEST_DISABLED}
int surface_testBlitBlendLoop(void *arg)
Tests some more blitting routines with loop.

Definition at line 620 of file testautomation_surface.c.

◆ surfaceTests

const SDLTest_TestCaseReference* surfaceTests[]
static
Initial value:
= {
}
static const SDLTest_TestCaseReference surfaceTest4
static const SDLTest_TestCaseReference surfaceTest7
static const SDLTest_TestCaseReference surfaceTest5
static const SDLTest_TestCaseReference surfaceTest10
static const SDLTest_TestCaseReference surfaceTest6
static const SDLTest_TestCaseReference surfaceTest9
static const SDLTest_TestCaseReference surfaceTest3
static const SDLTest_TestCaseReference surfaceTest12
static const SDLTest_TestCaseReference surfaceTest11
static const SDLTest_TestCaseReference surfaceTest2
static const SDLTest_TestCaseReference surfaceTest8
static const SDLTest_TestCaseReference surfaceTest1

Definition at line 635 of file testautomation_surface.c.

◆ surfaceTestSuite

SDLTest_TestSuiteReference surfaceTestSuite
Initial value:
= {
"Surface",
}
void _surfaceTearDown(void *arg)
static const SDLTest_TestCaseReference * surfaceTests[]
void _surfaceSetUp(void *arg)

Definition at line 642 of file testautomation_surface.c.

◆ testSurface