001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package javax.microedition.lcdui.game;
028:
029: import com.sun.midp.i3test.*;
030: import javax.microedition.lcdui.*;
031: import javax.microedition.midlet.*;
032:
033: public class TestSprite extends TestCase {
034: public void runTests() {
035: declare("testInitialSize");
036: testInitialSize();
037:
038: declare("testTransformNone");
039: testTransformNone();
040:
041: declare("testTransformRot90");
042: testTransformRot90();
043:
044: declare("testTransformRot180");
045: testTransformRot180();
046:
047: declare("testTransformRot270");
048: testTransformRot270();
049:
050: declare("testTransformMirror");
051: testTransformMirror();
052:
053: declare("testTransformMirrorRot90");
054: testTransformMirrorRot90();
055:
056: declare("testTransformMirrorRot180");
057: testTransformMirrorRot180();
058:
059: declare("testTransformMirrorRot270");
060: testTransformMirrorRot270();
061: }
062:
063: public void testInitialSize() {
064: Image image = Image.createImage(7, 4);
065: Sprite sprite = new Sprite(image);
066:
067: assertEquals(image.getWidth(), sprite.getWidth());
068: assertEquals(image.getHeight(), sprite.getHeight());
069: }
070:
071: public void testTransformNone() {
072: testTransform(0, 0, Sprite.TRANS_NONE, 11, 19, 4, 0, 2, 3);
073: testTransform(1, 2, Sprite.TRANS_NONE, 10, 17, 4, 0, 2, 3);
074: }
075:
076: public void testTransformRot90() {
077: testTransform(0, 0, Sprite.TRANS_ROT90, 8, 19, 1, 4, 3, 2);
078: testTransform(1, 2, Sprite.TRANS_ROT90, 10, 18, 1, 4, 3, 2);
079: }
080:
081: public void testTransformRot180() {
082: testTransform(0, 0, Sprite.TRANS_ROT180, 5, 16, 1, 1, 2, 3);
083: testTransform(1, 2, Sprite.TRANS_ROT180, 6, 18, 1, 1, 2, 3);
084: }
085:
086: public void testTransformRot270() {
087: testTransform(0, 0, Sprite.TRANS_ROT270, 11, 13, 0, 1, 3, 2);
088: testTransform(1, 2, Sprite.TRANS_ROT270, 9, 14, 0, 1, 3, 2);
089: }
090:
091: public void testTransformMirror() {
092: testTransform(0, 0, Sprite.TRANS_MIRROR, 5, 19, 1, 0, 2, 3);
093: testTransform(1, 2, Sprite.TRANS_MIRROR, 6, 17, 1, 0, 2, 3);
094: }
095:
096: public void testTransformMirrorRot90() {
097: testTransform(0, 0, Sprite.TRANS_MIRROR_ROT90, 8, 13, 1, 1, 3,
098: 2);
099: testTransform(1, 2, Sprite.TRANS_MIRROR_ROT90, 10, 14, 1, 1, 3,
100: 2);
101: }
102:
103: public void testTransformMirrorRot180() {
104: testTransform(0, 0, Sprite.TRANS_MIRROR_ROT180, 11, 16, 4, 1,
105: 2, 3);
106: testTransform(1, 2, Sprite.TRANS_MIRROR_ROT180, 10, 18, 4, 1,
107: 2, 3);
108: }
109:
110: public void testTransformMirrorRot270() {
111: testTransform(0, 0, Sprite.TRANS_MIRROR_ROT270, 11, 19, 0, 4,
112: 3, 2);
113: testTransform(1, 2, Sprite.TRANS_MIRROR_ROT270, 9, 18, 0, 4, 3,
114: 2);
115: }
116:
117: private void testTransform(int refX, int refY, int transform,
118: int expectedX, int expectedY, int expColRectX,
119: int expColRectY, int expColRectWidth, int expColRectHeight) {
120:
121: Sprite sprite = new Sprite(Image.createImage(7, 4));
122:
123: sprite.defineReferencePixel(refX, refY);
124: sprite.setRefPixelPosition(11, 19);
125: sprite.defineCollisionRectangle(4, 0, 2, 3);
126: sprite.setTransform(transform);
127:
128: assertEquals("Collision rectangle X", 4, sprite.collisionRectX);
129: assertEquals("Collision rectangle Y", 0, sprite.collisionRectY);
130: assertEquals("Collision rectangle width", 2,
131: sprite.collisionRectWidth);
132: assertEquals("Collision rectangle height", 3,
133: sprite.collisionRectHeight);
134:
135: assertEquals("X", expectedX, sprite.getX());
136: assertEquals("Y", expectedY, sprite.getY());
137: assertEquals("Transform collision rectangle X", expColRectX,
138: sprite.t_collisionRectX);
139: assertEquals("Transform Collision rectangle Y", expColRectY,
140: sprite.t_collisionRectY);
141: assertEquals("Transform collision rectangle width",
142: expColRectWidth, sprite.t_collisionRectWidth);
143: assertEquals("Transform collision rectangle height",
144: expColRectHeight, sprite.t_collisionRectHeight);
145: }
146: }
|