diff --git a/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandleTest.java b/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandleTest.java index 1c56827..10869cf 100644 --- a/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandleTest.java +++ b/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTBoundsHandleTest.java @@ -1,76 +1,65 @@ package edu.umd.cs.piccolox.swt; +import junit.framework.TestCase; import edu.umd.cs.piccolo.PCamera; import edu.umd.cs.piccolo.PNode; import edu.umd.cs.piccolo.event.PInputEventListener; import edu.umd.cs.piccolox.util.PBoundsLocator; -public class PSWTBoundsHandleTest extends SWTTest { +public class PSWTBoundsHandleTest extends TestCase { private PNode node; public void setUp() { - if (hasHead()) { - node = new PNode(); - node.setBounds(0, 0, 100, 100); - } + node = new PNode(); + node.setBounds(0, 0, 100, 100); } public void testAddBoundsHandlesToNodeAddsHandles() { - if (hasHead()) { - PSWTBoundsHandle.addBoundsHandlesTo(node); - assertEquals(8, node.getChildrenCount()); - - for (int i=0; i<8; i++) { - PNode child = node.getChild(i); - assertTrue(child instanceof PSWTBoundsHandle); - } + PSWTBoundsHandle.addBoundsHandlesTo(node); + assertEquals(8, node.getChildrenCount()); + + for (int i = 0; i < 8; i++) { + PNode child = node.getChild(i); + assertTrue(child instanceof PSWTBoundsHandle); } } - + public void testAddStickyBoundsHandlesToNodeAddsHandles() { - if (hasHead()) { - PCamera camera = new PCamera(); - PSWTBoundsHandle.addStickyBoundsHandlesTo(node, camera); - assertEquals(0, node.getChildrenCount()); - assertEquals(8, camera.getChildrenCount()); - - for (int i=0; i<8; i++) { - PNode child = camera.getChild(i); - assertTrue(child instanceof PSWTBoundsHandle); - } + PCamera camera = new PCamera(); + PSWTBoundsHandle.addStickyBoundsHandlesTo(node, camera); + assertEquals(0, node.getChildrenCount()); + assertEquals(8, camera.getChildrenCount()); + + for (int i = 0; i < 8; i++) { + PNode child = camera.getChild(i); + assertTrue(child instanceof PSWTBoundsHandle); } } - + public void testRemoveBoundsHandlesRemovesOnlyHandles() { - if (hasHead()) { - PNode child = new PNode(); - node.addChild(child); - PSWTBoundsHandle.addBoundsHandlesTo(node); - PSWTBoundsHandle.removeBoundsHandlesFrom(node); - assertEquals(1, node.getChildrenCount()); - assertEquals(child, node.getChild(0)); - } + PNode child = new PNode(); + node.addChild(child); + PSWTBoundsHandle.addBoundsHandlesTo(node); + PSWTBoundsHandle.removeBoundsHandlesFrom(node); + assertEquals(1, node.getChildrenCount()); + assertEquals(child, node.getChild(0)); } - + public void testRemoveBoundsHandlesDoesNothingWhenNoHandles() { - if (hasHead()) { - PNode child = new PNode(); - node.addChild(child); - PSWTBoundsHandle.removeBoundsHandlesFrom(node); - assertEquals(1, node.getChildrenCount()); - } + PNode child = new PNode(); + node.addChild(child); + PSWTBoundsHandle.removeBoundsHandlesFrom(node); + assertEquals(1, node.getChildrenCount()); } - + public void testCursorHandlerIsInstalledByDefault() { - if (hasHead()) { - PSWTBoundsHandle handle = new PSWTBoundsHandle(PBoundsLocator.createEastLocator(node)); - PInputEventListener dragHandler = handle.getHandleDraggerHandler(); - PInputEventListener cursorHandler = handle.getHandleCursorEventHandler(); - assertNotNull(cursorHandler); - PInputEventListener[] listeners = handle.getInputEventListeners(); - assertEquals(2, listeners.length); - assertTrue(cursorHandler == listeners[0] || cursorHandler == listeners[1]); - assertTrue(dragHandler == listeners[0] || dragHandler == listeners[1]); - } - } + PSWTBoundsHandle handle = new PSWTBoundsHandle(PBoundsLocator.createEastLocator(node)); + PInputEventListener dragHandler = handle.getHandleDraggerHandler(); + PInputEventListener cursorHandler = handle.getHandleCursorEventHandler(); + assertNotNull(cursorHandler); + PInputEventListener[] listeners = handle.getInputEventListeners(); + assertEquals(2, listeners.length); + assertTrue(cursorHandler == listeners[0] || cursorHandler == listeners[1]); + assertTrue(dragHandler == listeners[0] || dragHandler == listeners[1]); + } } diff --git a/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTCanvasTest.java b/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTCanvasTest.java index 36d20ee..6052aed 100644 --- a/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTCanvasTest.java +++ b/swt/src/test/java/edu/umd/cs/piccolox/swt/PSWTCanvasTest.java @@ -1,95 +1,82 @@ package edu.umd.cs.piccolox.swt; +import junit.framework.TestCase; + +import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; import edu.umd.cs.piccolo.event.PInputEventListener; import edu.umd.cs.piccolo.event.PPanEventHandler; import edu.umd.cs.piccolo.event.PZoomEventHandler; -public class PSWTCanvasTest extends SWTTest { +public class PSWTCanvasTest extends TestCase { private PSWTCanvas canvas; - public void setUp() { - if (hasHead()) { - canvas = buildSimpleCanvas(Display.getDefault()); - } - } - - public void testPanEventListenerIsInstalledByDefault() { - if (hasHead()) { - PPanEventHandler handler = canvas.getPanEventHandler(); - assertNotNull(handler); - - int handlerIndex = getHandlerIndex(handler); - assertFalse("Pan Event Handler not installed", handlerIndex == -1); - } + public void setUp() { + final Shell shell = new Shell(Display.getDefault()); + shell.setLayout(new FillLayout()); + canvas = new PSWTCanvas(shell, 0); } - private int getHandlerIndex(PInputEventListener handler) { + public void testPanEventListenerIsInstalledByDefault() { + PPanEventHandler handler = canvas.getPanEventHandler(); + assertNotNull(handler); + + int handlerIndex = getHandlerIndex(handler); + assertFalse("Pan Event Handler not installed", handlerIndex == -1); + } + + public void testZoomEventListenerIsInstalledByDefault() { + PZoomEventHandler handler = canvas.getZoomEventHandler(); + assertNotNull(handler); + + int handlerIndex = getHandlerIndex(handler); + assertFalse("Zoom Event Handler not installed", handlerIndex == -1); + } + + private int getHandlerIndex(PInputEventListener handler) { PInputEventListener[] listeners = canvas.getCamera().getInputEventListeners(); int handlerIndex = -1; - for (int i=0; i endBounds.width); - assertTrue(startBounds.height > endBounds.height); - } - } + PBounds endBounds = textNode.getBounds(); + assertTrue(startBounds.width > endBounds.width); + assertTrue(startBounds.height > endBounds.height); + } - public void testTranslationsBehaveLogically() { - if (hasHead()) { - textNode.setTranslation(1, 2); - assertEquals(1, textNode.getTranslateX(), Double.MIN_VALUE); - assertEquals(2, textNode.getTranslateY(), Double.MIN_VALUE); + public void testTranslationsBehaveLogically() { + textNode.setTranslation(1, 2); + assertEquals(1, textNode.getTranslateX(), Double.MIN_VALUE); + assertEquals(2, textNode.getTranslateY(), Double.MIN_VALUE); - textNode.setTranslateX(3); - assertEquals(3, textNode.getTranslateX(), Double.MIN_VALUE); + textNode.setTranslateX(3); + assertEquals(3, textNode.getTranslateX(), Double.MIN_VALUE); - textNode.setTranslateY(4); - assertEquals(4, textNode.getTranslateY(), Double.MIN_VALUE); + textNode.setTranslateY(4); + assertEquals(4, textNode.getTranslateY(), Double.MIN_VALUE); - assertEquals(new Point2D.Double(3, 4), textNode.getTranslation()); - - textNode.setTranslation(new Point2D.Double(5,6)); - assertEquals(new Point2D.Double(5,6), textNode.getTranslation()); - } - } + assertEquals(new Point2D.Double(3, 4), textNode.getTranslation()); - public void testTranslatingDoesntAffectSize() { - if (hasHead()) { - textNode.setText("Hello"); - PBounds startBounds = textNode.getBounds(); - textNode.translate(1, 2); - PBounds endBounds = textNode.getBounds(); - assertEquals(startBounds.width, endBounds.width, Double.MIN_VALUE); - assertEquals(startBounds.height, endBounds.height, Double.MIN_VALUE); + textNode.setTranslation(new Point2D.Double(5, 6)); + assertEquals(new Point2D.Double(5, 6), textNode.getTranslation()); + } - } - } + public void testTranslatingDoesntAffectSize() { + textNode.setText("Hello"); + PBounds startBounds = textNode.getBounds(); + textNode.translate(1, 2); + PBounds endBounds = textNode.getBounds(); + assertEquals(startBounds.width, endBounds.width, Double.MIN_VALUE); + assertEquals(startBounds.height, endBounds.height, Double.MIN_VALUE); + } } diff --git a/swt/src/test/java/edu/umd/cs/piccolox/swt/SWTTest.java b/swt/src/test/java/edu/umd/cs/piccolox/swt/SWTTest.java deleted file mode 100644 index 18eb23f..0000000 --- a/swt/src/test/java/edu/umd/cs/piccolox/swt/SWTTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package edu.umd.cs.piccolox.swt; - -import java.awt.GraphicsEnvironment; - -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -import junit.framework.TestCase; - -public abstract class SWTTest extends TestCase { - public final boolean isHeadless() { - return GraphicsEnvironment.isHeadless(); - } - - protected final boolean hasHead() { - return !isHeadless(); - } - - protected PSWTCanvas buildSimpleCanvas(Display display) { - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - return new PSWTCanvas(shell, 0); - } -}