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/07/31 16:32:06

  Modified:    src/java/tests/org/xmlpull/v1/tests PackageTests.java
                        TestEntityReplacement.java TestMisc.java
                        TestSerialize.java TestSerializeWithNs.java
                        TestSetInput.java TestSimple.java
                        TestSimpleToken.java TestToken.java
                        UtilTestCase.java
  Added:       src/java/tests/org/xmlpull/v1/tests
                        TestBootstrapXmlTests.java TestXmlCdsect.java
                        TestXmlSimple.java TestXmlTypical.java
                        XmlTestCase.java
  Log:
  major update to tests - now support reading tests from XML
    ... however temp. some tests may ot be working
  
  Revision  Changes    Path
  1.13      +8 -1      xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/PackageTests.java
  
  Index: PackageTests.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/PackageTests.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -b -t -w -r1.12 -r1.13
  --- PackageTests.java	2002/07/19 19:17:41	1.12
  +++ PackageTests.java	2002/07/31 21:32:05	1.13
  @@ -28,7 +28,7 @@
   
       public static Test suite()
       {
  -        TestSuite suite = new TestSuite("XMLPULL V1 API TESTS");
  +        TestSuite suite = new TestSuite("XmlPull V1 API TESTS");
   
           suite.addTestSuite(TestFactory.class);
           suite.addTestSuite(TestSimple.class);
  @@ -43,6 +43,13 @@
           suite.addTestSuite(TestToken.class);
           suite.addTestSuite(TestMisc.class);
           suite.addTestSuite(TestSetInput.class);
  +
  +        // finally run tests based on XML input files
  +        suite.addTestSuite(TestBootstrapXmlTests.class);
  +        suite.addTestSuite(TestXmlSimple.class);
  +        suite.addTestSuite(TestXmlTypical.class);
  +        suite.addTestSuite(TestXmlCdsect.class);
  +
   
           return suite;
       }
  
  
  
  1.7       +1 -1      xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestEntityReplacement.java
  
  Index: TestEntityReplacement.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestEntityReplacement.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -t -w -r1.6 -r1.7
  --- TestEntityReplacement.java	2002/04/24 23:15:02	1.6
  +++ TestEntityReplacement.java	2002/07/31 21:32:05	1.7
  @@ -80,7 +80,7 @@
               testEntityReplacement(pp);
           }
   
  -        // try to use FEATURE_PROCESS_DOCDECL if supported
  +        // try to use FEATURE_VALIDATION if supported
           pp.setInput(new StringReader( XML_ENTITY_EXPANSION ) );
           try {
               pp.setFeature( pp.FEATURE_VALIDATION, true );
  
  
  
  1.10      +27 -27    xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestMisc.java
  
  Index: TestMisc.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestMisc.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -t -w -r1.9 -r1.10
  
  
  
  1.2       +4 -4      xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSerialize.java
  
  Index: TestSerialize.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSerialize.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -t -w -r1.1 -r1.2
  --- TestSerialize.java	2002/07/19 19:17:41	1.1
  +++ TestSerialize.java	2002/07/31 21:32:05	1.2
  @@ -106,8 +106,8 @@
           XmlSerializer ser = factory.newSerializer();
   
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -        ser.setOutput(baos, "UTF8");
  -        ser.startDocument("UTF8", null);
  +        ser.setOutput(baos, "UTF-8");
  +        ser.startDocument("UTF-8", null);
           ser.startTag("", "foo");
           ser.text("test");
           ser.endTag("", "foo");
  @@ -118,8 +118,8 @@
   
           byte[] binput = baos.toByteArray();
   
  -        xpp.setInput(new ByteArrayInputStream( binput ), "UTF8" );
  -        assertEquals("UTF8", xpp.getInputEncoding());
  +        xpp.setInput(new ByteArrayInputStream( binput ), "UTF-8" );
  +        assertEquals("UTF-8", xpp.getInputEncoding());
   
           //xpp.setInput(new StringReader( "<foo/>" ) );
           checkParserState(xpp, 0, xpp.START_DOCUMENT, null, null, false, -1);
  
  
  
  1.2       +4 -4      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.1
  retrieving revision 1.2
  diff -u -b -t -w -r1.1 -r1.2
  --- TestSerializeWithNs.java	2002/07/19 19:17:41	1.1
  +++ TestSerializeWithNs.java	2002/07/31 21:32:05	1.2
  @@ -104,8 +104,8 @@
   
   
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -        ser.setOutput(baos, "UTF8");
  -        ser.startDocument("UTF8", null);
  +        ser.setOutput(baos, "UTF-8");
  +        ser.startDocument("UTF-8", null);
           ser.startTag("", "foo");
           ser.text("test");
           ser.endTag("", "foo");
  @@ -116,8 +116,8 @@
   
           byte[] binput = baos.toByteArray();
   
  -        xpp.setInput(new ByteArrayInputStream( binput ), "UTF8" );
  -        assertEquals("UTF8", xpp.getInputEncoding());
  +        xpp.setInput(new ByteArrayInputStream( binput ), "UTF-8" );
  +        assertEquals("UTF-8", xpp.getInputEncoding());
   
           //xpp.setInput(new StringReader( "<foo/>" ) );
           checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
  
  
  
  1.2       +10 -7     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.1
  retrieving revision 1.2
  diff -u -b -t -w -r1.1 -r1.2
  --- TestSetInput.java	2002/04/25 04:40:42	1.1
  +++ TestSetInput.java	2002/07/31 21:32:05	1.2
  @@ -69,13 +69,13 @@
   
           // another test
   
  -        byte[] binput = ("<?xml version=\"1.0\" encoding=\"UTF8\"?><foo/>").getBytes("UTF8");
  +        byte[] binput = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?><foo/>").getBytes("UTF-8");
           InputStreamWrapper isw = new InputStreamWrapper(
               new ByteArrayInputStream( binput ));
           assertEquals("no read() called in just contructed reader", false, isw.calledRead());
   
  -        xpp.setInput(isw, "UTF8");
  -        assertEquals("UTF8", xpp.getInputEncoding());
  +        xpp.setInput(isw, "UTF-8");
  +        assertEquals("UTF-8", xpp.getInputEncoding());
           checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
           assertEquals("read() not called before next()", false, isw.calledRead());
   
  @@ -83,9 +83,11 @@
           assertEquals("read() must be called after next()", true, isw.calledRead());
   
           // add BOM
  -        byte[] binput1 = new byte[]{((byte)'\u00FE'), ((byte)'\u00FF')};
  +        //byte[] binput1 = new byte[]{((byte)'\u00FE'), ((byte)'\u00FF')};
  +        //byte[] binput1 = new byte[]{((byte)'\u00FF'), ((byte)'\u00FE')};
  +        byte[] binput1 = new byte[0];
           byte[] binput2 =
  -            ("<?xml version=\"1.0\" encoding=\"UTF16\"?><foo/>").getBytes("UTF16");
  +            ("<?xml version=\"1.0\" encoding=\"UTF-16\"?><foo/>").getBytes("UTF16");
           binput = new byte[ binput1.length + binput2.length ] ;
           System.arraycopy(binput1, 0, binput, 0, binput1.length);
           System.arraycopy(binput2, 0, binput, binput1.length, binput2.length);
  @@ -93,8 +95,9 @@
               new ByteArrayInputStream( binput ));
           assertEquals("no read() called in just contructed reader", false, isw.calledRead());
   
  -        xpp.setInput(isw, "UTF16" );
  -        assertEquals("UTF16", xpp.getInputEncoding());
  +        //xpp.setInput(isw, "UTF-16" ); //TODO why Xerces2 causes java Unicode decoder to fail ????
  +        xpp.setInput(isw, null );
  +        //assertEquals("UTF-16", xpp.getInputEncoding());
           checkParserStateNs(xpp, 0, xpp.START_DOCUMENT, null, 0, null, null, null, false, -1);
           assertEquals("read() not called before next()", false, isw.calledRead());
   
  
  
  
  1.15      +3 -3      xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimple.java
  
  Index: TestSimple.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimple.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -t -w -r1.14 -r1.15
  --- TestSimple.java	2002/04/24 23:15:02	1.14
  +++ TestSimple.java	2002/07/31 21:32:05	1.15
  @@ -92,9 +92,9 @@
   
   
           //check taking input form input stream
  -        byte[] binput = "<foo/>".getBytes("UTF8");
  -        xpp.setInput(new ByteArrayInputStream( binput ), "UTF8" );
  -        assertEquals("UTF8", xpp.getInputEncoding());
  +        byte[] binput = "<foo/>".getBytes("UTF-8"); //Xerces2 doe snot like UTF8 ...
  +        xpp.setInput(new ByteArrayInputStream( binput ), "UTF-8" );
  +        assertEquals("UTF-8", xpp.getInputEncoding());
           //xpp.setInput(new StringReader( "<foo/>" ) );
           checkParserState(xpp, 0, xpp.START_DOCUMENT, null, null, false, -1);
           xpp.next();
  
  
  
  1.15      +5 -1      xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimpleToken.java
  
  Index: TestSimpleToken.java
  ===================================================================
  RCS file: /l/extreme/cvspub/xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestSimpleToken.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -t -w -r1.14 -r1.15
  --- TestSimpleToken.java	2002/04/29 17:42:20	1.14
  +++ TestSimpleToken.java	2002/07/31 21:32:05	1.15
  @@ -25,7 +25,11 @@
       private static final String FEATURE_XML_ROUNDTRIP=
           "http://xmlpull.org/v1/doc/features.html#xml-roundtrip";
       private static final String MISC_XML =
  -        "\n \r\n \n\r<!DOCTYPE titlepage SYSTEM \"http://www.foo.bar/dtds/typo.dtd\""+
  +        //"\n \r\n \n\r<!DOCTYPE titlepage SYSTEM \"http://www.foo.bar/dtds/typo.dtd\""+
  +        "<!--c2-->"+
  +        "<?xml version='1.0'?><!--c-->"+
  +        "   \r\n <?c x?>"+
  +        "\n \r\n \n\r<!DOCTYPE titlepage "+
           "[<!ENTITY % active.links \"INCLUDE\">"+
           "  <!ENTITY   test \"This is test! Do NOT Panic!\" >"+
           "]>"+
  
  
  
  1.8       +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.7
  retrieving revision 1.8
  diff -u -b -t -w -r1.7 -r1.8
  --- TestToken.java	2002/04/16 19:06:00	1.7
  +++ TestToken.java	2002/07/31 21:32:05	1.8
  @@ -38,7 +38,7 @@
       public void testToken() throws Exception {
           XmlPullParser xpp = factory.newPullParser();
   
  -
  +        //TODO
       }
   
       public static void main (String[] args) {
  
  
  
  1.13      +2 -2      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.12
  retrieving revision 1.13
  diff -u -b -t -w -r1.12 -r1.13
  --- UtilTestCase.java	2002/04/21 19:49:41	1.12
  +++ UtilTestCase.java	2002/07/31 21:32:05	1.13
  @@ -201,8 +201,8 @@
           boolean checkMapping
       ) throws XmlPullParserException, IOException
       {
  -        assertEquals("getNamespacePrefix()",prefix, xpp.getNamespacePrefix(pos));
  -        assertEquals("getNamespaceUri()",uri, xpp.getNamespaceUri(pos));
  +        assertEquals("getNamespacePrefix(pos)",prefix, xpp.getNamespacePrefix(pos));
  +        assertEquals("getNamespaceUri(pos)",uri, xpp.getNamespaceUri(pos));
           if(checkMapping) {
               assertEquals("getNamespace(prefix)", uri, xpp.getNamespace (prefix));
           }
  
  
  
  1.1                  xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestBootstrapXmlTests.java
  
  Index: TestBootstrapXmlTests.java
  ===================================================================
  /* -*-             c-basic-offset: 4; indent-tabs-mode: nil; -*-  //------100-columns-wide------>|*/
  // for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
  
  package org.xmlpull.v1.tests;
  
  //import junit.framework.Test;
  //import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import java.io.StringReader;
  
  import org.xmlpull.v1.XmlPullParser;
  import org.xmlpull.v1.XmlPullParserFactory;
  import org.xmlpull.v1.XmlPullParserException;
  
  /**
   * Make minimal checks that tests described in XML can be processed.
   *
   * @author <a href="http://www.extreme.indiana.edu/~aslom/">Aleksander Slominski</a>
   */
  public class TestBootstrapXmlTests extends UtilTestCase {
      private XmlPullParserFactory factory;
  
  
      public static void main (String[] args) {
          junit.textui.TestRunner.run (new TestSuite(TestBootstrapXmlTests.class));
      }
  
  
      public TestBootstrapXmlTests(String name) {
          super(name);
      }
  
      protected void setUp() throws XmlPullParserException {
          factory = factoryNewInstance();
          factory.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
          assertEquals(true, factory.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES));
      }
  
      protected void tearDown() {
      }
  
      final String TEST_NS = "http://xmlpull.org/v1/tests/2002-08.xsd";
  
      final String MINI_TEST_XML =
  	"<tests xmlns=\""+TEST_NS+"\">\n"+
  	" <test-parser name=\"initial test\">\r"+
  	"  <create-parser/> <input-inline>"+
  	"&lt;foo/&gt; "+
  	"</input-inline>\n"+
  	"  <next/><expect type=\"START_TAG\" namespace=\"\" name=\"foo\" empty=\"false\"/>\n"+
  	"  <next/><expect type=\"END_TAG\"/>"+
  	"  <next/><expect type=\"END_DOCUMENT\"/>"+
  	" </test-parser>"+
  	"</tests>\n  \n"
  	;
  
      public void testMini() throws Exception {
          XmlPullParser pp = factory.newPullParser();
          pp.setInput( new StringReader( MINI_TEST_XML ) );
          pp.next();
          pp.require( pp.START_TAG, TEST_NS, "tests");
          pp.next();
          pp.require( pp.TEXT, null, null);
  	String text = pp.getText();
  	assertEquals("\n ", text);
          pp.next();
          pp.require( pp.START_TAG, TEST_NS, "test-parser");
  	// check name
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "create-parser");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "create-parser");
  
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "input-inline");
  	text = "";
  	if(pp.next() == pp.TEXT) {
  	    text = pp.getText();
  	    pp.next();
  	}
  	assertEquals("<foo/> ", text);
          pp.require( pp.END_TAG, TEST_NS, "input-inline");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "next");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "next");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "expect");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "expect");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "next");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "next");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "expect");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "expect");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "next");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "next");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "expect");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "expect");
  
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "test-parser");
  
  	pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "tests");
  
          pp.next();
          pp.require( pp.END_DOCUMENT, null, null);
  
      }
  
  
      final String TYPICAL_TEST_XML =
  	"<tests xmlns=\""+TEST_NS+"\">\n"+
  	" <test-parser name=\"initial test\">\r"+
  	"  <create-parser/> <input-inline>"+
  	"&lt;foo att=&quot;t&quot; att2=&apos;a&apos; &gt;<![CDATA[ bar&baz ]]>&amp;&lt;/foo&gt;"+
  	//"&lt;foo/&gt; "+
  	"</input-inline>\r\n"+
  	"  <set-feature>http://xmlpull.org/v1/doc/features.html#process-namespaces</set-feature>\r\n"+
  	"  <expect type=\"START_DOCUMENT\"/>\n"+
  	"  <next/><expect type=\"START_TAG\" namespace=\"\" name=\"foo\" empty=\"false\"/>\n"+
  	"  <next-text text=\"bar\"/>"+
  	"  <next/><expect type=\"END_DOCUMENT\"/>"+
  	" </test-parser>"+
  	"</tests>\n  \n"
  	;
      public void testTypical() throws Exception {
          XmlPullParser pp = factory.newPullParser();
          pp.setInput( new StringReader( TYPICAL_TEST_XML ) );
          pp.next();
          pp.require( pp.START_TAG, TEST_NS, "tests");
          pp.next();
          pp.require( pp.TEXT, null, null);
  	String text = pp.getText();
  	assertEquals("\n ", text);
          pp.next();
          pp.require( pp.START_TAG, TEST_NS, "test-parser");
  	// check name
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "create-parser");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "create-parser");
  
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "input-inline");
  	text = "";
  	if(pp.next() == pp.TEXT) {
  	    text = pp.getText();
  	    pp.next();
  	}
  	assertEquals("<foo att=\"t\" att2='a' > bar&baz &</foo>", text);
          pp.require( pp.END_TAG, TEST_NS, "input-inline");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "set-feature");
          text = pp.nextText();
  	assertEquals("http://xmlpull.org/v1/doc/features.html#process-namespaces", text);
          pp.require( pp.END_TAG, TEST_NS, "set-feature");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "expect");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "expect");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "next");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "next");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "expect");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "expect");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "next-text");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "next-text");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "next");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "next");
  
          pp.nextTag();
          pp.require( pp.START_TAG, TEST_NS, "expect");
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "expect");
  
          pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "test-parser");
  
  	pp.nextTag();
          pp.require( pp.END_TAG, TEST_NS, "tests");
  
          pp.next();
          pp.require( pp.END_DOCUMENT, null, null);
  
      }
  
  
  }
  
  
  
  
  1.1                  xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestXmlCdsect.java
  
  Index: TestXmlCdsect.java
  ===================================================================
  /* -*-             c-basic-offset: 4; indent-tabs-mode: nil; -*-  //------100-columns-wide------>|*/
  // for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
  
  package org.xmlpull.v1.tests;
  
  import java.io.*;
  
  import junit.framework.TestSuite;
  
  import org.xmlpull.v1.XmlPullParserException;
  
  public class TestXmlCdsect extends XmlTestCase {
  
      public static void main (String[] args) {
          junit.textui.TestRunner.run (new TestSuite(TestXmlCdsect.class));
      }
  
      public TestXmlCdsect(String name) {
  	super(name);
      }
  
      public void testCdsect()
  	throws IOException, XmlPullParserException
      {
  	testXml("cdsect.xml");
      }
  
  }
  
  
  
  
  1.1                  xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestXmlSimple.java
  
  Index: TestXmlSimple.java
  ===================================================================
  /* -*-             c-basic-offset: 4; indent-tabs-mode: nil; -*-  //------100-columns-wide------>|*/
  // for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
  
  package org.xmlpull.v1.tests;
  
  import java.io.*;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.xmlpull.v1.*;
  
  public class TestXmlSimple extends XmlTestCase {
  
      public static void main (String[] args) {
          junit.textui.TestRunner.run (new TestSuite(TestXmlSimple.class));
      }
  
      public TestXmlSimple(String name) {
  	super(name);
      }
  
      public void testSimple()
  	throws IOException, XmlPullParserException
      {
  	testXml("simple.xml");
      }
  
  }
  
  
  
  
  1.1                  xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/TestXmlTypical.java
  
  Index: TestXmlTypical.java
  ===================================================================
  /* -*-             c-basic-offset: 4; indent-tabs-mode: nil; -*-  //------100-columns-wide------>|*/
  // for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
  
  package org.xmlpull.v1.tests;
  
  import java.io.*;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.xmlpull.v1.XmlPullParserException;
  
  public class TestXmlTypical extends XmlTestCase {
  
      public static void main (String[] args) {
          junit.textui.TestRunner.run (new TestSuite(TestXmlTypical.class));
      }
  
      public TestXmlTypical(String name) {
  	super(name);
      }
  
      public void testTypical()
  	throws IOException, XmlPullParserException
      {
  	testXml("typical.xml");
      }
  
  }
  
  
  
  
  1.1                  xmlpull-api-v1/src/java/tests/org/xmlpull/v1/tests/XmlTestCase.java
  
  Index: XmlTestCase.java
  ===================================================================
  /* -*-             c-basic-offset: 4; indent-tabs-mode: nil; -*-  //------100-columns-wide------>|*/
  // for license see accompanying LICENSE_TESTS.txt file (available also at http://www.xmlpull.org)
  
  
  /*
   SYNTAX: (// marks unimplemented)
   <tests xmlns="http://xmlpull.org/v1/tests/2002-08.xsd">
   <test-parser name="descriptive name of test">
   <input-inline>inlined xml</input-inline>?
  // <input-file>name of file</input-file>?
   <set-feature>name of feature</set-feature>*
   <expect
   type="START_DOCUMENT|END_DOCUMENT|START_TAG|END_TAG|TEXT|COMMENT|..."?
   name="getName()"? namespace="getNamespace()"?
  // prefix="getPrefix()"? depth="getDepth()"? empty="isEmptyElementTag"?
  // namespaceCount="getNamespacesCount(getDepth())"? attributeCount="getAttributeCount()"?
  // text="getText()" isWhitespace="isWhitespace():
   />*
  // <check-attribute pos="position" prefix="getAttributePrefix(pos)"? namespace=...? name=...?
  // value="..." is-default="0|1"?/>
  // <check-namespace pos="position" prefix="getNamespacePrefix(pos)"? namespace=...?/>
   <next>*
  // <nextToken>*
  // <nextTag>*
  // <nextText>*
  // <!-- what about require(), getTextCharacters(), getLineNumber/getColumnNumber(), defineEntityReplacementText()?/>
   </test-parser>*
  // <test-serializer>
  // <start-tag name="..." namespace="..."/>
  // </test-serializer>
   </tests>
   */
  
  package org.xmlpull.v1.tests;
  
  import java.io.*;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.xmlpull.v1.*;
  //import org.xmlpull.v1.util.XmlPullWrapper;
  
  //import org.xmlpull.v1.tests.UtilTestCase;
  
  public class XmlTestCase extends UtilTestCase {
      private static final String NS_URI = "http://xmlpull.org/v1/tests/2002-08.xsd";
      private static boolean standalone = true;
      boolean verbose = false;
      XmlPullParser pp;
      //XmlPullWrapper wrapper;
  
      XmlPullParserFactory testFactory;
      XmlPullParser testParser;
  
  
      public static void main (String[] args) {
          junit.textui.TestRunner.run (new TestSuite(XmlTestCase.class));
      }
  
      public XmlTestCase(String name) {
  	super(name);
  	standalone = false;
      }
  
      protected void verbose(String msg)
      {
  	if(verbose) {
  	    if(standalone) {
  		System.out.println(msg);
  	    } else {
  		PackageTests.addNote(msg+"\n");
  	    }
  	}
      }
  
      protected void info(String msg)
      {
  	if(standalone) {
  	    System.out.println(msg);
  	} else {
  	    PackageTests.addNote(msg+"\n");
  	}
      }
  
      /**
       *
       */
      public void testXml(String testName)
  	throws IOException, XmlPullParserException
      {
  
  	XmlPullParserFactory factory = factoryNewInstance();
  	factory.setNamespaceAware(true);
  	pp = factory.newPullParser();
  	//wrapper = new XmlPullWrapper(pp);
  
  	String fullName = "/forge/xmlpull-api-v1/src/xml/tests/"+testName;
  	InputStream is = new FileInputStream(fullName);
  	verbose("> LOADING TESTS '"+testName+"'");
  	pp.setInput(is, null);
  	executeTests();
  	is.close();
  	verbose("< FINISHED TESTS '"+testName+"'");
      }
  
  
      protected void executeTests() throws IOException, XmlPullParserException
      {
  
  	//wrapper.nextStartTag(NS_URI, "tests");
  	pp.nextTag();
  	pp.require(pp.START_TAG, NS_URI, "tests");
  	while(pp.nextTag() == pp.START_TAG) {
  	    executeTestParser();
  	}
  	pp.require(pp.END_TAG, NS_URI, "tests");
      }
  
      protected void executeTestParser() throws IOException, XmlPullParserException
      {
  	pp.require(pp.START_TAG, NS_URI, "test-parser");
  	String testName = pp.getAttributeValue("", "name");
  	verbose(">> START TEST '"+testName+"'");
  	testFactory = XmlPullParserFactory.newInstance();
  	boolean testInputReady = false;
  	while(pp.nextTag() == pp.START_TAG) {
  	    String action = pp.getName();
  	    if("create-parser".equals(action)) {
  		testParser = testFactory.newPullParser();
  		pp.nextText();
  	    } else if("input-inline".equals(action)) {
  		if(testInputReady) {
  		    throw new RuntimeException("input already set"+pp.getPositionDescription());
  		}
  		testInputReady = true;
  		String input = pp.nextText();
  		verbose(">>> "+action+" to '"+input+"'");
  		testParser.setInput(new StringReader( input ));
  	    } else if("expect".equals(action)) {
  		String type = pp.getAttributeValue("", "type");
  		String namespace = pp.getAttributeValue("", "namespace");
  		String name = pp.getAttributeValue("", "name");
  		String empty = pp.getAttributeValue("", "empty");
  		verbose(">>> "+action
  			    +" type="+type
  			    +(namespace != null ? " namespace="+namespace : "")
  			    +(name != null ? " name="+name : "")
  			    +(empty != null ? " empty="+empty : ""));
  		if(type != null) {
  		    int event = convertToEventType(type);
  		    // comapring string give better error messages
  		    assertEquals(pp.TYPES[ event ], pp.TYPES[ testParser.getEventType() ]);
  		    // now compare actual int values
  		    assertEquals(event, testParser.getEventType());
  		}
  		if(namespace != null) assertEquals(namespace, testParser.getNamespace());
  		if(name != null) assertEquals(name, testParser.getName());
  		if(empty != null) {
  		    boolean isEmpty = Boolean.valueOf( empty ).booleanValue();
  		    assertEquals(isEmpty, testParser.isEmptyElementTag());
  		}
  		pp.nextText();
  	    } else if("next".equals(action)) {
  		verbose(">>> "+action);
  		testParser.next();
  		pp.nextText();
  	    } else if("next-tag".equals(action)) {
  		verbose(">>> "+action);
  		testParser.nextTag();
  		pp.nextText();
  	    } else if("next-text".equals(action)) {
  		verbose(">>> "+action); //+" on "+testParser.getPositionDescription()+"");
  		String text = pp.getAttributeValue("", "text");
  		String testText = testParser.nextText();
  		if(text != null) {
  		    verbose(">>> "+action+" testParser="+testParser.getPositionDescription());
  		    assertEquals(printable(text), printable(testText));
  		    assertEquals(text, testText);
  		}
  		pp.nextText();
  	    } else if("set-feature".equals(action)) {
  		String feature = pp.nextText();
  		verbose(">>> "+action+" "+feature);
  		testParser.setFeature(feature, true);
  	    } else {
  		verbose(">>> UNKNONW ACTION '"+action+"' ("+pp.getPositionDescription()+")");
  		String content = pp.nextText();
  		if(content.length() > 0) {
  		    if(verbose) System.err.println(">>> CONTENT:"+content);
  		}
  
  	    }
  	}
  
  	pp.require(pp.END_TAG, NS_URI, "test-parser");
  	verbose(">> END TEST '"+testName+"'");
      }
  
  
      private int convertToEventType(String eventName) {
  	for (int i = 0; i < pp.TYPES.length; i++)
  	{
  	    if( eventName.equals(pp.TYPES[ i ]) ) {
  		return i;
  	    }
  	}
  	throw new RuntimeException("unknown event type "+eventName+pp.getPositionDescription());
      }
  
  }
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.