Example #1
0
/**
 * @brief Tests opening from memory.
 */
static void rwops_testFP (void)
{
#ifdef HAVE_STDIO_H
   FILE *fp;
   SDL_RWops *rw;

   /* Begin testcase. */
   SDL_ATbegin( "SDL_RWFromFP" );

   /* Run read tests. */
   fp = fopen( RWOPS_READ, "r" );
   if (SDL_ATassert( "Failed to open file '"RWOPS_READ"'", fp != NULL))
      return;
   rw = SDL_RWFromFP( fp, 1 );
   if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL ))
      return;
   if (rwops_testGeneric( rw, 0 ))
      return;
   SDL_FreeRW( rw );

   /* Run write tests. */
   fp = fopen( RWOPS_WRITE, "w+" );
   if (SDL_ATassert( "Failed to open file '"RWOPS_WRITE"'", fp != NULL))
      return;
   rw = SDL_RWFromFP( fp, 1 );
   if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL ))
      return;
   if (rwops_testGeneric( rw, 1 ))
      return;
   SDL_FreeRW( rw );

   /* End testcase. */
   SDL_ATend();
#endif /* HAVE_STDIO_H */
}
Example #2
0
/**
 * @brief Makes sure parameters work properly.
 */
static void rwops_testParam (void)
{
   SDL_RWops *rwops;

   /* Begin testcase. */
   SDL_ATbegin( "RWops Parameters" );

   /* These should all fail. */
   rwops = SDL_RWFromFile(NULL, NULL);
   if (SDL_ATassert( "SDL_RWFromFile(NULL, NULL) worked", rwops == NULL ))
      return;
   rwops = SDL_RWFromFile(NULL, "ab+");
   if (SDL_ATassert( "SDL_RWFromFile(NULL, \"ab+\") worked", rwops == NULL ))
      return;
   rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
   if (SDL_ATassert( "SDL_RWFromFile(NULL, \"sldfkjsldkfj\") worked", rwops == NULL ))
      return;
   rwops = SDL_RWFromFile("something", "");
   if (SDL_ATassert( "SDL_RWFromFile(\"something\", \"\") worked", rwops == NULL ))
      return;
   rwops = SDL_RWFromFile("something", NULL);
   if (SDL_ATassert( "SDL_RWFromFile(\"something\", NULL) worked", rwops == NULL ))
      return;


   /* End testcase. */
   SDL_ATend();
}
/**
 * @brief Makes sure parameters work properly.
 */
static void audio_testOpen (void)
{
   int i, n;
   int ret;

   /* Begin testcase. */
   SDL_ATbegin( "Audio Open" );

   /* List drivers. */
   n = SDL_GetNumAudioDrivers();
   SDL_ATprintVerbose( 1, "%d Audio Drivers\n", n );
   for (i=0; i<n; i++) {
      SDL_ATprintVerbose( 1, "   %s\n", SDL_GetAudioDriver(i) );
   }

   /* Start SDL. */
   ret = SDL_Init( SDL_INIT_AUDIO );
   if (SDL_ATvassert( ret==0, "SDL_Init( SDL_INIT_AUDIO ): %s", SDL_GetError()))
      return;

   /* Print devices. */
   SDL_ATprintVerbose( 1, "Using Audio Driver '%s'\n", SDL_GetCurrentAudioDriver() );
   audio_printDevices(0);
   audio_printDevices(1);

   /* Quit SDL. */
   SDL_Quit();

   /* End testcase. */
   SDL_ATend();
}
Example #4
0
/**
 * @brief Tests opening from memory.
 */
static void rwops_testFile (void)
{
   SDL_RWops *rw;

   /* Begin testcase. */
   SDL_ATbegin( "SDL_RWFromFile" );

   /* Read test. */
   rw = SDL_RWFromFile( RWOPS_READ, "r" );
   if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_READ"'", rw != NULL ))
      return;
   if (rwops_testGeneric( rw, 0 ))
      return;
   SDL_FreeRW( rw );

   /* Write test. */
   rw = SDL_RWFromFile( RWOPS_WRITE, "w+" );
   if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_WRITE"'", rw != NULL ))
      return;
   if (rwops_testGeneric( rw, 1 ))
      return;
   SDL_FreeRW( rw );

   /* End testcase. */
   SDL_ATend();
}
Example #5
0
int main( int argc, const char *argv[] )
{
   (void) argc;
   (void) argv;
#else /* TEST_STANDALONE */
int test_surface (void)
{
#endif /* TEST_STANDALONE */
   int ret;
   SDL_Surface *testsur;

   SDL_ATinit( "SDL_Surface" );

   SDL_ATbegin( "Initializing" );
   /* Initializes the SDL subsystems. */
   ret = SDL_Init(0);
   if (SDL_ATassert( "SDL_Init(0)", ret == 0))
      goto err;

   /* Now run on the video mode. */
   ret = SDL_InitSubSystem( SDL_INIT_VIDEO );
   if (SDL_ATassert( "SDL_InitSubSystem( SDL_INIT_VIDEO )", ret == 0))
      goto err;

   /*
    * Surface on surface tests.
    */
   /* Create the test surface. */
   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
         RMASK, GMASK, BMASK, AMASK );
   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
      goto err;
   SDL_ATend();
   /* Run surface on surface tests. */
   surface_testLoad( testsur );
   surface_runTests( testsur );
   /* Clean up. */
   SDL_FreeSurface( testsur );

   /* Exit SDL. */
   SDL_Quit();

   return SDL_ATfinish();

err:
   return SDL_ATfinish();
}
Example #6
0
/**
 * @brief Tests sprite loading.
 */
static void surface_testLoad( SDL_Surface *testsur )
{
   int ret;
   SDL_Surface *face, *rface;

   SDL_ATbegin( "Load Test" );

   /* Clear surface. */
   ret = SDL_FillRect( testsur, NULL,
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Create the blit surface. */
   face = SDL_LoadBMP("../icon.bmp");
   if (SDL_ATassert( "SDL_CreateLoadBmp", face != NULL))
      return;

   /* Set transparent pixel as the pixel at (0,0) */
   if (face->format->palette) {
      ret = SDL_SetColorKey(face, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
            *(Uint8 *) face->pixels);
      if (SDL_ATassert( "SDL_SetColorKey", ret == 0))
         return;
   }

   /* Convert to 32 bit to compare. */
   rface = SDL_ConvertSurface( face, testsur->format, 0 );
   if (SDL_ATassert( "SDL_ConvertSurface", rface != NULL))
      return;

   /* See if it's the same. */
   if (SDL_ATassert( "Primitives output not the same.",
            surface_compare( rface, &img_face)==0 ))
      return;

   /* Clean up. */
   SDL_FreeSurface( rface );
   SDL_FreeSurface( face );

   SDL_ATend();
}
Example #7
0
/**
 * @brief Tests opening from memory.
 */
static void rwops_testConstMem (void)
{
   SDL_RWops *rw;

   /* Begin testcase. */
   SDL_ATbegin( "SDL_RWFromConstMem" );

   /* Open. */
   rw = SDL_RWFromConstMem( const_mem, sizeof(const_mem)-1 );
   if (SDL_ATassert( "Opening memory with SDL_RWFromConstMem", rw != NULL ))
      return;

   /* Run generic tests. */
   if (rwops_testGeneric( rw, 0 ))
      return;

   /* Close. */
   SDL_FreeRW( rw );

   /* End testcase. */
   SDL_ATend();
}
Example #8
0
/**
 * @brief Tests opening from memory.
 */
static void rwops_testMem (void)
{
   char mem[sizeof(hello_world)];
   SDL_RWops *rw;

   /* Begin testcase. */
   SDL_ATbegin( "SDL_RWFromMem" );

   /* Open. */
   rw = SDL_RWFromMem( mem, sizeof(hello_world)-1 );
   if (SDL_ATassert( "Opening memory with SDL_RWFromMem", rw != NULL ))
      return;

   /* Run generic tests. */
   if (rwops_testGeneric( rw, 1 ))
      return;

   /* Close. */
   SDL_FreeRW( rw );

   /* End testcase. */
   SDL_ATend();
}
/**
 * @brief Tests SDL_IntersectRectAndLine()
 */
static void rect_testIntersectRectAndLine (void)
{
    SDL_Rect rect = { 0, 0, 32, 32 };
    int x1, y1;
    int x2, y2;
    SDL_bool clipped;

    SDL_ATbegin( "IntersectRectAndLine" );

    x1 = -10;
    y1 = 0;
    x2 = -10;
    y2 = 31;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( !clipped &&
                   x1 == -10 && y1 == 0 && x2 == -10 && y2 == 31,
        "line outside to the left was incorrectly clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    x1 = 40;
    y1 = 0;
    x2 = 40;
    y2 = 31;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( !clipped &&
                   x1 == 40 && y1 == 0 && x2 == 40 && y2 == 31,
        "line outside to the right was incorrectly clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    x1 = 0;
    y1 = -10;
    x2 = 31;
    y2 = -10;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( !clipped &&
                   x1 == 0 && y1 == -10 && x2 == 31 && y2 == -10,
        "line outside above was incorrectly clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    x1 = 0;
    y1 = 40;
    x2 = 31;
    y2 = 40;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( !clipped &&
                   x1 == 0 && y1 == 40 && x2 == 31 && y2 == 40,
        "line outside below was incorrectly clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    x1 = 0;
    y1 = 0;
    x2 = 31;
    y2 = 31;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( clipped &&
                   x1 == 0 && y1 == 0 && x2 == 31 && y2 == 31,
        "line fully inside rect was clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    x1 = -10;
    y1 = 15;
    x2 = 40;
    y2 = 15;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( clipped &&
                   x1 == 0 && y1 == 15 && x2 == 31 && y2 == 15,
        "horizontal line rect was incorrectly clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    x1 = -32;
    y1 = -32;
    x2 = 63;
    y2 = 63;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( clipped &&
                   x1 == 0 && y1 == 0 && x2 == 31 && y2 == 31,
        "diagonal line to lower right was incorrectly clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    x1 = 63;
    y1 = 63;
    x2 = -32;
    y2 = -32;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( clipped &&
                   x1 == 31 && y1 == 31 && x2 == 0 && y2 == 0,
        "diagonal line to upper left was incorrectly clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    x1 = 63;
    y1 = -32;
    x2 = -32;
    y2 = 63;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( clipped &&
                   x1 == 31 && y1 == 0 && x2 == 0 && y2 == 31,
        "diagonal line to lower left was incorrectly clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    x1 = -32;
    y1 = 63;
    x2 = 63;
    y2 = -32;
    clipped = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    SDL_ATvassert( clipped &&
                   x1 == 0 && y1 == 31 && x2 == 31 && y2 == 0,
        "diagonal line to upper right was incorrectly clipped: %d,%d - %d,%d",
        x1, y1, x2, y2);

    SDL_ATend();
}
Example #10
0
/**
 * @brief Tests the SDL primitives for rendering.
 */
static void surface_testPrimitives( SDL_Surface *testsur )
{
   int ret;
   int x, y;
   SDL_Rect rect;

   SDL_ATbegin( "Primitives Test" );

   /* Clear surface. */
   ret = SDL_FillRect( testsur, NULL,
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Create the surface. */
   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
         RMASK, GMASK, BMASK, AMASK );
   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
      return;

   /* Draw a rectangle. */
   rect.x = 40;
   rect.y = 0;
   rect.w = 40;
   rect.h = 80;
   ret = SDL_FillRect( testsur, &rect,
         SDL_MapRGB( testsur->format, 13, 73, 200 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Draw a rectangle. */
   rect.x = 10;
   rect.y = 10;
   rect.w = 60;
   rect.h = 40;
   ret = SDL_FillRect( testsur, &rect,
         SDL_MapRGB( testsur->format, 200, 0, 100 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Draw some points like so:
    * X.X.X.X..
    * .X.X.X.X.
    * X.X.X.X.. */
   for (y=0; y<3; y++) {
      x = y % 2;
      for (; x<80; x+=2) {
         ret = SDL_DrawPoint( testsur, x, y,
               SDL_MapRGB( testsur->format, x*y, x*y/2, x*y/3 ) );
         if (SDL_ATassert( "SDL_DrawPoint", ret == 0))
            return;
      }
   }

   /* Draw some lines. */
   ret = SDL_DrawLine( testsur, 0, 30, 80, 30,
         SDL_MapRGB( testsur->format, 0, 255, 0 ) );
   if (SDL_ATassert( "SDL_DrawLine", ret == 0))
      return;
   ret = SDL_DrawLine( testsur, 40, 30, 40, 60,
         SDL_MapRGB( testsur->format, 55, 55, 5 ) );
   if (SDL_ATassert( "SDL_DrawLine", ret == 0))
      return;
   ret = SDL_DrawLine( testsur, 0, 60, 80, 0,
         SDL_MapRGB( testsur->format, 5, 105, 105 ) );
   if (SDL_ATassert( "SDL_DrawLine", ret == 0))
      return;

   /* See if it's the same. */
   if (SDL_ATassert( "Primitives output not the same.",
            surface_compare( testsur, &img_primitives )==0 ))
      return;

   SDL_ATend();
}
Example #11
0
/**
 * @brief Tests some more blitting routines.
 */
static void surface_testBlitBlend( SDL_Surface *testsur )
{
   int ret;
   SDL_Rect rect;
   SDL_Surface *face;
   int i, j, ni, nj;
   int mode;

   SDL_ATbegin( "Blit Blending Tests" );

   /* Clear surface. */
   ret = SDL_FillRect( testsur, NULL,
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Create the blit surface. */
   face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
         img_face.width, img_face.height, 32, img_face.width*4,
         RMASK, GMASK, BMASK, AMASK );
   if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
      return;

   /* Set alpha mod. */
   ret = SDL_SetSurfaceAlphaMod( face, 100 );
   if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
      return;

   /* Steps to take. */
   ni     = testsur->w - face->w;
   nj     = testsur->h - face->h;

   /* Constant values. */
   rect.w = face->w;
   rect.h = face->h;

   /* Test None. */
   if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_NONE ))
      return;
   if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_NONE).",
            surface_compare( testsur, &img_blendNone )==0 ))
      return;

   /* Test Mask. */
   if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_MASK ))
      return;
   if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MASK).",
            surface_compare( testsur, &img_blendMask )==0 ))
      return;

   /* Test Blend. */
   if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND ))
      return;
   if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_BLEND).",
            surface_compare( testsur, &img_blendBlend )==0 ))
      return;

   /* Test Add. */
   if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD ))
      return;
   if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_ADD).",
            surface_compare( testsur, &img_blendAdd )==0 ))
      return;

   /* Test Mod. */
   if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD ))
      return;
   if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MOD).",
            surface_compare( testsur, &img_blendMod )==0 ))
      return;

   /* Clear surface. */
   ret = SDL_FillRect( testsur, NULL,
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Loop blit. */
   for (j=0; j <= nj; j+=4) {
      for (i=0; i <= ni; i+=4) {

         /* Set colour mod. */
         ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
         if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0))
            return;

         /* Set alpha mod. */
         ret = SDL_SetSurfaceAlphaMod( face, (100/ni)*i );
         if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
            return;

         /* Crazy blending mode magic. */
         mode = (i/4*j/4) % 4;
         if (mode==0) mode = SDL_BLENDMODE_MASK;
         else if (mode==1) mode = SDL_BLENDMODE_BLEND;
         else if (mode==2) mode = SDL_BLENDMODE_ADD;
         else if (mode==3) mode = SDL_BLENDMODE_MOD;
         ret = SDL_SetSurfaceBlendMode( face, mode );
         if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0))
            return;

         /* Blitting. */
         rect.x = i;
         rect.y = j;
         ret = SDL_BlitSurface( face, NULL, testsur, &rect );
         if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
            return;
      }
   }

   /* Check to see if matches. */
   if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLEND_*).",
            surface_compare( testsur, &img_blendAll )==0 ))
      return;

   /* Clean up. */
   SDL_FreeSurface( face );

   SDL_ATend();
}
Example #12
0
/**
 * @brief Tests some blitting routines.
 */
static void surface_testBlit( SDL_Surface *testsur )
{
   int ret;
   SDL_Rect rect;
   SDL_Surface *face;
   int i, j, ni, nj;

   SDL_ATbegin( "Blit Tests" );

   /* Clear surface. */
   ret = SDL_FillRect( testsur, NULL,
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Create face surface. */
   face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
         img_face.width, img_face.height, 32, img_face.width*4,
         RMASK, GMASK, BMASK, AMASK );
   if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
      return;

   /* Constant values. */
   rect.w = face->w;
   rect.h = face->h;
   ni     = testsur->w - face->w;
   nj     = testsur->h - face->h;

   /* Loop blit. */
   for (j=0; j <= nj; j+=4) {
      for (i=0; i <= ni; i+=4) {
         /* Blitting. */
         rect.x = i;
         rect.y = j;
         ret = SDL_BlitSurface( face, NULL, testsur, &rect );
         if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
            return;
      }
   }

   /* See if it's the same. */
   if (SDL_ATassert( "Blitting output not the same (normal blit).",
            surface_compare( testsur, &img_blit )==0 ))
      return;

   /* Clear surface. */
   ret = SDL_FillRect( testsur, NULL,
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Test blitting with colour mod. */
   for (j=0; j <= nj; j+=4) {
      for (i=0; i <= ni; i+=4) {
         /* Set colour mod. */
         ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
         if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0))
            return;

         /* Blitting. */
         rect.x = i;
         rect.y = j;
         ret = SDL_BlitSurface( face, NULL, testsur, &rect );
         if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
            return;
      }
   }

   /* See if it's the same. */
   if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceColorMod).",
            surface_compare( testsur, &img_blitColour )==0 ))
      return;

   /* Clear surface. */
   ret = SDL_FillRect( testsur, NULL,
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Restore colour. */
   ret = SDL_SetSurfaceColorMod( face, 255, 255, 255 );
   if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0))
      return;

   /* Test blitting with colour mod. */
   for (j=0; j <= nj; j+=4) {
      for (i=0; i <= ni; i+=4) {
         /* Set alpha mod. */
         ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
         if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
            return;

         /* Blitting. */
         rect.x = i;
         rect.y = j;
         ret = SDL_BlitSurface( face, NULL, testsur, &rect );
         if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
            return;
      }
   }

   /* See if it's the same. */
   if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceAlphaMod).",
            surface_compare( testsur, &img_blitAlpha )==0 ))
      return;

   /* Clean up. */
   SDL_FreeSurface( face );

   SDL_ATend();
}
Example #13
0
/**
 * @brief Tests the SDL primitives with alpha for rendering.
 */
static void surface_testPrimitivesBlend( SDL_Surface *testsur )
{
   int ret;
   int i, j;
   SDL_Rect rect;

   SDL_ATbegin( "Primitives Blend Test" );

   /* Clear surface. */
   ret = SDL_FillRect( testsur, NULL,
         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   if (SDL_ATassert( "SDL_FillRect", ret == 0))
      return;

   /* Create some rectangles for each blend mode. */
   ret = SDL_BlendRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 );
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
      return;
   rect.x = 10;
   rect.y = 25;
   rect.w = 40;
   rect.h = 25;
   ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 );
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
      return;
   rect.x = 30;
   rect.y = 40;
   rect.w = 45;
   rect.h = 15;
   ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 );
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
      return;
   rect.x = 25;
   rect.y = 25;
   rect.w = 25;
   rect.h = 25;
   ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_MOD, 10, 10, 240, 125 );
   if (SDL_ATassert( "SDL_BlendRect", ret == 0))
      return;

   /* Draw blended lines, lines for everyone. */
   for (i=0; i<testsur->w; i+=2)  {
      ret = SDL_BlendLine( testsur, 0, 0, i, 59,
            (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
               (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
            60+2*i, 240-2*i, 50, 3*i );
      if (SDL_ATassert( "SDL_BlendLine", ret == 0))
         return;
   }
   for (i=0; i<testsur->h; i+=2)  {
      ret = SDL_BlendLine( testsur, 0, 0, 79, i,
            (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
               (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
            60+2*i, 240-2*i, 50, 3*i );
      if (SDL_ATassert( "SDL_BlendLine", ret == 0))
         return;
   }

   /* Draw points. */
   for (j=0; j<testsur->h; j+=3) {
      for (i=0; i<testsur->w; i+=3) {
      ret = SDL_BlendPoint( testsur, i, j,
            ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
               ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
            j*4, i*3, j*4, i*3 );
      if (SDL_ATassert( "SDL_BlendPoint", ret == 0))
         return;
      }
   }

   /* See if it's the same. */
   if (SDL_ATassert( "Primitives output not the same.",
            surface_compare( testsur, &img_blend )==0 ))
      return;

   SDL_ATend();
}