1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 // Common Qetest / Xalan testing imports 19 import org.apache.qetest.Datalet; 20 import org.apache.qetest.Logger; 21 import org.apache.qetest.TestletImpl; 22 23 // REPLACE_imports needed for reproducing the bug 24 import java.io.StringReader; 25 import org.apache.xerces.parsers.DOMParser; 26 import org.apache.xpath.XPath; 27 import org.apache.xpath.XPathAPI; 28 import org.apache.xpath.objects.XObject; 29 import org.w3c.dom.Document; 30 import org.w3c.dom.Node; 31 import org.w3c.dom.traversal.NodeIterator; 32 import org.xml.sax.InputSource; 33 34 /** 35 * Testlet for reproducing Bugzilla reported bugs. 36 * @author [email protected] 37 * @author [email protected] 38 */ 39 public class Bugzilla1110 extends TestletImpl 40 { 41 // Initialize our classname for TestletImpl's main() method - must be updated! 42 static { thisClassName = "Bugzilla1110"; } 43 44 /** 45 * Write Minimal code to reproduce your Bugzilla bug report. 46 * Many Bugzilla tests won't bother with a datalet; they'll 47 * just have the data to reproduce the bug encoded by default. 48 * @param d (optional) Datalet to use as data point for the test. 49 */ execute(Datalet d)50 public void execute(Datalet d) 51 { 52 // Use logger.logMsg(...) instead of System.out.println(...) 53 logger.logMsg(Logger.STATUSMSG, "Reproducing Bugzilla1110"); 54 logger.logMsg(Logger.STATUSMSG, "User reports: I expect the following program prints ' e1\n null\n'."); 55 logger.logMsg(Logger.STATUSMSG, "User reports: But it actually prints ' null\n e1\n'."); 56 57 try 58 { 59 DOMParser domp = new DOMParser(); 60 final String docStr = 61 "<!DOCTYPE doc []>\n" 62 +"<doc>\n" 63 +" <e1>\n" 64 +" <e2/>\n" 65 +" </e1>\n" 66 +"</doc>\n"; 67 68 logger.logMsg(Logger.STATUSMSG, "---- about to parse document"); 69 logger.logMsg(Logger.STATUSMSG, docStr); 70 logger.logMsg(Logger.STATUSMSG, "----"); 71 domp.parse(new InputSource(new StringReader(docStr))); 72 Document doc = domp.getDocument(); 73 74 final String xpathStr = "(//.)[self::e1]"; 75 logger.logMsg(Logger.STATUSMSG, "about to eval '" + xpathStr + "'"); 76 XObject xobj = XPathAPI.eval(doc, xpathStr); 77 if (xobj.getType() != XObject.CLASS_NODESET) { 78 logger.checkFail("XObject returned is NOT a nodeset, is:" + xobj.str()); 79 } else { 80 NodeIterator iter = xobj.nodeset(); 81 logger.logMsg(Logger.STATUSMSG, "XObject returned Class is: " + iter.getClass().getName()); 82 logger.logMsg(Logger.STATUSMSG, "---- XObject returned value is"); 83 84 Node n = iter.nextNode(); 85 logger.logMsg(Logger.STATUSMSG, n == null ? " null" : " " + n.getNodeName()); 86 n = iter.nextNode(); 87 logger.logMsg(Logger.STATUSMSG, n == null ? " null" : " " + n.getNodeName()); 88 while ((n = iter.nextNode()) != null) 89 { 90 logger.logMsg(Logger.STATUSMSG, " " + n.getNodeName()); 91 } 92 iter.detach(); 93 logger.logMsg(Logger.WARNINGMSG, "NOTE: still need to validate expected error!"); 94 } 95 } 96 catch (Throwable t) 97 { 98 logger.logThrowable(Logger.ERRORMSG, t, "execute threw"); 99 logger.checkFail("execute threw: " + t.toString()); 100 } 101 } 102 103 /** 104 * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=NNNN"> 105 * Link to Bugzilla report</a> 106 * @return REPLACE_Bugzilla1110_description. 107 */ getDescription()108 public String getDescription() 109 { 110 return "REPLACE_Bugzilla1110_description"; 111 } 112 113 } // end of class Bugzilla1110 114 115