testautomation_surface.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /**
  2. * Original code: automated SDL surface test written by Edgar Simo "bobbens"
  3. * Adapted/rewritten for test lib by Andreas Schiffler
  4. */
  5. /* Supress C4996 VS compiler warnings for unlink() */
  6. #define _CRT_SECURE_NO_DEPRECATE
  7. #define _CRT_NONSTDC_NO_DEPRECATE
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. #include <sys/stat.h>
  11. #include "SDL.h"
  12. #include "SDL_test.h"
  13. #ifdef __MACOSX__
  14. #include <unistd.h> /* For unlink() */
  15. #endif
  16. /* ================= Test Case Implementation ================== */
  17. /* Shared test surface */
  18. static SDL_Surface *referenceSurface = NULL;
  19. static SDL_Surface *testSurface = NULL;
  20. /* Helper functions for the test cases */
  21. #define TEST_SURFACE_WIDTH testSurface->w
  22. #define TEST_SURFACE_HEIGHT testSurface->h
  23. /* Fixture */
  24. /* Create a 32-bit writable surface for blitting tests */
  25. void
  26. _surfaceSetUp(void *arg)
  27. {
  28. int result;
  29. SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
  30. SDL_BlendMode currentBlendMode;
  31. Uint32 rmask, gmask, bmask, amask;
  32. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  33. rmask = 0xff000000;
  34. gmask = 0x00ff0000;
  35. bmask = 0x0000ff00;
  36. amask = 0x000000ff;
  37. #else
  38. rmask = 0x000000ff;
  39. gmask = 0x0000ff00;
  40. bmask = 0x00ff0000;
  41. amask = 0xff000000;
  42. #endif
  43. referenceSurface = SDLTest_ImageBlit(); /* For size info */
  44. testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
  45. SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
  46. if (testSurface != NULL) {
  47. /* Disable blend mode for target surface */
  48. result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
  49. SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
  50. result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
  51. SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
  52. SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);
  53. }
  54. }
  55. void
  56. _surfaceTearDown(void *arg)
  57. {
  58. SDL_FreeSurface(referenceSurface);
  59. referenceSurface = NULL;
  60. SDL_FreeSurface(testSurface);
  61. testSurface = NULL;
  62. }
  63. /**
  64. * Helper that clears the test surface
  65. */
  66. void _clearTestSurface()
  67. {
  68. int ret;
  69. Uint32 color;
  70. /* Clear surface. */
  71. color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
  72. SDLTest_AssertPass("Call to SDL_MapRGBA()");
  73. ret = SDL_FillRect( testSurface, NULL, color);
  74. SDLTest_AssertPass("Call to SDL_FillRect()");
  75. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
  76. }
  77. /**
  78. * 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.
  79. */
  80. void _testBlitBlendMode(int mode)
  81. {
  82. int ret;
  83. int i, j, ni, nj;
  84. SDL_Surface *face;
  85. SDL_Rect rect;
  86. int nmode;
  87. SDL_BlendMode bmode;
  88. int checkFailCount1;
  89. int checkFailCount2;
  90. int checkFailCount3;
  91. int checkFailCount4;
  92. /* Check test surface */
  93. SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL");
  94. if (testSurface == NULL) return;
  95. /* Create sample surface */
  96. face = SDLTest_ImageFace();
  97. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  98. if (face == NULL) return;
  99. /* Reset alpha modulation */
  100. ret = SDL_SetSurfaceAlphaMod(face, 255);
  101. SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
  102. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
  103. /* Reset color modulation */
  104. ret = SDL_SetSurfaceColorMod(face, 255, 255, 255);
  105. SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
  106. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
  107. /* Reset color key */
  108. ret = SDL_SetColorKey(face, SDL_FALSE, 0);
  109. SDLTest_AssertPass("Call to SDL_SetColorKey()");
  110. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret);
  111. /* Clear the test surface */
  112. _clearTestSurface();
  113. /* Target rect size */
  114. rect.w = face->w;
  115. rect.h = face->h;
  116. /* Steps to take */
  117. ni = testSurface->w - face->w;
  118. nj = testSurface->h - face->h;
  119. /* Optionally set blend mode. */
  120. if (mode >= 0) {
  121. ret = SDL_SetSurfaceBlendMode( face, (SDL_BlendMode)mode );
  122. SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
  123. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret);
  124. }
  125. /* Test blend mode. */
  126. checkFailCount1 = 0;
  127. checkFailCount2 = 0;
  128. checkFailCount3 = 0;
  129. checkFailCount4 = 0;
  130. for (j=0; j <= nj; j+=4) {
  131. for (i=0; i <= ni; i+=4) {
  132. if (mode == -2) {
  133. /* Set color mod. */
  134. ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
  135. if (ret != 0) checkFailCount2++;
  136. }
  137. else if (mode == -3) {
  138. /* Set alpha mod. */
  139. ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
  140. if (ret != 0) checkFailCount3++;
  141. }
  142. else if (mode == -4) {
  143. /* Crazy blending mode magic. */
  144. nmode = (i/4*j/4) % 4;
  145. if (nmode==0) {
  146. bmode = SDL_BLENDMODE_NONE;
  147. } else if (nmode==1) {
  148. bmode = SDL_BLENDMODE_BLEND;
  149. } else if (nmode==2) {
  150. bmode = SDL_BLENDMODE_ADD;
  151. } else if (nmode==3) {
  152. bmode = SDL_BLENDMODE_MOD;
  153. }
  154. ret = SDL_SetSurfaceBlendMode( face, bmode );
  155. if (ret != 0) checkFailCount4++;
  156. }
  157. /* Blitting. */
  158. rect.x = i;
  159. rect.y = j;
  160. ret = SDL_BlitSurface( face, NULL, testSurface, &rect );
  161. if (ret != 0) checkFailCount1++;
  162. }
  163. }
  164. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1);
  165. SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", checkFailCount2);
  166. SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 0, got: %i", checkFailCount3);
  167. SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
  168. /* Clean up */
  169. SDL_FreeSurface(face);
  170. face = NULL;
  171. }
  172. /* Helper to check that a file exists */
  173. void
  174. _AssertFileExist(const char *filename)
  175. {
  176. struct stat st;
  177. int ret = stat(filename, &st);
  178. SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
  179. }
  180. /* Test case functions */
  181. /**
  182. * @brief Tests sprite saving and loading
  183. */
  184. int
  185. surface_testSaveLoadBitmap(void *arg)
  186. {
  187. int ret;
  188. const char *sampleFilename = "testSaveLoadBitmap.bmp";
  189. SDL_Surface *face;
  190. SDL_Surface *rface;
  191. /* Create sample surface */
  192. face = SDLTest_ImageFace();
  193. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  194. if (face == NULL) return TEST_ABORTED;
  195. /* Delete test file; ignore errors */
  196. unlink(sampleFilename);
  197. /* Save a surface */
  198. ret = SDL_SaveBMP(face, sampleFilename);
  199. SDLTest_AssertPass("Call to SDL_SaveBMP()");
  200. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret);
  201. _AssertFileExist(sampleFilename);
  202. /* Load a surface */
  203. rface = SDL_LoadBMP(sampleFilename);
  204. SDLTest_AssertPass("Call to SDL_LoadBMP()");
  205. SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
  206. if (rface != NULL) {
  207. SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
  208. SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
  209. }
  210. /* Delete test file; ignore errors */
  211. unlink(sampleFilename);
  212. /* Clean up */
  213. SDL_FreeSurface(face);
  214. face = NULL;
  215. SDL_FreeSurface(rface);
  216. rface = NULL;
  217. return TEST_COMPLETED;
  218. }
  219. /* !
  220. * Tests surface conversion.
  221. */
  222. int
  223. surface_testSurfaceConversion(void *arg)
  224. {
  225. SDL_Surface *rface = NULL, *face = NULL;
  226. int ret = 0;
  227. /* Create sample surface */
  228. face = SDLTest_ImageFace();
  229. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  230. if (face == NULL)
  231. return TEST_ABORTED;
  232. /* Set transparent pixel as the pixel at (0,0) */
  233. if (face->format->palette) {
  234. ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
  235. SDLTest_AssertPass("Call to SDL_SetColorKey()");
  236. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
  237. }
  238. /* Convert to 32 bit to compare. */
  239. rface = SDL_ConvertSurface( face, testSurface->format, 0 );
  240. SDLTest_AssertPass("Call to SDL_ConvertSurface()");
  241. SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
  242. /* Compare surface. */
  243. ret = SDLTest_CompareSurfaces( rface, face, 0 );
  244. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  245. /* Clean up. */
  246. SDL_FreeSurface(face);
  247. face = NULL;
  248. SDL_FreeSurface(rface);
  249. rface = NULL;
  250. return TEST_COMPLETED;
  251. }
  252. /* !
  253. * Tests surface conversion across all pixel formats.
  254. */
  255. int
  256. surface_testCompleteSurfaceConversion(void *arg)
  257. {
  258. Uint32 pixel_formats[] = {
  259. SDL_PIXELFORMAT_INDEX8,
  260. SDL_PIXELFORMAT_RGB332,
  261. SDL_PIXELFORMAT_RGB444,
  262. SDL_PIXELFORMAT_RGB555,
  263. SDL_PIXELFORMAT_BGR555,
  264. SDL_PIXELFORMAT_ARGB4444,
  265. SDL_PIXELFORMAT_RGBA4444,
  266. SDL_PIXELFORMAT_ABGR4444,
  267. SDL_PIXELFORMAT_BGRA4444,
  268. SDL_PIXELFORMAT_ARGB1555,
  269. SDL_PIXELFORMAT_RGBA5551,
  270. SDL_PIXELFORMAT_ABGR1555,
  271. SDL_PIXELFORMAT_BGRA5551,
  272. SDL_PIXELFORMAT_RGB565,
  273. SDL_PIXELFORMAT_BGR565,
  274. SDL_PIXELFORMAT_RGB24,
  275. SDL_PIXELFORMAT_BGR24,
  276. SDL_PIXELFORMAT_RGB888,
  277. SDL_PIXELFORMAT_RGBX8888,
  278. SDL_PIXELFORMAT_BGR888,
  279. SDL_PIXELFORMAT_BGRX8888,
  280. SDL_PIXELFORMAT_ARGB8888,
  281. SDL_PIXELFORMAT_RGBA8888,
  282. SDL_PIXELFORMAT_ABGR8888,
  283. SDL_PIXELFORMAT_BGRA8888,
  284. SDL_PIXELFORMAT_ARGB2101010,
  285. };
  286. SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
  287. SDL_PixelFormat *fmt1, *fmt2;
  288. int i, j, ret = 0;
  289. /* Create sample surface */
  290. face = SDLTest_ImageFace();
  291. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  292. if (face == NULL)
  293. return TEST_ABORTED;
  294. /* Set transparent pixel as the pixel at (0,0) */
  295. if (face->format->palette) {
  296. ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
  297. SDLTest_AssertPass("Call to SDL_SetColorKey()");
  298. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
  299. }
  300. for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
  301. for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
  302. fmt1 = SDL_AllocFormat(pixel_formats[i]);
  303. SDL_assert(fmt1 != NULL);
  304. cvt1 = SDL_ConvertSurface(face, fmt1, 0);
  305. SDL_assert(cvt1 != NULL);
  306. fmt2 = SDL_AllocFormat(pixel_formats[j]);
  307. SDL_assert(fmt1 != NULL);
  308. cvt2 = SDL_ConvertSurface(cvt1, fmt2, 0);
  309. SDL_assert(cvt2 != NULL);
  310. if ( fmt1->BytesPerPixel == face->format->BytesPerPixel &&
  311. fmt2->BytesPerPixel == face->format->BytesPerPixel &&
  312. (fmt1->Amask != 0) == (face->format->Amask != 0) &&
  313. (fmt2->Amask != 0) == (face->format->Amask != 0) ) {
  314. final = SDL_ConvertSurface( cvt2, face->format, 0 );
  315. SDL_assert(final != NULL);
  316. /* Compare surface. */
  317. ret = SDLTest_CompareSurfaces( face, final, 0 );
  318. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  319. SDL_FreeSurface(final);
  320. }
  321. SDL_FreeSurface(cvt1);
  322. SDL_FreeFormat(fmt1);
  323. SDL_FreeSurface(cvt2);
  324. SDL_FreeFormat(fmt2);
  325. }
  326. }
  327. /* Clean up. */
  328. SDL_FreeSurface( face );
  329. return TEST_COMPLETED;
  330. }
  331. /**
  332. * @brief Tests sprite loading. A failure case.
  333. */
  334. int
  335. surface_testLoadFailure(void *arg)
  336. {
  337. SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
  338. SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
  339. return TEST_COMPLETED;
  340. }
  341. /**
  342. * @brief Tests some blitting routines.
  343. */
  344. int
  345. surface_testBlit(void *arg)
  346. {
  347. int ret;
  348. SDL_Surface *compareSurface;
  349. /* Basic blitting */
  350. _testBlitBlendMode(-1);
  351. /* Verify result by comparing surfaces */
  352. compareSurface = SDLTest_ImageBlit();
  353. ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
  354. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  355. /* Clean up. */
  356. SDL_FreeSurface(compareSurface);
  357. return TEST_COMPLETED;
  358. }
  359. /**
  360. * @brief Tests some blitting routines with color mod
  361. */
  362. int
  363. surface_testBlitColorMod(void *arg)
  364. {
  365. int ret;
  366. SDL_Surface *compareSurface;
  367. /* Basic blitting with color mod */
  368. _testBlitBlendMode(-2);
  369. /* Verify result by comparing surfaces */
  370. compareSurface = SDLTest_ImageBlitColor();
  371. ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
  372. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  373. /* Clean up. */
  374. SDL_FreeSurface(compareSurface);
  375. return TEST_COMPLETED;
  376. }
  377. /**
  378. * @brief Tests some blitting routines with alpha mod
  379. */
  380. int
  381. surface_testBlitAlphaMod(void *arg)
  382. {
  383. int ret;
  384. SDL_Surface *compareSurface;
  385. /* Basic blitting with alpha mod */
  386. _testBlitBlendMode(-3);
  387. /* Verify result by comparing surfaces */
  388. compareSurface = SDLTest_ImageBlitAlpha();
  389. ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
  390. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  391. /* Clean up. */
  392. SDL_FreeSurface(compareSurface);
  393. return TEST_COMPLETED;
  394. }
  395. /**
  396. * @brief Tests some more blitting routines.
  397. */
  398. int
  399. surface_testBlitBlendNone(void *arg)
  400. {
  401. int ret;
  402. SDL_Surface *compareSurface;
  403. /* Basic blitting */
  404. _testBlitBlendMode(SDL_BLENDMODE_NONE);
  405. /* Verify result by comparing surfaces */
  406. compareSurface = SDLTest_ImageBlitBlendNone();
  407. ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
  408. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  409. /* Clean up. */
  410. SDL_FreeSurface(compareSurface);
  411. return TEST_COMPLETED;
  412. }
  413. /**
  414. * @brief Tests some more blitting routines.
  415. */
  416. int
  417. surface_testBlitBlendBlend(void *arg)
  418. {
  419. int ret;
  420. SDL_Surface *compareSurface;
  421. /* Blend blitting */
  422. _testBlitBlendMode(SDL_BLENDMODE_BLEND);
  423. /* Verify result by comparing surfaces */
  424. compareSurface = SDLTest_ImageBlitBlend();
  425. ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
  426. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  427. /* Clean up. */
  428. SDL_FreeSurface(compareSurface);
  429. return TEST_COMPLETED;
  430. }
  431. /**
  432. * @brief Tests some more blitting routines.
  433. */
  434. int
  435. surface_testBlitBlendAdd(void *arg)
  436. {
  437. int ret;
  438. SDL_Surface *compareSurface;
  439. /* Add blitting */
  440. _testBlitBlendMode(SDL_BLENDMODE_ADD);
  441. /* Verify result by comparing surfaces */
  442. compareSurface = SDLTest_ImageBlitBlendAdd();
  443. ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
  444. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  445. /* Clean up. */
  446. SDL_FreeSurface(compareSurface);
  447. return TEST_COMPLETED;
  448. }
  449. /**
  450. * @brief Tests some more blitting routines.
  451. */
  452. int
  453. surface_testBlitBlendMod(void *arg)
  454. {
  455. int ret;
  456. SDL_Surface *compareSurface;
  457. /* Mod blitting */
  458. _testBlitBlendMode(SDL_BLENDMODE_MOD);
  459. /* Verify result by comparing surfaces */
  460. compareSurface = SDLTest_ImageBlitBlendMod();
  461. ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
  462. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  463. /* Clean up. */
  464. SDL_FreeSurface(compareSurface);
  465. return TEST_COMPLETED;
  466. }
  467. /**
  468. * @brief Tests some more blitting routines with loop
  469. */
  470. int
  471. surface_testBlitBlendLoop(void *arg) {
  472. int ret;
  473. SDL_Surface *compareSurface;
  474. /* All blitting modes */
  475. _testBlitBlendMode(-4);
  476. /* Verify result by comparing surfaces */
  477. compareSurface = SDLTest_ImageBlitBlendAll();
  478. ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
  479. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  480. /* Clean up. */
  481. SDL_FreeSurface(compareSurface);
  482. return TEST_COMPLETED;
  483. }
  484. /* ================= Test References ================== */
  485. /* Surface test cases */
  486. static const SDLTest_TestCaseReference surfaceTest1 =
  487. { (SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED};
  488. static const SDLTest_TestCaseReference surfaceTest2 =
  489. { (SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED};
  490. static const SDLTest_TestCaseReference surfaceTest3 =
  491. { (SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED};
  492. static const SDLTest_TestCaseReference surfaceTest4 =
  493. { (SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED};
  494. static const SDLTest_TestCaseReference surfaceTest5 =
  495. { (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
  496. static const SDLTest_TestCaseReference surfaceTest6 =
  497. { (SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED};
  498. static const SDLTest_TestCaseReference surfaceTest7 =
  499. { (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
  500. static const SDLTest_TestCaseReference surfaceTest8 =
  501. { (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
  502. /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
  503. static const SDLTest_TestCaseReference surfaceTest9 =
  504. { (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blitting routines with various blending modes", TEST_DISABLED};
  505. /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
  506. static const SDLTest_TestCaseReference surfaceTest10 =
  507. { (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED};
  508. /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
  509. static const SDLTest_TestCaseReference surfaceTest11 =
  510. { (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED};
  511. static const SDLTest_TestCaseReference surfaceTest12 =
  512. { (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
  513. /* Sequence of Surface test cases */
  514. static const SDLTest_TestCaseReference *surfaceTests[] = {
  515. &surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
  516. &surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
  517. &surfaceTest11, &surfaceTest12, NULL
  518. };
  519. /* Surface test suite (global) */
  520. SDLTest_TestSuiteReference surfaceTestSuite = {
  521. "Surface",
  522. _surfaceSetUp,
  523. surfaceTests,
  524. _surfaceTearDown
  525. };