curcuru     02/02/11 06:37:47

  Added:       test/tests/bugzilla Bugzilla6329.java
  Log:
  Reproduce Bugzilla6329
  
  Revision  Changes    Path
  1.1                  xml-xalan/test/tests/bugzilla/Bugzilla6329.java
  
  Index: Bugzilla6329.java
  ===================================================================
  /*
   * Covered by The Apache Software License, Version 1.1
   * See xml-xalan/License
   */
  // Common Qetest / Xalan testing imports
  import org.apache.qetest.Datalet;
  import org.apache.qetest.Logger;
  import org.apache.qetest.TestletImpl;
  
  import java.io.ByteArrayInputStream;
  import org.apache.xpath.CachedXPathAPI;
  import org.w3c.dom.*;
  import javax.xml.parsers.*;
  
  /**
   * Testlet for reproducing Bugzilla reported bugs.
   *
   * @author [EMAIL PROTECTED]
   * @author [EMAIL PROTECTED]
   */
  public class Bugzilla6329 extends TestletImpl
  {
      // Initialize our classname for TestletImpl's main() method - must be 
updated!
      static { thisClassName = "Bugzilla6329"; }
  
      /**
       * The following program tries to select all nodes in the document using 
an
       * XPath expression but the XPath misses the CDATA section.
       * User reported output is:
       * <PRE>
       * Xerces-J 2.0.0
       * Xalan Java 2.2.0
       * 0 (DOCUMENT): [#document: null]
       * 1 (ELEMENT): [svg: null]
       * 2 (ATTRIBUTE): onload="thisInit()"
       * 3 (ATTRIBUTE): width="106.786pt"
       * 4 (ATTRIBUTE): xml:space="preserve"
       * 5 (ATTRIBUTE): [EMAIL PROTECTED]
       * 6 (TEXT_NODE): [#text:
       * ]
       * 7 (ELEMENT): [style: null]
       * 8 (ATTRIBUTE): type="text/css"
       * 9 (ATTRIBUTE): xml:space=""
       * 10 (TEXT_NODE): [#text:
       * ]
       * 11 (TEXT_NODE): [#text:
       * ]
       * </PRE>
       * @param d (optional) Datalet to use as data point for the test.
       */
      public void execute(Datalet d)
        {
          // Use logger.logMsg(...) instead of System.out.println(...)
          logger.logMsg(Logger.STATUSMSG, "Reproducing Bugzilla#6329");
  
          String input =
          "<svg  width='106.786pt' xml:space='preserve' onload='thisInit()'>\n" 
+
          "<style type='text/css' xml:space=''>\n" +
          "<![CDATA[\n" +
          "    
@font-face{font-family:'RussellSquare-Oblique';src:url(Arial.cef)}\n" +
          "]]>\n" +
          "</style>\n" +
          "</svg>\n";
  
          // Note: please avoid calling these directly, or at least use 
          //    reflection to find the classes: they do change with 
          //    different Xerces and Xalan builds! -sc
          //logger.logMsg(logger.STATUSMSG, 
org.apache.xerces.impl.Version.fVersion);
          //logger.logMsg(logger.STATUSMSG, 
org.apache.xalan.processor.XSLProcessorVersion.S_VERSION);
  
          try
          {
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              dbf.setNamespaceAware(true);
  
              DocumentBuilder db = dbf.newDocumentBuilder();
              Document doc = db.parse(new 
ByteArrayInputStream(input.getBytes()));
              CachedXPathAPI xp = new CachedXPathAPI();
              logger.logMsg(logger.STATUSMSG, "User case: 
xp.selectNodeList(doc, (//. | //@* | //namespace::*))");
              NodeList nl = xp.selectNodeList(doc, "(//. | //@* | 
//namespace::*)");
  
              for (int i = 0; i < nl.getLength(); i++) 
              {
                  // logger.logMsg(logger.STATUSMSG, i + " parent: " + 
nl.item(i).getParentNode());
                  // logger.logMsg(logger.STATUSMSG, i + " 
("+org.apache.xml.security.utils.XMLUtils.getNodeTypeString(nl.item(i))+"): " + 
nl.item(i));
                  logger.logMsg(logger.STATUSMSG, i + ": " + nl.item(i));
              }
  
              logger.logMsg(logger.STATUSMSG, "dave case: 
xp.selectNodeList(doc, (//.))");
              nl = xp.selectNodeList(doc, "(//.)");
  
              for (int i = 0; i < nl.getLength(); i++) 
              {
                  // logger.logMsg(logger.STATUSMSG, i + " parent: " + 
nl.item(i).getParentNode());
                  // logger.logMsg(logger.STATUSMSG, i + " 
("+org.apache.xml.security.utils.XMLUtils.getNodeTypeString(nl.item(i))+"): " + 
nl.item(i));
                  logger.logMsg(logger.STATUSMSG, i + ": " + nl.item(i));
              }
  
  
              logger.checkAmbiguous("Test needs manual validation! (But Joe 
hints it may be invalid)");
          } 
          catch (Throwable t)
          {
              logger.logThrowable(logger.ERRORMSG, t, "Unexpected exception");
              logger.checkErr("Unexpected exception: " + t.toString());
          }
      }
  
      /**
       * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6329";>
       * Link to Bugzilla report</a>
       * @return XPath does not catch CDATA Nodes.
       */
      public String getDescription()
      {
          return "XPath does not catch CDATA Nodes";
      }
  
  }  // end of class Bugzilla6329
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to