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: GapContent tests


I committed this patch:

2006-01-24 David Gilbert <david.gilbert@object-refinery.com>

* gnu/testlet/javax/swing/text/GapContent/constructors.java: New tests,
* gnu/testlet/javax/swing/text/GapContent/createPosition.java: Likewise,
* gnu/testlet/javax/swing/text/GapContent/getChars.java: Likewise,
* gnu/testlet/javax/swing/text/GapContent/getString.java: Likewise,
* gnu/testlet/javax/swing/text/GapContent/insertString.java
(test): Call testGeneral(TestHarness),
(testGeneral): New method,
* gnu/testlet/javax/swing/text/GapContent/length.java: New tests,
* gnu/testlet/javax/swing/text/GapContent/MyGapContent.java: New support class,
* gnu/testlet/javax/swing/text/GapContent/remove.java: New tests.


Regards,

Dave
Index: gnu/testlet/javax/swing/text/GapContent/MyGapContent.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/GapContent/MyGapContent.java
diff -N gnu/testlet/javax/swing/text/GapContent/MyGapContent.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/GapContent/MyGapContent.java	24 Jan 2006 16:23:21 -0000
@@ -0,0 +1,45 @@
+/* MyGapContent.java -- provides access to protected methods.
+   Copyright (C) 2006  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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: not-a-test
+
+
+package gnu.testlet.javax.swing.text.GapContent;
+
+import javax.swing.text.GapContent;
+
+public class MyGapContent extends GapContent 
+{
+  public MyGapContent() 
+  {
+    super();
+  }
+  
+  public MyGapContent(int count)
+  {
+    super(count);
+  }
+  
+  public int getArrayLength()
+  {
+    return super.getArrayLength();
+  }
+}
Index: gnu/testlet/javax/swing/text/GapContent/constructors.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/GapContent/constructors.java
diff -N gnu/testlet/javax/swing/text/GapContent/constructors.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/GapContent/constructors.java	24 Jan 2006 16:23:21 -0000
@@ -0,0 +1,92 @@
+/* constructors.java -- Some checks for the constructors in the GapContent
+                        class.
+   Copyright (C) 2006  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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: 1.2
+
+package gnu.testlet.javax.swing.text.GapContent;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.GapContent;
+
+public class constructors implements Testlet
+{
+    
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)      
+  {
+    testConstructor1(harness);
+    testConstructor2(harness);
+  }
+  
+  public void testConstructor1(TestHarness harness) 
+  {
+    harness.checkPoint("()");
+    MyGapContent gc = new MyGapContent();
+    harness.check(gc.length(), 1);
+    
+    boolean pass = false;
+    try
+    {
+      pass = gc.getString(0, 1).equals("\n");
+    }
+    catch (BadLocationException e)
+    {
+      harness.fail(e.toString());
+    }
+    harness.check(pass);
+    harness.check(gc.getArrayLength(), 10);
+  }
+  
+  public void testConstructor2(TestHarness harness) 
+  {
+    harness.checkPoint("(int)");
+    MyGapContent gc = new MyGapContent(10);
+    harness.check(gc.length(), 1);
+    boolean pass = false;
+    try
+    {
+      pass = gc.getString(0, 1).equals("\n");
+    }
+    catch (BadLocationException e)
+    {
+      harness.fail(e.toString());
+    }
+    harness.check(pass);
+    harness.check(gc.getArrayLength(), 10);
+    
+    // try unusual initial sizes
+    MyGapContent gc2 = new MyGapContent(0);
+    harness.check(gc2.length(), 1);
+    harness.check(gc2.getArrayLength(), 2);
+    gc2 = new MyGapContent(-1);
+    harness.check(gc2.getArrayLength(), 2);
+    
+  }
+
+}
\ No newline at end of file
Index: gnu/testlet/javax/swing/text/GapContent/createPosition.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/GapContent/createPosition.java
diff -N gnu/testlet/javax/swing/text/GapContent/createPosition.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/GapContent/createPosition.java	24 Jan 2006 16:23:21 -0000
@@ -0,0 +1,103 @@
+/* createPosition.java -- Some checks for the createPosition() method in the 
+                          GapContent class.
+   Copyright (C) 2006  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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: 1.2
+
+package gnu.testlet.javax.swing.text.GapContent;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.GapContent;
+import javax.swing.text.Position;
+
+public class createPosition implements Testlet
+{
+    
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)      
+  {
+    GapContent gc = new GapContent();
+    harness.check(gc.length(), 1);
+    try
+    {
+      gc.insertString(0, "ABC");
+    }
+    catch (BadLocationException e) 
+    {
+      // ignore
+    }
+    
+    // negative index
+    boolean pass = false;
+    try
+    {
+      gc.createPosition(-1);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // index of last char
+    Position p = null;
+    try
+    {
+      p = gc.createPosition(3);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(p.getOffset(), 3);
+    
+    // index of last char + 1
+    try
+    {
+      p = gc.createPosition(4);
+    }
+    catch (BadLocationException e)
+    {
+    }
+    harness.check(p.getOffset(), 4);
+    
+    // index of last char + 2
+    pass = false;
+    try
+    {
+      p = gc.createPosition(5);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+  }
+
+}
\ No newline at end of file
Index: gnu/testlet/javax/swing/text/GapContent/getChars.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/GapContent/getChars.java
diff -N gnu/testlet/javax/swing/text/GapContent/getChars.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/GapContent/getChars.java	24 Jan 2006 16:23:21 -0000
@@ -0,0 +1,165 @@
+/* getChars.java -- Some checks for the getChars() method in the GapContent
+                    class.
+   Copyright (C) 2006  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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: 1.2
+
+package gnu.testlet.javax.swing.text.GapContent;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.GapContent;
+import javax.swing.text.Segment;
+
+public class getChars implements Testlet
+{
+    
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)      
+  {
+    GapContent gc = new GapContent();
+    Segment seg = new Segment();
+    
+    // check default result
+    try
+    {
+      gc.getChars(0, 1, seg);
+    }
+    catch (BadLocationException e)
+    {
+      // ignore - tests below will fail if this happens
+    }
+    harness.check(seg.offset, 0);
+    harness.check(seg.count, 1);
+    harness.check(seg.array[0], '\n');
+
+    // if len goes past end of range, should get BadLocationException
+    boolean pass = false;
+    try
+    {
+      gc.getChars(0, 2, seg);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+
+    // add some more text
+    try
+    {
+      gc.insertString(0, "ABCDEFG");
+    }
+    catch (BadLocationException e)
+    {
+    }
+    harness.check(gc.length(), 8);
+    
+    // if index < 0 should get BadLocationException
+    pass = false;
+    try
+    {
+      gc.getChars(-1, 3, seg);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // if index > end of text should get BadLocationException
+    pass = false;
+    try
+    {
+      gc.getChars(99, 1, seg);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // if len goes past end of range, should get BadLocationException
+    pass = false;
+    try
+    {
+      gc.getChars(0, 99, seg);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // try a zero length string
+    try
+    {
+      gc.getChars(1, 0, seg);
+    }
+    catch (BadLocationException e)
+    {
+    }
+    harness.check(seg.offset, 1);
+    harness.check(seg.count, 0);
+    
+    // what happens for null Segment
+    pass = false;
+    try
+    {
+      gc.getChars(0, 1, null);
+    }
+    catch (NullPointerException e)
+    {
+      pass = true;
+    }
+    catch (BadLocationException e)
+    {
+      // ignore
+    }
+    harness.check(pass);
+    
+    // what happens if we update the Segment array, does that change the 
+    // StringContent
+    Segment seg2 = new Segment();
+    Segment seg3 = new Segment();
+    GapContent gc2 = new GapContent();
+    try
+    {
+      gc2.insertString(0, "XYZ");
+      gc2.getChars(0, 3, seg2);
+      seg2.array[1] = '5';
+      gc2.getChars(0, 3, seg3);
+    }
+    catch (BadLocationException e) 
+    {
+      // ignore
+    }
+    harness.check(seg2.array[1], '5');
+    harness.check(seg3.array[1], '5');
+  }
+
+}
\ No newline at end of file
Index: gnu/testlet/javax/swing/text/GapContent/getString.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/GapContent/getString.java
diff -N gnu/testlet/javax/swing/text/GapContent/getString.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/GapContent/getString.java	24 Jan 2006 16:23:21 -0000
@@ -0,0 +1,132 @@
+/* getString.java -- Some checks for the getString() method in the GapContent
+                     class.
+   Copyright (C) 2006  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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: 1.2
+
+package gnu.testlet.javax.swing.text.GapContent;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.GapContent;
+
+public class getString implements Testlet
+{
+    
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)      
+  {
+    GapContent gc = new GapContent();
+    
+    // check default result
+    boolean pass = false;
+    try
+    {
+      pass = gc.getString(0, 1).equals("\n");
+    }
+    catch (BadLocationException e)
+    {
+    }
+    harness.check(pass);
+
+    // if len goes past end of range, should get BadLocationException
+    pass = false;
+    try
+    {
+      gc.getString(0, 2);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+
+    // add some more text
+    try
+    {
+      gc.insertString(0, "ABCDEFG");
+    }
+    catch (BadLocationException e)
+    {
+    }
+    harness.check(gc.length(), 8);
+    
+    // if index < 0 should get BadLocationException
+    pass = false;
+    try
+    {
+      /*String s =*/ gc.getString(-1, 3);
+    }
+    catch (StringIndexOutOfBoundsException e) 
+    {
+      pass = false;  // JDK does this, API docs say it should be a 
+                     // BadLocationException
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // if index > end of text should get BadLocationException
+    pass = false;
+    try
+    {
+      /*String s =*/ gc.getString(99, 1);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // if len goes past end of range, should get BadLocationException
+    pass = false;
+    try
+    {
+      /* String s =*/ gc.getString(0, 99);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // try a zero length string
+    pass = false;
+    try
+    {
+      pass = gc.getString(1, 0).equals("");
+    }
+    catch (BadLocationException e)
+    {
+    }
+    harness.check(pass);
+    
+  }
+
+}
\ No newline at end of file
Index: gnu/testlet/javax/swing/text/GapContent/insertString.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/GapContent/insertString.java,v
retrieving revision 1.1
diff -u -r1.1 insertString.java
--- gnu/testlet/javax/swing/text/GapContent/insertString.java	18 Oct 2005 14:24:01 -0000	1.1
+++ gnu/testlet/javax/swing/text/GapContent/insertString.java	24 Jan 2006 16:23:23 -0000
@@ -1,6 +1,7 @@
 // Tags: JDK1.2
 
 // Copyright (C) 2005 Roman Kennke <kennke@aicas.com>
+// Copyright (C) 2006 David Gilbert  <david.gilbert@object-refinery.com>
 
 // This file is part of Mauve.
 
@@ -16,17 +17,17 @@
 
 // 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.
+// the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+// Boston, MA 02110-1301 USA.
 
 package gnu.testlet.javax.swing.text.GapContent;
 
-import javax.swing.text.BadLocationException;
-import javax.swing.text.GapContent;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import javax.swing.text.BadLocationException;
+import javax.swing.text.GapContent;
+
 /**
  * Tests if GapContent.insertString works correctly.
  *
@@ -65,6 +66,7 @@
     testBiggerInsert(harness);
     testBigInsert(harness);
     testComplexInsert(harness);
+    testGeneral(harness);
   }
 
   /**
@@ -169,4 +171,115 @@
     harness.check(c.getTestGapStart(), gapStart);
     harness.check(c.getTestGapEnd(), gapEnd);
   }
+  
+  /**
+   * The same tests that I added for StringContent.java.
+   */
+  public void testGeneral(TestHarness harness)      
+  {
+    harness.checkPoint("testGeneral()");
+    
+    GapContent gc = new GapContent();
+    // regular insert
+    try
+    {
+      gc.insertString(0, "ABC");
+      // ignoring undo/redo here - see insertUndo.java
+    }
+    catch (BadLocationException e)
+    {
+      // ignore - checks below will fail if this happens
+    }
+    harness.check(gc.length(), 4);
+    
+    // insert at location before start
+    boolean pass = false;
+    try
+    {
+      gc.insertString(-1, "XYZ");
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // insert at index of last character - this is OK
+    try
+    {
+      gc.insertString(3, "XYZ");
+    }
+    catch (BadLocationException e)
+    {
+      // ignore
+    }
+    harness.check(gc.length(), 7);
+    
+    // insert at index of last character + 1 - this seems to be OK for 
+    // GapContent, but not StringContent...
+    try
+    {
+      gc.insertString(7, "XYZ");
+    }
+    catch (BadLocationException e)
+    {
+      // ignore
+    }
+    harness.check(gc.length(), 10);
+
+    // insert at index of last character + 2 
+    pass = false;
+    try
+    {
+      gc.insertString(11, "XYZ");
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+
+    // insert empty string
+    try
+    {
+      gc.insertString(0, "");
+    }
+    catch (BadLocationException e)
+    {
+      // ignore
+    }
+    harness.check(gc.length(), 10);
+    
+    // insert null string
+    pass = false;
+    try
+    {
+      gc.insertString(0, null);
+    }
+    catch (BadLocationException e)
+    {
+      // ignore
+    }
+    catch (NullPointerException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // the following can be done with GapContent but not with StringContent
+    harness.checkPoint("anomaly");
+    GapContent gc2 = new GapContent();
+    try
+    {
+      harness.check(gc2.getString(0, 1).equals("\n"));
+      gc2.insertString(1, "X");
+      harness.check(gc2.getString(0, 2).equals("\nX"));      
+    }
+    catch (BadLocationException e)
+    {
+      harness.fail(e.toString());
+    }
+    
+  }
+
 }
Index: gnu/testlet/javax/swing/text/GapContent/length.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/GapContent/length.java
diff -N gnu/testlet/javax/swing/text/GapContent/length.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/GapContent/length.java	24 Jan 2006 16:23:23 -0000
@@ -0,0 +1,62 @@
+/* length.java -- Some checks for the length() method in the GapContent 
+                  class.
+   Copyright (C) 2006  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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: 1.2
+
+package gnu.testlet.javax.swing.text.GapContent;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.GapContent;
+
+public class length implements Testlet
+{
+    
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)      
+  {
+    GapContent gc = new GapContent();
+    harness.check(gc.length(), 1);
+    try 
+    {
+      gc.insertString(0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
+      harness.check(gc.length(), 27);
+      gc.remove(0, 3);
+      harness.check(gc.length(), 24);
+      gc.insertString(4, "123");
+      harness.check(gc.length(), 27);
+      gc.remove(20, 5);
+      harness.check(gc.length(), 22);  
+    }
+    catch (BadLocationException e) 
+    {
+      harness.fail(e.toString());  
+    }
+  }
+
+}
\ No newline at end of file
Index: gnu/testlet/javax/swing/text/GapContent/remove.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/GapContent/remove.java
diff -N gnu/testlet/javax/swing/text/GapContent/remove.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/GapContent/remove.java	24 Jan 2006 16:23:23 -0000
@@ -0,0 +1,142 @@
+/* remove.java -- Some checks for the remove() method in the 
+                  StringContent class.
+   Copyright (C) 2006  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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: 1.2
+
+package gnu.testlet.javax.swing.text.GapContent;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.GapContent;
+
+public class remove implements Testlet
+{
+    
+  /**
+   * Runs the test using the specified harness.
+   * 
+   * @param harness  the test harness (<code>null</code> not permitted).
+   */
+  public void test(TestHarness harness)      
+  {
+    testGeneral(harness);
+    testRemoveLast(harness);
+  }
+  
+  public void testGeneral(TestHarness harness) 
+  {
+    GapContent gc = new GapContent();
+    // regular insert
+    try
+    {
+      gc.insertString(0, "ABCDEFG");
+      // ignoring undo/redo here 
+    }
+    catch (BadLocationException e)
+    {
+      // ignore - checks below will fail if this happens
+    }
+    harness.check(gc.length(), 8);
+    
+    // remove from location before start
+    boolean pass = false;
+    try
+    {
+      gc.remove(-1, 3);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;  // Classpath does this
+    }
+    catch (StringIndexOutOfBoundsException e) 
+    {
+      pass = false;  // JDK does this - it is a bug given the API spec
+    }
+    harness.check(pass);
+    
+    // remove from location after end
+    pass = false;
+    try
+    {
+      gc.remove(99, 1);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // doesn't allow removal of last char
+    pass = false;
+    try
+    {
+      gc.remove(7, 1);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    harness.check(gc.length(), 8);
+
+    // remove 0 chars
+    pass = true;
+    try
+    {
+      gc.remove(0, 0);
+    }
+    catch (BadLocationException e)
+    {
+      pass = false;
+    }
+    harness.check(pass);
+    harness.check(gc.length(), 8);
+    
+  }
+  
+  /**
+   * The API spec says that the last character cannot be removed
+   * (where + nitems < length()).
+   * 
+   * @param harness
+   */
+  public void testRemoveLast(TestHarness harness) 
+  {
+    harness.checkPoint("testRemoveLast");
+    GapContent gc = new GapContent();
+    harness.check(gc.length(), 1);
+    
+    boolean pass = false;
+    try
+    {
+      gc.remove(0, 1);
+    }
+    catch (BadLocationException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+  }
+
+}
\ No newline at end of file

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