xref: /aosp_15_r20/external/apache-xml/test/tests/bugzilla/Bugzilla2925.java (revision 1212f9a0ffdc28482b8821715d2222bf16dc14e2)
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 
19 // Common Qetest / Xalan testing imports
20 import org.apache.qetest.Datalet;
21 import org.apache.qetest.Logger;
22 import org.apache.qetest.TestletImpl;
23 import org.apache.qetest.xsl.XHTFileCheckService;
24 import org.apache.qetest.CheckService;
25 
26 import org.w3c.dom.*;
27 
28 import javax.xml.parsers.*;
29 import javax.xml.transform.*;
30 import javax.xml.transform.stream.*;
31 
32 import org.apache.xalan.templates.*;
33 import org.apache.xalan.extensions.*;
34 import org.apache.xalan.transformer.*;
35 import org.apache.xpath.*;
36 import org.apache.xpath.objects.*;
37 
38 import org.apache.xml.dtm.*;
39 import org.apache.xml.dtm.ref.*;
40 import org.apache.xml.dtm.ref.sax2dtm.*;
41 
42 import org.apache.xpath.XPathContext.XPathExpressionContext;
43 import org.apache.xpath.axes.OneStepIterator;
44 
45 import java.io.File;
46 
47 /**
48  * Testlet for reproducing
49  * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2925">bug #2925</a>
50  * @author [email protected]
51  */
52 public class Bugzilla2925 extends TestletImpl
53 {
54 
55   // Initialize our classname for TestletImpl's main() method - must be updated!
56   static
57   {
58     thisClassName = "Bugzilla2925";
59   }
60 
61   /**
62    * Write Minimal code to reproduce your Bugzilla bug report.
63    * Many Bugzilla tests won't bother with a datalet; they'll
64    * just have the data to reproduce the bug encoded by default.
65    * @param d (optional) Datalet to use as data point for the test.
66    *
67    * NEEDSDOC @param datalet
68    */
execute(Datalet datalet)69   public void execute(Datalet datalet)
70   {
71 
72     // Use logger.logMsg(...) instead of System.out.println(...)
73     logger.logMsg(Logger.STATUSMSG, "Reproducing Bugzilla#2925");
74 
75     try
76     {
77       TransformerFactory tf = TransformerFactory.newInstance();
78       Transformer t = tf.newTransformer(new StreamSource("Bugzilla2925.xsl"));
79       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
80 
81       dbf.setNamespaceAware(true);
82 
83       DocumentBuilder db = dbf.newDocumentBuilder();
84       Document doc = db.parse("Bugzilla2925Params.xml");
85 
86       t.setParameter("stylesheets", doc.getDocumentElement());
87       t.transform(new StreamSource("bugzilla2925.xml"),
88                   new StreamResult("bugzilla2925.xsr")
89                   // new StreamResult(System.err)
90                   );
91 
92       // If we get here, attempt to validate the contents of
93       //  the outputFile created
94       CheckService fileChecker = new XHTFileCheckService();
95 
96       if (Logger.PASS_RESULT
97               != fileChecker.check(logger, new File("bugzilla2925.xsr"),
98                                    new File("bugzilla2925.out"),
99                                    getDescription())){}
100     }
101     catch (Exception e)
102     {
103       logger.checkFail(e.getMessage());
104     }
105 
106     // Optional: use the Datalet d if supplied
107     // Call code to reproduce the bug here
108     // Call logger.checkFail("desc") (like Junit's assert(true, "desc")
109     //  or logger.checkPass("desc")  (like Junit's assert(false, "desc")
110     //  to report the actual bug fail/pass status
111   }
112 
dtmTest(org.apache.xalan.extensions.ExpressionContext exprContext, String relativeURI)113   public static DTM dtmTest(org.apache.xalan.extensions.ExpressionContext exprContext,
114                      String relativeURI)
115   {
116     XPathExpressionContext xpathExprContext = (XPathExpressionContext)exprContext;
117     DTMManager dtmMgr = xpathExprContext.getDTMManager();
118 
119     DTM dtm = dtmMgr.getDTM(new StreamSource(relativeURI), true, null, false, true);
120     // System.err.println("Returning a DTM: "+dtm);
121     // ((DTMDefaultBase)dtm).dumpDTM();
122     return dtm;
123   }
124 
DTMAxisIteratorTest( org.apache.xalan.extensions.ExpressionContext exprContext, String relativeURI)125   public static DTMAxisIterator DTMAxisIteratorTest(
126                      org.apache.xalan.extensions.ExpressionContext exprContext,
127                      String relativeURI)
128   {
129     XPathExpressionContext xpathExprContext = (XPathExpressionContext)exprContext;
130     DTMManager dtmMgr = xpathExprContext.getDTMManager();
131 
132     DTM dtm = dtmMgr.getDTM(new StreamSource(relativeURI), true, null, false, true);
133     // System.err.println("Returning a DTM: "+dtm);
134     // ((DTMDefaultBase)dtm).dumpDTM();
135 
136     DTMAxisIterator iter = dtm.getAxisIterator(Axis.SELF);
137     iter.setStartNode(dtm.getDocument());
138 
139     return iter;
140   }
141 
DTMIteratorTest( org.apache.xalan.extensions.ExpressionContext exprContext, String relativeURI)142   public static DTMIterator DTMIteratorTest(
143                      org.apache.xalan.extensions.ExpressionContext exprContext,
144                      String relativeURI)
145       throws Exception
146   {
147     XPathExpressionContext xpathExprContext = (XPathExpressionContext)exprContext;
148     DTMManager dtmMgr = xpathExprContext.getDTMManager();
149 
150     DTM dtm = dtmMgr.getDTM(new StreamSource(relativeURI), true, null, false, true);
151     // System.err.println("Returning a DTM: "+dtm);
152     // ((DTMDefaultBase)dtm).dumpDTM();
153 
154 /***************************
155 // Comment out compile error: Bugzilla2925.java:141: Wrong number of arguments in constructor.
156     DTMIterator iterator = new OneStepIterator(dtm.getAxisIterator(Axis.SELF));
157     iterator.setRoot(dtm.getDocument(), xpathExprContext.getXPathContext());
158 
159     return iterator;
160 // Comment out compile error: Bugzilla2925.java:141: Wrong number of arguments in constructor.
161 ***************************/
162     return null;
163   }
164 
165 
166 
167   /**
168    * <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2925">
169    * Link to Bugzilla report</a>
170    * @return "Parameter set from DOM Node, broken".
171    */
getDescription()172   public String getDescription()
173   {
174     return "http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2925";
175   }
176 }  // end of class Bugzilla2925
177 
178