Author: allain.lalonde
Date: Sat Jul 18 05:08:49 2009
New Revision: 509
Modified:
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventTest.java
Log:
Some Unit Tests for PInputEvent
Modified:
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java
==============================================================================
---
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java
(original)
+++
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PInputEvent.java
Sat Jul 18 05:08:49 2009
@@ -407,11 +407,7 @@
pickPath.canvasToLocal(r, getCamera());
return (PDimension) getCamera().localToView(r);
}
-
- // ****************************************************************
- // Debugging - methods for debugging
- // ****************************************************************
-
+
/**
* Returns a string representation of this object for debugging
purposes.
*/
Modified:
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventTest.java
==============================================================================
---
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventTest.java
(original)
+++
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PInputEventTest.java
Sat Jul 18 05:08:49 2009
@@ -11,28 +11,95 @@
public class PInputEventTest extends TestCase {
private PCanvas canvas;
+ private MouseEvent swingEvent;
+ private PInputEvent mouseEvent;
public void setUp() {
canvas = new PCanvas();
canvas.setPreferredSize(new Dimension(100, 100));
canvas.setBounds(0, 0, 100, 100);
+ swingEvent = buildSwingClick(5, 5);
+
+ mouseEvent = new
PInputEvent(canvas.getRoot().getDefaultInputManager(), swingEvent,
canvas.getCamera());
}
public void testGetCameraUsesInputSourceIfPathIsNull() {
- InputEvent swingEvent = buildSwingClick(5, 5);
-
- PInputEvent event = new
PInputEvent(canvas.getRoot().getDefaultInputManager(), swingEvent,
canvas.getCamera());
- assertEquals(canvas.getCamera(), event.getCamera());
+ assertEquals(canvas.getCamera(), mouseEvent.getCamera());
}
public void testInputManagerShouldBeSameAsGivenToConstructor() {
- InputEvent swingEvent = buildSwingClick(5, 5);
+ assertSame(canvas.getRoot().getDefaultInputManager(),
mouseEvent.getInputManager());
+ }
+
+ public void testComponentIsComponentPassedToSwingEvent() {
+ assertEquals(canvas, mouseEvent.getComponent());
+ }
+
+ public void testKeyboardAccessorsThrowExceptionsOnMousEvents() {
+ try {
+ mouseEvent.getKeyChar();
+ } catch (IllegalStateException e) {
+ //expected
+ }
+
+ try {
+ mouseEvent.getKeyCode();
+ } catch (IllegalStateException e) {
+ //expected
+ }
+
+ try {
+ mouseEvent.getKeyLocation();
+ } catch (IllegalStateException e) {
+ //expected
+ }
+
+ try {
+ mouseEvent.isActionKey();
+ } catch (IllegalStateException e) {
+ //expected
+ }
- PInputEvent event = new
PInputEvent(canvas.getRoot().getDefaultInputManager(), swingEvent,
canvas.getCamera());
- assertSame(canvas.getRoot().getDefaultInputManager(),
event.getInputManager());
+ }
+
+ public void testCorrectlyIdentifiesPositiveLeftMouseClick() {
+ assertTrue(mouseEvent.isLeftMouseButton());
+ }
+
+ public void testCorrectlyIdentifiesNegativeRightMouseClick() {
+ assertFalse(mouseEvent.isRightMouseButton());
+ }
+
+ public void testCorrectlyIdentifiesNegativeMiddleMouseClick() {
+ assertFalse(mouseEvent.isMiddleMouseButton());
+ }
+
+ public void testEventsAreNotHandledByDefault() {
+ assertFalse(mouseEvent.isHandled());
}
- private MouseEvent buildSwingClick(int x, int y) {
- return new MouseEvent(canvas, 1, System.currentTimeMillis(),
MouseEvent.MOUSE_CLICKED, x, y, 1, false);
+ public void testSetHandledPersists() {
+ mouseEvent.setHandled(true);
+ assertTrue(mouseEvent.isHandled());
+ }
+
+ public void testHandledEventCanBeUnHandled() {
+ mouseEvent.setHandled(true);
+ mouseEvent.setHandled(false);
+ assertFalse(mouseEvent.isHandled());
+ }
+
+ public void testReturnsCorrectModifiers() {
+ assertEquals(InputEvent.BUTTON1_MASK, mouseEvent.getModifiers());
}
+
+ public void testGetButtonUsesWhatWasPassedToMouseEvent() {
+ assertEquals(MouseEvent.BUTTON1, mouseEvent.getButton());
+ }
+
+
+ private MouseEvent buildSwingClick(int x, int y) {
+ return new MouseEvent(canvas, 1, System.currentTimeMillis(),
InputEvent.BUTTON1_MASK, x, y, 1, false, MouseEvent.BUTTON1);
+ }
+
}
--~--~---------~--~----~------------~-------~--~----~
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en
-~----------~----~----~----~------~----~------~--~---