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: fix for Utilities.getTabbedTextOffset test and new test


Hi,
the attached changes the Utilities.getTabbedTextOffset test. I got confused
about the meaning of the methods arguments and made it dependent on the length
of the text. However the argument in question is a coordinate and has nothing to
do with the length. I added a note and changed the argument.

Additionally this patch contains a new test which I used to find out errors in
our javax.swing.text.Utilities.getNextWord() implementation.

2006-04-27  Robert Schuster  <robertschuster@fsfe.org>

        * gnu/testlet/javax/swing/text/Utilities/getNextWord.java: New test.
        * gnu/testlet/javax/swing/text/Utilities/getTabbedTextOffset.java:
        (test): Use fixed value to end loop.


cya
Robert

Index: gnu/testlet/javax/swing/text/Utilities/getNextWord.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/Utilities/getNextWord.java
diff -N gnu/testlet/javax/swing/text/Utilities/getNextWord.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/Utilities/getNextWord.java	27 Apr 2006 16:28:22 -0000
@@ -0,0 +1,108 @@
+/* getNextWord.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 getNextWord 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[] { 0, 4, 13, 15, 25, 35, 39, 43, 45, 48, 50, 54, 62,
+                               65, 72, 77, 82, 88, 98, 102, 106, 111, 119,
+                               128, 132, 142, 146, 150, 155, 167, 175 };
+
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)      
+  {
+	int pos = 0;
+
+        // 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.getNextWord(tf, expected[i]), expected[i+1]);
+          }
+        catch (BadLocationException ble)
+          {
+            ble.printStackTrace();
+	    System.err.println("index: "  + ble.offsetRequested());
+            harness.fail("BadLocationException occurred!");
+          }
+
+        // Given an offset >= 175 the method should throw a BadLocationException
+        // as there are no more words.
+        harness.checkPoint("exception");
+        boolean correctException = false;
+        try
+          {
+	      Utilities.getNextWord(tf, 175);
+          }
+        catch (Exception e)
+          {
+            correctException = e instanceof BadLocationException;
+          }
+        harness.check(correctException);
+        
+	correctException = false;
+        try
+          {
+	      Utilities.getNextWord(tf, 176);
+          }
+        catch (Exception e)
+          {
+            correctException = e instanceof BadLocationException;
+          }
+        harness.check(correctException);
+        
+	correctException = false;
+        try
+          {
+	      Utilities.getNextWord(tf, 177);
+          }
+        catch (Exception e)
+          {
+            correctException = e instanceof BadLocationException;
+          }
+        harness.check(correctException);
+  }
+
+}
Index: gnu/testlet/javax/swing/text/Utilities/getTabbedTextOffset.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/Utilities/getTabbedTextOffset.java,v
retrieving revision 1.1
diff -u -r1.1 getTabbedTextOffset.java
--- gnu/testlet/javax/swing/text/Utilities/getTabbedTextOffset.java	27 Apr 2006 09:21:15 -0000	1.1
+++ gnu/testlet/javax/swing/text/Utilities/getTabbedTextOffset.java	27 Apr 2006 16:28:22 -0000
@@ -51,17 +51,19 @@
    */
   public void test(TestHarness harness)      
   {
+     // The x value that has to be reached before getTabbedTextOffset stops.
+     int endX = 50;
 
      harness.checkPoint("without rounding");
-     for (int i=0; i < s.count; i++)
+     for (int i=0; i <= endX; i++)
        harness.check(calculate(i, false), expectWithoutRounding(i));
 
      harness.checkPoint("with rounding");
-     for (int i=0; i < s.count; i++)
+     for (int i=0; i <= endX; i++)
        harness.check(calculate(i, true), expectWithRounding(i));
 
      harness.checkPoint("with rounding (implicit)");
-     for (int i=0; i < s.count; i++)
+     for (int i=0; i <= endX; i++)
        harness.check(calculate(i), expectWithRounding(i));
 
   }

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]