test/testautomation_surface.c
changeset 7374 29ace61fca99
parent 7191 75360622e65f
child 7403 9de6ef8865a2
equal deleted inserted replaced
7373:5e6efd29b461 7374:29ace61fca99
   305 
   305 
   306     return TEST_COMPLETED;
   306     return TEST_COMPLETED;
   307 }
   307 }
   308 
   308 
   309 
   309 
       
   310 /*!
       
   311  *  Tests surface conversion across all pixel formats.
       
   312  */
       
   313 int
       
   314 surface_testCompleteSurfaceConversion(void *arg)
       
   315 {
       
   316     Uint32 pixel_formats[] = {
       
   317         SDL_PIXELFORMAT_INDEX8,
       
   318         SDL_PIXELFORMAT_RGB332,
       
   319         SDL_PIXELFORMAT_RGB444,
       
   320         SDL_PIXELFORMAT_RGB555,
       
   321         SDL_PIXELFORMAT_BGR555,
       
   322         SDL_PIXELFORMAT_ARGB4444,
       
   323         SDL_PIXELFORMAT_RGBA4444,
       
   324         SDL_PIXELFORMAT_ABGR4444,
       
   325         SDL_PIXELFORMAT_BGRA4444,
       
   326         SDL_PIXELFORMAT_ARGB1555,
       
   327         SDL_PIXELFORMAT_RGBA5551,
       
   328         SDL_PIXELFORMAT_ABGR1555,
       
   329         SDL_PIXELFORMAT_BGRA5551,
       
   330         SDL_PIXELFORMAT_RGB565,
       
   331         SDL_PIXELFORMAT_BGR565,
       
   332         SDL_PIXELFORMAT_RGB24,
       
   333         SDL_PIXELFORMAT_BGR24,
       
   334         SDL_PIXELFORMAT_RGB888,
       
   335         SDL_PIXELFORMAT_RGBX8888,
       
   336         SDL_PIXELFORMAT_BGR888,
       
   337         SDL_PIXELFORMAT_BGRX8888,
       
   338         SDL_PIXELFORMAT_ARGB8888,
       
   339         SDL_PIXELFORMAT_RGBA8888,
       
   340         SDL_PIXELFORMAT_ABGR8888,
       
   341         SDL_PIXELFORMAT_BGRA8888,
       
   342         SDL_PIXELFORMAT_ARGB2101010,
       
   343     };
       
   344     SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
       
   345     SDL_PixelFormat *fmt1, *fmt2;
       
   346     Uint32 rgba[4];
       
   347     int bpp, i, j, ret = 0;
       
   348 
       
   349     /* Create sample surface */
       
   350     face = SDLTest_ImageFace();
       
   351     SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
       
   352     if (face == NULL)
       
   353         return TEST_ABORTED;
       
   354 
       
   355     /* Set transparent pixel as the pixel at (0,0) */
       
   356     if (face->format->palette) {
       
   357        ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
       
   358        SDLTest_AssertPass("Call to SDL_SetColorKey()");
       
   359        SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
       
   360     }
       
   361 
       
   362     for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
       
   363         for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
       
   364             /*printf("Converting %s -> %s\n", SDL_GetPixelFormatName(pixel_formats[i]), SDL_GetPixelFormatName(pixel_formats[j]));*/
       
   365 
       
   366             fmt1 = SDL_AllocFormat(pixel_formats[i]);
       
   367             SDL_assert(fmt1 != NULL);
       
   368             cvt1 = SDL_ConvertSurface(face, fmt1, 0);
       
   369             SDL_assert(cvt1 != NULL);
       
   370 
       
   371             fmt2 = SDL_AllocFormat(pixel_formats[j]);
       
   372             SDL_assert(fmt1 != NULL);
       
   373             cvt2 = SDL_ConvertSurface(cvt1, fmt2, 0);
       
   374             SDL_assert(cvt2 != NULL);
       
   375 
       
   376             if ( fmt1->BytesPerPixel == face->format->BytesPerPixel &&
       
   377                  fmt2->BytesPerPixel == face->format->BytesPerPixel &&
       
   378                  (fmt1->Amask != 0) == (face->format->Amask != 0) &&
       
   379                  (fmt2->Amask != 0) == (face->format->Amask != 0) ) {
       
   380                 final = SDL_ConvertSurface( cvt2, face->format, 0 );
       
   381                 SDL_assert(final != NULL);
       
   382 
       
   383                 /* Compare surface. */
       
   384                 ret = SDLTest_CompareSurfaces( face, final, 0 );
       
   385                 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
       
   386                 SDL_FreeSurface(final);
       
   387             }
       
   388 
       
   389             SDL_FreeSurface(cvt1);
       
   390             SDL_FreeFormat(fmt1);
       
   391             SDL_FreeSurface(cvt2);
       
   392             SDL_FreeFormat(fmt2);
       
   393         }
       
   394     }
       
   395 
       
   396     /* Clean up. */
       
   397     SDL_FreeSurface( face );
       
   398 
       
   399     return TEST_COMPLETED;
       
   400 }
       
   401 
       
   402 
   310 /**
   403 /**
   311  * @brief Tests sprite loading. A failure case.
   404  * @brief Tests sprite loading. A failure case.
   312  */
   405  */
   313 int
   406 int
   314 surface_testLoadFailure(void *arg)
   407 surface_testLoadFailure(void *arg)
   538 
   631 
   539 static const SDLTest_TestCaseReference surfaceTest5 =
   632 static const SDLTest_TestCaseReference surfaceTest5 =
   540         { (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
   633         { (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
   541 
   634 
   542 static const SDLTest_TestCaseReference surfaceTest6 =
   635 static const SDLTest_TestCaseReference surfaceTest6 =
       
   636         { (SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED};
       
   637 
       
   638 static const SDLTest_TestCaseReference surfaceTest7 =
   543         { (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
   639         { (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
   544 
   640 
   545 static const SDLTest_TestCaseReference surfaceTest7 =
   641 static const SDLTest_TestCaseReference surfaceTest8 =
   546         { (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
   642         { (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
   547 
       
   548 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
       
   549 static const SDLTest_TestCaseReference surfaceTest8 =
       
   550         { (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blittin routines with verious blending modes", TEST_DISABLED};
       
   551 
   643 
   552 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   644 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   553 static const SDLTest_TestCaseReference surfaceTest9 =
   645 static const SDLTest_TestCaseReference surfaceTest9 =
   554         { (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED};
   646         { (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blittin routines with verious blending modes", TEST_DISABLED};
   555 
   647 
   556 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   648 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
   557 static const SDLTest_TestCaseReference surfaceTest10 =
   649 static const SDLTest_TestCaseReference surfaceTest10 =
       
   650         { (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED};
       
   651 
       
   652 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
       
   653 static const SDLTest_TestCaseReference surfaceTest11 =
   558         { (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED};
   654         { (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED};
   559 
   655 
   560 static const SDLTest_TestCaseReference surfaceTest11 =
   656 static const SDLTest_TestCaseReference surfaceTest12 =
   561         { (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
   657         { (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
   562 
   658 
   563 /* Sequence of Surface test cases */
   659 /* Sequence of Surface test cases */
   564 static const SDLTest_TestCaseReference *surfaceTests[] =  {
   660 static const SDLTest_TestCaseReference *surfaceTests[] =  {
   565     &surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
   661     &surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
   566     &surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10, &surfaceTest11, NULL
   662     &surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
       
   663     &surfaceTest11, &surfaceTest12, NULL
   567 };
   664 };
   568 
   665 
   569 /* Surface test suite (global) */
   666 /* Surface test suite (global) */
   570 SDLTest_TestSuiteReference surfaceTestSuite = {
   667 SDLTest_TestSuiteReference surfaceTestSuite = {
   571     "Surface",
   668     "Surface",