You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by vh...@apache.org on 2001/04/20 08:36:18 UTC
cvs commit: xml-batik/test-resources/org/apache/batik/test/resources Messages.properties
vhardy 01/04/19 23:36:18
Modified: test-sources/org/apache/batik/test/xml
XMLTestSuiteRunner.java XTRConstants.java
XTRunConstants.java XTSConstants.java
test-resources/org/apache/batik/test regard.xml
unitTesting.xml
test-resources/org/apache/batik/test/resources
Messages.properties
Added: test-sources/org/apache/batik/svggen Messages.java
Painter.java SVGAccuracyTest.java
SVGAccuracyTestValidator.java
test-sources/org/apache/batik/test/xml XMLReflect.java
XMLReflectConstants.java XMLTestSuiteLoader.java
test-resources/org/apache/batik/svggen/resources
Messages.properties
Log:
a. Improved XML Test classes by separating out Test suite loading from
the Test run loading. Also separated out reflection code.
b. Add core test for replacing regsvggen: org.apache.batik.svggen.SVGAccuracyTest
and its unit testing org.apache.batik.svggen.SVGAccuracyTestValidator.
Revision Changes Path
1.1 xml-batik/test-sources/org/apache/batik/svggen/Messages.java
Index: Messages.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.svggen;
import java.util.Locale;
import java.util.MissingResourceException;
import org.apache.batik.i18n.Localizable;
import org.apache.batik.i18n.LocalizableSupport;
/**
* This class manages the message for the test.svg module.
*
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
* @version $Id: Messages.java,v 1.1 2001/04/20 06:36:14 vhardy Exp $
*/
public class Messages {
/**
* This class does not need to be instantiated.
*/
protected Messages() { }
/**
* The error messages bundle class name.
*/
protected final static String RESOURCES =
"org.apache.batik.svggen.resources.Messages";
/**
* The localizable support for the error messages.
*/
protected static LocalizableSupport localizableSupport =
new LocalizableSupport(RESOURCES);
/**
* Implements {@link org.apache.batik.i18n.Localizable#setLocale(Locale)}.
*/
public static void setLocale(Locale l) {
localizableSupport.setLocale(l);
}
/**
* Implements {@link org.apache.batik.i18n.Localizable#getLocale()}.
*/
public static Locale getLocale() {
return localizableSupport.getLocale();
}
/**
* Implements {@link
* org.apache.batik.i18n.Localizable#formatMessage(String,Object[])}.
*/
public static String formatMessage(String key, Object[] args)
throws MissingResourceException {
return localizableSupport.formatMessage(key, args);
}
}
1.1 xml-batik/test-sources/org/apache/batik/svggen/Painter.java
Index: Painter.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.svggen;
import java.awt.Graphics2D;
/**
* Interface expected from object that can perform an arbitrary
* rendering sequence. This is used to generate SVG content and
* compare it to a reference.
*
* @author <a href="vhardy@eng.sun.com">Vincent Hardy</a>
* @version $Id: Painter.java,v 1.1 2001/04/20 06:36:14 vhardy Exp $
*/
public interface Painter {
public void paint(Graphics2D g);
}
1.1 xml-batik/test-sources/org/apache/batik/svggen/SVGAccuracyTest.java
Index: SVGAccuracyTest.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.svggen;
import java.net.URL;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.PrintWriter;
import org.apache.batik.util.SVGConstants;
import org.apache.batik.test.AbstractTest;
import org.apache.batik.test.DefaultTestReport;
import org.apache.batik.test.TestReport;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
/**
* This test validates that a given rendering sequence, modeled
* by a <tt>Painter</tt> is properly converted to an SVG document
* by comparing the generated SVG document to a know, valid
* SVG reference.
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
* @version $Id: SVGAccuracyTest.java,v 1.1 2001/04/20 06:36:14 vhardy Exp $
*/
public class SVGAccuracyTest extends AbstractTest
implements SVGConstants{
/**
* Error when an error occurs while generating SVG
* with the <tt>SVGGraphics2D</tt>
* {0} = painter class name if painter not null. Null otherwise
* {1} = exception class name
* {2} = exception message
* {3} = exception stack trace.
*/
public static final String ERROR_CANNOT_GENERATE_SVG
= "SVGAccuracyTest.error.cannot.generate.svg";
/**
* Error when the reference SVG file cannot be opened
* {0} = URI of the reference image
* {1} = IOException message
*/
public static final String ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE
= "SVGAccuracyTest.error.cannot.open.reference.svg.file";
/**
* Error when there is an IOException while comparing the
* reference SVG file with the newly generated SVG content
* {0} = URI of the reference image
* {1} = IOException message.
*/
public static final String ERROR_ERROR_WHILE_COMPARING_FILES
= "SVGAccuracyTest.error.while.comparing.files";
/**
* Error when the generated SVG is inaccurate
*/
public static final String ERROR_GENERATED_SVG_INACCURATE
= "SVGAccuracyTest.error.generated.svg.inaccurate";
public static final String ENTRY_KEY_ERROR_DESCRIPTION
= "SVGAccuracyTest.entry.key.error.description";
/**
* Painter which performs an arbitrary rendering
* sequence.
*/
private Painter painter;
/**
* Reference SVG URL
*/
private URL refURL;
/**
* File where the generated SVG might be saved
*/
private File saveSVG;
/**
* Constructor
* @param painter the <tt>Painter</tt> object which will
* perform an arbitrary rendering sequence.
* @param refURL the location of a reference SVG which
* should be exactly identical to that generated
* by the painter.
*/
public SVGAccuracyTest(Painter painter,
URL refURL){
this.painter = painter;
this.refURL = refURL;
}
public File getSaveSVG(){
return saveSVG;
}
public void setSaveSVG(File saveSVG){
this.saveSVG = saveSVG;
}
/**
* This method will only throw exceptions if some aspect
* of the test's internal operation fails.
*/
public TestReport runImpl() throws Exception {
DefaultTestReport report
= new DefaultTestReport(this);
SVGGraphics2D g2d = buildSVGGraphics2D();
//
// Generate SVG content
//
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(bos);
try{
painter.paint(g2d);
g2d.stream(osw);
osw.flush();
bos.flush();
bos.close();
}catch(Exception e){
StringWriter trace = new StringWriter();
e.printStackTrace(new PrintWriter(trace));
report.setErrorCode(ERROR_CANNOT_GENERATE_SVG);
report.setDescription(new TestReport.Entry[]{
new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
Messages.formatMessage(ERROR_CANNOT_GENERATE_SVG,
new String[]{painter == null? "null" : painter.getClass().getName(),
e.getClass().getName(),
e.getMessage(),
trace.toString() })) });
report.setPassed(false);
return report;
}
//
// Compare with reference SVG
//
InputStream refStream = null;
try {
refStream =
new BufferedInputStream(refURL.openStream());
}catch(Exception e){
report.setErrorCode(ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE);
report.setDescription( new TestReport.Entry[]{
new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
Messages.formatMessage(ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE,
new Object[]{refURL != null? refURL.toExternalForm() : "null",
e.getMessage()})) });
report.setPassed(false);
save(bos.toByteArray());
return report;
}
InputStream newStream = new ByteArrayInputStream(bos.toByteArray());
boolean accurate = false;
try{
accurate = compare(refStream, newStream);
} catch(IOException e) {
report.setErrorCode(ERROR_ERROR_WHILE_COMPARING_FILES);
report.setDescription(new TestReport.Entry[]{
new TestReport.Entry(Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
Messages.formatMessage(ERROR_ERROR_WHILE_COMPARING_FILES,
new Object[]{refURL.toExternalForm(),
e.getMessage()}))});
report.setPassed(false);
save(bos.toByteArray());
return report;
}
if(!accurate){
save(bos.toByteArray());
report.setErrorCode(ERROR_GENERATED_SVG_INACCURATE);
report.setPassed(false);
}
else{
report.setPassed(true);
}
return report;
}
/**
* Returns this Test's name
*/
public String getName(){
String painterInfo = painter != null ? painter.getClass().getName() : "null";
return painterInfo + " -- " + super.getName();
}
/**
* Saves the byte array in the "saveSVG" file
* if that file's parent directory exists.
*/
protected void save(byte[] data) throws IOException{
if(saveSVG == null){
return;
}
FileOutputStream os = new FileOutputStream(saveSVG);
os.write(data);
os.close();
}
/**
* Compare the two input streams
*/
protected boolean compare(InputStream refStream,
InputStream newStream)
throws IOException{
int b, nb;
boolean accurate;
do {
b = refStream.read();
nb = newStream.read();
} while (b != -1 && nb != -1 && b == nb);
refStream.close();
newStream.close();
return (b == nb);
}
/**
* Builds an <tt>SVGGraphics2D</tt> with a default
* configuration.
*/
protected SVGGraphics2D buildSVGGraphics2D(){
// CSSDocumentHandler.setParserClassName(CSS_PARSER_CLASS_NAME);
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
String namespaceURI = SVGDOMImplementation.SVG_NAMESPACE_URI;
Document domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null);
return new SVGGraphics2D(domFactory);
}
}
1.1 xml-batik/test-sources/org/apache/batik/svggen/SVGAccuracyTestValidator.java
Index: SVGAccuracyTestValidator.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.svggen;
import java.awt.Graphics2D;
import java.awt.Color;
import java.net.URL;
import java.io.File;
import org.apache.batik.test.DefaultTestSuite;
import org.apache.batik.test.Test;
import org.apache.batik.test.TestReportValidator;
import org.apache.batik.test.TestReport;
/**
* Validates the operation of the <tt>SVGAccuractyTest</tt> class
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
* @version $Id: SVGAccuracyTestValidator.java,v 1.1 2001/04/20 06:36:14 vhardy Exp $
*/
public class SVGAccuracyTestValidator extends DefaultTestSuite {
/**
* Checks that test fails if:
* + Rendering sequence generates an exception
* + There is no reference image
* + Reference SVG differs from the generated SVG
* Checks that test works if SVG and reference SVG
* are identical
*/
public SVGAccuracyTestValidator(){
addTest(new NullPainter());
addTest(new PainterWithException());
addTest(new NullReferenceURL());
addTest(new InexistantReferenceURL());
addTest(new DiffWithReferenceImage());
addTest(new SameAsReferenceImage());
}
static class NullPainter extends TestReportValidator {
public TestReport runImpl() throws Exception {
Painter painter = null;
URL refURL = new URL("http",
"dummyHost",
"dummyFile.svg");
Test t
= new SVGAccuracyTest(painter, refURL);
setConfig(t,
false,
SVGAccuracyTest.ERROR_CANNOT_GENERATE_SVG);
return super.runImpl();
}
}
static class PainterWithException extends TestReportValidator
implements Painter {
public void paint(Graphics2D g){
g.setComposite(null); // Will cause the exception
g.fillRect(0, 0, 20, 20);
}
public TestReport runImpl() throws Exception {
Painter painter = this;
URL refURL = new URL("http",
"dummyHost",
"dummyFile.svg");
Test t = new SVGAccuracyTest(painter, refURL);
setConfig(t,
false,
SVGAccuracyTest.ERROR_CANNOT_GENERATE_SVG);
return super.runImpl();
}
}
static class ValidPainterTest extends TestReportValidator
implements Painter{
public void paint(Graphics2D g){
g.setPaint(Color.red);
g.fillRect(0, 0, 40, 40);
}
}
static class NullReferenceURL extends ValidPainterTest {
public TestReport runImpl() throws Exception {
Test t = new SVGAccuracyTest(this, null);
setConfig(t,
false,
SVGAccuracyTest.ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE);
return super.runImpl();
}
}
static class InexistantReferenceURL extends ValidPainterTest {
public TestReport runImpl() throws Exception {
Test t = new SVGAccuracyTest(this,
new URL("http",
"dummyHost",
"dummyFile.svg"));
setConfig(t,
false,
SVGAccuracyTest.ERROR_CANNOT_OPEN_REFERENCE_SVG_FILE);
return super.runImpl();
}
}
static class DiffWithReferenceImage extends ValidPainterTest {
public TestReport runImpl() throws Exception {
File tmpFile = File.createTempFile("EmptySVGReference",
null);
tmpFile.deleteOnExit();
Test t = new SVGAccuracyTest(this,
tmpFile.toURL());
setConfig(t,
false,
SVGAccuracyTest.ERROR_GENERATED_SVG_INACCURATE);
return super.runImpl();
}
}
static class SameAsReferenceImage extends ValidPainterTest {
public TestReport runImpl() throws Exception {
File tmpFile = File.createTempFile("SVGReference",
null);
tmpFile.deleteOnExit();
SVGAccuracyTest t = new SVGAccuracyTest(this,
tmpFile.toURL());
t.setSaveSVG(tmpFile);
setConfig(t,
false,
SVGAccuracyTest.ERROR_GENERATED_SVG_INACCURATE);
// This first run should fail but it should
// have created the reference image in tmpFile
super.runImpl();
// Second run should work because the reference
// image should match
setConfig(t,
true,
null);
return super.runImpl();
}
}
}
1.7 +4 -275 xml-batik/test-sources/org/apache/batik/test/xml/XMLTestSuiteRunner.java
Index: XMLTestSuiteRunner.java
===================================================================
RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/xml/XMLTestSuiteRunner.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XMLTestSuiteRunner.java 2001/04/18 23:54:04 1.6
+++ XMLTestSuiteRunner.java 2001/04/20 06:36:15 1.7
@@ -54,31 +54,10 @@
* generated by the various <tt>TestSuites</tt>.<br />
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
- * @version $Id: XMLTestSuiteRunner.java,v 1.6 2001/04/18 23:54:04 vhardy Exp $
+ * @version $Id: XMLTestSuiteRunner.java,v 1.7 2001/04/20 06:36:15 vhardy Exp $
*/
public class XMLTestSuiteRunner implements XTRunConstants, XTSConstants{
/**
- * An error happened while processing a <tt>Test</tt>
- * description.
- * {0} : the <test> "className" attribute value
- * {1} : exception's class name
- * {2} : exception's message
- * {3} : exception's stack trace
- */
- public static final String CANNOT_CREATE_TEST
- = "xml.XMLTestSuiteRunner.error.cannot.create.test";
-
- /**
- * An error happened while loading a test suite document.
- * {0} : the <testSuite> href value.
- * {1} : the exception's class name
- * {2} : exception's message
- * {3} : exception's stack trace
- */
- public static final String TEST_SUITE_LOADING_EXCEPTION
- = "xml.XMLTestSuiteRunner.error.test.suite.loading.exception";
-
- /**
* An error happened while processing a <tt>TestreportProcessor</tt>
* description.
* {0} : the <testReportProcessor> "className" attribute value
@@ -149,19 +128,14 @@
*/
protected TestReportProcessor buildProcessor(Element element)
throws TestException {
-
- String className
- = element.getAttributeNS(null,
- XTRun_CLASS_ATTRIBUTE);
-
try{
- return (TestReportProcessor)buildObject(className, element);
+ return (TestReportProcessor)XMLReflect.buildObject(element);
}catch(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
throw new TestException(CANNOT_CREATE_TEST_REPORT_PROCESSOR,
- new Object[] { className,
+ new Object[] { element.getAttributeNS(null, XR_CLASS_ATTRIBUTE),
e.getClass().getName(),
e.getMessage(),
sw.toString() },
@@ -188,55 +162,13 @@
String suiteHref =
testSuites[i].getAttributeNS(null, XTRun_HREF_ATTRIBUTE);
- testSuite.addTest( loadTestSuite(suiteHref) );
+ testSuite.addTest( XMLTestSuiteLoader.loadTestSuite(suiteHref) );
}
return testSuite;
}
/**
- * Load the test suite defined by the input URI
- */
- protected TestSuite loadTestSuite(String testSuiteURI)
- throws TestException{
- Document testSuiteDocument = loadTestSuiteDocument(testSuiteURI);
- return buildTestSuite(testSuiteDocument.getDocumentElement());
- }
-
- /**
- * Loads the URI as a <tt>Document</tt>
- */
- protected Document loadTestSuiteDocument(String testSuiteURI)
- throws TestException{
- DocumentFactory df
- = new SAXDocumentFactory(SVGDOMImplementation.getDOMImplementation(),
- Messages.formatMessage(XML_PARSER, null));
-
- Document doc = null;
-
- try{
- URL url = new URL(testSuiteURI);
- doc = df.createDocument(null,
- XTS_TEST_SUITE_TAG,
- url.toString(),
- url.openStream());
- }catch(Exception e){
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- throw new TestException(TEST_SUITE_LOADING_EXCEPTION,
- new Object[] { testSuiteURI,
- e.getClass().getName(),
- e.getMessage(),
- sw.toString() },
- e);
-
- }
-
- return doc;
- }
-
- /**
* Gets all the children of a given type.
*/
protected Element[] getChildrenByTagName(Element element,
@@ -269,209 +201,6 @@
return a;
}
- /**
- * Builds a <tt>TestSuite</tt> from an input element.
- * This method assumes that element is a <testSuite>
- * instance, as the input document should have been
- * validated when loaded.
- */
- protected TestSuite buildTestSuite(Element element)
- throws TestException {
- DefaultTestSuite testSuite
- = new DefaultTestSuite();
-
- String suiteName
- = element.getAttributeNS(null,
- XTRun_NAME_ATTRIBUTE);
-
- testSuite.setName(suiteName + " -- " + testSuite.getName());
-
- NodeList children = element.getChildNodes();
- if(children != null && children.getLength() > 0){
- int n = children.getLength();
- for(int i=0; i<n; i++){
- Node child = children.item(i);
- if(child.getNodeType() == Node.ELEMENT_NODE){
- Element childElement = (Element)child;
- String tagName = childElement.getTagName().intern();
- if(tagName == XTS_TEST_TAG){
- Test t = buildTest(childElement);
- testSuite.addTest(t);
- }
- }
- }
- }
-
- return testSuite;
- }
-
- protected Test buildTest(Element element) throws TestException {
- String className
- = element.getAttributeNS(null,
- XTS_CLASS_ATTRIBUTE);
-
- try{
- return (Test)buildObject(className, element);
-
- }catch (Exception e) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- e.printStackTrace(pw);
- throw new TestException(CANNOT_CREATE_TEST,
- new Object[] { className,
- e.getClass().getName(),
- e.getMessage(),
- sw.toString() },
- e);
- }
- }
-
- /**
- * Implementation helper: builds a generic object
- */
- public Object buildObject(String className,
- Element element) throws Exception {
- Class cl = Class.forName(className);
- Object[] argsArray = null;
- Class[] argsClasses = null;
-
- NodeList children = element.getChildNodes();
- if(children != null && children.getLength() > 0){
- int n = children.getLength();
- Vector args = new Vector();
- for(int i=0; i<n; i++){
- Node child = children.item(i);
- if(child.getNodeType() == Node.ELEMENT_NODE){
- Element childElement = (Element)child;
- String tagName = childElement.getTagName().intern();
- if(tagName == XTS_ARG_TAG){
- Object arg = buildArgument(childElement);
- args.addElement(arg);
- }
- }
- }
-
- if(args.size() > 0){
- argsArray = new Object[args.size()];
- args.copyInto(argsArray);
-
- argsClasses = new Class[args.size()];
-
- for(int i=0; i<args.size(); i++){
- argsClasses[i] = argsArray[i].getClass();
- }
- }
- }
-
- Constructor constructor
- = getDeclaredConstructor(cl, argsClasses);
-
- return configureObject(constructor.newInstance(argsArray),
- element);
- }
-
- /**
- * Implementation helper: configures a generic object
- */
- public Object configureObject(Object obj,
- Element element) throws Exception {
- NodeList children = element.getChildNodes();
- if(children != null && children.getLength() > 0){
- int n = children.getLength();
- Vector args = new Vector();
- for(int i=0; i<n; i++){
- Node child = children.item(i);
- if(child.getNodeType() == Node.ELEMENT_NODE){
- Element childElement = (Element)child;
- String tagName = childElement.getTagName().intern();
- if(tagName == XTS_PROPERTY_TAG){
- Object arg = buildArgument(childElement);
- String propertyName
- = childElement.getAttributeNS(null, XTS_NAME_ATTRIBUTE);
- setObjectProperty(obj, propertyName, arg);
- }
- }
- }
-
- }
-
- return obj;
- }
-
- /**
- * Sets the property with given name on object to the input value
- */
- protected void setObjectProperty(Object obj,
- String propertyName,
- Object propertyValue)
- throws Exception {
- Class cl = obj.getClass();
- Method m = cl.getDeclaredMethod("set" + propertyName,
- new Class[]{propertyValue.getClass()});
-
- if(m != null){
- m.invoke(obj, new Object[]{propertyValue});
- }
- }
-
-
- /**
- * Returns a constructor that has can be used for the input class
- * types.
- */
- protected Constructor getDeclaredConstructor(Class cl,
- Class[] argClasses){
- Constructor[] cs = cl.getDeclaredConstructors();
- for(int i=0; i<cs.length; i++){
- Class[] reqArgClasses = cs[i].getParameterTypes();
- if(reqArgClasses != null && reqArgClasses.length > 0){
- if(reqArgClasses.length == argClasses.length){
- int j=0;
- for(; j<argClasses.length; j++){
- if(!reqArgClasses[j].isAssignableFrom(argClasses[j])){
- break;
- }
- }
- if(j == argClasses.length){
- return cs[i];
- }
- }
- }
- else{
- if(argClasses == null || argClasses.length == 0){
- return cs[i];
- }
- }
- }
-
- return null;
- }
-
- /**
- * Limitation: Arguments *must* have a String based
- * constructor. Or be an object that takes a set of string
- * based arguments.
- */
- public Object buildArgument(Element element) throws Exception {
- String classAttr = element.getAttributeNS(null,
- XTS_CLASS_ATTRIBUTE);
-
- if(!element.hasChildNodes()){
- String value = element.getAttributeNS(null,
- XTS_VALUE_ATTRIBUTE);
-
- // String based argument
- Class cl = Class.forName(classAttr);
-
- Constructor constructor
- = cl.getDeclaredConstructor(new Class[] { String.class });
-
- return constructor.newInstance(new Object[] {value});
- }
- else{
- return buildObject(classAttr, element);
- }
- }
/**
* Runs the test suite described by the input
1.2 +3 -3 xml-batik/test-sources/org/apache/batik/test/xml/XTRConstants.java
Index: XTRConstants.java
===================================================================
RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/xml/XTRConstants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XTRConstants.java 2001/04/10 22:10:35 1.1
+++ XTRConstants.java 2001/04/20 06:36:15 1.2
@@ -12,9 +12,9 @@
* Contains constants for the XML Test Report (XTR) syntax.
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
- * @version $Id: XTRConstants.java,v 1.1 2001/04/10 22:10:35 vhardy Exp $
+ * @version $Id: XTRConstants.java,v 1.2 2001/04/20 06:36:15 vhardy Exp $
*/
-public interface XTRConstants {
+public interface XTRConstants extends XMLReflectConstants{
String XTR_NAMESPACE_URI
= "http://xml.apache.org/xml-batik/test/xtr";
@@ -35,7 +35,7 @@
String XTR_ERROR_CODE_ATTRIBUTE = "errorCode";
String XTR_STATUS_ATTRIBUTE = "status";
String XTR_TEST_NAME_ATTRIBUTE = "testName";
- String XTR_VALUE_ATTRIBUTE = "value";
+ String XTR_VALUE_ATTRIBUTE = "value";
/////////////////////////////////////////////////////////////////////////
// XTR values
1.2 +1 -5 xml-batik/test-sources/org/apache/batik/test/xml/XTRunConstants.java
Index: XTRunConstants.java
===================================================================
RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/xml/XTRunConstants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XTRunConstants.java 2001/04/18 23:54:04 1.1
+++ XTRunConstants.java 2001/04/20 06:36:15 1.2
@@ -12,7 +12,7 @@
* Contains constants for the XML Test Run (XTRun) syntax.
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
- * @version $Id: XTRunConstants.java,v 1.1 2001/04/18 23:54:04 vhardy Exp $
+ * @version $Id: XTRunConstants.java,v 1.2 2001/04/20 06:36:15 vhardy Exp $
*/
public interface XTRunConstants {
String XTRun_NAMESPACE_URI
@@ -21,8 +21,6 @@
/////////////////////////////////////////////////////////////////////////
// XTRun tags
/////////////////////////////////////////////////////////////////////////
- String XTRun_ARG_TAG = "arg";
- String XTRun_PROPERTY_TAG = "property";
String XTRun_TEST_RUN_TAG = "testRun";
String XTRun_TEST_SUITE_TAG = "testSuite";
String XTRun_TEST_REPORT_PROCESSOR_TAG = "testReportProcessor";
@@ -30,8 +28,6 @@
/////////////////////////////////////////////////////////////////////////
// XTRun attributes
/////////////////////////////////////////////////////////////////////////
- String XTRun_CLASS_ATTRIBUTE = "class";
String XTRun_HREF_ATTRIBUTE = "href";
String XTRun_NAME_ATTRIBUTE = "name";
- String XTRun_VALUE_ATTRIBUTE = "value";
}
1.3 +3 -11 xml-batik/test-sources/org/apache/batik/test/xml/XTSConstants.java
Index: XTSConstants.java
===================================================================
RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/xml/XTSConstants.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XTSConstants.java 2001/04/16 22:42:37 1.2
+++ XTSConstants.java 2001/04/20 06:36:15 1.3
@@ -12,28 +12,20 @@
* Contains constants for the XML Test Suite (XTS) syntax.
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
- * @version $Id: XTSConstants.java,v 1.2 2001/04/16 22:42:37 vhardy Exp $
+ * @version $Id: XTSConstants.java,v 1.3 2001/04/20 06:36:15 vhardy Exp $
*/
-public interface XTSConstants {
+public interface XTSConstants extends XMLReflectConstants{
String XTS_NAMESPACE_URI
= "http://xml.apache.org/xml-batik/test/xts";
-
/////////////////////////////////////////////////////////////////////////
// XTS tags
/////////////////////////////////////////////////////////////////////////
- String XTS_ARG_TAG = "arg";
- String XTS_PROPERTY_TAG = "property";
String XTS_TEST_TAG = "test";
String XTS_TEST_SUITE_TAG = "testSuite";
- String XTS_TEST_REPORT_PROCESSOR_TAG = "testReportProcessor";
-
-
/////////////////////////////////////////////////////////////////////////
// XTS attributes
/////////////////////////////////////////////////////////////////////////
- String XTS_CLASS_ATTRIBUTE = "class";
- String XTS_NAME_ATTRIBUTE = "name";
- String XTS_VALUE_ATTRIBUTE = "value";
+ String XTS_NAME_ATTRIBUTE = "name";
}
1.1 xml-batik/test-sources/org/apache/batik/test/xml/XMLReflect.java
Index: XMLReflect.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.test.xml;
import java.util.Vector;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* This helper class can be used to build Java object from their
* XML description.
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
* @version $Id: XMLReflect.java,v 1.1 2001/04/20 06:36:15 vhardy Exp $
*/
public class XMLReflect implements XMLReflectConstants{
/**
* Implementation helper: builds a generic object
*/
public static Object buildObject(Element element) throws Exception {
String className
= element.getAttributeNS(null,
XR_CLASS_ATTRIBUTE);
Class cl = Class.forName(className);
Object[] argsArray = null;
Class[] argsClasses = null;
NodeList children = element.getChildNodes();
if(children != null && children.getLength() > 0){
int n = children.getLength();
Vector args = new Vector();
for(int i=0; i<n; i++){
Node child = children.item(i);
if(child.getNodeType() == Node.ELEMENT_NODE){
Element childElement = (Element)child;
String tagName = childElement.getTagName().intern();
if(tagName == XR_ARG_TAG){
Object arg = buildArgument(childElement);
args.addElement(arg);
}
}
}
if(args.size() > 0){
argsArray = new Object[args.size()];
args.copyInto(argsArray);
argsClasses = new Class[args.size()];
for(int i=0; i<args.size(); i++){
argsClasses[i] = argsArray[i].getClass();
}
}
}
Constructor constructor
= getDeclaredConstructor(cl, argsClasses);
return configureObject(constructor.newInstance(argsArray),
element);
}
/**
* Implementation helper: configures a generic object
*/
public static Object configureObject(Object obj,
Element element) throws Exception {
NodeList children = element.getChildNodes();
if(children != null && children.getLength() > 0){
int n = children.getLength();
Vector args = new Vector();
for(int i=0; i<n; i++){
Node child = children.item(i);
if(child.getNodeType() == Node.ELEMENT_NODE){
Element childElement = (Element)child;
String tagName = childElement.getTagName().intern();
if(tagName == XR_PROPERTY_TAG){
Object arg = buildArgument(childElement);
String propertyName
= childElement.getAttributeNS(null, XR_NAME_ATTRIBUTE);
setObjectProperty(obj, propertyName, arg);
}
}
}
}
return obj;
}
/**
* Sets the property with given name on object to the input value
*/
public static void setObjectProperty(Object obj,
String propertyName,
Object propertyValue)
throws Exception {
Class cl = obj.getClass();
Method m = cl.getDeclaredMethod("set" + propertyName,
new Class[]{propertyValue.getClass()});
if(m != null){
m.invoke(obj, new Object[]{propertyValue});
}
}
/**
* Returns a constructor that has can be used for the input class
* types.
*/
public static Constructor getDeclaredConstructor(Class cl,
Class[] argClasses){
Constructor[] cs = cl.getDeclaredConstructors();
for(int i=0; i<cs.length; i++){
Class[] reqArgClasses = cs[i].getParameterTypes();
if(reqArgClasses != null && reqArgClasses.length > 0){
if(reqArgClasses.length == argClasses.length){
int j=0;
for(; j<argClasses.length; j++){
if(!reqArgClasses[j].isAssignableFrom(argClasses[j])){
break;
}
}
if(j == argClasses.length){
return cs[i];
}
}
}
else{
if(argClasses == null || argClasses.length == 0){
return cs[i];
}
}
}
return null;
}
/**
* Limitation: Arguments *must* have a String based
* constructor. Or be an object that takes a set of string
* based arguments.
*/
public static Object buildArgument(Element element) throws Exception {
if(!element.hasChildNodes()){
String classAttr = element.getAttributeNS(null,
XR_CLASS_ATTRIBUTE);
String value = element.getAttributeNS(null,
XR_VALUE_ATTRIBUTE);
// String based argument
Class cl = Class.forName(classAttr);
Constructor constructor
= cl.getDeclaredConstructor(new Class[] { String.class });
return constructor.newInstance(new Object[] {value});
}
else{
return buildObject(element);
}
}
}
1.1 xml-batik/test-sources/org/apache/batik/test/xml/XMLReflectConstants.java
Index: XMLReflectConstants.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.test.xml;
/**
* Contains constants for elements and attributes used to
* describe Java objects, constructor arguments and properties
* in XML.
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
* @version $Id: XMLReflectConstants.java,v 1.1 2001/04/20 06:36:15 vhardy Exp $
*/
public interface XMLReflectConstants {
/////////////////////////////////////////////////////////////////////////
// Tags
/////////////////////////////////////////////////////////////////////////
String XR_ARG_TAG = "arg";
String XR_PROPERTY_TAG = "property";
/////////////////////////////////////////////////////////////////////////
// XTS attributes
/////////////////////////////////////////////////////////////////////////
String XR_CLASS_ATTRIBUTE = "class";
String XR_NAME_ATTRIBUTE = "name";
String XR_VALUE_ATTRIBUTE = "value";
}
1.1 xml-batik/test-sources/org/apache/batik/test/xml/XMLTestSuiteLoader.java
Index: XMLTestSuiteLoader.java
===================================================================
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Apache Software License *
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
package org.apache.batik.test.xml;
import java.io.File;
import java.io.StringWriter;
import java.io.PrintWriter;
import java.net.URL;
import java.net.MalformedURLException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Vector;
import org.apache.batik.test.DefaultTestSuite;
import org.apache.batik.test.TestReport;
import org.apache.batik.test.TestSuite;
import org.apache.batik.test.Test;
import org.apache.batik.test.TestException;
import org.apache.batik.test.TestReportProcessor;
import org.apache.batik.dom.util.DocumentFactory;
import org.apache.batik.dom.util.SAXDocumentFactory;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.xml.sax.InputSource;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* This class loads an XML document describing a test suite
* into a <tt>TestSuite</tt> object.
*
* @author <a href="mailto:vhardy@apache.org">Vincent Hardy</a>
* @version $Id: XMLTestSuiteLoader.java,v 1.1 2001/04/20 06:36:15 vhardy Exp $
*/
public class XMLTestSuiteLoader implements XTSConstants {
/**
* Configuration parameter. Use same parser as XMLTestSuiteRunner
*/
public static final String XML_PARSER =
"XMLTestSuiteRunner.config.xml.parser";
/**
* An error happened while loading a test suite document.
* {0} : the <testSuite> href value.
* {1} : the exception's class name
* {2} : exception's message
* {3} : exception's stack trace
*/
public static final String TEST_SUITE_LOADING_EXCEPTION
= "xml.XMLTestSuiteLoader.error.test.suite.loading.exception";
/**
* An error happened while processing a <tt>Test</tt>
* description.
* {0} : the <test> "className" attribute value
* {1} : exception's class name
* {2} : exception's message
* {3} : exception's stack trace
*/
public static final String CANNOT_CREATE_TEST
= "xml.XMLTestSuiteLoader.error.cannot.create.test";
/**
* Load the test suite defined by the input URI
*/
public static TestSuite loadTestSuite(String testSuiteURI)
throws TestException{
Document testSuiteDocument = loadTestSuiteDocument(testSuiteURI);
return buildTestSuite(testSuiteDocument.getDocumentElement());
}
/**
* Loads the URI as a <tt>Document</tt>
*/
protected static Document loadTestSuiteDocument(String testSuiteURI)
throws TestException{
DocumentFactory df
= new SAXDocumentFactory(SVGDOMImplementation.getDOMImplementation(),
Messages.formatMessage(XML_PARSER, null));
Document doc = null;
try{
URL url = new URL(testSuiteURI);
doc = df.createDocument(null,
XTS_TEST_SUITE_TAG,
url.toString(),
url.openStream());
}catch(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
throw new TestException(TEST_SUITE_LOADING_EXCEPTION,
new Object[] { testSuiteURI,
e.getClass().getName(),
e.getMessage(),
sw.toString() },
e);
}
return doc;
}
/**
* Builds a <tt>TestSuite</tt> from an input element.
* This method assumes that element is a <testSuite>
* instance, as the input document should have been
* validated when loaded.
*/
protected static TestSuite buildTestSuite(Element element)
throws TestException {
DefaultTestSuite testSuite
= new DefaultTestSuite();
String suiteName
= element.getAttributeNS(null,
XTS_NAME_ATTRIBUTE);
testSuite.setName(suiteName + " -- " + testSuite.getName());
NodeList children = element.getChildNodes();
if(children != null && children.getLength() > 0){
int n = children.getLength();
for(int i=0; i<n; i++){
Node child = children.item(i);
if(child.getNodeType() == Node.ELEMENT_NODE){
Element childElement = (Element)child;
String tagName = childElement.getTagName().intern();
if(tagName == XTS_TEST_TAG){
Test t = buildTest(childElement);
testSuite.addTest(t);
}
}
}
}
return testSuite;
}
protected static Test buildTest(Element element) throws TestException {
try{
return (Test)XMLReflect.buildObject(element);
}catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
throw new TestException(CANNOT_CREATE_TEST,
new Object[] { element.getAttributeNS(null, XR_CLASS_ATTRIBUTE),
e.getClass().getName(),
e.getMessage(),
sw.toString() },
e);
}
}
}
1.1 xml-batik/test-resources/org/apache/batik/svggen/resources/Messages.properties
Index: Messages.properties
===================================================================
#############################################################################
# Copyright (C) The Apache Software Foundation. All rights reserved. #
#############################################################################
# This software is published under the terms of the Apache Software License #
# version 1.1, a copy of which has been included with this distribution in #
# the LICENSE file. #
#############################################################################
#
# Error Messages values
#
SVGAccuracyTest.error.cannot.generate.svg = \
Error while generating SVG with Painter : {0} \
Got exception {1} with message {2} \
and stack trace {3}
SVGAccuracyTest.error.cannot.open.reference.svg.file = \
Cannot open reference SVG file : {0} \
Got IOException with message : {1}
SVGAccuracyTest.error.while.comparing.files = \
Error while comparing generated SVG and reference SVG {0}. \
Got IOException with message : {1}
SVGAccuracyTest.error.generated.svg.inaccurate = \
Generated SVG is inaccurate.
#
# Entry Keys
#
SVGAccuracyTest.entry.key.error.description = \
Error Description.
1.2 +2 -2 xml-batik/test-resources/org/apache/batik/test/regard.xml
Index: regard.xml
===================================================================
RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/regard.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- regard.xml 2001/04/18 23:54:02 1.1
+++ regard.xml 2001/04/20 06:36:17 1.2
@@ -11,7 +11,7 @@
<!-- regression testing. -->
<!-- -->
<!-- @author vincent.hardy@eng.sun.com -->
-<!-- @version $Id: regard.xml,v 1.1 2001/04/18 23:54:02 vhardy Exp $ -->
+<!-- @version $Id: regard.xml,v 1.2 2001/04/20 06:36:17 vhardy Exp $ -->
<!-- ========================================================================= -->
<testRun name="Batik Standard Regression Test Run">
<testRun name="REGARD">
@@ -28,7 +28,7 @@
</arg>
</testReportProcessor>
- <testSuite href="file:test-resources/org/apache/batik/test/samplesRendering.xml" />
+ <testSuite href="file:test-resources/org/apache/batik/test/samplesRendering.xml" />
<testSuite href="file:test-resources/org/apache/batik/test/unitTesting.xml" />
</testRun>
1.2 +6 -1 xml-batik/test-resources/org/apache/batik/test/unitTesting.xml
Index: unitTesting.xml
===================================================================
RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/unitTesting.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- unitTesting.xml 2001/04/18 23:54:02 1.1
+++ unitTesting.xml 2001/04/20 06:36:17 1.2
@@ -8,11 +8,16 @@
<!-- ========================================================================= -->
<!-- @author vincent.hardy@eng.sun.com -->
-<!-- @version $Id: unitTesting.xml,v 1.1 2001/04/18 23:54:02 vhardy Exp $ -->
+<!-- @version $Id: unitTesting.xml,v 1.2 2001/04/20 06:36:17 vhardy Exp $ -->
<!-- ========================================================================= -->
<testSuite name="Test Module - Unit Testing">
<!-- ========================================================================== -->
<!-- Validates that the SVGRenderingAccuracyTest class is operating as expected -->
<!-- ========================================================================== -->
<test class="org.apache.batik.test.svg.SVGRenderingAccuracyTestValidator" />
+
+ <!-- ========================================================================== -->
+ <!-- Validates that the SVGAccuracyTest class is operating as expected -->
+ <!-- ========================================================================== -->
+ <test class="org.apache.batik.svggen.SVGAccuracyTestValidator" />
</testSuite>
1.4 +3 -3 xml-batik/test-resources/org/apache/batik/test/resources/Messages.properties
Index: Messages.properties
===================================================================
RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/resources/Messages.properties,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Messages.properties 2001/04/18 23:54:02 1.3
+++ Messages.properties 2001/04/20 06:36:18 1.4
@@ -48,9 +48,9 @@
and stack trace : {2}
#
-# XMLTestSuiteRunner error codes
+# XMLTestSuiteLoader and XMLTestSuiteRunner error codes
#
-xml.XMLTestSuiteRunner.error.cannot.create.test = \
+xml.XMLTestSuiteLoader.error.cannot.create.test = \
Cannot build Test instance of class : {0}. \
Got exception of class : {1} with messages {2} \
and stack trace : {3}
@@ -60,7 +60,7 @@
Got exception of class : {1} with messages {2} \
and stack trace : {3}
-xml.XMLTestSuiteRunner.error.test.suite.loading.exception = \
+xml.XMLTestSuiteLoader.error.test.suite.loading.exception = \
Got exception while loading test suite {0} \
Got exception of class : {1} with messages {2} \
and stack trace : {3}
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org