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/19 18:33:13

  Modified:    src/java/api/org/xmlpull/v1 XmlSerializer.java
               src/java/tests/org/xmlpull/v1/tests TestSerializeWithNs.java
                        TestSetInput.java TestToken.java
  Log:
  * XmlSeriaizer is now required ot throw exception when user tries to
  write startTag()  in default namespace ("") and default namesapce is bound
  to non-empty string, added test to check for it
  * changed tests to require support for ROUNTRIP==false
  and additional checks for EOL nomralization of tokens
  
  Revision  Changes    Path
  1.10      +3 -1      xmlpull-api-v1/src/java/api/org/xmlpull/v1/XmlSerializer.java
  
  Index: XmlSerializer.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/api/org/xmlpull/v1/XmlSerializer.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -t -w -r1.9 -r1.10
  --- XmlSerializer.java	2002/08/28 04:32:56	1.9
  +++ XmlSerializer.java	2002/09/19 23:33:13	1.10
  @@ -163,7 +163,9 @@
        * immediately before this method.
        * If namespace is null no namespace prefix is printed but just name.
        * If namespace is empty string then serialzier will make sure that
  -     * default empty namespace is declared (in XML 1.0 xmlns='').
  +     * default empty namespace is declared (in XML 1.0 xmlns='')
  +     * or throw IllegalStateException if default namespace is already bound
  +     * to non-empty string.
        */
       public XmlSerializer startTag (String namespace, String name)
           throws IOException, IllegalArgumentException, IllegalStateException;
  
  
  
  1.9       +28 -10    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.8
  retrieving revision 1.9
  diff -u -b -t -w -r1.8 -r1.9
  --- TestSerializeWithNs.java	2002/09/11 16:55:43	1.8
  +++ TestSerializeWithNs.java	2002/09/19 23:33:13	1.9
  @@ -343,8 +343,8 @@
                                  attvalueUseApostrophe.booleanValue());
                   if(!serializerUseApostropheSupported) {
                       PackageTests.addNote(
  -                        "* optional feature "
  -                            +FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE+" is supported");
  +                        "* feature "
  +                            +FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE+" is supported\n");
                       serializerUseApostropheSupported = true;
                   }
               } catch(Exception ex) {
  @@ -356,8 +356,8 @@
                   ser.setProperty(PROPERTY_SERIALIZER_INDENTATION, indentation);
                   if(!serializerIndentationSupported) {
                       PackageTests.addNote(
  -                        "* optional property "
  -                            +PROPERTY_SERIALIZER_INDENTATION+" is supported");
  +                        "* property "
  +                            +PROPERTY_SERIALIZER_INDENTATION+" is supported\n");
                       serializerIndentationSupported = true;
                   }
               } catch(Exception ex) {
  @@ -369,8 +369,8 @@
                   ser.setProperty(PROPERTY_SERIALIZER_LINE_SEPARATOR, lineSeparator);
                   if(!serializerLineSeparatorSupported) {
                       PackageTests.addNote(
  -                        "* optional property "
  -                            +PROPERTY_SERIALIZER_LINE_SEPARATOR+" is supported");
  +                        "* property "
  +                            +PROPERTY_SERIALIZER_LINE_SEPARATOR+" is supported\n");
                       serializerLineSeparatorSupported = true;
                   }
               } catch(Exception ex) {
  @@ -539,6 +539,24 @@
       }
   
   
  +    public void testConflictingDefaultNs() throws Exception {
  +        XmlSerializer ser = factory.newSerializer();
  +
  +        ByteArrayOutputStream baos = new ByteArrayOutputStream();
  +        ser.setOutput(baos, "UTF8");
  +
  +        ser.setPrefix("", "namesp");
  +        ser.setPrefix("ns1", "namesp1");
  +        ser.setPrefix("ns2", "namesp2");
  +        try {
  +            ser.startTag("", "foo");
  +            fail("exception was expected when default namespace can not be declared");
  +        } catch(IllegalStateException ex) {
  +            //
  +        }
  +    }
  +
  +
       public void testMultipleOverlappingNamespaces() throws Exception {
           XmlSerializer ser = factory.newSerializer();
   
  @@ -565,7 +583,7 @@
           ser.setPrefix("", "namesp");
           ser.setPrefix("ns1", "namesp1");
           ser.setPrefix("ns2", "namesp2");
  -        ser.startTag("", "foo");
  +        ser.startTag("namesp", "foo");
   
           ser.setPrefix("ns1", "x1");
           ser.setPrefix("ns3", "namesp3");
  @@ -587,13 +605,13 @@
   
           ser.endTag("x1", "bar");
   
  -        ser.endTag("", "foo");
  +        ser.endTag("namesp", "foo");
           ser.endDocument();
   
   
           byte[] binput = baos.toByteArray();
   
  -        //System.out.println("serialized="+new String(binput, "US-ASCII"));
  +        //System.out.println(getClass().getName()+"serialized="+new String(binput, "US-ASCII"));
   
           xpp.setInput(new ByteArrayInputStream( binput ), "US-ASCII" );
           assertEquals("US-ASCII", xpp.getInputEncoding());
  
  
  
  1.5       +1 -1      xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSetInput.java
  
  Index: TestSetInput.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSetInput.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -t -w -r1.4 -r1.5
  --- TestSetInput.java	2002/09/02 20:19:54	1.4
  +++ TestSetInput.java	2002/09/19 23:33:13	1.5
  @@ -113,7 +113,7 @@
               "http://xmlpull.org/v1/doc/features.html#detect-encoding";
           if(xpp.getFeature(FEATURE_DETECT_ENCODING)) {
   
  -            PackageTests.addNote("* optional feature "+FEATURE_DETECT_ENCODING+" is supported\n");
  +            PackageTests.addNote("* feature "+FEATURE_DETECT_ENCODING+" is supported\n");
   
               isw = new InputStreamWrapper(
                   new ByteArrayInputStream( binput ));
  
  
  
  1.15      +27 -6     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.14
  retrieving revision 1.15
  diff -u -b -t -w -r1.14 -r1.15
  --- TestToken.java	2002/09/09 05:36:19	1.14
  +++ TestToken.java	2002/09/19 23:33:13	1.15
  @@ -48,10 +48,10 @@
           "[<!ENTITY % active.links \"INCLUDE\">"+
           "  <!ENTITY   test \"This is test! Do NOT Panic!\" >"+
           "]>"+
  -        "<foo attrName='attrVal'>bar<!--comment-->"+
  +        "<foo attrName='attrVal'>bar<!--comment\r\ntest-->"+
           "&test;&test;&lt;&#32;"+
           "&amp;&gt;&apos;&quot;&#x20;&#x3C;"+
  -        "<?pi ds?><![CDATA[ vo<o ]]></foo>";
  +        "<?pi ds\r\nda?><![CDATA[ vo<o ]]></foo>";
       private static final String MISC_XML =
           //"\n \r\n \n\r<!DOCTYPE titlepage SYSTEM \"http://www.foo.bar/dtds/typo.dtd\""+
           //"<!--c2-->"+
  @@ -116,11 +116,15 @@
           // attempt to set roundtrip
           try {
               xpp.setFeature(FEATURE_XML_ROUNDTRIP, useRoundtrip);
  -        } catch(Exception ex) {  // make sure we ignore if failed ...
  +        } catch(Exception ex) {  // make sure we ignore if failed to set roundtrip ...
           }
           // did we succeeded?
           boolean roundtripSupported = xpp.getFeature(FEATURE_XML_ROUNDTRIP);
           //boolean unnormalizedSupported = xpp.getFeature(FEATURE_UNNORMALIZED_XML);
  +        if(!useRoundtrip && roundtripSupported != false) {
  +            throw new RuntimeException(
  +                "disabling feature "+FEATURE_XML_ROUNDTRIP+" must be supported");
  +        }
   
           checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
           try {
  @@ -209,12 +213,21 @@
           }
   
           //xpp.nextToken();
  -        checkParserStateNs(xpp, 1, xpp.COMMENT, null, 0, null, null, "comment", false, -1);
  +
  +        checkParserStateNs(xpp, 1, xpp.COMMENT, null, 0, null, null, false, -1);
           try {
               xpp.isWhitespace();
               fail("whitespace function must fail for COMMENT");
           } catch(XmlPullParserException ex) {
           }
  +        {
  +            String text = xpp.getText();
  +                if(roundtripSupported) {
  +                    assertEquals(printable("comment\r\ntest"), printable(text));
  +                } else {
  +                    assertEquals(printable("comment\ntest"), printable(text));
  +                }
  +            }
   
           boolean processDocdecl = xpp.getFeature(xpp.FEATURE_PROCESS_DOCDECL);
   
  @@ -278,12 +291,20 @@
           checkParserStateNs(xpp, 1, xpp.ENTITY_REF, null, 0, null, "#x3C", "<", false, -1);
   
           xpp.nextToken();
  -        checkParserStateNs(xpp, 1, xpp.PROCESSING_INSTRUCTION, null, 0, null, null, "pi ds", false, -1);
  +        checkParserStateNs(xpp, 1, xpp.PROCESSING_INSTRUCTION, null, 0, null, null, false, -1);
           try {
               xpp.isWhitespace();
               fail("whitespace function must fail for START_DOCUMENT");
           } catch(XmlPullParserException ex) {
           }
  +        {
  +            String text = xpp.getText();
  +                if(roundtripSupported) {
  +                    assertEquals(printable("pi ds\r\nda"), printable(text));
  +                } else {
  +                    assertEquals(printable("pi ds\nda"), printable(text));
  +                }
  +            }
   
           xpp.nextToken();
           checkParserStateNs(xpp, 1, xpp.CDSECT, null, 0, null, null, " vo<o ", false, -1);
  @@ -346,7 +367,7 @@
           if(!roundtripSupported) {
               return;
           }
  -        PackageTests.addNote("* optional feature "+FEATURE_XML_ROUNDTRIP+" is supported\n");
  +        PackageTests.addNote("* feature "+FEATURE_XML_ROUNDTRIP+" is supported\n");
   
           StringWriter sw = new StringWriter();
           String s;
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.