This is the mail archive of the mauve-patches@sourceware.org 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]

FYI: new test Utilities.getPreviousWord


Hi,
the attached patch contains a new test for Utilities.getPreviousWord() it is and
adaption of the test for Utilities.getNextWord().

Currently it will show some errors in Classpath but I have fixes for that.

The ChangeLog:

2006-05-12  Robert Schuster  <robertschuster@fsfe.org>

        * gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java:
        New test.

cya
Robert
Index: gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java
diff -N gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java	12 May 2006 11:19:19 -0000
@@ -0,0 +1,108 @@
+/* getPreviousWord.java
+   Copyright (C) 2006  Robert Schuster <robertschuster@fsfe.org>
+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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: 1.2
+
+package gnu.testlet.javax.swing.text.Utilities;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.JTextField;
+
+import javax.swing.text.Utilities;
+import javax.swing.text.BadLocationException;
+
+public class getPreviousWord implements Testlet
+{
+  String text = "GNU Classpath, Essential Libraries for Java, " +
+                "is a GNU project to create free core class " +
+                "libraries for use with virtual machines and " +
+                "compilers for the java programming language.";
+
+  JTextField tf = new JTextField(text);
+
+  int[] expected = new int[] { 175, 167, 155, 150, 146, 142, 132, 128, 119,
+                               111, 106, 102, 98, 88, 82, 77, 72, 65, 62, 54,
+                               50, 48, 45, 43, 39, 35, 25, 15, 13, 4, 0 
+                             };
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)      
+  {
+        // At first Utilities.getNextWord() has to return the correct offsets
+        // for the given text.
+        harness.checkPoint("indices");
+        try
+          {
+            for ( int i=0; i < expected.length - 1; i++)
+	      harness.check(Utilities.getPreviousWord(tf, expected[i]), expected[i+1]);
+          }
+        catch (BadLocationException ble)
+          {
+            ble.printStackTrace();
+	    harness.verbose("index: "  + ble.offsetRequested());
+            harness.fail("BadLocationException occurred!");
+          }
+
+        // Given an offset > text.length() the method should throw a
+        // BadLocationException.
+        harness.checkPoint("exception");
+        boolean correctException = false;
+        try
+          {
+	      Utilities.getPreviousWord(tf, 180);
+          }
+        catch (Exception e)
+          {
+            correctException = e instanceof BadLocationException;
+          }
+        harness.check(correctException);
+
+	// Given an offset <= 0 the method should throw a
+        // BadLocationException..
+	correctException = false;
+        try
+          {
+	      Utilities.getPreviousWord(tf, 0);
+          }
+        catch (Exception e)
+          {
+            correctException = e instanceof BadLocationException;
+          }
+        harness.check(correctException);
+        
+	correctException = false;
+        try
+          {
+	      Utilities.getPreviousWord(tf, -1);
+          }
+        catch (Exception e)
+          {
+            correctException = e instanceof BadLocationException;
+          }
+        harness.check(correctException);
+  }
+
+}

Attachment: signature.asc
Description: OpenPGP digital signature


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