Revision: 1029
Author: heuermh
Date: Fri Jul 23 12:24:02 2010
Log: refactoring PNodeTest, moving methods that do not refer to node field
to PNodeTest
http://code.google.com/p/piccolo2d/source/detail?r=1029
Modified:
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/AbstractPNodeTest.java
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/PNodeTest.java
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/AbstractPNodeTest.java
Fri Jul 23 12:15:23 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/AbstractPNodeTest.java
Fri Jul 23 12:24:02 2010
@@ -275,100 +275,40 @@
}
public void testLocalToGlobal() {
- final PNode parent = new PNode();
- final PNode aChild = new PNode();
-
- parent.addChild(aChild);
- aChild.scale(0.5);
+ final PNode child = new PNode();
+
+ node.addChild(child);
+ child.scale(0.5);
// bounds
final PBounds bnds = new PBounds(0, 0, 50, 50);
- aChild.localToGlobal(bnds);
+ child.localToGlobal(bnds);
assertEquals(0, bnds.x, 0);
assertEquals(0, bnds.y, 0);
assertEquals(25, bnds.width, 0);
assertEquals(25, bnds.height, 0);
- aChild.globalToLocal(bnds);
+ child.globalToLocal(bnds);
assertEquals(0, bnds.x, 0);
assertEquals(0, bnds.y, 0);
assertEquals(50, bnds.width, 0);
assertEquals(50, bnds.height, 0);
- aChild.getGlobalToLocalTransform(new PAffineTransform());
- aChild.getLocalToGlobalTransform(new
PAffineTransform()).createTransformedShape(aChild.getBounds());
+ child.getGlobalToLocalTransform(new PAffineTransform());
+ child.getLocalToGlobalTransform(new
PAffineTransform()).createTransformedShape(child.getBounds());
// dimensions
final PDimension dim = new PDimension(50, 50);
- aChild.localToGlobal(dim);
+ child.localToGlobal(dim);
assertEquals(25, dim.getHeight(), 0);
assertEquals(25, dim.getWidth(), 0);
- aChild.globalToLocal(dim);
+ child.globalToLocal(dim);
assertEquals(50, dim.getHeight(), 0);
assertEquals(50, dim.getWidth(), 0);
}
-
- public void testToString() {
- final PNode a = new PNode();
- final PNode b = new PNode();
- final PNode c = new PNode();
- final PNode d = new PNode();
- final PNode e = new PNode();
- final PNode f = new PNode();
-
- a.translate(100, 100);
- a.getFullBoundsReference();
-
- a.addChild(b);
- b.addChild(c);
- c.addChild(d);
- d.addChild(e);
- e.addChild(f);
-
- assertNotNull(a.toString());
- }
-
- public void testRecursiveLayout() {
- final PNode layoutNode1 = new PNode() {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- protected void layoutChildren() {
- if (getChildrenCount() > 0) {
- getChild(0).setOffset(1, 0);
- }
- }
- };
-
- final PNode layoutNode2 = new PNode() {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- protected void layoutChildren() {
- if (getChildrenCount() > 0) {
- getChild(0).setOffset(1, 0);
- }
- }
- };
-
- layoutNode1.addChild(layoutNode2);
-
- final PNode n = new PNode();
- n.setBounds(0, 0, 100, 100);
-
- layoutNode2.addChild(n);
-
- n.setBounds(10, 10, 100, 100);
-
- layoutNode1.getFullBoundsReference();
- }
public void testAnimateToBoundsWithDuration0IsImmediate() {
node.setBounds(0, 0, 100, 100);
@@ -646,11 +586,11 @@
}
public void testParentToLocalTransformsOrphanChildWhenTransformed() {
- final PNode aChild = new PNode();
- aChild.scale(0.5);
+ final PNode child = new PNode();
+ child.scale(0.5);
final Point2D point = new Point2D.Double(5, 6);
- aChild.parentToLocal(point);
+ child.parentToLocal(point);
assertEquals(10, point.getX(), 0.0001);
assertEquals(12, point.getY(), 0.0001);
}
@@ -754,40 +694,6 @@
final PBounds expected = new PBounds(-50, -50, 100, 100);
assertEquals(expected, node.getBounds());
}
-
- public void testCenterFullBoundsOnPointWorksAsExpected() {
- final PNode parent = buildComplexSquareNode();
-
- parent.centerFullBoundsOnPoint(0, 0);
-
- final PBounds expected = new PBounds(-50, -50, 100, 100);
- assertEquals(expected, parent.getFullBounds());
- }
-
- // todo: not sure about this. . .
- private PNode buildComplexSquareNode() {
- final PNode parent = new PNode();
- parent.setBounds(0, 0, 50, 100);
-
- final PNode child1 = new PNode();
- child1.setBounds(50, 0, 50, 50);
- parent.addChild(child1);
-
- final PNode child2 = new PNode();
- child2.setBounds(50, 50, 50, 50);
- parent.addChild(child2);
-
- return parent;
- }
-
- public void testGetUnionOfChildrenBoundsAcceptsNull() {
- final PNode node = buildComplexSquareNode();
-
- final PBounds union = node.getUnionOfChildrenBounds(null);
-
- assertNotNull(union);
- assertEquals(new PBounds(50, 0, 50, 100), union);
- }
public void testGetGlobalFullBoundsIsSameWhenNoTransforms() {
final PNode child = new PNode();
@@ -897,26 +803,6 @@
assertEquals(0, PNode.lerp(0, 0, 10), 0.001);
assertEquals(10, PNode.lerp(1, 0, 10), 0.001);
}
-
- public void testAnimateToRelativePositionResultsInProperTransform() {
- final PCanvas canvas = new PCanvas();
- final PNode A = new PNode();
- A.setBounds(0, 0, 50, 50);
- canvas.getLayer().addChild(A);
- final PNode B = new PNode();
- B.setBounds(0, 0, 100, 100);
- B.setOffset(100, 100);
- canvas.getLayer().addChild(B);
-
- final Point2D srcPt = new Point2D.Double(1.0, 0.0);
- final Point2D destPt = new Point2D.Double(0.0, 0.0);
- A.animateToRelativePosition(srcPt, destPt, B.getGlobalBounds(), 0);
-
- final PAffineTransform expectedTransform = new PAffineTransform();
- expectedTransform.translate(50, 100);
-
- assertEquals(expectedTransform, A.getTransform());
- }
public void testGetInverseTransformWorks() {
node.translate(50, 50);
@@ -940,42 +826,7 @@
}
}
- // PNode only
- public void testSetVisibleIsRespectedOnPaint() {
- final int[] paintCounts = new int[1];
-
- final PNode node = new PNode() {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void paint(final PPaintContext pc) {
- paintCounts[0]++;
- }
- };
- node.setBounds(0, 0, 100, 100);
- node.setVisible(true);
-
- final PCanvas canvas = buildCanvasContainingNode(node);
-
- final BufferedImage img = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
- final Graphics g =
GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(img);
-
- canvas.paintComponent(g);
-
- assertEquals(1, paintCounts[0]);
-
- node.setVisible(false);
- node.invalidatePaint();
- canvas.paintComponent(g);
- assertEquals(1, paintCounts[0]);
-
- node.setVisible(true);
- node.invalidatePaint();
- canvas.paintComponent(g);
- assertEquals(2, paintCounts[0]);
- }
+ // todo: most of these pixel-perfect tests probably will not work on
subclasses
public void testSetTransparency1MeansInvisible() {
node.setBounds(0, 0, 100, 100);
@@ -1423,26 +1274,4 @@
node.setOccluded(true);
assertTrue(node.getOccluded());
}
-
- // to PNodeTest
- public void testHiddenNodesAreNotPickable() {
- final PCanvas canvas = new PCanvas();
- canvas.setBounds(0, 0, 400, 400);
- canvas.setPreferredSize(new Dimension(400, 400));
- final PNode node1 = new PNode();
- node1.setBounds(0, 0, 100, 100);
- node1.setPaint(Color.RED);
- canvas.getLayer().addChild(node1);
-
- final PNode node2 = (PNode) node1.clone();
- node2.setPaint(Color.BLUE);
-
- final PLayer layer2 = new PLayer();
- layer2.addChild(node2);
- layer2.setVisible(false);
- canvas.getCamera().addLayer(layer2);
-
- final PPickPath path = canvas.getCamera().pick(5, 5, 5);
- assertSame(node1, path.getPickedNode());
- }
-}
+}
=======================================
---
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/PNodeTest.java
Fri Jul 23 12:15:23 2010
+++
/piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/PNodeTest.java
Fri Jul 23 12:24:02 2010
@@ -74,4 +74,181 @@
protected PNode createNode() {
return new PNode();
}
-}
+
+ public void testToString() {
+ final PNode a = new PNode();
+ final PNode b = new PNode();
+ final PNode c = new PNode();
+ final PNode d = new PNode();
+ final PNode e = new PNode();
+ final PNode f = new PNode();
+
+ a.translate(100, 100);
+ a.getFullBoundsReference();
+
+ a.addChild(b);
+ b.addChild(c);
+ c.addChild(d);
+ d.addChild(e);
+ e.addChild(f);
+
+ assertNotNull(a.toString());
+ }
+
+ public void testRecursiveLayout() {
+ final PNode layoutNode1 = new PNode() {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ protected void layoutChildren() {
+ if (getChildrenCount() > 0) {
+ getChild(0).setOffset(1, 0);
+ }
+ }
+ };
+
+ final PNode layoutNode2 = new PNode() {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ protected void layoutChildren() {
+ if (getChildrenCount() > 0) {
+ getChild(0).setOffset(1, 0);
+ }
+ }
+ };
+
+ layoutNode1.addChild(layoutNode2);
+
+ final PNode n = new PNode();
+ n.setBounds(0, 0, 100, 100);
+
+ layoutNode2.addChild(n);
+
+ n.setBounds(10, 10, 100, 100);
+
+ layoutNode1.getFullBoundsReference();
+ }
+
+ public void testCenterFullBoundsOnPointWorksAsExpected() {
+ final PNode parent = buildComplexSquareNode();
+
+ parent.centerFullBoundsOnPoint(0, 0);
+
+ final PBounds expected = new PBounds(-50, -50, 100, 100);
+ assertEquals(expected, parent.getFullBounds());
+ }
+
+ // todo: not sure about this. . .
+ private PNode buildComplexSquareNode() {
+ final PNode parent = new PNode();
+ parent.setBounds(0, 0, 50, 100);
+
+ final PNode child1 = new PNode();
+ child1.setBounds(50, 0, 50, 50);
+ parent.addChild(child1);
+
+ final PNode child2 = new PNode();
+ child2.setBounds(50, 50, 50, 50);
+ parent.addChild(child2);
+
+ return parent;
+ }
+
+ public void testGetUnionOfChildrenBoundsAcceptsNull() {
+ final PNode node = buildComplexSquareNode();
+
+ final PBounds union = node.getUnionOfChildrenBounds(null);
+
+ assertNotNull(union);
+ assertEquals(new PBounds(50, 0, 50, 100), union);
+ }
+
+ public void testAnimateToRelativePositionResultsInProperTransform() {
+ final PCanvas canvas = new PCanvas();
+ final PNode A = new PNode();
+ A.setBounds(0, 0, 50, 50);
+ canvas.getLayer().addChild(A);
+ final PNode B = new PNode();
+ B.setBounds(0, 0, 100, 100);
+ B.setOffset(100, 100);
+ canvas.getLayer().addChild(B);
+
+ final Point2D srcPt = new Point2D.Double(1.0, 0.0);
+ final Point2D destPt = new Point2D.Double(0.0, 0.0);
+ A.animateToRelativePosition(srcPt, destPt, B.getGlobalBounds(), 0);
+
+ final PAffineTransform expectedTransform = new PAffineTransform();
+ expectedTransform.translate(50, 100);
+
+ assertEquals(expectedTransform, A.getTransform());
+ }
+
+ public void testSetVisibleIsRespectedOnPaint() {
+ final int[] paintCounts = new int[1];
+
+ final PNode node = new PNode() {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public void paint(final PPaintContext pc) {
+ paintCounts[0]++;
+ }
+ };
+ node.setBounds(0, 0, 100, 100);
+ node.setVisible(true);
+
+ final PCanvas canvas = buildCanvasContainingNode(node);
+
+ final BufferedImage img = new BufferedImage(100, 100,
BufferedImage.TYPE_INT_RGB);
+ final Graphics g =
GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(img);
+
+ canvas.paintComponent(g);
+
+ assertEquals(1, paintCounts[0]);
+
+ node.setVisible(false);
+ node.invalidatePaint();
+ canvas.paintComponent(g);
+ assertEquals(1, paintCounts[0]);
+
+ node.setVisible(true);
+ node.invalidatePaint();
+ canvas.paintComponent(g);
+ assertEquals(2, paintCounts[0]);
+ }
+
+ private PCanvas buildCanvasContainingNode(final PNode node) {
+ final PCanvas canvas = new PCanvas();
+ canvas.setSize(100, 100);
+ canvas.getLayer().addChild(node);
+ return canvas;
+ }
+
+ public void testHiddenNodesAreNotPickable() {
+ final PCanvas canvas = new PCanvas();
+ canvas.setBounds(0, 0, 400, 400);
+ canvas.setPreferredSize(new Dimension(400, 400));
+ final PNode node1 = new PNode();
+ node1.setBounds(0, 0, 100, 100);
+ node1.setPaint(Color.RED);
+ canvas.getLayer().addChild(node1);
+
+ final PNode node2 = (PNode) node1.clone();
+ node2.setPaint(Color.BLUE);
+
+ final PLayer layer2 = new PLayer();
+ layer2.addChild(node2);
+ layer2.setVisible(false);
+ canvas.getCamera().addLayer(layer2);
+
+ final PPickPath path = canvas.getCamera().pick(5, 5, 5);
+ assertSame(node1, path.getPickedNode());
+ }
+}
--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en