| 1 |
/** |
| 2 |
* Original code: automated SDL surface test written by Edgar Simo "bobbens" |
| 3 |
* Adapted/rewritten for test lib by Andreas Schiffler |
| 4 |
*/ |
| 5 |
|
| 6 |
/* Supress C4996 VS compiler warnings for unlink() */ |
| 7 |
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) |
| 8 |
#define _CRT_SECURE_NO_DEPRECATE |
| 9 |
#endif |
| 10 |
#if defined(_MSC_VER) && !defined(_CRT_NONSTDC_NO_DEPRECATE) |
| 11 |
#define _CRT_NONSTDC_NO_DEPRECATE |
| 12 |
#endif |
| 13 |
|
| 14 |
#include <stdio.h> |
| 15 |
#ifndef _MSC_VER |
| 16 |
#include <unistd.h> |
| 17 |
#endif |
| 18 |
#include <sys/stat.h> |
| 19 |
|
| 20 |
#include "SDL.h" |
| 21 |
#include "SDL_test.h" |
| 22 |
|
| 23 |
#ifdef __MACOSX__ |
| 24 |
#include <unistd.h> /* For unlink() */ |
| 25 |
#endif |
| 26 |
|
| 27 |
/* ================= Test Case Implementation ================== */ |
| 28 |
|
| 29 |
/* Shared test surface */ |
| 30 |
|
| 31 |
static SDL_Surface *referenceSurface = NULL; |
| 32 |
static SDL_Surface *testSurface = NULL; |
| 33 |
|
| 34 |
/* Helper functions for the test cases */ |
| 35 |
|
| 36 |
#define TEST_SURFACE_WIDTH testSurface->w |
| 37 |
#define TEST_SURFACE_HEIGHT testSurface->h |
| 38 |
|
| 39 |
/* Fixture */ |
| 40 |
|
| 41 |
/* Create a 32-bit writable surface for blitting tests */ |
| 42 |
void _surfaceSetUp(void *arg) |
| 43 |
{ |
| 44 |
int result; |
| 45 |
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE; |
| 46 |
SDL_BlendMode currentBlendMode; |
| 47 |
Uint32 rmask, gmask, bmask, amask; |
| 48 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
| 49 |
rmask = 0xff000000; |
| 50 |
gmask = 0x00ff0000; |
| 51 |
bmask = 0x0000ff00; |
| 52 |
amask = 0x000000ff; |
| 53 |
#else |
| 54 |
rmask = 0x000000ff; |
| 55 |
gmask = 0x0000ff00; |
| 56 |
bmask = 0x00ff0000; |
| 57 |
amask = 0xff000000; |
| 58 |
#endif |
| 59 |
|
| 60 |
referenceSurface = SDLTest_ImageBlit(); /* For size info */ |
| 61 |
testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask); |
| 62 |
SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL"); |
| 63 |
if (testSurface != NULL) { |
| 64 |
/* Disable blend mode for target surface */ |
| 65 |
result = SDL_SetSurfaceBlendMode(testSurface, blendMode); |
| 66 |
SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result); |
| 67 |
result = SDL_GetSurfaceBlendMode(testSurface, ¤tBlendMode); |
| 68 |
SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result); |
| 69 |
SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
void _surfaceTearDown(void *arg) |
| 74 |
{ |
| 75 |
SDL_FreeSurface(referenceSurface); |
| 76 |
referenceSurface = NULL; |
| 77 |
SDL_FreeSurface(testSurface); |
| 78 |
testSurface = NULL; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Helper that clears the test surface |
| 83 |
*/ |
| 84 |
void _clearTestSurface(void) |
| 85 |
{ |
| 86 |
int ret; |
| 87 |
Uint32 color; |
| 88 |
|
| 89 |
/* Clear surface. */ |
| 90 |
color = SDL_MapRGBA(testSurface->format, 0, 0, 0, 0); |
| 91 |
SDLTest_AssertPass("Call to SDL_MapRGBA()"); |
| 92 |
ret = SDL_FillRect(testSurface, NULL, color); |
| 93 |
SDLTest_AssertPass("Call to SDL_FillRect()"); |
| 94 |
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* 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. |
| 99 |
*/ |
| 100 |
void _testBlitBlendMode(int mode) |
| 101 |
{ |
| 102 |
int ret; |
| 103 |
int i, j, ni, nj; |
| 104 |
SDL_Surface *face; |
| 105 |
SDL_Rect rect; |
| 106 |
int nmode; |
| 107 |
SDL_BlendMode bmode; |
| 108 |
int checkFailCount1; |
| 109 |
int checkFailCount2; |
| 110 |
int checkFailCount3; |
| 111 |
int checkFailCount4; |
| 112 |
|
| 113 |
/* Check test surface */ |
| 114 |
SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL"); |
| 115 |
if (testSurface == NULL) { |
| 116 |
return; |
| 117 |
} |
| 118 |
|
| 119 |
/* Create sample surface */ |
| 120 |
face = SDLTest_ImageFace(); |
| 121 |
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL"); |
| 122 |
if (face == NULL) { |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
/* Reset alpha modulation */ |
| 127 |
ret = SDL_SetSurfaceAlphaMod(face, 255); |
| 128 |
SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()"); |
| 129 |
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret); |
| 130 |
|
| 131 |
/* Reset color modulation */ |
| 132 |
ret = SDL_SetSurfaceColorMod(face, 255, 255, 255); |
| 133 |
SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()"); |
| 134 |
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret); |
| 135 |
|
| 136 |
/* Reset color key */ |
| 137 |
ret = SDL_SetColorKey(face, SDL_FALSE, 0); |
| 138 |
SDLTest_AssertPass("Call to SDL_SetColorKey()"); |
| 139 |
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret); |
| 140 |
|
| 141 |
/* Clear the test surface */ |
| 142 |
_clearTestSurface(); |
| 143 |
|
| 144 |
/* Target rect size */ |
| 145 |
rect.w = face->w; |
| 146 |
rect.h = face->h; |
| 147 |
|
| 148 |
/* Steps to take */ |
| 149 |
ni = testSurface->w - face->w; |
| 150 |
nj = testSurface->h - face->h; |
| 151 |
|
| 152 |
/* Optionally set blend mode. */ |
| 153 |
if (mode >= 0) { |
| 154 |
ret = SDL_SetSurfaceBlendMode(face, (SDL_BlendMode)mode); |
| 155 |
SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()"); |
| 156 |
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret); |
| 157 |
} |
| 158 |
|
| 159 |
/* Test blend mode. */ |
| 160 |
checkFailCount1 = 0; |
| 161 |
checkFailCount2 = 0; |
| 162 |
checkFailCount3 = 0; |
| 163 |
checkFailCount4 = 0; |
| 164 |
for (j = 0; j <= nj; j += 4) { |
| 165 |
for (i = 0; i <= ni; i += 4) { |
| 166 |
if (mode == -2) { |
| 167 |
/* Set color mod. */ |
| 168 |
ret = SDL_SetSurfaceColorMod(face, (255 / nj) * j, (255 / ni) * i, (255 / nj) * j); |
| 169 |
if (ret != 0) { |
| 170 |
checkFailCount2++; |
| 171 |
} |
| 172 |
} else if (mode == -3) { |
| 173 |
/* Set alpha mod. */ |
| 174 |
ret = SDL_SetSurfaceAlphaMod(face, (255 / ni) * i); |
| 175 |
if (ret != 0) { |
| 176 |
checkFailCount3++; |
| 177 |
} |
| 178 |
} else if (mode == -4) { |
| 179 |
/* Crazy blending mode magic. */ |
| 180 |
nmode = (i / 4 * j / 4) % 4; |
| 181 |
if (nmode == 0) { |
| 182 |
bmode = SDL_BLENDMODE_NONE; |
| 183 |
} else if (nmode == 1) { |
| 184 |
bmode = SDL_BLENDMODE_BLEND; |
| 185 |
} else if (nmode == 2) { |
| 186 |
bmode = SDL_BLENDMODE_ADD; |
| 187 |
} else if (nmode == 3) { |
| 188 |
bmode = SDL_BLENDMODE_MOD; |
| 189 |
} else { |
| 190 |
/* Should be impossible, but some static checkers are too imprecise and will complain */ |
| 191 |
SDLTest_LogError("Invalid: nmode=%d", nmode); |
| 192 |
return; |
| 193 |
} |
| 194 |
ret = SDL_SetSurfaceBlendMode(face, bmode); |
| 195 |
if (ret != 0) { |
| 196 |
checkFailCount4++; |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
/* Blitting. */ |
| 201 |
rect.x = i; |
| 202 |
rect.y = j; |
| 203 |
ret = SDL_BlitSurface(face, NULL, testSurface, &rect); |
| 204 |
if (ret != 0) { |
| 205 |
checkFailCount1++; |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1); |
| 210 |
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", checkFailCount2); |
| 211 |
SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 0, got: %i", checkFailCount3); |
| 212 |
SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4); |
| 213 |
|
| 214 |
/* Clean up */ |
| 215 |
SDL_FreeSurface(face); |
| 216 |
face = NULL; |
| 217 |
} |
| 218 |
|
| 219 |
/* Helper to check that a file exists */ |
| 220 |
void _AssertFileExist(const char *filename) |
| 221 |
{ |
| 222 |
struct stat st; |
| 223 |
int ret = stat(filename, &st); |
| 224 |
|
| 225 |
SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename); |
| 226 |
} |
| 227 |
|
| 228 |
/* Test case functions */ |
| 229 |
|
| 230 |
/** |
| 231 |
* @brief Tests sprite saving and loading |
| 232 |
*/ |
| 233 |
int surface_testSaveLoadBitmap(void *arg) |
| 234 |
{ |
| 235 |
int ret; |
| 236 |
const char *sampleFilename = "testSaveLoadBitmap.bmp"; |
| 237 |
SDL_Surface *face; |
| 238 |
SDL_Surface *rface; |
| 239 |
|
| 240 |
/* Create sample surface */ |
| 241 |
face = SDLTest_ImageFace(); |
| 242 |
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL"); |
| 243 |
if (face == NULL) { |
| 244 |
return TEST_ABORTED; |
| 245 |
} |
| 246 |
|
| 247 |
/* Delete test file; ignore errors */ |
| 248 |
unlink(sampleFilename); |
| 249 |
|
| 250 |
/* Save a surface */ |
| 251 |
ret = SDL_SaveBMP(face, sampleFilename); |
| 252 |
SDLTest_AssertPass("Call to SDL_SaveBMP()"); |
| 253 |
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret); |
| 254 |
_AssertFileExist(sampleFilename); |
| 255 |
|
| 256 |
/* Load a surface */ |
| 257 |
rface = SDL_LoadBMP(sampleFilename); |
| 258 |
SDLTest_AssertPass("Call to SDL_LoadBMP()"); |
| 259 |
SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL"); |
| 260 |
if (rface != NULL) { |
| 261 |
SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w); |
| 262 |
SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h); |
| 263 |
} |
| 264 |
|
| 265 |
/* Delete test file; ignore errors */ |
| 266 |
unlink(sampleFilename); |
| 267 |
|
| 268 |
/* Clean up */ |
| 269 |
SDL_FreeSurface(face); |
| 270 |
face = NULL; |
| 271 |
SDL_FreeSurface(rface); |
| 272 |
rface = NULL; |
| 273 |
|
| 274 |
return TEST_COMPLETED; |
| 275 |
} |
| 276 |
|
| 277 |
/* ! |
| 278 |
* Tests surface conversion. |
| 279 |
*/ |
| 280 |
int surface_testSurfaceConversion(void *arg) |
| 281 |
{ |
| 282 |
SDL_Surface *rface = NULL, *face = NULL; |
| 283 |
int ret = 0; |
| 284 |
|
| 285 |
/* Create sample surface */ |
| 286 |
face = SDLTest_ImageFace(); |
| 287 |
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL"); |
| 288 |
if (face == NULL) { |
| 289 |
return TEST_ABORTED; |
| 290 |
} |
| 291 |
|
| 292 |
/* Set transparent pixel as the pixel at (0,0) */ |
| 293 |
if (face->format->palette) { |
| 294 |
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *)face->pixels); |
| 295 |
SDLTest_AssertPass("Call to SDL_SetColorKey()"); |
| 296 |
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret); |
| 297 |
} |
| 298 |
|
| 299 |
/* Convert to 32 bit to compare. */ |
| 300 |
rface = SDL_ConvertSurface( face, testSurface->format, 0 ); |
| 301 |
SDLTest_AssertPass("Call to SDL_ConvertSurface()"); |
| 302 |
SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL"); |
| 303 |
|
| 304 |
/* Compare surface. */ |
| 305 |
ret = SDLTest_CompareSurfaces(rface, face, 0); |
| 306 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 307 |
|
| 308 |
/* Clean up. */ |
| 309 |
SDL_FreeSurface(face); |
| 310 |
face = NULL; |
| 311 |
SDL_FreeSurface(rface); |
| 312 |
rface = NULL; |
| 313 |
|
| 314 |
return TEST_COMPLETED; |
| 315 |
} |
| 316 |
|
| 317 |
/* ! |
| 318 |
* Tests surface conversion across all pixel formats. |
| 319 |
*/ |
| 320 |
int surface_testCompleteSurfaceConversion(void *arg) |
| 321 |
{ |
| 322 |
Uint32 pixel_formats[] = { |
| 323 |
SDL_PIXELFORMAT_INDEX8, |
| 324 |
SDL_PIXELFORMAT_RGB332, |
| 325 |
SDL_PIXELFORMAT_RGB444, |
| 326 |
SDL_PIXELFORMAT_BGR444, |
| 327 |
SDL_PIXELFORMAT_RGB555, |
| 328 |
SDL_PIXELFORMAT_BGR555, |
| 329 |
SDL_PIXELFORMAT_ARGB4444, |
| 330 |
SDL_PIXELFORMAT_RGBA4444, |
| 331 |
SDL_PIXELFORMAT_ABGR4444, |
| 332 |
SDL_PIXELFORMAT_BGRA4444, |
| 333 |
SDL_PIXELFORMAT_ARGB1555, |
| 334 |
SDL_PIXELFORMAT_RGBA5551, |
| 335 |
SDL_PIXELFORMAT_ABGR1555, |
| 336 |
SDL_PIXELFORMAT_BGRA5551, |
| 337 |
SDL_PIXELFORMAT_RGB565, |
| 338 |
SDL_PIXELFORMAT_BGR565, |
| 339 |
SDL_PIXELFORMAT_RGB24, |
| 340 |
SDL_PIXELFORMAT_BGR24, |
| 341 |
SDL_PIXELFORMAT_RGB888, |
| 342 |
SDL_PIXELFORMAT_RGBX8888, |
| 343 |
SDL_PIXELFORMAT_BGR888, |
| 344 |
SDL_PIXELFORMAT_BGRX8888, |
| 345 |
SDL_PIXELFORMAT_ARGB8888, |
| 346 |
SDL_PIXELFORMAT_RGBA8888, |
| 347 |
SDL_PIXELFORMAT_ABGR8888, |
| 348 |
SDL_PIXELFORMAT_BGRA8888, |
| 349 |
#if 0 /* We aren't testing HDR10 colorspace conversion */ |
| 350 |
SDL_PIXELFORMAT_ARGB2101010, |
| 351 |
#endif |
| 352 |
}; |
| 353 |
SDL_Surface *face = NULL, *cvt1, *cvt2, *final; |
| 354 |
SDL_PixelFormat *fmt1, *fmt2; |
| 355 |
int i, j, ret = 0; |
| 356 |
|
| 357 |
/* Create sample surface */ |
| 358 |
face = SDLTest_ImageFace(); |
| 359 |
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL"); |
| 360 |
if (face == NULL) { |
| 361 |
return TEST_ABORTED; |
| 362 |
} |
| 363 |
|
| 364 |
/* Set transparent pixel as the pixel at (0,0) */ |
| 365 |
if (face->format->palette) { |
| 366 |
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *)face->pixels); |
| 367 |
SDLTest_AssertPass("Call to SDL_SetColorKey()"); |
| 368 |
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret); |
| 369 |
} |
| 370 |
|
| 371 |
for (i = 0; i < SDL_arraysize(pixel_formats); ++i) { |
| 372 |
for (j = 0; j < SDL_arraysize(pixel_formats); ++j) { |
| 373 |
fmt1 = SDL_AllocFormat(pixel_formats[i]); |
| 374 |
SDL_assert(fmt1 != NULL); |
| 375 |
cvt1 = SDL_ConvertSurface(face, fmt1, 0); |
| 376 |
SDL_assert(cvt1 != NULL); |
| 377 |
|
| 378 |
fmt2 = SDL_AllocFormat(pixel_formats[j]); |
| 379 |
SDL_assert(fmt1 != NULL); |
| 380 |
cvt2 = SDL_ConvertSurface(cvt1, fmt2, 0); |
| 381 |
SDL_assert(cvt2 != NULL); |
| 382 |
|
| 383 |
if ( fmt1->BytesPerPixel == face->format->BytesPerPixel && |
| 384 |
fmt2->BytesPerPixel == face->format->BytesPerPixel && |
| 385 |
(fmt1->Amask != 0) == (face->format->Amask != 0) && |
| 386 |
(fmt2->Amask != 0) == (face->format->Amask != 0) ) { |
| 387 |
final = SDL_ConvertSurface( cvt2, face->format, 0 ); |
| 388 |
SDL_assert(final != NULL); |
| 389 |
|
| 390 |
/* Compare surface. */ |
| 391 |
ret = SDLTest_CompareSurfaces(face, final, 0); |
| 392 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 393 |
SDL_FreeSurface(final); |
| 394 |
} |
| 395 |
|
| 396 |
SDL_FreeSurface(cvt1); |
| 397 |
SDL_FreeFormat(fmt1); |
| 398 |
SDL_FreeSurface(cvt2); |
| 399 |
SDL_FreeFormat(fmt2); |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
/* Clean up. */ |
| 404 |
SDL_FreeSurface(face); |
| 405 |
|
| 406 |
return TEST_COMPLETED; |
| 407 |
} |
| 408 |
|
| 409 |
/** |
| 410 |
* @brief Tests sprite loading. A failure case. |
| 411 |
*/ |
| 412 |
int surface_testLoadFailure(void *arg) |
| 413 |
{ |
| 414 |
SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp"); |
| 415 |
SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp"); |
| 416 |
|
| 417 |
return TEST_COMPLETED; |
| 418 |
} |
| 419 |
|
| 420 |
/** |
| 421 |
* @brief Tests some blitting routines. |
| 422 |
*/ |
| 423 |
int surface_testBlit(void *arg) |
| 424 |
{ |
| 425 |
int ret; |
| 426 |
SDL_Surface *compareSurface; |
| 427 |
|
| 428 |
/* Basic blitting */ |
| 429 |
_testBlitBlendMode(-1); |
| 430 |
|
| 431 |
/* Verify result by comparing surfaces */ |
| 432 |
compareSurface = SDLTest_ImageBlit(); |
| 433 |
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0); |
| 434 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 435 |
|
| 436 |
/* Clean up. */ |
| 437 |
SDL_FreeSurface(compareSurface); |
| 438 |
|
| 439 |
return TEST_COMPLETED; |
| 440 |
} |
| 441 |
|
| 442 |
/** |
| 443 |
* @brief Tests some blitting routines with color mod |
| 444 |
*/ |
| 445 |
int surface_testBlitColorMod(void *arg) |
| 446 |
{ |
| 447 |
int ret; |
| 448 |
SDL_Surface *compareSurface; |
| 449 |
|
| 450 |
/* Basic blitting with color mod */ |
| 451 |
_testBlitBlendMode(-2); |
| 452 |
|
| 453 |
/* Verify result by comparing surfaces */ |
| 454 |
compareSurface = SDLTest_ImageBlitColor(); |
| 455 |
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0); |
| 456 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 457 |
|
| 458 |
/* Clean up. */ |
| 459 |
SDL_FreeSurface(compareSurface); |
| 460 |
|
| 461 |
return TEST_COMPLETED; |
| 462 |
} |
| 463 |
|
| 464 |
/** |
| 465 |
* @brief Tests some blitting routines with alpha mod |
| 466 |
*/ |
| 467 |
int surface_testBlitAlphaMod(void *arg) |
| 468 |
{ |
| 469 |
int ret; |
| 470 |
SDL_Surface *compareSurface; |
| 471 |
|
| 472 |
/* Basic blitting with alpha mod */ |
| 473 |
_testBlitBlendMode(-3); |
| 474 |
|
| 475 |
/* Verify result by comparing surfaces */ |
| 476 |
compareSurface = SDLTest_ImageBlitAlpha(); |
| 477 |
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0); |
| 478 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 479 |
|
| 480 |
/* Clean up. */ |
| 481 |
SDL_FreeSurface(compareSurface); |
| 482 |
|
| 483 |
return TEST_COMPLETED; |
| 484 |
} |
| 485 |
|
| 486 |
/** |
| 487 |
* @brief Tests some more blitting routines. |
| 488 |
*/ |
| 489 |
int surface_testBlitBlendNone(void *arg) |
| 490 |
{ |
| 491 |
int ret; |
| 492 |
SDL_Surface *compareSurface; |
| 493 |
|
| 494 |
/* Basic blitting */ |
| 495 |
_testBlitBlendMode(SDL_BLENDMODE_NONE); |
| 496 |
|
| 497 |
/* Verify result by comparing surfaces */ |
| 498 |
compareSurface = SDLTest_ImageBlitBlendNone(); |
| 499 |
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0); |
| 500 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 501 |
|
| 502 |
/* Clean up. */ |
| 503 |
SDL_FreeSurface(compareSurface); |
| 504 |
|
| 505 |
return TEST_COMPLETED; |
| 506 |
} |
| 507 |
|
| 508 |
/** |
| 509 |
* @brief Tests some more blitting routines. |
| 510 |
*/ |
| 511 |
int surface_testBlitBlendBlend(void *arg) |
| 512 |
{ |
| 513 |
int ret; |
| 514 |
SDL_Surface *compareSurface; |
| 515 |
|
| 516 |
/* Blend blitting */ |
| 517 |
_testBlitBlendMode(SDL_BLENDMODE_BLEND); |
| 518 |
|
| 519 |
/* Verify result by comparing surfaces */ |
| 520 |
compareSurface = SDLTest_ImageBlitBlend(); |
| 521 |
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0); |
| 522 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 523 |
|
| 524 |
/* Clean up. */ |
| 525 |
SDL_FreeSurface(compareSurface); |
| 526 |
|
| 527 |
return TEST_COMPLETED; |
| 528 |
} |
| 529 |
|
| 530 |
/** |
| 531 |
* @brief Tests some more blitting routines. |
| 532 |
*/ |
| 533 |
int surface_testBlitBlendAdd(void *arg) |
| 534 |
{ |
| 535 |
int ret; |
| 536 |
SDL_Surface *compareSurface; |
| 537 |
|
| 538 |
/* Add blitting */ |
| 539 |
_testBlitBlendMode(SDL_BLENDMODE_ADD); |
| 540 |
|
| 541 |
/* Verify result by comparing surfaces */ |
| 542 |
compareSurface = SDLTest_ImageBlitBlendAdd(); |
| 543 |
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0); |
| 544 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 545 |
|
| 546 |
/* Clean up. */ |
| 547 |
SDL_FreeSurface(compareSurface); |
| 548 |
|
| 549 |
return TEST_COMPLETED; |
| 550 |
} |
| 551 |
|
| 552 |
/** |
| 553 |
* @brief Tests some more blitting routines. |
| 554 |
*/ |
| 555 |
int surface_testBlitBlendMod(void *arg) |
| 556 |
{ |
| 557 |
int ret; |
| 558 |
SDL_Surface *compareSurface; |
| 559 |
|
| 560 |
/* Mod blitting */ |
| 561 |
_testBlitBlendMode(SDL_BLENDMODE_MOD); |
| 562 |
|
| 563 |
/* Verify result by comparing surfaces */ |
| 564 |
compareSurface = SDLTest_ImageBlitBlendMod(); |
| 565 |
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0); |
| 566 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 567 |
|
| 568 |
/* Clean up. */ |
| 569 |
SDL_FreeSurface(compareSurface); |
| 570 |
|
| 571 |
return TEST_COMPLETED; |
| 572 |
} |
| 573 |
|
| 574 |
/** |
| 575 |
* @brief Tests some more blitting routines with loop |
| 576 |
*/ |
| 577 |
int surface_testBlitBlendLoop(void *arg) |
| 578 |
{ |
| 579 |
|
| 580 |
int ret; |
| 581 |
SDL_Surface *compareSurface; |
| 582 |
|
| 583 |
/* All blitting modes */ |
| 584 |
_testBlitBlendMode(-4); |
| 585 |
|
| 586 |
/* Verify result by comparing surfaces */ |
| 587 |
compareSurface = SDLTest_ImageBlitBlendAll(); |
| 588 |
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0); |
| 589 |
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); |
| 590 |
|
| 591 |
/* Clean up. */ |
| 592 |
SDL_FreeSurface(compareSurface); |
| 593 |
|
| 594 |
return TEST_COMPLETED; |
| 595 |
} |
| 596 |
|
| 597 |
int surface_testOverflow(void *arg) |
| 598 |
{ |
| 599 |
char buf[1024]; |
| 600 |
const char *expectedError; |
| 601 |
SDL_Surface *surface; |
| 602 |
|
| 603 |
SDL_memset(buf, '\0', sizeof(buf)); |
| 604 |
|
| 605 |
expectedError = "Parameter 'width' is invalid"; |
| 606 |
surface = SDL_CreateRGBSurfaceWithFormat(0, -3, 100, 8, SDL_PIXELFORMAT_INDEX8); |
| 607 |
SDLTest_AssertCheck(surface == NULL, "Should detect negative width"); |
| 608 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 609 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 610 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, -1, 1, 8, 4, SDL_PIXELFORMAT_INDEX8); |
| 611 |
SDLTest_AssertCheck(surface == NULL, "Should detect negative width"); |
| 612 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 613 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 614 |
surface = SDL_CreateRGBSurfaceFrom(buf, -1, 1, 32, 4, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); |
| 615 |
SDLTest_AssertCheck(surface == NULL, "Should detect negative width"); |
| 616 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 617 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 618 |
|
| 619 |
expectedError = "Parameter 'height' is invalid"; |
| 620 |
surface = SDL_CreateRGBSurfaceWithFormat(0, 100, -3, 8, SDL_PIXELFORMAT_INDEX8); |
| 621 |
SDLTest_AssertCheck(surface == NULL, "Should detect negative height"); |
| 622 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 623 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 624 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 1, -1, 8, 4, SDL_PIXELFORMAT_INDEX8); |
| 625 |
SDLTest_AssertCheck(surface == NULL, "Should detect negative height"); |
| 626 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 627 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 628 |
surface = SDL_CreateRGBSurfaceFrom(buf, 1, -1, 32, 4, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); |
| 629 |
SDLTest_AssertCheck(surface == NULL, "Should detect negative height"); |
| 630 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 631 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 632 |
|
| 633 |
expectedError = "Parameter 'pitch' is invalid"; |
| 634 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 8, -1, SDL_PIXELFORMAT_INDEX8); |
| 635 |
SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch"); |
| 636 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 637 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 638 |
surface = SDL_CreateRGBSurfaceFrom(buf, 1, 1, 32, -1, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); |
| 639 |
SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch"); |
| 640 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 641 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 642 |
|
| 643 |
/* Less than 1 byte per pixel: the pitch can legitimately be less than |
| 644 |
* the width, but it must be enough to hold the appropriate number of |
| 645 |
* bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */ |
| 646 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 4, 3, SDL_PIXELFORMAT_INDEX4LSB); |
| 647 |
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s", |
| 648 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 649 |
SDL_FreeSurface(surface); |
| 650 |
surface = SDL_CreateRGBSurfaceFrom(buf, 6, 1, 4, 3, 0, 0, 0, 0); |
| 651 |
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s", |
| 652 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 653 |
SDL_FreeSurface(surface); |
| 654 |
|
| 655 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, 3, SDL_PIXELFORMAT_INDEX4LSB); |
| 656 |
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); |
| 657 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 658 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 659 |
surface = SDL_CreateRGBSurfaceFrom(buf, 7, 1, 4, 3, 0, 0, 0, 0); |
| 660 |
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); |
| 661 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 662 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 663 |
|
| 664 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, 4, SDL_PIXELFORMAT_INDEX4LSB); |
| 665 |
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s", |
| 666 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 667 |
SDL_FreeSurface(surface); |
| 668 |
surface = SDL_CreateRGBSurfaceFrom(buf, 7, 1, 4, 4, 0, 0, 0, 0); |
| 669 |
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s", |
| 670 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 671 |
SDL_FreeSurface(surface); |
| 672 |
|
| 673 |
/* SDL_PIXELFORMAT_INDEX2* needs 1 byte per 4 pixels. */ |
| 674 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 12, 1, 2, 3, SDL_PIXELFORMAT_INDEX2LSB); |
| 675 |
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s", |
| 676 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 677 |
SDL_FreeSurface(surface); |
| 678 |
surface = SDL_CreateRGBSurfaceFrom(buf, 12, 1, 2, 3, 0, 0, 0, 0); |
| 679 |
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s", |
| 680 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 681 |
SDL_FreeSurface(surface); |
| 682 |
|
| 683 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 13, 1, 2, 3, SDL_PIXELFORMAT_INDEX2LSB); |
| 684 |
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp (%d)", surface ? surface->pitch : 0); |
| 685 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 686 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 687 |
surface = SDL_CreateRGBSurfaceFrom(buf, 13, 1, 2, 3, 0, 0, 0, 0); |
| 688 |
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); |
| 689 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 690 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 691 |
|
| 692 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 13, 1, 2, 4, SDL_PIXELFORMAT_INDEX2LSB); |
| 693 |
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s", |
| 694 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 695 |
SDL_FreeSurface(surface); |
| 696 |
surface = SDL_CreateRGBSurfaceFrom(buf, 13, 1, 2, 4, 0, 0, 0, 0); |
| 697 |
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s", |
| 698 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 699 |
SDL_FreeSurface(surface); |
| 700 |
|
| 701 |
/* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */ |
| 702 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 16, 1, 1, 2, SDL_PIXELFORMAT_INDEX1LSB); |
| 703 |
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s", |
| 704 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 705 |
SDL_FreeSurface(surface); |
| 706 |
surface = SDL_CreateRGBSurfaceFrom(buf, 16, 1, 1, 2, 0, 0, 0, 0); |
| 707 |
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s", |
| 708 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 709 |
SDL_FreeSurface(surface); |
| 710 |
|
| 711 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 1, 2, SDL_PIXELFORMAT_INDEX1LSB); |
| 712 |
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); |
| 713 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 714 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 715 |
surface = SDL_CreateRGBSurfaceFrom(buf, 17, 1, 1, 2, 0, 0, 0, 0); |
| 716 |
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); |
| 717 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 718 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 719 |
|
| 720 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 1, 3, SDL_PIXELFORMAT_INDEX1LSB); |
| 721 |
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s", |
| 722 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 723 |
SDL_FreeSurface(surface); |
| 724 |
surface = SDL_CreateRGBSurfaceFrom(buf, 17, 1, 1, 3, 0, 0, 0, 0); |
| 725 |
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s", |
| 726 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 727 |
SDL_FreeSurface(surface); |
| 728 |
|
| 729 |
/* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */ |
| 730 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 5, 1, 8, 5, SDL_PIXELFORMAT_RGB332); |
| 731 |
SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s", |
| 732 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 733 |
SDL_FreeSurface(surface); |
| 734 |
surface = SDL_CreateRGBSurfaceFrom(buf, 5, 1, 8, 5, 0, 0, 0, 0); |
| 735 |
SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s", |
| 736 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 737 |
SDL_FreeSurface(surface); |
| 738 |
|
| 739 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 8, 5, SDL_PIXELFORMAT_RGB332); |
| 740 |
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); |
| 741 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 742 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 743 |
surface = SDL_CreateRGBSurfaceFrom(buf, 6, 1, 8, 5, 0, 0, 0, 0); |
| 744 |
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); |
| 745 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 746 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 747 |
|
| 748 |
/* Everything else requires more than 1 byte per pixel, and rounds up |
| 749 |
* each pixel to an integer number of bytes (e.g. RGB555 is really |
| 750 |
* XRGB1555, with 1 bit per pixel wasted). */ |
| 751 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 3, 1, 15, 6, SDL_PIXELFORMAT_RGB555); |
| 752 |
SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s", |
| 753 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 754 |
SDL_FreeSurface(surface); |
| 755 |
surface = SDL_CreateRGBSurfaceFrom(buf, 3, 1, 15, 6, 0, 0, 0, 0); |
| 756 |
SDLTest_AssertCheck(surface != NULL, "5px * 15 (really 16) bits per px fits in 6 bytes: %s", |
| 757 |
surface != NULL ? "(success)" : SDL_GetError()); |
| 758 |
SDL_FreeSurface(surface); |
| 759 |
|
| 760 |
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 15, 6, SDL_PIXELFORMAT_RGB555); |
| 761 |
SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes"); |
| 762 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 763 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 764 |
surface = SDL_CreateRGBSurfaceFrom(buf, 4, 1, 15, 6, 0, 0, 0, 0); |
| 765 |
SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes"); |
| 766 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, |
| 767 |
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); |
| 768 |
|
| 769 |
if (sizeof(size_t) == 4 && sizeof(int) >= 4) { |
| 770 |
SDL_ClearError(); |
| 771 |
/* 0x5555'5555 * 3bpp = 0xffff'ffff which fits in size_t, but adding |
| 772 |
* alignment padding makes it overflow */ |
| 773 |
surface = SDL_CreateRGBSurfaceWithFormat(0, 0x55555555, 1, 24, SDL_PIXELFORMAT_RGB24); |
| 774 |
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width + alignment"); |
| 775 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), "") != 0, "Error indicator should be set"); |
| 776 |
SDL_ClearError(); |
| 777 |
/* 0x4000'0000 * 4bpp = 0x1'0000'0000 which (just) overflows */ |
| 778 |
surface = SDL_CreateRGBSurfaceWithFormat(0, 0x40000000, 1, 32, SDL_PIXELFORMAT_ARGB8888); |
| 779 |
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel"); |
| 780 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), "") != 0, "Error indicator should be set"); |
| 781 |
SDL_ClearError(); |
| 782 |
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 29) - 1, (1 << 29) - 1, 8, SDL_PIXELFORMAT_INDEX8); |
| 783 |
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height"); |
| 784 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), "") != 0, "Error indicator should be set"); |
| 785 |
SDL_ClearError(); |
| 786 |
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 15) + 1, (1 << 15) + 1, 32, SDL_PIXELFORMAT_ARGB8888); |
| 787 |
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel"); |
| 788 |
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), "") != 0, "Error indicator should be set"); |
| 789 |
} else { |
| 790 |
SDLTest_Log("Can't easily overflow size_t on this platform"); |
| 791 |
} |
| 792 |
|
| 793 |
return TEST_COMPLETED; |
| 794 |
} |
| 795 |
|
| 796 |
static int surface_testSetGetClipRect(void *args) |
| 797 |
{ |
| 798 |
const struct { |
| 799 |
SDL_Rect r; |
| 800 |
SDL_bool clipsetval; |
| 801 |
SDL_bool cmpval; |
| 802 |
} rect_list[] = { |
| 803 |
{ { 0, 0, 0, 0}, SDL_FALSE, SDL_TRUE}, |
| 804 |
{ { 2, 2, 0, 0}, SDL_FALSE, SDL_TRUE}, |
| 805 |
{ { 2, 2, 5, 1}, SDL_TRUE, SDL_TRUE}, |
| 806 |
{ { 6, 5, 10, 3}, SDL_TRUE, SDL_FALSE}, |
| 807 |
{ { 0, 0, 10, 10}, SDL_TRUE, SDL_TRUE}, |
| 808 |
{ { 0, 0, -10, 10}, SDL_FALSE, SDL_TRUE}, |
| 809 |
{ { 0, 0, -10, -10}, SDL_FALSE, SDL_TRUE}, |
| 810 |
{ { -10, -10, 10, 10}, SDL_FALSE, SDL_FALSE}, |
| 811 |
{ { 10, -10, 10, 10}, SDL_FALSE, SDL_FALSE}, |
| 812 |
{ { 10, 10, 10, 10}, SDL_TRUE, SDL_FALSE} |
| 813 |
}; |
| 814 |
SDL_Surface *s; |
| 815 |
SDL_Rect r; |
| 816 |
int i; |
| 817 |
|
| 818 |
SDLTest_AssertPass("About to call SDL_CreateRGBSurface(0, 15, 15, 32, 0, 0, 0, 0)"); |
| 819 |
s = SDL_CreateRGBSurface(0, 15, 15, 32, 0, 0, 0, 0); |
| 820 |
SDLTest_AssertCheck(s != NULL, "SDL_CreateRGBSurface returned non-null surface"); |
| 821 |
SDL_zero(r); |
| 822 |
SDL_GetClipRect(s, &r); |
| 823 |
SDLTest_AssertCheck(r.x == 0 && r.y == 0 && r.w == 15 && r.h == 15, |
| 824 |
"SDL_GetClipRect of just-created surface. Got {%d, %d, %d, %d}. (Expected {%d, %d, %d, %d})", |
| 825 |
r.x, r.y, r.w, r.h, 0, 0, 15, 15); |
| 826 |
|
| 827 |
for (i = 0; i < SDL_arraysize(rect_list); i++) { |
| 828 |
SDL_bool b; |
| 829 |
const SDL_Rect *r_in = &rect_list[i].r; |
| 830 |
SDL_Rect r_out; |
| 831 |
|
| 832 |
SDLTest_AssertPass("About to do SDL_SetClipRect({%d, %d, %d, %d})", r_in->x, r_in->y, r_in->w, r_in->h); |
| 833 |
b = SDL_SetClipRect(s, r_in); |
| 834 |
SDLTest_AssertCheck(b == rect_list[i].clipsetval, "SDL_SetClipRect returned %d (expected %d)", b, rect_list[i].clipsetval); |
| 835 |
SDL_zero(r_out); |
| 836 |
SDL_GetClipRect(s, &r_out); |
| 837 |
SDLTest_AssertPass("SDL_GetClipRect returned {%d, %d, %d, %d}", r_out.x, r_out.y, r_out.w, r_out.h); |
| 838 |
b = r_out.x == r_in->x && r_out.y == r_in->y && r_out.w == r_in->w && r_out.h == r_in->h; |
| 839 |
SDLTest_AssertCheck(b == rect_list[i].cmpval, "Current clipping rect is identical to input clipping rect: %d (expected %d)", |
| 840 |
b, rect_list[i].cmpval); |
| 841 |
} |
| 842 |
SDL_FreeSurface(s); |
| 843 |
return TEST_COMPLETED; |
| 844 |
}; |
| 845 |
|
| 846 |
/* ================= Test References ================== */ |
| 847 |
|
| 848 |
/* Surface test cases */ |
| 849 |
static const SDLTest_TestCaseReference surfaceTest1 = { |
| 850 |
(SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED |
| 851 |
}; |
| 852 |
|
| 853 |
static const SDLTest_TestCaseReference surfaceTest2 = { |
| 854 |
(SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED |
| 855 |
}; |
| 856 |
|
| 857 |
static const SDLTest_TestCaseReference surfaceTest3 = { |
| 858 |
(SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED |
| 859 |
}; |
| 860 |
|
| 861 |
static const SDLTest_TestCaseReference surfaceTest4 = { |
| 862 |
(SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED |
| 863 |
}; |
| 864 |
|
| 865 |
static const SDLTest_TestCaseReference surfaceTest5 = { |
| 866 |
(SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED |
| 867 |
}; |
| 868 |
|
| 869 |
static const SDLTest_TestCaseReference surfaceTest6 = { |
| 870 |
(SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED |
| 871 |
}; |
| 872 |
|
| 873 |
static const SDLTest_TestCaseReference surfaceTest7 = { |
| 874 |
(SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED |
| 875 |
}; |
| 876 |
|
| 877 |
static const SDLTest_TestCaseReference surfaceTest8 = { |
| 878 |
(SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED |
| 879 |
}; |
| 880 |
|
| 881 |
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */ |
| 882 |
static const SDLTest_TestCaseReference surfaceTest9 = { |
| 883 |
(SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blitting routines with various blending modes", TEST_DISABLED |
| 884 |
}; |
| 885 |
|
| 886 |
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */ |
| 887 |
static const SDLTest_TestCaseReference surfaceTest10 = { |
| 888 |
(SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED |
| 889 |
}; |
| 890 |
|
| 891 |
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */ |
| 892 |
static const SDLTest_TestCaseReference surfaceTest11 = { |
| 893 |
(SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED |
| 894 |
}; |
| 895 |
|
| 896 |
static const SDLTest_TestCaseReference surfaceTest12 = { |
| 897 |
(SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED |
| 898 |
}; |
| 899 |
|
| 900 |
static const SDLTest_TestCaseReference surfaceTestOverflow = { |
| 901 |
surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED |
| 902 |
}; |
| 903 |
|
| 904 |
static const SDLTest_TestCaseReference surfaceTestSetGetClipRect = { |
| 905 |
surface_testSetGetClipRect, "surface_testSetGetClipRect", "Test SDL_(Set|Get)ClipRect.", TEST_ENABLED |
| 906 |
}; |
| 907 |
|
| 908 |
/* Sequence of Surface test cases */ |
| 909 |
static const SDLTest_TestCaseReference *surfaceTests[] = { |
| 910 |
&surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5, |
| 911 |
&surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10, |
| 912 |
&surfaceTest11, &surfaceTest12, &surfaceTestOverflow, |
| 913 |
&surfaceTestSetGetClipRect, |
| 914 |
NULL |
| 915 |
}; |
| 916 |
|
| 917 |
/* Surface test suite (global) */ |
| 918 |
SDLTest_TestSuiteReference surfaceTestSuite = { |
| 919 |
"Surface", |
| 920 |
_surfaceSetUp, |
| 921 |
surfaceTests, |
| 922 |
_surfaceTearDown |
| 923 |
|
| 924 |
}; |