From f911ba985aa7fe0096c386c5be385ac5825ea527 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 16 Jul 2005 00:30:23 +0000 Subject: Initial revision From-SVN: r102074 --- .../AllParserTests.java | 149 +++++++++++ .../test/gnu/javax/swing/text/html/HTML_Test.java | 130 ++++++++++ .../swing/text/html/parser/AttributeList_test.java | 68 +++++ .../gnu/javax/swing/text/html/parser/DTD_test.java | 102 ++++++++ .../javax/swing/text/html/parser/Element_Test.java | 117 +++++++++ .../javax/swing/text/html/parser/Entity_Test.java | 119 +++++++++ .../javax/swing/text/html/parser/HTML_parsing.java | 281 +++++++++++++++++++++ .../swing/text/html/parser/HTML_randomTable.java | 155 ++++++++++++ .../text/html/parser/ParserEntityResolverTest.java | 99 ++++++++ .../javax/swing/text/html/parser/ParserTest.java | 150 +++++++++++ .../javax/swing/text/html/parser/Parser_Test.java | 162 ++++++++++++ .../swing/text/html/parser/TagElement_Test.java | 87 +++++++ .../gnu/javax/swing/text/html/parser/TestCase.java | 138 ++++++++++ .../gnu/javax/swing/text/html/parser/Text.java | 155 ++++++++++++ .../swing/text/html/parser/Token_locations.java | 124 +++++++++ .../swing/text/html/parser/low/Buffer_Test.java | 67 +++++ .../swing/text/html/parser/low/Constants_Test.java | 89 +++++++ .../text/html/parser/low/ReaderTokenizer_Test.java | 159 ++++++++++++ .../text/html/parser/parameterDefaulter_Test.java | 92 +++++++ .../html/parser/supplementaryNotifications.java | 86 +++++++ .../text/html/parser/textPreProcessor_Test.java | 150 +++++++++++ 21 files changed, 2679 insertions(+) create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/AllParserTests.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/HTML_Test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/AttributeList_test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/DTD_test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Element_Test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Entity_Test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_parsing.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_randomTable.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserEntityResolverTest.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserTest.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Parser_Test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TagElement_Test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TestCase.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Text.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Token_locations.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Buffer_Test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Constants_Test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/ReaderTokenizer_Test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/parameterDefaulter_Test.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/supplementaryNotifications.java create mode 100644 libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/textPreProcessor_Test.java (limited to 'libjava/classpath/testsuite/javax.swing.text.html.parser') diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/AllParserTests.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/AllParserTests.java new file mode 100644 index 0000000..d4fca26 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/AllParserTests.java @@ -0,0 +1,149 @@ +/* AllParserTests.java -- The comprehensive HTML parser test. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +import test.gnu.javax.swing.text.html.HTML_Test; +import test.gnu.javax.swing.text.html.parser.AttributeList_test; +import test.gnu.javax.swing.text.html.parser.DTD_test; +import test.gnu.javax.swing.text.html.parser.Element_Test; +import test.gnu.javax.swing.text.html.parser.Entity_Test; +import test.gnu.javax.swing.text.html.parser.HTML_parsing; +import test.gnu.javax.swing.text.html.parser.HTML_randomTable; +import test.gnu.javax.swing.text.html.parser.ParserEntityResolverTest; +import test.gnu.javax.swing.text.html.parser.TagElement_Test; +import test.gnu.javax.swing.text.html.parser.Text; +import test.gnu.javax.swing.text.html.parser.Token_locations; +import test.gnu.javax.swing.text.html.parser.parameterDefaulter_Test; +import test.gnu.javax.swing.text.html.parser.supplementaryNotifications; +import test.gnu.javax.swing.text.html.parser.textPreProcessor_Test; +import test.gnu.javax.swing.text.html.parser.low.Buffer_Test; +import test.gnu.javax.swing.text.html.parser.low.Constants_Test; +import test.gnu.javax.swing.text.html.parser.low.ReaderTokenizer_Test; + +/** + * This is a complete test for javax.swing.text.html.parser package. + * Apart javax.* classes, it also tests the implementation specific + * gnu.javax.* classes and in this way is more strict than + * Mauve tests. To avoid regression it is strongly recommended to run + * this test after you modify clases in javax.swing.text.html.parser or + * gnu.javax.swing.text.html.parser. + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class AllParserTests +{ + public static void main(String[] args) + { + try + { + HTML_Test a_HTML_Test = new HTML_Test(); + a_HTML_Test.testGetAttributeKey(); + a_HTML_Test.testGetIntegerAttributeValue(); + a_HTML_Test.testGetTag(); + a_HTML_Test.testCaseSensitivity(); + a_HTML_Test.testConstructor(); + + Buffer_Test a_Buffer_Test = new Buffer_Test(); + a_Buffer_Test.testDelete(); + a_Buffer_Test.testAppend(); + + Constants_Test a_Constants_Test = new Constants_Test(); + a_Constants_Test.testCases(); + + ReaderTokenizer_Test a_ReaderTokenizer_Test = + new ReaderTokenizer_Test(); + a_ReaderTokenizer_Test.testReadingAndAhead(); + a_ReaderTokenizer_Test.testComplexToken(); + + AttributeList_test a_AttributeList_test = new AttributeList_test(); + a_AttributeList_test.testSame(); + + DTD_test a_DTD_test = new DTD_test(); + a_DTD_test.testGetElement(); + + Element_Test a_Element_Test = new Element_Test(); + a_Element_Test.testName2type(); + a_Element_Test.testAttributeGetter(); + + Entity_Test a_Entity_Test = new Entity_Test(); + a_Entity_Test.testName2type(); + a_Entity_Test.testPublicSystemGeneralParameter(); + + HTML_parsing a_HTML_parsing = new HTML_parsing(); + a_HTML_parsing.testHTMLParsing(); + + HTML_randomTable a_HTML_randomTable = new HTML_randomTable(); + a_HTML_randomTable.testTableParsing(); + + parameterDefaulter_Test a_parameterDefaulter_Test = + new parameterDefaulter_Test(); + a_parameterDefaulter_Test.testDefaultValues(); + + ParserEntityResolverTest a_ParserEntityResolverTest = + new ParserEntityResolverTest(); + a_ParserEntityResolverTest.testResolver(); + + supplementaryNotifications a_supplementaryNotifications = + new supplementaryNotifications(); + a_supplementaryNotifications.testHTMLParsing(); + + TagElement_Test a_TagElement_Test = new TagElement_Test(); + a_TagElement_Test.testTagElement(); + + textPreProcessor_Test a_textPreProcessor_Test = + new textPreProcessor_Test(); + a_textPreProcessor_Test.testStandardPreProcessing(); + a_textPreProcessor_Test.testPreFormattedPreProcessing(); + + Text a_Text = new Text(); + a_Text.testTextParsing(); + + Token_locations a_Token_locations = new Token_locations(); + a_Token_locations.testHTMLParsing(); + } + catch (Exception ex) + { + System.err.println("The tests have FAILED.\nPlease either correct your " + + "changes\nor, if you are absolutely sure, correct the tests.\n" + + "See the following exception for details" + ); + ex.printStackTrace(System.err); + System.exit(1); + } + System.out.println("HTML parser tests have passed."); + System.exit(0); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/HTML_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/HTML_Test.java new file mode 100644 index 0000000..60247fd --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/HTML_Test.java @@ -0,0 +1,130 @@ +/* HTML_Test.java -- HTML parser test. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html; + +import test.gnu.javax.swing.text.html.parser.TestCase; + +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.html.HTML; + +public class HTML_Test + extends TestCase +{ + /** + * By the language definition, HTML tags and attributes are case + * insensitive. Hence if it is not clearly specified, in which case + * the tag name must be, it should be expected to come as in + * lowercase, as in uppercase. This should be true for HTML.getTag(String) + * and for HTML.getAttributeKey(String). + * + * In some implementations these two functions may be case sensitive. + * As this requirement is not mentioned in the documentation, + * and also it is not documented, in which case the name must be supplied, + * this will be reported as an error in this test. + * The GNU CLASSPATH implementation is case insensitive. + */ + public void testCaseSensitivity() + { + String def = "case sensitivity"; + assertEquals("html=Html", HTML.getTag("html"), HTML.getTag("HtmL")); + assertEquals("html=HTML", HTML.getTag("html"), HTML.getTag("HTML")); + assertEquals("size=SIZE", HTML.getAttributeKey("size"), + HTML.getAttributeKey("SIZE") + ); + assertEquals("size=SizE", HTML.getAttributeKey("size"), + HTML.getAttributeKey("SizE") + ); + } + + public void testConstructor() + { + new HTML(); + } + + public void testGetAttributeKey() + { + // Test the known tags. + String[] mine = toStrings(HTML.getAllAttributeKeys()); + + for (int i = 0; i < mine.length; i++) + assertNotNull(mine [ i ], HTML.getAttributeKey(mine [ i ])); + + // Test the unknown tag. + assertNull("surely unknown", HTML.getTag("audrius")); + } + + public void testGetIntegerAttributeValue() + { + SimpleAttributeSet ase = new SimpleAttributeSet(); + ase.addAttribute(HTML.getAttributeKey("size"), "222"); + assertEquals(222, + HTML.getIntegerAttributeValue(ase, + HTML.getAttributeKey("size"), 333 + ) + ); + + assertEquals(333, + HTML.getIntegerAttributeValue(ase, + HTML.getAttributeKey("href"), 333 + ) + ); + } + + public void testGetTag() + { + // known tags: + String[] mine = toStrings(HTML.getAllTags()); + + for (int i = 0; i < mine.length; i++) + assertNotNull(mine [ i ], HTML.getTag(mine [ i ])); + + // unknown tag + assertNull("surely unknown", HTML.getTag("audrius")); + } + + private String[] toStrings(Object[] objs) + { + String[] a = new String[ objs.length ]; + + for (int i = 0; i < a.length; i++) + a [ i ] = objs [ i ].toString(); + + return a; + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/AttributeList_test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/AttributeList_test.java new file mode 100644 index 0000000..3166277 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/AttributeList_test.java @@ -0,0 +1,68 @@ +/* AttributeList_test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import javax.swing.text.html.parser.AttributeList; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class AttributeList_test + extends TestCase +{ + private AttributeList attributeList = null; + + public void testSame() + { + for (int i = 0; i < 100; i++) + { + String t = AttributeList.type2name(i); + if (t != null) + assertEquals(i, AttributeList.name2type(t)); + } + } + + protected void setUp() + throws Exception + { + super.setUp(); + attributeList = new AttributeList("ku"); + assertEquals(attributeList.toString(), "ku"); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/DTD_test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/DTD_test.java new file mode 100644 index 0000000..b204a02 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/DTD_test.java @@ -0,0 +1,102 @@ +/* DTD_test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import javax.swing.text.html.HTML; +import javax.swing.text.html.parser.DTD; +import javax.swing.text.html.parser.Element; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class DTD_test + extends TestCase +{ + static class D + extends DTD + { + public D() + { + super("audrius"); + } + + public Element createElement(String n) + { + return getElement(n); + } + } + + public void testGetElement() + { + D d = new D(); + HTML.Tag[] tags = HTML.getAllTags(); + + Element prehead = d.createElement("head"); + + for (int i = 0; i < tags.length; i++) + { + Element e = d.createElement(tags [ i ].toString()); + String name = tags [ i ].toString(); + assertNotNull("Element creation", e); + assertTrue("Element name", e.getName().equalsIgnoreCase(name)); + } + + // Test upper/lowercase + Element e = d.createElement("head"); + + assertNotNull("Element creation", e); + assertTrue("Element name", e.getName().equalsIgnoreCase("head")); + assertEquals(HTML.Tag.HEAD, HTML.getTag(e.name)); + assertEquals("Field assignment", d.head, e); + + assertEquals(prehead, e); + } + + protected void setUp() + throws Exception + { + super.setUp(); + } + + protected void tearDown() + throws Exception + { + super.tearDown(); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Element_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Element_Test.java new file mode 100644 index 0000000..039be4a --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Element_Test.java @@ -0,0 +1,117 @@ +/* Element_Test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import javax.swing.text.html.parser.AttributeList; +import javax.swing.text.html.parser.DTD; +import javax.swing.text.html.parser.DTDConstants; +import javax.swing.text.html.parser.Element; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Element_Test + extends TestCase +{ + private Element element = null; + + public void testAttributeGetter() + throws Exception + { + // Create a chain of 24 attributes: + AttributeList list = new AttributeList("heading"); + AttributeList head = list; + list.value = null; + for (int i = 0; i < 24; i++) + { + AttributeList a = new AttributeList("a" + i); + a.value = "v" + i; + list.next = a; + list = a; + } + + Element e = DTD.getDTD("test").getElement("e"); + e.atts = head; + + for (int i = 0; i < 24; i++) + { + // Check if the name is found. + assertEquals(e.getAttribute("a" + i).toString(), "a" + i); + + // Check if the attribute value is correct. + assertEquals(e.getAttribute("a" + i).value, "v" + i); + + // Check if the attribute can be found by value. + assertEquals(e.getAttributeByValue("v" + i).name, "a" + i); + } + + // Check is the null value is searched correctly. + assertEquals(e.getAttributeByValue(null).toString(), "heading"); + + // Check for unknown attribute + assertEquals(e.getAttribute("audrius"), null); + + // Check for unknown value + assertEquals(e.getAttributeByValue("audrius"), null); + } + + public void testName2type() + { + assertEquals(Element.name2type("CDATA"), DTDConstants.CDATA); + assertEquals(Element.name2type("RCDATA"), DTDConstants.RCDATA); + assertEquals(Element.name2type("EMPTY"), DTDConstants.EMPTY); + assertEquals(Element.name2type("ANY"), DTDConstants.ANY); + + assertEquals(Element.name2type("audrius"), 0); + assertEquals(Element.name2type("rcdata"), 0); + } + + protected void setUp() + throws Exception + { + super.setUp(); + } + + protected void tearDown() + throws Exception + { + element = null; + super.tearDown(); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Entity_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Entity_Test.java new file mode 100644 index 0000000..b9fd21c --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Entity_Test.java @@ -0,0 +1,119 @@ +/* Entity_Test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import javax.swing.text.html.parser.DTDConstants; +import javax.swing.text.html.parser.Element; +import javax.swing.text.html.parser.Entity; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Entity_Test + extends TestCase +{ + private Element element = null; + + public void testName2type() + { + assertEquals("PUBLIC", Entity.name2type("PUBLIC"), DTDConstants.PUBLIC); + assertEquals("SDATA", Entity.name2type("SDATA"), DTDConstants.SDATA); + assertEquals("PI", Entity.name2type("PI"), DTDConstants.PI); + assertEquals("STARTTAG", Entity.name2type("STARTTAG"), DTDConstants.STARTTAG); + assertEquals("ENDTAG", Entity.name2type("ENDTAG"), DTDConstants.ENDTAG); + assertEquals("MS", Entity.name2type("MS"), DTDConstants.MS); + assertEquals("MD", Entity.name2type("MD"), DTDConstants.MD); + assertEquals("SYSTEM", Entity.name2type("SYSTEM"), DTDConstants.SYSTEM); + + assertEquals("surely unknown ", Entity.name2type("audrius"), + DTDConstants.CDATA + ); + } + + public void testPublicSystemGeneralParameter() + { + int[] pu_sy = new int[] { DTDConstants.PUBLIC, DTDConstants.SYSTEM, 0 }; + + int[] gen_par = + new int[] { DTDConstants.GENERAL, DTDConstants.PARAMETER, 0 }; + + for (int ps = 0; ps < pu_sy.length; ps++) + { + for (int gp = 0; gp < gen_par.length; gp++) + { + Entity e = new Entity(null, 0, null); + e.type = pu_sy [ ps ] | gen_par [ gp ]; + + assertEquals(e.isGeneral(), gen_par [ gp ] == DTDConstants.GENERAL); + assertEquals(e.isParameter(), + gen_par [ gp ] == DTDConstants.PARAMETER + ); + + assertEquals((e.type & DTDConstants.SYSTEM) != 0, + pu_sy [ ps ] == DTDConstants.SYSTEM + ); + + assertEquals((e.type & DTDConstants.PUBLIC) != 0, + pu_sy [ ps ] == DTDConstants.PUBLIC + ); + + assertEquals((e.type & DTDConstants.GENERAL) != 0, + gen_par [ gp ] == DTDConstants.GENERAL + ); + + assertEquals((e.type & DTDConstants.PARAMETER) != 0, + gen_par [ gp ] == DTDConstants.PARAMETER + ); + } + } + } + + protected void setUp() + throws Exception + { + super.setUp(); + } + + protected void tearDown() + throws Exception + { + element = null; + super.tearDown(); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_parsing.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_parsing.java new file mode 100644 index 0000000..3072385 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_parsing.java @@ -0,0 +1,281 @@ +/* HTML_parsing.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class HTML_parsing + extends TestCase +{ + /** + * This is used for profiling. + */ + public static void main(String[] args) + { + long t = System.currentTimeMillis(); + try + { + HTML_parsing p = new HTML_parsing(); + for (int i = 0; i < 2000; i++) + { + p.testHTMLParsing(); + if (i % 10 == 0) + System.out.print('.'); + } + } + catch (Exception ex) + { + } + System.out.println("TIME " + (System.currentTimeMillis() - t)); + } + + public void testHTMLParsing() + throws Exception + { + Parser_Test v = new Parser_Test(); + v.hideImplied = false; + + // Test subsequent tags. + v.verify("text", + "'text'" + ); + + // Test entities. + v.verify("hex: U eqdec: = ampnamed: &", + "'hex: U eqdec: = ampnamed: &'" + ); + + // Test comments. + v.verify("< !--b--> ", + "{a}{b}{c}{ d}{e }{f}{g}{-h-}{ i }{- j -}{ -- }{------}" + ); + + // Test unclosed tags. + v.verify("
", + "

" + ); + + // Test errors and unclosed tags. + v.verify("
", + "
'# class = c'
" + ); + + // Test script. + v.verify("

", + "

" + ); + + // Test valid attributes. + v.verify("


", + "


" + ); + + // Test unknown attribute without value. + v.verify("
", + "
" + ); + + // Test known attributes witout value. + v.verify("" + ); + + // Test table content model. + v.verify("a
", + "
'a'
" + ); + + // Test table content model. + v.verify("a
cap
", + "
'cap'
'a'
" + ); + + // Test typical table. + v.verify("
xyz
", + "
'x''y''z'
" + ); + + // Test nested table. + v.verify("
nested
x
yz
", + "
'nested'
'x'
'y''z'
" + ); + + // Test simple nested list. + v.verify("
  • a
    • na
    • nb
  • b
", + "
  • 'a'
    • 'na'
    • 'nb'
  • 'b'
" + ); + + // Test simple non-nested list. + v.verify("
  • a
  • na
  • nb
  • b
", + "
  • 'a'
  • 'na'
  • 'nb'
  • 'b'
" + ); + + // Test list without closing tags (obsolete list form). + v.verify("
  • a
  • na
  • nb
  • b
", + "
  • 'a'
  • 'na'
  • 'nb'
  • 'b'
" + ); + + // Test list without closing tags (obsolete list form). + v.verify("
  • a
    • na
    • nb
  • b
", + "
  • 'a'
    • 'na'
    • 'nb'
  • 'b'
" + ); + + // Test Obsolete table. + v.verify("", + "
abc
'a''b''c'
" + ); + + // Test html no head no body. + v.verify("text", + "'text'" + ); + + // Test head only. + v.verify("text", + "'text'" + ); + + // Test head and body. + v.verify("titext", + "'ti''text'" + ); + + // Test title and text. + v.verify("titletext", + "'title''text'" + ); + + // Test html only. + v.verify("text", + "'text'" + ); + + // Test body only. + v.verify("text", + "'text'" + ); + + // Test head only. + v.verify("text", + "'text'" + ); + + // Test obsolete table. + v.verify("", + "
a
a
'a'
'a'
" + ); + + // Test obsolete table. + v.verify("
ab
abc", + "
'a''b'
'a''b''c'
" + ); + + // Test style. + v.verify("
", + "
" + ); + + // Test style. + v.verify("x", + "'x'" + ); + + // Test entities in attributes. + v.verify("
", + "
" + ); + + // Test colgroup. + v.verify("x", + "
ab
'a''b'
'x'
" + ); + + // Test definition list, obsolete. + v.verify("
ha
a
hb
b", + "
'ha'
'a'
'hb'
'b'
" + ); + + // Test definition list. + v.verify("
'ha'
'a'
'hb'
'b'
", + "
''ha''
''a''
''hb''
''b''
" + ); + + // Test paragraphs. + v.verify("

b

c

d", + "

'b'

'c'

'd'

" + ); + + // Test paragraphs. + v.verify("

'b'

'c'

'd'

", + "

''b''

''c''

''d''

" + ); + + // Test select obsolete. + v.verify("
" + ); + + // Test select current. + v.verify("
", + "
" + ); + + // Test select current. + v.verify("
", + "
" + ); + + // Test << antihang. + v.verify("<text", + "'<''text'" + ); + + // Test << antihang with spaces. + v.verify(" < < i>text", + "'<''text'" + ); + + // Test Standalone <. + v.verify("Text text ", + "'Text'''text'" + ); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_randomTable.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_randomTable.java new file mode 100644 index 0000000..d7a52b5 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_randomTable.java @@ -0,0 +1,155 @@ +/* HTML_randomTable.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import java.util.Random; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class HTML_randomTable + extends TestCase +{ + class table + { + final String[][] rows; + final boolean caption = r.nextBoolean(); + + table() + { + int nrows = r.nextInt(5) + 1; + rows = new String[ nrows ][]; + for (int i = 0; i < rows.length; i++) + { + int ncol = r.nextInt(5) + 1; + rows [ i ] = new String[ ncol ]; + for (int j = 0; j < rows [ i ].length; j++) + { + rows [ i ] [ j ] = "C_" + i + "_" + j; + } + } + } + + public String getHtml() + { + StringBuffer b = new StringBuffer(""); + if (caption) + b.append(""); + if (r.nextBoolean()) + b.append("<" + s() + "tbody" + s() + ">"); + for (int row = 0; row < rows.length; row++) + { + b.append("<" + s() + "tr" + s() + ">"); + for (int col = 0; col < rows [ row ].length; col++) + { + b.append("<" + s() + "td" + s() + ">"); + b.append(rows [ row ] [ col ]); + if (r.nextBoolean()) + b.append("<" + s() + "/" + "td" + s() + ">"); + } + if (r.nextBoolean()) + b.append("<" + s() + "/" + "tr" + s() + ">"); + } + b.append("
capt
"); + return b.toString(); + } + + public String getTrace() + { + StringBuffer b = new StringBuffer(""); + if (caption) + b.append(""); + b.append(""); + for (int row = 0; row < rows.length; row++) + { + b.append(""); + for (int col = 0; col < rows [ row ].length; col++) + { + b.append(""); + } + b.append(""); + } + b.append("
'capt'
'" + rows [ row ] [ col ] + "'
"); + return b.toString(); + } + + void test() + throws Exception + { + String trace = getTrace(); + String html = getHtml(); + v.verify(html, trace); + } + } + + Parser_Test v = new Parser_Test(); + Random r = new Random(); + + public HTML_randomTable() + throws Exception + { + } + + public String s() + { + if (r.nextBoolean()) + return ""; + + StringBuffer b = new StringBuffer(); + int spc = r.nextInt(4); + for (int i = 0; i < spc; i++) + { + b.append(' '); + } + return b.toString(); + } + + /** + * Try 1001 variable randomly generated table. + */ + public void testTableParsing() + throws Exception + { + v.hideImplied = true; + for (int i = 0; i < 1001; i++) + { + new table().test(); + } + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserEntityResolverTest.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserEntityResolverTest.java new file mode 100644 index 0000000..414aadc --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserEntityResolverTest.java @@ -0,0 +1,99 @@ +/* ParserEntityResolverTest.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import gnu.javax.swing.text.html.parser.HTML_401F; +import gnu.javax.swing.text.html.parser.support.Parser; + +import java.lang.reflect.Method; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ParserEntityResolverTest + extends TestCase +{ + /* Testing private methods of entity resolver. */ + public void testResolver() + throws Exception + { + Parser p = + new Parser(HTML_401F.getInstance()) + { + public void error(String a, String b) + { + } + }; + + Method rn = + p.getClass().getSuperclass().getDeclaredMethod("resolveNamedEntity", + new Class[] { String.class } + ); + rn.setAccessible(true); + + assertEquals(exe(p, rn, "&"), "&"); + assertEquals(exe(p, rn, "&"), "&"); + assertEquals(exe(p, rn, "&"), "&"); + assertEquals(exe(p, rn, "&amP"), "&"); + + assertEquals(exe(p, rn, "&;"), "&;"); + assertEquals(exe(p, rn, "&audrius;"), "&audrius;"); + + rn = + p.getClass().getSuperclass().getDeclaredMethod("resolveNumericEntity", + new Class[] { String.class } + ); + rn.setAccessible(true); + + assertEquals(exe(p, rn, "U"), "U"); + assertEquals(exe(p, rn, "U"), "U"); + assertEquals(exe(p, rn, "="), "="); + assertEquals(exe(p, rn, "="), "="); + + assertEquals(exe(p, rn, "&#audrius"), "?"); + } + + private String exe(Parser p, Method m, String arg) + throws Exception + { + Object[] o = new Object[ 1 ]; + o [ 0 ] = arg; + return m.invoke(p, o).toString(); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserTest.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserTest.java new file mode 100644 index 0000000..af12cbb --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserTest.java @@ -0,0 +1,150 @@ +/* ParserTest.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import gnu.javax.swing.text.html.parser.support.Parser; + +import java.io.PrintStream; + +import java.util.Enumeration; + +import javax.swing.text.AttributeSet; +import javax.swing.text.html.parser.Element; +import javax.swing.text.html.parser.TagElement; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ParserTest + extends gnu.javax.swing.text.html.parser.support.Parser +{ + PrintStream out = System.out; + StringBuffer errors = new StringBuffer(); + + public ParserTest() + { + super(gnu.javax.swing.text.html.parser.HTML_401F.getInstance()); + } + + public static void main(String[] args) + { + String sx; + sx = + "< tbody>< td >C_0_0< td>C_0_1< td >C_0_2< /td >< td >C_0_3
C_0_4< /td>
"; + try + { + System.out.println(sx); + + ParserTest t = new ParserTest(); + t.parse(new java.io.StringReader(sx)); + System.out.println("\nErrors:"); + System.out.println(t.errors); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + protected void handleComment(char[] parm1) + { + out.print("{" + new String(parm1) + "}"); + } + + protected void handleEOFInComment() + { + out.print(" [EOF in comment] "); + } + + protected void handleEmptyTag(TagElement tag) + throws javax.swing.text.ChangedCharSetException + { + out.print("<" + tag); + + javax.swing.text.AttributeSet atts = getAttributes(); + dumpAttributes(atts); + out.print("/>"); + } + + protected void handleEndTag(TagElement tag) + { + out.print(" "); + } + + protected void handleError(int line, String message) + { + errors.append(message); + errors.append('\n'); + } + + protected void handleStartTag(TagElement tag) + { + out.print("<" + tag); + + javax.swing.text.AttributeSet atts = getAttributes(); + dumpAttributes(atts); + out.print('>'); + } + + protected void handleText(char[] parm1) + { + out.print("'" + new String(parm1) + "'"); + } + + protected void handleTitle(char[] parm1) + { + out.print(" [ Title: " + new String(parm1) + "] "); + } + + protected void markFirstTime(Element element) + { + out.print("(1:" + element + ")"); + } + + private void dumpAttributes(AttributeSet atts) + { + Enumeration enum = atts.getAttributeNames(); + while (enum.hasMoreElements()) + { + String a = enum.nextElement().toString(); + String v = (String) atts.getAttribute(a); + out.print(" " + a + "='" + v + "'"); + } + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Parser_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Parser_Test.java new file mode 100644 index 0000000..c3ba38a --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Parser_Test.java @@ -0,0 +1,162 @@ +/* Parser_Test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + + +package test.gnu.javax.swing.text.html.parser; + +import java.io.StringReader; + +import java.util.Enumeration; +import java.util.Iterator; +import java.util.TreeSet; + +import javax.swing.text.AttributeSet; +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.html.HTML; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.text.html.HTMLEditorKit.ParserCallback; +import javax.swing.text.html.parser.ParserDelegator; +import javax.swing.text.html.parser.TagElement; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Parser_Test + extends HTMLEditorKit.ParserCallback +{ + public boolean hideImplied = true; + protected StringBuffer out = new StringBuffer(); + AttributeSet atts = new SimpleAttributeSet(); + + public void generate(String x, String comment) + throws Exception + { + String prolog = ""; + String epilog = ""; + String html = x; // prolog+x+epilog; + System.out.println("// Test " + comment + "."); + System.out.println("v.verify(\"" + html + "\",\n \"" + verify(html, null) + + "\");" + ); + } + + public void handleComment(char[] parm1, int position) + { + out.append("{" + new String(parm1) + "}"); + } + + public void handleEndTag(HTML.Tag tag, int position) + { + out.append(""); + } + + public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet attributes, + int position + ) + { + if (tag.toString().equals("#pcdata")) + return; + out.append("<" + tag); + dumpAttributes(attributes); + out.append("/>"); + } + + public void handleStartTag(HTML.Tag tag, MutableAttributeSet attributes, + int position + ) + { + out.append("<" + tag); + dumpAttributes(attributes); + out.append('>'); + } + + public void handleText(char[] chars, int position) + { + out.append("'" + new String(chars) + "'"); + } + + public String verify(String html, String trace) + throws Exception + { + out.setLength(0); + + HTMLEditorKit.ParserCallback callback = this; + ParserDelegator delegator = new ParserDelegator(); + delegator.parse(new StringReader(html), callback, true); + + String ou = out.toString(); + if (trace != null) + { + if (!ou.equals(trace)) + { + System.err.println("Unable to parse '" + html + "':"); + System.err.println(" expected: '" + trace + "',"); + System.out.println(" returned: '" + ou + "'."); + throw new Exception("'" + html + "' -> '" + ou + "' expected '" + + trace + "'" + ); + } + } + return ou; + } + + protected void dumpAttributes(AttributeSet atts) + { + Enumeration enum = atts.getAttributeNames(); + + // Sort them to ensure the same order every time: + TreeSet t = new TreeSet(); + while (enum.hasMoreElements()) + t.add(enum.nextElement().toString()); + + Iterator iter = t.iterator(); + + while (iter.hasNext()) + { + String a = iter.next().toString(); + + if (hideImplied) + if (a.equals("_implied_")) + continue; + + String v = atts.getAttribute(a).toString(); + out.append(" " + a + "='" + v + "'"); + } + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TagElement_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TagElement_Test.java new file mode 100644 index 0000000..12c07cf --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TagElement_Test.java @@ -0,0 +1,87 @@ +/* TagElement_Test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import javax.swing.text.html.HTML; +import javax.swing.text.html.parser.DTD; +import javax.swing.text.html.parser.Element; +import javax.swing.text.html.parser.TagElement; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class TagElement_Test + extends TestCase +{ + public void testTagElement() + throws Exception + { + HTML.Tag[] tags = HTML.getAllTags(); + + for (int i = 0; i < tags.length; i++) + { + HTML.Tag t = tags [ i ]; + String tn = t.toString(); + Element e = DTD.getDTD("test").getElement("e"); + e.name = tn; + + TagElement te = new TagElement(e, true); + assertTrue(" must be fictional", te.fictional()); + + te = new TagElement(e); + assertFalse("must be non fictional", te.fictional()); + + assertEquals(te.getHTMLTag().toString(), t.toString()); + assertEquals(t.breaksFlow(), te.breaksFlow()); + assertEquals(t.isPreformatted(), te.isPreformatted()); + } + } + + protected void setUp() + throws Exception + { + super.setUp(); + } + + protected void tearDown() + throws Exception + { + super.tearDown(); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TestCase.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TestCase.java new file mode 100644 index 0000000..84c1603 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TestCase.java @@ -0,0 +1,138 @@ +/* TestCase.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class TestCase +{ + public TestCase() + { + try + { + setUp(); + } + catch (Exception ex) + { + throw new RuntimeException(ex); + } + } + + public void assertEquals(String msg, Object a, Object b) + { + if (a == b) + return; + if (!a.equals(b)) + throw new RuntimeException(msg); + } + + public void assertEquals(Object a, Object b) + { + if (a == b) + return; + if (!a.equals(b)) + throw new RuntimeException("Objects must be equal"); + } + + public void assertEquals(int a, int b) + { + if (a != b) + throw new RuntimeException(a + "!=" + b); + } + + public void assertEquals(String msg, int a, int b) + { + if (a != b) + throw new RuntimeException(msg + ":" + a + "!=" + b); + } + + public void assertEquals(boolean a, boolean b) + { + if (a != b) + throw new RuntimeException(a + "!=" + b); + } + + public void assertFalse(String msg, boolean a) + { + if (a) + throw new RuntimeException(msg); + } + + public void assertFalse(boolean a) + { + if (a) + throw new RuntimeException("Must be false"); + } + + public void assertNotNull(String msg, Object a) + { + if (a == null) + throw new RuntimeException(msg); + } + + public void assertNull(String msg, Object a) + { + if (a != null) + throw new RuntimeException(msg); + } + + public void assertTrue(String msg, boolean a) + { + if (!a) + throw new RuntimeException(msg); + } + + public void assertTrue(boolean a) + { + if (!a) + throw new RuntimeException("Must be true"); + } + + protected void setUp() + throws Exception + { + } + + protected void tearDown() + throws Exception + { + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Text.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Text.java new file mode 100644 index 0000000..9fe592a --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Text.java @@ -0,0 +1,155 @@ +/* Text.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.html.HTML; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Text + extends TestCase +{ + public void testTextParsing() + throws Exception + { + Parser_Test v = + new Parser_Test() + { + public void handleSimpleTag(HTML.Tag tag, + MutableAttributeSet attributes, int position + ) + { + if (!tag.toString().equalsIgnoreCase("#pcdata")) + out.append("<" + tag + ">"); + } + + public void handleStartTag(HTML.Tag tag, + MutableAttributeSet attributes, int position + ) + { + out.append("<" + tag + ">"); + } + + public void handleText(char[] chars, int position) + { + for (int i = 0; i < chars.length; i++) + { + out.append(Integer.toHexString(chars [ i ])); + if (chars [ i ] > ' ') + out.append("'" + chars [ i ]); + out.append(" "); + } + } + + public void handleEndTag(HTML.Tag tag, int position) + { + out.append(""); + } + }; + + v.hideImplied = true; + + // NON - preformatted mode: + // Everything mutates into spaces, multiple spaces mustates + // into single one, all whitespace around tags is consumed. + v.verify("\r \n \t {abc r\rn\nt}\t \r\n \r \t", + "7b'{ 61'a 62'b 63'c 20 72'r 20" + + " 6e'n 20 74't 7d'} " + ); + + v.verify(" abba ", + "61'a 62'b 62'b 61'a " + ); + + v.verify(" \r ab \t \r \n ba ", + "61'a 62'b 20 62'b 61'a " + ); + + // Preformatted mode (in PRE tag): + // Heading/closing spaces and tabs preserve. ONE \r, \n or \r\n is removed. + // /r mutates into \n + v.verify("
\n\n\n\n   abba   \r\t \r\n
", + "
a a a 20 20 20 61'a 62'b 62'b" +
+             " 61'a 20 20 20 a 9 20 
" + ); + + v.verify("
   abba   
", + "
20 20 20 61'a 62'b 62'b 61'a 20 " +
+             "20 20 
" + ); + + v.verify("
\r\n   abba   
", + "
20 20 20 61'a 62'b 62'b 61'a 20 " +
+             "20 20 
" + ); + + v.verify("
\r\n\r\n   abba   \r\n
", + "
a 20 20 20 61'a 62'b 62'b 61'a 20 20" +
+             " 20 
" + ); + + v.verify("
 \r ab  \t \r \n  ba   
", + "
20 a 20 61'a 62'b 20 20 9 20 a" +
+             " 20 a 20 20 62'b 61'a 20 20 20 
" + ); + + v.verify("
 \r\n ab  \t \r\n \n  ba   
", + "
20 a 20 61'a 62'b 20 20 9 20 a" +
+             " 20 a 20 20 62'b 61'a 20 20 20 
" + ); + + // In TEXTAREA tag, same. + v.verify("", + "" + ); + + v.verify("", + "" + ); + + v.verify("", + "" + ); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Token_locations.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Token_locations.java new file mode 100644 index 0000000..8cbcaad --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Token_locations.java @@ -0,0 +1,124 @@ +/* Token_locations.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.html.HTML; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Token_locations + extends TestCase +{ + public void testHTMLParsing() + throws Exception + { + Parser_Test v = + new Parser_Test() + { + public void handleSimpleTag(HTML.Tag tag, + MutableAttributeSet attributes, int position + ) + { + if (tag.toString().equals("#pcdata")) + return; + out.append("<" + tag + "[" + position + "]"); + dumpAttributes(attributes); + out.append("/>"); + } + + public void handleStartTag(HTML.Tag tag, + MutableAttributeSet attributes, int position + ) + { + if (tag.toString().equalsIgnoreCase("tbody")) + return; + out.append("<" + tag + "[" + position + "]"); + dumpAttributes(attributes); + out.append('>'); + } + + public void handleText(char[] chars, int position) + { + out.append("'" + new String(chars) + "[" + position + "]'"); + } + + public void handleEndTag(HTML.Tag tag, int position) + { + if (tag.toString().equalsIgnoreCase("tbody")) + return; + out.append(""); + } + + public void handleComment(char[] parm1, int position) + { + out.append("{" + new String(parm1) + "[" + position + "]}"); + } + }; + + v.hideImplied = true; + + // 0123456789012345678901234567890 + v.verify("", + "" + + "'a[15]''b[20]'" + + "'c[25]'" + + "" + ); + + // 0123456789012345678901234567890 + v.verify("ab", + "'a[0]'{ comment [1]}'b[17]'" + + "{ comment2 [18]}" + ); + + // 012345678901234567 + v.verify("

b

c

d", + "'b[3]''" + + "c[7]''d[11]'" + ); + + // Test SGML + v.verify("sgml", + "" + + "'sgml[23]'" + ); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Buffer_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Buffer_Test.java new file mode 100644 index 0000000..49d86c6 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Buffer_Test.java @@ -0,0 +1,67 @@ +/* Buffer_Test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser.low; + +import test.gnu.javax.swing.text.html.parser.TestCase; + +import gnu.javax.swing.text.html.parser.support.low.Buffer; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Buffer_Test + extends TestCase +{ + public void testAppend() + { + Buffer.INITIAL_SIZE = 2; + + Buffer b = new Buffer("01"); + b.append('A', 0); + b.append('B', 0); + assertEquals(b.toString(), "01AB"); + } + + public void testDelete() + { + Buffer b = new Buffer("0123456789ABCDEFGHIJKLMN"); + b.delete(2, 7); + assertEquals(b.toString(), "01789ABCDEFGHIJKLMN"); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Constants_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Constants_Test.java new file mode 100644 index 0000000..4f463d1 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Constants_Test.java @@ -0,0 +1,89 @@ +/* Constants_Test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser.low; + +import test.gnu.javax.swing.text.html.parser.TestCase; + +import gnu.javax.swing.text.html.parser.support.low.Buffer; +import gnu.javax.swing.text.html.parser.support.low.Constants; +import gnu.javax.swing.text.html.parser.support.low.Token; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Constants_Test + extends TestCase +{ + Constants c = new Constants(); + + public void testCases() + { + verify("x stYle ", c.STYLE, "stYle"); + verify("x !style!", c.STYLE, "style"); + verify("x !Script!", c.SCRIPT, "Script"); + verify(" \r\t\n z", c.WS, " \r\t\n "); + verify("123 ", c.NUMTOKEN, "123"); + verify("AaB123#", c.NUMTOKEN, "AaB123"); + verify("x-- ", c.DOUBLE_DASH, "--"); + verify("x--- ", c.DOUBLE_DASH, "--"); + + verify("z&entitu ", c.ENTITY, "&entitu"); + + verifyNull("x stYle"); + verifyNull("x !style"); + verifyNull("x !Script"); + verifyNull(" \r\t\n "); + verifyNull("123"); + verifyNull("AaB123"); + verifyNull("x--"); + } + + public void verify(String sequence, int kind, String image) + { + Token t = c.endMatches(new Buffer(sequence)); + assertEquals(kind, t.kind); + assertEquals(image, t.getImage()); + } + + public void verifyNull(String sequence) + { + Token t = c.endMatches(new Buffer(sequence)); + assertNull("The end should not match any token", t); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/ReaderTokenizer_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/ReaderTokenizer_Test.java new file mode 100644 index 0000000..ebfda42 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/ReaderTokenizer_Test.java @@ -0,0 +1,159 @@ +/* ReaderTokenizer_Test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser.low; + +import test.gnu.javax.swing.text.html.parser.TestCase; + +import gnu.javax.swing.text.html.parser.support.low.Constants; +import gnu.javax.swing.text.html.parser.support.low.ReaderTokenizer; +import gnu.javax.swing.text.html.parser.support.low.Token; +import gnu.javax.swing.text.html.parser.support.low.node; +import gnu.javax.swing.text.html.parser.support.low.pattern; + +import java.io.StringReader; + +import java.util.ArrayList; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ReaderTokenizer_Test + extends TestCase +{ + ReaderTokenizer rt = new ReaderTokenizer(); + + public void testComplexToken() + throws Exception + { + String x = "< style >x"; + + pattern a = + new pattern(new node[] + { + new node(Constants.BEGIN), new node(Constants.NUMTOKEN), + new node(Constants.END), new node(Constants.NUMTOKEN) + } + ); + + pattern b = + new pattern(new node[] + { + new node(Constants.BEGIN), new node(Constants.STYLE), + new node(Constants.END), new node(Constants.NUMTOKEN) + } + ); + + pattern c = + new pattern(new node[] + { + new node(Constants.BEGIN), new node(Constants.WS, true), + new node(Constants.STYLE), new node(Constants.WS, true), + new node(Constants.END), new node(Constants.NUMTOKEN) + } + ); + + pattern d = + new pattern(new node[] + { + new node(Constants.BEGIN), new node(Constants.WS, true), + new node(Constants.STYLE), new node(Constants.WS, true), + new node(Constants.END), new node(Constants.BEGIN) + } + ); + + ReaderTokenizer rt = new ReaderTokenizer(); + rt.reset(new StringReader(x)); + + assertFalse(a.matches(rt)); + assertFalse(b.matches(rt)); + assertTrue(c.matches(rt)); + assertFalse(d.matches(rt)); + } + + public void testReadingAndAhead() + throws Exception + { + ArrayList tokens = new ArrayList(); + StringBuffer b = new StringBuffer(); + for (int i = 0; i < 10; i++) + { + String r = rs(); + b.append(" "); + b.append(r + i); + tokens.add(" "); + tokens.add(r + i); + } + rt.reset(new StringReader(b.toString())); + + for (int i = 0; i < 10; i++) + { + for (int ah = 0; ah < 10; ah++) + { + Token ahead = rt.getTokenAhead(ah); + if (i + ah >= tokens.size()) + { + assertEquals(ahead.kind, rt.EOF); + } + else + { + if ((i + ah) % 2 == 0) + assertEquals(ahead.kind, rt.WS); + else + { + assertEquals(ahead.getImage(), tokens.get(i + ah)); + assertEquals(ahead.kind, rt.NUMTOKEN); + } + } + } + + Token r = rt.getNextToken(); + assertEquals(r.getImage(), tokens.get(i)); + } + } + + private String rs() + { + StringBuffer b = new StringBuffer(); + for (int i = 0; i < 10 * Math.random(); i++) + { + b.append("l"); + } + return b.toString(); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/parameterDefaulter_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/parameterDefaulter_Test.java new file mode 100644 index 0000000..866a7fc --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/parameterDefaulter_Test.java @@ -0,0 +1,92 @@ +/* parameterDefaulter_Test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import gnu.javax.swing.text.html.parser.HTML_401F; +import gnu.javax.swing.text.html.parser.htmlAttributeSet; +import gnu.javax.swing.text.html.parser.support.parameterDefaulter; + +import javax.swing.text.AttributeSet; +import javax.swing.text.html.HTML; +import javax.swing.text.html.HTML.Attribute; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class parameterDefaulter_Test + extends TestCase +{ + parameterDefaulter defaulter; + + public void testDefaultValues() + { + AttributeSet d; + d = defaulter.getDefaultParameters("FrAmE"); + assertEquals(d.getAttribute("scrolling"), "auto"); + d = defaulter.getDefaultParameters("input"); + assertEquals(d.getAttribute("type"), "text"); + + htmlAttributeSet hma = new htmlAttributeSet(); + hma.setResolveParent(d); + hma.addAttribute("ku", "1"); + hma.addAttribute(Attribute.ACTION, "sleep"); + + assertEquals(hma.getAttribute("action"), "sleep"); + assertEquals(hma.getAttribute(Attribute.ACTION), "sleep"); + assertEquals(hma.getAttribute("ku"), "1"); + + // Calling the parent: + assertEquals(hma.getAttribute(Attribute.TYPE), "text"); + + d = defaulter.getDefaultParameters("audrius"); + assertEquals(d.getAttribute("scrolling"), null); + } + + protected void setUp() + { + defaulter = new parameterDefaulter(HTML_401F.getInstance()); + } + + protected void tearDown() + throws java.lang.Exception + { + defaulter = null; + super.tearDown(); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/supplementaryNotifications.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/supplementaryNotifications.java new file mode 100644 index 0000000..d17298f --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/supplementaryNotifications.java @@ -0,0 +1,86 @@ +/* supplementaryNotifications.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import javax.swing.text.MutableAttributeSet; +import javax.swing.text.html.HTML; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class supplementaryNotifications + extends TestCase +{ + String eoln = null; + int flushed = 0; + + public void testHTMLParsing() + throws Exception + { + Parser_Test v = + new Parser_Test() + { + public void handleEndOfLineString(String end_of_line) + { + eoln = end_of_line; + } + + public void flush() + { + flushed++; + } + }; + + v.hideImplied = true; + + v.verify("a \n b", "'a b'"); + + assertEquals(eoln, "\n"); + + v.verify("a \r b", "'a b'"); + + assertEquals(eoln, "\r"); + + v.verify("a \r\n b", "'a b'"); + + assertEquals(eoln, "\r\n"); + + assertEquals(flushed, 3); + } +} diff --git a/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/textPreProcessor_Test.java b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/textPreProcessor_Test.java new file mode 100644 index 0000000..9149c54 --- /dev/null +++ b/libjava/classpath/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/textPreProcessor_Test.java @@ -0,0 +1,150 @@ +/* textPreProcessor_Test.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath 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. + +GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package test.gnu.javax.swing.text.html.parser; + +import gnu.javax.swing.text.html.parser.support.textPreProcessor; + +/** + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class textPreProcessor_Test + extends TestCase +{ + textPreProcessor p = new textPreProcessor(); + + public void testPreFormattedPreProcessing() + { + verifyF("rnrn...r.n.Q.Q.r.n.rn.Q...r.r.rn", "n...n.n.Q.Q.n.n.n.Q...n.n."); + verifyF("...r.n.Q.Q.r.n.rn.Q...r.r.n", "...n.n.Q.Q.n.n.n.Q...n.n."); + verifyF("r...r.n.Q.Q.r.n.rn.Q...r.r.n", "...n.n.Q.Q.n.n.n.Q...n.n."); + verifyF("Q", "Q"); + verifyF(".", "."); + verifyF("abc..\t..xyz", "abc..\t..xyz"); + verifyF("abcxyz", "abcxyz"); + } + + public void testStandardPreProcessing() + { + verifyS("...r.n.Q.Q.r.n.rn.Q...r.r.n", "Q.Q.Q"); + verifyS("r...r.n.Q.Q.r.n.rn.Q...r.r.n", "Q.Q.Q"); + verifyS("Q", "Q"); + verifyS(" ", null); + verifyS(" \r\n", null); + verifyS("abc..\t..xyz", "abc.xyz"); + verifyS("abcxyz", "abcxyz"); + } + + StringBuffer fromText(String x) + { + StringBuffer b = new StringBuffer(); + char c; + for (int i = 0; i < x.length(); i++) + { + c = x.charAt(i); + + if (c == 'n') + b.append('\n'); + else if (c == 'r') + b.append('\r'); + else if (c == '.') + b.append(' '); + else + b.append(c); + } + return b; + } + + StringBuffer toText(String x) + { + StringBuffer b = new StringBuffer(); + char c; + for (int i = 0; i < x.length(); i++) + { + c = x.charAt(i); + + if (c == '\n') + b.append('n'); + else if (c == '\r') + b.append('r'); + else if (c == ' ') + b.append('.'); + else + b.append(c); + } + return b; + } + + void verifyF(String text, String result) + { + char[] pp = p.preprocessPreformatted(fromText(text)); + + if (result == null && pp == null) + return; + + String processed = new String(pp); + + processed = toText(processed).toString(); + + if (!processed.equals(result)) + { + System.err.println(result); + System.out.println(processed); + } + assertEquals(text, result, processed); + } + + void verifyS(String text, String result) + { + char[] pp = p.preprocess(fromText(text)); + + if (result == null && pp == null) + return; + + String processed = new String(pp); + + processed = toText(processed).toString(); + + if (!processed.equals(result)) + { + System.err.println(result); + System.out.println(processed); + } + assertEquals(text, result, processed); + } +} -- cgit v1.1

abc