Ignore:
Timestamp:
Feb 11, 2013, 8:53:47 PM (13 years ago)
Author:
dmik
Message:

Merge icedtea-web v1.3 to trunk.

Location:
trunk/icedtea-web
Files:
3 edited
41 copied

Legend:

Unmodified
Added
Removed
  • trunk/icedtea-web

  • trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/ParserCornerCases.java

    r348 r418  
    3939
    4040import java.io.ByteArrayInputStream;
     41import java.io.IOException;
     42import java.io.StringReader;
     43import net.sourceforge.jnlp.annotations.KnownToFail;
    4144
    42 import org.junit.After;
     45import net.sourceforge.nanoxml.XMLElement;
     46import net.sourceforge.nanoxml.XMLParseException;
     47
    4348import org.junit.Assert;
    44 import org.junit.Before;
    4549import org.junit.Test;
    4650
    4751/** Test various corner cases of the parser */
    4852public class ParserCornerCases {
     53
     54    @Test
     55    public void testCdata() throws ParseException, XMLParseException, IOException {
     56        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>";
     57        XMLElement elem = new XMLElement();
     58        elem.parseFromReader(new StringReader(data));
     59        XMLElement target = elem;
     60        Assert.assertEquals("argument", target.getName());
     61        Assert.assertTrue("too small", target.getContent().length() > 20);
     62        Assert.assertTrue(target.getContent().contains("xml"));
     63        Assert.assertTrue(target.getContent().contains("DOCTYPE"));
     64        Assert.assertTrue(target.getContent().contains("<entry key=\"key\">value</entry>"));
     65
     66        Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()));
     67        Assert.assertEquals("argument", node.getNodeName());
     68        String contents = node.getNodeValue();
     69        Assert.assertTrue(contents.contains("xml"));
     70        Assert.assertTrue(contents.contains("DOCTYPE"));
     71        Assert.assertTrue(contents.contains("<entry key=\"key\">value</entry>"));
     72    }
     73
     74    @Test
     75    public void testCdataNested() throws ParseException, XMLParseException, IOException {
     76        String data = "<jnlp>\n" +
     77                "<application-desc>\n" +
     78                "<argument>\n" +
     79                "<![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> ]]>" +
     80                "</argument>\n" +
     81                "<argument>1</argument>\n" +
     82                "</application-desc>\n" +
     83                "</jnlp>";
     84        XMLElement elem = new XMLElement();
     85        elem.parseFromReader(new StringReader(data));
     86        XMLElement target = (XMLElement) ((XMLElement) elem.enumerateChildren().nextElement()).enumerateChildren().nextElement();
     87        Assert.assertEquals("argument", target.getName());
     88        Assert.assertTrue("too small", target.getContent().length() > 20);
     89        Assert.assertTrue(target.getContent().contains("xml"));
     90        Assert.assertTrue(target.getContent().contains("DOCTYPE"));
     91        Assert.assertTrue(target.getContent().contains("<entry key=\"key\">value</entry>"));
     92
     93        Node node = Parser.getRootNode(new ByteArrayInputStream(data.getBytes()));
     94        node = node.getFirstChild().getFirstChild();
     95        Assert.assertEquals("argument", node.getNodeName());
     96        String contents = node.getNodeValue();
     97        Assert.assertTrue(contents.contains("xml"));
     98        Assert.assertTrue(contents.contains("DOCTYPE"));
     99        Assert.assertTrue(contents.contains("<entry key=\"key\">value</entry>"));
     100    }
     101
     102    @Test
     103    @KnownToFail
     104    public void testCDataFirstChild() throws XMLParseException, IOException {
     105        String xml = "<?xml version=\"1.0\"?>\n" +
     106                "<jnlp spec=\"1.5+\">\n" +
     107                "<![CDATA[Text you want to escape goes here...<test> random tag test </test>]]>\n" +
     108                "<information/>\n" +
     109                "</jnlp>";
     110        XMLElement elem = new XMLElement();
     111        elem.parseFromReader(new StringReader(xml));
     112    }
     113
     114    @Test
     115    @KnownToFail
     116    public void testCDataSecondChild() throws XMLParseException, IOException {
     117        String xml = "<?xml version=\"1.0\"?>\n" +
     118                "<jnlp spec=\"1.5+\">\n" +
     119                "<information/>\n" +
     120                "<![CDATA[Text you want to escape goes here...<test> random tag test </test>]]>\n" +
     121                "</jnlp>";
     122        XMLElement elem = new XMLElement();
     123        elem.parseFromReader(new StringReader(xml));
     124    }
     125
    49126    @Test
    50127    public void testUnsupportedSpecNumber() throws ParseException {
     
    72149
    73150    @Test
     151    public void testCommentInElements2() throws ParseException {
     152        String malformedJnlp = "<?xml?><jnlp <!-- comment --> spec='1.0'> </jnlp>";
     153        Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()));
     154        Parser p = new Parser(null, null, root, false, false);
     155        Assert.assertEquals("1.0", p.getSpecVersion().toString());
     156    }
     157
     158    @Test
     159    @KnownToFail
    74160    public void testCommentInAttributes() throws ParseException {
    75161        String malformedJnlp = "<?xml?><jnlp spec='<!-- something -->'></jnlp>";
     
    82168    public void testNestedComments() throws ParseException {
    83169        String malformedJnlp = "<?xml?>" +
    84                 "<jnlp><information><description>" +
     170                "<jnlp><information><title>testNestedComments</title>" +
     171                "<vendor>IcedTea</vendor><description>" +
    85172                "<!-- outer <!-- inner --> -->" +
    86173                "</description></information></jnlp>";
     
    89176        Assert.assertEquals(" -->", p.getInfo(root).get(0).getDescription());
    90177    }
     178
     179    @Test
     180    public void testDoubleDashesInComments() throws ParseException {
     181        String malformedJnlp = "<?xml?>" +
     182                "<jnlp> <!-- \n" +
     183                " -- a very very long and \n" +
     184                " -- multiline comment \n" +
     185                " -- that contains double dashes \n" +
     186                " -->\n" +
     187                "  <information/>" +
     188                "</jnlp>";
     189        Node root = Parser.getRootNode(new ByteArrayInputStream(malformedJnlp.getBytes()));
     190        Parser p = new Parser(null, null, root, false, false);
     191    }
     192
    91193}
  • trunk/icedtea-web/tests/netx/unit/net/sourceforge/jnlp/ParserMalformedXml.java

    r348 r418  
    4343import java.io.InputStreamReader;
    4444import java.io.IOException;
     45import net.sourceforge.jnlp.annotations.KnownToFail;
    4546
    4647import org.junit.BeforeClass;
     
    7576
    7677    @Test
     78    @KnownToFail
    7779    public void testMalformedArguments() throws ParseException {
    7880        String malformedJnlp = originalJnlp.replace("arg2</argument", "arg2<argument");
     
    8183
    8284    @Test
     85    @KnownToFail
    8386    public void testTagNotClosed() throws ParseException {
    8487        String malformedJnlp = originalJnlp.replace("</jnlp>", "<jnlp>");
     
    8790
    8891    @Test
     92    @KnownToFail
    8993    public void testUnquotedAttributes() throws ParseException {
    9094        String malformedJnlp = originalJnlp.replace("'jnlp.jnlp'", "jnlp.jnlp");
Note: See TracChangeset for help on using the changeset viewer.