Author: allain.lalonde
Date: Tue Jul 14 09:00:52 2009
New Revision: 463

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

Log:
Added more tests for PCameraTest and removed an errant ImageIO.write in  
PNode

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/PCameraTest.java     
 
(original)
+++  
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PCameraTest.java     
 
Tue Jul 14 09:00:52 2009
@@ -33,13 +33,11 @@
  import java.awt.Graphics2D;
  import java.awt.GraphicsEnvironment;
  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.activities.PActivity;
+import edu.umd.cs.piccolo.activities.PTransformActivity;
  import edu.umd.cs.piccolo.util.PAffineTransform;
  import edu.umd.cs.piccolo.util.PBounds;
  import edu.umd.cs.piccolo.util.PDebug;
@@ -256,11 +254,29 @@
        }
        
        public void testAnimateViewToPanToBoundsDoesNotAffectScale() {
-               camera.setViewBounds(new PBounds(0, 0, 10, 10));
-               camera.animateViewToPanToBounds(new PBounds(10, 10, 10, 30), 0);
-               
-               assertEquals(1, camera.getViewScale(), 0.0001);
-       }
+        camera.setViewBounds(new PBounds(0, 0, 10, 10));
+        camera.animateViewToPanToBounds(new PBounds(10, 10, 10, 30), 0);
+
+        assertEquals(1, camera.getViewScale(), 0.0001);
+    }
+       
+       public void testAnimateViewToPanToBoundsIsImmediateWhenDurationIsZero() 
{
+        camera.setViewBounds(new PBounds(0, 0, 10, 10));
+        PActivity activity = camera.animateViewToPanToBounds(new  
PBounds(10, 10, 10, 10), 0);
+
+        assertNull(activity);
+        assertEquals(PAffineTransform.getTranslateInstance(-15, -15),  
camera.getViewTransform());
+    }
+       
+       public void  
testAnimateViewToPanToBoundsReturnsAppropriatelyConfiguredActivity() {
+        camera.setViewBounds(new PBounds(0, 0, 10, 10));
+        PTransformActivity activity = camera.animateViewToPanToBounds(new  
PBounds(10, 10, 10, 10), 100);
+
+        assertNotNull(activity);
+        assertEquals(100, activity.getDuration());
+        assertFalse(activity.isStepping());
+        assertEquals(PAffineTransform.getTranslateInstance(-15, -15), new  
PAffineTransform(activity.getDestinationTransform()));
+    }
        
        public void testPDebugDebugBoundsPaintsBounds() throws IOException {
          PCanvas canvas = new PCanvas();
@@ -308,11 +324,25 @@
          assertPointColor(Color.WHITE, img, 15, 10);
      }
        
-       public void testPDebugDebugFullBoundsFillsBounds() throws IOException {
-    }
-
      private void assertPointColor(Color expectedColor, BufferedImage img,  
int x, int y) {
          assertEquals(expectedColor.getRGB(), img.getRGB(x, y));
+    }
+
+    public void testSetViewOffsetIsNotCummulative() {
+        camera.setViewOffset(100, 100);
+        camera.setViewOffset(100, 100);
+        assertEquals(100, camera.getViewTransform().getTranslateX(),  
0.001);
+        assertEquals(100, camera.getViewTransform().getTranslateY(),  
0.001);
+
+    }
+
+    public void testDefaultViewConstraintsIsNone() {
+        assertEquals(PCamera.VIEW_CONSTRAINT_NONE,  
camera.getViewConstraint());
+    }
+
+    public void testSetViewContraintsPersists() {
+        camera.setViewConstraint(PCamera.VIEW_CONSTRAINT_ALL);
+        assertEquals(PCamera.VIEW_CONSTRAINT_ALL,  
camera.getViewConstraint());
      }
        
        class MockPComponent implements PComponent {

Modified:  
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java
==============================================================================
---  
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java       
 
(original)
+++  
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java       
 
Tue Jul 14 09:00:52 2009
@@ -994,7 +994,7 @@
                node.setPaint(Color.RED);

                BufferedImage img = (BufferedImage) node.toImage(20, 40, 
Color.BLUE);
-               ImageIO.write(img, "JPEG", new File("C:\\test.jpg"));
+               
                assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
                assertEquals(Color.RED.getRGB(), img.getRGB(19, 0));
                assertEquals(Color.RED.getRGB(), img.getRGB(0, 19));

--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to