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