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: changes to all the ElementBuffer tests


Committed large changes to the DefaultStyledDocument.ElementBuffer
tests.  

Now, each of these tests does the following:
- subclasses DefaultStyledDocument
- subclasses ElementBuffer
- overrides createLeafElement and createBranchElement to test if the
correct Elements are being created
- overrides DefaultStyledDocument.insertUpdate to test if the
DocumentEvents are coming in correctly
- overrides ElementBuffer.insertUpdate to test if the ElementSpecs
created by DefaultStyledDocument.insertUpdate are correct

Before each of the tests were doing a smaller subset of these tests, but
now they each do them all.  


2006-01-23  Anthony Balkissoon  <abalkiss@redhat.com>

	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure1.java: Added more detailed tests.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure2.java: Removed this test because it is a duplicate of 
	ElementStructure1.java.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure3.java: Added more detailed tests.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure7.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument1.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument2.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument3.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument4.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument5.java: Likewise.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument6.java: Likewise.

--Tony
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure1.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure1.java,v
retrieving revision 1.1
diff -u -r1.1 ElementStructure1.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure1.java	20 Dec 2005 19:20:18 -0000	1.1
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure1.java	23 Jan 2006 18:26:25 -0000
@@ -1,6 +1,6 @@
 // Tags: JDK1.2
 
-// Copyright (C) 2005 Red Hat.
+// Copyright (C) 2006 Red Hat.
 
 // This file is part of Mauve.
 
@@ -21,53 +21,246 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.DefaultStyledDocument;
 import javax.swing.text.Element;
-import javax.swing.text.SimpleAttributeSet;
-import javax.swing.text.DefaultStyledDocument;
-
-import gnu.testlet.TestHarness;
-import gnu.testlet.Testlet;
 
-public class ElementStructure1 implements Testlet
+public class ElementStructure1 extends DefaultStyledDocument implements Testlet
 {
-  /**
-   * Starts the test run.
-   *
-   * @param harness the test harness to use
-   */
+	/**
+	 * Starts the test run.
+	 * 
+	 * @param harness
+	 *            the test harness to use
+	 */
   public void test(TestHarness harness)
   {
-    DefaultStyledDocument doc = new DefaultStyledDocument();
+    h2 = harness;
+    ElementStructure1 doc = new ElementStructure1();
     Element root = doc.getDefaultRootElement();
     try
       {
-        // Add some regular text
+        // In this test no new LeafElements or BranchElements should be 
+        // created.  We're able to add everything to the original Element
+        // that was created when the document was constructed.
+        harness.checkPoint ("initial setup");
         harness.check (root.getElementCount() == 1);
         harness.check (root.getElement(0).getElementCount() == 1);
-        harness.check (root.getElement(0).getElement(0).getElementCount() == 0);
+        harness.check 
+          (root.getElement(0).getElement(0).getElementCount() == 0);        
         doc.insertString(0, "the quick brown fox", null);
 
+        harness.checkPoint("after first insertion");
         harness.check (root.getElementCount() == 1);
         harness.check (root.getElement(0).getElementCount() == 1);
-        harness.check (root.getElement(0).getElement(0).getElementCount() == 0);
-        doc.insertString(6, "MIDDLE", null);
+        harness.check 
+          (root.getElement(0).getElement(0).getElementCount() == 0);
+        harness.check (root.getEndOffset() == 20);
+        doc.insertString(6, "MIDDLE", null);        
 
+        harness.checkPoint("after second insertion");
         harness.check (root.getElementCount() == 1);
         harness.check (root.getElement(0).getElementCount() == 1);
-        harness.check (root.getElement(0).getElement(0).getElementCount() == 0);
-        doc.insertString(0, "START", null);
+        harness.check 
+          (root.getElement(0).getElement(0).getElementCount() == 0);
+        harness.check (root.getEndOffset() == 26);
+        doc.insertString(0, "START", null);        
 
+        harness.checkPoint("after third insertion");
         harness.check (root.getElementCount() == 1);
         harness.check (root.getElement(0).getElementCount() == 1);
-        harness.check (root.getElement(0).getElement(0).getElementCount() == 0);
-        doc.insertString(30, "END", null);        
+        harness.check 
+          (root.getElement(0).getElement(0).getElementCount() == 0);
+        harness.check (root.getEndOffset() == 31);
+        doc.insertString(30, "END", null);
+        
+        harness.checkPoint("after fourth insertion");
+        harness.check(root.getEndOffset() == 34);
+
+        // printElements(doc.getDefaultRootElement(), 0);
       }
     catch (BadLocationException ex)
       {
+        // ex.printStackTrace();
         harness.debug(ex);
-      }        
+      }
+    catch (AssertionError ex)
+      {
+        // ex.printStackTrace();
+        harness.debug(ex);
+      }
+  }
+  
+  static TestHarness h2;
+  static int numInserts = 0;
+  static int numLeaves = 0;
+  static int numBranches = 0;
 
+  public ElementStructure1()
+  {
+    // We override the constructor so we can explicitly set the type of the
+    // buffer to be our ElementBuffer2, allowing us to test some internals.
+    super();
+    buffer = new ElementBuffer2(createDefaultRoot());
+  }
+
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.check(o == 0);
+        h2.check(l == 19);
+      }
+    else if (numInserts == 1)
+    {
+      h2.check(o == 6);
+      h2.check(l == 6);
+    } 
+    else if (numInserts == 2)
+      {
+        h2.check(o == 0);
+        h2.check(l == 5);
+      }
+    else if (numInserts == 3)
+      {
+        h2.check(o == 30);
+        h2.check(l == 3);
+      }
+    else
+      h2.fail ("too many calls to DefaultStyledDocument.insertUpdate");
+    super.insertUpdate(ev, attr);
+  }
+  
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, 
+                                      AttributeSet a, int p0, int p1)
+  {
+    numLeaves ++;
+    // In this test if we create a new LeafElement the test should fail.
+    h2.fail("no new leaf elements should be created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+  
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent,
+                                        AttributeSet a)
+  {
+    numBranches ++;
+    // In this test if we create a new BranchElement the test should fail.
+    h2.fail("no new branch elements should be created");
+    return super.createBranchElement(parent, a);
+  }
+  
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements (Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println ("ROOT ELEMENT ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println ("BranchElement ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else
+      {
+        try
+          {
+            System.out.println ("LeafElement ("+start.getStartOffset()+", "
+                                + start.getEndOffset()+"): "
+                                + start.getAttributes().getAttributeCount() + 
+                                ": "
+                                + start.getDocument().
+                                getText(start.getStartOffset(), 
+                                        start.getEndOffset() - 
+                                        start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i ++)
+      printElements (start.getElement(i), pad+3);
+  }
+
+  
+  // A class to be the buffer of the styled document.
+  // This allows us to check that some values are correct internally within
+  // the ElementBuffer.
+  public class ElementBuffer2 extends ElementBuffer
+  {
+    public ElementBuffer2(Element root)
+    {
+      super(root);
+    }
+    
+    // This method allows us to check that the ElementSpecs generated by 
+    // DefaultStyledDocument.insertUpdate are correct.
+    protected void insertUpdate(ElementSpec[] data)
+    {
+      numInserts ++;
+      if (numInserts == 1)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: first insertion");
+          h2.check (data.length == 1);
+          h2.check (data[0].getType() == ElementSpec.ContentType);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check (data[0].getOffset() == 0);
+          h2.check (data[0].getLength() == 19);
+        }
+      else if (numInserts == 2)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: second insertion");
+          h2.check (data.length == 1);
+          h2.check (data[0].getType() == ElementSpec.ContentType);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check (data[0].getOffset() == 0);
+          h2.check (data[0].getLength() == 6);
+        }
+      else if (numInserts == 3)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: third insertion");
+          h2.check (data.length == 1);
+          h2.check (data[0].getType() == ElementSpec.ContentType);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check (data[0].getOffset() == 0);
+          h2.check (data[0].getLength() == 5);
+        }
+      else if (numInserts == 4)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: fourth insertion");
+          h2.check (data.length == 1);
+          h2.check (data[0].getType() == ElementSpec.ContentType);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check (data[0].getOffset() == 0);
+          h2.check (data[0].getLength() == 3);
+        }
+      else
+        h2.fail("too many ElementSpecs created");
+      super.insertUpdate(data);
+    }
   }
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure2.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure2.java
diff -N gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure2.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure2.java	21 Dec 2005 18:31:54 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,85 +0,0 @@
-// Tags: JDK1.2
-
-// Copyright (C) 2005 Red Hat.
-
-// 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.
-
-package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
-
-import javax.swing.text.BadLocationException;
-import javax.swing.text.DefaultStyledDocument;
-import javax.swing.text.Element;
-import javax.swing.text.SimpleAttributeSet;
-import javax.swing.text.DefaultStyledDocument;
-
-import gnu.testlet.TestHarness;
-import gnu.testlet.Testlet;
-
-public class ElementStructure2 extends DefaultStyledDocument implements Testlet
-{
-
-  static TestHarness h2;
-
-  // Creates a new StyledDocument2 using an ElementBuffer2 as the buffer
-  public ElementStructure2()
-  {
-    super();
-    buffer = new ElementBuffer2(createDefaultRoot());
-  }
-
-  
- public class ElementBuffer2 extends ElementBuffer
-  {
-    public ElementBuffer2(Element root)
-    {
-      super(root);
-    }
-    
-    protected void insertUpdate(ElementSpec[] data)
-    {
-      // Check that ElementSpecs were created with JoinPreviousDirection
-      for (int i = 0; i < data.length; i ++)
-        h2.check (data[i].getDirection() == ElementSpec.JoinPreviousDirection);
-      super.insertUpdate(data);
-    }
-  }
-  /**
-   * Starts the test run.
-   *
-   * @param harness the test harness to use
-   */
-  public void test(TestHarness harness)
-  {
-    h2 = harness;
-    DefaultStyledDocument doc = new ElementStructure2();
-    Element root = doc.getDefaultRootElement();
-    try
-      {
-        // Add some regular text
-        doc.insertString(0, "the quick brown fox", null);
-        doc.insertString(6, "MIDDLE", null);
-        doc.insertString(0, "START", null);
-        doc.insertString(30, "END", null);        
-      }
-    catch (BadLocationException ex)
-      {
-        harness.debug(ex);
-      }        
-
-  }
-}
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure3.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure3.java,v
retrieving revision 1.3
diff -u -r1.3 ElementStructure3.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure3.java	21 Dec 2005 22:12:53 -0000	1.3
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure3.java	23 Jan 2006 18:26:25 -0000
@@ -1,6 +1,6 @@
 // Tags: JDK1.2
 
-// Copyright (C) 2005 Red Hat.
+// Copyright (C) 2006 Red Hat.
 
 // This file is part of Mauve.
 
@@ -21,30 +21,66 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.text.DefaultStyledDocument;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Segment;
-import javax.swing.text.AttributeSet;
-import javax.swing.text.Element;
-import javax.swing.JTextPane;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.Segment;
+
 public class ElementStructure3 extends DefaultStyledDocument implements Testlet
 {
-
+	/**
+   * Starts the test run.
+   * 
+   * @param harness
+   *          the test harness to use
+   */
+public void test(TestHarness harness)
+  {
+    h2 = harness;
+    try
+    {
+      ElementStructure3 doc = new ElementStructure3();
+      doc.insertString(0, "Questions are <font size=\"+1\" color=\"blue\">a "
+                       + "burden</font> to others,\n"
+                       + "answers <font size=\"+2\" color=\"red\">a "
+                       + "prison</font> for oneself.", null);
+      // printElements(doc.getDefaultRootElement(), 0);
+    }
+    catch (Exception t)
+    {
+      // t.printStackTrace();
+      harness.debug(t);
+    }    
+    catch (AssertionError e)
+    {
+      // e.printStackTrace();
+      harness.debug(e);
+    }
+  }
+  
   static TestHarness h2;
+  static int numInserts = 0;
+  static int numLeaves = 0;
+  static int numBranches = 0;
 
-  // Creates a new ElementStructure3 using an ElementBuffer2 as the buffer
+  // We override the constructor so we can explicitly set the type of the
+  // buffer to be our ElementBuffer2, allowing us to test some internals.
   public ElementStructure3()
   {
-    super();
+    super();    
     buffer = new ElementBuffer2(createDefaultRoot());
   }
-
+  
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
   protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
-  {
+  {    
     int newLines = 0;
     h2.check (ev.getLength() == 134);
     h2.check (ev.getOffset() == 0);
@@ -64,69 +100,171 @@
           newLines ++;
       }
     h2.check (newLines == 1);
-    h2.check (txt.array[i] == '\n');
+    h2.check (txt.array[i] == '\n');    
     super.insertUpdate(ev, attr);
   }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, 
+                                      AttributeSet a, int p0, int p1)
+  {
+    // In this test 3 LeafElements should be created.
+    numLeaves++;
+    if (numLeaves== 1)
+      {
+        h2.checkPoint ("create first leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 70);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 135);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint ("create second leaf element");
+        h2.check (p0 == 134);
+        h2.check (p1 == 135);
+        h2.check (parent.getElementCount() == 0);
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint ("create third leaf element");
+        h2.check (p0 == 70);
+        h2.check (p1 == 135);
+        try
+        {
+          h2.check (parent.getStartOffset() == 134);
+          h2.check (parent.getEndOffset() == 135);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+  
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent,
+                                        AttributeSet a)
+  {
+    // In this test we create 1 new BranchElement.    
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 135);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
   
- public class ElementBuffer2 extends ElementBuffer
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements (Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println ("ROOT ELEMENT ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println ("BranchElement ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else
+      {
+        try
+          {
+            System.out.println ("LeafElement ("+start.getStartOffset()+", "
+                                + start.getEndOffset()+"): "
+                                + start.getAttributes().getAttributeCount() 
+                                + ": "
+                                + start.getDocument().
+                                getText(start.getStartOffset(), 
+                                        start.getEndOffset() - 
+                                        start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i ++)
+      printElements (start.getElement(i), pad+3);
+  }
+
+  
+  // A class to be the buffer of the styled document.
+  // This allows us to check that some values are correct internally within
+  // the ElementBuffer.
+  public class ElementBuffer2 extends ElementBuffer
   {
     public ElementBuffer2(Element root)
     {
       super(root);
     }
     
+    // This method allows us to check that the ElementSpecs generated by 
+    // DefaultStyledDocument.insertUpdate are correct.
     protected void insertUpdate(ElementSpec[] data)
     {
-      // Check that ElementSpecs were created with the proper direction, offset
-      // and length, and that the right number of Specs were created.
-      h2.check (data.length == 4);
-      for (int i = 0; i < data.length; i ++)
+      numInserts ++;
+      if (numInserts == 1)
         {
-          short s = data[i].getDirection();
-          if (s == ElementSpec.JoinPreviousDirection)
-            {
-              h2.check (data[i].getOffset() == 0);
-              h2.check (data[i].getLength() == 70);
-            }
-          else if (s == ElementSpec.JoinNextDirection)
-            {
-              h2.check (data[i].getOffset() == 0);
-              h2.check (data[i].getLength() == 64);
-            }
-          else if (s == ElementSpec.JoinFractureDirection)
-            {
-              h2.check (data[i].getOffset() == 0);
-              h2.check (data[i].getLength() == 0);
-            }
-          else if (s == ElementSpec.OriginateDirection)
-            {
-              h2.check (data[i].getOffset() == 0);
-              h2.check (data[i].getLength() == 0);
-            }
+          h2.checkPoint("ElementBuffer insertUpdate: first insertion");
+          h2.check (data.length == 4);
+          h2.check (data[0].getType() == ElementSpec.ContentType);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check (data[0].getOffset() == 0);
+          h2.check (data[0].getLength() == 70);
+          
+          h2.check (data[1].getType() == ElementSpec.EndTagType);
+          h2.check (data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check (data[1].getOffset() == 0);
+          h2.check (data[1].getLength() == 0);
+
+          h2.check (data[2].getType() == ElementSpec.StartTagType);
+          h2.check 
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check (data[2].getOffset() == 0);
+          h2.check (data[2].getLength() == 0);
+
+          h2.check (data[3].getType() == ElementSpec.ContentType);
+          h2.check (data[3].getDirection() == ElementSpec.JoinNextDirection);
+          h2.check (data[3].getOffset() == 0);
+          h2.check (data[3].getLength() == 64);
         }
+      else 
+        h2.fail("too many ElementSpecs created");
       super.insertUpdate(data);
     }
   }
-  /**
-   * Starts the test run.
-   *
-   * @param harness the test harness to use
-   */
-  public void test(TestHarness harness)
-  {
-    try
-      {
-        h2 = harness;
-        JTextPane tp = new JTextPane();
-        tp.setDocument(new ElementStructure3());
-        tp.setText("Questions are <font size=\"+1\" color=\"blue\">a " + 
-                   "burden</font> to others,\n" +
-                   "answers <font size=\"+2\" color=\"red\">a " + 
-                   "prison</font> for oneself.");
-      }
-    catch (Throwable t)
-      {
-        harness.debug(t);
-      }
-  }
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java,v
retrieving revision 1.2
diff -u -r1.2 ElementStructure4.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java	20 Jan 2006 22:06:00 -0000	1.2
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java	23 Jan 2006 18:26:25 -0000
@@ -1,6 +1,6 @@
 // Tags: JDK1.2
 
-// Copyright (C) 2005 Red Hat.
+// Copyright (C) 2006 Red Hat.
 
 // This file is part of Mauve.
 
@@ -21,16 +21,18 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.text.DefaultStyledDocument;
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
 import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
 import javax.swing.text.Element;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.StyleConstants;
 
-import gnu.testlet.TestHarness;
-import gnu.testlet.Testlet;
-
-public class ElementStructure4 implements Testlet
+public class ElementStructure4 extends DefaultStyledDocument implements Testlet
 {
   /**
    * Starts the test run.
@@ -41,7 +43,8 @@
   {
     try
       {
-        DefaultStyledDocument doc = new DefaultStyledDocument();
+        h2 = harness;
+        ElementStructure4 doc = new ElementStructure4();
         SimpleAttributeSet atts = new SimpleAttributeSet();
         Element root = doc.getDefaultRootElement();
 
@@ -49,22 +52,25 @@
         atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
         doc.insertString(0, "Strike through text.\n", atts);
         atts.removeAttributes(atts);
+        harness.checkPoint("after first insertion");
         harness.check(root.getElementCount() == 2);
         harness.check(root.getElement(0).getStartOffset() == 0);
         harness.check(root.getElement(0).getEndOffset() == 21);
         harness.check(root.getElement(1).getStartOffset() == 21);
         harness.check(root.getElement(1).getEndOffset() == 22);
 
-
         // Add plain text in front.
         doc.insertString(0, "a", null);
+        harness.checkPoint("after second insertion");
         harness.check(root.getElement(0).getElementCount() == 2);
         harness.check(root.getElement(1).getElementCount() == 1);
+
         doc.insertString(1, "b", null);
+        harness.checkPoint("after second insertion");
         harness.check(root.getElement(0).getElementCount() == 2);
         harness.check(root.getElement(1).getElementCount() == 1);
 
-
+        harness.checkPoint("final structure");
         Element first = root.getElement(0).getElement(0);
         harness.check(first.getStartOffset() == 0);
         harness.check(first.getEndOffset() == 2);
@@ -72,10 +78,257 @@
         Element second = root.getElement(0).getElement(1);
         harness.check(second.getStartOffset() == 2);
         harness.check(second.getEndOffset() == 23);
+        // printElements(doc.getDefaultRootElement(), 0);
+      }
+    catch (Exception t)
+      {
+        // t.printStackTrace();
+        harness.debug(t);
+      }
+    catch (AssertionError e)
+      {
+        // e.printStackTrace();
+        harness.debug(e);
+      }
+  }
+
+  static TestHarness h2;
+
+  static int numInserts = 0;
+
+  static int numLeaves = 0;
+
+  static int numBranches = 0;
+
+  // We override the constructor so we can explicitly set the type of the
+  // buffer to be our ElementBuffer2, allowing us to test some internals.
+  public ElementStructure4()
+  {
+    super();
+    buffer = new ElementBuffer2(createDefaultRoot());
+  }
+
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 21);
       }
-    catch (Throwable t)
+    else if (numInserts == 1)
+    {
+      h2.checkPoint("second doc event");
+      h2.check(o == 0);      
+      h2.check(l == 1);
+    } 
+    else if (numInserts == 2)
       {
-        harness.fail(t.toString());
+        h2.checkPoint("third doc event");
+        h2.check(o == 1);
+        h2.check(l == 1);
       }
+    else
+      h2.fail ("too many calls to DefaultStyledDocument.insertUpdate");
+
+    super.insertUpdate(ev, attr);
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, AttributeSet a, int p0,
+                                      int p1)
+  {
+    // In this test we create 4 new LeafElements.
+    numLeaves++;
+    if (numLeaves == 1)
+      {
+        h2.checkPoint("create first leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 22);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("parent Element should have children, but has none.");
+            h2.fail("parent Element should have children, but has none.");
+          }
+        h2.check(a.getAttributeCount() == 1);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint("create second leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 22);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint("create third leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 1);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 22);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint("create fourth leaf element");
+        h2.check(p0 == 1);
+        h2.check(p1 == 22);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 22);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 1);        
+      }
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent, AttributeSet a)
+  {
+    // In this test we create 1 new BranchElement.    
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 22);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else 
+      h2.fail("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements(Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println("ROOT ELEMENT (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println("BranchElement (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else
+      {
+        try
+          {
+            System.out.println("LeafElement ("+ start.getStartOffset()
+                               + ", " + start.getEndOffset() + "): "
+                               + start.getAttributes().getAttributeCount()
+                               + ": " + start.getDocument().
+                               getText(start.getStartOffset(),
+                                       start.getEndOffset()
+                                       - start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i++)
+      printElements(start.getElement(i), pad + 3);
+  }
+
+  // A class to be the buffer of the styled document.
+  // This allows us to check that some values are correct internally within
+  // the ElementBuffer.
+  public class ElementBuffer2 extends ElementBuffer
+  {
+    public ElementBuffer2(Element root)
+    {
+      super(root);
+    }
+
+    // This method allows us to check that the ElementSpecs generated by 
+    // DefaultStyledDocument.insertUpdate are correct.
+    protected void insertUpdate(ElementSpec[] data)
+    {
+      numInserts++;
+      if (numInserts == 1)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: first insertion");
+          h2.check (data.length == 3);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check(data[0].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 21);
+
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0);
+        }
+      else if (numInserts == 2)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: second insertion");
+          h2.check (data.length == 1);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check(data[0].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 1);          
+        }
+      else if (numInserts == 3)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: third insertion");
+          h2.check (data.length == 1);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 1);          
+        }
+      else
+        h2.fail("too many ElementSpecs created");
+      super.insertUpdate(data);
+    }
   }
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java,v
retrieving revision 1.1
diff -u -r1.1 ElementStructure5.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java	4 Jan 2006 16:32:46 -0000	1.1
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java	23 Jan 2006 18:26:25 -0000
@@ -1,6 +1,6 @@
 // Tags: JDK1.2
 
-// Copyright (C) 2005 Red Hat.
+// Copyright (C) 2006 Red Hat.
 
 // This file is part of Mauve.
 
@@ -21,14 +21,16 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.text.DefaultStyledDocument;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Element;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
-public class ElementStructure5 implements Testlet
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+
+public class ElementStructure5 extends DefaultStyledDocument implements Testlet
 {
   /**
    * Starts the test run.
@@ -39,7 +41,8 @@
   {
     try
       {
-        DefaultStyledDocument doc = new DefaultStyledDocument();
+        h2 = harness;
+        ElementStructure5 doc = new ElementStructure5();
         Element root = doc.getDefaultRootElement();
 
         // Add a first line of text.
@@ -70,10 +73,271 @@
         Element third = root.getElement(2).getElement(0);
         harness.check(third.getStartOffset() == 43);
         harness.check(third.getEndOffset() == 44);
+        
+        // printElements(doc.getDefaultRootElement(), 0);
       }
-    catch (Throwable t)
+    catch (Exception t)
       {
+        // t.printStackTrace();
         harness.debug(t);
       }
+    catch (AssertionError e)
+      {
+        // e.printStackTrace();
+        harness.debug(e);
+      }
+  }
+  
+  static TestHarness h2;
+
+  static int numInserts = 0;
+
+  static int numLeaves = 0;
+
+  static int numBranches = 0;
+
+  // We override the constructor so we can explicitly set the type of the
+  // buffer to be our ElementBuffer2, allowing us to test some internals.
+  public ElementStructure5()
+  {
+    super();
+    buffer = new ElementBuffer2(createDefaultRoot());
+  }
+
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 21);
+      }
+    else if (numInserts == 1)
+    {
+      h2.checkPoint("second doc event");
+      h2.check(o == 21);      
+      h2.check(l == 22);
+    } 
+    else
+      h2.fail ("too many calls to DefaultStyledDocument.insertUpdate");
+
+    super.insertUpdate(ev, attr);
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, AttributeSet a, int p0,
+                                      int p1)
+  {
+    numLeaves++;
+    if (numLeaves == 1)
+      {
+        h2.checkPoint("create first leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 22);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("parent Element should have children, but has none.");
+            h2.fail("parent Element should have children, but has none.");
+          }        
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint("create second leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 22);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint("create third leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 43);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint("create fourth leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 43);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent, AttributeSet a)
+  {    
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create first branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 22);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numBranches == 2)
+      {
+        h2.checkPoint("create second branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 44);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else
+      h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements(Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println("ROOT ELEMENT (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println("BranchElement (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else
+      {
+        try
+          {
+            System.out.println("LeafElement ("
+                               + start.getStartOffset()
+                               + ", "
+                               + start.getEndOffset()
+                               + "): "
+                               + start.getAttributes().getAttributeCount()
+                               + ": "
+                               + start.getDocument().
+                               getText(start.getStartOffset(),
+                                       start.getEndOffset()
+                                       - start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i++)
+      printElements(start.getElement(i), pad + 3);
+  }
+
+  // A class to be the buffer of the styled document.
+  // This allows us to check that some values are correct internally within
+  // the ElementBuffer.
+  public class ElementBuffer2 extends ElementBuffer
+  {
+    public ElementBuffer2(Element root)
+    {
+      super(root);
+    }
+
+    // This method allows us to check that the ElementSpecs generated by 
+    // DefaultStyledDocument.insertUpdate are correct.
+    protected void insertUpdate(ElementSpec[] data)
+    {
+      numInserts++;
+      if (numInserts == 1)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: first insertion");
+          h2.check (data.length == 3);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 21);
+
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0);
+        }
+      else if (numInserts == 2)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: second insertion");
+          h2.check (data.length == 5);
+          h2.check(data[0].getType() == ElementSpec.EndTagType);
+          h2.check(data[0].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 0);
+          
+          h2.check(data[1].getType() == ElementSpec.StartTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);          
+          
+          h2.check(data[2].getType() == ElementSpec.ContentType);
+          h2.check(data[2].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 22);
+          
+          h2.check(data[3].getType() == ElementSpec.EndTagType);
+          h2.check(data[3].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 0);
+          
+          h2.check(data[4].getType() == ElementSpec.StartTagType);
+          h2.check(data[4].getDirection() == ElementSpec.JoinNextDirection);
+          h2.check(data[4].getOffset() == 0);
+          h2.check(data[4].getLength() == 0);          
+        }
+      else if (numInserts == 3)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: third insertion");
+          h2.check (data.length == 1);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 1);          
+        }
+      else
+        h2.fail("too many ElementSpecs created");
+      super.insertUpdate(data);
+    }
   }
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java,v
retrieving revision 1.1
diff -u -r1.1 ElementStructure6.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java	5 Jan 2006 19:32:51 -0000	1.1
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java	23 Jan 2006 18:26:25 -0000
@@ -21,76 +21,267 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.text.*;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
-public class ElementStructure6 implements Testlet
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+
+public class ElementStructure6 extends DefaultStyledDocument implements Testlet
 {
-  static TestHarness h2;
-  static DefaultStyledDocument doc = new StyledDocument2();
-  static AbstractDocument.DefaultDocumentEvent docEvent = null;
-  
   public void test(TestHarness harness)
   {
+    ElementStructure6 doc = new ElementStructure6();
     try
       {
         h2 = harness;
         doc.insertString(0, "First line of text. \n", null);
       }
-    catch (BadLocationException ex)
+    catch (Exception ex)
       {
+        // ex.printStackTrace();
         h2.debug(ex);
-      }        
+      }
+    catch (AssertionError e)
+      {
+        // e.printStackTrace();
+        harness.debug(e);
+      }
+    //printElements(doc.getDefaultRootElement(), 0);
   }
   
+  static TestHarness h2;
+  
+  static AbstractDocument.DefaultDocumentEvent docEvent = null;
+
+  static int numInserts = 0;
 
-  static class StyledDocument2 extends DefaultStyledDocument
+  static int numLeaves = 0;
+
+  static int numBranches = 0;  
+
+  // We override the constructor so we can explicitly set the type of the
+  // buffer to be our ElementBuffer2, allowing us to test some internals.
+  public ElementStructure6()
   {
-    public class ElementBuffer2 extends ElementBuffer
-    {
-      public ElementBuffer2(Element root)
+    super();
+    buffer = new ElementBuffer2(createDefaultRoot());
+  }
+
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
       {
-        super(root);
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 21);
       }
-      
-      // ElementBuffer.insertUpdate
-      protected void insertUpdate(ElementSpec[] data)
+    else
+      h2.fail ("too many calls to DefaultStyledDocument.insertUpdate");
+
+    docEvent = ev;
+    h2.check(docEvent.getChange(getDefaultRootElement()) == null);
+    super.insertUpdate (ev, attr);
+    h2.check(docEvent.getChange(getDefaultRootElement()) != null);
+
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, AttributeSet a, int p0,
+                                      int p1)
+  {
+    numLeaves++;
+    if (numLeaves == 1)
       {
-        h2.check(docEvent.getChange(getDefaultRootElement()) == null);
-        super.insertUpdate(data);
-        h2.check(docEvent.getChange(getDefaultRootElement()) == null);
+        h2.checkPoint("create first leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 22);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("parent Element should have children, but has none.");
+            h2.fail("parent Element should have children, but has none.");
+          }        
+        h2.check(a.getAttributeCount() == 0);
       }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint("create second leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 22);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent, AttributeSet a)
+  {    
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create first branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 22);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
 
-      public void insert(int offset,
-                         int length,
-                         DefaultStyledDocument.ElementSpec[] data,
-                         AbstractDocument.DefaultDocumentEvent de)
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements(Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println("ROOT ELEMENT (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println("BranchElement (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else
       {
-        h2.check(docEvent.getChange(getDefaultRootElement()) == null);
-        super.insert(offset, length, data, de);
-        h2.check(docEvent.getChange(getDefaultRootElement()) != null);
+        try
+          {
+            System.out.println("LeafElement ("
+                               + start.getStartOffset()
+                               + ", "
+                               + start.getEndOffset()
+                               + "): "
+                               + start.getAttributes().getAttributeCount()
+                               + ": "
+                               + start.getDocument().
+                               getText(
+                                       start.getStartOffset(),
+                                       start.getEndOffset()
+                                       - start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
       }
+    for (int i = 0; i < start.getElementCount(); i++)
+      printElements(start.getElement(i), pad + 3);
+  }
+
+  // A class to be the buffer of the styled document.
+  // This allows us to check that some values are correct internally within
+  // the ElementBuffer.
+  public class ElementBuffer2 extends ElementBuffer
+  {
+    public ElementBuffer2(Element root)
+    {
+      super(root);
     }
-    
-    // Creates a new StyledDocument2 using an ElementBuffer2 as the buffer
-    public StyledDocument2()
+
+    // This method allows us to check that the ElementSpecs generated by 
+    // DefaultStyledDocument.insertUpdate are correct.
+    protected void insertUpdate(ElementSpec[] data)
     {
-      super();
-      buffer = new ElementBuffer2(createDefaultRoot());
+      numInserts++;
+      if (numInserts == 1)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: first insertion");
+          h2.check (data.length == 3);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 21);
+
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0);
+        }
+      else if (numInserts == 2)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: second insertion");
+          h2.check (data.length == 5);
+          h2.check(data[0].getType() == ElementSpec.EndTagType);
+          h2.check(data[0].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 0);
+          
+          h2.check(data[1].getType() == ElementSpec.StartTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);          
+          
+          h2.check(data[2].getType() == ElementSpec.ContentType);
+          h2.check(data[2].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 22);
+          
+          h2.check(data[3].getType() == ElementSpec.EndTagType);
+          h2.check(data[3].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 0);
+          
+          h2.check(data[4].getType() == ElementSpec.StartTagType);
+          h2.check(data[4].getDirection() == ElementSpec.JoinNextDirection);
+          h2.check(data[4].getOffset() == 0);
+          h2.check(data[4].getLength() == 0);          
+        }
+      else if (numInserts == 3)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: third insertion");
+          h2.check (data.length == 1);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 1);          
+        }
+      else
+        h2.fail("too many ElementSpecs created");
+      h2.check(docEvent.getChange(getDefaultRootElement()) == null);
+      super.insertUpdate(data);
+      h2.check(docEvent.getChange(getDefaultRootElement()) == null);
     }
     
-    // DefaultStyledDocument.insertUpdate
-    protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng,
-                                AttributeSet attr)
-    {      
-      docEvent = chng;
+    public void insert(int offset,
+                       int length,
+                       DefaultStyledDocument.ElementSpec[] data,
+                       AbstractDocument.DefaultDocumentEvent de)
+    {
       h2.check(docEvent.getChange(getDefaultRootElement()) == null);
-      super.insertUpdate (chng, attr);
+      super.insert(offset, length, data, de);
       h2.check(docEvent.getChange(getDefaultRootElement()) != null);
-    }    
-  }    
+    }
+  }
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure7.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure7.java,v
retrieving revision 1.3
diff -u -r1.3 ElementStructure7.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure7.java	12 Jan 2006 16:49:26 -0000	1.3
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure7.java	23 Jan 2006 18:26:25 -0000
@@ -21,20 +21,20 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.JTextPane;
-import javax.swing.text.*;
-import javax.swing.event.*;
-
-import java.util.Vector;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
-public class ElementStructure7 implements Testlet
-{
+import java.util.Vector;
 
-  static TestHarness h2;
+import javax.swing.event.DocumentEvent;
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
 
+public class ElementStructure7 extends DefaultStyledDocument implements Testlet
+{
   /**
    * Starts the test run.
    * 
@@ -43,82 +43,354 @@
    */
   public void test(TestHarness harness)
   {
+    ElementStructure7 doc = new ElementStructure7();
+    h2 = harness;
     try
       {
-        JTextPane tp = new JTextPane();
-        StyledDocument doc = new StyledDocument2();
-        tp.setStyledDocument(doc);
-
-        h2 = harness;
         doc.insertString(0, "aaaaaaaaa\nbbbbbbbbb", null);
         doc.insertString(5, "\nN", null);
       }
-    catch (BadLocationException ex)
+    catch (Exception ex)
       {
+        // ex.printStackTrace();
         h2.debug(ex);
       }
+    catch (AssertionError e)
+      {
+        // e.printStackTrace();
+        harness.debug(e);
+      }
+    // printElements(doc.getDefaultRootElement(), 0);
   }
+  
+  static TestHarness h2;
+  
+  static DefaultDocumentEvent2 docEvent = null;
 
-  static class StyledDocument2 extends DefaultStyledDocument
-  {
-    DefaultDocumentEvent2 docEvent = null;
+  static int numInserts = 0;
 
-    public StyledDocument2()
-    {
-      super();
-      buffer = new ElementBuffer2(createDefaultRoot());
-    }
+  static int numLeaves = 0;
 
-    public class ElementBuffer2 extends ElementBuffer
-    {
+  static int numBranches = 0;  
 
-      public ElementBuffer2(Element root)
+  // We override the constructor so we can explicitly set the type of the
+  // buffer to be our ElementBuffer2, allowing us to test some internals.
+  public ElementStructure7()
+  {
+    super();
+    buffer = new ElementBuffer2(createDefaultRoot());
+  }
+
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
       {
-        super(root);
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 19);
       }
-
-      public void insert(int offset, int length, ElementSpec[] data,
-                         DefaultDocumentEvent ev)
+    else if (numInserts == 1)
       {
-        docEvent = new DefaultDocumentEvent2(ev.getOffset(), ev.getLength(),
-                                             ev.getType());
-        super.insert(offset, length, data, docEvent);
-        Vector edits = docEvent.getEdits();
-        h2.check(data.length == 4);
-        h2.check(data[0].getType() == ElementSpec.ContentType);
-        h2.check(data[0].getDirection() == ElementSpec.JoinPreviousDirection);
-        h2.check(data[1].getType() == ElementSpec.EndTagType);
-        h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
-        h2.check(data[2].getType() == ElementSpec.StartTagType);
-        h2.check(data[2].getDirection() == ElementSpec.JoinFractureDirection);
-        h2.check(data[3].getType() == ElementSpec.ContentType);
-        h2.check(data[3].getDirection() == ElementSpec.JoinNextDirection);
-        h2.check(edits.size(), 3);
-        Object zero = edits.get(0);
-        h2.check(zero instanceof AbstractDocument.ElementEdit);
-        h2.check(((AbstractDocument.ElementEdit) zero).canUndo());
-        Object one = edits.get(1);
-        h2.check(one instanceof AbstractDocument.ElementEdit);
-        h2.check(((AbstractDocument.ElementEdit) one).canUndo());
-        Object two = edits.get(2);
-        h2.check(two instanceof AbstractDocument.ElementEdit);
-        h2.check(((AbstractDocument.ElementEdit) two).canUndo());
+        h2.checkPoint("second doc event");
+        h2.check(o == 5);
+        h2.check(l == 2);
       }
-    }
+    else
+      h2.fail ("too many calls to DefaultStyledDocument.insertUpdate");
 
-    public class DefaultDocumentEvent2 extends DefaultDocumentEvent
-    {
+    super.insertUpdate (ev, attr);
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, AttributeSet a, int p0,
+                                      int p1)
+  {
+    numLeaves++;
+    if (numLeaves == 1)
+      {
+        h2.checkPoint("create first leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 10);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 20);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("parent Element should have children, but has none.");
+            h2.fail("parent Element should have children, but has none.");
+          }        
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint("create second leaf element");
+        h2.check(p0 == 19);
+        h2.check(p1 == 20);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint("create third leaf element");
+        h2.check(p0 == 10);
+        h2.check(p1 == 20);
+        try
+        {
+          h2.check(parent.getStartOffset() == 19);
+          h2.check(parent.getEndOffset() == 20);
+        }
+      catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail("parent Element should have children, but has none.");
+          h2.fail("parent Element should have children, but has none.");
+        }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint("create fourth leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 6);
+        try
+        {
+          h2.check(parent.getStartOffset() == 0);
+          h2.check(parent.getEndOffset() == 12);
+        }
+      catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail("parent Element should have children, but has none.");
+          h2.fail("parent Element should have children, but has none.");
+        }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 5)
+      {
+        h2.checkPoint("create fifth leaf element");
+        h2.check(p0 == 7);
+        h2.check(p1 == 12);
+        h2.check (parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 6)
+      {
+        h2.checkPoint("create sixth leaf element");
+        h2.check(p0 == 6);
+        h2.check(p1 == 12);
+        try
+        {
+          h2.check(parent.getStartOffset() == 7);
+          h2.check(parent.getEndOffset() == 12);
+        }
+      catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail("parent Element should have children, but has none.");
+          h2.fail("parent Element should have children, but has none.");
+        }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
 
-      public DefaultDocumentEvent2(int offset, int length,
-                                   DocumentEvent.EventType type)
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent, AttributeSet a)
+  {    
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create first branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 20);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numBranches == 2)
       {
-        super(offset, length, type);
+        h2.checkPoint("create second branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 22);
+        h2.check(a.getAttributeCount() == 0);
       }
+    else
+      h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
 
-      public Vector getEdits()
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements(Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println("ROOT ELEMENT (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println("BranchElement (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else
       {
-        return edits;
+        try
+          {
+            System.out.println("LeafElement ("
+                               + start.getStartOffset()
+                               + ", "
+                               + start.getEndOffset()
+                               + "): "
+                               + start.getAttributes().getAttributeCount()
+                               + ": "
+                               + start.getDocument().
+                               getText(
+                                       start.getStartOffset(),
+                                       start.getEndOffset()
+                                       - start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
       }
+    for (int i = 0; i < start.getElementCount(); i++)
+      printElements(start.getElement(i), pad + 3);
+  }
+
+  // A class to be the buffer of the styled document.
+  // This allows us to check that some values are correct internally within
+  // the ElementBuffer.
+  public class ElementBuffer2 extends ElementBuffer
+  {
+    public ElementBuffer2(Element root)
+    {
+      super(root);
+    }
+
+    // This method allows us to check that the ElementSpecs generated by 
+    // DefaultStyledDocument.insertUpdate are correct.
+    protected void insertUpdate(ElementSpec[] data)
+    {
+      numInserts++;
+      if (numInserts == 1)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: first insertion");
+          h2.check (data.length == 4);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 10);
+
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0);
+          
+          h2.check(data[3].getType() == ElementSpec.ContentType);
+          h2.check(data[3].getDirection() == ElementSpec.JoinNextDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 9);
+        }
+      else if (numInserts == 2)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: second insertion");
+          h2.check (data.length == 4);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 1);
+          
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+          
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0);
+          
+          h2.check(data[3].getType() == ElementSpec.ContentType);
+          h2.check(data[3].getDirection() == ElementSpec.JoinNextDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 1);
+
+        }
+      else
+        h2.fail("too many ElementSpecs created");
+      h2.check(docEvent.getChange(getDefaultRootElement()) == null);
+      super.insertUpdate(data);
+      h2.check(docEvent.getChange(getDefaultRootElement()) == null);
+    }
+    
+    public void insert(int offset, int length, ElementSpec[] data,
+                       DefaultDocumentEvent ev)
+    {
+      docEvent = new DefaultDocumentEvent2(ev.getOffset(), ev.getLength(),
+                                           ev.getType());
+      super.insert(offset, length, data, docEvent);
+      Vector edits = docEvent.getEdits();
+      h2.check(data.length == 4);
+      h2.check(data[0].getType() == ElementSpec.ContentType);
+      h2.check(data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+      h2.check(data[1].getType() == ElementSpec.EndTagType);
+      h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+      h2.check(data[2].getType() == ElementSpec.StartTagType);
+      h2.check(data[2].getDirection() == ElementSpec.JoinFractureDirection);
+      h2.check(data[3].getType() == ElementSpec.ContentType);
+      h2.check(data[3].getDirection() == ElementSpec.JoinNextDirection);
+      h2.check(edits.size(), 3);
+      Object zero = edits.get(0);
+      h2.check(zero instanceof AbstractDocument.ElementEdit);
+      h2.check(((AbstractDocument.ElementEdit) zero).canUndo());
+      Object one = edits.get(1);
+      h2.check(one instanceof AbstractDocument.ElementEdit);
+      h2.check(((AbstractDocument.ElementEdit) one).canUndo());
+      Object two = edits.get(2);
+      h2.check(two instanceof AbstractDocument.ElementEdit);
+      h2.check(((AbstractDocument.ElementEdit) two).canUndo());
+    }
+  }
+  public class DefaultDocumentEvent2 extends DefaultDocumentEvent
+  {
+
+    public DefaultDocumentEvent2(int offset, int length,
+                                 DocumentEvent.EventType type)
+    {
+      super(offset, length, type);
+    }
+
+    public Vector getEdits()
+    {
+      return edits;
     }
   }
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java,v
retrieving revision 1.8
diff -u -r1.8 ElementStructure8.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java	18 Jan 2006 20:34:44 -0000	1.8
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java	23 Jan 2006 18:26:25 -0000
@@ -23,13 +23,16 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.text.DefaultStyledDocument;
-import javax.swing.text.Element;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
-public class ElementStructure8 implements Testlet
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+
+public class ElementStructure8 extends DefaultStyledDocument implements Testlet
 {
   /**
    * Starts the test run.
@@ -38,11 +41,12 @@
    */
   public void test(TestHarness harness)
   {
+    h2 = harness;
     try
       {
         /* TEST 0 *////////////////////////////////////////////////////////////
         harness.checkPoint("Test 0");
-        DefaultStyledDocument doc = new DefaultStyledDocument();
+        ElementStructure8 doc = new ElementStructure8();
         Element root = doc.getDefaultRootElement();
         doc.insertString(0, "first line of text. \n", null);
         harness.check(root.getElementCount() == 2);
@@ -50,7 +54,8 @@
         harness.check(root.getElement(0).getEndOffset() == 21);
         harness.check(root.getElement(1).getStartOffset() == 21);
         harness.check(root.getElement(1).getEndOffset() == 22);
-        doc.insertString(21, "second line of text. \n third line of text. \n", null);
+        doc.insertString
+          (21, "second line of text. \n third line of text. \n", null);
         harness.check(root.getElementCount() == 4);
         harness.check(root.getElement(0).getElementCount() == 1);
         harness.check(root.getElement(1).getElementCount() == 1);
@@ -72,9 +77,11 @@
         harness.check(fourth.getStartOffset() == 65);
         harness.check(fourth.getEndOffset() == 66);
         
+        //printElements(doc.getDefaultRootElement(), 0);
+        
         /* TEST 1 *////////////////////////////////////////////////////////////
         harness.checkPoint("Test 1");
-        doc = new DefaultStyledDocument();
+        doc = new ElementStructure8();
         root = doc.getDefaultRootElement();
         doc.insertString(0, "first line of text. \n", null);
         harness.check(root.getElementCount() == 2);
@@ -103,10 +110,12 @@
         fourth = root.getElement(2).getElement(1);
         harness.check(fourth.getStartOffset() == 44);
         harness.check(fourth.getEndOffset() == 45);
+        
+        //printElements(doc.getDefaultRootElement(), 0);
 
         /* TEST 2 *////////////////////////////////////////////////////////////
         harness.checkPoint("Test 2");
-        doc = new DefaultStyledDocument();
+        doc = new ElementStructure8();
         root = doc.getDefaultRootElement();
         doc.insertString(0, "first line of text.", null);
         harness.check(root.getElementCount() == 1);
@@ -125,9 +134,11 @@
         harness.check(second.getStartOffset() == 18);
         harness.check(second.getEndOffset() == 42);
         
+        //printElements(doc.getDefaultRootElement(), 0);
+        
         /* TEST 3 *////////////////////////////////////////////////////////////
         harness.checkPoint("Test 3");
-        doc = new DefaultStyledDocument();
+        doc = new ElementStructure8();
         root = doc.getDefaultRootElement();
         doc.insertString(0, "first line of text. \n", null);
         harness.check(root.getElementCount() == 2);
@@ -135,7 +146,8 @@
         harness.check(root.getElement(0).getEndOffset() == 21);
         harness.check(root.getElement(1).getStartOffset() == 21);
         harness.check(root.getElement(1).getEndOffset() == 22);
-        doc.insertString(21, "\n second line of text. \n third line of text. \n", null);
+        doc.insertString
+          (21, "\n second line of text. \n third line of text. \n", null);
         harness.check(root.getElementCount() == 5);
         harness.check(root.getElement(0).getElementCount() == 1);
         harness.check(root.getElement(1).getElementCount() == 1);
@@ -162,11 +174,14 @@
         harness.check(fifth.getStartOffset() == 67);
         harness.check(fifth.getEndOffset() == 68);
         
+        //printElements(doc.getDefaultRootElement(), 0);
+        
         /* TEST 4 *////////////////////////////////////////////////////////////
         harness.checkPoint("Test 4");
-        doc = new DefaultStyledDocument();
+        doc = new ElementStructure8();
         root = doc.getDefaultRootElement();
-        doc.insertString(0, "\n second line of text. \n third line of text. \n", null);
+        doc.insertString
+          (0, "\n second line of text. \n third line of text. \n", null);
         harness.check(root.getElementCount() == 4);
         harness.check(root.getElement(0).getElementCount() == 1);
         harness.check(root.getElement(1).getElementCount() == 1);
@@ -189,9 +204,11 @@
         harness.check(fourth.getStartOffset() == 46);
         harness.check(fourth.getEndOffset() == 47);
         
+        //printElements(doc.getDefaultRootElement(), 0);
+        
         /* TEST 5 *////////////////////////////////////////////////////////////
         harness.checkPoint("Test 5");
-        doc = new DefaultStyledDocument();
+        doc = new ElementStructure8();
         root = doc.getDefaultRootElement();
         doc.insertString(0, "first line of text.", null);
         harness.check(root.getElementCount() == 1);
@@ -214,10 +231,966 @@
         third = root.getElement(2).getElement(0);
         harness.check(third.getStartOffset() == 21);
         harness.check(third.getEndOffset() == 41);
+        
+        //printElements(doc.getDefaultRootElement(), 0);
+      }
+    catch (Exception t)
+      {
+        // t.printStackTrace();
+        harness.debug(t);
+      }
+    catch (AssertionError e)
+      {
+        e.printStackTrace();
+        harness.debug(e);
+      }
+  }
+  
+  static TestHarness h2;
+
+  static int numInserts = 0;
+
+  static int numLeaves = 0;
+
+  static int numBranches = 0;
+
+  // We override the constructor so we can explicitly set the type of the
+  // buffer to be our ElementBuffer2, allowing us to test some internals.
+  public ElementStructure8()
+  {
+    super();
+    buffer = new ElementBuffer2(createDefaultRoot());
+  }
+
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 21);
+      }
+    else if (numInserts == 1)
+    {
+      h2.checkPoint("second doc event");
+      h2.check(o == 21);      
+      h2.check(l == 44);
+    } 
+    else if (numInserts == 2)
+      {
+        h2.checkPoint("third doc event");
+        h2.check(o == 0);      
+        h2.check(l == 21);
+      } 
+    else if (numInserts == 3)
+      {
+        h2.checkPoint("fourth doc event");
+        h2.check(o == 21);      
+        h2.check(l == 23);
+      } 
+    else if (numInserts == 4)
+      {
+        h2.checkPoint("fifth doc event");
+        h2.check(o == 0);      
+        h2.check(l == 19);
+      } 
+    else if (numInserts == 5)
+      {
+        h2.checkPoint("sixth doc event");
+        h2.check(o == 5);      
+        h2.check(l == 22);
+      } 
+    else if (numInserts == 6)
+      {
+        h2.checkPoint("seventh doc event");
+        h2.check(o == 0);      
+        h2.check(l == 21);
+      } 
+    else if (numInserts == 7)
+      {
+        h2.checkPoint("eighth doc event");
+        h2.check(o == 21);      
+        h2.check(l == 46);
+      } 
+    else if (numInserts == 8)
+      {
+        h2.checkPoint("ninth doc event");
+        h2.check(o == 0);      
+        h2.check(l == 46);
+      } 
+    else if (numInserts == 9)
+      {
+        h2.checkPoint("tenth doc event");
+        h2.check(o == 0);      
+        h2.check(l == 19);
+      }
+    else if (numInserts == 10)
+      {
+        h2.checkPoint("eleventh doc event");
+        h2.check(o == 20);      
+        h2.check(l == 21);
+      } 
+
+    else
+      h2.fail ("too many calls to DefaultStyledDocument.insertUpdate");
+
+    super.insertUpdate(ev, attr);
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, AttributeSet a, int p0,
+                                      int p1)
+  {
+    numLeaves++;
+    if (numLeaves == 1)
+      {
+        h2.checkPoint("create first leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 22);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("parent Element should have children, but has none.");
+            h2.fail("parent Element should have children, but has none.");
+          }        
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint("create second leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 22);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint("create third leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 65);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint("create fourth leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 43);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 5)
+      {
+        h2.checkPoint("create fifth leaf element");
+        h2.check(p0 == 43);
+        h2.check(p1 == 65);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 6)
+      {
+        h2.checkPoint("create sixth leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 22);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 7)
+      {
+        h2.checkPoint("create seventh leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 22);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 8)
+      {
+        h2.checkPoint("create eighth leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 44);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 9)
+      {
+        h2.checkPoint("create ninth leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 43);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 10)
+      {
+        h2.checkPoint("create tenth leaf element");
+        h2.check(p0 == 43);
+        h2.check(p1 == 44);
+        try
+          {
+            h2.check(parent.getStartOffset() == 44);
+            h2.check(parent.getEndOffset() == 45);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 11)
+      {
+        h2.checkPoint("create eleventh leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 18);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 42);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 12)
+      {
+        h2.checkPoint("create twelfth leaf element");
+        h2.check(p0 == 27);
+        h2.check(p1 == 42);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 13)
+      {
+        h2.checkPoint("create thirteenth leaf element");
+        h2.check(p0 == 18);
+        h2.check(p1 == 42);
+        try
+          {
+            h2.check(parent.getStartOffset() == 27);
+            h2.check(parent.getEndOffset() == 42);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
       }
-    catch (Throwable t)
+    else if (numLeaves == 14)
       {
-        harness.fail(t.getCause() + " Exception caught!");
+        h2.checkPoint("create fourteenth leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 22);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
       }
+    else if (numLeaves == 15)
+      {
+        h2.checkPoint("create fifteenth leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 22);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 16)
+      {
+        h2.checkPoint("create sixteenth leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 21);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 67);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 17)
+      {
+        h2.checkPoint("create seventeeth leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 22);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 18)
+      {
+        h2.checkPoint("create eighteenth leaf element");
+        h2.check(p0 == 22);
+        h2.check(p1 == 45);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 19)
+      {
+        h2.checkPoint("create nineteenth leaf element");
+        h2.check(p0 == 45);
+        h2.check(p1 == 67);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 20)
+      {
+        h2.checkPoint("create twentieth leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 1);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 47);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 21)
+      {
+        h2.checkPoint("create twenty-first leaf element");
+        h2.check(p0 == 1);
+        h2.check(p1 == 24);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 22)
+      {
+        h2.checkPoint("create twenty-second leaf element");
+        h2.check(p0 == 24);
+        h2.check(p1 == 46);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 23)
+      {
+        h2.checkPoint("create twenty-third leaf element");
+        h2.check(p0 == 46);
+        h2.check(p1 == 47);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 24)
+      {
+        h2.checkPoint("create twenty-fourth leaf element");
+        h2.check(p0 == 0);
+        h2.check(p1 == 20);
+        try
+          {
+            h2.check(parent.getStartOffset() == 0);
+            h2.check(parent.getEndOffset() == 41);
+          }
+        catch (Exception e)
+          {
+            // I put 2 fails here so that the total number of tests will remain
+            // the same whether we pass or fail these tests.
+            h2.fail("branch element should have children, but has none");
+            h2.fail("branch element should have children, but has none");
+          }
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 25)
+      {
+        h2.checkPoint("create twenty-fifth leaf element");
+        h2.check(p0 == 20);
+        h2.check(p1 == 21);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 26)
+      {
+        h2.checkPoint("create twenty-sixth leaf element");
+        h2.check(p0 == 21);
+        h2.check(p1 == 41);
+        h2.check(parent.getElementCount() == 0);
+        h2.check(a.getAttributeCount() == 0);
+      }
+
+    else      
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent, AttributeSet a)
+  {    
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create first branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 22);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numBranches == 2)
+      {
+        h2.checkPoint("create second branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 66);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 3)
+      {
+        h2.checkPoint("create third branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 66);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 4)
+      {
+        h2.checkPoint("create fourth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 22);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 5)
+      {
+        h2.checkPoint("create fifth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 45);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 6)
+      {
+        h2.checkPoint("create sixth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 42);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 7)
+      {
+        h2.checkPoint("create seventh branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 22);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 8)
+      {
+        h2.checkPoint("create eighth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 68);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 9)
+      {
+        h2.checkPoint("create ninth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 68);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 10)
+      {
+        h2.checkPoint("create tenth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 68);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 11)
+      {
+        h2.checkPoint("create eleventh branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 47);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 12)
+      {
+        h2.checkPoint("create twelfth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 47);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 13)
+      {
+        h2.checkPoint("create thirteenth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 47);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 14)
+      {
+        h2.checkPoint("create fourteenth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 41);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else if (numBranches == 15)
+      {
+        h2.checkPoint("create fifteenth branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 41);
+        h2.check(a.getAttributeCount() == 0); 
+      }
+    else
+      h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements(Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println("ROOT ELEMENT (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println("BranchElement (" + start.getStartOffset() + ", "
+                         + start.getEndOffset() + ")");
+    else
+      {
+        try
+          {
+            System.out.println("LeafElement ("
+                               + start.getStartOffset()
+                               + ", "
+                               + start.getEndOffset()
+                               + "): "
+                               + start.getAttributes().getAttributeCount()
+                               + ": "
+                               + start.getDocument().
+                               getText(
+                                       start.getStartOffset(),
+                                       start.getEndOffset()
+                                       - start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i++)
+      printElements(start.getElement(i), pad + 3);
+  }
+
+  // A class to be the buffer of the styled document.
+  // This allows us to check that some values are correct internally within
+  // the ElementBuffer.
+  public class ElementBuffer2 extends ElementBuffer
+  {
+    public ElementBuffer2(Element root)
+    {
+      super(root);
+    }
+
+    // This method allows us to check that the ElementSpecs generated by 
+    // DefaultStyledDocument.insertUpdate are correct.
+    protected void insertUpdate(ElementSpec[] data)
+    {
+      numInserts++;
+      if (numInserts == 1)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: first insertion");
+          h2.check(data.length == 3);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 21);
+
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0);
+        }
+      else if (numInserts == 2)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: second insertion");
+          h2.check (data.length == 8);
+          h2.check(data[0].getType() == ElementSpec.EndTagType);
+          h2.check(data[0].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 0);
+          
+          h2.check(data[1].getType() == ElementSpec.StartTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);          
+          
+          h2.check(data[2].getType() == ElementSpec.ContentType);
+          h2.check(data[2].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 22);
+          
+          h2.check(data[3].getType() == ElementSpec.EndTagType);
+          h2.check(data[3].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 0);
+          
+          h2.check(data[4].getType() == ElementSpec.StartTagType);
+          h2.check(data[4].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[4].getOffset() == 0);
+          h2.check(data[4].getLength() == 0);
+          
+          h2.check(data[5].getType() == ElementSpec.ContentType);
+          h2.check(data[5].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[5].getOffset() == 0);
+          h2.check(data[5].getLength() == 22);          
+
+          h2.check(data[6].getType() == ElementSpec.EndTagType);
+          h2.check(data[6].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[6].getOffset() == 0);
+          h2.check(data[6].getLength() == 0);          
+
+          h2.check(data[7].getType() == ElementSpec.StartTagType);
+          h2.check(data[7].getDirection() == ElementSpec.JoinNextDirection);
+          h2.check(data[7].getOffset() == 0);
+          h2.check(data[7].getLength() == 0);          
+        }
+      else if (numInserts == 3)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: third insertion");
+          h2.check(data.length == 3);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 21);
+          
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+          
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0); 
+        }
+      else if (numInserts == 4)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: fourth insertion");
+          h2.check (data.length == 6);
+          h2.check(data[0].getType() == ElementSpec.EndTagType);
+          h2.check(data[0].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 0);
+          
+          h2.check(data[1].getType() == ElementSpec.StartTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);          
+          
+          h2.check(data[2].getType() == ElementSpec.ContentType);
+          h2.check(data[2].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 22);
+          
+          h2.check(data[3].getType() == ElementSpec.EndTagType);
+          h2.check(data[3].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 0);
+          
+          h2.check(data[4].getType() == ElementSpec.StartTagType);
+          h2.check(data[4].getDirection() == ElementSpec.JoinNextDirection);
+          h2.check(data[4].getOffset() == 0);
+          h2.check(data[4].getLength() == 0);
+          
+          h2.check(data[5].getType() == ElementSpec.ContentType);
+          h2.check(data[5].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[5].getOffset() == 0);
+          h2.check(data[5].getLength() == 1);          
+        }
+      else if (numInserts == 5)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: fifth insertion");
+          h2.check(data.length == 1);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 19);
+        }
+      else if (numInserts == 6)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: sixth insertion");
+          h2.check(data.length == 4);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 13);
+          
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+          
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0);
+          
+          h2.check(data[3].getType() == ElementSpec.ContentType);
+          h2.check(data[3].getDirection() == ElementSpec.JoinNextDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 9);          
+        }
+      else if (numInserts == 7)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: seventh insertion");
+          h2.check(data.length == 3);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 21);
+          
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+          
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0); 
+        }
+      else if (numInserts == 8)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: second insertion");
+          h2.check (data.length == 11);
+          h2.check(data[0].getType() == ElementSpec.EndTagType);
+          h2.check(data[0].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 0);
+          
+          h2.check(data[1].getType() == ElementSpec.StartTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);          
+          
+          h2.check(data[2].getType() == ElementSpec.ContentType);
+          h2.check(data[2].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 1);
+          
+          h2.check(data[3].getType() == ElementSpec.EndTagType);
+          h2.check(data[3].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 0);
+          
+          h2.check(data[4].getType() == ElementSpec.StartTagType);
+          h2.check(data[4].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[4].getOffset() == 0);
+          h2.check(data[4].getLength() == 0);
+          
+          h2.check(data[5].getType() == ElementSpec.ContentType);
+          h2.check(data[5].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[5].getOffset() == 0);
+          h2.check(data[5].getLength() == 23);          
+
+          h2.check(data[6].getType() == ElementSpec.EndTagType);
+          h2.check(data[6].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[6].getOffset() == 0);
+          h2.check(data[6].getLength() == 0);          
+
+          h2.check(data[7].getType() == ElementSpec.StartTagType);
+          h2.check(data[7].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[7].getOffset() == 0);
+          h2.check(data[7].getLength() == 0);
+          
+          h2.check(data[8].getType() == ElementSpec.ContentType);
+          h2.check(data[8].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[8].getOffset() == 0);
+          h2.check(data[8].getLength() == 22);
+          
+          h2.check(data[9].getType() == ElementSpec.EndTagType);
+          h2.check(data[9].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[9].getOffset() == 0);
+          h2.check(data[9].getLength() == 0);          
+
+          h2.check(data[10].getType() == ElementSpec.StartTagType);
+          h2.check(data[10].getDirection() == ElementSpec.JoinNextDirection);
+          h2.check(data[10].getOffset() == 0);
+          h2.check(data[10].getLength() == 0);          
+        }
+      else if (numInserts == 9)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: second insertion");
+          h2.check (data.length == 9);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 1);
+          
+          h2.check(data[1].getType() == ElementSpec.EndTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);
+          
+          h2.check(data[2].getType() == ElementSpec.StartTagType);
+          h2.check(data[2].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 0);          
+          
+          h2.check(data[3].getType() == ElementSpec.ContentType);
+          h2.check(data[3].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 23);
+          
+          h2.check(data[4].getType() == ElementSpec.EndTagType);
+          h2.check(data[4].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[4].getOffset() == 0);
+          h2.check(data[4].getLength() == 0);
+          
+          h2.check(data[5].getType() == ElementSpec.StartTagType);
+          h2.check(data[5].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[5].getOffset() == 0);
+          h2.check(data[5].getLength() == 0);
+          
+          h2.check(data[6].getType() == ElementSpec.ContentType);
+          h2.check(data[6].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[6].getOffset() == 0);
+          h2.check(data[6].getLength() == 22);          
+
+          h2.check(data[7].getType() == ElementSpec.EndTagType);
+          h2.check(data[7].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[7].getOffset() == 0);
+          h2.check(data[7].getLength() == 0);          
+
+          h2.check(data[8].getType() == ElementSpec.StartTagType);
+          h2.check
+            (data[8].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check(data[8].getOffset() == 0);
+          h2.check(data[8].getLength() == 0);          
+        }
+      else if (numInserts == 10)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: tenth insertion");
+          h2.check(data.length == 1);
+          h2.check(data[0].getType() == ElementSpec.ContentType);
+          h2.check
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 19);
+        }
+      else if (numInserts == 11)
+        {
+          h2.checkPoint("ElementBuffer insertUpdate: eleventh insertion");
+          h2.check (data.length == 6);
+          h2.check(data[0].getType() == ElementSpec.EndTagType);
+          h2.check(data[0].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[0].getOffset() == 0);
+          h2.check(data[0].getLength() == 0);
+          
+          h2.check(data[1].getType() == ElementSpec.StartTagType);
+          h2.check(data[1].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[1].getOffset() == 0);
+          h2.check(data[1].getLength() == 0);          
+          
+          h2.check(data[2].getType() == ElementSpec.ContentType);
+          h2.check(data[2].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[2].getOffset() == 0);
+          h2.check(data[2].getLength() == 1);
+          
+          h2.check(data[3].getType() == ElementSpec.EndTagType);
+          h2.check(data[3].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[3].getOffset() == 0);
+          h2.check(data[3].getLength() == 0);
+          
+          h2.check(data[4].getType() == ElementSpec.StartTagType);
+          h2.check(data[4].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[4].getOffset() == 0);
+          h2.check(data[4].getLength() == 0);
+          
+          h2.check(data[5].getType() == ElementSpec.ContentType);
+          h2.check(data[5].getDirection() == ElementSpec.OriginateDirection);
+          h2.check(data[5].getOffset() == 0);
+          h2.check(data[5].getLength() == 20);          
+        }
+
+      else
+        h2.fail("too many ElementSpecs created");
+      super.insertUpdate(data);
+    }
   }
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument1.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument1.java,v
retrieving revision 1.1
diff -u -r1.1 StyledDocument1.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument1.java	12 Jan 2006 15:57:46 -0000	1.1
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument1.java	23 Jan 2006 18:26:25 -0000
@@ -21,20 +21,48 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.text.*;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+
 public class StyledDocument1 extends DefaultStyledDocument implements Testlet
 {
+  public void test(TestHarness harness) 
+  {
+    h2 = harness;
+    StyledDocument1 doc = new StyledDocument1();
+    try
+      {
+        doc.insertString(0, "aaaaaaaaa\nbbbbbbbbb", null);
+        doc.insertString(10, "N", null);
+      }
+    catch (Exception ex)
+      {
+        // ex.printStackTrace();
+        harness.debug(ex);
+      }
+    catch (AssertionError e)
+      {
+        e.printStackTrace();
+        harness.debug(e);
+      }
+    // printElements(doc.getDefaultRootElement(), 0);
+  }
+  
   // A variable to keep track of the number of times text has been inserted
   static int numInserts = 0;
 
   static TestHarness h2;
+  
+  static int numLeaves = 0;
+  static int numBranches = 0;
 
+  
   // Creates a new StyledDocument1 using an ElementBuffer2 as the buffer
   public StyledDocument1()
   {
@@ -42,6 +70,184 @@
     buffer = new ElementBuffer2(createDefaultRoot());
   }
 
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 19);
+      }
+    else if (numInserts == 1)
+    {
+      h2.checkPoint("second doc event");
+      h2.check(o == 10);      
+      h2.check(l == 1);
+    } 
+    else
+      h2.fail ("too many calls to DefaultStyledDocument.insertUpdate");
+
+    super.insertUpdate(ev, attr);
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, 
+                                      AttributeSet a, int p0, int p1)
+  {
+    numLeaves++;
+    if (numLeaves== 1)
+      {
+        h2.checkPoint ("create first leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 10);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 20);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint ("create second leaf element");
+        h2.check (p0 == 19);
+        h2.check (p1 == 20);
+        h2.check (parent.getElementCount() == 0);
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint ("create third leaf element");
+        h2.check (p0 == 10);
+        h2.check (p1 == 20);
+        try
+        {
+          h2.check (parent.getStartOffset() == 19);
+          h2.check (parent.getEndOffset() == 20);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint ("create fourth leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 10);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 11);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 5)
+      {
+        h2.checkPoint ("create fifth leaf element");
+        h2.check (p0 == 10);
+        h2.check (p1 == 21);
+        try
+        {
+          h2.check (parent.getStartOffset() == 11);
+          h2.check (parent.getEndOffset() == 21);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+  
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent,
+                                        AttributeSet a)
+  {
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 20);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+  
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements (Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println ("ROOT ELEMENT ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println ("BranchElement ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else
+      {
+        try
+          {
+            System.out.println ("LeafElement ("+start.getStartOffset()+", "
+                                + start.getEndOffset()+"): "
+                                + start.getAttributes().getAttributeCount() 
+                                + ": "
+                                + start.getDocument().
+                                getText(start.getStartOffset(), 
+                                        start.getEndOffset() - 
+                                        start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i ++)
+      printElements (start.getElement(i), pad+3);
+  }
+  
   // A class to be the buffer of the styled document that also prints out some 
   // debugging info and checks that internal structure is correct
   public class ElementBuffer2 extends ElementBuffer
@@ -57,7 +263,8 @@
       if (numInserts == 1)
         {
           h2.check (data[0].getType() == ElementSpec.ContentType);
-          h2.check (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
           h2.check (data[0].getOffset() == 0);
           h2.check (data[0].getLength() == 10);
 
@@ -67,7 +274,8 @@
           h2.check (data[1].getLength() == 0);
 
           h2.check (data[2].getType() == ElementSpec.StartTagType);
-          h2.check (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check 
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
           h2.check (data[2].getOffset() == 0);
           h2.check (data[2].getLength() == 0);
 
@@ -93,22 +301,9 @@
           h2.check (data[2].getOffset() == 0);
           h2.check (data[2].getLength() == 1);
         }
+      else 
+        h2.fail("too many ElementSpecs created");
       super.insertUpdate(data);
     }
-  }
-  
-  public void test(TestHarness harness) 
-  {
-    h2 = harness;
-    StyledDocument doc = new StyledDocument1();
-    try
-      {
-        doc.insertString(0, "aaaaaaaaa\nbbbbbbbbb", null);
-        doc.insertString(10, "N", null);
-      }
-    catch (BadLocationException ex)
-      {
-        harness.debug(ex);
-      }        
-  }
+  }  
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument2.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument2.java,v
retrieving revision 1.1
diff -u -r1.1 StyledDocument2.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument2.java	12 Jan 2006 15:57:46 -0000	1.1
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument2.java	23 Jan 2006 18:26:25 -0000
@@ -21,19 +21,52 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.text.*;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+
 public class StyledDocument2 extends DefaultStyledDocument implements Testlet
 {
+  public void test(TestHarness harness) 
+  {
+    h2 = harness;
+    StyledDocument2 doc = new StyledDocument2();
+    SimpleAttributeSet atts = new SimpleAttributeSet();
+    try
+      {
+        atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        doc.insertString(0, "bbbbb", atts);
+        doc.insertString(5, "aaaaa", null);
+      }
+    catch (Exception ex)
+      {
+        // ex.printStackTrace();
+        harness.debug(ex);
+      }
+    catch (AssertionError e)
+      {
+        // e.printStackTrace();
+        harness.debug(e);
+      }
+    // printElements(doc.getDefaultRootElement(), 0);
+  }
+  
   // A variable to keep track of the number of times text has been inserted
   static int numInserts = 0;
 
   static TestHarness h2;
+  
+  
+  static int numLeaves = 0;
+  static int numBranches = 0;
+
 
   // Creates a new StyledDocument2 using an ElementBuffer2 as the buffer
   public StyledDocument2()
@@ -44,10 +77,169 @@
 
   protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
   {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 5);
+      }
+    else if (numInserts == 1)
+    {
+      h2.checkPoint("second doc event");
+      h2.check(o == 5);      
+      h2.check(l == 5);
+    } 
+    else
+      h2.fail ("too many calls to DefaultStyledDocument.insertUpdate");
+    
     super.insertUpdate(ev, attr);
-    h2.check (getDefaultRootElement().getElement(0).getElementCount() == (numInserts + 1));
+    h2.check 
+      (getDefaultRootElement().getElement(0).getElementCount() == 
+       (numInserts + 1));
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, 
+                                      AttributeSet a, int p0, int p1)
+  {
+    numLeaves++;
+    if (numLeaves== 1)
+      {
+        h2.checkPoint ("create first leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 5);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 6);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+        h2.check 
+          (a.getAttribute(StyleConstants.StrikeThrough) == Boolean.TRUE);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint ("create second leaf element");
+        h2.check (p0 == 5);
+        h2.check (p1 == 6);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 6);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint ("create third leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 5);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 11);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check 
+          (a.getAttribute(StyleConstants.StrikeThrough) == Boolean.TRUE);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint ("create fourth leaf element");
+        h2.check (p0 == 5);
+        h2.check (p1 == 10);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 11);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+  
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent,
+                                        AttributeSet a)
+  {
+    numBranches ++;
+    h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+  
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
   }
 
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements (Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println ("ROOT ELEMENT ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println ("BranchElement ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else
+      {
+        try
+          {
+            System.out.println ("LeafElement ("+start.getStartOffset()+", "
+                                + start.getEndOffset()+"): "
+                                + start.getAttributes().getAttributeCount()
+                                + ": "
+                                + start.getDocument().
+                                getText(start.getStartOffset(), 
+                                        start.getEndOffset() - 
+                                        start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i ++)
+      printElements (start.getElement(i), pad+3);
+  }
+
+  
   // A class to be the buffer of the styled document that also prints out some 
   // debugging info and checks that internal structure is correct
   public class ElementBuffer2 extends ElementBuffer
@@ -74,25 +266,10 @@
           h2.check (data[0].getOffset() == 0);
           h2.check (data[0].getLength() == 5);
         }
+      else 
+        h2.fail("too many ElementSpecs created");
 
       super.insertUpdate(data);
     }
-  }
-   
-  public void test(TestHarness harness) 
-  {
-    h2 = harness;
-    StyledDocument doc = new StyledDocument2();
-    SimpleAttributeSet atts = new SimpleAttributeSet();
-    try
-      {
-        atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
-        doc.insertString(0, "bbbbb", atts);
-        doc.insertString(5, "aaaaa", null);
-      }
-    catch (BadLocationException ex)
-      {
-        ex.printStackTrace();
-      }            
-  }
+  }   
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument3.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument3.java,v
retrieving revision 1.1
diff -u -r1.1 StyledDocument3.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument3.java	12 Jan 2006 15:57:46 -0000	1.1
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument3.java	23 Jan 2006 18:26:25 -0000
@@ -21,19 +21,54 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.text.*;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyledDocument;
+
 public class StyledDocument3 extends DefaultStyledDocument implements Testlet
 {
+  public void test(TestHarness harness) 
+  {
+    h2 = harness;
+    StyledDocument doc = new StyledDocument3();
+    SimpleAttributeSet atts = new SimpleAttributeSet();
+    try
+      {
+        atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        doc.insertString(0, "bbbbb", atts);
+        doc.insertString(5, "aaaaa", null);
+        doc.insertString(5, "N", atts);
+        atts.addAttribute(StyleConstants.Bold, Boolean.TRUE);
+        doc.insertString(6, "M", atts);
+      }
+    catch (Exception ex)
+      {
+        // ex.printStackTrace();
+        harness.debug(ex);
+      }
+    catch (AssertionError e)
+      {
+        // e.printStackTrace();
+        harness.debug(e);
+      }
+    // printElements(doc.getDefaultRootElement(), 0);
+  }
+  
   // A variable to keep track of the number of times text has been inserted
   static int numInserts = 0;
 
   static TestHarness h2;
+  
+  static int numLeaves = 0;
+  static int numBranches = 0;
 
   // Creates a new StyledDocument3 using an ElementBuffer2 as the buffer
   public StyledDocument3()
@@ -42,6 +77,226 @@
     buffer = new ElementBuffer2(createDefaultRoot());
   }
 
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 5);
+      }
+    else if (numInserts == 1)
+      {
+        h2.checkPoint("second doc event");
+        h2.check(o == 5);
+        h2.check(l == 5);
+      }
+    else if (numInserts == 2)
+      {
+        h2.checkPoint("third doc event");
+        h2.check(o == 5);
+        h2.check(l == 1);
+      }
+    else if (numInserts == 3)
+      {
+        h2.checkPoint("fourth doc event");
+        h2.check(o == 6);      
+        h2.check(l == 1);
+      } 
+    else
+      h2.fail("too many calls to DefaultStyledDocument.insertUpdate");
+
+    super.insertUpdate(ev, attr);
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, 
+                                      AttributeSet a, int p0, int p1)
+  {
+    numLeaves++;
+    if (numLeaves== 1)
+      {
+        h2.checkPoint ("create first leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 5);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 6);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+        h2.check (a.getAttributeCount() == 1);
+        h2.check 
+          (a.getAttribute(StyleConstants.StrikeThrough) == Boolean.TRUE);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint ("create second leaf element");
+        h2.check (p0 == 5);
+        h2.check (p1 == 6);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 6);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint ("create third leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 5);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 11);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 1);
+        h2.check 
+          (a.getAttribute(StyleConstants.StrikeThrough) == Boolean.TRUE);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint ("create fourth leaf element");
+        h2.check (p0 == 5);
+        h2.check (p1 == 10);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 11);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 5)
+      {
+        h2.checkPoint ("create fifth leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 6);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 13);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 1);
+        h2.check 
+          (a.getAttribute(StyleConstants.StrikeThrough) == Boolean.TRUE);
+      }
+    else if (numLeaves == 6)
+      {
+        h2.checkPoint ("create sixth leaf element");
+        h2.check (p0 == 6);
+        h2.check (p1 == 7);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 13);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 2);
+        h2.check 
+          (a.getAttribute(StyleConstants.StrikeThrough) == Boolean.TRUE);
+        h2.check (a.getAttribute(StyleConstants.Bold) == Boolean.TRUE);
+      }
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+  
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent,
+                                        AttributeSet a)
+  {
+    numBranches ++;
+    h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+  
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements (Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println ("ROOT ELEMENT ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println ("BranchElement ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else
+      {
+        try
+          {
+            System.out.println ("LeafElement ("+start.getStartOffset()+", "
+                                + start.getEndOffset()+"): "
+                                + start.getAttributes().getAttributeCount() 
+                                + ": "
+                                + start.getDocument().
+                                getText(start.getStartOffset(), 
+                                        start.getEndOffset() - 
+                                        start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i ++)
+      printElements (start.getElement(i), pad+3);
+  }
+  
   // A class to be the buffer of the styled document that also prints out some 
   // debugging info and checks that internal structure is correct
   public class ElementBuffer2 extends ElementBuffer
@@ -71,7 +326,8 @@
       else if (numInserts == 3)
         {
           h2.check (data[0].getType() == ElementSpec.ContentType);
-          h2.check (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
           h2.check (data[0].getOffset() == 0);
           h2.check (data[0].getLength() == 1);
         }
@@ -87,24 +343,5 @@
     }
   }
     
-  public void test(TestHarness harness) 
-  {
-    h2 = harness;
-    StyledDocument doc = new StyledDocument3();
-    SimpleAttributeSet atts = new SimpleAttributeSet();
-    try
-      {
-        atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
-        doc.insertString(0, "bbbbb", atts);
-        doc.insertString(5, "aaaaa", null);
-        doc.insertString(5, "N", atts);
-        atts.addAttribute(StyleConstants.Bold, Boolean.TRUE);
-        doc.insertString(6, "M", atts);
-      }
-    catch (BadLocationException ex)
-      {
-        ex.printStackTrace();
-      }        
 
-  }
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument4.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument4.java,v
retrieving revision 1.1
diff -u -r1.1 StyledDocument4.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument4.java	12 Jan 2006 15:57:46 -0000	1.1
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument4.java	23 Jan 2006 18:26:25 -0000
@@ -21,26 +21,249 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.text.*;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.StyledDocument;
+
 public class StyledDocument4 extends DefaultStyledDocument implements Testlet
 {
+  public void test(TestHarness harness) 
+  {
+    h2 = harness;
+    StyledDocument doc = new StyledDocument4();
+    try
+      {
+        doc.insertString(0, "aaaaaaaaa\nbbbbbbbbb", null);
+        doc.insertString(5, "\nN", null);
+      }
+    catch (Exception ex)
+      {
+        // ex.printStackTrace();
+        harness.debug(ex);
+      }
+    catch (AssertionError e)
+      {
+        // e.printStackTrace();
+        harness.debug(e);
+      }
+    
+    // printElements(doc.getDefaultRootElement(), 0);
+  }
+  
   // A variable to keep track of the number of times text has been inserted
   static int numInserts = 0;
 
   static TestHarness h2;
-
+  
+  static int numLeaves = 0;
+  static int numBranches = 0;
+  
   // Creates a new StyledDocument4 using an ElementBuffer2 as the buffer
   public StyledDocument4()
   {
     super();
     buffer = new ElementBuffer2(createDefaultRoot());
   }
+  
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 19);
+      }
+    else if (numInserts == 1)
+      {
+        h2.checkPoint("second doc event");
+        h2.check(o == 5);
+        h2.check(l == 2);
+      }
+    else
+      h2.fail("too many calls to DefaultStyledDocument.insertUpdate");
+
+    super.insertUpdate(ev, attr);
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, 
+                                      AttributeSet a, int p0, int p1)
+  {
+    numLeaves++;
+    if (numLeaves== 1)
+      {
+        h2.checkPoint ("create first leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 10);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 20);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint ("create second leaf element");
+        h2.check (p0 == 19);
+        h2.check (p1 == 20);
+        h2.check(parent.getElementCount() == 0);
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint ("create third leaf element");
+        h2.check (p0 == 10);
+        h2.check (p1 == 20);
+        try
+        {
+          h2.check (parent.getStartOffset() == 19);
+          h2.check (parent.getEndOffset() == 20);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint ("create fourth leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 6);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 12);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 5)
+      {
+        h2.checkPoint ("create fifth leaf element");
+        h2.check (p0 == 7);
+        h2.check (p1 == 12);
+        h2.check (parent.getElementCount() == 0);
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 6)
+      {
+        h2.checkPoint ("create sixth leaf element");
+        h2.check (p0 == 6);
+        h2.check (p1 == 12);
+        try
+        {
+          h2.check (parent.getStartOffset() == 7);
+          h2.check (parent.getEndOffset() == 12);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+  
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent,
+                                        AttributeSet a)
+  {
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create first branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 20);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numBranches == 2)
+      {
+        h2.checkPoint("create second branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 22);
+        h2.check(a.getAttributeCount() == 0);
+      }
+
+    else
+      h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+  
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements (Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println ("ROOT ELEMENT ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println ("BranchElement ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else
+      {
+        try
+          {
+            System.out.println ("LeafElement ("+start.getStartOffset()+", "
+                                + start.getEndOffset()+"): "
+                                + start.getAttributes().getAttributeCount() 
+                                + ": "
+                                + start.getDocument().
+                                getText(start.getStartOffset(), 
+                                        start.getEndOffset() - 
+                                        start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i ++)
+      printElements (start.getElement(i), pad+3);
+  }
+
 
   // A class to be the buffer of the styled document that also prints out some 
   // debugging info and checks that internal structure is correct
@@ -57,7 +280,8 @@
       if (numInserts == 1)
         {
           h2.check (data[0].getType() == ElementSpec.ContentType);
-          h2.check (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
           h2.check (data[0].getOffset() == 0);
           h2.check (data[0].getLength() == 10);
 
@@ -67,7 +291,8 @@
           h2.check (data[1].getLength() == 0);
 
           h2.check (data[2].getType() == ElementSpec.StartTagType);
-          h2.check (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check 
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
           h2.check (data[2].getOffset() == 0);
           h2.check (data[2].getLength() == 0);
 
@@ -79,7 +304,8 @@
       else if (numInserts == 2)
         {
           h2.check (data[0].getType() == ElementSpec.ContentType);
-          h2.check (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
           h2.check (data[0].getOffset() == 0);
           h2.check (data[0].getLength() == 1);
           
@@ -89,7 +315,8 @@
           h2.check (data[1].getLength() == 0);
 
           h2.check (data[2].getType() == ElementSpec.StartTagType);
-          h2.check (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check 
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
           h2.check (data[2].getOffset() == 0);
           h2.check (data[2].getLength() == 0);
 
@@ -102,18 +329,5 @@
     }
   }
   
-  public void test(TestHarness harness) 
-  {
-    h2 = harness;
-    StyledDocument doc = new StyledDocument4();
-    try
-      {
-        doc.insertString(0, "aaaaaaaaa\nbbbbbbbbb", null);
-        doc.insertString(5, "\nN", null);
-      }
-    catch (BadLocationException ex)
-      {
-        ex.printStackTrace();
-      }     
-  }
+
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument5.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument5.java,v
retrieving revision 1.1
diff -u -r1.1 StyledDocument5.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument5.java	12 Jan 2006 15:57:46 -0000	1.1
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument5.java	23 Jan 2006 18:26:25 -0000
@@ -21,20 +21,49 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.text.*;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.StyledDocument;
+
 public class StyledDocument5 extends DefaultStyledDocument implements Testlet
 {
+  public void test(TestHarness harness) 
+  {
+    h2 = harness;
+    StyledDocument doc = new StyledDocument5();
+    try
+      {
+        doc.insertString(0, "aaaaaaaaa\nbbbbbbbbb", null);
+        doc.insertString(10, "N", null);        
+        doc.insertString(5, "\nhellooooo", null);
+      }
+    catch (Exception ex)
+      {
+        //ex.printStackTrace();
+        harness.debug(ex);
+      }
+    catch (AssertionError e)
+      {
+        // e.printStackTrace();
+        harness.debug(e);
+      }
+    // printElements(doc.getDefaultRootElement(), 0);
+  }
+
   // A variable to keep track of the number of times text has been inserted
   static int numInserts = 0;
   
   static TestHarness h2;
 
+  static int numLeaves = 0;
+  static int numBranches = 0;
+
   // Creates a new StyledDocument5 using an ElementBuffer2 as the buffer
   public StyledDocument5()
   {
@@ -42,6 +71,244 @@
     buffer = new ElementBuffer2(createDefaultRoot());
   }
 
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 19);
+      }
+    else if (numInserts == 1)
+      {
+        h2.checkPoint("second doc event");
+        h2.check(o == 10);
+        h2.check(l == 1);
+      }
+    else if (numInserts == 2)
+      {
+        h2.checkPoint("third doc event");
+        h2.check(o == 5);
+        h2.check(l == 10);
+      }
+    else
+      h2.fail("too many calls to DefaultStyledDocument.insertUpdate");
+
+    super.insertUpdate(ev, attr);
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, 
+                                      AttributeSet a, int p0, int p1)
+  {
+    numLeaves++;
+    if (numLeaves== 1)
+      {
+        h2.checkPoint ("create first leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 10);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 20);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint ("create second leaf element");
+        h2.check (p0 == 19);
+        h2.check (p1 == 20);
+        h2.check(parent.getElementCount() == 0);
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint ("create third leaf element");
+        h2.check (p0 == 10);
+        h2.check (p1 == 20);
+        try
+        {
+          h2.check (parent.getStartOffset() == 19);
+          h2.check (parent.getEndOffset() == 20);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint ("create fourth leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 10);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 11);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 5)
+      {
+        h2.checkPoint ("create fifth leaf element");
+        h2.check (p0 == 10);
+        h2.check (p1 == 21);
+        try
+        {
+          h2.check (parent.getStartOffset() == 11);
+          h2.check (parent.getEndOffset() == 21);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 6)
+      {
+        h2.checkPoint ("create sixth leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 6);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 20);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 7)
+      {
+        h2.checkPoint ("create seventh leaf element");
+        h2.check (p0 == 15);
+        h2.check (p1 == 20);
+        h2.check(parent.getElementCount() == 0);
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 8)
+      {
+        h2.checkPoint ("create eigth leaf element");
+        h2.check (p0 == 6);
+        h2.check (p1 == 20);
+        try
+        {
+          h2.check (parent.getStartOffset() == 15);
+          h2.check (parent.getEndOffset() == 20);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+  
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent,
+                                        AttributeSet a)
+  {
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create first branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 20);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numBranches == 2)
+      {
+        h2.checkPoint("create second branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 31);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+  
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements (Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println ("ROOT ELEMENT ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println ("BranchElement ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else
+      {
+        try
+          {
+            System.out.println ("LeafElement ("+start.getStartOffset()+", "
+                                + start.getEndOffset()+"): "
+                                + start.getAttributes().getAttributeCount() 
+                                + ": "
+                                + start.getDocument().
+                                getText(start.getStartOffset(), 
+                                        start.getEndOffset() - 
+                                        start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i ++)
+      printElements (start.getElement(i), pad+3);
+  }
+  
   // A class to be the buffer of the styled document that also prints out some 
   // debugging info and checks that internal structure is correct
   public class ElementBuffer2 extends ElementBuffer
@@ -57,7 +324,8 @@
       if (numInserts == 1)
         {
           h2.check (data[0].getType() == ElementSpec.ContentType);
-          h2.check (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
           h2.check (data[0].getOffset() == 0);
           h2.check (data[0].getLength() == 10);
           
@@ -67,7 +335,8 @@
           h2.check (data[1].getLength() == 0);
 
           h2.check (data[2].getType() == ElementSpec.StartTagType);
-          h2.check (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check 
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
           h2.check (data[2].getOffset() == 0);
           h2.check (data[2].getLength() == 0);
 
@@ -96,7 +365,8 @@
       else if (numInserts == 3)
         {
           h2.check (data[0].getType() == ElementSpec.ContentType);
-          h2.check (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
           h2.check (data[0].getOffset() == 0);
           h2.check (data[0].getLength() == 1);
           
@@ -106,7 +376,8 @@
           h2.check (data[1].getLength() == 0);
 
           h2.check (data[2].getType() == ElementSpec.StartTagType);
-          h2.check (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check 
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
           h2.check (data[2].getOffset() == 0);
           h2.check (data[2].getLength() == 0);
 
@@ -118,21 +389,5 @@
 
       super.insertUpdate(data);
     }
-  }
-     
-  public void test(TestHarness harness) 
-  {
-    h2 = harness;
-    StyledDocument doc = new StyledDocument5();
-    try
-      {
-        doc.insertString(0, "aaaaaaaaa\nbbbbbbbbb", null);
-        doc.insertString(10, "N", null);        
-        doc.insertString(5, "\nhellooooo", null);
-      }
-    catch (BadLocationException ex)
-      {
-        harness.debug(ex);
-      }        
-  }
+  }     
 }
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument6.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument6.java,v
retrieving revision 1.1
diff -u -r1.1 StyledDocument6.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument6.java	12 Jan 2006 15:57:46 -0000	1.1
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument6.java	23 Jan 2006 18:26:25 -0000
@@ -21,20 +21,59 @@
 
 package gnu.testlet.javax.swing.text.DefaultStyledDocument.ElementBuffer;
 
-import javax.swing.*;
-import javax.swing.event.*;
-import javax.swing.text.*;
-
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.StyledDocument;
+
 public class StyledDocument6 extends DefaultStyledDocument implements Testlet
 {
+  public void test(TestHarness harness) 
+  {
+    h2 = harness;
+    StyledDocument doc = new StyledDocument6();
+    SimpleAttributeSet atts = new SimpleAttributeSet();
+    try
+      {
+        doc.insertString(0, "aaa", null);
+        atts.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        doc.insertString(3, "bbb", atts);
+        atts.removeAttributes(atts);
+        atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        doc.insertString(6, "ccc", atts);
+        atts.removeAttributes(atts);
+        atts.addAttribute(StyleConstants.Underline, Boolean.TRUE);
+        doc.insertString(5, "\nB", atts);
+      }
+    catch (Exception ex)
+      {
+        // ex.printStackTrace();
+        harness.debug(ex);
+      }
+    catch (AssertionError e)
+      {
+        // e.printStackTrace();
+        harness.debug(e);
+      }
+    // printElements(doc.getDefaultRootElement(), 0);
+  }
+
   // A variable to keep track of the number of times text has been inserted
   static int numInserts = 0;
 
   static TestHarness h2;
 
+  static int numLeaves = 0;
+  static int numBranches = 0;
+
+  
   // Creates a new StyledDocument6 using an ElementBuffer2 as the buffer
   public StyledDocument6()
   {
@@ -42,6 +81,286 @@
     buffer = new ElementBuffer2(createDefaultRoot());
   }
 
+  // Overriding this method allows us to check that the right number
+  // of newLines was encountered and that the event has the proper
+  // offset and length.
+  protected void insertUpdate(DefaultDocumentEvent ev, AttributeSet attr)
+  {
+    int l = ev.getLength();
+    int o = ev.getOffset();
+    if (numInserts == 0)
+      {
+        h2.checkPoint("first doc event");
+        h2.check(o == 0);
+        h2.check(l == 3);
+      }
+    else if (numInserts == 1)
+      {
+        h2.checkPoint("second doc event");
+        h2.check(o == 3);
+        h2.check(l == 3);
+      }
+    else if (numInserts == 2)
+      {
+        h2.checkPoint("third doc event");
+        h2.check(o == 6);
+        h2.check(l == 3);
+      }
+    else if (numInserts == 3)
+      {
+        h2.checkPoint("fourth doc event");
+        h2.check(o == 5);
+        h2.check(l == 2);
+      }
+    else
+      h2.fail("too many calls to DefaultStyledDocument.insertUpdate");
+
+    super.insertUpdate(ev, attr);
+  }
+
+  // Overriding this method allows us to check that the proper LeafElements
+  // are being created.
+  protected Element createLeafElement(Element parent, 
+                                      AttributeSet a, int p0, int p1)
+  {
+    numLeaves++;
+    if (numLeaves== 1)
+      {
+        h2.checkPoint ("create first leaf element");
+        h2.check (p0 == 0);
+        h2.check (p1 == 3);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 7);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 2)
+      {
+        h2.checkPoint ("create second leaf element");
+        h2.check (p0 == 3);
+        h2.check (p1 == 6);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 7);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("parent Element should have children, but has none.");
+          h2.fail ("parent Element should have children, but has none.");
+        }
+        h2.check (a.getAttributeCount() == 1);
+        h2.check (a.getAttribute(StyleConstants.Underline) == Boolean.TRUE);
+      }
+    else if (numLeaves == 3)
+      {
+        h2.checkPoint ("create third leaf element");
+        h2.check (p0 == 6);
+        h2.check (p1 == 7);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 7);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 4)
+      {
+        h2.checkPoint ("create fourth leaf element");
+        h2.check (p0 == 3);
+        h2.check (p1 == 6);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 10);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 1);
+        h2.check (a.getAttribute(StyleConstants.Underline) == Boolean.TRUE);
+        
+      }
+    else if (numLeaves == 5)
+      {
+        h2.checkPoint ("create fifth leaf element");
+        h2.check (p0 == 6);
+        h2.check (p1 == 9);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 10);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 1);
+        h2.check 
+          (a.getAttribute(StyleConstants.StrikeThrough) == Boolean.TRUE);
+      }
+    else if (numLeaves == 6)
+      {
+        h2.checkPoint ("create sixth leaf element");
+        h2.check (p0 == 3);
+        h2.check (p1 == 6);
+        try
+        {
+          h2.check (parent.getStartOffset() == 0);
+          h2.check (parent.getEndOffset() == 12);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 1);
+        h2.check (a.getAttribute(StyleConstants.Underline) == Boolean.TRUE);
+      }
+    else if (numLeaves == 7)
+      {
+        h2.checkPoint ("create seventh leaf element");
+        h2.check (p0 == 7);
+        h2.check (p1 == 8);
+        h2.check(parent.getElementCount() == 0);
+        h2.check (a.getAttributeCount() == 1);
+        h2.check (a.getAttribute(StyleConstants.Underline) == Boolean.TRUE);
+      }
+    else if (numLeaves == 8)
+      {
+        h2.checkPoint ("create eighth leaf element");
+        h2.check (p0 == 8);
+        h2.check (p1 == 11);
+        h2.check (parent.getElementCount() == 0);
+        h2.check (a.getAttributeCount() == 1);
+        h2.check 
+          (a.getAttribute(StyleConstants.StrikeThrough) == Boolean.TRUE);
+      }
+    else if (numLeaves == 9)
+      {
+        h2.checkPoint ("create ninth leaf element");
+        h2.check (p0 == 11);
+        h2.check (p1 == 12);
+        h2.check (parent.getElementCount() == 0);
+        h2.check (a.getAttributeCount() == 0);
+      }
+    else if (numLeaves == 10)
+      {
+        h2.checkPoint ("create tenth leaf element");
+        h2.check (p0 == 6);
+        h2.check (p1 == 8);
+        try
+        {
+          h2.check (parent.getStartOffset() == 7);
+          h2.check (parent.getEndOffset() == 12);
+        }
+        catch (Exception e)
+        {
+          // I put 2 fails here so that the total number of tests will remain
+          // the same whether we pass or fail these tests.
+          h2.fail ("branch element should have children, but has none");
+          h2.fail ("branch element should have children, but has none");
+        }
+        h2.check (a.getAttributeCount() == 1);
+        h2.check (a.getAttribute(StyleConstants.Underline) == Boolean.TRUE);
+      }
+    else
+      h2.fail ("too many leaf elements created");
+    return super.createLeafElement(parent, a, p0, p1);
+  }
+  
+  // Overriding this method allows us to check that the proper BranchElements
+  // are being created.
+  protected Element createBranchElement(Element parent,
+                                        AttributeSet a)
+  {
+    numBranches ++;
+    if (numBranches == 1)
+      {
+        h2.checkPoint("create first branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 12);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else if (numBranches == 2)
+      {
+        h2.checkPoint("create second branch element");
+        h2.check(parent.getStartOffset() == 0);
+        h2.check(parent.getEndOffset() == 31);
+        h2.check(a.getAttributeCount() == 0);
+      }
+    else
+      h2.fail ("too many branch elements created");
+    return super.createBranchElement(parent, a);
+  }
+  
+  // Prints some spaces.
+  public static void pad(int pad)
+  {
+    for (int i = 0; i < pad; i++)
+      System.out.print(" ");
+  }
+
+  // Displays the Element hierarchy starting with <code>start</code>.
+  // This is just debugging code.
+  public static void printElements (Element start, int pad)
+  {
+    pad(pad);
+    if (pad == 0)
+      System.out.println ("ROOT ELEMENT ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else if (start instanceof AbstractDocument.BranchElement)
+      System.out.println ("BranchElement ("+start.getStartOffset()+", "
+                          + start.getEndOffset()+")");
+    else
+      {
+        try
+          {
+            System.out.println ("LeafElement ("+start.getStartOffset()+", "
+                                + start.getEndOffset()+"): "
+                                + start.getAttributes().getAttributeCount() 
+                                + ": "
+                                + start.getDocument().
+                                getText(start.getStartOffset(), 
+                                        start.getEndOffset() - 
+                                        start.getStartOffset()));
+          }
+        catch (BadLocationException ble)
+          {
+          }
+      }
+    for (int i = 0; i < start.getElementCount(); i ++)
+      printElements (start.getElement(i), pad+3);
+  }
+
+  
   // A class to be the buffer of the styled document that also prints out some 
   // debugging info and checks that internal structure is correct
   public class ElementBuffer2 extends ElementBuffer
@@ -57,7 +376,8 @@
       if (numInserts == 1)
         {
           h2.check (data[0].getType() == ElementSpec.ContentType);
-          h2.check (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
           h2.check (data[0].getOffset() == 0);
           h2.check (data[0].getLength() == 3);
         }
@@ -78,7 +398,8 @@
       else if (numInserts == 4)
         {
           h2.check (data[0].getType() == ElementSpec.ContentType);
-          h2.check (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
+          h2.check 
+            (data[0].getDirection() == ElementSpec.JoinPreviousDirection);
           h2.check (data[0].getOffset() == 0);
           h2.check (data[0].getLength() == 1);
 
@@ -88,7 +409,8 @@
           h2.check (data[1].getLength() == 0);
 
           h2.check (data[2].getType() == ElementSpec.StartTagType);
-          h2.check (data[2].getDirection() == ElementSpec.JoinFractureDirection);
+          h2.check 
+            (data[2].getDirection() == ElementSpec.JoinFractureDirection);
           h2.check (data[2].getOffset() == 0);
           h2.check (data[2].getLength() == 0);
 
@@ -99,28 +421,5 @@
         }
       super.insertUpdate(data);
     }
-  }
-     
-  public void test(TestHarness harness) 
-  {
-    h2 = harness;
-    StyledDocument doc = new StyledDocument6();
-    SimpleAttributeSet atts = new SimpleAttributeSet();
-    try
-      {
-        doc.insertString(0, "aaa", null);
-        atts.addAttribute(StyleConstants.Underline, Boolean.TRUE);
-        doc.insertString(3, "bbb", atts);
-        atts.removeAttributes(atts);
-        atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
-        doc.insertString(6, "ccc", atts);
-        atts.removeAttributes(atts);
-        atts.addAttribute(StyleConstants.Underline, Boolean.TRUE);
-        doc.insertString(5, "\nB", atts);
-      }
-    catch (BadLocationException ex)
-      {
-        ex.printStackTrace();
-      }        
-  }
+  }     
 }

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