Mercurial > sdl-ios-xcode
comparison test/automated/surface/surface.c @ 3716:ac6bc19a2dfb gsoc2009_unit_tests
Added surfarce blend rendering functions testcase.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Wed, 01 Jul 2009 22:03:32 +0000 |
parents | 3c9d9c052c8f |
children | 9d71382713b5 |
comparison
equal
deleted
inserted
replaced
3715:3c9d9c052c8f | 3716:ac6bc19a2dfb |
---|---|
34 | 34 |
35 /* | 35 /* |
36 * Pull in images for testcases. | 36 * Pull in images for testcases. |
37 */ | 37 */ |
38 #include "primitives.c" | 38 #include "primitives.c" |
39 #include "blend.c" | |
39 | 40 |
40 | 41 |
41 /** | 42 /** |
42 * @brief Compares a surface and a surface image for equality. | 43 * @brief Compares a surface and a surface image for equality. |
43 * | 44 * |
174 SDL_ATend(); | 175 SDL_ATend(); |
175 } | 176 } |
176 | 177 |
177 | 178 |
178 /** | 179 /** |
180 * @brief Tests the SDL primitives with alpha for rendering. | |
181 */ | |
182 static void surface_testPrimitivesAlpha (void) | |
183 { | |
184 int ret; | |
185 int i, j; | |
186 SDL_Rect rect; | |
187 SDL_Surface *testsur; | |
188 | |
189 SDL_ATbegin( "Primitives Alpha Test" ); | |
190 | |
191 /* Create the surface. */ | |
192 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, | |
193 RMASK, GMASK, BMASK, AMASK ); | |
194 | |
195 /* Create some rectangles for each blend mode. */ | |
196 ret = SDL_BlendRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 ); | |
197 if (SDL_ATassert( "SDL_BlendRect", ret == 0)) | |
198 return; | |
199 rect.x = 10; | |
200 rect.y = 25; | |
201 rect.w = 40; | |
202 rect.h = 25; | |
203 ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 ); | |
204 if (SDL_ATassert( "SDL_BlendRect", ret == 0)) | |
205 return; | |
206 rect.x = 30; | |
207 rect.y = 40; | |
208 rect.w = 45; | |
209 rect.h = 15; | |
210 ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 ); | |
211 if (SDL_ATassert( "SDL_BlendRect", ret == 0)) | |
212 return; | |
213 rect.x = 25; | |
214 rect.y = 25; | |
215 rect.w = 25; | |
216 rect.h = 25; | |
217 ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_MOD, 10, 10, 240, 125 ); | |
218 if (SDL_ATassert( "SDL_BlendRect", ret == 0)) | |
219 return; | |
220 | |
221 /* Draw blended lines, lines for everyone. */ | |
222 for (i=0; i<testsur->w; i+=2) { | |
223 ret = SDL_BlendLine( testsur, 0, 0, i, 59, | |
224 (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : | |
225 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD, | |
226 60+2*j, 240-2*j, 50, 3*j ); | |
227 if (SDL_ATassert( "SDL_BlendLine", ret == 0)) | |
228 return; | |
229 } | |
230 for (i=0; i<testsur->h; i+=2) { | |
231 ret = SDL_BlendLine( testsur, 0, 0, 79, i, | |
232 (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : | |
233 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD, | |
234 60+2*j, 240-2*j, 50, 3*j ); | |
235 if (SDL_ATassert( "SDL_BlendLine", ret == 0)) | |
236 return; | |
237 } | |
238 | |
239 /* Draw points. */ | |
240 for (j=0; j<testsur->h; j+=3) { | |
241 for (i=0; i<testsur->w; i+=3) { | |
242 ret = SDL_BlendPoint( testsur, i, j, | |
243 ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND : | |
244 ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD, | |
245 j*4, i*3, j*4, i*3 ); | |
246 if (SDL_ATassert( "SDL_BlendPoint", ret == 0)) | |
247 return; | |
248 } | |
249 } | |
250 | |
251 /* See if it's the same. */ | |
252 if (SDL_ATassert( "Primitives output not the same.", | |
253 surface_compare( testsur, &img_blend )==0 )) | |
254 return; | |
255 | |
256 /* Clean up. */ | |
257 SDL_FreeSurface( testsur ); | |
258 | |
259 SDL_ATend(); | |
260 } | |
261 | |
262 | |
263 /** | |
179 * @brief Entry point. | 264 * @brief Entry point. |
180 */ | 265 */ |
181 int main( int argc, const char *argv[] ) | 266 int main( int argc, const char *argv[] ) |
182 { | 267 { |
183 SDL_ATinit( "SDL_Surface" ); | 268 SDL_ATinit( "SDL_Surface" ); |
184 | 269 |
185 /* Initializes the SDL subsystems. */ | 270 /* Initializes the SDL subsystems. */ |
186 SDL_Init(0); | 271 SDL_Init(0); |
187 | 272 |
188 surface_testPrimitives(); | 273 surface_testPrimitives(); |
189 /*surface_testPrimitivesAlpha();*/ | 274 surface_testPrimitivesAlpha(); |
190 | 275 |
191 /* Exit SDL. */ | 276 /* Exit SDL. */ |
192 SDL_Quit(); | 277 SDL_Quit(); |
193 | 278 |
194 return SDL_ATfinish(1); | 279 return SDL_ATfinish(1); |