CVS Update: xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests

Aleksander Andrzej Slominski <[email protected]>
Newsgroups gmane.text.xml.xmlpull.devel
Message-ID <[email protected]>
aslom       02/09/09 00:36:19

  Modified:    src/java/tests/org/xmlpull/v1/tests TestSerializeWithNs.java
                        TestToken.java UtilTestCase.java
  Log:
  added more coverage tests for XmlSerializer
  
  Revision  Changes    Path
  1.6       +83 -3     xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSerializeWithNs.java
  
  Index: TestSerializeWithNs.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSerializeWithNs.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -t -w -r1.5 -r1.6
  --- TestSerializeWithNs.java	2002/09/07 20:39:44	1.5
  +++ TestSerializeWithNs.java	2002/09/09 05:36:19	1.6
  @@ -120,7 +120,8 @@
           ser.setOutput(baos, "UTF-8");
           ser.startDocument("UTF-8", null);
           ser.startTag("", "foo");
  -        ser.text("test");
  +        final String text = "\"test<&>&amp;";
  +        ser.text(text);
           ser.endTag("", "foo");
           ser.endDocument();
   
  @@ -134,7 +135,7 @@
   
           //xpp.setInput(new StringReader( "<foo/>" ) );
   
  -        checkSimpleWriterResult("test");
  +        checkSimpleWriterResult(text);
   
       }
   
  @@ -164,7 +165,86 @@
       }
   
       public void testMisc() throws Exception {
  +        XmlSerializer ser = factory.newSerializer();
  +        StringWriter sw = new StringWriter();
  +        ser.setOutput(sw);
  +
           // all comments etc
  +        ser.startDocument(null, Boolean.TRUE);
  +        final String docdecl = " foo [\n"+
  +            "<!ELEMENT foo (#PCDATA|bar)* >\n"+
  +            "<!ELEMENT pbar (#PCDATA) >\n"
  +            +"]";
  +        ser.docdecl(docdecl);
  +        ser.processingInstruction("pi test");
  +        final String iws = "\n\t";
  +        ser.ignorableWhitespace(iws);
  +        ser.startTag(null, "foo");
  +        final String attrVal = "attrVal&<>&amp;";
  +        //final String attrVal = "attrVal&;";
  +        ser.attribute(null, "attrName", attrVal);
  +        ser.entityRef("amp");
  +        final String cdsect = "hello<test>\"test";
  +        ser.cdsect(cdsect);
  +        ser.startTag("uri1", "bar");
  +        final String text = "test\n\ntest";
  +        char[] buf = text.toCharArray();
  +        ser.text(buf, 0, buf.length);
  +        final String comment = "comment B- ";
  +        ser.comment(comment);
  +        ser.endDocument(); // should close unclosed foo and bar start tag
  +
  +        // -- now check that we get back what we serialized ...
  +
  +        String serialized = sw.toString();
  +        System.out.println(getClass()+" serialized="+serialized);
  +        xpp.setInput(new StringReader(serialized));
  +        xpp.setFeature(xpp.FEATURE_PROCESS_NAMESPACES, true);
  +
  +        checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
  +
  +        xpp.nextToken();
  +        checkParserStateNs(xpp, 0, xpp.DOCDECL, null, 0, null, null, false, -1);
  +        String gotDocdecl = xpp.getText();
  +        if(gotDocdecl != null) {
  +            assertEquals(printable(docdecl), printable(gotDocdecl));
  +        }
  +
  +        xpp.nextToken();
  +        checkParserStateNs(xpp, 0, xpp.PROCESSING_INSTRUCTION, null, 0, null, null, "pi test", false, -1);
  +
  +
  +        xpp.nextToken();
  +        if(xpp.getEventType() == xpp.IGNORABLE_WHITESPACE) {
  +            String expectedIws = gatherTokenText(xpp, xpp.IGNORABLE_WHITESPACE, true);
  +            assertEquals(printable(iws), printable(expectedIws));
  +        }
  +
  +        checkParserStateNs(xpp, 1, xpp.START_TAG, null, 0, "", "foo", null, false, 1);
  +        checkAttribNs(xpp, 0, null, "", "attrName", attrVal);
  +
  +        xpp.nextToken();
  +        checkParserStateNs(xpp, 1, xpp.ENTITY_REF, null, 0, null, "amp", "&", false, -1);
  +
  +        xpp.nextToken();
  +        checkParserStateNs(xpp, 1, xpp.CDSECT, null, 0, null, null, cdsect, false, -1);
  +        assertEquals(false, xpp.isWhitespace());
  +
  +        xpp.nextToken();
  +        checkParserStateNs(xpp, 2, xpp.START_TAG, 1, "uri1", "bar", false, 0);
  +
  +        String gotText = nextTokenGathered(xpp, xpp.TEXT, false);
  +        assertEquals(printable(text), printable(gotText));
  +
  +        //xpp.nextToken();
  +        checkParserStateNs(xpp, 2, xpp.COMMENT, null, 1, null, null, comment, false, -1);
  +
  +        xpp.nextToken();
  +        checkParserStateNs(xpp, 2, xpp.END_TAG, 1, "uri1", "bar", false, -1);
  +
  +        xpp.nextToken();
  +        checkParserStateNs(xpp, 1, xpp.END_TAG, 0, "", "foo", false, -1);
  +
       }
   
       public void testSetPrefix() throws Exception {
  
  
  
  1.14      +1 -1      xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestToken.java
  
  Index: TestToken.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestToken.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -b -t -w -r1.13 -r1.14
  --- TestToken.java	2002/09/07 20:39:44	1.13
  +++ TestToken.java	2002/09/09 05:36:19	1.14
  @@ -212,7 +212,7 @@
           checkParserStateNs(xpp, 1, xpp.COMMENT, null, 0, null, null, "comment", false, -1);
           try {
               xpp.isWhitespace();
  -            fail("whitespace function must fail for START_DOCUMENT");
  +            fail("whitespace function must fail for COMMENT");
           } catch(XmlPullParserException ex) {
           }
   
  
  
  
  1.20      +17 -3     xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/UtilTestCase.java
  
  Index: UtilTestCase.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/UtilTestCase.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -b -t -w -r1.19 -r1.20
  --- UtilTestCase.java	2002/09/09 04:17:51	1.19
  +++ UtilTestCase.java	2002/09/09 05:36:19	1.20
  @@ -47,7 +47,7 @@
   
       public static XmlPullParserFactory factoryNewInstance() throws XmlPullParserException {
           String property = System.getProperty(XmlPullParserFactory.PROPERTY_NAME);
  -        //"org.xmlpull.mxp1.MXParserFactory",
  +        //property = "org.xmlpull.mxp1.MXParserFactory";
           //"org.xmlpull.v1.xni2xmlpull1.X2ParserFactory",
           //property = "org.xmlpull.mxp1.MXParser,org.xmlpull.mxp1_serializer.MXSerializer";
           XmlPullParserFactory factory = XmlPullParserFactory.newInstance(
  @@ -151,7 +151,6 @@
           XmlPullParser xpp,
           int depth,
           int type,
  -        String prefix,
           int nsCount,
           String namespace,
           String name,
  @@ -171,7 +170,6 @@
           assertEquals("getName()", name, xpp.getName());
   
           assertEquals("getDepth()", depth, xpp.getDepth());
  -        assertEquals("getPrefix()", prefix, xpp.getPrefix());
           assertEquals("getNamespacesCount(getDepth())", nsCount, xpp.getNamespaceCount(depth));
           assertEquals("getNamespace()", namespace, xpp.getNamespace());
   
  @@ -185,6 +183,22 @@
               }
           }
           assertEquals("getAttributeCount()", attribCount, xpp.getAttributeCount());
  +    }
  +
  +    public void checkParserStateNs(
  +        XmlPullParser xpp,
  +        int depth,
  +        int type,
  +        String prefix,
  +        int nsCount,
  +        String namespace,
  +        String name,
  +        boolean isEmpty,
  +        int attribCount
  +    ) throws XmlPullParserException, IOException
  +    {
  +        checkParserStateNs(xpp, depth, type, nsCount, namespace, name, isEmpty, attribCount);
  +        assertEquals("getPrefix()", prefix, xpp.getPrefix());
       }
   
       public void checkParserStateNs(
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.