vhardy 01/10/08 07:15:04
Modified: test-sources/org/apache/batik/ext/awt/image/codec
PNGEncoderTest.java
test-sources/org/apache/batik/test AbstractTest.java
TestReport.java
test-sources/org/apache/batik/test/svg
SVGRenderingAccuracyTest.java
test-sources/org/apache/batik/test/xml
XMLTestReportProcessor.java
test-resources/org/apache/batik/test/resources
Messages.properties
test-resources/org/apache/batik/test/svg HTMLReport.xsl
Log:
Modified file naming approach for test resource files such as
comparison images and so forth. Now, file names are only random
if a meaningful name cannot be created from the SVG file URL.
Revision Changes Path
1.2 +1 -64
xml-batik/test-sources/org/apache/batik/ext/awt/image/codec/PNGEncoderTest.java
Index: PNGEncoderTest.java
===================================================================
RCS file:
/home/cvs/xml-batik/test-sources/org/apache/batik/ext/awt/image/codec/PNGEncoderTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PNGEncoderTest.java 2001/09/28 12:02:47 1.1
+++ PNGEncoderTest.java 2001/10/08 14:15:04 1.2
@@ -20,7 +20,7 @@
* decodes it and compares the decoded image with the original one.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
- * @version $Id: PNGEncoderTest.java,v 1.1 2001/09/28 12:02:47 vhardy Exp $
+ * @version $Id: PNGEncoderTest.java,v 1.2 2001/10/08 14:15:04 vhardy Exp $
*/
public class PNGEncoderTest extends AbstractTest {
/**
@@ -43,12 +43,6 @@
public static final String ERROR_DECODED_DOES_NOT_MATCH_ENCODED
= "PNGEncoderTest.error.decoded.does.not.match.encoded";
- /**
- * Entry describing the error
- */
- public static final String ENTRY_KEY_ERROR_DESCRIPTION
- = "SVGRenderingAccuracyTest.entry.key.error.description";
-
public TestReport runImpl() throws Exception {
// Create a BufferedImage to be encoded
BufferedImage image = new BufferedImage(100, 75,
BufferedImage.TYPE_INT_ARGB);
@@ -169,61 +163,4 @@
return identical;
}
- /**
- * Convenience method to report a simple error code.
- */
- public TestReport reportError(String errorCode){
- DefaultTestReport report = new DefaultTestReport(this);
- report.setErrorCode(errorCode);
- report.setPassed(false);
- return report;
- }
-
- /**
- * Convenience method to report success.
- */
- public TestReport reportSuccess(){
- DefaultTestReport report = new DefaultTestReport(this);
- report.setPassed(true);
- return report;
- }
-
- /**
- * Convenience method to help implementations report errors.
- * An <tt>AbstractTest</tt> extension will typically catch
- * exceptions for specific error conditions it wants to point
- * out. For example:<tt>
- * public TestReport runImpl() throws Exception { <br />
- * try{ <br />
- * .... something .... <br />
- * catch(MySpecialException e){ <br />
- * return reportException(MY_SPECIAL_ERROR_CODE, e); <br />
- * } <br />
- * <br />
- * public static final String MY_SPECIAL_ERROR_CODE =
"myNonQualifiedClassName.my.error.code" <br />
- * <br />
- * </tt> <br />
- * Note that the implementor will also need to add an entry
- * in its Messages.properties file. That file is expected to be
- * in a resource file called <tt>Messages</tt> having the same package
- * name as the <tt>Test</tt> class, appended with "<tt>.resources</tt>".
- */
- public TestReport reportException(String errorCode,
- Exception e){
- DefaultTestReport report
- = new DefaultTestReport(this);
-
- StringWriter trace = new StringWriter();
- e.printStackTrace(new PrintWriter(trace));
- report.setErrorCode(errorCode);
- report.setDescription(new TestReport.Entry[] {
- new TestReport.Entry
- (Messages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
- Messages.formatMessage
- (errorCode,
- new String[]{trace.toString()})) });
- report.setPassed(false);
- return report;
- }
-
}
1.5 +62 -1 xml-batik/test-sources/org/apache/batik/test/AbstractTest.java
Index: AbstractTest.java
===================================================================
RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/AbstractTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractTest.java 2001/10/04 08:25:36 1.4
+++ AbstractTest.java 2001/10/08 14:15:04 1.5
@@ -16,7 +16,7 @@
* method.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
- * @version $Id: AbstractTest.java,v 1.4 2001/10/04 08:25:36 vhardy Exp $
+ * @version $Id: AbstractTest.java,v 1.5 2001/10/08 14:15:04 vhardy Exp $
*/
public abstract class AbstractTest implements Test {
/**
@@ -116,12 +116,15 @@
report.setDescription(entries);
+ }catch(Exception ex){
+ ex.printStackTrace();
}finally {
//
// In case we are in severe trouble, even filling in the
// TestReport may fail. Because the TestReport instance
// was created up-front, this ensures we can return
// the report, even though it may be incomplete.
+ System.out.println("SERIOUS ERROR");
return report;
}
@@ -165,4 +168,62 @@
report.setPassed(true);
return report;
}
+
+ /**
+ * Convenience method to report a simple error code.
+ */
+ public TestReport reportError(String errorCode){
+ DefaultTestReport report = new DefaultTestReport(this);
+ report.setErrorCode(errorCode);
+ report.setPassed(false);
+ return report;
+ }
+
+ /**
+ * Convenience method to help implementations report errors.
+ * An <tt>AbstractTest</tt> extension will typically catch
+ * exceptions for specific error conditions it wants to point
+ * out. For example:<tt>
+ * public TestReport runImpl() throws Exception { <br />
+ * try{ <br />
+ * .... something .... <br />
+ * catch(MySpecialException e){ <br />
+ * return reportException(MY_SPECIAL_ERROR_CODE, e); <br />
+ * } <br />
+ * <br />
+ * public static final String MY_SPECIAL_ERROR_CODE =
"myNonQualifiedClassName.my.error.code" <br />
+ * <br />
+ * </tt> <br />
+ * Note that the implementor will also need to add an entry
+ * in its Messages.properties file. That file is expected to be
+ * in a resource file called <tt>Messages</tt> having the same package
+ * name as the <tt>Test</tt> class, appended with "<tt>.resources</tt>".
+ */
+ public TestReport reportException(String errorCode,
+ Exception e){
+ DefaultTestReport report
+ = new DefaultTestReport(this);
+
+ StringWriter trace = new StringWriter();
+ e.printStackTrace(new PrintWriter(trace));
+ report.setErrorCode(errorCode);
+
+
+ TestReport.Entry[] entries = new TestReport.Entry[]{
+ new TestReport.Entry
+
(Messages.formatMessage(report.ENTRY_KEY_REPORTED_TEST_FAILURE_EXCEPTION_CLASS, null),
+ e.getClass().getName()),
+ new TestReport.Entry
+
(Messages.formatMessage(report.ENTRY_KEY_REPORTED_TEST_FAILURE_EXCEPTION_MESSAGE,
null),
+ e.getMessage()),
+ new TestReport.Entry
+
(Messages.formatMessage(report.ENTRY_KEY_REPORTED_TEST_FAILURE_EXCEPTION_STACK_TRACE,
null),
+ trace.toString())
+ };
+ report.setDescription(entries);
+ report.setPassed(false);
+ return report;
+ }
+
+
}
1.3 +43 -4 xml-batik/test-sources/org/apache/batik/test/TestReport.java
Index: TestReport.java
===================================================================
RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/TestReport.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestReport.java 2001/10/04 08:25:36 1.2
+++ TestReport.java 2001/10/08 14:15:04 1.3
@@ -13,7 +13,7 @@
* by a <tt>Test</tt> case.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
- * @version $Id: TestReport.java,v 1.2 2001/10/04 08:25:36 vhardy Exp $
+ * @version $Id: TestReport.java,v 1.3 2001/10/08 14:15:04 vhardy Exp $
*/
public interface TestReport {
/**
@@ -39,7 +39,7 @@
*/
public static final String
ENTRY_KEY_INTERNAL_TEST_FAILURE_EXCEPTION_CLASS
- = "TestReport.entry.key.test.failure.exception.class";
+ = "TestReport.entry.key.internal.test.failure.exception.class";
/**
* Entry describing the messages of the internal exception
@@ -47,7 +47,7 @@
*/
public static final String
ENTRY_KEY_INTERNAL_TEST_FAILURE_EXCEPTION_MESSAGE
- = "TestReport.entry.key.test.failure.exception.message";
+ = "TestReport.entry.key.internal.test.failure.exception.message";
/**
* Entry with the stack trace for the internal exception
@@ -55,7 +55,46 @@
*/
public static final String
ENTRY_KEY_INTERNAL_TEST_FAILURE_EXCEPTION_STACK_TRACE
- = "TestReport.entry.key.test.failure.exception.stack.trace";
+ = "TestReport.entry.key.internal.test.failure.exception.stack.trace";
+
+ /**
+ * Entry with the class of the exception that caused the test to fail.
+ * Note that this is different from
+ * ENTRY_KEY_INTERNAL_TEST_FAILURE_EXCEPTION_CLASS, in
+ * which case, the test itself failed unexpectedly. In this
+ * case, the entry is used to describe an expected exception
+ * for which the <tt>Test</tt> author probably created a
+ * specific error code.
+ */
+ public static final String
+ ENTRY_KEY_REPORTED_TEST_FAILURE_EXCEPTION_CLASS
+ = "TestReport.entry.key.reported.test.failure.exception.class";
+
+ /**
+ * Entry with the message of the exception that caused the test to fail.
+ * Note that this is different from
+ * ENTRY_KEY_INTERNAL_TEST_FAILURE_EXCEPTION_MESSAGE, in
+ * which case, the test itself failed unexpectedly. In this
+ * case, the entry is used to describe an expected exception
+ * for which the <tt>Test</tt> author probably created a
+ * specific error code.
+ */
+ public static final String
+ ENTRY_KEY_REPORTED_TEST_FAILURE_EXCEPTION_MESSAGE
+ = "TestReport.entry.key.reported.test.failure.exception.message";
+
+ /**
+ * Entry with the stack trace that caused the test to fail.
+ * Note that this is different from
+ * ENTRY_KEY_INTERNAL_TEST_FAILURE_EXCEPTION_STACK_TRACE, in
+ * which case, the test itself failed unexpectedly. In this
+ * case, the entry is used to describe an expected exception
+ * for which the <tt>Test</tt> author probably created a
+ * specific error code.
+ */
+ public static final String
+ ENTRY_KEY_REPORTED_TEST_FAILURE_EXCEPTION_STACK_TRACE
+ = "TestReport.entry.key.reported.test.failure.exception.stack.trace";
/**
* Inner class for describing an information element in a
1.12 +139 -15
xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java
Index: SVGRenderingAccuracyTest.java
===================================================================
RCS file:
/home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/SVGRenderingAccuracyTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- SVGRenderingAccuracyTest.java 2001/10/04 08:25:37 1.11
+++ SVGRenderingAccuracyTest.java 2001/10/08 14:15:04 1.12
@@ -62,7 +62,7 @@
* all pixel values are the same).
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
- * @version $Id: SVGRenderingAccuracyTest.java,v 1.11 2001/10/04 08:25:37 vhardy
Exp $
+ * @version $Id: SVGRenderingAccuracyTest.java,v 1.12 2001/10/08 14:15:04 vhardy
Exp $
*/
public class SVGRenderingAccuracyTest extends AbstractTest {
/**
@@ -180,6 +180,21 @@
"org.apache.batik.test.svg.resources.Configuration";
/**
+ * Suffix used for comparison images
+ */
+ public final static String IMAGE_TYPE_COMPARISON = "_cmp";
+
+ /**
+ * Suffix used for diff images
+ */
+ public final static String IMAGE_TYPE_DIFF = "_diff";
+
+ /**
+ * Suffix used for saved images (e.g., comparison and diff images)
+ */
+ public final static String IMAGE_FILE_EXTENSION = ".png";
+
+ /**
* The configuration resource bundle
*/
protected static ResourceBundle configuration;
@@ -232,6 +247,29 @@
protected File saveVariation;
/**
+ * Temporary directory
+ */
+ protected static File tempDirectory;
+
+ /**
+ * Returns the temporary directory
+ */
+ public static File getTempDirectory(){
+ if(tempDirectory == null){
+ String tmpDir = System.getProperty("java.io.tmpdir");
+ if(tmpDir == null){
+ throw new Error();
+ }
+
+ tempDirectory = new File(tmpDir);
+ if(!tempDirectory.exists()){
+ throw new Error();
+ }
+ }
+ return tempDirectory;
+ }
+
+ /**
* Constructor.
* @param svgURL the URL String for the SVG document being tested.
* @param refImgURL the URL for the reference image.
@@ -461,7 +499,7 @@
// computed difference.
//
if(variationURL != null){
- File tmpDiff = imageToFile(diff);
+ File tmpDiff = imageToFile(diff, IMAGE_TYPE_DIFF);
InputStream variationURLStream = null;
try{
@@ -500,8 +538,8 @@
// b. One with the difference between the two images and the
set of
// different pixels.
BufferedImage cmp = makeCompareImage(ref, gen);
- File cmpFile = imageToFile(cmp);
- File diffFile = imageToFile(diff);
+ File cmpFile = imageToFile(cmp, IMAGE_TYPE_COMPARISON);
+ File diffFile = imageToFile(diff, IMAGE_TYPE_DIFF);
report.setErrorCode(ERROR_SVG_RENDERING_NOT_ACCURATE);
@@ -651,27 +689,113 @@
}
/**
- * Creates a temporary File into which the input image is
+ * Creates a File into which the input image is
* saved.
+ * If there is a "file" component in the SVG url,
+ * then a temporary file is created with that
+ * name and the imageType suffix in the temp
+ * directory of the test-reports directory.
*/
- protected File imageToFile(BufferedImage img)
+ protected File imageToFile(BufferedImage img,
+ String imageType)
throws IOException {
+ String file = getURLFile(svgURL);
- File imgFile
- = File.createTempFile(TEMP_FILE_PREFIX,
- TEMP_FILE_SUFFIX,
- null);
- imgFile.deleteOnExit();
+ File imageFile = null;
+ if( !"".equals(file) ){
+ imageFile = makeTempFileName(file, imageType);
+ }
+ else{
+ imageFile = makeRandomFileName(imageType);
+ }
+
+ imageFile.deleteOnExit();
PNGImageEncoder encoder
- = new PNGImageEncoder(new FileOutputStream(imgFile),
- PNGEncodeParam.getDefaultEncodeParam(img));
-
+ = new PNGImageEncoder(new FileOutputStream(imageFile),
+ PNGEncodeParam.getDefaultEncodeParam(img));
+
encoder.encode(img);
+
+ return imageFile;
+
+ }
- return imgFile;
+ /**
+ * Extracts the file portion of the URL
+ */
+ protected String getURLFile(URL url){
+ String path = url.getPath();
+ int n = path.lastIndexOf('/');
+ if(n == -1){
+ return path;
+ }
+ else{
+ if(n<path.length()){
+ return path.substring(n+1, path.length());
+ }
+ else{
+ return "";
+ }
+ }
}
+ protected File makeTempFileName(String svgFileName,
+ String imageType){
+ int dotIndex = svgFileName.lastIndexOf('.');
+ if( dotIndex == -1){
+ return getNextTempFileName(svgFileName + imageType);
+ }
+ else{
+ return getNextTempFileName
+ (svgFileName.substring(0, dotIndex) +
+ imageType + IMAGE_FILE_EXTENSION);
+ }
+ }
+
+ protected File getNextTempFileName(String fileName){
+ File f = new File(getTempDirectory(), fileName);
+ if(!f.exists()){
+ return f;
+ }
+ else{
+ return getNextTempFileName(fileName,
+ 1);
+ }
+ }
+
+ protected File getNextTempFileName(String fileName,
+ int instance){
+ // First, create a 'versioned' file name
+ int n = fileName.lastIndexOf('.');
+ String iFileName = fileName + instance;
+ if(n != -1){
+ iFileName = fileName.substring(0, n) + instance
+ + fileName.substring(n, fileName.length());
+ }
+
+ File r = new File(getTempDirectory(), iFileName);
+ if(!r.exists()){
+ return r;
+ }
+ else{
+ return getNextTempFileName(fileName,
+ instance + 1);
+ }
+ }
+
+ /**
+ * Creates a temporary File into which the input image is
+ * saved.
+ */
+ protected File makeRandomFileName(String imageType)
+ throws IOException {
+
+ return File.createTempFile(TEMP_FILE_PREFIX,
+ TEMP_FILE_SUFFIX + imageType,
+ null);
+ }
+
/**
* Returns the <tt>ImageTranscoder</tt> the Test should
* use
1.11 +2 -2
xml-batik/test-sources/org/apache/batik/test/xml/XMLTestReportProcessor.java
Index: XMLTestReportProcessor.java
===================================================================
RCS file:
/home/cvs/xml-batik/test-sources/org/apache/batik/test/xml/XMLTestReportProcessor.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- XMLTestReportProcessor.java 2001/10/08 11:37:47 1.10
+++ XMLTestReportProcessor.java 2001/10/08 14:15:04 1.11
@@ -51,7 +51,7 @@
* report consumer of the XML file it created.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
- * @version $Id: XMLTestReportProcessor.java,v 1.10 2001/10/08 11:37:47 vhardy Exp $
+ * @version $Id: XMLTestReportProcessor.java,v 1.11 2001/10/08 14:15:04 vhardy Exp $
*/
public class XMLTestReportProcessor
implements TestReportProcessor,
@@ -306,7 +306,7 @@
XTR_TEST_NAME_ATTRIBUTE,
report.getTest().getName());
- String id = report.getTest().getId();
+ String id = report.getTest().getQualifiedId();
if( !"".equals(id) ){
reportElement.setAttributeNS(null,
XTR_ID_ATTRIBUTE,
1.5 +12 -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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Messages.properties 2001/04/20 06:36:18 1.4
+++ Messages.properties 2001/10/08 14:15:04 1.5
@@ -18,14 +18,23 @@
DefaultTestSuiteReport.entry.key.passed.child.test.report = \
Child Report
-TestReport.entry.key.test.failure.exception.class = \
+TestReport.entry.key.internal.test.failure.exception.class = \
Internal test exception class
-TestReport.entry.key.test.failure.exception.message = \
+TestReport.entry.key.internal.test.failure.exception.message = \
Internal test exception message
-TestReport.entry.key.test.failure.exception.stack.trace = \
+TestReport.entry.key.internal.test.failure.exception.stack.trace = \
Internal test exception stack trace
+
+TestReport.entry.key.reported.test.failure.exception.class = \
+Reported test exception class
+
+TestReport.entry.key.reported.test.failure.exception.message = \
+Reported test exception message
+
+TestReport.entry.key.reported.test.failure.exception.stack.trace = \
+Reported test exception stack trace
TestReportValidator.entry.key.expected.error.code = \
Expected error code
1.7 +7 -1
xml-batik/test-resources/org/apache/batik/test/svg/HTMLReport.xsl
Index: HTMLReport.xsl
===================================================================
RCS file:
/home/cvs/xml-batik/test-resources/org/apache/batik/test/svg/HTMLReport.xsl,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HTMLReport.xsl 2001/10/04 08:25:37 1.6
+++ HTMLReport.xsl 2001/10/08 14:15:04 1.7
@@ -9,7 +9,7 @@
<!-- ========================================================================= -->
<!-- @author [EMAIL PROTECTED] -->
-<!-- @version $Id: HTMLReport.xsl,v 1.6 2001/10/04 08:25:37 vhardy Exp $ -->
+<!-- @version $Id: HTMLReport.xsl,v 1.7 2001/10/08 14:15:04 vhardy Exp $ -->
<!-- ========================================================================= -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/2000/xlink/namespace/" >
@@ -37,6 +37,12 @@
<xsl:variable name="childrenTests" select="description/testReport" />
<xsl:variable name="childrenTestSuites"
select="description/testSuiteReport" />
<xsl:variable name="childrenTestsCount" select="count($childrenTests) +
count($childrenTestSuites)" />
+
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="@id" />
+ </xsl:attribute>
+ </a>
<xsl:choose>
<xsl:when test="$childrenTestsCount > 0 or @status='failed'">
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]