Mercurial > sdl-ios-xcode
comparison test/automated/render/render.c @ 3735:27b4b4d71011 gsoc2009_unit_tests
Test for capabilities for each test.
Divided into more tests to match capabilities.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Mon, 20 Jul 2009 18:07:29 +0000 |
parents | 42356acbc993 |
children | c875baafce36 |
comparison
equal
deleted
inserted
replaced
3734:42356acbc993 | 3735:27b4b4d71011 |
---|---|
28 | 28 |
29 /* | 29 /* |
30 * Prototypes. | 30 * Prototypes. |
31 */ | 31 */ |
32 static int render_compare( const char *msg, const SurfaceImage_t *s ); | 32 static int render_compare( const char *msg, const SurfaceImage_t *s ); |
33 static int render_hasDrawColor (void); | |
34 static int render_hasBlendModes (void); | |
35 static int render_hasTexColor (void); | |
36 static int render_hasTexAlpha (void); | |
33 static int render_clearScreen (void); | 37 static int render_clearScreen (void); |
34 /* Testcases. */ | 38 /* Testcases. */ |
35 static int render_testPrimitives (void); | 39 static int render_testPrimitives (void); |
36 static int render_testPrimitivesBlend (void); | 40 static int render_testPrimitivesBlend (void); |
37 static int render_testBlit (void); | 41 static int render_testBlit (void); |
42 static int render_testBlitColour (void); | |
43 static int render_testBlitAlpha (void); | |
38 static int render_testBlitBlendMode( SDL_TextureID tface, int mode ); | 44 static int render_testBlitBlendMode( SDL_TextureID tface, int mode ); |
39 static int render_testBlitBlend (void); | 45 static int render_testBlitBlend (void); |
40 | 46 |
41 | 47 |
42 /** | 48 /** |
43 * Compares screen pixels with image pixels. | 49 * @brief Compares screen pixels with image pixels. |
50 * | |
51 * @param msg Message on failure. | |
52 * @param s Image to compare against. | |
53 * @return 0 on success. | |
44 */ | 54 */ |
45 static int render_compare( const char *msg, const SurfaceImage_t *s ) | 55 static int render_compare( const char *msg, const SurfaceImage_t *s ) |
46 { | 56 { |
47 (void) msg; | 57 (void) msg; |
48 (void) s; | 58 (void) s; |
73 return 1; | 83 return 1; |
74 | 84 |
75 /* Clean up. */ | 85 /* Clean up. */ |
76 SDL_FreeSurface( testsur ); | 86 SDL_FreeSurface( testsur ); |
77 free(pix); | 87 free(pix); |
78 | |
79 #endif | 88 #endif |
80 | 89 |
81 return 0; | 90 return 0; |
82 } | 91 } |
83 | 92 |
93 | |
94 /** | |
95 * @brief Test to see if we can vary the draw colour. | |
96 */ | |
97 static int render_hasDrawColor (void) | |
98 { | |
99 int ret; | |
100 Uint8 r, g, b, a; | |
101 | |
102 /* Set colour. */ | |
103 ret = SDL_SetRenderDrawColor( 100, 100, 100, 100 ); | |
104 ret |= SDL_GetRenderDrawColor( &r, &g, &b, &a ); | |
105 /* Restore natural. */ | |
106 ret |= SDL_SetRenderDrawColor( 0, 0, 0, SDL_ALPHA_OPAQUE ); | |
107 | |
108 /* Something failed, consider not available. */ | |
109 if (ret != 0) | |
110 return 0; | |
111 /* Not set properly, consider failed. */ | |
112 else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) | |
113 return 0; | |
114 return 1; | |
115 } | |
116 | |
117 | |
118 /** | |
119 * @brief Test to see if we can vary the blend mode. | |
120 */ | |
121 static int render_hasBlendModes (void) | |
122 { | |
123 int ret; | |
124 int mode; | |
125 | |
126 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); | |
127 ret |= SDL_GetRenderDrawBlendMode( &mode ); | |
128 ret |= (mode != SDL_BLENDMODE_BLEND); | |
129 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); | |
130 ret |= SDL_GetRenderDrawBlendMode( &mode ); | |
131 ret |= (mode != SDL_BLENDMODE_ADD); | |
132 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); | |
133 ret |= SDL_GetRenderDrawBlendMode( &mode ); | |
134 ret |= (mode != SDL_BLENDMODE_MOD); | |
135 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MASK ); | |
136 ret |= SDL_GetRenderDrawBlendMode( &mode ); | |
137 ret |= (mode != SDL_BLENDMODE_MASK); | |
138 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); | |
139 ret |= SDL_GetRenderDrawBlendMode( &mode ); | |
140 ret |= (mode != SDL_BLENDMODE_NONE); | |
141 | |
142 return !ret; | |
143 } | |
144 | |
145 | |
146 /** | |
147 * @brief Loads the test face. | |
148 */ | |
149 static SDL_TextureID render_loadTestFace (void) | |
150 { | |
151 SDL_Surface *face; | |
152 SDL_TextureID tface; | |
153 | |
154 /* Create face surface. */ | |
155 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, | |
156 img_face.width, img_face.height, 32, img_face.width*4, | |
157 RMASK, GMASK, BMASK, AMASK ); | |
158 if (face == NULL) | |
159 return 0; | |
160 tface = SDL_CreateTextureFromSurface( 0, face ); | |
161 SDL_FreeSurface(face); | |
162 | |
163 return tface; | |
164 } | |
165 | |
166 | |
167 /** | |
168 * @brief Test to see if can set texture colour mode. | |
169 */ | |
170 static int render_hasTexColor (void) | |
171 { | |
172 int ret; | |
173 SDL_TextureID tface; | |
174 Uint8 r, g, b; | |
175 | |
176 /* Get test face. */ | |
177 tface = render_loadTestFace(); | |
178 if (tface == 0) | |
179 return 0; | |
180 | |
181 /* See if supported. */ | |
182 ret = SDL_SetTextureColorMod( tface, 100, 100, 100 ); | |
183 ret |= SDL_GetTextureColorMod( tface, &r, &g, &b ); | |
184 | |
185 /* Clean up. */ | |
186 SDL_DestroyTexture( tface ); | |
187 | |
188 if (ret) | |
189 return 0; | |
190 else if ((r != 100) || (g != 100) || (b != 100)) | |
191 return 0; | |
192 return 1; | |
193 } | |
194 | |
195 | |
196 /** | |
197 * @brief Test to see if we can vary the alpha of the texture. | |
198 */ | |
199 static int render_hasTexAlpha (void) | |
200 { | |
201 int ret; | |
202 SDL_TextureID tface; | |
203 Uint8 a; | |
204 | |
205 /* Get test face. */ | |
206 tface = render_loadTestFace(); | |
207 if (tface == 0) | |
208 return 0; | |
209 | |
210 /* See if supported. */ | |
211 ret = SDL_SetTextureAlphaMod( tface, 100 ); | |
212 ret |= SDL_GetTextureAlphaMod( tface, &a ); | |
213 | |
214 /* Clean up. */ | |
215 SDL_DestroyTexture( tface ); | |
216 | |
217 if (ret) | |
218 return 0; | |
219 else if (a != 100) | |
220 return 0; | |
221 return 1; | |
222 } | |
223 | |
224 | |
84 /** | 225 /** |
85 * @brief Clears the screen. | 226 * @brief Clears the screen. |
227 * | |
228 * @note We don't test for errors, but they shouldn't happen. | |
86 */ | 229 */ |
87 static int render_clearScreen (void) | 230 static int render_clearScreen (void) |
88 { | 231 { |
89 int ret; | 232 int ret; |
90 | 233 |
91 /* Set colour. */ | 234 /* Set colour. */ |
92 ret = SDL_SetRenderDrawColor( 0, 0, 0, SDL_ALPHA_OPAQUE ); | 235 ret = SDL_SetRenderDrawColor( 0, 0, 0, SDL_ALPHA_OPAQUE ); |
93 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 236 /* |
94 return -1; | 237 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
238 return -1; | |
239 */ | |
95 | 240 |
96 /* Clear screen. */ | 241 /* Clear screen. */ |
97 ret = SDL_RenderFill( NULL ); | 242 ret = SDL_RenderFill( NULL ); |
243 /* | |
98 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) | 244 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) |
99 return -1; | 245 return -1; |
246 */ | |
100 | 247 |
101 /* Set defaults. */ | 248 /* Set defaults. */ |
102 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); | 249 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); |
250 /* | |
103 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 251 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
104 return -1; | 252 return -1; |
253 */ | |
105 ret = SDL_SetRenderDrawColor( 255, 255, 255, SDL_ALPHA_OPAQUE ); | 254 ret = SDL_SetRenderDrawColor( 255, 255, 255, SDL_ALPHA_OPAQUE ); |
106 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 255 /* |
107 return -1; | 256 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
257 return -1; | |
258 */ | |
108 | 259 |
109 return 0; | 260 return 0; |
110 } | 261 } |
111 | 262 |
112 | 263 |
120 SDL_Rect rect; | 271 SDL_Rect rect; |
121 | 272 |
122 /* Clear surface. */ | 273 /* Clear surface. */ |
123 if (render_clearScreen()) | 274 if (render_clearScreen()) |
124 return -1; | 275 return -1; |
276 | |
277 /* Need drawcolour or just skip test. */ | |
278 if (!render_hasDrawColor()) | |
279 return 0; | |
125 | 280 |
126 /* Draw a rectangle. */ | 281 /* Draw a rectangle. */ |
127 rect.x = 40; | 282 rect.x = 40; |
128 rect.y = 0; | 283 rect.y = 0; |
129 rect.w = 40; | 284 rect.w = 40; |
202 | 357 |
203 /* Clear surface. */ | 358 /* Clear surface. */ |
204 if (render_clearScreen()) | 359 if (render_clearScreen()) |
205 return -1; | 360 return -1; |
206 | 361 |
207 /* See if we can actually run the test. */ | 362 /* Need drawcolour and blendmode or just skip test. */ |
208 #if 0 | 363 if (!render_hasDrawColor() || !render_hasBlendModes()) |
209 ret = 0; | 364 return 0; |
210 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); | |
211 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); | |
212 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); | |
213 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); | |
214 if (ret != 0) | |
215 return -1; | |
216 #endif | |
217 | 365 |
218 /* Create some rectangles for each blend mode. */ | 366 /* Create some rectangles for each blend mode. */ |
219 ret = SDL_SetRenderDrawColor( 255, 255, 255, 0 ); | 367 ret = SDL_SetRenderDrawColor( 255, 255, 255, 0 ); |
220 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 368 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
221 return -1; | 369 return -1; |
328 | 476 |
329 /* Clear surface. */ | 477 /* Clear surface. */ |
330 if (render_clearScreen()) | 478 if (render_clearScreen()) |
331 return -1; | 479 return -1; |
332 | 480 |
481 /* Need drawcolour or just skip test. */ | |
482 if (!render_hasDrawColor()) | |
483 return 0; | |
484 | |
333 /* Create face surface. */ | 485 /* Create face surface. */ |
334 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, | 486 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, |
335 img_face.width, img_face.height, 32, img_face.width*4, | 487 img_face.width, img_face.height, 32, img_face.width*4, |
336 RMASK, GMASK, BMASK, AMASK ); | 488 RMASK, GMASK, BMASK, AMASK ); |
337 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) | 489 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) |
359 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) | 511 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) |
360 return -1; | 512 return -1; |
361 } | 513 } |
362 } | 514 } |
363 | 515 |
516 /* Clean up. */ | |
517 SDL_DestroyTexture( tface ); | |
518 | |
364 /* See if it's the same. */ | 519 /* See if it's the same. */ |
365 if (render_compare( "Blit output not the same.", &img_blit )) | 520 if (render_compare( "Blit output not the same.", &img_blit )) |
366 return -1; | 521 return -1; |
367 | 522 |
523 return 0; | |
524 } | |
525 | |
526 | |
527 /** | |
528 * @brief Blits doing colour tests. | |
529 */ | |
530 static int render_testBlitColour (void) | |
531 { | |
532 int ret; | |
533 SDL_Rect rect; | |
534 SDL_Surface *face; | |
535 SDL_TextureID tface; | |
536 int i, j, ni, nj; | |
537 | |
368 /* Clear surface. */ | 538 /* Clear surface. */ |
369 if (render_clearScreen()) | 539 if (render_clearScreen()) |
370 return -1; | 540 return -1; |
541 | |
542 /* Need drawcolour or just skip test. */ | |
543 if (!render_hasTexColor()) | |
544 return 0; | |
545 | |
546 /* Create face surface. */ | |
547 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, | |
548 img_face.width, img_face.height, 32, img_face.width*4, | |
549 RMASK, GMASK, BMASK, AMASK ); | |
550 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) | |
551 return -1; | |
552 tface = SDL_CreateTextureFromSurface( 0, face ); | |
553 if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0)) | |
554 return -1; | |
555 | |
556 /* Clean up. */ | |
557 SDL_FreeSurface( face ); | |
558 | |
559 /* Constant values. */ | |
560 rect.w = face->w; | |
561 rect.h = face->h; | |
562 ni = SCREEN_W - face->w; | |
563 nj = SCREEN_H - face->h; | |
371 | 564 |
372 /* Test blitting with colour mod. */ | 565 /* Test blitting with colour mod. */ |
373 for (j=0; j <= nj; j+=4) { | 566 for (j=0; j <= nj; j+=4) { |
374 for (i=0; i <= ni; i+=4) { | 567 for (i=0; i <= ni; i+=4) { |
375 /* Set colour mod. */ | 568 /* Set colour mod. */ |
384 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) | 577 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) |
385 return -1; | 578 return -1; |
386 } | 579 } |
387 } | 580 } |
388 | 581 |
582 /* Clean up. */ | |
583 SDL_DestroyTexture( tface ); | |
584 | |
389 /* See if it's the same. */ | 585 /* See if it's the same. */ |
390 if (render_compare( "Blit output not the same (using SDL_SetTextureColorMod).", | 586 if (render_compare( "Blit output not the same (using SDL_SetTextureColorMod).", |
391 &img_blitColour )) | 587 &img_blitColour )) |
392 return -1; | 588 return -1; |
393 | 589 |
590 return 0; | |
591 } | |
592 | |
593 | |
594 /** | |
595 * @brief Tests blitting with alpha. | |
596 */ | |
597 static int render_testBlitAlpha (void) | |
598 { | |
599 int ret; | |
600 SDL_Rect rect; | |
601 SDL_Surface *face; | |
602 SDL_TextureID tface; | |
603 int i, j, ni, nj; | |
604 | |
394 /* Clear surface. */ | 605 /* Clear surface. */ |
395 if (render_clearScreen()) | 606 if (render_clearScreen()) |
396 return -1; | 607 return -1; |
397 | 608 |
398 /* Restore colour. */ | 609 /* Need alpha or just skip test. */ |
399 ret = SDL_SetTextureColorMod( tface, 255, 255, 255 ); | 610 if (!render_hasTexAlpha()) |
400 if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0)) | 611 return 0; |
401 return -1; | 612 |
402 | 613 /* Create face surface. */ |
403 /* Test blitting with colour mod. */ | 614 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, |
615 img_face.width, img_face.height, 32, img_face.width*4, | |
616 RMASK, GMASK, BMASK, AMASK ); | |
617 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) | |
618 return -1; | |
619 tface = SDL_CreateTextureFromSurface( 0, face ); | |
620 if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0)) | |
621 return -1; | |
622 | |
623 /* Clean up. */ | |
624 SDL_FreeSurface( face ); | |
625 | |
626 /* Constant values. */ | |
627 rect.w = face->w; | |
628 rect.h = face->h; | |
629 ni = SCREEN_W - face->w; | |
630 nj = SCREEN_H - face->h; | |
631 | |
632 /* Clear surface. */ | |
633 if (render_clearScreen()) | |
634 return -1; | |
635 | |
636 /* Test blitting with alpha mod. */ | |
404 for (j=0; j <= nj; j+=4) { | 637 for (j=0; j <= nj; j+=4) { |
405 for (i=0; i <= ni; i+=4) { | 638 for (i=0; i <= ni; i+=4) { |
406 /* Set alpha mod. */ | 639 /* Set alpha mod. */ |
407 ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i ); | 640 ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i ); |
408 if (SDL_ATassert( "SDL_SetTextureAlphaMod", ret == 0)) | 641 if (SDL_ATassert( "SDL_SetTextureAlphaMod", ret == 0)) |
415 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) | 648 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) |
416 return -1; | 649 return -1; |
417 } | 650 } |
418 } | 651 } |
419 | 652 |
653 /* Clean up. */ | |
654 SDL_DestroyTexture( tface ); | |
655 | |
420 /* See if it's the same. */ | 656 /* See if it's the same. */ |
421 if (render_compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).", | 657 if (render_compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).", |
422 &img_blitAlpha )) | 658 &img_blitAlpha )) |
423 return -1; | 659 return -1; |
424 | |
425 /* Clean up. */ | |
426 SDL_DestroyTexture( tface ); | |
427 | 660 |
428 return 0; | 661 return 0; |
429 } | 662 } |
430 | 663 |
431 | 664 |
484 int mode; | 717 int mode; |
485 | 718 |
486 /* Clear surface. */ | 719 /* Clear surface. */ |
487 if (render_clearScreen()) | 720 if (render_clearScreen()) |
488 return -1; | 721 return -1; |
722 | |
723 /* Need drawcolour and blendmode or just skip test. */ | |
724 if (!render_hasBlendModes() || !render_hasTexColor() || !render_hasTexAlpha()) | |
725 return 0; | |
489 | 726 |
490 /* Create face surface. */ | 727 /* Create face surface. */ |
491 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, | 728 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, |
492 img_face.width, img_face.height, 32, img_face.width*4, | 729 img_face.width, img_face.height, 32, img_face.width*4, |
493 RMASK, GMASK, BMASK, AMASK ); | 730 RMASK, GMASK, BMASK, AMASK ); |
579 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) | 816 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) |
580 return -1; | 817 return -1; |
581 } | 818 } |
582 } | 819 } |
583 | 820 |
821 /* Clean up. */ | |
822 SDL_DestroyTexture( tface ); | |
823 | |
584 /* Check to see if matches. */ | 824 /* Check to see if matches. */ |
585 if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_*).", | 825 if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_*).", |
586 &img_blendAll )) | 826 &img_blendAll )) |
587 return -1; | 827 return -1; |
588 | 828 |
589 /* Clean up. */ | |
590 SDL_DestroyTexture( tface ); | |
591 | |
592 return 0; | 829 return 0; |
593 } | 830 } |
594 | 831 |
595 | 832 |
596 /** | 833 /** |
604 | 841 |
605 /* No error. */ | 842 /* No error. */ |
606 ret = 0; | 843 ret = 0; |
607 | 844 |
608 /* Software surface blitting. */ | 845 /* Software surface blitting. */ |
609 ret |= render_testPrimitives(); | 846 ret = render_testPrimitives(); |
610 if (ret) | 847 if (ret) |
611 return -1; | 848 return -1; |
612 ret |= render_testPrimitivesBlend(); | 849 ret = render_testPrimitivesBlend(); |
613 if (ret) | 850 if (ret) |
614 return -1; | 851 return -1; |
615 ret |= render_testBlit(); | 852 ret = render_testBlit(); |
616 if (ret) | 853 if (ret) |
617 return -1; | 854 return -1; |
618 ret |= render_testBlitBlend(); | 855 ret = render_testBlitColour(); |
856 if (ret) | |
857 return -1; | |
858 ret = render_testBlitAlpha(); | |
859 if (ret) | |
860 return -1; | |
861 ret = render_testBlitBlend(); | |
862 | |
619 | 863 |
620 return ret; | 864 return ret; |
621 } | 865 } |
622 | 866 |
623 | 867 |