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: More ZoneView tests


Here comes more ZoneView tests that test the 2 new methods that I just implemented in Classpath.

2006-08-29 Roman Kennke <kennke@aicas.com>

	* gnu/testlet/javax/swing/text/ZoneView/TestZoneView.java
	(getViewIndexAtPosition): Overridden to make public.
	(loadChildren): Likewise.
	(getViewFactory): Overridden to provide a ViewFactory.
	* gnu/testlet/javax/swing/text/ZoneView/getViewIndexAtPosition.java:
	New tests.
	* gnu/testlet/javax/swing/text/ZoneView/loadChildren.java:
	New tests.

/Roman
Index: gnu/testlet/javax/swing/text/ZoneView/TestZoneView.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/ZoneView/TestZoneView.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 TestZoneView.java
--- gnu/testlet/javax/swing/text/ZoneView/TestZoneView.java	30 Aug 2006 15:22:33 -0000	1.1
+++ gnu/testlet/javax/swing/text/ZoneView/TestZoneView.java	30 Aug 2006 20:02:07 -0000
@@ -19,24 +19,25 @@
 
 */
 
 // Tags: not-a-test
 
 package gnu.testlet.javax.swing.text.ZoneView;
 
 import java.util.ArrayList;
 
 import javax.swing.text.Element;
 import javax.swing.text.PlainDocument;
 import javax.swing.text.View;
+import javax.swing.text.ViewFactory;
 import javax.swing.text.ZoneView;
 
 public class TestZoneView extends ZoneView
 {
 
   private static final Element DEFAULT_ELEMENT;
   static
   {
     PlainDocument doc = new PlainDocument();
     Element el = doc.getDefaultRootElement();
     DEFAULT_ELEMENT = el;
   }
@@ -73,13 +74,36 @@
     lastUnloadedZones.add(zone);
   }
 
   public boolean isZoneLoaded(View z)
   {
     return super.isZoneLoaded(z);
   }
 
   public View createZone(int p0, int p1)
   {
     return super.createZone(p0, p1);
   }
+
+  public int getViewIndexAtPosition(int pos)
+  {
+    return super.getViewIndexAtPosition(pos);
+  }
+
+  public void loadChildren(ViewFactory vf)
+  {
+    super.loadChildren(vf);
+  }
+
+  public ViewFactory getViewFactory()
+  {
+    return new ViewFactory()
+    {
+
+      public View create(Element elem)
+      {
+        return new TestView(elem, View.X_AXIS);
+      }
+      
+    };
+  }
 }
Index: gnu/testlet/javax/swing/text/ZoneView/getViewIndexAtPosition.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/ZoneView/getViewIndexAtPosition.java
diff -N gnu/testlet/javax/swing/text/ZoneView/getViewIndexAtPosition.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/ZoneView/getViewIndexAtPosition.java	30 Aug 2006 20:02:07 -0000
@@ -0,0 +1,75 @@
+/* getViewIndexAtPosition.java -- Checks ZoneViewgetViewIndexAtPosition()
+   Copyright (C) 2006 Roman Kennke (kennke@aicas.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: JDK1.3
+
+package gnu.testlet.javax.swing.text.ZoneView;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Element;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.View;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+public class getViewIndexAtPosition implements Testlet
+{
+
+  public void test(TestHarness h)
+  {
+    PlainDocument doc = new PlainDocument();
+    try
+      {
+        doc.insertString(0, "0123456789", null);
+      }
+    catch (BadLocationException ex)
+      {
+        RuntimeException rte = new RuntimeException();
+        rte.initCause(ex);
+        throw rte;
+      }
+    Element el = doc.getDefaultRootElement();
+    TestZoneView zv = new TestZoneView(el, View.X_AXIS);
+    zv.append(zv.createZone(0, 3));
+    zv.append(zv.createZone(3, 7));
+    zv.append(zv.createZone(7, 10));
+
+    h.check(zv.getViewIndexAtPosition(-100), -1);
+    h.check(zv.getViewIndexAtPosition(-1), -1);
+    h.check(zv.getViewIndexAtPosition(0), 0);
+    h.check(zv.getViewIndexAtPosition(2), 0);
+    h.check(zv.getViewIndexAtPosition(3), 1);
+    h.check(zv.getViewIndexAtPosition(6), 1);
+    h.check(zv.getViewIndexAtPosition(7), 2);
+    h.check(zv.getViewIndexAtPosition(9), 2);
+    // This is a noteworthy detail: The offset 10 isn't actually covered
+    // by any child view, but the endOffset of the view (11) yields the index
+    // of the last view in the RI. I think this is a bug in Sun's impl as the
+    // method should return -1 if the offset isn't covered by any child view.
+    h.check(zv.getViewIndexAtPosition(10), -1);
+    // The RI does the following:
+    //h.check(zv.getViewIndexAtPosition(11), 2);
+    h.check(zv.getViewIndexAtPosition(11), -1);
+    h.check(zv.getViewIndexAtPosition(100), -1);
+  }
+
+}
Index: gnu/testlet/javax/swing/text/ZoneView/loadChildren.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/ZoneView/loadChildren.java
diff -N gnu/testlet/javax/swing/text/ZoneView/loadChildren.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/ZoneView/loadChildren.java	30 Aug 2006 20:02:07 -0000
@@ -0,0 +1,105 @@
+/* loadChildren.java -- Tests ZoneView.loadChildren().
+   Copyright (C) 2006 Roman Kennke (kennke@aicas.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: JDK1.3
+
+package gnu.testlet.javax.swing.text.ZoneView;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Element;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.View;
+import javax.swing.text.AbstractDocument.BranchElement;
+import javax.swing.text.AbstractDocument.LeafElement;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+public class loadChildren implements Testlet
+{
+
+  public void test(TestHarness harness)
+  {
+    testSimple(harness);
+    testOversize(harness);
+  }
+
+  private void testSimple(TestHarness h)
+  {
+    PlainDocument doc = new PlainDocument();
+    try
+      {
+        doc.insertString(0, "0123456789", null);
+      }
+    catch (BadLocationException ex)
+      {
+        RuntimeException rte = new RuntimeException();
+        rte.initCause(ex);
+        throw rte;
+      }
+    Element el = doc.getDefaultRootElement();
+    TestZoneView zv = new TestZoneView(el, View.Y_AXIS);
+    zv.loadChildren(zv.getViewFactory());
+    h.check(zv.getViewCount(), 1);
+    View child = zv.getView(0);
+    h.check(child.getStartOffset(), 0);
+    h.check(child.getEndOffset(), el.getEndOffset());
+  }
+
+  private void testOversize(TestHarness h)
+  {
+    PlainDocument doc = new PlainDocument();
+    try
+      {
+        doc.insertString(0, "0123456789", null);
+      }
+    catch (BadLocationException ex)
+      {
+        RuntimeException rte = new RuntimeException();
+        rte.initCause(ex);
+        throw rte;
+      }
+    
+    BranchElement el = (BranchElement) doc.getDefaultRootElement();
+    // Modify the element structure a little and seen how the initial
+    // elements are created then.
+    LeafElement el1 = doc.new LeafElement(el, null, 0, 3);
+    LeafElement el2 = doc.new LeafElement(el, null, 3, 7);
+    LeafElement el3 = doc.new LeafElement(el, null, 7, 11);
+    el.replace(0, 1, new Element[]{el1, el2, el3});
+
+
+    TestZoneView zv = new TestZoneView(el, View.Y_AXIS);
+    // Set the maximum zone size somewhere inside the second element.
+    zv.setMaximumZoneSize(5);
+    zv.loadChildren(zv.getViewFactory());
+    h.check(zv.getViewCount(), 3);
+    View child = zv.getView(0);
+    h.check(child.getStartOffset(), 0);
+    h.check(child.getEndOffset(), 3);
+    child = zv.getView(1);
+    h.check(child.getStartOffset(), 3);
+    h.check(child.getEndOffset(), 7);
+    child = zv.getView(2);
+    h.check(child.getStartOffset(), 7);
+    h.check(child.getEndOffset(), 11);
+  }
+}

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