Revision: 758
Author: allain.lalonde
Date: Tue Oct 20 07:48:52 2009
Log: Adding clone tests to allow for later refactoring.
http://code.google.com/p/piccolo2d/source/detail?r=758
Added:
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/handles
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/handles/PHandleTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/P3DRectTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCacheCameraTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PClipTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCompositeTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLensTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLineTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PNodeCacheTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PStyledTextTest.java
Modified:
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PHtmlViewTest.java
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PShadowTest.java
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java
/piccolo2d.java/trunk/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/handles/PHandleTest.java
Tue Oct 20 07:48:52 2009
@@ -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;
+ }
+ }
+}
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/P3DRectTest.java
Tue Oct 20 07:48:52 2009
@@ -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());
+ }
+}
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCacheCameraTest.java
Tue Oct 20 07:48:52 2009
@@ -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);
+ }
+}
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PClipTest.java
Tue Oct 20 07:48:52 2009
@@ -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);
+ }
+}
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PCompositeTest.java
Tue Oct 20 07:48:52 2009
@@ -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);
+ }
+}
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLensTest.java
Tue Oct 20 07:48:52 2009
@@ -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]);
+ }
+}
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PLineTest.java
Tue Oct 20 07:48:52 2009
@@ -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());
+ }
+}
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PNodeCacheTest.java
Tue Oct 20 07:48:52 2009
@@ -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);
+ }
+}
=======================================
--- /dev/null
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PStyledTextTest.java
Tue Oct 20 07:48:52 2009
@@ -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);
+ }
+}
=======================================
---
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java
Tue Jul 28 12:46:54 2009
+++
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java
Tue Oct 20 07:48:52 2009
@@ -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);
+
+
+ final PCamera cameraCopy = (PCamera) camera1.clone();
+ //TODO: assertEquals(2, cameraCopy.getLayerCount());
}
public void testCameraShouldHaveNullComponentUntilAssigned() {
=======================================
---
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java
Wed Oct 14 13:39:44 2009
+++
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java
Tue Oct 20 07:48:52 2009
@@ -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() {
-
- }
-}
+}
=======================================
---
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PHtmlViewTest.java
Fri Sep 25 13:55:20 2009
+++
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PHtmlViewTest.java
Tue Oct 20 07:48:52 2009
@@ -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 = "<html><body>30. Lorem ipsum
dolor sit amet, consectetur adipiscing elit posuere.</body></html>";
private MockPropertyChangeListener mockListener;
public void setUp() {
@@ -226,7 +223,7 @@
}
public void testPaintFillsBounds() {
- PHtmlView html = new PHtmlView("<html><body>30. Lorem ipsum dolor
sit amet, consectetur adipiscing elit posuere.</body></html>");
+ 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());
+ }
+}
=======================================
---
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java
Fri Jul 31 14:04:44 2009
+++
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PImageTest.java
Tue Oct 20 07:48:52 2009
@@ -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() {
=======================================
---
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java
Fri Sep 25 13:55:20 2009
+++
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PPathTest.java
Tue Oct 20 07:48:52 2009
@@ -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 {
=======================================
---
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java
Thu Jul 30 02:15:41 2009
+++
/piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/nodes/PTextTest.java
Tue Oct 20 07:48:52 2009
@@ -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() {
=======================================
---
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PShadowTest.java
Mon Oct 19 07:28:52 2009
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/nodes/PShadowTest.java
Tue Oct 20 07:48:52 2009
@@ -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));
+ }
+}
=======================================
---
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java
Mon Oct 19 22:48:50 2009
+++
/piccolo2d.java/trunk/extras/src/test/java/edu/umd/cs/piccolox/pswing/PSwingTest.java
Tue Oct 20 07:48:52 2009
@@ -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();
=======================================
---
/piccolo2d.java/trunk/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java
Thu Oct 15 11:45:01 2009
+++
/piccolo2d.java/trunk/swt-examples/src/main/java/edu/umd/cs/piccolox/swt/examples/SWTBasicExample.java
Tue Oct 20 07:48:52 2009
@@ -38,19 +38,8 @@
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.
*
@@ -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);
--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---