testautomation_surface.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. /**
  2. * Original code: automated SDL surface test written by Edgar Simo "bobbens"
  3. * Adapted/rewritten for test lib by Andreas Schiffler
  4. */
  5. /* Suppress C4996 VS compiler warnings for unlink() */
  6. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
  7. #define _CRT_SECURE_NO_DEPRECATE
  8. #endif
  9. #if defined(_MSC_VER) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
  10. #define _CRT_NONSTDC_NO_DEPRECATE
  11. #endif
  12. #include <stdio.h>
  13. #ifndef _MSC_VER
  14. #include <unistd.h>
  15. #endif
  16. #include <sys/stat.h>
  17. #include <SDL3/SDL.h>
  18. #include <SDL3/SDL_test.h>
  19. #include "testautomation_suites.h"
  20. #include "testautomation_images.h"
  21. #define CHECK_FUNC(FUNC, PARAMS) \
  22. { \
  23. int result = FUNC PARAMS; \
  24. if (result != 0) { \
  25. SDLTest_AssertCheck(result == 0, "Validate result from %s, expected: 0, got: %i, %s", #FUNC, result, SDL_GetError()); \
  26. } \
  27. }
  28. /* ================= Test Case Implementation ================== */
  29. /* Shared test surface */
  30. static SDL_Surface *referenceSurface = NULL;
  31. static SDL_Surface *testSurface = NULL;
  32. /* Fixture */
  33. /* Create a 32-bit writable surface for blitting tests */
  34. static void surfaceSetUp(void *arg)
  35. {
  36. int result;
  37. SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
  38. SDL_BlendMode currentBlendMode;
  39. referenceSurface = SDLTest_ImageBlit(); /* For size info */
  40. testSurface = SDL_CreateSurface(referenceSurface->w, referenceSurface->h, SDL_PIXELFORMAT_RGBA32);
  41. SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
  42. if (testSurface != NULL) {
  43. /* Disable blend mode for target surface */
  44. result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
  45. SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
  46. result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
  47. SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
  48. SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, blendMode, currentBlendMode);
  49. /* Clear the target surface */
  50. result = SDL_FillSurfaceRect(testSurface, NULL, SDL_MapSurfaceRGBA(testSurface, 0, 0, 0, 255));
  51. SDLTest_AssertCheck(result == 0, "Validate result from SDL_FillSurfaceRect, expected: 0, got: %i", result);
  52. }
  53. }
  54. static void surfaceTearDown(void *arg)
  55. {
  56. SDL_DestroySurface(referenceSurface);
  57. referenceSurface = NULL;
  58. SDL_DestroySurface(testSurface);
  59. testSurface = NULL;
  60. }
  61. static void DitherPalette(SDL_Palette *palette)
  62. {
  63. int i;
  64. for (i = 0; i < palette->ncolors; i++) {
  65. int r, g, b;
  66. /* map each bit field to the full [0, 255] interval,
  67. so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */
  68. r = i & 0xe0;
  69. r |= r >> 3 | r >> 6;
  70. palette->colors[i].r = (Uint8)r;
  71. g = (i << 3) & 0xe0;
  72. g |= g >> 3 | g >> 6;
  73. palette->colors[i].g = (Uint8)g;
  74. b = i & 0x3;
  75. b |= b << 2;
  76. b |= b << 4;
  77. palette->colors[i].b = (Uint8)b;
  78. palette->colors[i].a = SDL_ALPHA_OPAQUE;
  79. }
  80. }
  81. /**
  82. * Helper that blits in a specific blend mode, -1 for color mod, -2 for alpha mod
  83. */
  84. static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, SDL_PixelFormat dst_format)
  85. {
  86. /* Allow up to 1 delta from theoretical value to account for rounding error */
  87. const int MAXIMUM_ERROR = 1;
  88. int ret;
  89. SDL_Surface *src;
  90. SDL_Surface *dst;
  91. Uint32 color;
  92. Uint8 srcR = 10, srcG = 128, srcB = 240, srcA = 100;
  93. Uint8 dstR = 128, dstG = 128, dstB = 128, dstA = 128;
  94. Uint8 expectedR, expectedG, expectedB, expectedA;
  95. Uint8 actualR, actualG, actualB, actualA;
  96. int deltaR, deltaG, deltaB, deltaA;
  97. /* Create dst surface */
  98. dst = SDL_CreateSurface(1, 1, dst_format);
  99. SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL");
  100. if (dst == NULL) {
  101. return;
  102. }
  103. /* Clear surface. */
  104. if (SDL_ISPIXELFORMAT_INDEXED(dst_format)) {
  105. SDL_Palette *palette = SDL_CreateSurfacePalette(dst);
  106. DitherPalette(palette);
  107. palette->colors[0].r = dstR;
  108. palette->colors[0].g = dstG;
  109. palette->colors[0].b = dstB;
  110. palette->colors[0].a = dstA;
  111. color = 0;
  112. } else {
  113. color = SDL_MapSurfaceRGBA(dst, dstR, dstG, dstB, dstA);
  114. SDLTest_AssertPass("Call to SDL_MapSurfaceRGBA()");
  115. }
  116. ret = SDL_FillSurfaceRect(dst, NULL, color);
  117. SDLTest_AssertPass("Call to SDL_FillSurfaceRect()");
  118. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillSurfaceRect, expected: 0, got: %i", ret);
  119. SDL_GetRGBA(color, SDL_GetPixelFormatDetails(dst->format), SDL_GetSurfacePalette(dst), &dstR, &dstG, &dstB, &dstA);
  120. /* Create src surface */
  121. src = SDL_CreateSurface(1, 1, src_format);
  122. SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL");
  123. if (src == NULL) {
  124. return;
  125. }
  126. if (SDL_ISPIXELFORMAT_INDEXED(src_format)) {
  127. SDL_Palette *palette = SDL_CreateSurfacePalette(src);
  128. palette->colors[0].r = srcR;
  129. palette->colors[0].g = srcG;
  130. palette->colors[0].b = srcB;
  131. palette->colors[0].a = srcA;
  132. }
  133. /* Reset alpha modulation */
  134. ret = SDL_SetSurfaceAlphaMod(src, 255);
  135. SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
  136. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
  137. /* Reset color modulation */
  138. ret = SDL_SetSurfaceColorMod(src, 255, 255, 255);
  139. SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
  140. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
  141. /* Reset color key */
  142. ret = SDL_SetSurfaceColorKey(src, SDL_FALSE, 0);
  143. SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
  144. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorKey(), expected: 0, got: %i", ret);
  145. /* Clear surface. */
  146. color = SDL_MapSurfaceRGBA(src, srcR, srcG, srcB, srcA);
  147. SDLTest_AssertPass("Call to SDL_MapSurfaceRGBA()");
  148. ret = SDL_FillSurfaceRect(src, NULL, color);
  149. SDLTest_AssertPass("Call to SDL_FillSurfaceRect()");
  150. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillSurfaceRect, expected: 0, got: %i", ret);
  151. SDL_GetRGBA(color, SDL_GetPixelFormatDetails(src->format), SDL_GetSurfacePalette(src), &srcR, &srcG, &srcB, &srcA);
  152. /* Set blend mode. */
  153. if (mode >= 0) {
  154. ret = SDL_SetSurfaceBlendMode(src, (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. } else {
  158. ret = SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND);
  159. SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
  160. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret);
  161. }
  162. /* Test blend mode. */
  163. #define FLOAT(X) ((float)X / 255.0f)
  164. switch (mode) {
  165. case -1:
  166. /* Set color mod. */
  167. ret = SDL_SetSurfaceColorMod(src, srcR, srcG, srcB);
  168. SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", ret);
  169. expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  170. expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  171. expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  172. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  173. break;
  174. case -2:
  175. /* Set alpha mod. */
  176. ret = SDL_SetSurfaceAlphaMod(src, srcA);
  177. SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 0, got: %i", ret);
  178. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstR) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  179. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstG) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  180. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstB) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  181. expectedA = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstA) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  182. break;
  183. case SDL_BLENDMODE_NONE:
  184. expectedR = srcR;
  185. expectedG = srcG;
  186. expectedB = srcB;
  187. expectedA = SDL_ISPIXELFORMAT_ALPHA(dst_format) ? srcA : 255;
  188. break;
  189. case SDL_BLENDMODE_BLEND:
  190. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  191. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  192. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  193. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  194. break;
  195. case SDL_BLENDMODE_BLEND_PREMULTIPLIED:
  196. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  197. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  198. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  199. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  200. break;
  201. case SDL_BLENDMODE_ADD:
  202. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  203. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  204. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  205. expectedA = dstA;
  206. break;
  207. case SDL_BLENDMODE_ADD_PREMULTIPLIED:
  208. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  209. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  210. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  211. expectedA = dstA;
  212. break;
  213. case SDL_BLENDMODE_MOD:
  214. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  215. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  216. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  217. expectedA = dstA;
  218. break;
  219. case SDL_BLENDMODE_MUL:
  220. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  221. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  222. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  223. expectedA = dstA;
  224. break;
  225. default:
  226. SDLTest_LogError("Invalid blending mode: %d", mode);
  227. return;
  228. }
  229. if (SDL_ISPIXELFORMAT_INDEXED(dst_format)) {
  230. SDL_Palette *palette = SDL_GetSurfacePalette(dst);
  231. palette->colors[1].r = expectedR;
  232. palette->colors[1].g = expectedG;
  233. palette->colors[1].b = expectedB;
  234. palette->colors[1].a = expectedA;
  235. }
  236. /* Blitting. */
  237. ret = SDL_BlitSurface(src, NULL, dst, NULL);
  238. SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i: %s", ret, (ret < 0) ? SDL_GetError() : "success");
  239. if (ret == 0) {
  240. SDL_ReadSurfacePixel(dst, 0, 0, &actualR, &actualG, &actualB, &actualA);
  241. deltaR = SDL_abs((int)actualR - expectedR);
  242. deltaG = SDL_abs((int)actualG - expectedG);
  243. deltaB = SDL_abs((int)actualB - expectedB);
  244. deltaA = SDL_abs((int)actualA - expectedA);
  245. SDLTest_AssertCheck(
  246. deltaR <= MAXIMUM_ERROR &&
  247. deltaG <= MAXIMUM_ERROR &&
  248. deltaB <= MAXIMUM_ERROR &&
  249. deltaA <= MAXIMUM_ERROR,
  250. "Checking %s -> %s blit results, expected %d,%d,%d,%d, got %d,%d,%d,%d",
  251. SDL_GetPixelFormatName(src_format),
  252. SDL_GetPixelFormatName(dst_format),
  253. expectedR, expectedG, expectedB, expectedA, actualR, actualG, actualB, actualA);
  254. }
  255. /* Clean up */
  256. SDL_DestroySurface(src);
  257. SDL_DestroySurface(dst);
  258. }
  259. static void testBlitBlendMode(int mode)
  260. {
  261. const SDL_PixelFormat src_formats[] = {
  262. SDL_PIXELFORMAT_INDEX8, SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
  263. };
  264. const SDL_PixelFormat dst_formats[] = {
  265. SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
  266. };
  267. int i, j;
  268. for (i = 0; i < SDL_arraysize(src_formats); ++i) {
  269. for (j = 0; j < SDL_arraysize(dst_formats); ++j) {
  270. testBlitBlendModeWithFormats(mode, src_formats[i], dst_formats[j]);
  271. }
  272. }
  273. }
  274. /* Helper to check that a file exists */
  275. static void AssertFileExist(const char *filename)
  276. {
  277. struct stat st;
  278. int ret = stat(filename, &st);
  279. SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
  280. }
  281. /* Test case functions */
  282. /**
  283. * Tests sprite saving and loading
  284. */
  285. static int surface_testSaveLoadBitmap(void *arg)
  286. {
  287. int ret;
  288. const char *sampleFilename = "testSaveLoadBitmap.bmp";
  289. SDL_Surface *face;
  290. SDL_Surface *rface;
  291. /* Create sample surface */
  292. face = SDLTest_ImageFace();
  293. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  294. if (face == NULL) {
  295. return TEST_ABORTED;
  296. }
  297. /* Delete test file; ignore errors */
  298. unlink(sampleFilename);
  299. /* Save a surface */
  300. ret = SDL_SaveBMP(face, sampleFilename);
  301. SDLTest_AssertPass("Call to SDL_SaveBMP()");
  302. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret);
  303. AssertFileExist(sampleFilename);
  304. /* Load a surface */
  305. rface = SDL_LoadBMP(sampleFilename);
  306. SDLTest_AssertPass("Call to SDL_LoadBMP()");
  307. SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
  308. if (rface != NULL) {
  309. SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
  310. SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
  311. }
  312. /* Delete test file; ignore errors */
  313. unlink(sampleFilename);
  314. /* Clean up */
  315. SDL_DestroySurface(face);
  316. face = NULL;
  317. SDL_DestroySurface(rface);
  318. rface = NULL;
  319. return TEST_COMPLETED;
  320. }
  321. /**
  322. * Tests tiled blitting.
  323. */
  324. static int surface_testBlitTiled(void *arg)
  325. {
  326. SDL_Surface *face = NULL;
  327. SDL_Surface *testSurface2x = NULL;
  328. SDL_Surface *referenceSurface2x = NULL;
  329. int ret = 0;
  330. /* Create sample surface */
  331. face = SDLTest_ImageFace();
  332. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  333. if (face == NULL) {
  334. return TEST_ABORTED;
  335. }
  336. /* Tiled blit - 1.0 scale */
  337. {
  338. ret = SDL_BlitSurfaceTiled(face, NULL, testSurface, NULL);
  339. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_BlitSurfaceTiled expected: 0, got: %i", ret);
  340. /* See if it's the same */
  341. SDL_DestroySurface(referenceSurface);
  342. referenceSurface = SDLTest_ImageBlitTiled();
  343. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  344. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  345. }
  346. /* Tiled blit - 2.0 scale */
  347. {
  348. testSurface2x = SDL_CreateSurface(testSurface->w * 2, testSurface->h * 2, testSurface->format);
  349. SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface2x is not NULL");
  350. ret = SDL_FillSurfaceRect(testSurface2x, NULL, SDL_MapSurfaceRGBA(testSurface2x, 0, 0, 0, 255));
  351. SDLTest_AssertCheck(ret == 0, "Validate result from SDL_FillSurfaceRect, expected: 0, got: %i", ret);
  352. ret = SDL_BlitSurfaceTiledWithScale(face, NULL, 2.0f, SDL_SCALEMODE_NEAREST, testSurface2x, NULL);
  353. SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTextureTiled, expected: 0, got: %i", ret);
  354. /* See if it's the same */
  355. referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format);
  356. SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST);
  357. SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i", ret);
  358. ret = SDLTest_CompareSurfaces(testSurface2x, referenceSurface2x, 0);
  359. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  360. }
  361. /* Clean up. */
  362. SDL_DestroySurface(face);
  363. SDL_DestroySurface(testSurface2x);
  364. SDL_DestroySurface(referenceSurface2x);
  365. return TEST_COMPLETED;
  366. }
  367. /**
  368. * Tests surface conversion.
  369. */
  370. static int surface_testSurfaceConversion(void *arg)
  371. {
  372. SDL_Surface *rface = NULL, *face = NULL;
  373. int ret = 0;
  374. /* Create sample surface */
  375. face = SDLTest_ImageFace();
  376. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  377. if (face == NULL) {
  378. return TEST_ABORTED;
  379. }
  380. /* Set transparent pixel as the pixel at (0,0) */
  381. if (SDL_GetSurfacePalette(face)) {
  382. ret = SDL_SetSurfaceColorKey(face, SDL_TRUE, *(Uint8 *)face->pixels);
  383. SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
  384. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorKey, expected: 0, got: %i", ret);
  385. }
  386. /* Convert to 32 bit to compare. */
  387. rface = SDL_ConvertSurface(face, testSurface->format);
  388. SDLTest_AssertPass("Call to SDL_ConvertSurface()");
  389. SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
  390. /* Compare surface. */
  391. ret = SDLTest_CompareSurfaces(rface, face, 0);
  392. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  393. /* Clean up. */
  394. SDL_DestroySurface(face);
  395. face = NULL;
  396. SDL_DestroySurface(rface);
  397. rface = NULL;
  398. return TEST_COMPLETED;
  399. }
  400. /**
  401. * Tests surface conversion across all pixel formats.
  402. */
  403. static int surface_testCompleteSurfaceConversion(void *arg)
  404. {
  405. Uint32 pixel_formats[] = {
  406. SDL_PIXELFORMAT_INDEX8,
  407. SDL_PIXELFORMAT_RGB332,
  408. SDL_PIXELFORMAT_XRGB4444,
  409. SDL_PIXELFORMAT_XBGR4444,
  410. SDL_PIXELFORMAT_XRGB1555,
  411. SDL_PIXELFORMAT_XBGR1555,
  412. SDL_PIXELFORMAT_ARGB4444,
  413. SDL_PIXELFORMAT_RGBA4444,
  414. SDL_PIXELFORMAT_ABGR4444,
  415. SDL_PIXELFORMAT_BGRA4444,
  416. SDL_PIXELFORMAT_ARGB1555,
  417. SDL_PIXELFORMAT_RGBA5551,
  418. SDL_PIXELFORMAT_ABGR1555,
  419. SDL_PIXELFORMAT_BGRA5551,
  420. SDL_PIXELFORMAT_RGB565,
  421. SDL_PIXELFORMAT_BGR565,
  422. SDL_PIXELFORMAT_RGB24,
  423. SDL_PIXELFORMAT_BGR24,
  424. SDL_PIXELFORMAT_XRGB8888,
  425. SDL_PIXELFORMAT_RGBX8888,
  426. SDL_PIXELFORMAT_XBGR8888,
  427. SDL_PIXELFORMAT_BGRX8888,
  428. SDL_PIXELFORMAT_ARGB8888,
  429. SDL_PIXELFORMAT_RGBA8888,
  430. SDL_PIXELFORMAT_ABGR8888,
  431. SDL_PIXELFORMAT_BGRA8888,
  432. #if 0 /* We aren't testing HDR10 colorspace conversion */
  433. SDL_PIXELFORMAT_XRGB2101010,
  434. SDL_PIXELFORMAT_XBGR2101010,
  435. SDL_PIXELFORMAT_ARGB2101010,
  436. SDL_PIXELFORMAT_ABGR2101010,
  437. #endif
  438. };
  439. SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
  440. const SDL_PixelFormatDetails *fmt1, *fmt2;
  441. int i, j, ret = 0;
  442. /* Create sample surface */
  443. face = SDLTest_ImageFace();
  444. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  445. if (face == NULL) {
  446. return TEST_ABORTED;
  447. }
  448. /* Set transparent pixel as the pixel at (0,0) */
  449. if (SDL_GetSurfacePalette(face)) {
  450. ret = SDL_SetSurfaceColorKey(face, SDL_TRUE, *(Uint8 *)face->pixels);
  451. SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
  452. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorKey, expected: 0, got: %i", ret);
  453. }
  454. for (i = 0; i < SDL_arraysize(pixel_formats); ++i) {
  455. for (j = 0; j < SDL_arraysize(pixel_formats); ++j) {
  456. fmt1 = SDL_GetPixelFormatDetails(pixel_formats[i]);
  457. SDLTest_AssertCheck(fmt1 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
  458. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  459. cvt1 = SDL_ConvertSurface(face, fmt1->format);
  460. SDLTest_AssertCheck(cvt1 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
  461. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  462. fmt2 = SDL_GetPixelFormatDetails(pixel_formats[j]);
  463. SDLTest_AssertCheck(fmt2 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
  464. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  465. cvt2 = SDL_ConvertSurface(cvt1, fmt2->format);
  466. SDLTest_AssertCheck(cvt2 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
  467. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  468. if (fmt1 && fmt2 &&
  469. fmt1->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
  470. fmt2->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
  471. SDL_ISPIXELFORMAT_ALPHA(fmt1->format) == SDL_ISPIXELFORMAT_ALPHA(face->format) &&
  472. SDL_ISPIXELFORMAT_ALPHA(fmt2->format) == SDL_ISPIXELFORMAT_ALPHA(face->format)) {
  473. final = SDL_ConvertSurface(cvt2, face->format);
  474. SDL_assert(final != NULL);
  475. /* Compare surface. */
  476. ret = SDLTest_CompareSurfaces(face, final, 0);
  477. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  478. SDL_DestroySurface(final);
  479. }
  480. SDL_DestroySurface(cvt1);
  481. SDL_DestroySurface(cvt2);
  482. }
  483. }
  484. /* Clean up. */
  485. SDL_DestroySurface(face);
  486. return TEST_COMPLETED;
  487. }
  488. /**
  489. * Tests sprite loading. A failure case.
  490. */
  491. static int surface_testLoadFailure(void *arg)
  492. {
  493. SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
  494. SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
  495. return TEST_COMPLETED;
  496. }
  497. /**
  498. * Tests some blitting routines.
  499. */
  500. static int surface_testBlit(void *arg)
  501. {
  502. /* Basic blitting */
  503. testBlitBlendMode(SDL_BLENDMODE_NONE);
  504. return TEST_COMPLETED;
  505. }
  506. /**
  507. * Tests some blitting routines with color mod
  508. */
  509. static int surface_testBlitColorMod(void *arg)
  510. {
  511. /* Basic blitting with color mod */
  512. testBlitBlendMode(-1);
  513. return TEST_COMPLETED;
  514. }
  515. /**
  516. * Tests some blitting routines with alpha mod
  517. */
  518. static int surface_testBlitAlphaMod(void *arg)
  519. {
  520. /* Basic blitting with alpha mod */
  521. testBlitBlendMode(-2);
  522. return TEST_COMPLETED;
  523. }
  524. /**
  525. * Tests some more blitting routines.
  526. */
  527. static int surface_testBlitBlendBlend(void *arg)
  528. {
  529. /* Blend blitting */
  530. testBlitBlendMode(SDL_BLENDMODE_BLEND);
  531. return TEST_COMPLETED;
  532. }
  533. /**
  534. * @brief Tests some more blitting routines.
  535. */
  536. static int surface_testBlitBlendPremultiplied(void *arg)
  537. {
  538. /* Blend premultiplied blitting */
  539. testBlitBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED);
  540. return TEST_COMPLETED;
  541. }
  542. /**
  543. * Tests some more blitting routines.
  544. */
  545. static int surface_testBlitBlendAdd(void *arg)
  546. {
  547. /* Add blitting */
  548. testBlitBlendMode(SDL_BLENDMODE_ADD);
  549. return TEST_COMPLETED;
  550. }
  551. /**
  552. * Tests some more blitting routines.
  553. */
  554. static int surface_testBlitBlendAddPremultiplied(void *arg)
  555. {
  556. /* Add premultiplied blitting */
  557. testBlitBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED);
  558. return TEST_COMPLETED;
  559. }
  560. /**
  561. * Tests some more blitting routines.
  562. */
  563. static int surface_testBlitBlendMod(void *arg)
  564. {
  565. /* Mod blitting */
  566. testBlitBlendMode(SDL_BLENDMODE_MOD);
  567. return TEST_COMPLETED;
  568. }
  569. /**
  570. * Tests some more blitting routines.
  571. */
  572. static int surface_testBlitBlendMul(void *arg)
  573. {
  574. /* Mod blitting */
  575. testBlitBlendMode(SDL_BLENDMODE_MUL);
  576. return TEST_COMPLETED;
  577. }
  578. static int surface_testOverflow(void *arg)
  579. {
  580. char buf[1024];
  581. const char *expectedError;
  582. SDL_Surface *surface;
  583. SDL_memset(buf, '\0', sizeof(buf));
  584. expectedError = "Parameter 'width' is invalid";
  585. surface = SDL_CreateSurface(-3, 100, SDL_PIXELFORMAT_INDEX8);
  586. SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
  587. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  588. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  589. surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_INDEX8, buf, 4);
  590. SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
  591. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  592. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  593. surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
  594. SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
  595. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  596. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  597. expectedError = "Parameter 'height' is invalid";
  598. surface = SDL_CreateSurface(100, -3, SDL_PIXELFORMAT_INDEX8);
  599. SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
  600. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  601. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  602. surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_INDEX8, buf, 4);
  603. SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
  604. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  605. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  606. surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
  607. SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
  608. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  609. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  610. expectedError = "Parameter 'pitch' is invalid";
  611. surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_INDEX8, buf, -1);
  612. SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
  613. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  614. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  615. surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, -1);
  616. SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
  617. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  618. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  619. surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 0);
  620. SDLTest_AssertCheck(surface == NULL, "Should detect zero pitch");
  621. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  622. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  623. surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, NULL, 0);
  624. SDLTest_AssertCheck(surface != NULL, "Allow zero pitch for partially set up surfaces: %s",
  625. surface != NULL ? "(success)" : SDL_GetError());
  626. SDL_DestroySurface(surface);
  627. /* Less than 1 byte per pixel: the pitch can legitimately be less than
  628. * the width, but it must be enough to hold the appropriate number of
  629. * bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */
  630. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
  631. SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
  632. surface != NULL ? "(success)" : SDL_GetError());
  633. SDL_DestroySurface(surface);
  634. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
  635. SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
  636. surface != NULL ? "(success)" : SDL_GetError());
  637. SDL_DestroySurface(surface);
  638. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
  639. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  640. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  641. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  642. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
  643. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  644. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  645. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  646. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 4);
  647. SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
  648. surface != NULL ? "(success)" : SDL_GetError());
  649. SDL_DestroySurface(surface);
  650. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 4);
  651. SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
  652. surface != NULL ? "(success)" : SDL_GetError());
  653. SDL_DestroySurface(surface);
  654. /* SDL_PIXELFORMAT_INDEX2* needs 1 byte per 4 pixels. */
  655. surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
  656. SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
  657. surface != NULL ? "(success)" : SDL_GetError());
  658. SDL_DestroySurface(surface);
  659. surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
  660. SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
  661. surface != NULL ? "(success)" : SDL_GetError());
  662. SDL_DestroySurface(surface);
  663. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
  664. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp (%d)", surface ? surface->pitch : 0);
  665. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  666. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  667. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
  668. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  669. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  670. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  671. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 4);
  672. SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
  673. surface != NULL ? "(success)" : SDL_GetError());
  674. SDL_DestroySurface(surface);
  675. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 4);
  676. SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
  677. surface != NULL ? "(success)" : SDL_GetError());
  678. SDL_DestroySurface(surface);
  679. /* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
  680. surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
  681. SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
  682. surface != NULL ? "(success)" : SDL_GetError());
  683. SDL_DestroySurface(surface);
  684. surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
  685. SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
  686. surface != NULL ? "(success)" : SDL_GetError());
  687. SDL_DestroySurface(surface);
  688. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
  689. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  690. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  691. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  692. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
  693. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  694. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  695. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  696. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 3);
  697. SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
  698. surface != NULL ? "(success)" : SDL_GetError());
  699. SDL_DestroySurface(surface);
  700. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 3);
  701. SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
  702. surface != NULL ? "(success)" : SDL_GetError());
  703. SDL_DestroySurface(surface);
  704. /* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */
  705. surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
  706. SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
  707. surface != NULL ? "(success)" : SDL_GetError());
  708. SDL_DestroySurface(surface);
  709. surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
  710. SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
  711. surface != NULL ? "(success)" : SDL_GetError());
  712. SDL_DestroySurface(surface);
  713. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
  714. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  715. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  716. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  717. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
  718. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  719. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  720. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  721. /* Everything else requires more than 1 byte per pixel, and rounds up
  722. * each pixel to an integer number of bytes (e.g. RGB555 is really
  723. * XRGB1555, with 1 bit per pixel wasted). */
  724. surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  725. SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s",
  726. surface != NULL ? "(success)" : SDL_GetError());
  727. SDL_DestroySurface(surface);
  728. surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  729. SDLTest_AssertCheck(surface != NULL, "5px * 15 (really 16) bits per px fits in 6 bytes: %s",
  730. surface != NULL ? "(success)" : SDL_GetError());
  731. SDL_DestroySurface(surface);
  732. surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  733. SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
  734. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  735. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  736. surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  737. SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
  738. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  739. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  740. if (sizeof(size_t) == 4 && sizeof(int) >= 4) {
  741. SDL_ClearError();
  742. expectedError = "aligning pitch would overflow";
  743. /* 0x5555'5555 * 3bpp = 0xffff'ffff which fits in size_t, but adding
  744. * alignment padding makes it overflow */
  745. surface = SDL_CreateSurface(0x55555555, 1, SDL_PIXELFORMAT_RGB24);
  746. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in pitch + alignment");
  747. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  748. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  749. SDL_ClearError();
  750. expectedError = "width * bpp would overflow";
  751. /* 0x4000'0000 * 4bpp = 0x1'0000'0000 which (just) overflows */
  752. surface = SDL_CreateSurface(0x40000000, 1, SDL_PIXELFORMAT_ARGB8888);
  753. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel");
  754. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  755. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  756. SDL_ClearError();
  757. expectedError = "height * pitch would overflow";
  758. surface = SDL_CreateSurface((1 << 29) - 1, (1 << 29) - 1, SDL_PIXELFORMAT_INDEX8);
  759. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height");
  760. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  761. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  762. SDL_ClearError();
  763. expectedError = "height * pitch would overflow";
  764. surface = SDL_CreateSurface((1 << 15) + 1, (1 << 15) + 1, SDL_PIXELFORMAT_ARGB8888);
  765. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel");
  766. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  767. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  768. } else {
  769. SDLTest_Log("Can't easily overflow size_t on this platform");
  770. }
  771. return TEST_COMPLETED;
  772. }
  773. static int surface_testFlip(void *arg)
  774. {
  775. SDL_Surface *surface;
  776. Uint8 *pixels;
  777. int offset;
  778. const char *expectedError;
  779. surface = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGB24);
  780. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  781. SDL_ClearError();
  782. expectedError = "Parameter 'surface' is invalid";
  783. SDL_FlipSurface(NULL, SDL_FLIP_HORIZONTAL);
  784. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  785. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  786. SDL_ClearError();
  787. expectedError = "Parameter 'flip' is invalid";
  788. SDL_FlipSurface(surface, SDL_FLIP_NONE);
  789. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  790. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  791. pixels = (Uint8 *)surface->pixels;
  792. *pixels = 0xFF;
  793. offset = 0;
  794. SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_VERTICAL)");
  795. CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_VERTICAL));
  796. SDLTest_AssertCheck(pixels[offset] == 0x00,
  797. "Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
  798. offset = 2 * surface->pitch;
  799. SDLTest_AssertCheck(pixels[offset] == 0xFF,
  800. "Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
  801. SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_HORIZONTAL)");
  802. CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_HORIZONTAL));
  803. SDLTest_AssertCheck(pixels[offset] == 0x00,
  804. "Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
  805. offset += (surface->w - 1) * SDL_BYTESPERPIXEL(surface->format);
  806. SDLTest_AssertCheck(pixels[offset] == 0xFF,
  807. "Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
  808. SDL_DestroySurface(surface);
  809. return TEST_COMPLETED;
  810. }
  811. static int surface_testPalette(void *arg)
  812. {
  813. SDL_Surface *source, *surface, *output;
  814. SDL_Palette *palette;
  815. Uint8 *pixels;
  816. palette = SDL_CreatePalette(2);
  817. SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
  818. source = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  819. SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
  820. SDLTest_AssertCheck(SDL_GetSurfacePalette(source) == NULL, "SDL_GetSurfacePalette(source)");
  821. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  822. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  823. SDLTest_AssertCheck(SDL_GetSurfacePalette(surface) == NULL, "SDL_GetSurfacePalette(surface)");
  824. pixels = (Uint8 *)surface->pixels;
  825. SDLTest_AssertCheck(*pixels == 0, "Expected *pixels == 0 got %u", *pixels);
  826. /* Identity copy between indexed surfaces without a palette */
  827. *(Uint8 *)source->pixels = 1;
  828. SDL_BlitSurface(source, NULL, surface, NULL);
  829. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  830. /* Identity copy between indexed surfaces where the destination has a palette */
  831. palette->colors[0].r = 0;
  832. palette->colors[0].g = 0;
  833. palette->colors[0].b = 0;
  834. palette->colors[1].r = 0xFF;
  835. palette->colors[1].g = 0;
  836. palette->colors[1].b = 0;
  837. SDL_SetSurfacePalette(surface, palette);
  838. *pixels = 0;
  839. SDL_BlitSurface(source, NULL, surface, NULL);
  840. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  841. output = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
  842. SDLTest_AssertCheck(output != NULL, "SDL_CreateSurface()");
  843. pixels = (Uint8 *)output->pixels;
  844. SDL_BlitSurface(surface, NULL, output, NULL);
  845. SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
  846. /* Set the palette color and blit again */
  847. palette->colors[1].r = 0xAA;
  848. SDL_SetSurfacePalette(surface, palette);
  849. SDL_BlitSurface(surface, NULL, output, NULL);
  850. SDLTest_AssertCheck(*pixels == 0xAA, "Expected *pixels == 0xAA got 0x%.2X", *pixels);
  851. SDL_DestroyPalette(palette);
  852. SDL_DestroySurface(source);
  853. SDL_DestroySurface(surface);
  854. SDL_DestroySurface(output);
  855. return TEST_COMPLETED;
  856. }
  857. static int surface_testClearSurface(void *arg)
  858. {
  859. SDL_PixelFormat formats[] = {
  860. SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
  861. SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
  862. SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
  863. SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
  864. SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_NV12
  865. };
  866. SDL_Surface *surface;
  867. SDL_PixelFormat format;
  868. const float MAXIMUM_ERROR_RGB = 0.0001f;
  869. const float MAXIMUM_ERROR_YUV = 0.01f;
  870. float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 1.0f;
  871. float actualR, actualG, actualB, actualA;
  872. float deltaR, deltaG, deltaB, deltaA;
  873. int i, ret;
  874. for (i = 0; i < SDL_arraysize(formats); ++i) {
  875. const float MAXIMUM_ERROR = SDL_ISPIXELFORMAT_FOURCC(formats[i]) ? MAXIMUM_ERROR_YUV : MAXIMUM_ERROR_RGB;
  876. format = formats[i];
  877. surface = SDL_CreateSurface(1, 1, format);
  878. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  879. ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
  880. SDLTest_AssertCheck(ret == 0, "SDL_ClearSurface()");
  881. ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, &actualA);
  882. SDLTest_AssertCheck(ret == 0, "SDL_ReadSurfacePixelFloat()");
  883. deltaR = SDL_fabsf(actualR - srcR);
  884. deltaG = SDL_fabsf(actualG - srcG);
  885. deltaB = SDL_fabsf(actualB - srcB);
  886. deltaA = SDL_fabsf(actualA - srcA);
  887. SDLTest_AssertCheck(
  888. deltaR <= MAXIMUM_ERROR &&
  889. deltaG <= MAXIMUM_ERROR &&
  890. deltaB <= MAXIMUM_ERROR &&
  891. deltaA <= MAXIMUM_ERROR,
  892. "Checking %s surface clear results, expected %.4f,%.4f,%.4f,%.4f, got %.4f,%.4f,%.4f,%.4f",
  893. SDL_GetPixelFormatName(format),
  894. srcR, srcG, srcB, srcA, actualR, actualG, actualB, actualA);
  895. SDL_DestroySurface(surface);
  896. }
  897. return TEST_COMPLETED;
  898. }
  899. static int surface_testPremultiplyAlpha(void *arg)
  900. {
  901. SDL_PixelFormat formats[] = {
  902. SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
  903. SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
  904. SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
  905. SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
  906. };
  907. SDL_Surface *surface;
  908. SDL_PixelFormat format;
  909. const float MAXIMUM_ERROR_LOW_PRECISION = 1 / 255.0f;
  910. const float MAXIMUM_ERROR_HIGH_PRECISION = 0.0001f;
  911. float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 170 / 255.0f;
  912. float expectedR = srcR * srcA;
  913. float expectedG = srcG * srcA;
  914. float expectedB = srcB * srcA;
  915. float actualR, actualG, actualB;
  916. float deltaR, deltaG, deltaB;
  917. int i, ret;
  918. for (i = 0; i < SDL_arraysize(formats); ++i) {
  919. const float MAXIMUM_ERROR = (SDL_BITSPERPIXEL(formats[i]) > 32) ? MAXIMUM_ERROR_HIGH_PRECISION : MAXIMUM_ERROR_LOW_PRECISION;
  920. format = formats[i];
  921. surface = SDL_CreateSurface(1, 1, format);
  922. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  923. ret = SDL_SetSurfaceColorspace(surface, SDL_COLORSPACE_SRGB);
  924. SDLTest_AssertCheck(ret == 0, "SDL_SetSurfaceColorspace()");
  925. ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
  926. SDLTest_AssertCheck(ret == 0, "SDL_ClearSurface()");
  927. ret = SDL_PremultiplySurfaceAlpha(surface, SDL_FALSE);
  928. SDLTest_AssertCheck(ret == 0, "SDL_PremultiplySurfaceAlpha()");
  929. ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, NULL);
  930. SDLTest_AssertCheck(ret == 0, "SDL_ReadSurfacePixelFloat()");
  931. deltaR = SDL_fabsf(actualR - expectedR);
  932. deltaG = SDL_fabsf(actualG - expectedG);
  933. deltaB = SDL_fabsf(actualB - expectedB);
  934. SDLTest_AssertCheck(
  935. deltaR <= MAXIMUM_ERROR &&
  936. deltaG <= MAXIMUM_ERROR &&
  937. deltaB <= MAXIMUM_ERROR,
  938. "Checking %s alpha premultiply results, expected %.4f,%.4f,%.4f, got %.4f,%.4f,%.4f",
  939. SDL_GetPixelFormatName(format),
  940. expectedR, expectedG, expectedB, actualR, actualG, actualB);
  941. SDL_DestroySurface(surface);
  942. }
  943. return TEST_COMPLETED;
  944. }
  945. /* ================= Test References ================== */
  946. /* Surface test cases */
  947. static const SDLTest_TestCaseReference surfaceTestSaveLoadBitmap = {
  948. (SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
  949. };
  950. static const SDLTest_TestCaseReference surfaceTestBlit = {
  951. (SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED
  952. };
  953. static const SDLTest_TestCaseReference surfaceTestBlitTiled = {
  954. (SDLTest_TestCaseFp)surface_testBlitTiled, "surface_testBlitTiled", "Tests tiled blitting.", TEST_ENABLED
  955. };
  956. static const SDLTest_TestCaseReference surfaceTestLoadFailure = {
  957. (SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED
  958. };
  959. static const SDLTest_TestCaseReference surfaceTestSurfaceConversion = {
  960. (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED
  961. };
  962. static const SDLTest_TestCaseReference surfaceTestCompleteSurfaceConversion = {
  963. (SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED
  964. };
  965. static const SDLTest_TestCaseReference surfaceTestBlitColorMod = {
  966. (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED
  967. };
  968. static const SDLTest_TestCaseReference surfaceTestBlitAlphaMod = {
  969. (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED
  970. };
  971. static const SDLTest_TestCaseReference surfaceTestBlitBlendBlend = {
  972. (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_ENABLED
  973. };
  974. static const SDLTest_TestCaseReference surfaceTestBlitBlendPremultiplied = {
  975. (SDLTest_TestCaseFp)surface_testBlitBlendPremultiplied, "surface_testBlitBlendPremultiplied", "Tests blitting routines with premultiplied blending mode.", TEST_ENABLED
  976. };
  977. static const SDLTest_TestCaseReference surfaceTestBlitBlendAdd = {
  978. (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_ENABLED
  979. };
  980. static const SDLTest_TestCaseReference surfaceTestBlitBlendAddPremultiplied = {
  981. (SDLTest_TestCaseFp)surface_testBlitBlendAddPremultiplied, "surface_testBlitBlendAddPremultiplied", "Tests blitting routines with premultiplied add blending mode.", TEST_ENABLED
  982. };
  983. static const SDLTest_TestCaseReference surfaceTestBlitBlendMod = {
  984. (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED
  985. };
  986. static const SDLTest_TestCaseReference surfaceTestBlitBlendMul = {
  987. (SDLTest_TestCaseFp)surface_testBlitBlendMul, "surface_testBlitBlendMul", "Tests blitting routines with mul blending mode.", TEST_ENABLED
  988. };
  989. static const SDLTest_TestCaseReference surfaceTestOverflow = {
  990. surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED
  991. };
  992. static const SDLTest_TestCaseReference surfaceTestFlip = {
  993. surface_testFlip, "surface_testFlip", "Test surface flipping.", TEST_ENABLED
  994. };
  995. static const SDLTest_TestCaseReference surfaceTestPalette = {
  996. surface_testPalette, "surface_testPalette", "Test surface palette operations.", TEST_ENABLED
  997. };
  998. static const SDLTest_TestCaseReference surfaceTestClearSurface = {
  999. surface_testClearSurface, "surface_testClearSurface", "Test clear surface operations.", TEST_ENABLED
  1000. };
  1001. static const SDLTest_TestCaseReference surfaceTestPremultiplyAlpha = {
  1002. surface_testPremultiplyAlpha, "surface_testPremultiplyAlpha", "Test alpha premultiply operations.", TEST_ENABLED
  1003. };
  1004. /* Sequence of Surface test cases */
  1005. static const SDLTest_TestCaseReference *surfaceTests[] = {
  1006. &surfaceTestSaveLoadBitmap,
  1007. &surfaceTestBlit,
  1008. &surfaceTestBlitTiled,
  1009. &surfaceTestLoadFailure,
  1010. &surfaceTestSurfaceConversion,
  1011. &surfaceTestCompleteSurfaceConversion,
  1012. &surfaceTestBlitColorMod,
  1013. &surfaceTestBlitAlphaMod,
  1014. &surfaceTestBlitBlendBlend,
  1015. &surfaceTestBlitBlendPremultiplied,
  1016. &surfaceTestBlitBlendAdd,
  1017. &surfaceTestBlitBlendAddPremultiplied,
  1018. &surfaceTestBlitBlendMod,
  1019. &surfaceTestBlitBlendMul,
  1020. &surfaceTestOverflow,
  1021. &surfaceTestFlip,
  1022. &surfaceTestPalette,
  1023. &surfaceTestClearSurface,
  1024. &surfaceTestPremultiplyAlpha,
  1025. NULL
  1026. };
  1027. /* Surface test suite (global) */
  1028. SDLTest_TestSuiteReference surfaceTestSuite = {
  1029. "Surface",
  1030. surfaceSetUp,
  1031. surfaceTests,
  1032. surfaceTearDown
  1033. };