This is the mail archive of the mauve-patches@sources.redhat.com mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

java.awt.AWTKeyStroke - new tests


I've added some new tests for the java.awt.AWTKeyStroke class:

2004-11-09  David Gilbert  <david.gilbert@object-refinery.com>

	* gnu/testlet/java/awt/AWTKeyStroke/equals.java,
	gnu/testlet/java/awt/AWTKeyStroke/getAWTKeyStroke.java,
	gnu/testlet/java/awt/AWTKeyStroke/serialization.java: New tests.

See the attached patch.

Regards,

Dave Gilbert
Index: ChangeLog
===================================================================
RCS file: /cvs/mauve/mauve/ChangeLog,v
retrieving revision 1.734
diff -u -r1.734 ChangeLog
--- ChangeLog	8 Nov 2004 12:32:30 -0000	1.734
+++ ChangeLog	9 Nov 2004 09:45:54 -0000
@@ -1,3 +1,9 @@
+2004-11-09  David Gilbert  <david.gilbert@object-refinery.com>
+
+	* gnu/testlet/java/awt/AWTKeyStroke/equals.java,
+	gnu/testlet/java/awt/AWTKeyStroke/getAWTKeyStroke.java,
+	gnu/testlet/java/awt/AWTKeyStroke/serialization.java: New tests.
+	
 2004-11-08  Robert Schuster <thebohemian@gmx.net>
 
 	gnu/testlet/java/beans/Introspector/getBeanInfo2_2.java:
Index: gnu/testlet/java/awt/AWTKeyStroke/equals.java
===================================================================
RCS file: gnu/testlet/java/awt/AWTKeyStroke/equals.java
diff -N gnu/testlet/java/awt/AWTKeyStroke/equals.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/AWTKeyStroke/equals.java	9 Nov 2004 09:45:55 -0000
@@ -0,0 +1,70 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2004 David Gilbert (david.gilbert@object-refinery.com)
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING.  If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.  */
+
+package gnu.testlet.java.awt.AWTKeyStroke;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.AWTKeyStroke;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+
+/**
+ * Some checks for the equals() method.
+ */
+public class equals
+  implements Testlet
+{
+  /**
+   * Some checks for the equals() method.
+   */
+  public void test(TestHarness harness)
+  {
+    AWTKeyStroke ks1 = AWTKeyStroke.getAWTKeyStroke('A');
+    AWTKeyStroke ks2 = AWTKeyStroke.getAWTKeyStroke('A');
+    harness.check(ks1.equals(ks2));
+    
+    harness.check(!ks1.equals(null));
+    harness.check(!ks1.equals(new Integer(42)));
+    
+    ks1 = AWTKeyStroke.getAWTKeyStroke('a');
+    harness.check(!ks1.equals(ks2));
+    ks2 = AWTKeyStroke.getAWTKeyStroke('a');
+    harness.check(ks1.equals(ks2));
+
+    ks1 = AWTKeyStroke.getAWTKeyStroke(new Character('a'), InputEvent.SHIFT_DOWN_MASK);
+    harness.check(!ks1.equals(ks2));
+    ks2 = AWTKeyStroke.getAWTKeyStroke(new Character('a'), InputEvent.SHIFT_DOWN_MASK);
+    harness.check(ks1.equals(ks2));
+
+    ks1 = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_A, InputEvent.SHIFT_DOWN_MASK, false);
+    harness.check(!ks1.equals(ks2));
+    ks2 = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_A, InputEvent.SHIFT_DOWN_MASK, false);
+    harness.check(ks1.equals(ks2));
+
+    ks1 = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_A, InputEvent.SHIFT_DOWN_MASK, true);
+    harness.check(!ks1.equals(ks2));
+    ks2 = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_A, InputEvent.SHIFT_DOWN_MASK, true);
+    harness.check(ks1.equals(ks2));
+  }
+
+}
\ No newline at end of file
Index: gnu/testlet/java/awt/AWTKeyStroke/getAWTKeyStroke.java
===================================================================
RCS file: gnu/testlet/java/awt/AWTKeyStroke/getAWTKeyStroke.java
diff -N gnu/testlet/java/awt/AWTKeyStroke/getAWTKeyStroke.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/AWTKeyStroke/getAWTKeyStroke.java	9 Nov 2004 09:45:55 -0000
@@ -0,0 +1,148 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2004 David Gilbert (david.gilbert@object-refinery.com)
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING.  If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.  */
+
+package gnu.testlet.java.awt.AWTKeyStroke;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.AWTKeyStroke;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+
+/**
+ * Some checks for the getAWTKeyStroke() methods.
+ */
+public class getAWTKeyStroke
+  implements Testlet
+{
+  /**
+   * Confirm that two lines with the same end points are NOT considered equal.
+   */
+  public void test(TestHarness harness)
+  {
+    testMethod1(harness);
+    testMethod2(harness);
+    testMethod3(harness);
+    testMethod4(harness);
+    testMethod5(harness);
+  }
+  
+  private void testMethod1(TestHarness harness) 
+  {
+    harness.checkPoint("(char)");    
+    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke('s');
+    harness.check(ks.getKeyEventType(), KeyEvent.KEY_TYPED);
+    harness.check(ks.getKeyChar(), 's');
+    harness.check(ks.getModifiers(), 0);
+    harness.check(ks.isOnKeyRelease(), false);
+  }
+
+  private void testMethod2(TestHarness harness) 
+  {
+    harness.checkPoint("(Character, int)");    
+    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke(new Character('s'), InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
+    harness.check(ks.getKeyEventType(), KeyEvent.KEY_TYPED);
+    harness.check(ks.getKeyChar(), 's');
+    harness.check(ks.getModifiers(), InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK);
+    harness.check(ks.isOnKeyRelease(), false);
+
+    // check for IllegalArgumentException for null argument
+    try
+    {
+      ks = AWTKeyStroke.getAWTKeyStroke(null, 0);
+      harness.check(false);
+    }
+    catch (IllegalArgumentException e) 
+    {
+      harness.check(true);
+    }
+  }
+
+  private void testMethod3(TestHarness harness) 
+  {
+    harness.checkPoint("(int, int)");    
+    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
+    harness.check(ks.getKeyEventType(), KeyEvent.KEY_PRESSED);
+    harness.check(ks.getKeyChar(), KeyEvent.CHAR_UNDEFINED);
+    harness.check(ks.getModifiers(), InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK);
+    harness.check(ks.isOnKeyRelease(), false);
+  }
+
+  private void testMethod4(TestHarness harness) 
+  {
+    harness.checkPoint("(int, int, boolean)");    
+    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true);
+    harness.check(ks.getKeyEventType(), KeyEvent.KEY_RELEASED);
+    harness.check(ks.getKeyChar(), KeyEvent.CHAR_UNDEFINED);
+    harness.check(ks.getModifiers(), InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK);
+    harness.check(ks.isOnKeyRelease(), true);
+  }
+
+  private void testMethod5(TestHarness harness) 
+  {
+    harness.checkPoint("(String)");    
+    
+    AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke("INSERT");
+    AWTKeyStroke expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_INSERT, 0);
+    harness.check(ks, expected);
+    
+    ks = AWTKeyStroke.getAWTKeyStroke("control DELETE");
+    expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_MASK);
+    harness.check(ks, expected);
+
+    ks = AWTKeyStroke.getAWTKeyStroke("alt shift X");
+    expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK);
+    harness.check(ks, expected);
+  
+    ks = AWTKeyStroke.getAWTKeyStroke("alt shift released X");
+    expected = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true);
+    harness.check(ks, expected);
+    
+    ks = AWTKeyStroke.getAWTKeyStroke("typed a");
+    expected = AWTKeyStroke.getAWTKeyStroke('a');
+    harness.check(ks, expected);
+    
+    // check for IllegalArgumentException for null argument
+    try
+    {
+      ks = AWTKeyStroke.getAWTKeyStroke(null);
+      harness.check(false);
+    }
+    catch (IllegalArgumentException e) 
+    {
+      harness.check(true);
+    }
+    
+    // check for IllegalArgumentException for bad string
+    try
+    {
+      ks = AWTKeyStroke.getAWTKeyStroke("bad");
+      harness.check(false);
+    }
+    catch (IllegalArgumentException e) 
+    {
+      harness.check(true);
+    }
+    
+    
+  }
+}
\ No newline at end of file
Index: gnu/testlet/java/awt/AWTKeyStroke/serialization.java
===================================================================
RCS file: gnu/testlet/java/awt/AWTKeyStroke/serialization.java
diff -N gnu/testlet/java/awt/AWTKeyStroke/serialization.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/AWTKeyStroke/serialization.java	9 Nov 2004 09:45:55 -0000
@@ -0,0 +1,71 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
+
+// This file is part of Mauve.
+
+// Mauve is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// Mauve is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Mauve; see the file COPYING.  If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.java.awt.AWTKeyStroke;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.AWTKeyStroke;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+
+/**
+ * Some checks for serialization of the {@link AWTKeyStroke} class.
+ */
+public class serialization implements Testlet 
+{
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)      
+  {
+    AWTKeyStroke ks1 = AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true);
+    AWTKeyStroke ks2 = null;
+
+    try {
+      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+      ObjectOutput out = new ObjectOutputStream(buffer);
+      out.writeObject(ks1);
+      out.close();
+
+      ObjectInput in = new ObjectInputStream(
+        new ByteArrayInputStream(buffer.toByteArray())
+      );
+      ks2 = (AWTKeyStroke) in.readObject();
+      in.close();
+    }
+    catch (Exception e) {
+      harness.debug(e);
+    }
+    harness.check(ks1.equals(ks2));
+  }
+  
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]