diff options
22 files changed, 2726 insertions, 1 deletions
@@ -1,4 +1,50 @@ -2005-03-05 Audrius Meskauskas <audriusa@bluewin.ch> +2005-03-10 Audrius Meskauskas <audriusa@bluewin.ch> + + * testsuite\javax.swing.text.html.parser\ + AllParserTests.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\HTML_Test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\AttributeList_test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\DTD_test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\Element_Test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\Entity_Test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\HTML_parsing.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\HTML_randomTable.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\parameterDefaulter_Test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\Parser_Test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\ParserEntityResolverTest.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\ParserTest.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\supplementaryNotifications.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\TagElement_Test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\TestCase.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\Text.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\textPreProcessor_Test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\Token_locations.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\low\Buffer_Test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\low\Constants_Test.java, + testsuite\javax.swing.text.html.parser\ + test\gnu\javax\swing\text\html\parser\low\ReaderTokenizer_Test.java: + New Classpath specific tests for the parser classes in gnu namespace. + +2005-03-10 Audrius Meskauskas <audriusa@bluewin.ch> * javax/swing/text/ChangedCharSetException.java, javax/swing/text/html/HTMLEditorKit.java, diff --git a/testsuite/javax.swing.text.html.parser/AllParserTests.java b/testsuite/javax.swing.text.html.parser/AllParserTests.java new file mode 100644 index 000000000..8e9413a6d --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/HTML_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/HTML_Test.java new file mode 100644 index 000000000..7a0220c05 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/AttributeList_test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/AttributeList_test.java new file mode 100644 index 000000000..02d174dba --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/DTD_test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/DTD_test.java new file mode 100644 index 000000000..d539fff75 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Element_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Element_Test.java new file mode 100644 index 000000000..355d9384e --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Entity_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Entity_Test.java new file mode 100644 index 000000000..ff1dc118d --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_parsing.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_parsing.java new file mode 100644 index 000000000..6f81c23ee --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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("<b><i><u>text</b><i></u>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><b><i><u>'text'</b><i></u></i></i></body></html>" + ); + + // Test entities. + v.verify("hex: U eqdec: = ampnamed: &", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'hex: U eqdec: = ampnamed: &'</body></html>" + ); + + // Test comments. + v.verify("<html><head></head><body><!--a-->< !--b--><! --c--><!-- d--><!--e --><!--f-- ><!--g--><!---h---><!-- i --><!--- j ---><!-- -- --> <b> <!---------->", + "<html><head></head><body>{a}{b}{c}{ d}{e }{f}{g}{-h-}{ i }{- j -}{ -- }<b>{------}</b></body></html>" + ); + + // Test unclosed tags. + v.verify("<hr id = 1 class = c<hr id=2>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr class='c' id='1'/><hr id='2'/></body></html>" + ); + + // Test errors and unclosed tags. + v.verify("<b#r><hr id = 1 # class = c<hr id=2>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><b><hr id='1'/>'# class = c'<hr id='2'/></b></body></html>" + ); + + // Test script. + v.verify("<hr id=1><script a=b c=d><hr id=1></script><hr id=1>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr id='1'/><script a='b' c='d'>'<hr id=1>'</script><hr id='1'/></body></html>" + ); + + // Test valid attributes. + v.verify("<hr id='i' title=\"tit\" class=cl><hr><hr id = 2>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr class='cl' id='i' title='tit'/><hr/><hr id='2'/></body></html>" + ); + + // Test unknown attribute without value. + v.verify("<hr audrius title=\"tit\">", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr audrius='#DEFAULT' title='tit'/></body></html>" + ); + + // Test known attributes witout value. + v.verify("<option id=a selected><option id=b selected = selected class=cC><input checked>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><option id='a' selected='selected'></option></body><body _implied_='true'><option class='cC' id='b' selected='selected'></option><input checked='checked'/></body></html>" + ); + + // Test table content model. + v.verify("<table>a</table>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr _implied_='true'><td _implied_='true'>'a'</td></tr></tbody></table></body></html>" + ); + + // Test table content model. + v.verify("<table><caption>cap</caption>a</table>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><caption>'cap'</caption><tbody _implied_='true'><tr _implied_='true'><td _implied_='true'>'a'</td></tr></tbody></table></body></html>" + ); + + // Test typical table. + v.verify("<table><tr><td>x</td><td>y</td><td>z</td></table>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'x'</td><td>'y'</td><td>'z'</td></tr></tbody></table></body></html>" + ); + + // Test nested table. + v.verify("<table><tr><td><table>nested</table>x</td><td>y</td><td>z</td></table>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td><table><tbody _implied_='true'><tr _implied_='true'><td _implied_='true'>'nested'</td></tr></tbody></table>'x'</td><td>'y'</td><td>'z'</td></tr></tbody></table></body></html>" + ); + + // Test simple nested list. + v.verify("<ul><li>a</li><ul><li>na</li><li>nb</li></ul><li>b</li></ul>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'</li><ul><li>'na'</li><li>'nb'</li></ul><li>'b'</li></ul></body></html>" + ); + + // Test simple non-nested list. + v.verify("<ul><li>a</li><li>na</li><li>nb</li><li>b</li></ul>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'</li><li>'na'</li><li>'nb'</li><li>'b'</li></ul></body></html>" + ); + + // Test list without closing tags (obsolete list form). + v.verify("<ul><li>a<li>na<li>nb<li>b</ul>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'</li><li>'na'</li><li>'nb'</li><li>'b'</li></ul></body></html>" + ); + + // Test list without closing tags (obsolete list form). + v.verify("<ul><li>a<ul><li>na<li>nb</ul><li>b</ul>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><ul><li>'a'<ul><li>'na'</li><li>'nb'</li></ul></li><li>'b'</li></ul></body></html>" + ); + + // Test Obsolete table. + v.verify("<table><tr><td>a<td>b<td>c</tr>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'a'</td><td>'b'</td><td>'c'</td></tr></tbody></table></body></html>" + ); + + // Test html no head no body. + v.verify("<html>text</html>", + "<html><head _implied_='true'></head><body _implied_='true'>'text'</body></html>" + ); + + // Test head only. + v.verify("<head></head>text", + "<html _implied_='true'><head></head><body _implied_='true'>'text'</body></html>" + ); + + // Test head and body. + v.verify("<head><title>ti</title></head><body>text", + "<html _implied_='true'><head><title>'ti'</title></head><body>'text'</body></html>" + ); + + // Test title and text. + v.verify("<title>title</title>text", + "<html _implied_='true'><head _implied_='true'><title>'title'</title></head><body _implied_='true'>'text'</body></html>" + ); + + // Test html only. + v.verify("<html>text</html>", + "<html><head _implied_='true'></head><body _implied_='true'>'text'</body></html>" + ); + + // Test body only. + v.verify("<body>text</body>", + "<html _implied_='true'><head _implied_='true'></head><body>'text'</body></html>" + ); + + // Test head only. + v.verify("<head></head>text", + "<html _implied_='true'><head></head><body _implied_='true'>'text'</body></html>" + ); + + // Test obsolete table. + v.verify("<table><tr><td>a</td><tr><td>a</td>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'a'</td></tr><tr><td>'a'</td></tr></tbody></table></body></html>" + ); + + // Test obsolete table. + v.verify("<table><tr><td>a<td>b<tr><td>a<td>b<td>c", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><tbody _implied_='true'><tr><td>'a'</td><td>'b'</td></tr><tr><td>'a'</td><td>'b'</td><td>'c'</td></tr></tbody></table></body></html>" + ); + + // Test style. + v.verify("<html><head><style><hr id=2></style></head><hr id = b>", + "<html><head><style>'<hr id=2>'</style></head><body _implied_='true'><hr id='b'/></body></html>" + ); + + // Test style. + v.verify("<style><hr id=2></style>x", + "<html _implied_='true'><head _implied_='true'><style>'<hr id=2>'</style></head><body _implied_='true'>'x'</body></html>" + ); + + // Test entities in attributes. + v.verify("<hr id='id_AZ' class= \"Y_&\" >", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><hr class='Y_&' id='id_AZ'/></body></html>" + ); + + // Test colgroup. + v.verify("<table><COLGROUP width=\"25\"><COL span=\"45\"><COL id=\"identifier\"></COLGROUP><td>a<td>b<tr>x", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><table><colgroup width='25'><col span='45'/><col id='identifier'/></colgroup><tbody _implied_='true'><tr _implied_='true'><td>'a'</td><td>'b'</td></tr><tr><td _implied_='true'>'x'</td></tr></tbody></table></body></html>" + ); + + // Test definition list, obsolete. + v.verify("<dl><dt>ha<dd>a<dt>hb<dd>b", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><dl><dt>'ha'</dt><dd>'a'</dd><dt>'hb'</dt><dd>'b'</dd></dl></body></html>" + ); + + // Test definition list. + v.verify("<html><head></head><body><dl><dt>'ha'</dt><dd>'a'</dd><dt>'hb'</dt><dd>'b'</dd></dl></body></html>", + "<html><head></head><body><dl><dt>''ha''</dt><dd>''a''</dd><dt>''hb''</dt><dd>''b''</dd></dl></body></html>" + ); + + // Test paragraphs. + v.verify("<p>b<p>c<p>d", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><p>'b'</p><p>'c'</p><p>'d'</p></body></html>" + ); + + // Test paragraphs. + v.verify("<p>'b'</p><p>'c'</p><p>'d'</p>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><p>''b''</p><p>''c''</p><p>''d''</p></body></html>" + ); + + // Test select obsolete. + v.verify("<form><select><option value='hi' disabled>a<option selected>b<option>normal", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><form><select><option disabled='disabled' value='hi'>'a'</option><option selected='selected'>'b'</option><option>'normal'</option></select></form></body></html>" + ); + + // Test select current. + v.verify("<form><select><option>'a'</option><option SELECTED='selected'>'b'</option></select></form>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><form><select><option>''a''</option><option selected='selected'>''b''</option></select></form></body></html>" + ); + + // Test select current. + v.verify("<form><select><option>after<optgroup><option>'a'</option><option SELECTED='selected'>'b'</option></optgroup></select></form>", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'><form><select><option>'after'</option><optgroup><option>''a''</option><option selected='selected'>''b''</option></optgroup></select></form></body></html>" + ); + + // Test << antihang. + v.verify("<<i>text", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'<'<i>'text'</i></body></html>" + ); + + // Test << antihang with spaces. + v.verify(" < < i>text", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'<'<i>'text'</i></body></html>" + ); + + // Test Standalone <. + v.verify("Text <wrong tag is it! <b> text ", + "<html _implied_='true'><head _implied_='true'></head><body _implied_='true'>'Text''<wrong tag is it!'<b>'text'</b></body></html>" + ); + } +} diff --git a/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_randomTable.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/HTML_randomTable.java new file mode 100644 index 000000000..ee3db8951 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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("<html><head></head><body><table>"); + if (caption) + b.append("<caption>capt</caption>"); + 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("</tbody></table></body></html>"); + return b.toString(); + } + + public String getTrace() + { + StringBuffer b = new StringBuffer("<html><head></head><body><table>"); + if (caption) + b.append("<caption>'capt'</caption>"); + b.append("<tbody>"); + for (int row = 0; row < rows.length; row++) + { + b.append("<tr>"); + for (int col = 0; col < rows [ row ].length; col++) + { + b.append("<td>'" + rows [ row ] [ col ] + "'</td>"); + } + b.append("</tr>"); + } + b.append("</tbody></table></body></html>"); + 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserEntityResolverTest.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserEntityResolverTest.java new file mode 100644 index 000000000..1ce8a1afd --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserTest.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/ParserTest.java new file mode 100644 index 000000000..6b9146383 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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 = + "<html><head></head><body><table>< tbody><tr >< td >C_0_0< td>C_0_1< td >C_0_2< /td >< td >C_0_3<td>C_0_4< /td></tr ></tbody></table></body></html>"; + 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("</" + tag + "> "); + } + + 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Parser_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Parser_Test.java new file mode 100644 index 000000000..b15185760 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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 = "<html><head></head><body>"; + String epilog = "</body></html>"; + 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("</" + tag + ">"); + } + + 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TagElement_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TagElement_Test.java new file mode 100644 index 000000000..dcf2edd42 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TestCase.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/TestCase.java new file mode 100644 index 000000000..c0ce61413 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Text.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Text.java new file mode 100644 index 000000000..e7d08bd14 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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("</" + tag + ">"); + } + }; + + 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", + "<html><head></head><body>7b'{ 61'a 62'b 63'c 20 72'r 20" + + " 6e'n 20 74't 7d'} </body></html>" + ); + + v.verify(" abba ", + "<html><head></head><body>61'a 62'b 62'b 61'a </body></html>" + ); + + v.verify(" \r ab \t \r \n ba ", + "<html><head></head><body>61'a 62'b 20 62'b 61'a </body></html>" + ); + + // 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("<pre>\n\n\n\n abba \r\t \r\n</pre>", + "<html><head></head><body><pre>a a a 20 20 20 61'a 62'b 62'b" + + " 61'a 20 20 20 a 9 20 </pre></body></html>" + ); + + v.verify("<pre> abba </pre>", + "<html><head></head><body><pre>20 20 20 61'a 62'b 62'b 61'a 20 " + + "20 20 </pre></body></html>" + ); + + v.verify("<pre>\r\n abba </pre>", + "<html><head></head><body><pre>20 20 20 61'a 62'b 62'b 61'a 20 " + + "20 20 </pre></body></html>" + ); + + v.verify("<pre>\r\n\r\n abba \r\n</pre>", + "<html><head></head><body><pre>a 20 20 20 61'a 62'b 62'b 61'a 20 20" + + " 20 </pre></body></html>" + ); + + v.verify("<pre> \r ab \t \r \n ba </pre>", + "<html><head></head><body><pre>20 a 20 61'a 62'b 20 20 9 20 a" + + " 20 a 20 20 62'b 61'a 20 20 20 </pre></body></html>" + ); + + v.verify("<pre> \r\n ab \t \r\n \n ba </pre>", + "<html><head></head><body><pre>20 a 20 61'a 62'b 20 20 9 20 a" + + " 20 a 20 20 62'b 61'a 20 20 20 </pre></body></html>" + ); + + // In TEXTAREA tag, same. + v.verify("<textarea>\n\n\n\n abba \r\n</textarea>", + "<html><head></head><body><textarea>a a a 20 20 20 61'a " + + "62'b 62'b 61'a 20 </textarea></body></html>" + ); + + v.verify("<textarea> abba </textarea>", + "<html><head></head><body><textarea>20 20 20 61'a 62'b 62'b 61'a 20 " + + "20 20 </textarea></body></html>" + ); + + v.verify("<textarea> \r ab \t \r \n ba </textarea>", + "<html><head></head><body><textarea>20 a 20 61'a 62'b 20 20 9 20 a" + + " 20 a 20 20 62'b 61'a 20 20 20 </textarea></body></html>" + ); + } +} diff --git a/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Token_locations.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/Token_locations.java new file mode 100644 index 000000000..a13b4b481 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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("</" + tag + "[" + position + "]>"); + } + + public void handleComment(char[] parm1, int position) + { + out.append("{" + new String(parm1) + "[" + position + "]}"); + } + }; + + v.hideImplied = true; + + // 0123456789012345678901234567890 + v.verify("<table><tr><td>a<td>b<td>c</tr>", + "<html[0]><head[0]></head[0]><body[0]><table[0]>" + + "<tr[7]><td[11]>'a[15]'</td[16]><td[16]>'b[20]'</td[21]>" + + "<td[21]>'c[25]'</td[26]></tr[26]></table[26]></body[26]>" + + "</html[26]>" + ); + + // 0123456789012345678901234567890 + v.verify("a<!-- comment -->b<!-- comment2 -->", + "<html[0]><head[0]></head[0]><body[0]>'a[0]'{ comment [1]}'b[17]'" + + "{ comment2 [18]}</body[18]></html[18]>" + ); + + // 012345678901234567 + v.verify("<p>b<p>c<p>d", + "<html[0]><head[0]></head[0]><body[0]><p[0]>'b[3]'</p[4]><p[4]>'" + + "c[7]'</p[8]><p[8]>'d[11]'</p[11]></body[11]></html[11]>" + ); + + // Test SGML + v.verify("<! the sgml construct >sgml", + "<html[23]><head[23]></head[23]><body[23]>" + + "'sgml[23]'</body[23]></html[23]>" + ); + } +} diff --git a/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Buffer_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Buffer_Test.java new file mode 100644 index 000000000..ed21b5676 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Constants_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/Constants_Test.java new file mode 100644 index 000000000..5c422a121 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/ReaderTokenizer_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/low/ReaderTokenizer_Test.java new file mode 100644 index 000000000..60ff030e4 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/parameterDefaulter_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/parameterDefaulter_Test.java new file mode 100644 index 000000000..ad6667f9a --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/supplementaryNotifications.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/supplementaryNotifications.java new file mode 100644 index 000000000..9cccfe91d --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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", "<html><head></head><body>'a b'</body></html>"); + + assertEquals(eoln, "\n"); + + v.verify("a \r b", "<html><head></head><body>'a b'</body></html>"); + + assertEquals(eoln, "\r"); + + v.verify("a \r\n b", "<html><head></head><body>'a b'</body></html>"); + + assertEquals(eoln, "\r\n"); + + assertEquals(flushed, 3); + } +} diff --git a/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/textPreProcessor_Test.java b/testsuite/javax.swing.text.html.parser/test/gnu/javax/swing/text/html/parser/textPreProcessor_Test.java new file mode 100644 index 000000000..cf13b7f06 --- /dev/null +++ b/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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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); + } +} |