* FYI: Cleanup of the javax.swing.text tests
@ 2006-07-28 11:04 Roman Kennke
0 siblings, 0 replies; only message in thread
From: Roman Kennke @ 2006-07-28 11:04 UTC (permalink / raw)
To: mauve-patches
[-- Attachment #1: Type: text/plain, Size: 1471 bytes --]
Here comes some cleanup that I did in the javax.swing.text tests, as
well as a couple of new tests that have been lying around on my HD.
2006-07-28 Roman Kennke <kennke@aicas.com>
* gnu/testlet/javax/swing/text/AbstractDocument/getDocumentProperties.java:
Removed debug output.
*
gnu/testlet/javax/swing/text/AbstractDocument/BranchElement/getElementIndex.java:
New test.
*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java:
Changed tests to do check(x, y) rather than check(x == y), so
that the wrong value gets recognized by Mauve.
*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java:
Likewise.
*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument2.java:
Likewise.
*
gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/insert.java
(testNewlines2): New test.
* gnu/testlet/javax/swing/text/FlowView/FlowStrategy/TestView.java:
New helper class.
* gnu/testlet/javax/swing/text/FlowView/FlowStrategy/adjustRow.java:
New test.
* gnu/testlet/javax/swing/text/FlowView/TestFlowView.java:
Fixed.
* gnu/testlet/javax/swing/text/PlainDocument/getRootElements.java:
Fixed test.
* gnu/testlet/javax/swing/text/Utilities/getBreakLocation.java:
New test.
* gnu/testlet/javax/swing/text/View/getMaximumSpan.java:
Added comment.
*
gnu/testlet/javax/swing/text/html/parser/ParserDelegator/parsingTester.java:
Fixed test.
/Roman
[-- Attachment #2: patch.diff --]
[-- Type: text/x-patch, Size: 43835 bytes --]
Index: gnu/testlet/javax/swing/text/AbstractDocument/getDocumentProperties.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/AbstractDocument/getDocumentProperties.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 getDocumentProperties.java
--- gnu/testlet/javax/swing/text/AbstractDocument/getDocumentProperties.java 22 Jun 2006 12:41:27 -0000 1.1
+++ gnu/testlet/javax/swing/text/AbstractDocument/getDocumentProperties.java 28 Jul 2006 11:02:44 -0000
@@ -18,41 +18,39 @@
02110-1301 USA.
*/
// Tags: FIXME
package gnu.testlet.javax.swing.text.AbstractDocument;
import java.util.Dictionary;
import java.util.Enumeration;
import javax.swing.text.AbstractDocument;
-import javax.swing.text.PlainDocument;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
public class getDocumentProperties implements Testlet
{
public void test(TestHarness harness)
{
testDefault(harness);
}
private void testDefault(TestHarness h)
{
AbstractDocument doc = new TestAbstractDocument();
Dictionary props = doc.getDocumentProperties();
Enumeration keys = props.keys();
while (keys.hasMoreElements())
{
Object key = keys.nextElement();
- System.out.println("key: " + key + ", value: " + props.get(key));
}
h.check(props.size(), 1);
h.check(props.get("i18n"), Boolean.FALSE);
}
}
Index: gnu/testlet/javax/swing/text/AbstractDocument/BranchElement/getElementIndex.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/AbstractDocument/BranchElement/getElementIndex.java
diff -N gnu/testlet/javax/swing/text/AbstractDocument/BranchElement/getElementIndex.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/AbstractDocument/BranchElement/getElementIndex.java 28 Jul 2006 11:02:44 -0000
@@ -0,0 +1,73 @@
+/* getElementIndex.java -- Checks the getElementIndex method in BranchElement
+ Copyright (C) 2006 Roman Kennke (kennke@aicas.com)
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: JDK1.2
+
+package gnu.testlet.javax.swing.text.AbstractDocument.BranchElement;
+
+import javax.swing.text.AbstractDocument;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Element;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.AbstractDocument.BranchElement;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * Checks various aspects of the getElementIndex() method in BranchElement.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class getElementIndex implements Testlet
+{
+
+ /**
+ * The entry point into this test.
+ *
+ * @param harness the test harness to use
+ */
+ public void test(TestHarness harness)
+ {
+ testBeyondBoundary(harness);
+ }
+
+ /**
+ * Checks how getElementIndex should behave when the requested index is
+ * beyond the document boundary.
+ *
+ * @param h
+ */
+ private void testBeyondBoundary(TestHarness h)
+ {
+ PlainDocument doc = new PlainDocument();
+ try
+ {
+ doc.insertString(0, "hello\n", null);
+ }
+ catch (BadLocationException ex)
+ {
+ h.fail(ex.getMessage());
+ }
+ Element root = doc.getDefaultRootElement();
+ h.check(root.getElementIndex(6), 1);
+ }
+}
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.4
diff -u -1 -2 -r1.4 ElementStructure4.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java 6 Feb 2006 15:24:54 -0000 1.4
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure4.java 28 Jul 2006 11:02:44 -0000
@@ -15,27 +15,25 @@
// 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 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 ElementStructure4 extends DefaultStyledDocument implements Testlet
{
/**
* Starts the test run.
*
* @param harness the test harness to use
*/
@@ -44,29 +42,29 @@
try
{
h2 = harness;
ElementStructure4 doc = new ElementStructure4();
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.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);
+ 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);
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.10
diff -u -1 -2 -r1.10 ElementStructure8.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java 6 Feb 2006 15:24:54 -0000 1.10
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/ElementStructure8.java 28 Jul 2006 11:02:44 -0000
@@ -205,42 +205,37 @@
harness.check(fourth.getEndOffset() == 47);
//printElements(doc.getDefaultRootElement(), 0);
/* TEST 5 *////////////////////////////////////////////////////////////
harness.checkPoint("Test 5");
doc = new ElementStructure8();
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(20, "\n third line of text.", 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);
+ doc.insertString(19, "\n third line 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() == 20);
+ harness.check(first.getStartOffset(), 0);
+ harness.check(first.getEndOffset(), 20);
second = root.getElement(1).getElement(0);
- harness.check(second.getStartOffset() == 20);
- harness.check(second.getEndOffset() == 21);
+ harness.check(second.getStartOffset(), 20);
+ harness.check(second.getEndOffset(), 41);
- 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);
}
@@ -319,26 +314,26 @@
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);
+ h2.check(o, 19);
+ h2.check(l, 21);
}
else
h2.fail ("too many calls to DefaultStyledDocument.insertUpdate");
super.insertUpdate(ev, attr);
}
// 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
@@ -644,50 +639,41 @@
{
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);
+ 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(), 20);
+
}
else
h2.fail("too many ElementSpecs created");
super.insertUpdate(data);
}
}
}
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.2
diff -u -1 -2 -r1.2 StyledDocument2.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument2.java 23 Jan 2006 18:31:58 -0000 1.2
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/StyledDocument2.java 28 Jul 2006 11:02:44 -0000
@@ -100,30 +100,30 @@
(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);
+ h2.check (p0, 0);
+ h2.check (p1, 5);
try
{
- h2.check (parent.getStartOffset() == 0);
- h2.check (parent.getEndOffset() == 6);
+ 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)
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.4
diff -u -1 -2 -r1.4 insert.java
--- gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/insert.java 21 Feb 2006 20:52:22 -0000 1.4
+++ gnu/testlet/javax/swing/text/DefaultStyledDocument/ElementBuffer/insert.java 28 Jul 2006 11:02:44 -0000
@@ -93,24 +93,25 @@
testJoinPrevious2(harness);
testJoinPrevious3(harness);
testJoinNext1(harness);
testJoinNext2(harness);
testJoinNext3(harness);
testEndTag1(harness);
testEndTag2(harness);
testEndTag3(harness);
testEndTag4(harness);
testEndTag5(harness);
testNewlines(harness);
+ testNewlines2(harness);
}
/**
* Tests content insertion with OriginateDirection. This test inserts
* a content element between two existing elements.
*
* @param h the test harness to use
*/
private void testOriginate1(TestHarness h)
{
h.checkPoint("testOriginate1");
TestDocument doc = new TestDocument();
@@ -952,55 +953,55 @@
// 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);
+ specs[2].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);
+ specs[2].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);
+ specs[2].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);
@@ -1012,24 +1013,137 @@
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);
}
+
+ /**
+ * Inserts 'a\na\na' 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 testNewlines2(TestHarness h)
+ {
+ h.checkPoint("testNewlines2");
+ 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[2].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[2].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[2].setDirection(TestDocument.ElementSpec.JoinFractureDirection);
+ doc.insert(3, specs);
+
+ // The 3rd '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[2].setDirection(TestDocument.ElementSpec.OriginateDirection);
+ doc.insert(4, specs);
+
+ // We have 3 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 2 children in the 3rd paragraph.
+ par = root.getElement(2);
+ h.check(par.getElementCount(), 2);
+ el = par.getElement(0);
+ h.check(el.getStartOffset(), 4);
+ h.check(el.getEndOffset(), 5);
+ el = par.getElement(1);
+ h.check(el.getStartOffset(), 5);
+ h.check(el.getEndOffset(), 6);
+
+ }
+
/**
* Receives notification when some text attributes have changed.
*
* @param event the document event
*/
public void changedUpdate(DocumentEvent event)
{
// Do nothing here.
}
/**
* Receives notification when some text has been inserted into the document.
Index: gnu/testlet/javax/swing/text/FlowView/TestFlowView.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/FlowView/TestFlowView.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 TestFlowView.java
--- gnu/testlet/javax/swing/text/FlowView/TestFlowView.java 7 Feb 2006 14:20:16 -0000 1.1
+++ gnu/testlet/javax/swing/text/FlowView/TestFlowView.java 28 Jul 2006 11:02:44 -0000
@@ -14,46 +14,120 @@
You should have received a copy of the GNU General Public License
along with Mauve; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
// Tags: not-a-test
package gnu.testlet.javax.swing.text.FlowView;
+import gnu.testlet.javax.swing.text.FlowView.FlowStrategy.TestView;
+
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.Shape;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.BoxView;
import javax.swing.text.Element;
import javax.swing.text.FlowView;
import javax.swing.text.View;
+import javax.swing.text.Position.Bias;
/**
* A concrete subclass of FlowView that can be used to test the FlowView.
*
* @author Roman Kennke (kennke@aicas.com)
*/
public class TestFlowView extends FlowView
{
+ public class TestFlowStrategy extends FlowStrategy
+ {
+ public void adjustRow(FlowView fv, int rowIndex, int desiredSpan, int x)
+ {
+ super.adjustRow(fv, rowIndex, desiredSpan, x);
+ }
+ }
+
+ public class TestRow extends BoxView
+ {
+ public int preferred = 200;
+ public TestRow break1;
+ public TestRow break2;
+ public int breakWeight = View.BadBreakWeight;
+
+ public TestRow(Element el)
+ {
+ super(el, View.X_AXIS);
+ }
+
+ public float getPreferredSpan(int axis)
+ {
+ System.err.println("preferredSpan called");
+ return preferred;
+ }
+
+ public float getMinimumSpan(int axis)
+ {
+ System.err.println("minimumSpan called");
+ return preferred;
+ }
+
+ /**
+ * This is implemented to return <code>breakWeight</code> when pos + len >
+ * <code>preferred / 2</code>, that means it returns the break weight
+ * specified by the testing code when the desired break location is beyond
+ * the middle of the view.
+ */
+ public int getBreakWeight(int axis, float pos, float len)
+ {System.err.println("getBreakWeight called");
+ if (pos + len > preferred)
+ return breakWeight;
+ else
+ return View.BadBreakWeight;
+ }
+
+ public View breakView(int axis, int offset, float pos, float len)
+ {System.err.println("breakView called");
+ break1 = new TestRow(getElement());
+ break1.preferred = preferred / 2;
+ break2 = new TestRow(getElement());
+ break2.preferred = preferred / 2;
+ if (offset < preferred / 2)
+ return break1;
+ else
+ return break2;
+ }
+
+ }
+
/**
* Constructs a new TestFlowView by calling super.
*
* @param element the element
* @param axis the axis
*/
public TestFlowView(Element element, int axis)
{
super(element, axis);
+ strategy = new TestFlowStrategy();
}
/**
* Creates a row.
*
* @return a view for one row
*/
- protected View createRow()
+ public View createRow()
{
- return null;
+ return new TestRow(getElement());
}
+ public TestFlowStrategy getFlowStragy()
+ {
+ return (TestFlowStrategy) strategy;
+ }
}
Index: gnu/testlet/javax/swing/text/FlowView/FlowStrategy/TestView.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/FlowView/FlowStrategy/TestView.java
diff -N gnu/testlet/javax/swing/text/FlowView/FlowStrategy/TestView.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/FlowView/FlowStrategy/TestView.java 28 Jul 2006 11:02:44 -0000
@@ -0,0 +1,102 @@
+/* TestView.java -- A mock view for testing
+ Copyright (C) 2006 Roman Kennke (kennke@aicas.com)
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: not-a-test
+
+package gnu.testlet.javax.swing.text.FlowView.FlowStrategy;
+
+import java.awt.Graphics;
+import java.awt.Shape;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Element;
+import javax.swing.text.View;
+import javax.swing.text.Position.Bias;
+
+
+public class TestView extends View
+{
+
+ public int preferred = 100;
+
+ public int breakWeight = View.BadBreakWeight;
+
+ public TestView break1;
+ public TestView break2;
+
+ public TestView(Element el)
+ {
+ super(el);
+ }
+
+ public void paint(Graphics g, Shape s)
+ {
+ // Not needed in testing.
+ }
+
+ public float getMinimumSpan(int axis)
+ {
+ return getPreferredSpan(axis);
+ }
+ public float getPreferredSpan(int axis)
+ {
+ return preferred;
+ }
+
+ public Shape modelToView(int pos, Shape a, Bias b)
+ throws BadLocationException
+ {
+ // Not needed in testing.
+ return null;
+ }
+
+ public int viewToModel(float x, float y, Shape a, Bias[] b)
+ {
+ // Not needed in testing.
+ return 0;
+ }
+
+ /**
+ * This is implemented to return <code>breakWeight</code> when pos + len >
+ * <code>preferred / 2</code>, that means it returns the break weight
+ * specified by the testing code when the desired break location is beyond
+ * the middle of the view.
+ */
+ public int getBreakWeight(int axis, float pos, float len)
+ {
+ if (pos + len > preferred)
+ return breakWeight;
+ else
+ return View.BadBreakWeight;
+ }
+
+ public View breakView(int axis, int offset, float pos, float len)
+ {
+ break1 = new TestView(getElement());
+ break1.preferred = preferred / 2;
+ break2 = new TestView(getElement());
+ break2.preferred = preferred / 2;
+ if (offset < preferred / 2)
+ return break1;
+ else
+ return break2;
+ }
+}
Index: gnu/testlet/javax/swing/text/FlowView/FlowStrategy/adjustRow.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/FlowView/FlowStrategy/adjustRow.java
diff -N gnu/testlet/javax/swing/text/FlowView/FlowStrategy/adjustRow.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/FlowView/FlowStrategy/adjustRow.java 28 Jul 2006 11:02:44 -0000
@@ -0,0 +1,140 @@
+/* adjustRow.java -- Tests the FlowStrategy.adjustRow() method
+ Copyright (C) 2006 Roman Kennke (kennke@aicas.com)
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: JDK1.2
+// Uses: ../TestFlowView
+
+package gnu.testlet.javax.swing.text.FlowView.FlowStrategy;
+
+import javax.swing.text.DefaultStyledDocument;
+import javax.swing.text.Element;
+import javax.swing.text.View;
+import javax.swing.text.AbstractDocument.BranchElement;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+import gnu.testlet.javax.swing.text.FlowView.TestFlowView;
+
+/**
+ * Tests the FlowStrategy.adjustRow() method.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class adjustRow implements Testlet
+{
+
+ /**
+ * The entry point into this test.
+ *
+ * @param the test harness to use
+ */
+ public void test(TestHarness harness)
+ {
+ testUnbreakable(harness);
+ testGoodBreakable(harness);
+ testExcellentBreakable(harness);
+ testForceBreakable(harness);
+ }
+
+ /**
+ * This places one row into the FlowView and one view into that row that
+ * is bigger than the desired span. However, since it is not breakable, this
+ * will not be touched.
+ *
+ * @param h
+ */
+ private void testUnbreakable(TestHarness h)
+ {
+ DefaultStyledDocument doc = new DefaultStyledDocument();
+ Element el = doc.new BranchElement(null, null);
+ TestFlowView fv = new TestFlowView(el, View.Y_AXIS);
+ // Create one row and fill it with one oversized testview.
+ TestFlowView.TestRow row = (TestFlowView.TestRow) fv.createRow();
+ fv.replace(0, 0, new View[]{row});
+ row.preferred = 200;
+
+ fv.getFlowStragy().adjustRow(fv, 0, 150, 0);
+ h.check(fv.getView(0), row);
+ }
+
+ /**
+ * This places one row into the FlowView and one view into that row that
+ * is bigger than the desired span. However, since it is not breakable, this
+ * will not be touched.
+ *
+ * @param h
+ */
+ private void testGoodBreakable(TestHarness h)
+ {
+ DefaultStyledDocument doc = new DefaultStyledDocument();
+ Element el = doc.new BranchElement(null, null);
+ TestFlowView fv = new TestFlowView(el, View.Y_AXIS);
+ // Create one row and fill it with one oversized testview.
+ TestFlowView.TestRow row = (TestFlowView.TestRow) fv.createRow();
+ fv.replace(0, 0, new View[]{row});
+ row.breakWeight = View.GoodBreakWeight;
+ row.preferred = 200;
+ fv.getFlowStragy().adjustRow(fv, 0, 150, 0);
+ h.check(fv.getView(0), row);
+ }
+
+ /**
+ * This places one row into the FlowView and one view into that row that
+ * is bigger than the desired span. However, since it is not breakable, this
+ * will not be touched.
+ *
+ * @param h
+ */
+ private void testExcellentBreakable(TestHarness h)
+ {
+ DefaultStyledDocument doc = new DefaultStyledDocument();
+ Element el = doc.new BranchElement(null, null);
+ TestFlowView fv = new TestFlowView(el, View.Y_AXIS);
+ // Create one row and fill it with one oversized testview.
+ TestFlowView.TestRow row = (TestFlowView.TestRow) fv.createRow();
+ fv.replace(0, 0, new View[]{row});
+ row.breakWeight = View.ExcellentBreakWeight;
+ row.preferred = 200;
+ fv.getFlowStragy().adjustRow(fv, 0, 150, 0);
+ h.check(fv.getView(0), row);
+ }
+
+ /**
+ * This places one row into the FlowView and one view into that row that
+ * is bigger than the desired span. However, since it is not breakable, this
+ * will not be touched.
+ *
+ * @param h
+ */
+ private void testForceBreakable(TestHarness h)
+ {
+ DefaultStyledDocument doc = new DefaultStyledDocument();
+ Element el = doc.new BranchElement(null, null);
+ TestFlowView fv = new TestFlowView(el, View.Y_AXIS);
+ // Create one row and fill it with one oversized testview.
+ TestFlowView.TestRow row = (TestFlowView.TestRow) fv.createRow();
+ fv.replace(0, 0, new View[]{row});
+ row.breakWeight = View.ForcedBreakWeight;
+ row.preferred = 200;
+ fv.getFlowStragy().adjustRow(fv, 0, 150, 0);
+ h.check(fv.getView(0), row);
+ }
+}
Index: gnu/testlet/javax/swing/text/PlainDocument/getRootElements.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/PlainDocument/getRootElements.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 getRootElements.java
--- gnu/testlet/javax/swing/text/PlainDocument/getRootElements.java 25 Jan 2006 18:15:10 -0000 1.1
+++ gnu/testlet/javax/swing/text/PlainDocument/getRootElements.java 28 Jul 2006 11:02:44 -0000
@@ -33,17 +33,17 @@
public class getRootElements implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
PlainDocument d = new PlainDocument();
Element[] e = d.getRootElements();
- harness.check(e.length, 1);
+ harness.check(e.length, 2);
harness.check(e[0], d.getDefaultRootElement());
}
}
\ No newline at end of file
Index: gnu/testlet/javax/swing/text/Utilities/getBreakLocation.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/Utilities/getBreakLocation.java
diff -N gnu/testlet/javax/swing/text/Utilities/getBreakLocation.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/Utilities/getBreakLocation.java 28 Jul 2006 11:02:44 -0000
@@ -0,0 +1,38 @@
+/* getBreakLocation.java -- FIXME: describe
+ Copyright (C) 2006 FIXME: your info here
+This file is part of Mauve.
+
+Mauve is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+Mauve is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mauve; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+*/
+
+// Tags: FIXME
+
+package gnu.testlet.javax.swing.text.Utilities;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+public class getBreakLocation implements Testlet
+{
+
+ public void test(TestHarness harness)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Index: gnu/testlet/javax/swing/text/View/getMaximumSpan.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/View/getMaximumSpan.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 getMaximumSpan.java
--- gnu/testlet/javax/swing/text/View/getMaximumSpan.java 9 Feb 2006 11:58:15 -0000 1.1
+++ gnu/testlet/javax/swing/text/View/getMaximumSpan.java 28 Jul 2006 11:02:44 -0000
@@ -83,22 +83,27 @@
* Tests the default impl for the Y_AXIS. This will forward to
* getPreferredSpan().
*
* @param harness the test harness to use
*/
private void testYAxis(TestHarness harness)
{
TestView v = new TestView();
v.preferred[View.Y_AXIS] = 123F;
harness.check(v.getMaximumSpan(View.Y_AXIS), 123F);
}
+ /**
+ * Tests the maximumSpan with a positive resizeWeight.
+ *
+ * @param harness the test harness to use
+ */
private void testPositiveResizeWeight(TestHarness harness)
{
PositiveResizeWeightView v = new PositiveResizeWeightView();
v.resizeWeight = 100;
v.preferred[View.X_AXIS] = 123F;
v.preferred[View.Y_AXIS] = 123F;
harness.check((int) v.getMaximumSpan(View.X_AXIS), Integer.MAX_VALUE);
harness.check((int) v.getMaximumSpan(View.Y_AXIS), Integer.MAX_VALUE);
}
}
Index: gnu/testlet/javax/swing/text/html/parser/ParserDelegator/parsingTester.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/javax/swing/text/html/parser/ParserDelegator/parsingTester.java,v
retrieving revision 1.5
diff -u -1 -2 -r1.5 parsingTester.java
--- gnu/testlet/javax/swing/text/html/parser/ParserDelegator/parsingTester.java 17 Feb 2005 19:30:05 -0000 1.5
+++ gnu/testlet/javax/swing/text/html/parser/ParserDelegator/parsingTester.java 28 Jul 2006 11:02:44 -0000
@@ -96,62 +96,62 @@
public void test(TestHarness a_harness)
{
harness = a_harness;
testHTMLParsing();
}
public void testHTMLParsing()
{
// Test subsequent tags.
verify("<b><i><u>text</b><i></u>",
"<html _implied_='true'><head _implied_='true'></head>"+
- "<body _implied_='true'><b><i><u>[text]</b><i></u></i>"+
+ "<body _implied_='true'><b><i><u>'text'</u></i></b><i>"+
"</i></body></html>", "subseqent tags");
// Test entities.
verify("eqdec: = ampnamed: &",
"<html _implied_='true'><head _implied_='true'></head>" +
"<body _implied_='true'>'eqdec: = ampnamed: &'</body></html>",
"Named and numeric entities"
);
// Test entities in attributes.
verify("<hr id='id_)Z' class= \"Y_&\" >",
"<html _implied_='true'><head _implied_='true'></head>" +
- "<body _implied_='true'><hr class='Y_&' id='id_)Z'/></body></html>",
+ "<body _implied_='true'><hr class='y_&' id='id_)Z'/></body></html>",
"Numeric and named entities in attributes"
);
// Test unclosed tags.
verify("<hr id = 1 class = c<hr id=2>",
"<html _implied_='true'><head _implied_='true'></head>" +
"<body _implied_='true'><hr class='c' id='1'/><hr id='2'/>" +
"</body></html>", "Error tolerance (unclosed tags)"
);
// Test valid attributes.
verify("<hr id='i' TITLE=\"tit\" clAss=cl><hr><hr id = 2>",
"<html _implied_='true'><head _implied_='true'>" +
"</head><body _implied_='true'><hr class='cl' id='i' title='tit'/>" +
"<hr/><hr id='2'/></body></html>", "Attributes"
);
// Test attributes witout value.
verify("<option id=a selected><option id=b selected = " +
"selected class=cC><input checked>",
"<html _implied_='true'><head _implied_='true'></head>" +
"<body _implied_='true'><option id='a' selected='selected'>" +
- "</option><option class='cC' id='b' selected='selected'></option>" +
+ "</option><option class='cc' id='b' selected='selected'></option>" +
"<input checked='checked'/></body></html>",
"Attributes without value"
);
// Test unknown attribute without value.
verify("<hr audrius title=\"tit\">",
"<html _implied_='true'><head _implied_='true'>"+
"</head><body _implied_='true'><hr audrius='#DEFAULT' "+
"title='tit'/></body></html>",
"surely unknown attribute 'audrius' without value"
);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-07-28 11:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-28 11:04 FYI: Cleanup of the javax.swing.text tests Roman Kennke
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).