Mercurial > hg > release > icedtea-web-1.6
changeset 293:739a31d80baf
Add tests for CDATA sections
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Wed, 21 Sep 2011 14:36:44 -0400 |
parents | 1d720491c619 |
children | 8ab68d19c6f7 |
files | ChangeLog tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java tests/netx/unit/net/sourceforge/jnlp/application/application0.jnlp tests/netx/unit/net/sourceforge/jnlp/templates/template0.jnlp |
diffstat | 4 files changed, 110 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Sep 22 15:27:14 2011 -0400 +++ b/ChangeLog Wed Sep 21 14:36:44 2011 -0400 @@ -1,3 +1,12 @@ +2011-09-20 Omair Majid <omajid@redhat.com> + + * tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java + (testCdata, testCdataNested, testCDataFirstChild, testCDataSecondChild) + (testCommentInElements2, testDoubleDashesInComments): New methods + * tests/netx/unit/net/sourceforge/jnlp/application/application0.jnlp, + * tests/netx/unit/net/sourceforge/jnlp/templates/template0.jnlp: + Change <!CDATA[ to <![CDATA[. + 2011-09-22 Lars Herschke <lhersch@dssgmbh.de> PR789: typo in jrunscript.sh
--- a/tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java Thu Sep 22 15:27:14 2011 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java Wed Sep 21 14:36:44 2011 -0400 @@ -38,14 +38,88 @@ package net.sourceforge.jnlp; import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.StringReader; -import org.junit.After; +import net.sourceforge.nanoxml.XMLElement; +import net.sourceforge.nanoxml.XMLParseException; + import org.junit.Assert; -import org.junit.Before; import org.junit.Test; /** Test various corner cases of the parser */ public class ParserCornerCases { + + @Test + public void testCdata() throws ParseException, XMLParseException, IOException { + String data = "<argument><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> <!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\"> <properties> <entry key=\"key\">value</entry> </properties> ]]></argument>"; + XMLElement elem = new XMLElement(); + elem.parseFromReader(new StringReader(data)); + XMLElement target = elem; + Assert.assertEquals("argument", target.getName()); + Assert.assertTrue("too small", target.getContent().length() > 20); + Assert.assertTrue(target.getContent().contains("xml")); + Assert.assertTrue(target.getContent().contains("DOCTYPE")); + Assert.assertTrue(target.getContent().contains("<entry key=\"key\">value</entry>")); + + Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("argument", node.getNodeName()); + String contents = node.getNodeValue(); + Assert.assertTrue(contents.contains("xml")); + Assert.assertTrue(contents.contains("DOCTYPE")); + Assert.assertTrue(contents.contains("<entry key=\"key\">value</entry>")); + } + + @Test + public void testCdataNested() throws ParseException, XMLParseException, IOException { + String data = "<jnlp>\n" + + "<application-desc>\n" + + "<argument>\n" + + "<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?> <!DOCTYPE properties SYSTEM \"http://java.sun.com/dtd/properties.dtd\"> <properties> <entry key=\"key\">value</entry> </properties> ]]>" + + "</argument>\n" + + "<argument>1</argument>\n" + + "</application-desc>\n" + + "</jnlp>"; + XMLElement elem = new XMLElement(); + elem.parseFromReader(new StringReader(data)); + XMLElement target = (XMLElement) ((XMLElement) elem.enumerateChildren().nextElement()).enumerateChildren().nextElement(); + Assert.assertEquals("argument", target.getName()); + Assert.assertTrue("too small", target.getContent().length() > 20); + Assert.assertTrue(target.getContent().contains("xml")); + Assert.assertTrue(target.getContent().contains("DOCTYPE")); + Assert.assertTrue(target.getContent().contains("<entry key=\"key\">value</entry>")); + + Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + node = node.getFirstChild().getFirstChild(); + Assert.assertEquals("argument", node.getNodeName()); + String contents = node.getNodeValue(); + Assert.assertTrue(contents.contains("xml")); + Assert.assertTrue(contents.contains("DOCTYPE")); + Assert.assertTrue(contents.contains("<entry key=\"key\">value</entry>")); + } + + @Test + public void testCDataFirstChild() throws XMLParseException, IOException { + String xml = "<?xml version=\"1.0\"?>\n" + + "<jnlp spec=\"1.5+\">\n" + + "<![CDATA[Text you want to escape goes here...<test> random tag test </test>]]>\n" + + "<information/>\n" + + "</jnlp>"; + XMLElement elem = new XMLElement(); + elem.parseFromReader(new StringReader(xml)); + } + + @Test + public void testCDataSecondChild() throws XMLParseException, IOException { + String xml = "<?xml version=\"1.0\"?>\n" + + "<jnlp spec=\"1.5+\">\n" + + "<information/>\n" + + "<![CDATA[Text you want to escape goes here...<test> random tag test </test>]]>\n" + + "</jnlp>"; + XMLElement elem = new XMLElement(); + elem.parseFromReader(new StringReader(xml)); + } + @Test public void testUnsupportedSpecNumber() throws ParseException { String malformedJnlp = "<?xml?><jnlp spec='11.11'></jnlp>"; @@ -71,6 +145,14 @@ } @Test + public void testCommentInElements2() throws ParseException { + String malformedJnlp = "<?xml?><jnlp <!-- comment --> spec='1.0'> </jnlp>"; + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); + Parser p = new Parser(null, null, root, false, false); + Assert.assertEquals("1.0", p.getSpecVersion().toString()); + } + + @Test public void testCommentInAttributes() throws ParseException { String malformedJnlp = "<?xml?><jnlp spec='<!-- something -->'></jnlp>"; Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); @@ -88,4 +170,19 @@ Parser p = new Parser(null, null, root, false, false); Assert.assertEquals(" -->", p.getInfo(root).get(0).getDescription()); } + + @Test + public void testDoubleDashesInComments() throws ParseException { + String malformedJnlp = "<?xml?>" + + "<jnlp> <!-- \n" + + " -- a very very long and \n" + + " -- multiline comment \n" + + " -- that contains double dashes \n" + + " -->\n" + + " <information/>" + + "</jnlp>"; + Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes())); + Parser p = new Parser(null, null, root, false, false); + } + }
--- a/tests/netx/unit/net/sourceforge/jnlp/application/application0.jnlp Thu Sep 22 15:27:14 2011 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/application/application0.jnlp Wed Sep 21 14:36:44 2011 -0400 @@ -4,7 +4,7 @@ href="www.redhat.com" > - <!CDATA[ + <![CDATA[ Text you want to escape goes here... <test> random tag test </test> ]]>
--- a/tests/netx/unit/net/sourceforge/jnlp/templates/template0.jnlp Thu Sep 22 15:27:14 2011 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/templates/template0.jnlp Wed Sep 21 14:36:44 2011 -0400 @@ -12,7 +12,7 @@ </information> - <!CDATA[ + <![CDATA[ Text you want to escape goes here... <test> random tag test </test> ]]>