You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by pa...@apache.org on 2002/06/04 17:39:13 UTC
cvs commit: xml-xalan/test/java/src/org/apache/qetest/dtm TestDTM.java
pauldick 2002/06/04 08:39:12
Modified: test/java/src/org/apache/qetest/dtm TestDTM.java
Log:
Major overhaul. Now runs with harness, and uses the new
LinebyLineCheckService used to compare text based output.
Revision Changes Path
1.2 +235 -98 xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTM.java
Index: TestDTM.java
===================================================================
RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/dtm/TestDTM.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestDTM.java 9 Apr 2002 14:20:23 -0000 1.1
+++ TestDTM.java 4 Jun 2002 15:39:12 -0000 1.2
@@ -56,17 +56,25 @@
*/
package org.apache.qetest.dtm;
+// Support for test reporting and harness classes
+import org.apache.qetest.*;
+import org.apache.qetest.xsl.*;
+
+// java classes
+import java.io.File;
import java.io.StringReader;
+import java.io.FileOutputStream;
+import java.util.Properties;
+
+// Needed SAX, DOM, JAXP, Xalan classes
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
-import org.apache.xpath.objects.XMLStringFactoryImpl;
-
import org.apache.xml.dtm.*;
import org.apache.xml.dtm.ref.*;
-
+import org.apache.xpath.objects.XMLStringFactoryImpl;
/**
* Unit test for DTMManager/DTM
@@ -80,7 +88,51 @@
* %REVIEW% Extend to test DOM2DTM, incremental, DOM view of the DTM,
* whitespace-filtered, indexed/nonindexed, ...
* */
-public class TestDTM {
+public class TestDTM extends XSLProcessorTestBase
+{
+/**
+* This test creates a DTM and tests basic functionality of the DTM API
+* - execute 'build package.trax', 'traxapitest TestDTMIter.java'
+* - a bunch of convenience variables/initializers are included,
+* use or delete as is useful
+* @author Paul Dick
+* @version $Id: TestDTM.java,v 1.2 2002/06/04 15:39:12 pauldick Exp $
+*
+* Provides nextName(), currentName() functionality for tests
+* that may produce any number of output files.
+*/
+protected OutputNameManager outNames;
+
+/**
+* Information about an xsl/xml file pair for transforming.
+* Public members include inputName (for xsl); xmlName; goldName; etc.
+* If you don't use an .xml file on disk, you don't actually need this.
+*/
+protected XSLTestfileInfo testFileInfo = new XSLTestfileInfo();
+
+/** Subdirectory under test\tests\api for our xsl/xml files. */
+public static final String DTM_SUBDIR = "dtm";
+public static final String DTM_Prefix = "DTM_";
+
+String defaultSource=
+ "<?xml version=\"1.0\"?>\n"+
+ " <bdd:dummyDocument xmlns:bdd=\"www.bdd.org\" version=\"99\">\n"+
+ " <!-- Default test document -->	&"+
+ " <?api attrib1=\"yes\" attrib2=\"no\"?>"+
+ " <A>\n"+
+ " <B hat=\"new\" car=\"Honda\" dog=\"Boxer\">Life is good</B>\n"+
+ " </A>\n"+
+ " <C>My Anaconda<xyz:D xmlns:xyz=\"www.xyz.org\"/>Words</C>\n"+
+ " Want a more interesting docuent, provide the URI on the command line!\n"+
+ " <Sub-Doc xmlns:d=\"www.d.com\" a1=\"hello\" a2=\"goodbye\">"+
+ " <!-- Default test Subdocument -->"+
+ " <?api a1=\"yes\" a2=\"no\"?>"+
+ " <A><!-- A Subtree --><B><C><D><E><f:F xmlns:f=\"www.f.com\" a1=\"down\" a2=\"up\"/></E></D></C></B></A>"+
+ " <Aa/><Ab/><Ac><Ac1/></Ac>"+
+ " <Ad:Ad xmlns:Ad=\"www.Ad.com\" xmlns:y=\"www.y.com\" xmlns:z=\"www.z.com\">"+
+ " <Ad1/></Ad:Ad>"+
+ " </Sub-Doc>"+
+ " </bdd:dummyDocument>\n";
static final String[] TYPENAME=
{ "NULL",
@@ -99,76 +151,110 @@
"NAMESPACE"
};
- public static void main(String argv[])
- {
- System.out.println("\nHELLO THERE AND WELCOME TO THE WACKY WORLD OF DTM'S \n");
- try
+ /** Just initialize test name, comment, numTestCases. */
+ public TestDTM()
{
- // Pick our input source
- Source source=null;
- if(argv.length<1)
- {
- String defaultSource=
- "<?xml version=\"1.0\"?>\n"+
- " <bdd:dummyDocument xmlns:bdd=\"www.bdd.org\">\n"+
- " <!-- Default test document -->	&"+
- " <?api attrib1=\"yes\" attrib2=\"no\"?>"+
- " <A>\n"+
- " <B hat=\"new\" car=\"Honda\" dog=\"Boxer\">Life is good</B>\n"+
- " </A>\n"+
- " <C>My Anaconda<xyz:D xmlns:xyz=\"www.xyz.org\"/>Words</C>\n"+
- " Want a more interesting docuent, provide the URI on the command line!\n"+
- " </bdd:dummyDocument>\n";
- source=new StreamSource(new StringReader(defaultSource));
- }
- else if (argv.length>1 && "X".equalsIgnoreCase(argv[1]))
- {
- // XNI stream startup goes here
- // Remember to perform Schema validation, to obtain PSVI annotations
- }
- else
- {
- // Read from a URI via whatever mechanism the DTMManager prefers
- source=new StreamSource(argv[0]);
- }
-
- // Get a DTM manager, and ask it to load the DTM "uniquely",
- // with no whitespace filtering, nonincremental, but _with_
- // indexing (a fairly common case, and avoids the special
- // mode used for RTF DTMs).
- DTMManager manager= new DTMManagerDefault().newInstance(new XMLStringFactoryImpl());
- DTM dtm=manager.getDTM(source, true, null, false, true);
-
- // Get the root node. NOTE THE ASSUMPTION that this is a single-document
- // DTM -- which will always be true for a node obtained this way, but
- // won't be true for "shared" DTMs used to hold XSLT variables
- int rootNode=dtm.getDocument();
- System.out.println("DOCUMENT PROPERTIES:\n"+
+ numTestCases = 1;
+ testName = "TestDTM";
+ testComment = "Function test of DTM";
+ }
+
+ /**
+ * Initialize this test - Set names of xml/xsl test files,
+ * REPLACE_other_test_file_init.
+ *
+ * @param p Properties to initialize from (if needed)
+ * @return false if we should abort the test; true otherwise
+ */
+ public boolean doTestFileInit(Properties p)
+ {
+ // Used for all tests; just dump files in dtm subdir
+ File outSubDir = new File(outputDir + File.separator + DTM_SUBDIR);
+ if (!outSubDir.mkdirs())
+ reporter.logWarningMsg("Could not create output dir: " + outSubDir);
+
+ // Initialize an output name manager to that dir with .out extension
+ outNames = new OutputNameManager(outputDir + File.separator + DTM_SUBDIR
+ + File.separator + testName, ".out");
+
+ String testBasePath = inputDir
+ + File.separator
+ + DTM_SUBDIR
+ + File.separator;
+ String goldBasePath = goldDir
+ + File.separator
+ + DTM_SUBDIR
+ + File.separator
+ + DTM_Prefix;
+
+ //testFileInfo.inputName = testBasePath + "REPLACE_xslxml_filename.xsl";
+ //testFileInfo.xmlName = testBasePath + "REPLACE_xslxml_filename.xml";
+ testFileInfo.goldName = goldBasePath;
+
+ return true;
+ }
+
+ /**
+ * Cleanup this test - REPLACE_other_test_file_cleanup.
+ *
+ * @param p Properties to initialize from (if needed)
+ * @return false if we should abort the test; true otherwise
+ */
+ public boolean doTestFileClose(Properties p)
+ {
+ // Often will be a no-op
+ return true;
+ }
+
+ /**
+ * Create AxisIterator and walk CHILD axis.
+ * @return false if we should abort the test; true otherwise
+ */
+public boolean testCase1()
+ {
+ reporter.testCaseInit("Basic Functionality of DTM");
+ StringBuffer buf = new StringBuffer();
+ FileOutputStream fos = openFileStream(outNames.nextName());
+ String gold = testFileInfo.goldName + "testcase1.out";
+
+ // Create dtm and generate initial context
+ DTM dtm = generateDTM();
+
+ // DTM -- which will always be true for a node obtained this way, but
+ // won't be true for "shared" DTMs used to hold XSLT variables
+ int rootNode=dtm.getDocument();
+ buf.append(" *** DOCUMENT PROPERTIES: *** "+
"\nDocURI=\""+dtm.getDocumentBaseURI()+"\" "+
"SystemID=\""+dtm.getDocumentSystemIdentifier(rootNode)+"\"\n"+
"DocEncoding=\""+dtm.getDocumentEncoding(rootNode)+"\" "+
"StandAlone=\""+dtm.getDocumentStandalone(rootNode)+"\" "+
- "DocVersion=\""+dtm.getDocumentVersion(rootNode)+"\" "+
- " "
- );
+ "DocVersion=\""+dtm.getDocumentVersion(rootNode)+"\""+
+ "\n\n");
- // Simple test: Recursively dump the DTM's content.
- // We'll want to replace this with more serious examples
- System.out.println("\nDOCUMENT DATA:\n");
- recursiveDumpNode(dtm,rootNode);
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
+ // Simple test: Recursively dump the DTM's content.
+ // We'll want to replace this with more serious examples
+ buf.append(" *** DOCUMENT DATA: *** ");
+ recursiveDumpNode(dtm, rootNode, buf);
+
+ // Write results and close output file.
+ writeClose(fos, buf);
+
+ // Verify results
+ LinebyLineCheckService myfilechecker = new LinebyLineCheckService();
+ myfilechecker.check(reporter, new File(outNames.currentName()),
+ new File(gold),
+ "Testcase1");
+ reporter.testCaseClose();
+ return true;
+
+}
- static void recursiveDumpNode(DTM dtm,int nodeHandle)
- {
+void recursiveDumpNode(DTM dtm, int nodeHandle, StringBuffer buf)
+{
// ITERATE over siblings
for( ; nodeHandle!=DTM.NULL; nodeHandle=dtm.getNextSibling(nodeHandle) )
{
- printNode(dtm,nodeHandle,"");
+ buf.append(getNodeInfo(dtm,nodeHandle,""));
// List the namespaces, if any.
// Include only node's local namespaces, not inherited
@@ -176,10 +262,10 @@
int kid=dtm.getFirstNamespaceNode(nodeHandle,false);
if(kid!=DTM.NULL)
{
- System.out.println("\tNAMESPACES:");
+ buf.append("\n\tNAMESPACES:");
for( ; kid!=DTM.NULL; kid=dtm.getNextNamespaceNode(nodeHandle,kid,false))
{
- printNode(dtm,kid,"\t");
+ buf.append(getNodeInfo(dtm,kid,"\t"));
}
}
@@ -187,54 +273,105 @@
kid=dtm.getFirstAttribute(nodeHandle);
if(kid!=DTM.NULL)
{
- System.out.println("\tATTRIBUTES:");
+ buf.append("\n\tATTRIBUTES:");
for( ; kid!=DTM.NULL; kid=dtm.getNextSibling(kid))
{
- printNode(dtm,kid,"\t");
+ buf.append(getNodeInfo(dtm,kid,"\t"));
}
}
// Recurse into the children, if any
- recursiveDumpNode(dtm,dtm.getFirstChild(nodeHandle));
+ recursiveDumpNode(dtm, dtm.getFirstChild(nodeHandle), buf);
}
- }
+}
- static void printNode(DTM dtm,int nodeHandle,String indent)
- {
- // Briefly display this node
- // Don't bother displaying namespaces or attrs; we do that at the
- // next level up.
- // %REVIEW% Add namespace info, type info, ...
+String getNodeInfo(DTM dtm, int nodeHandle, String indent)
+{
// Formatting hack -- suppress quotes when value is null, to distinguish
// it from "null".
+ String buf = new String("null");
String value=dtm.getNodeValue(nodeHandle);
String vq=(value==null) ? "" : "\"";
- System.out.println(indent+
- "Node "+nodeHandle+": "+
- TYPENAME[dtm.getNodeType(nodeHandle)]+" \""+
+ // Skip outputing of text nodes. In most cases they clutter the output,
+ // besides I'm only interested in the elemental structure of the dtm.
+ {
+ buf = new String("\n" + indent+
+ nodeHandle+": "+
+ TYPENAME[dtm.getNodeType(nodeHandle)]+" "+
dtm.getNodeNameX(nodeHandle)+ " : " +
dtm.getNodeName(nodeHandle)+
- "\" expandedType="+dtm.getExpandedTypeID(nodeHandle)+
-
- "\n"+
- indent+
- "\tQName Info: "+
- //"Prefix= " +dtm.getPrefix(kid)+
- " LocalName= "+"\""+dtm.getLocalName(nodeHandle)+"\""+
- " URI= "+"\""+dtm.getNamespaceURI(nodeHandle)+"\""+
-
- "\n"+
+ "\" E-Type="+dtm.getExpandedTypeID(nodeHandle)+
+ " Level=" + dtm.getLevel(nodeHandle)+
+ " Value=" + vq + value + vq + "\n"+
indent+
- "\tParent=" + dtm.getParent(nodeHandle) +
- " FirstChild=" + dtm.getFirstChild(nodeHandle) +
- " NextSib=" + dtm.getNextSibling(nodeHandle)+
- " Level=" + dtm.getLevel(nodeHandle)+"\n"+
-
- indent+
- "\tValue=" + vq + value + vq
- );
- }
+ "\tPrefix= "+"\""+dtm.getPrefix(nodeHandle)+"\""+
+ " Name= "+"\""+dtm.getLocalName(nodeHandle)+"\""+
+ " URI= "+"\""+dtm.getNamespaceURI(nodeHandle)+"\" "+
+ "Parent=" + dtm.getParent(nodeHandle) +
+ " 1stChild=" + dtm.getFirstChild(nodeHandle) +
+ " NextSib=" + dtm.getNextSibling(nodeHandle)
+ );
+
+ }
+ return buf;
+}
+public String usage()
+{
+ return ("Common [optional] options supported by TestDTM:\n"
+ + "(Note: assumes inputDir=.\\tests\\api)\n");
+}
+
+FileOutputStream openFileStream(String name)
+{
+ FileOutputStream fos = null;
+
+ try
+ { fos = new FileOutputStream(name); }
+
+ catch (Exception e)
+ { reporter.checkFail("Failure opening output file."); }
+
+ return fos;
+}
+
+// This routine generates a new DTM for each testcase
+DTM generateDTM()
+{
+ dtmWSStripper stripper = new dtmWSStripper();
+
+ // Create DTM and generate initial context
+ Source source = new StreamSource(new StringReader(defaultSource));
+ DTMManager manager= new DTMManagerDefault().newInstance(new XMLStringFactoryImpl());
+ DTM dtm=manager.getDTM(source, true, stripper, false, true);
+
+ return dtm;
+}
+
+void writeClose(FileOutputStream fos, StringBuffer buf)
+{
+ // Write results and close output file.
+ try
+ {
+ fos.write(buf.toString().getBytes());
+ fos.close();
+ }
+
+ catch (Exception e)
+ { reporter.checkFail("Failure writing output."); }
+ }
+
+/**
+* Main method to run test from the command line - can be left alone.
+* @param args command line argument array
+*/
+public static void main(String[] args)
+{
+ TestDTM app = new TestDTM();
+ app.doMain(args);
+}
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org