This is the mail archive of the
mauve-patches@sourceware.org
mailing list for the Mauve project.
FYI: New ElementBuffer test
- From: "Roman Kennke" <roman dot kennke at aicas dot com>
- To: mauve-patches at sources dot redhat dot com
- Date: Tue, 21 Feb 2006 20:57:58 +0000
- Subject: FYI: New ElementBuffer test
- Bounce-to: "Roman Kennke" <roman.kennke@aicas.com>
I added a new test for the ElementBuffer class which demonstrates a
misbehaviour in Classpath's implementation.
2006-02-21 Roman Kennke <kennke@aicas.com>
*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/insert.java:
(testNewlines): New test.
/Roman
Index: gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/insert.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/insert.java,v
retrieving revision 1.3
diff -u -r1.3 insert.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/insert.java 23 Nov 2005 13:59:55 -0000 1.3
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/insert.java 21 Feb 2006 20:49:54 -0000
@@ -100,6 +100,8 @@
testEndTag3(harness);
testEndTag4(harness);
testEndTag5(harness);
+
+ testNewlines(harness);
}
/**
@@ -926,6 +928,100 @@
}
/**
+ * Inserts 'a\na\n' and checks the results. The characters are inserted
+ * one by one, as if somebody typed it in by keyboard.
+ *
+ * @param h the test harness to use
+ */
+ private void testNewlines(TestHarness h)
+ {
+ h.checkPoint("testNewlines");
+ TestDocument doc = new TestDocument();
+ doc.addDocumentListener(this);
+
+ // The first 'a'
+ char[] text = new char[] {'a'};
+ SimpleAttributeSet atts = new SimpleAttributeSet();
+ TestDocument.ElementSpec[] specs = new TestDocument.ElementSpec[1];
+ specs[0] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.ContentType,
+ text, 0, 1);
+ specs[0].setDirection(TestDocument.ElementSpec.JoinPreviousDirection);
+ doc.insert(0, specs);
+
+ // The first '\n'
+ text = new char[] {'\n'};
+ specs = new TestDocument.ElementSpec[3];
+ specs[0] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.ContentType,
+ text, 0, 1);
+ specs[0].setDirection(TestDocument.ElementSpec.JoinPreviousDirection);
+ specs[1] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.EndTagType);
+ specs[1].setDirection(TestDocument.ElementSpec.OriginateDirection);
+ specs[2] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.StartTagType);
+ specs[1].setDirection(TestDocument.ElementSpec.JoinFractureDirection);
+ doc.insert(1, specs);
+
+ // The second 'a'
+ text = new char[] {'a'};
+ specs = new TestDocument.ElementSpec[3];
+ specs[0] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.EndTagType);
+ specs[0].setDirection(TestDocument.ElementSpec.OriginateDirection);
+ specs[1] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.StartTagType);
+ specs[1].setDirection(TestDocument.ElementSpec.JoinNextDirection);
+ specs[2] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.ContentType,
+ text, 0, 1);
+ specs[1].setDirection(TestDocument.ElementSpec.OriginateDirection);
+ doc.insert(2, specs);
+
+ // The second '\n'
+ text = new char[] {'\n'};
+ specs = new TestDocument.ElementSpec[3];
+ specs[0] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.ContentType,
+ text, 0, 1);
+ specs[0].setDirection(TestDocument.ElementSpec.JoinPreviousDirection);
+ specs[1] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.EndTagType);
+ specs[1].setDirection(TestDocument.ElementSpec.OriginateDirection);
+ specs[2] =
+ new TestDocument.ElementSpec(atts, TestDocument.ElementSpec.StartTagType);
+ specs[1].setDirection(TestDocument.ElementSpec.JoinFractureDirection);
+ doc.insert(3, specs);
+
+ // We have one paragraph in the root element.
+ Element root = doc.getDefaultRootElement();
+ h.check(root.getElementCount(), 3);
+
+ // We should now have 1 child in the 1st paragraph.
+ Element par = root.getElement(0);
+ h.check(par.getElementCount(), 1);
+ Element el = par.getElement(0);
+ h.check(el.getStartOffset(), 0);
+ h.check(el.getEndOffset(), 2);
+
+ // We should now have 1 child in the 2nd paragraph.
+ par = root.getElement(1);
+ h.check(par.getElementCount(), 1);
+ el = par.getElement(0);
+ h.check(el.getStartOffset(), 2);
+ h.check(el.getEndOffset(), 4);
+
+ // We should now have 1 child in the 3rd paragraph.
+ par = root.getElement(2);
+ h.check(par.getElementCount(), 1);
+ el = par.getElement(0);
+ h.check(el.getStartOffset(), 4);
+ h.check(el.getEndOffset(), 5);
+
+ }
+
+ /**
* Receives notification when some text attributes have changed.
*
* @param event the document event