public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: More DefaultStyledDocument tests
@ 2005-12-21 18:33 Anthony Balkissoon
  0 siblings, 0 replies; 4+ messages in thread
From: Anthony Balkissoon @ 2005-12-21 18:33 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 226 bytes --]

More new tests for DefaultStyledDocument.  More to follow.

2005-12-20  Anthony Balkissoon  <abalkiss@redhat.com>

	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure2.java: New test.	

--Tony

[-- Attachment #2: ElementStructure2.java --]
[-- Type: text/x-java, Size: 2462 bytes --]

// 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);
      }        

  }
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* FYI: More DefaultStyledDocument tests
@ 2006-01-16 19:59 Lillian Angel
  0 siblings, 0 replies; 4+ messages in thread
From: Lillian Angel @ 2006-01-16 19:59 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 331 bytes --]

Added more tests to check different structures when newlines are
inserted in various places. This currently causes regressions.

2006-01-16  Lillian Angel  <langel@redhat.com>

        *
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java:
        Added more complicated tests and checkpoints.


[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 3936 bytes --]

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.5
diff -u -r1.5 ElementStructure8.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java	16 Jan 2006 18:51:12 -0000	1.5
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java	16 Jan 2006 19:56:17 -0000
@@ -40,6 +40,7 @@
   {
     try
       {
+        harness.checkPoint("Test 0");
         DefaultStyledDocument doc = new DefaultStyledDocument();
         Element root = doc.getDefaultRootElement();
         doc.insertString(0, "first line of text. \n", null);
@@ -71,6 +72,60 @@
         harness.check(fourth.getEndOffset() == 66);
         
         
+        harness.checkPoint("Test 1");
+        doc = new DefaultStyledDocument();
+        root = doc.getDefaultRootElement();
+        doc.insertString(0, "first line of text. \n", null);
+        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);
+        doc.insertString(21, "second line of text. \n ", null);
+        harness.check(root.getElementCount() == 3);
+        harness.check(root.getElement(0).getElementCount() == 1);
+        harness.check(root.getElement(1).getElementCount() == 1);
+        harness.check(root.getElement(2).getElementCount() == 2);
+
+        first = root.getElement(0).getElement(0);
+        harness.check(first.getStartOffset() == 0);
+        harness.check(first.getEndOffset() == 21);
+
+        second = root.getElement(1).getElement(0);
+        harness.check(second.getStartOffset() == 21);
+        harness.check(second.getEndOffset() == 43);
+
+        third = root.getElement(2).getElement(0);
+        harness.check(third.getStartOffset() == 43);
+        harness.check(third.getEndOffset() == 44);
+        
+        fourth = root.getElement(2).getElement(1);
+        harness.check(fourth.getStartOffset() == 44);
+        harness.check(fourth.getEndOffset() == 45);
+
+        
+        harness.checkPoint("Test 2");
+        doc = new DefaultStyledDocument();
+        root = doc.getDefaultRootElement();
+        doc.insertString(0, "first line of text.", null);
+        harness.check(root.getElementCount() == 1);
+        harness.check(root.getElement(0).getStartOffset() == 0);
+        harness.check(root.getElement(0).getEndOffset() == 20);
+        doc.insertString(5, "second line \n of text.", null);
+        harness.check(root.getElementCount() == 2);
+        harness.check(root.getElement(0).getElementCount() == 1);
+        harness.check(root.getElement(1).getElementCount() == 1);
+
+        first = root.getElement(0).getElement(0);
+        harness.check(first.getStartOffset() == 0);
+        harness.check(first.getEndOffset() == 18);
+
+        second = root.getElement(1).getElement(0);
+        harness.check(second.getStartOffset() == 18);
+        harness.check(second.getEndOffset() == 42);
+        
+        
+        harness.checkPoint("Test 3");
         doc = new DefaultStyledDocument();
         root = doc.getDefaultRootElement();
         doc.insertString(0, "first line of text. \n", null);
@@ -106,7 +161,7 @@
         harness.check(fifth.getStartOffset() == 67);
         harness.check(fifth.getEndOffset() == 68);
         
-        
+        harness.checkPoint("Test 4");
         doc = new DefaultStyledDocument();
         root = doc.getDefaultRootElement();
         doc.insertString(0, "\n second line of text. \n third line of text. \n", null);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* FYI: More DefaultStyledDocument tests
@ 2006-01-05 19:33 Anthony Balkissoon
  0 siblings, 0 replies; 4+ messages in thread
From: Anthony Balkissoon @ 2006-01-05 19:33 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 165 bytes --]

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

	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java: New test.

--Tony

[-- Attachment #2: ElementStructure6.diff --]
[-- Type: text/x-patch, Size: 3585 bytes --]

Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java
diff -N gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure6.java	5 Jan 2006 19:31:55 -0000
@@ -0,0 +1,96 @@
+// 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.*;
+import javax.swing.event.*;
+import javax.swing.text.*;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+public class ElementStructure6 implements Testlet
+{
+  static TestHarness h2;
+  static DefaultStyledDocument doc = new StyledDocument2();
+  static AbstractDocument.DefaultDocumentEvent docEvent = null;
+  
+  public void test(TestHarness harness)
+  {
+    try
+      {
+        h2 = harness;
+        doc.insertString(0, "First line of text. \n", null);
+      }
+    catch (BadLocationException ex)
+      {
+        h2.debug(ex);
+      }        
+  }
+  
+
+  static class StyledDocument2 extends DefaultStyledDocument
+  {
+    public class ElementBuffer2 extends ElementBuffer
+    {
+      public ElementBuffer2(Element root)
+      {
+        super(root);
+      }
+      
+      // ElementBuffer.insertUpdate
+      protected void insertUpdate(ElementSpec[] data)
+      {
+        h2.check(docEvent.getChange(getDefaultRootElement()) == null);
+        super.insertUpdate(data);
+        h2.check(docEvent.getChange(getDefaultRootElement()) == null);
+      }
+
+      public void insert(int offset,
+                         int length,
+                         DefaultStyledDocument.ElementSpec[] data,
+                         AbstractDocument.DefaultDocumentEvent de)
+      {
+        h2.check(docEvent.getChange(getDefaultRootElement()) == null);
+        super.insert(offset, length, data, de);
+        h2.check(docEvent.getChange(getDefaultRootElement()) != null);
+      }
+    }
+    
+    // Creates a new StyledDocument2 using an ElementBuffer2 as the buffer
+    public StyledDocument2()
+    {
+      super();
+      buffer = new ElementBuffer2(createDefaultRoot());
+    }
+    
+    // DefaultStyledDocument.insertUpdate
+    protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng,
+                                AttributeSet attr)
+    {      
+      docEvent = chng;
+      h2.check(docEvent.getChange(getDefaultRootElement()) == null);
+      super.insertUpdate (chng, attr);
+      h2.check(docEvent.getChange(getDefaultRootElement()) != null);
+    }    
+  }    
+}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* FYI: More DefaultStyledDocument tests
@ 2006-01-04 16:34 Anthony Balkissoon
  0 siblings, 0 replies; 4+ messages in thread
From: Anthony Balkissoon @ 2006-01-04 16:34 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 437 bytes --]

Here are more tests that we currently fail.  I'm still trying to figure
out the internals of DefaultStyledDocument and its interaction with the
text Views and events.  

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

	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java: New test.
	*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java: New test.

--Tony

[-- Attachment #2: ElementStructure4And5.diff --]
[-- Type: text/x-patch, Size: 6737 bytes --]

Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java
diff -N gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java	4 Jan 2006 16:31:14 -0000
@@ -0,0 +1,81 @@
+// 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.DefaultStyledDocument;
+import javax.swing.text.BadLocationException;
+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
+{
+  /**
+   * Starts the test run.
+   *
+   * @param harness the test harness to use
+   */
+  public void test(TestHarness harness)
+  {
+    try
+      {
+        DefaultStyledDocument doc = new DefaultStyledDocument();
+        SimpleAttributeSet atts = new SimpleAttributeSet();
+        Element root = doc.getDefaultRootElement();
+
+        // Add strike trough text.
+        atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
+        doc.insertString(0, "Strike through text.\n", atts);
+        atts.removeAttributes(atts);
+        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.check(root.getElement(0).getElementCount() == 2);
+        harness.check(root.getElement(1).getElementCount() == 1);
+        doc.insertString(1, "b", null);
+        harness.check(root.getElement(0).getElementCount() == 2);
+        harness.check(root.getElement(1).getElementCount() == 1);
+
+
+        Element first = root.getElement(0).getElement(0);
+        harness.check(first.getStartOffset() == 0);
+        harness.check(first.getEndOffset() == 2);
+
+        Element second = root.getElement(0).getElement(1);
+        harness.check(second.getStartOffset() == 2);
+        harness.check(second.getEndOffset() == 23);
+      }
+    catch (Throwable t)
+      {
+        harness.debug(t);
+      }
+  }
+}
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java
diff -N gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure5.java	4 Jan 2006 16:31:14 -0000
@@ -0,0 +1,79 @@
+// 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.DefaultStyledDocument;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Element;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+public class ElementStructure5 implements Testlet
+{
+  /**
+   * Starts the test run.
+   *
+   * @param harness the test harness to use
+   */
+  public void test(TestHarness harness)
+  {
+    try
+      {
+        DefaultStyledDocument doc = new DefaultStyledDocument();
+        Element root = doc.getDefaultRootElement();
+
+        // Add a first line of text.
+        doc.insertString(0, "first line of text. \n", null);
+        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 another line of text.
+        doc.insertString(21, "second line of text. \n", null);
+        harness.check(root.getElementCount() == 3);
+        harness.check(root.getElement(0).getElementCount() == 1);
+        harness.check(root.getElement(1).getElementCount() == 1);
+        harness.check(root.getElement(2).getElementCount() == 1);
+
+
+        Element first = root.getElement(0).getElement(0);
+        harness.check(first.getStartOffset() == 0);
+        harness.check(first.getEndOffset() == 21);
+
+        Element second = root.getElement(1).getElement(0);
+        harness.check(second.getStartOffset() == 21);
+        harness.check(second.getEndOffset() == 43);
+
+        Element third = root.getElement(2).getElement(0);
+        harness.check(third.getStartOffset() == 43);
+        harness.check(third.getEndOffset() == 44);
+      }
+    catch (Throwable t)
+      {
+        harness.debug(t);
+      }
+  }
+}

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-01-16 19:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-21 18:33 FYI: More DefaultStyledDocument tests Anthony Balkissoon
2006-01-04 16:34 Anthony Balkissoon
2006-01-05 19:33 Anthony Balkissoon
2006-01-16 19:59 Lillian Angel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).