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] |
Hi, this adds a new test for Utilities.getWordStart and enhances the existing one for getNextWord and getPreviousWord. Unfortunately these show bugs in Classpath which are more difficult to fix. 2006-05-13 Robert Schuster <robertschuster@fsfe.org> * gnu/testlet/javax/swing/text/Utilities/getWordStart.java: New test. * gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java: Renamed fields, added second string to check. * gnu/testlet/javax/swing/text/Utilities/getNextWord.java: Dito. cya Robert
Index: gnu/testlet/javax/swing/text/Utilities/getNextWord.java =================================================================== RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/Utilities/getNextWord.java,v retrieving revision 1.1 diff -u -r1.1 getNextWord.java --- gnu/testlet/javax/swing/text/Utilities/getNextWord.java 27 Apr 2006 16:28:53 -0000 1.1 +++ gnu/testlet/javax/swing/text/Utilities/getNextWord.java 13 May 2006 10:55:37 -0000 @@ -33,17 +33,21 @@ 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."; + String text1 = "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); + JTextField tf = new JTextField(text1); - 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, + int[] expected1 = 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 }; + String text2 = "foo 333 . **777.1)/&"; + + int[] expected2 = new int[] { 0, 4, 8, 10, 11, 12, 17, 18, 19 }; + /** * Runs the test using the specified harness. * @@ -58,13 +62,13 @@ harness.checkPoint("indices"); try { - for ( int i=0; i < expected.length - 1; i++) - harness.check(Utilities.getNextWord(tf, expected[i]), expected[i+1]); + for ( int i=0; i < expected1.length - 1; i++) + harness.check(Utilities.getNextWord(tf, expected1[i]), expected1[i+1]); } catch (BadLocationException ble) { ble.printStackTrace(); - System.err.println("index: " + ble.offsetRequested()); + harness.verbose("index: " + ble.offsetRequested()); harness.fail("BadLocationException occurred!"); } @@ -103,6 +107,21 @@ correctException = e instanceof BadLocationException; } harness.check(correctException); + + tf.setText(text2); + harness.checkPoint("indices-tricky"); + try + { + for ( int i=0; i < expected2.length - 1; i++) + harness.check(Utilities.getNextWord(tf, expected2[i]), expected2[i+1]); + } + catch (BadLocationException ble) + { + ble.printStackTrace(); + harness.verbose("index: " + ble.offsetRequested()); + harness.fail("BadLocationException occurred!"); + } + } } Index: gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java =================================================================== RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java,v retrieving revision 1.1 diff -u -r1.1 getPreviousWord.java --- gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java 12 May 2006 11:19:40 -0000 1.1 +++ gnu/testlet/javax/swing/text/Utilities/getPreviousWord.java 13 May 2006 10:55:37 -0000 @@ -33,17 +33,22 @@ public class getPreviousWord implements Testlet { - String text = "GNU Classpath, Essential Libraries for Java, " + + String text1 = "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); + JTextField tf = new JTextField(text1); + + int[] expected1 = new int[] { 176, 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 + }; + + String text2 = "foo 333 . **777.1)/&"; + + int[] expected2 = new int[] { 19, 18, 17, 12, 11, 10, 8, 4, 0 }; - 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. * @@ -53,11 +58,11 @@ { // At first Utilities.getNextWord() has to return the correct offsets // for the given text. - harness.checkPoint("indices"); + harness.checkPoint("indices-normal"); try { - for ( int i=0; i < expected.length - 1; i++) - harness.check(Utilities.getPreviousWord(tf, expected[i]), expected[i+1]); + for ( int i=0; i < expected1.length - 1; i++) + harness.check(Utilities.getPreviousWord(tf, expected1[i]), expected1[i+1]); } catch (BadLocationException ble) { @@ -103,6 +108,21 @@ correctException = e instanceof BadLocationException; } harness.check(correctException); + + // Do the index check again with a more complicated text. + tf.setText(text2); + harness.checkPoint("indices-tricky"); + try + { + for ( int i=0; i < expected2.length - 1; i++) + harness.check(Utilities.getPreviousWord(tf, expected2[i]), expected2[i+1]); + } + catch (BadLocationException ble) + { + ble.printStackTrace(); + harness.verbose("index: " + ble.offsetRequested()); + harness.fail("BadLocationException occurred!"); + } } } Index: gnu/testlet/javax/swing/text/Utilities/getWordStart.java =================================================================== RCS file: gnu/testlet/javax/swing/text/Utilities/getWordStart.java diff -N gnu/testlet/javax/swing/text/Utilities/getWordStart.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/javax/swing/text/Utilities/getWordStart.java 13 May 2006 10:55:37 -0000 @@ -0,0 +1,123 @@ +/* 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 getWordStart 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, 0, 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 13, 14, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 24, 25, 25, + 25, 25, 25, 25, 25, 25, 25, 34, 35, 35, 35, 38, + 39, 39, 39, 39, 43, 44, 45, 45, 47, 48, 49, 50, + 50, 50, 53, 54, 54, 54, 54, 54, 54, 54, 61, 62, + 62, 64, 65, 65, 65, 65, 65, 65, 71, 72, 72, 72, + 72, 76, 77, 77, 77, 77, 81, 82, 82, 82, 82, 82, + 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 97, 98, + 98, 98, 101, 102, 102, 102, 105, 106, 106, 106, + 106, 110, 111, 111, 111, 111, 111, 111, 111, + 118, 119, 119, 119, 119, 119, 119, 119, 119, + 127, 128, 128, 128, 131, 132, 132, 132, 132, + 132, 132, 132, 132, 132, 141, 142, 142, 142, + 145, 146, 146, 146, 149, 150, 150, 150, 150, + 154, 155, 155, 155, 155, 155, 155, 155, 155, + 155, 155, 155, 166, 167, 167, 167, 167, 167, + 167, 167, 167, 175, 175 + }; + + /** + * 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 <= text.length(); i++) + harness.check(Utilities.getWordStart(tf, i), expected[i]); + } + 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] |