summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/test/testautomation_surface.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/SDL-3.2.8/test/testautomation_surface.c')
-rw-r--r--contrib/SDL-3.2.8/test/testautomation_surface.c1675
1 files changed, 1675 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/test/testautomation_surface.c b/contrib/SDL-3.2.8/test/testautomation_surface.c
new file mode 100644
index 0000000..c1d641e
--- /dev/null
+++ b/contrib/SDL-3.2.8/test/testautomation_surface.c
@@ -0,0 +1,1675 @@
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/* Suppress 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 <SDL3/SDL.h>
21#include <SDL3/SDL_test.h>
22#include "testautomation_suites.h"
23#include "testautomation_images.h"
24
25
26#define CHECK_FUNC(FUNC, PARAMS) \
27{ \
28 bool result = FUNC PARAMS; \
29 if (!result) { \
30 SDLTest_AssertCheck(result, "Validate result from %s, expected: true, got: false, %s", #FUNC, SDL_GetError()); \
31 } \
32}
33
34/* ================= Test Case Implementation ================== */
35
36/* Shared test surface */
37
38static SDL_Surface *referenceSurface = NULL;
39static SDL_Surface *testSurface = NULL;
40
41/* Fixture */
42
43/* Create a 32-bit writable surface for blitting tests */
44static void SDLCALL surfaceSetUp(void **arg)
45{
46 int result;
47 SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
48 SDL_BlendMode currentBlendMode;
49
50 referenceSurface = SDLTest_ImageBlit(); /* For size info */
51 testSurface = SDL_CreateSurface(referenceSurface->w, referenceSurface->h, SDL_PIXELFORMAT_RGBA32);
52 SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
53 if (testSurface != NULL) {
54 /* Disable blend mode for target surface */
55 result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
56 SDLTest_AssertCheck(result == true, "Validate result from SDL_SetSurfaceBlendMode, expected: true, got: %i", result);
57 result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
58 SDLTest_AssertCheck(result == true, "Validate result from SDL_GetSurfaceBlendMode, expected: true, got: %i", result);
59 SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, blendMode, currentBlendMode);
60
61 /* Clear the target surface */
62 result = SDL_FillSurfaceRect(testSurface, NULL, SDL_MapSurfaceRGBA(testSurface, 0, 0, 0, 255));
63 SDLTest_AssertCheck(result == true, "Validate result from SDL_FillSurfaceRect, expected: true, got: %i", result);
64 }
65}
66
67static void SDLCALL surfaceTearDown(void *arg)
68{
69 SDL_DestroySurface(referenceSurface);
70 referenceSurface = NULL;
71 SDL_DestroySurface(testSurface);
72 testSurface = NULL;
73}
74
75static void DitherPalette(SDL_Palette *palette)
76{
77 int i;
78
79 for (i = 0; i < palette->ncolors; i++) {
80 int r, g, b;
81 /* map each bit field to the full [0, 255] interval,
82 so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */
83 r = i & 0xe0;
84 r |= r >> 3 | r >> 6;
85 palette->colors[i].r = (Uint8)r;
86 g = (i << 3) & 0xe0;
87 g |= g >> 3 | g >> 6;
88 palette->colors[i].g = (Uint8)g;
89 b = i & 0x3;
90 b |= b << 2;
91 b |= b << 4;
92 palette->colors[i].b = (Uint8)b;
93 palette->colors[i].a = SDL_ALPHA_OPAQUE;
94 }
95}
96
97/**
98 * Helper that blits in a specific blend mode, -1 for color mod, -2 for alpha mod
99 */
100static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, SDL_PixelFormat dst_format)
101{
102 /* Allow up to 1 delta from theoretical value to account for rounding error */
103 const int MAXIMUM_ERROR = 1;
104 int ret;
105 SDL_Surface *src;
106 SDL_Surface *dst;
107 Uint32 color;
108 Uint8 srcR = 10, srcG = 128, srcB = 240, srcA = 100;
109 Uint8 dstR = 128, dstG = 128, dstB = 128, dstA = 128;
110 Uint8 expectedR, expectedG, expectedB, expectedA;
111 Uint8 actualR, actualG, actualB, actualA;
112 int deltaR, deltaG, deltaB, deltaA;
113
114 /* Create dst surface */
115 dst = SDL_CreateSurface(1, 1, dst_format);
116 SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL");
117 if (dst == NULL) {
118 return;
119 }
120
121 /* Clear surface. */
122 if (SDL_ISPIXELFORMAT_INDEXED(dst_format)) {
123 SDL_Palette *palette = SDL_CreateSurfacePalette(dst);
124 DitherPalette(palette);
125 palette->colors[0].r = dstR;
126 palette->colors[0].g = dstG;
127 palette->colors[0].b = dstB;
128 palette->colors[0].a = dstA;
129 color = 0;
130 } else {
131 color = SDL_MapSurfaceRGBA(dst, dstR, dstG, dstB, dstA);
132 SDLTest_AssertPass("Call to SDL_MapSurfaceRGBA()");
133 }
134 ret = SDL_FillSurfaceRect(dst, NULL, color);
135 SDLTest_AssertPass("Call to SDL_FillSurfaceRect()");
136 SDLTest_AssertCheck(ret == true, "Verify result from SDL_FillSurfaceRect, expected: true, got: %i", ret);
137 SDL_GetRGBA(color, SDL_GetPixelFormatDetails(dst->format), SDL_GetSurfacePalette(dst), &dstR, &dstG, &dstB, &dstA);
138
139 /* Create src surface */
140 src = SDL_CreateSurface(1, 1, src_format);
141 SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL");
142 if (src == NULL) {
143 return;
144 }
145 if (SDL_ISPIXELFORMAT_INDEXED(src_format)) {
146 SDL_Palette *palette = SDL_CreateSurfacePalette(src);
147 palette->colors[0].r = srcR;
148 palette->colors[0].g = srcG;
149 palette->colors[0].b = srcB;
150 palette->colors[0].a = srcA;
151 }
152
153 /* Reset alpha modulation */
154 ret = SDL_SetSurfaceAlphaMod(src, 255);
155 SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
156 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceAlphaMod(), expected: true, got: %i", ret);
157
158 /* Reset color modulation */
159 ret = SDL_SetSurfaceColorMod(src, 255, 255, 255);
160 SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
161 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceColorMod(), expected: true, got: %i", ret);
162
163 /* Reset color key */
164 ret = SDL_SetSurfaceColorKey(src, false, 0);
165 SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
166 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceColorKey(), expected: true, got: %i", ret);
167
168 /* Clear surface. */
169 color = SDL_MapSurfaceRGBA(src, srcR, srcG, srcB, srcA);
170 SDLTest_AssertPass("Call to SDL_MapSurfaceRGBA()");
171 ret = SDL_FillSurfaceRect(src, NULL, color);
172 SDLTest_AssertPass("Call to SDL_FillSurfaceRect()");
173 SDLTest_AssertCheck(ret == true, "Verify result from SDL_FillSurfaceRect, expected: true, got: %i", ret);
174 SDL_GetRGBA(color, SDL_GetPixelFormatDetails(src->format), SDL_GetSurfacePalette(src), &srcR, &srcG, &srcB, &srcA);
175
176 /* Set blend mode. */
177 if (mode >= 0) {
178 ret = SDL_SetSurfaceBlendMode(src, (SDL_BlendMode)mode);
179 SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
180 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: true, got: %i", mode, ret);
181 } else {
182 ret = SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND);
183 SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
184 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: true, got: %i", mode, ret);
185 }
186
187 /* Test blend mode. */
188#define FLOAT(X) ((float)X / 255.0f)
189 switch (mode) {
190 case -1:
191 /* Set color mod. */
192 ret = SDL_SetSurfaceColorMod(src, srcR, srcG, srcB);
193 SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_SetSurfaceColorMod, expected: true, got: %i", ret);
194 expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
195 expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
196 expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
197 expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
198 break;
199 case -2:
200 /* Set alpha mod. */
201 ret = SDL_SetSurfaceAlphaMod(src, srcA);
202 SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: true, got: %i", ret);
203 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);
204 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);
205 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);
206 expectedA = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstA) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
207 break;
208 case SDL_BLENDMODE_NONE:
209 expectedR = srcR;
210 expectedG = srcG;
211 expectedB = srcB;
212 expectedA = SDL_ISPIXELFORMAT_ALPHA(dst_format) ? srcA : 255;
213 break;
214 case SDL_BLENDMODE_BLEND:
215 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
216 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
217 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
218 expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
219 break;
220 case SDL_BLENDMODE_BLEND_PREMULTIPLIED:
221 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
222 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
223 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
224 expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
225 break;
226 case SDL_BLENDMODE_ADD:
227 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
228 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
229 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
230 expectedA = dstA;
231 break;
232 case SDL_BLENDMODE_ADD_PREMULTIPLIED:
233 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
234 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
235 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
236 expectedA = dstA;
237 break;
238 case SDL_BLENDMODE_MOD:
239 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
240 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
241 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
242 expectedA = dstA;
243 break;
244 case SDL_BLENDMODE_MUL:
245 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
246 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
247 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
248 expectedA = dstA;
249 break;
250 default:
251 SDLTest_LogError("Invalid blending mode: %d", mode);
252 return;
253 }
254
255 if (SDL_ISPIXELFORMAT_INDEXED(dst_format)) {
256 SDL_Palette *palette = SDL_GetSurfacePalette(dst);
257 palette->colors[1].r = expectedR;
258 palette->colors[1].g = expectedG;
259 palette->colors[1].b = expectedB;
260 palette->colors[1].a = expectedA;
261 }
262
263 /* Blitting. */
264 ret = SDL_BlitSurface(src, NULL, dst, NULL);
265 SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_BlitSurface, expected: true, got: %i: %s", ret, !ret ? SDL_GetError() : "success");
266 if (ret) {
267 SDL_ReadSurfacePixel(dst, 0, 0, &actualR, &actualG, &actualB, &actualA);
268 deltaR = SDL_abs((int)actualR - expectedR);
269 deltaG = SDL_abs((int)actualG - expectedG);
270 deltaB = SDL_abs((int)actualB - expectedB);
271 deltaA = SDL_abs((int)actualA - expectedA);
272 SDLTest_AssertCheck(
273 deltaR <= MAXIMUM_ERROR &&
274 deltaG <= MAXIMUM_ERROR &&
275 deltaB <= MAXIMUM_ERROR &&
276 deltaA <= MAXIMUM_ERROR,
277 "Checking %s -> %s blit results, expected %d,%d,%d,%d, got %d,%d,%d,%d",
278 SDL_GetPixelFormatName(src_format),
279 SDL_GetPixelFormatName(dst_format),
280 expectedR, expectedG, expectedB, expectedA, actualR, actualG, actualB, actualA);
281 }
282
283 /* Clean up */
284 SDL_DestroySurface(src);
285 SDL_DestroySurface(dst);
286}
287
288static void testBlitBlendMode(int mode)
289{
290 const SDL_PixelFormat src_formats[] = {
291 SDL_PIXELFORMAT_INDEX8, SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
292 };
293 const SDL_PixelFormat dst_formats[] = {
294 SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
295 };
296 int i, j;
297
298 for (i = 0; i < SDL_arraysize(src_formats); ++i) {
299 for (j = 0; j < SDL_arraysize(dst_formats); ++j) {
300 testBlitBlendModeWithFormats(mode, src_formats[i], dst_formats[j]);
301 }
302 }
303}
304
305/* Helper to check that a file exists */
306static void AssertFileExist(const char *filename)
307{
308 struct stat st;
309 int ret = stat(filename, &st);
310
311 SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
312}
313
314/* Test case functions */
315
316/**
317 * Tests sprite saving and loading
318 */
319static int SDLCALL surface_testSaveLoadBitmap(void *arg)
320{
321 int ret;
322 const char *sampleFilename = "testSaveLoadBitmap.bmp";
323 SDL_Surface *face;
324 SDL_Surface *rface;
325
326 /* Create sample surface */
327 face = SDLTest_ImageFace();
328 SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
329 if (face == NULL) {
330 return TEST_ABORTED;
331 }
332
333 /* Delete test file; ignore errors */
334 unlink(sampleFilename);
335
336 /* Save a surface */
337 ret = SDL_SaveBMP(face, sampleFilename);
338 SDLTest_AssertPass("Call to SDL_SaveBMP()");
339 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SaveBMP, expected: true, got: %i", ret);
340 AssertFileExist(sampleFilename);
341
342 /* Load a surface */
343 rface = SDL_LoadBMP(sampleFilename);
344 SDLTest_AssertPass("Call to SDL_LoadBMP()");
345 SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
346 if (rface != NULL) {
347 SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
348 SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
349 }
350
351 /* Delete test file; ignore errors */
352 unlink(sampleFilename);
353
354 /* Clean up */
355 SDL_DestroySurface(face);
356 face = NULL;
357 SDL_DestroySurface(rface);
358 rface = NULL;
359
360 return TEST_COMPLETED;
361}
362
363/**
364 * Tests tiled blitting.
365 */
366static int SDLCALL surface_testBlitTiled(void *arg)
367{
368 SDL_Surface *face = NULL;
369 SDL_Surface *testSurface2x = NULL;
370 SDL_Surface *referenceSurface2x = NULL;
371 int ret = 0;
372
373 /* Create sample surface */
374 face = SDLTest_ImageFace();
375 SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
376 if (face == NULL) {
377 return TEST_ABORTED;
378 }
379
380 /* Tiled blit - 1.0 scale */
381 {
382 ret = SDL_BlitSurfaceTiled(face, NULL, testSurface, NULL);
383 SDLTest_AssertCheck(ret == true, "Verify result from SDL_BlitSurfaceTiled expected: true, got: %i", ret);
384
385 /* See if it's the same */
386 SDL_DestroySurface(referenceSurface);
387 referenceSurface = SDLTest_ImageBlitTiled();
388 ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
389 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
390 }
391
392 /* Tiled blit - 2.0 scale */
393 {
394 testSurface2x = SDL_CreateSurface(testSurface->w * 2, testSurface->h * 2, testSurface->format);
395 SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface2x is not NULL");
396 ret = SDL_FillSurfaceRect(testSurface2x, NULL, SDL_MapSurfaceRGBA(testSurface2x, 0, 0, 0, 255));
397 SDLTest_AssertCheck(ret == true, "Validate result from SDL_FillSurfaceRect, expected: true, got: %i", ret);
398
399 ret = SDL_BlitSurfaceTiledWithScale(face, NULL, 2.0f, SDL_SCALEMODE_NEAREST, testSurface2x, NULL);
400 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_BlitSurfaceTiledWithScale, expected: true, got: %i", ret);
401
402 /* See if it's the same */
403 referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format);
404 SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST);
405 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_BlitSurfaceScaled, expected: true, got: %i", ret);
406 ret = SDLTest_CompareSurfaces(testSurface2x, referenceSurface2x, 0);
407 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
408 }
409
410 /* Clean up. */
411 SDL_DestroySurface(face);
412 SDL_DestroySurface(testSurface2x);
413 SDL_DestroySurface(referenceSurface2x);
414
415 return TEST_COMPLETED;
416}
417
418static const Uint8 COLOR_SEPARATION = 85;
419
420static void Fill9GridReferenceSurface(SDL_Surface *surface, int left_width, int right_width, int top_height, int bottom_height)
421{
422 SDL_Rect rect;
423
424 // Upper left
425 rect.x = 0;
426 rect.y = 0;
427 rect.w = left_width;
428 rect.h = top_height;
429 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
430
431 // Top
432 rect.x = left_width;
433 rect.y = 0;
434 rect.w = surface->w - left_width - right_width;
435 rect.h = top_height;
436 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
437
438 // Upper right
439 rect.x = surface->w - right_width;
440 rect.y = 0;
441 rect.w = right_width;
442 rect.h = top_height;
443 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
444
445 // Left
446 rect.x = 0;
447 rect.y = top_height;
448 rect.w = left_width;
449 rect.h = surface->h - top_height - bottom_height;
450 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
451
452 // Center
453 rect.x = left_width;
454 rect.y = top_height;
455 rect.w = surface->w - right_width - left_width;
456 rect.h = surface->h - top_height - bottom_height;
457 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
458
459 // Right
460 rect.x = surface->w - right_width;
461 rect.y = top_height;
462 rect.w = right_width;
463 rect.h = surface->h - top_height - bottom_height;
464 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
465
466 // Lower left
467 rect.x = 0;
468 rect.y = surface->h - bottom_height;
469 rect.w = left_width;
470 rect.h = bottom_height;
471 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
472
473 // Bottom
474 rect.x = left_width;
475 rect.y = surface->h - bottom_height;
476 rect.w = surface->w - left_width - right_width;
477 rect.h = bottom_height;
478 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
479
480 // Lower right
481 rect.x = surface->w - right_width;
482 rect.y = surface->h - bottom_height;
483 rect.w = right_width;
484 rect.h = bottom_height;
485 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
486}
487
488/**
489 * Tests 9-grid blitting.
490 */
491static int SDLCALL surface_testBlit9Grid(void *arg)
492{
493 SDL_Surface *source = NULL;
494 int x, y;
495 int ret = 0;
496
497 /* Create source surface */
498 source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32);
499 SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
500 for (y = 0; y < 3; ++y) {
501 for (x = 0; x < 3; ++x) {
502 SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255);
503 }
504 }
505
506 /* 9-grid blit - 1.0 scale */
507 {
508 /* Create reference surface */
509 SDL_DestroySurface(referenceSurface);
510 referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
511 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
512 Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1);
513
514 ret = SDL_BlitSurface9Grid(source, NULL, 1, 1, 1, 1, 0.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
515 SDLTest_AssertCheck(ret == true, "Validate result from SDL_BlitSurface9Grid, expected: true, got: %i", ret);
516
517 ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
518 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
519 }
520
521 /* 9-grid blit - 2.0 scale */
522 {
523 /* Create reference surface */
524 SDL_DestroySurface(referenceSurface);
525 referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
526 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
527 Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2);
528
529 ret = SDL_BlitSurface9Grid(source, NULL, 1, 1, 1, 1, 2.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
530 SDLTest_AssertCheck(ret == true, "Validate result from SDL_BlitSurface9Grid, expected: true, got: %i", ret);
531
532 ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
533 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
534 }
535
536 /* Clean up. */
537 SDL_DestroySurface(source);
538
539 /* Create complex source surface */
540 source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32);
541 SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
542 SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
543 SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
544 SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
545 SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
546 SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
547
548 SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
549 SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
550 SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
551 SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
552 SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
553
554 SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
555 SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
556 SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
557 SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
558 SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
559
560 SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
561 SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
562 SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
563 SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
564 SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
565
566 SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
567 SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
568 SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
569 SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
570 SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
571
572 /* complex 9-grid blit - 1.0 scale */
573 {
574 SDLTest_Log("complex 9-grid blit - 1.0 scale");
575 /* Create reference surface */
576 SDL_DestroySurface(referenceSurface);
577 referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
578 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
579 Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2);
580
581 ret = SDL_BlitSurface9Grid(source, NULL, 1, 2, 1, 2, 0.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
582 SDLTest_AssertCheck(ret == true, "Validate result from SDL_BlitSurface9Grid, expected: true, got: %i", ret);
583
584 ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
585 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
586 }
587
588 /* complex 9-grid blit - 2.0 scale */
589 {
590 SDLTest_Log("complex 9-grid blit - 2.0 scale");
591 /* Create reference surface */
592 SDL_DestroySurface(referenceSurface);
593 referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
594 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
595 Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4);
596
597 ret = SDL_BlitSurface9Grid(source, NULL, 1, 2, 1, 2, 2.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
598 SDLTest_AssertCheck(ret == true, "Validate result from SDL_BlitSurface9Grid, expected: true, got: %i", ret);
599
600 ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
601 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
602 }
603
604 /* Clean up. */
605 SDL_DestroySurface(source);
606
607 return TEST_COMPLETED;
608}
609
610/**
611 * Tests blitting between multiple surfaces of the same format
612 */
613static int SDLCALL surface_testBlitMultiple(void *arg)
614{
615 SDL_Surface *source, *surface;
616 SDL_Palette *palette;
617 Uint8 *pixels;
618
619 palette = SDL_CreatePalette(2);
620 SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
621 palette->colors[0].r = 0;
622 palette->colors[0].g = 0;
623 palette->colors[0].b = 0;
624 palette->colors[1].r = 0xFF;
625 palette->colors[1].g = 0;
626 palette->colors[1].b = 0;
627
628 source = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
629 SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
630 SDL_SetSurfacePalette(source, palette);
631 *(Uint8 *)source->pixels = 1;
632
633 /* Set up a blit to a surface using the palette */
634 surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
635 SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
636 SDL_SetSurfacePalette(surface, palette);
637 pixels = (Uint8 *)surface->pixels;
638 *pixels = 0;
639 SDL_BlitSurface(source, NULL, surface, NULL);
640 SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
641
642 /* Set up a blit to another surface using the same palette */
643 SDL_DestroySurface(surface);
644 surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
645 SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
646 SDL_SetSurfacePalette(surface, palette);
647 pixels = (Uint8 *)surface->pixels;
648 *pixels = 0;
649 SDL_BlitSurface(source, NULL, surface, NULL);
650 SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
651
652 /* Set up a blit to new surface with a different format */
653 SDL_DestroySurface(surface);
654 surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
655 SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
656 pixels = (Uint8 *)surface->pixels;
657 SDL_BlitSurface(source, NULL, surface, NULL);
658 SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
659
660 /* Set up a blit to another surface with the same format */
661 SDL_DestroySurface(surface);
662 surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
663 SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
664 pixels = (Uint8 *)surface->pixels;
665 SDL_BlitSurface(source, NULL, surface, NULL);
666 SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
667
668 SDL_DestroyPalette(palette);
669 SDL_DestroySurface(source);
670 SDL_DestroySurface(surface);
671
672 return TEST_COMPLETED;
673}
674
675/**
676 * Tests surface conversion.
677 */
678static int SDLCALL surface_testSurfaceConversion(void *arg)
679{
680 SDL_Surface *rface = NULL, *face = NULL;
681 int ret = 0;
682
683 /* Create sample surface */
684 face = SDLTest_ImageFace();
685 SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
686 if (face == NULL) {
687 return TEST_ABORTED;
688 }
689
690 /* Set transparent pixel as the pixel at (0,0) */
691 if (SDL_GetSurfacePalette(face)) {
692 ret = SDL_SetSurfaceColorKey(face, true, *(Uint8 *)face->pixels);
693 SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
694 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceColorKey, expected: true, got: %i", ret);
695 }
696
697 /* Convert to 32 bit to compare. */
698 rface = SDL_ConvertSurface(face, testSurface->format);
699 SDLTest_AssertPass("Call to SDL_ConvertSurface()");
700 SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
701
702 /* Compare surface. */
703 ret = SDLTest_CompareSurfaces(rface, face, 0);
704 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
705
706 /* Clean up. */
707 SDL_DestroySurface(face);
708 face = NULL;
709 SDL_DestroySurface(rface);
710 rface = NULL;
711
712 return TEST_COMPLETED;
713}
714
715/**
716 * Tests surface conversion across all pixel formats.
717 */
718static int SDLCALL surface_testCompleteSurfaceConversion(void *arg)
719{
720 Uint32 pixel_formats[] = {
721 SDL_PIXELFORMAT_INDEX8,
722 SDL_PIXELFORMAT_RGB332,
723 SDL_PIXELFORMAT_XRGB4444,
724 SDL_PIXELFORMAT_XBGR4444,
725 SDL_PIXELFORMAT_XRGB1555,
726 SDL_PIXELFORMAT_XBGR1555,
727 SDL_PIXELFORMAT_ARGB4444,
728 SDL_PIXELFORMAT_RGBA4444,
729 SDL_PIXELFORMAT_ABGR4444,
730 SDL_PIXELFORMAT_BGRA4444,
731 SDL_PIXELFORMAT_ARGB1555,
732 SDL_PIXELFORMAT_RGBA5551,
733 SDL_PIXELFORMAT_ABGR1555,
734 SDL_PIXELFORMAT_BGRA5551,
735 SDL_PIXELFORMAT_RGB565,
736 SDL_PIXELFORMAT_BGR565,
737 SDL_PIXELFORMAT_RGB24,
738 SDL_PIXELFORMAT_BGR24,
739 SDL_PIXELFORMAT_XRGB8888,
740 SDL_PIXELFORMAT_RGBX8888,
741 SDL_PIXELFORMAT_XBGR8888,
742 SDL_PIXELFORMAT_BGRX8888,
743 SDL_PIXELFORMAT_ARGB8888,
744 SDL_PIXELFORMAT_RGBA8888,
745 SDL_PIXELFORMAT_ABGR8888,
746 SDL_PIXELFORMAT_BGRA8888,
747#if 0 /* We aren't testing HDR10 colorspace conversion */
748 SDL_PIXELFORMAT_XRGB2101010,
749 SDL_PIXELFORMAT_XBGR2101010,
750 SDL_PIXELFORMAT_ARGB2101010,
751 SDL_PIXELFORMAT_ABGR2101010,
752#endif
753 };
754 SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
755 const SDL_PixelFormatDetails *fmt1, *fmt2;
756 int i, j, ret = 0;
757
758 /* Create sample surface */
759 face = SDLTest_ImageFace();
760 SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
761 if (face == NULL) {
762 return TEST_ABORTED;
763 }
764
765 /* Set transparent pixel as the pixel at (0,0) */
766 if (SDL_GetSurfacePalette(face)) {
767 ret = SDL_SetSurfaceColorKey(face, true, *(Uint8 *)face->pixels);
768 SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
769 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceColorKey, expected: true, got: %i", ret);
770 }
771
772 for (i = 0; i < SDL_arraysize(pixel_formats); ++i) {
773 for (j = 0; j < SDL_arraysize(pixel_formats); ++j) {
774 fmt1 = SDL_GetPixelFormatDetails(pixel_formats[i]);
775 SDLTest_AssertCheck(fmt1 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
776 SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
777 cvt1 = SDL_ConvertSurface(face, fmt1->format);
778 SDLTest_AssertCheck(cvt1 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
779 SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
780
781 fmt2 = SDL_GetPixelFormatDetails(pixel_formats[j]);
782 SDLTest_AssertCheck(fmt2 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
783 SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
784 cvt2 = SDL_ConvertSurface(cvt1, fmt2->format);
785 SDLTest_AssertCheck(cvt2 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
786 SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
787
788 if (fmt1 && fmt2 &&
789 fmt1->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
790 fmt2->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
791 SDL_ISPIXELFORMAT_ALPHA(fmt1->format) == SDL_ISPIXELFORMAT_ALPHA(face->format) &&
792 SDL_ISPIXELFORMAT_ALPHA(fmt2->format) == SDL_ISPIXELFORMAT_ALPHA(face->format)) {
793 final = SDL_ConvertSurface(cvt2, face->format);
794 SDL_assert(final != NULL);
795
796 /* Compare surface. */
797 ret = SDLTest_CompareSurfaces(face, final, 0);
798 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
799 SDL_DestroySurface(final);
800 }
801
802 SDL_DestroySurface(cvt1);
803 SDL_DestroySurface(cvt2);
804 }
805 }
806
807 /* Clean up. */
808 SDL_DestroySurface(face);
809
810 return TEST_COMPLETED;
811}
812
813/**
814 * Tests sprite loading. A failure case.
815 */
816static int SDLCALL surface_testLoadFailure(void *arg)
817{
818 SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
819 SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
820
821 return TEST_COMPLETED;
822}
823
824/**
825 * Tests blitting from a zero sized source rectangle
826 */
827static int SDLCALL surface_testBlitZeroSource(void *arg)
828{
829 SDL_Surface *src = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA8888);
830 SDL_Surface *dst = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA8888);
831 SDL_Rect srcrect = { 0, 0, 0, 0 };
832 int ret;
833
834 SDLTest_AssertPass("Call to SDL_BlitSurfaceScaled() with zero sized source rectangle");
835 SDL_FillSurfaceRect(src, NULL, SDL_MapSurfaceRGB(src, 255, 255, 255));
836 SDL_BlitSurfaceScaled(src, &srcrect, dst, NULL, SDL_SCALEMODE_NEAREST);
837 ret = SDLTest_CompareSurfaces(dst, src, 0);
838 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
839 SDL_DestroySurface(src);
840 SDL_DestroySurface(dst);
841
842 return TEST_COMPLETED;
843}
844
845/**
846 * Tests some blitting routines.
847 */
848static int SDLCALL surface_testBlit(void *arg)
849{
850 /* Basic blitting */
851 testBlitBlendMode(SDL_BLENDMODE_NONE);
852
853 return TEST_COMPLETED;
854}
855
856/**
857 * Tests some blitting routines with color mod
858 */
859static int SDLCALL surface_testBlitColorMod(void *arg)
860{
861 /* Basic blitting with color mod */
862 testBlitBlendMode(-1);
863
864 return TEST_COMPLETED;
865}
866
867/**
868 * Tests some blitting routines with alpha mod
869 */
870static int SDLCALL surface_testBlitAlphaMod(void *arg)
871{
872 /* Basic blitting with alpha mod */
873 testBlitBlendMode(-2);
874
875 return TEST_COMPLETED;
876}
877
878/**
879 * Tests some more blitting routines.
880 */
881static int SDLCALL surface_testBlitBlendBlend(void *arg)
882{
883 /* Blend blitting */
884 testBlitBlendMode(SDL_BLENDMODE_BLEND);
885
886 return TEST_COMPLETED;
887}
888
889/**
890 * @brief Tests some more blitting routines.
891 */
892static int SDLCALL surface_testBlitBlendPremultiplied(void *arg)
893{
894 /* Blend premultiplied blitting */
895 testBlitBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED);
896
897 return TEST_COMPLETED;
898}
899
900/**
901 * Tests some more blitting routines.
902 */
903static int SDLCALL surface_testBlitBlendAdd(void *arg)
904{
905 /* Add blitting */
906 testBlitBlendMode(SDL_BLENDMODE_ADD);
907
908 return TEST_COMPLETED;
909}
910
911/**
912 * Tests some more blitting routines.
913 */
914static int SDLCALL surface_testBlitBlendAddPremultiplied(void *arg)
915{
916 /* Add premultiplied blitting */
917 testBlitBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED);
918
919 return TEST_COMPLETED;
920}
921
922/**
923 * Tests some more blitting routines.
924 */
925static int SDLCALL surface_testBlitBlendMod(void *arg)
926{
927 /* Mod blitting */
928 testBlitBlendMode(SDL_BLENDMODE_MOD);
929
930 return TEST_COMPLETED;
931}
932
933/**
934 * Tests some more blitting routines.
935 */
936static int SDLCALL surface_testBlitBlendMul(void *arg)
937{
938 /* Mod blitting */
939 testBlitBlendMode(SDL_BLENDMODE_MUL);
940
941 return TEST_COMPLETED;
942}
943
944static int SDLCALL surface_testOverflow(void *arg)
945{
946 char buf[1024];
947 const char *expectedError;
948 SDL_Surface *surface;
949
950 SDL_memset(buf, '\0', sizeof(buf));
951
952 expectedError = "Parameter 'width' is invalid";
953 surface = SDL_CreateSurface(-3, 100, SDL_PIXELFORMAT_INDEX8);
954 SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
955 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
956 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
957 surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_INDEX8, buf, 4);
958 SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
959 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
960 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
961 surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
962 SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
963 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
964 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
965
966 expectedError = "Parameter 'height' is invalid";
967 surface = SDL_CreateSurface(100, -3, SDL_PIXELFORMAT_INDEX8);
968 SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
969 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
970 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
971 surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_INDEX8, buf, 4);
972 SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
973 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
974 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
975 surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
976 SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
977 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
978 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
979
980 expectedError = "Parameter 'pitch' is invalid";
981 surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_INDEX8, buf, -1);
982 SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
983 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
984 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
985 surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, -1);
986 SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
987 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
988 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
989 surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 0);
990 SDLTest_AssertCheck(surface == NULL, "Should detect zero pitch");
991 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
992 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
993 surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, NULL, 0);
994 SDLTest_AssertCheck(surface != NULL, "Allow zero pitch for partially set up surfaces: %s",
995 surface != NULL ? "(success)" : SDL_GetError());
996 SDL_DestroySurface(surface);
997
998 /* Less than 1 byte per pixel: the pitch can legitimately be less than
999 * the width, but it must be enough to hold the appropriate number of
1000 * bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */
1001 surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
1002 SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
1003 surface != NULL ? "(success)" : SDL_GetError());
1004 SDL_DestroySurface(surface);
1005 surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
1006 SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
1007 surface != NULL ? "(success)" : SDL_GetError());
1008 SDL_DestroySurface(surface);
1009
1010 surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
1011 SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
1012 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1013 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1014 surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
1015 SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
1016 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1017 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1018
1019 surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 4);
1020 SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
1021 surface != NULL ? "(success)" : SDL_GetError());
1022 SDL_DestroySurface(surface);
1023 surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 4);
1024 SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
1025 surface != NULL ? "(success)" : SDL_GetError());
1026 SDL_DestroySurface(surface);
1027
1028 /* SDL_PIXELFORMAT_INDEX2* needs 1 byte per 4 pixels. */
1029 surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
1030 SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
1031 surface != NULL ? "(success)" : SDL_GetError());
1032 SDL_DestroySurface(surface);
1033 surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
1034 SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
1035 surface != NULL ? "(success)" : SDL_GetError());
1036 SDL_DestroySurface(surface);
1037
1038 surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
1039 SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp (%d)", surface ? surface->pitch : 0);
1040 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1041 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1042 surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
1043 SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
1044 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1045 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1046
1047 surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 4);
1048 SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
1049 surface != NULL ? "(success)" : SDL_GetError());
1050 SDL_DestroySurface(surface);
1051 surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 4);
1052 SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
1053 surface != NULL ? "(success)" : SDL_GetError());
1054 SDL_DestroySurface(surface);
1055
1056 /* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
1057 surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
1058 SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
1059 surface != NULL ? "(success)" : SDL_GetError());
1060 SDL_DestroySurface(surface);
1061 surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
1062 SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
1063 surface != NULL ? "(success)" : SDL_GetError());
1064 SDL_DestroySurface(surface);
1065
1066 surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
1067 SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
1068 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1069 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1070 surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
1071 SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
1072 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1073 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1074
1075 surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 3);
1076 SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
1077 surface != NULL ? "(success)" : SDL_GetError());
1078 SDL_DestroySurface(surface);
1079 surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 3);
1080 SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
1081 surface != NULL ? "(success)" : SDL_GetError());
1082 SDL_DestroySurface(surface);
1083
1084 /* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */
1085 surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
1086 SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
1087 surface != NULL ? "(success)" : SDL_GetError());
1088 SDL_DestroySurface(surface);
1089 surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
1090 SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
1091 surface != NULL ? "(success)" : SDL_GetError());
1092 SDL_DestroySurface(surface);
1093
1094 surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
1095 SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
1096 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1097 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1098 surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
1099 SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
1100 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1101 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1102
1103 /* Everything else requires more than 1 byte per pixel, and rounds up
1104 * each pixel to an integer number of bytes (e.g. RGB555 is really
1105 * XRGB1555, with 1 bit per pixel wasted). */
1106 surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
1107 SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s",
1108 surface != NULL ? "(success)" : SDL_GetError());
1109 SDL_DestroySurface(surface);
1110 surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
1111 SDLTest_AssertCheck(surface != NULL, "5px * 15 (really 16) bits per px fits in 6 bytes: %s",
1112 surface != NULL ? "(success)" : SDL_GetError());
1113 SDL_DestroySurface(surface);
1114
1115 surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
1116 SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
1117 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1118 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1119 surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
1120 SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
1121 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1122 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1123
1124 if (sizeof(size_t) == 4 && sizeof(int) >= 4) {
1125 SDL_ClearError();
1126 expectedError = "aligning pitch would overflow";
1127 /* 0x5555'5555 * 3bpp = 0xffff'ffff which fits in size_t, but adding
1128 * alignment padding makes it overflow */
1129 surface = SDL_CreateSurface(0x55555555, 1, SDL_PIXELFORMAT_RGB24);
1130 SDLTest_AssertCheck(surface == NULL, "Should detect overflow in pitch + alignment");
1131 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1132 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1133 SDL_ClearError();
1134 expectedError = "width * bpp would overflow";
1135 /* 0x4000'0000 * 4bpp = 0x1'0000'0000 which (just) overflows */
1136 surface = SDL_CreateSurface(0x40000000, 1, SDL_PIXELFORMAT_ARGB8888);
1137 SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel");
1138 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1139 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1140 SDL_ClearError();
1141 expectedError = "height * pitch would overflow";
1142 surface = SDL_CreateSurface((1 << 29) - 1, (1 << 29) - 1, SDL_PIXELFORMAT_INDEX8);
1143 SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height");
1144 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1145 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1146 SDL_ClearError();
1147 expectedError = "height * pitch would overflow";
1148 surface = SDL_CreateSurface((1 << 15) + 1, (1 << 15) + 1, SDL_PIXELFORMAT_ARGB8888);
1149 SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel");
1150 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1151 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1152 } else {
1153 SDLTest_Log("Can't easily overflow size_t on this platform");
1154 }
1155
1156 return TEST_COMPLETED;
1157}
1158
1159static int SDLCALL surface_testFlip(void *arg)
1160{
1161 SDL_Surface *surface;
1162 Uint8 *pixels;
1163 int offset;
1164 const char *expectedError;
1165
1166 surface = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGB24);
1167 SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
1168
1169 SDL_ClearError();
1170 expectedError = "Parameter 'surface' is invalid";
1171 SDL_FlipSurface(NULL, SDL_FLIP_HORIZONTAL);
1172 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1173 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1174
1175 SDL_ClearError();
1176 expectedError = "Parameter 'flip' is invalid";
1177 SDL_FlipSurface(surface, SDL_FLIP_NONE);
1178 SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
1179 "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
1180
1181 pixels = (Uint8 *)surface->pixels;
1182 *pixels = 0xFF;
1183 offset = 0;
1184
1185 SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_VERTICAL)");
1186 CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_VERTICAL));
1187 SDLTest_AssertCheck(pixels[offset] == 0x00,
1188 "Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
1189 offset = 2 * surface->pitch;
1190 SDLTest_AssertCheck(pixels[offset] == 0xFF,
1191 "Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
1192
1193 SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_HORIZONTAL)");
1194 CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_HORIZONTAL));
1195 SDLTest_AssertCheck(pixels[offset] == 0x00,
1196 "Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
1197 offset += (surface->w - 1) * SDL_BYTESPERPIXEL(surface->format);
1198 SDLTest_AssertCheck(pixels[offset] == 0xFF,
1199 "Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
1200
1201 SDL_DestroySurface(surface);
1202
1203 return TEST_COMPLETED;
1204}
1205
1206static int SDLCALL surface_testPalette(void *arg)
1207{
1208 SDL_Surface *source, *surface, *output;
1209 SDL_Palette *palette;
1210 Uint8 *pixels;
1211
1212 palette = SDL_CreatePalette(2);
1213 SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
1214
1215 source = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
1216 SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
1217 SDLTest_AssertCheck(SDL_GetSurfacePalette(source) == NULL, "SDL_GetSurfacePalette(source)");
1218
1219 surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
1220 SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
1221 SDLTest_AssertCheck(SDL_GetSurfacePalette(surface) == NULL, "SDL_GetSurfacePalette(surface)");
1222
1223 pixels = (Uint8 *)surface->pixels;
1224 SDLTest_AssertCheck(*pixels == 0, "Expected *pixels == 0 got %u", *pixels);
1225
1226 /* Identity copy between indexed surfaces without a palette */
1227 *(Uint8 *)source->pixels = 1;
1228 SDL_BlitSurface(source, NULL, surface, NULL);
1229 SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
1230
1231 /* Identity copy between indexed surfaces where the source has a palette */
1232 palette->colors[0].r = 0;
1233 palette->colors[0].g = 0;
1234 palette->colors[0].b = 0;
1235 palette->colors[1].r = 0xFF;
1236 palette->colors[1].g = 0;
1237 palette->colors[1].b = 0;
1238 SDL_SetSurfacePalette(source, palette);
1239 *pixels = 0;
1240 SDL_BlitSurface(source, NULL, surface, NULL);
1241 SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
1242
1243 /* Identity copy between indexed surfaces where the destination has a palette */
1244 palette->colors[0].r = 0;
1245 palette->colors[0].g = 0;
1246 palette->colors[0].b = 0;
1247 palette->colors[1].r = 0xFF;
1248 palette->colors[1].g = 0;
1249 palette->colors[1].b = 0;
1250 SDL_SetSurfacePalette(source, NULL);
1251 SDL_SetSurfacePalette(surface, palette);
1252 *pixels = 0;
1253 SDL_BlitSurface(source, NULL, surface, NULL);
1254 SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
1255
1256 /* Identity copy between indexed surfaces where the source and destination share a palette */
1257 palette->colors[0].r = 0;
1258 palette->colors[0].g = 0;
1259 palette->colors[0].b = 0;
1260 palette->colors[1].r = 0xFF;
1261 palette->colors[1].g = 0;
1262 palette->colors[1].b = 0;
1263 SDL_SetSurfacePalette(source, palette);
1264 SDL_SetSurfacePalette(surface, palette);
1265 *pixels = 0;
1266 SDL_BlitSurface(source, NULL, surface, NULL);
1267 SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
1268
1269 output = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
1270 SDLTest_AssertCheck(output != NULL, "SDL_CreateSurface()");
1271
1272 pixels = (Uint8 *)output->pixels;
1273 SDL_BlitSurface(surface, NULL, output, NULL);
1274 SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
1275
1276 /* Set the palette color and blit again */
1277 palette->colors[1].r = 0xAA;
1278 SDL_SetSurfacePalette(surface, palette);
1279 SDL_BlitSurface(surface, NULL, output, NULL);
1280 SDLTest_AssertCheck(*pixels == 0xAA, "Expected *pixels == 0xAA got 0x%.2X", *pixels);
1281
1282 SDL_DestroyPalette(palette);
1283 SDL_DestroySurface(source);
1284 SDL_DestroySurface(surface);
1285 SDL_DestroySurface(output);
1286
1287 return TEST_COMPLETED;
1288}
1289
1290static int SDLCALL surface_testPalettization(void *arg)
1291{
1292 const SDL_Color palette_colors[] = {
1293 { 0x80, 0x00, 0x00, 0xff },
1294 { 0x00, 0x80, 0x00, 0xff },
1295 { 0x00, 0x00, 0x80, 0xff },
1296 { 0x40, 0x00, 0x00, 0xff },
1297 { 0x00, 0x40, 0x00, 0xff },
1298 { 0x00, 0x00, 0x40, 0xff },
1299 { 0x00, 0x00, 0x00, 0xff },
1300 { 0xff, 0x00, 0x00, 0xff },
1301 { 0x00, 0xff, 0x00, 0xff },
1302 { 0x00, 0x00, 0xff, 0xff },
1303 { 0xff, 0xff, 0x00, 0xff },
1304 { 0x00, 0xff, 0xff, 0xff },
1305 { 0xff, 0x00, 0xff, 0xff },
1306 };
1307 const struct {
1308 SDL_Color c;
1309 Uint8 e;
1310 } colors[] = {
1311 { { 0xff, 0x00, 0x00, 0xff }, 7 },
1312 { { 0xfe, 0x00, 0x00, 0xff }, 7 },
1313 { { 0xfd, 0x00, 0x00, 0xff }, 7 },
1314 { { 0xf0, 0x00, 0x00, 0xff }, 7 },
1315 { { 0xd0, 0x00, 0x00, 0xff }, 7 },
1316 { { 0xb0, 0x00, 0x00, 0xff }, 0 },
1317 { { 0xa0, 0x00, 0x00, 0xff }, 0 },
1318 { { 0xff, 0x00, 0x00, 0x00 }, 7 },
1319 { { 0x00, 0x10, 0x21, 0xff }, 5 },
1320 { { 0x00, 0x10, 0x19, 0xff }, 6 },
1321 { { 0x81, 0x00, 0x41, 0xff }, 0 },
1322 { { 0x80, 0xf0, 0xf0, 0x7f }, 11 },
1323 { { 0x00, 0x00, 0x00, 0xff }, 6 },
1324 { { 0x00, 0x00, 0x00, 0x01 }, 6 },
1325 };
1326 int i;
1327 int result;
1328 SDL_Surface *source, *output;
1329 SDL_Palette *palette;
1330 Uint8 *pixels;
1331
1332 palette = SDL_CreatePalette(SDL_arraysize(palette_colors));
1333 SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
1334
1335 result = SDL_SetPaletteColors(palette, palette_colors, 0, SDL_arraysize(palette_colors));
1336 SDLTest_AssertCheck(result, "SDL_SetPaletteColors()");
1337
1338 source = SDL_CreateSurface(SDL_arraysize(palette_colors) + SDL_arraysize(colors), 1, SDL_PIXELFORMAT_RGBA8888);
1339 SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
1340 SDLTest_AssertCheck(source->w == SDL_arraysize(palette_colors) + SDL_arraysize(colors), "Expected source->w == %d, got %d", (int)(SDL_arraysize(palette_colors) + SDL_arraysize(colors)), source->w);
1341 SDLTest_AssertCheck(source->h == 1, "Expected source->h == %d, got %d", 1, source->h);
1342 SDLTest_AssertCheck(source->format == SDL_PIXELFORMAT_RGBA8888, "Expected source->format == SDL_PIXELFORMAT_RGBA8888, got 0x%x (%s)", source->format, SDL_GetPixelFormatName(source->format));
1343 for (i = 0; i < SDL_arraysize(colors); i++) {
1344 result = SDL_WriteSurfacePixel(source, i, 0, colors[i].c.r, colors[i].c.g, colors[i].c.b, colors[i].c.a);
1345 SDLTest_AssertCheck(result == true, "SDL_WriteSurfacePixel");
1346 }
1347 for (i = 0; i < SDL_arraysize(palette_colors); i++) {
1348 result = SDL_WriteSurfacePixel(source, SDL_arraysize(colors) + i, 0, palette_colors[i].r, palette_colors[i].g, palette_colors[i].b, palette_colors[i].a);
1349 SDLTest_AssertCheck(result == true, "SDL_WriteSurfacePixel");
1350 }
1351
1352 output = SDL_ConvertSurfaceAndColorspace(source, SDL_PIXELFORMAT_INDEX8, palette, SDL_COLORSPACE_UNKNOWN, 0);
1353 SDLTest_AssertCheck(output != NULL, "SDL_ConvertSurfaceAndColorspace()");
1354 SDLTest_AssertCheck(output->w == source->w, "Expected output->w == %d, got %d", source->w, output->w);
1355 SDLTest_AssertCheck(output->h == source->h, "Expected output->h == %d, got %d", source->h, output->h);
1356 SDLTest_AssertCheck(output->format == SDL_PIXELFORMAT_INDEX8, "Expected output->format == SDL_PIXELFORMAT_INDEX8, got 0x%x (%s)", output->format, SDL_GetPixelFormatName(output->format));
1357
1358 pixels = output->pixels;
1359 for (i = 0; i < SDL_arraysize(colors); i++) {
1360 int idx = i;
1361 Uint8 actual = pixels[idx];
1362 Uint8 expected = colors[i].e;
1363 SDLTest_AssertCheck(actual < SDL_arraysize(palette_colors), "output->pixels[%d] < %d", idx, (int)SDL_arraysize(palette_colors));
1364 SDLTest_AssertCheck(actual == expected, "Expected output->pixels[%d] == %u, got %u", idx, expected, actual);
1365 }
1366 SDLTest_AssertPass("Check palette 1:1 mapping");
1367 for (i = 0; i < SDL_arraysize(palette_colors); i++) {
1368 int idx = SDL_arraysize(colors) + i;
1369 Uint8 actual = pixels[idx];
1370 Uint8 expected = i;
1371 SDLTest_AssertCheck(actual < SDL_arraysize(palette_colors), "output->pixels[%d] < %d", idx, (int)SDL_arraysize(palette_colors));
1372 SDLTest_AssertCheck(actual == expected, "Expected output->pixels[%d] == %u, got %u", idx, expected, actual);
1373 }
1374 SDL_DestroyPalette(palette);
1375 SDL_DestroySurface(source);
1376 SDL_DestroySurface(output);
1377
1378 return TEST_COMPLETED;
1379}
1380
1381static int SDLCALL surface_testClearSurface(void *arg)
1382{
1383 SDL_PixelFormat formats[] = {
1384 SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
1385 SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
1386 SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
1387 SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
1388 SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_NV12
1389 };
1390 SDL_Surface *surface;
1391 SDL_PixelFormat format;
1392 const float MAXIMUM_ERROR_RGB = 0.0001f;
1393 const float MAXIMUM_ERROR_YUV = 0.01f;
1394 float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 1.0f;
1395 float actualR, actualG, actualB, actualA;
1396 float deltaR, deltaG, deltaB, deltaA;
1397 int i, ret;
1398
1399 for (i = 0; i < SDL_arraysize(formats); ++i) {
1400 const float MAXIMUM_ERROR = SDL_ISPIXELFORMAT_FOURCC(formats[i]) ? MAXIMUM_ERROR_YUV : MAXIMUM_ERROR_RGB;
1401
1402 format = formats[i];
1403
1404 surface = SDL_CreateSurface(1, 1, format);
1405 SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
1406 ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
1407 SDLTest_AssertCheck(ret == true, "SDL_ClearSurface()");
1408 ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, &actualA);
1409 SDLTest_AssertCheck(ret == true, "SDL_ReadSurfacePixelFloat()");
1410 deltaR = SDL_fabsf(actualR - srcR);
1411 deltaG = SDL_fabsf(actualG - srcG);
1412 deltaB = SDL_fabsf(actualB - srcB);
1413 deltaA = SDL_fabsf(actualA - srcA);
1414 SDLTest_AssertCheck(
1415 deltaR <= MAXIMUM_ERROR &&
1416 deltaG <= MAXIMUM_ERROR &&
1417 deltaB <= MAXIMUM_ERROR &&
1418 deltaA <= MAXIMUM_ERROR,
1419 "Checking %s surface clear results, expected %.4f,%.4f,%.4f,%.4f, got %.4f,%.4f,%.4f,%.4f",
1420 SDL_GetPixelFormatName(format),
1421 srcR, srcG, srcB, srcA, actualR, actualG, actualB, actualA);
1422
1423 SDL_DestroySurface(surface);
1424 }
1425
1426 return TEST_COMPLETED;
1427}
1428
1429static int SDLCALL surface_testPremultiplyAlpha(void *arg)
1430{
1431 SDL_PixelFormat formats[] = {
1432 SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
1433 SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
1434 SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
1435 SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
1436 };
1437 SDL_Surface *surface;
1438 SDL_PixelFormat format;
1439 const float MAXIMUM_ERROR_LOW_PRECISION = 1 / 255.0f;
1440 const float MAXIMUM_ERROR_HIGH_PRECISION = 0.0001f;
1441 float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 170 / 255.0f;
1442 float expectedR = srcR * srcA;
1443 float expectedG = srcG * srcA;
1444 float expectedB = srcB * srcA;
1445 float actualR, actualG, actualB;
1446 float deltaR, deltaG, deltaB;
1447 int i, ret;
1448
1449 for (i = 0; i < SDL_arraysize(formats); ++i) {
1450 const float MAXIMUM_ERROR = (SDL_BITSPERPIXEL(formats[i]) > 32) ? MAXIMUM_ERROR_HIGH_PRECISION : MAXIMUM_ERROR_LOW_PRECISION;
1451
1452 format = formats[i];
1453
1454 surface = SDL_CreateSurface(1, 1, format);
1455 SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
1456 ret = SDL_SetSurfaceColorspace(surface, SDL_COLORSPACE_SRGB);
1457 SDLTest_AssertCheck(ret == true, "SDL_SetSurfaceColorspace()");
1458 ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
1459 SDLTest_AssertCheck(ret == true, "SDL_ClearSurface()");
1460 ret = SDL_PremultiplySurfaceAlpha(surface, false);
1461 SDLTest_AssertCheck(ret == true, "SDL_PremultiplySurfaceAlpha()");
1462 ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, NULL);
1463 SDLTest_AssertCheck(ret == true, "SDL_ReadSurfacePixelFloat()");
1464 deltaR = SDL_fabsf(actualR - expectedR);
1465 deltaG = SDL_fabsf(actualG - expectedG);
1466 deltaB = SDL_fabsf(actualB - expectedB);
1467 SDLTest_AssertCheck(
1468 deltaR <= MAXIMUM_ERROR &&
1469 deltaG <= MAXIMUM_ERROR &&
1470 deltaB <= MAXIMUM_ERROR,
1471 "Checking %s alpha premultiply results, expected %.4f,%.4f,%.4f, got %.4f,%.4f,%.4f",
1472 SDL_GetPixelFormatName(format),
1473 expectedR, expectedG, expectedB, actualR, actualG, actualB);
1474
1475 SDL_DestroySurface(surface);
1476 }
1477
1478 return TEST_COMPLETED;
1479}
1480
1481
1482static int SDLCALL surface_testScale(void *arg)
1483{
1484 SDL_PixelFormat formats[] = {
1485 SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
1486 SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
1487 SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
1488 SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
1489 };
1490 SDL_ScaleMode modes[] = {
1491 SDL_SCALEMODE_NEAREST, SDL_SCALEMODE_LINEAR
1492 };
1493 SDL_Surface *surface, *result;
1494 SDL_PixelFormat format;
1495 SDL_ScaleMode mode;
1496 const float MAXIMUM_ERROR = 0.0001f;
1497 float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 170 / 255.0f;
1498 float actualR, actualG, actualB, actualA;
1499 float deltaR, deltaG, deltaB, deltaA;
1500 int i, j, ret;
1501
1502 for (i = 0; i < SDL_arraysize(formats); ++i) {
1503 for (j = 0; j < SDL_arraysize(modes); ++j) {
1504 format = formats[i];
1505 mode = modes[j];
1506
1507 surface = SDL_CreateSurface(1, 1, format);
1508 SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
1509 ret = SDL_SetSurfaceColorspace(surface, SDL_COLORSPACE_SRGB);
1510 SDLTest_AssertCheck(ret == true, "SDL_SetSurfaceColorspace()");
1511 ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
1512 SDLTest_AssertCheck(ret == true, "SDL_ClearSurface()");
1513 result = SDL_ScaleSurface(surface, 2, 2, mode);
1514 SDLTest_AssertCheck(ret == true, "SDL_PremultiplySurfaceAlpha()");
1515 ret = SDL_ReadSurfacePixelFloat(result, 1, 1, &actualR, &actualG, &actualB, &actualA);
1516 SDLTest_AssertCheck(ret == true, "SDL_ReadSurfacePixelFloat()");
1517 deltaR = SDL_fabsf(actualR - srcR);
1518 deltaG = SDL_fabsf(actualG - srcG);
1519 deltaB = SDL_fabsf(actualB - srcB);
1520 deltaA = SDL_fabsf(actualA - srcA);
1521 SDLTest_AssertCheck(
1522 deltaR <= MAXIMUM_ERROR &&
1523 deltaG <= MAXIMUM_ERROR &&
1524 deltaB <= MAXIMUM_ERROR &&
1525 deltaA <= MAXIMUM_ERROR,
1526 "Checking %s %s scaling results, expected %.4f,%.4f,%.4f,%.4f got %.4f,%.4f,%.4f,%.4f",
1527 SDL_GetPixelFormatName(format),
1528 mode == SDL_SCALEMODE_NEAREST ? "nearest" : "linear",
1529 srcR, srcG, srcB, srcA, actualR, actualG, actualB, actualA);
1530
1531 SDL_DestroySurface(surface);
1532 SDL_DestroySurface(result);
1533 }
1534 }
1535
1536 return TEST_COMPLETED;
1537}
1538
1539
1540/* ================= Test References ================== */
1541
1542/* Surface test cases */
1543static const SDLTest_TestCaseReference surfaceTestSaveLoadBitmap = {
1544 surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
1545};
1546
1547static const SDLTest_TestCaseReference surfaceTestBlitZeroSource = {
1548 surface_testBlitZeroSource, "surface_testBlitZeroSource", "Tests blitting from a zero sized source rectangle", TEST_ENABLED
1549};
1550
1551static const SDLTest_TestCaseReference surfaceTestBlit = {
1552 surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED
1553};
1554
1555static const SDLTest_TestCaseReference surfaceTestBlitTiled = {
1556 surface_testBlitTiled, "surface_testBlitTiled", "Tests tiled blitting.", TEST_ENABLED
1557};
1558
1559static const SDLTest_TestCaseReference surfaceTestBlit9Grid = {
1560 surface_testBlit9Grid, "surface_testBlit9Grid", "Tests 9-grid blitting.", TEST_ENABLED
1561};
1562
1563static const SDLTest_TestCaseReference surfaceTestBlitMultiple = {
1564 surface_testBlitMultiple, "surface_testBlitMultiple", "Tests blitting between multiple surfaces of the same format.", TEST_ENABLED
1565};
1566
1567static const SDLTest_TestCaseReference surfaceTestLoadFailure = {
1568 surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED
1569};
1570
1571static const SDLTest_TestCaseReference surfaceTestSurfaceConversion = {
1572 surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED
1573};
1574
1575static const SDLTest_TestCaseReference surfaceTestCompleteSurfaceConversion = {
1576 surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED
1577};
1578
1579static const SDLTest_TestCaseReference surfaceTestBlitColorMod = {
1580 surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED
1581};
1582
1583static const SDLTest_TestCaseReference surfaceTestBlitAlphaMod = {
1584 surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED
1585};
1586
1587static const SDLTest_TestCaseReference surfaceTestBlitBlendBlend = {
1588 surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_ENABLED
1589};
1590
1591static const SDLTest_TestCaseReference surfaceTestBlitBlendPremultiplied = {
1592 surface_testBlitBlendPremultiplied, "surface_testBlitBlendPremultiplied", "Tests blitting routines with premultiplied blending mode.", TEST_ENABLED
1593};
1594
1595static const SDLTest_TestCaseReference surfaceTestBlitBlendAdd = {
1596 surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_ENABLED
1597};
1598
1599static const SDLTest_TestCaseReference surfaceTestBlitBlendAddPremultiplied = {
1600 surface_testBlitBlendAddPremultiplied, "surface_testBlitBlendAddPremultiplied", "Tests blitting routines with premultiplied add blending mode.", TEST_ENABLED
1601};
1602
1603static const SDLTest_TestCaseReference surfaceTestBlitBlendMod = {
1604 surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED
1605};
1606
1607static const SDLTest_TestCaseReference surfaceTestBlitBlendMul = {
1608 surface_testBlitBlendMul, "surface_testBlitBlendMul", "Tests blitting routines with mul blending mode.", TEST_ENABLED
1609};
1610
1611static const SDLTest_TestCaseReference surfaceTestOverflow = {
1612 surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED
1613};
1614
1615static const SDLTest_TestCaseReference surfaceTestFlip = {
1616 surface_testFlip, "surface_testFlip", "Test surface flipping.", TEST_ENABLED
1617};
1618
1619static const SDLTest_TestCaseReference surfaceTestPalette = {
1620 surface_testPalette, "surface_testPalette", "Test surface palette operations.", TEST_ENABLED
1621};
1622
1623static const SDLTest_TestCaseReference surfaceTestPalettization = {
1624 surface_testPalettization, "surface_testPalettization", "Test surface palettization.", TEST_ENABLED
1625};
1626
1627static const SDLTest_TestCaseReference surfaceTestClearSurface = {
1628 surface_testClearSurface, "surface_testClearSurface", "Test clear surface operations.", TEST_ENABLED
1629};
1630
1631static const SDLTest_TestCaseReference surfaceTestPremultiplyAlpha = {
1632 surface_testPremultiplyAlpha, "surface_testPremultiplyAlpha", "Test alpha premultiply operations.", TEST_ENABLED
1633};
1634
1635static const SDLTest_TestCaseReference surfaceTestScale = {
1636 surface_testScale, "surface_testScale", "Test scaling operations.", TEST_ENABLED
1637};
1638
1639/* Sequence of Surface test cases */
1640static const SDLTest_TestCaseReference *surfaceTests[] = {
1641 &surfaceTestSaveLoadBitmap,
1642 &surfaceTestBlitZeroSource,
1643 &surfaceTestBlit,
1644 &surfaceTestBlitTiled,
1645 &surfaceTestBlit9Grid,
1646 &surfaceTestBlitMultiple,
1647 &surfaceTestLoadFailure,
1648 &surfaceTestSurfaceConversion,
1649 &surfaceTestCompleteSurfaceConversion,
1650 &surfaceTestBlitColorMod,
1651 &surfaceTestBlitAlphaMod,
1652 &surfaceTestBlitBlendBlend,
1653 &surfaceTestBlitBlendPremultiplied,
1654 &surfaceTestBlitBlendAdd,
1655 &surfaceTestBlitBlendAddPremultiplied,
1656 &surfaceTestBlitBlendMod,
1657 &surfaceTestBlitBlendMul,
1658 &surfaceTestOverflow,
1659 &surfaceTestFlip,
1660 &surfaceTestPalette,
1661 &surfaceTestPalettization,
1662 &surfaceTestClearSurface,
1663 &surfaceTestPremultiplyAlpha,
1664 &surfaceTestScale,
1665 NULL
1666};
1667
1668/* Surface test suite (global) */
1669SDLTest_TestSuiteReference surfaceTestSuite = {
1670 "Surface",
1671 surfaceSetUp,
1672 surfaceTests,
1673 surfaceTearDown
1674
1675};