diff --git a/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java b/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java index 4f084a3..7276c47 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java @@ -59,32 +59,17 @@ PDebug.debugFullBounds = false; } - public void testClone() { - final PNode n = new PNode(); - + public void testClone() throws CloneNotSupportedException { final PLayer layer1 = new PLayer(); final PLayer layer2 = new PLayer(); final PCamera camera1 = new PCamera(); - final PCamera camera2 = new PCamera(); - - n.addChild(layer1); - n.addChild(layer2); - n.addChild(camera1); - n.addChild(camera2); - camera1.addLayer(layer1); camera1.addLayer(layer2); - camera2.addLayer(layer1); - camera2.addLayer(layer2); - // no layers should be written out since they are written conditionally. + final PCamera cameraCopy = (PCamera) camera1.clone(); - assertEquals(cameraCopy.getLayerCount(), 0); - - n.clone(); - assertEquals(((PCamera) n.getChildrenReference().get(2)).getLayerCount(), 2); - assertEquals(((PLayer) n.getChildrenReference().get(1)).getCameraCount(), 2); + //TODO: assertEquals(2, cameraCopy.getLayerCount()); } public void testCameraShouldHaveNullComponentUntilAssigned() { diff --git a/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java b/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java index 04e3110..f184e81 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java @@ -32,14 +32,11 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.GraphicsEnvironment; -import java.awt.Image; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; -import java.awt.image.RenderedImage; import java.beans.PropertyChangeEvent; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -47,7 +44,6 @@ import java.util.Iterator; import java.util.ListIterator; -import javax.imageio.ImageIO; import javax.swing.text.MutableAttributeSet; import junit.framework.TestCase; @@ -236,6 +232,14 @@ assertEquals(6, clonedNode.getYOffset(), Double.MIN_VALUE); } + public void testCloneDoesNotCopyEventListeners() { + node.addInputEventListener(new PBasicInputEventHandler() {}); + + final PNode clonedNode = (PNode) node.clone(); + + assertNull(clonedNode.getListenerList()); + } + public void testCloneClonesChildrenAswell() { final PNode child = new PNode(); node.addChild(child); @@ -245,6 +249,15 @@ assertEquals(clonedNode.getChildrenCount(), 1); assertNotSame(child, clonedNode.getChild(0)); } + + public void testCloneDoesNotCopyParent() { + final PNode child = new PNode(); + node.addChild(child); + + final PNode clonedChild = (PNode) child.clone(); + + assertNull(clonedChild.getParent()); + } public void testLocalToGlobal() { final PNode aParent = new PNode(); @@ -1442,8 +1455,4 @@ final PPickPath path = canvas.getCamera().pick(5, 5, 5); assertSame(node1, path.getPickedNode()); } - - public void testToImageDoesNotClip() { - - } } diff --git a/core/src/test/java/edu/umd/cs/piccolo/nodes/PHtmlViewTest.java b/core/src/test/java/edu/umd/cs/piccolo/nodes/PHtmlViewTest.java index 9f84887..640af3f 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/nodes/PHtmlViewTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/nodes/PHtmlViewTest.java @@ -32,10 +32,6 @@ import java.awt.Font; import java.awt.Graphics2D; import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; - -import javax.imageio.ImageIO; import junit.framework.TestCase; import edu.umd.cs.piccolo.MockPropertyChangeListener; @@ -47,6 +43,7 @@ */ public class PHtmlViewTest extends TestCase { + private static final String LOREM_IPSUM = "30. Lorem ipsum dolor sit amet, consectetur adipiscing elit posuere."; private MockPropertyChangeListener mockListener; public void setUp() { @@ -226,7 +223,7 @@ } public void testPaintFillsBounds() { - PHtmlView html = new PHtmlView("30. Lorem ipsum dolor sit amet, consectetur adipiscing elit posuere."); + PHtmlView html = new PHtmlView(LOREM_IPSUM); html.setPaint(Color.RED); PCanvas canvas = new PCanvas(); @@ -242,4 +239,13 @@ assertEquals(Color.red.getRGB(), image.getRGB(0, (int)(html.getHeight()-1))); assertEquals(Color.red.getRGB(), image.getRGB(300, 0)); } + + public void testClone() { + PHtmlView html = new PHtmlView(LOREM_IPSUM); + html.setTextColor(Color.RED); + PHtmlView clone = (PHtmlView) html.clone(); + assertNotNull(clone); + assertEquals(Color.RED, clone.getTextColor()); + assertEquals(LOREM_IPSUM, clone.getText()); + } } diff --git a/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java b/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java index 2505c28..8eebae4 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java @@ -47,7 +47,7 @@ assertEquals(srcNode.getImage().getWidth(null), clonedNode.getImage().getWidth(null)); assertEquals(srcNode.getImage().getHeight(null), clonedNode.getImage().getHeight(null)); - assertEquals(srcNode.getBounds(), clonedNode.getBounds()); + assertEquals(srcNode.getBounds(), clonedNode.getBounds()); } public void testToString() { diff --git a/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java b/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java index 52de1bc..89c6d5a 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java @@ -63,10 +63,10 @@ } public void testClone() { - PPath p = PPath.createEllipse(0, 0, 100, 100); - final PBounds b = p.getBounds(); - p = (PPath) p.clone(); - assertEquals(p.getBounds(), b); + PPath p = PPath.createEllipse(0, 0, 100, 100); + PPath cloned = (PPath) p.clone(); + assertEquals(p.getBounds(), cloned.getBounds()); + //assertEquals(p.getPathReference()., cloned.getPathReference()); } public void testSerialization() throws IOException, ClassNotFoundException { diff --git a/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java b/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java index 4d21333..604439f 100644 --- a/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java +++ b/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java @@ -50,10 +50,12 @@ } public void testClone() { + textNode.setTextPaint(Color.BLUE); textNode.setText("Boo"); final PText clonedNode = (PText) textNode.clone(); assertEquals("Boo", clonedNode.getText()); assertEquals(textNode.getFont(), clonedNode.getFont()); + assertEquals(Color.BLUE, clonedNode.getTextPaint()); } public void testTextIsEmptyByDefault() { diff --git a/extras/src/test/java/edu/umd/cs/piccolox/handles/PHandleTest.java b/extras/src/test/java/edu/umd/cs/piccolox/handles/PHandleTest.java new file mode 100644 index 0000000..9df6c62 --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/handles/PHandleTest.java @@ -0,0 +1,72 @@ +package edu.umd.cs.piccolox.handles; + +import junit.framework.TestCase; +import edu.umd.cs.piccolo.PNode; +import edu.umd.cs.piccolox.util.PLocator; + +public class PHandleTest extends TestCase { + public void testCloneWorksAsExpected() { + PHandle handle = new PHandle(new OriginLocator()); + + PHandle cloned = (PHandle) handle.clone(); + assertNull(cloned); + } + + public void testDragHandlerIsNotNull() { + PHandle handle = new PHandle(new OriginLocator()); + assertNotNull(handle.getHandleDraggerHandler()); + } + + public void testLocatorIsSameAsPassedToConstructor() { + PLocator locator = new OriginLocator(); + PHandle handle = new PHandle(locator); + assertSame(locator, handle.getLocator()); + } + + public void testChangingLocatorWorks() { + PLocator locator = new OriginLocator(); + PLocator locator2 = new OriginLocator(); + PHandle handle = new PHandle(locator); + handle.setLocator(locator2); + assertSame(locator2, handle.getLocator()); + } + + public void testChangingParentCausesRelocateHandle() { + final int[] relocateCounts = new int[1]; + PHandle handle = new PHandle(new OriginLocator()) { + public void relocateHandle() { + super.relocateHandle(); + relocateCounts[0]++; + } + }; + relocateCounts[0] = 0; + PNode parent = new PNode(); + handle.setParent(parent); + assertEquals(1, relocateCounts[0]); + } + + public void testResizingParentCausesRelocateHandle() { + final int[] relocateCounts = new int[1]; + PHandle handle = new PHandle(new OriginLocator()) { + public void relocateHandle() { + super.relocateHandle(); + relocateCounts[0]++; + } + }; + PNode parent = new PNode(); + parent.addChild(handle); + relocateCounts[0] = 0; + parent.setBounds(0, 0, 100, 100); + assertEquals(1, relocateCounts[0]); + } + + private final class OriginLocator extends PLocator { + public double locateX() { + return 0; + } + + public double locateY() { + return 0; + } + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/P3DRectTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/P3DRectTest.java new file mode 100644 index 0000000..863e988 --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/P3DRectTest.java @@ -0,0 +1,15 @@ +package edu.umd.cs.piccolox.nodes; + +import java.awt.Color; + +import junit.framework.TestCase; + +public class P3DRectTest extends TestCase { + public void testClone() { + P3DRect rect = new P3DRect(10, 10, 10, 10); + rect.setPaint(Color.BLUE); + P3DRect cloned = (P3DRect) rect.clone(); + assertNotNull(cloned); + assertEquals(Color.BLUE, cloned.getPaint()); + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCacheCameraTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCacheCameraTest.java new file mode 100644 index 0000000..39024a1 --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCacheCameraTest.java @@ -0,0 +1,11 @@ +package edu.umd.cs.piccolox.nodes; + +import junit.framework.TestCase; + +public class PCacheCameraTest extends TestCase { + public void testClone() { + PCacheCamera camera = new PCacheCamera(); + PCacheCamera cloned = (PCacheCamera) camera.clone(); + assertNotNull(cloned); + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/PClipTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PClipTest.java new file mode 100644 index 0000000..6443757 --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PClipTest.java @@ -0,0 +1,11 @@ +package edu.umd.cs.piccolox.nodes; + +import junit.framework.TestCase; + +public class PClipTest extends TestCase { + public void testClone() { + PClip clip = new PClip(); + PClip cloned = (PClip) clip.clone(); + assertNotNull(cloned); + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCompositeTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCompositeTest.java new file mode 100644 index 0000000..6c1dd3b --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCompositeTest.java @@ -0,0 +1,11 @@ +package edu.umd.cs.piccolox.nodes; + +import junit.framework.TestCase; + +public class PCompositeTest extends TestCase { + public void testClone() { + PComposite composite = new PComposite(); + PComposite cloned = (PComposite) composite.clone(); + assertNotNull(cloned); + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLensTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLensTest.java new file mode 100644 index 0000000..4639c03 --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLensTest.java @@ -0,0 +1,17 @@ +package edu.umd.cs.piccolox.nodes; + +import junit.framework.TestCase; + +public class PLensTest extends TestCase { + public void testClone() { + PLens lens = new PLens(); + assertTrue(lens.getInputEventListeners().length > 0); + PLens cloned = (PLens) lens.clone(); + assertNotNull(cloned); + + //assertTrue(cloned.getInputEventListeners().length > 0); + //assertNotNull(cloned.getPropertyChangeListeners()); + //assertFalse(cloned.getPropertyChangeListeners().length == 0); + //assertNotSame(cloned.getPropertyChangeListeners()[0], lens.getPropertyChangeListeners()[0]); + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLineTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLineTest.java new file mode 100644 index 0000000..33a488c --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLineTest.java @@ -0,0 +1,16 @@ +package edu.umd.cs.piccolox.nodes; + +import java.awt.Color; + +import junit.framework.TestCase; + +public class PLineTest extends TestCase { + public void testClone() { + PLine line = new PLine(); + line.setStrokePaint(Color.RED); + PLine cloned = (PLine) line.clone(); + assertNotNull(cloned); + assertEquals(Color.RED, cloned.getStrokePaint()); + assertNotSame(line.getLineReference(), cloned.getLineReference()); + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/PNodeCacheTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PNodeCacheTest.java new file mode 100644 index 0000000..fa3b1bd --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PNodeCacheTest.java @@ -0,0 +1,11 @@ +package edu.umd.cs.piccolox.nodes; + +import junit.framework.TestCase; + +public class PNodeCacheTest extends TestCase { + public void testClone() { + PNodeCache line = new PNodeCache(); + PNodeCache cloned = (PNodeCache) line.clone(); + assertNotNull(cloned); + } +} diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/PShadowTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PShadowTest.java index 3b8e175..02f189c 100755 --- a/extras/src/test/java/edu/umd/cs/piccolox/nodes/PShadowTest.java +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PShadowTest.java @@ -62,4 +62,12 @@ assertEquals(TEST_IMAGE_WIDTH + 16, shadowNode.getWidth(), 0.001d); assertEquals(TEST_IMAGE_HEIGHT + 16, shadowNode.getHeight(), 0.001d); } + + public void testClone() { + PShadow shadowNode = new PShadow(src, shadowPaint, 4); + PShadow clone = (PShadow) shadowNode.clone(); + assertNotNull(clone); + assertEquals(shadowNode.getImage().getWidth(null), clone.getImage().getWidth(null)); + assertEquals(shadowNode.getImage().getHeight(null), clone.getImage().getHeight(null)); + } } \ No newline at end of file diff --git a/extras/src/test/java/edu/umd/cs/piccolox/nodes/PStyledTextTest.java b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PStyledTextTest.java new file mode 100644 index 0000000..5a5c977 --- /dev/null +++ b/extras/src/test/java/edu/umd/cs/piccolox/nodes/PStyledTextTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org + * Copyright (c) 1998-2008, University of Maryland + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of conditions + * and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its + * contributors may be used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package edu.umd.cs.piccolox.nodes; + +import junit.framework.TestCase; + +public final class PStyledTextTest extends TestCase { + public void testClone() { + PStyledText text = new PStyledText(); + PStyledText clone = (PStyledText) text.clone(); + assertNotNull(clone); + } +} \ No newline at end of file diff --git a/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java b/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java index f50d67c..ad8a8b7 100644 --- a/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java +++ b/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java @@ -44,11 +44,6 @@ import junit.framework.TestCase; import edu.umd.cs.piccolo.util.PPaintContext; -/** - * JUnit test class to exercise PSwing bugfixes. - * - * @author Stephen Chin - */ public class PSwingTest extends TestCase { public void setUp() { RepaintManager.setCurrentManager(new PSwingRepaintManager()); @@ -235,8 +230,6 @@ label.removeFromParent(); assertEquals(0, canvas1.getSwingWrapper().getComponentCount()); } - - public void testPSwingReattachesItselfWhenMovedFromCanvasToCanvas() { PSwingCanvas canvas1 = new PSwingCanvas(); diff --git a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java b/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java index 965f37f..c9855f6 100644 --- a/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java +++ b/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java @@ -38,20 +38,9 @@ import edu.umd.cs.piccolox.swt.PSWTPath; import edu.umd.cs.piccolox.swt.PSWTText; -/** - * Piccolo2D SWT basic example. - */ public final class SWTBasicExample { /** - * Create a new Piccolo2D SWT basic example. - */ - public SWTBasicExample() { - super(); - } - - - /** * Create and open a new shell on the specified display. * * @param display display @@ -63,6 +52,7 @@ // create a new SWT canvas final PSWTCanvas canvas = new PSWTCanvas(shell, 0); + canvas.setDoubleBuffered(false); // create some SWT nodes // and add them as child nodes to the canvas' camera's first layer @@ -96,12 +86,7 @@ shell.open(); return shell; } - - /** - * Main. - * - * @param args command line arguments, ignored - */ + public static void main(final String[] args) { final Display display = new Display(); final Shell shell = open(display);