FileDocCategorySizeDatePackage
TestSprite.javaAPI DocphoneME MR2 API (J2ME)5132Wed May 02 18:00:22 BST 2007javax.microedition.lcdui.game

TestSprite

public class TestSprite extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidrunTests()

        declare("testInitialSize");
        testInitialSize();

        declare("testTransformNone");
        testTransformNone();

        declare("testTransformRot90");
        testTransformRot90();

        declare("testTransformRot180");
        testTransformRot180();

        declare("testTransformRot270");
        testTransformRot270();

        declare("testTransformMirror");
        testTransformMirror();

        declare("testTransformMirrorRot90");
        testTransformMirrorRot90();

        declare("testTransformMirrorRot180");
        testTransformMirrorRot180();

        declare("testTransformMirrorRot270");
        testTransformMirrorRot270();
    
public voidtestInitialSize()

        Image image = Image.createImage(7, 4);
        Sprite sprite = new Sprite(image);

        assertEquals(image.getWidth(), sprite.getWidth());
        assertEquals(image.getHeight(), sprite.getHeight());
    
private voidtestTransform(int refX, int refY, int transform, int expectedX, int expectedY, int expColRectX, int expColRectY, int expColRectWidth, int expColRectHeight)


        Sprite sprite = new Sprite(Image.createImage(7, 4));

        sprite.defineReferencePixel(refX, refY);
        sprite.setRefPixelPosition(11, 19);
        sprite.defineCollisionRectangle(4, 0, 2, 3);
        sprite.setTransform(transform);

        assertEquals("Collision rectangle X", 4, sprite.collisionRectX);
        assertEquals("Collision rectangle Y", 0, sprite.collisionRectY);
        assertEquals("Collision rectangle width", 2,
                     sprite.collisionRectWidth);
        assertEquals("Collision rectangle height", 3,
                     sprite.collisionRectHeight);

        assertEquals("X", expectedX, sprite.getX());
        assertEquals("Y", expectedY, sprite.getY());
        assertEquals("Transform collision rectangle X", expColRectX,
                     sprite.t_collisionRectX);
        assertEquals("Transform Collision rectangle Y", expColRectY,
                     sprite.t_collisionRectY);
        assertEquals("Transform collision rectangle width", expColRectWidth,
                     sprite.t_collisionRectWidth);
        assertEquals("Transform collision rectangle height", expColRectHeight,
                     sprite.t_collisionRectHeight);
    
public voidtestTransformMirror()

        testTransform(0, 0, Sprite.TRANS_MIRROR, 5, 19, 1, 0, 2, 3);
        testTransform(1, 2, Sprite.TRANS_MIRROR, 6, 17, 1, 0, 2, 3);
    
public voidtestTransformMirrorRot180()

        testTransform(0, 0, Sprite.TRANS_MIRROR_ROT180, 11, 16, 4, 1, 2, 3);
        testTransform(1, 2, Sprite.TRANS_MIRROR_ROT180, 10, 18, 4, 1, 2, 3);
    
public voidtestTransformMirrorRot270()

        testTransform(0, 0, Sprite.TRANS_MIRROR_ROT270, 11, 19, 0, 4, 3, 2);
        testTransform(1, 2, Sprite.TRANS_MIRROR_ROT270, 9, 18, 0, 4, 3, 2);
    
public voidtestTransformMirrorRot90()

        testTransform(0, 0, Sprite.TRANS_MIRROR_ROT90, 8, 13, 1, 1, 3, 2);
        testTransform(1, 2, Sprite.TRANS_MIRROR_ROT90, 10, 14, 1, 1, 3, 2);
    
public voidtestTransformNone()

        testTransform(0, 0, Sprite.TRANS_NONE, 11, 19, 4, 0, 2, 3);
        testTransform(1, 2, Sprite.TRANS_NONE, 10, 17, 4, 0, 2, 3);
    
public voidtestTransformRot180()

        testTransform(0, 0, Sprite.TRANS_ROT180, 5, 16, 1, 1, 2, 3);
        testTransform(1, 2, Sprite.TRANS_ROT180, 6, 18, 1, 1, 2, 3);
    
public voidtestTransformRot270()

        testTransform(0, 0, Sprite.TRANS_ROT270, 11, 13, 0, 1, 3, 2);
        testTransform(1, 2, Sprite.TRANS_ROT270, 9, 14, 0, 1, 3, 2);
    
public voidtestTransformRot90()

        testTransform(0, 0, Sprite.TRANS_ROT90, 8, 19, 1, 4, 3, 2);
        testTransform(1, 2, Sprite.TRANS_ROT90, 10, 18, 1, 4, 3, 2);