vhardy 01/10/19 02:22:18
Modified: test-sources/org/apache/batik/test AbstractTest.java
TestReport.java
test-sources/org/apache/batik/test/xml
XMLTestReportProcessor.java XTRConstants.java
test-resources/org/apache/batik/test samplesRendering.xml
test-resources/org/apache/batik/test/svg HTMLReport.xsl
test-resources/org/apache/batik/test/svg/resources/style
style.css
Log:
- Fix to the date output in reports.
- Added documentation to AbstractTest to explain how to easily write
new tests.
- Added support for assertions in AbstractTest for a different style
of test writing.
Revision Changes Path
1.7 +129 -13 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractTest.java 2001/10/12 12:34:35 1.6
+++ AbstractTest.java 2001/10/19 09:22:17 1.7
@@ -12,18 +12,72 @@
import java.io.PrintWriter;
/**
- * Provides a default implementation for the <tt>getName</tt>
- * method.
+ * Base class containing convenience methods for writing tests. <br />
+ * There are at least three approaches to write new tests derived from
+ * <tt>AbstractTest</tt>:<br /><ul>
+ * <li>You can simply override the <tt>runImplBase</tt> method and
+ * return true or false depending on whether or not the test fails.</li>
+ * <li>You can choose to report more complex test failure conditions
+ * by overriding the <tt>runImpl</tt> method which returns a <tt>TestReport</tt>.
+ * In that case, you can use the convenience methods such as <tt>reportFailure</tt>
+ * <tt>reportSuccess</tt> or <tt>reportException</tt> to help build a
<tt>TestReport</tt>,
+ * and use the <tt>TestReport</tt>'s <tt>addDescriptionEntry</tt> to populate
+ * the report with relevant error description.</li>
+ * <li>You can choose to use the various assertion methods such as
<tt>assertNull</tt>,
+ * <tt>assertEquals</tt> or <tt>assertTrue</tt>. These methods throw exceptions
which
+ * will be turned in <tt>TestReports</tt> by the <tt>AbstractTest</tt>.</li>
+ * </ul>
+ *
+ * Here are some examples:
+ * <code>
+ * public class MyTestA extends AbstractTest {
+ * public boolean runImplBase() {
+ * if(someConditionFails){
+ * return false;
+ * }
+ * return true;
+ * }
+ * }
+ * </code>
+ *
+ * <code>
+ * public class MyTestB extends AbstractTest {
+ * public TestReport runImpl() {
+ * if(someConditionFails){
+ * TestReport report = reportError(MY_ERROR_CODE);
+ * report.addDescriptionEntry(ENTRY_KEY_MY_ERROR_DESCRIPTION_KEY,
+ * myErrorDescriptionValue);
+ * return report;
+ * }
+ *
+ * return reportSuccess;
+ * }
+ * </code>
*
+ * <code>
+ * public class MyTestC extends AbstractTest {
+ * public TestReport runImpl() throws Exception {
+ * assertTrue(somCondition);
+ * assertEquals(valueA, valueB);
+ * assertNull(shouldBeNullRef);
+ *
+ * if(someErrorCondition){
+ * error(MY_ERROR_CODE);
+ * }
+ *
+ * return reportSuccess();
+ * }
+ * </code>
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
- * @version $Id: AbstractTest.java,v 1.6 2001/10/12 12:34:35 vhardy Exp $
+ * @version $Id: AbstractTest.java,v 1.7 2001/10/19 09:22:17 vhardy Exp $
*/
public abstract class AbstractTest implements Test {
/**
* This test's id.
*/
protected String id = "";
-
+
/**
* This test's parent, in case this test is part of
* a suite.
@@ -31,6 +85,11 @@
protected TestSuite parent;
/**
+ * This test's name. If null, the class' name is returned.
+ */
+ protected String name;
+
+ /**
* TestReport
*/
private DefaultTestReport report
@@ -40,15 +99,26 @@
setPassed(false);
}
};
-
+
/**
* Returns this <tt>Test</tt>'s name.
*/
public String getName(){
- return getClass().getName();
+ if(name == null){
+ return getClass().getName();
+ }
+
+ return name;
}
/**
+ * Sets this test's name
+ */
+ public void setName(String name){
+ this.name = name;
+ }
+
+ /**
* Return this <tt>Test</tt>'s id.
*/
public String getId(){
@@ -83,10 +153,10 @@
public void setParent(TestSuite parent){
this.parent = parent;
}
-
+
/**
* This default implementation of the run method
- * catches any Exception or Error throw from the
+ * catches any Exception thrown from the
* runImpl method and creates a <tt>TestReport</tt>
* indicating an internal <tt>Test</tt> failure
* when that happens. Otherwise, this method
@@ -96,7 +166,9 @@
public TestReport run(){
try{
return runImpl();
- }catch(Exception e){
+ } catch(TestErrorConditionException e){
+ return e.getTestReport(this);
+ } catch(Exception e){
try {
StringWriter trace = new StringWriter();
@@ -141,7 +213,7 @@
*/
public TestReport runImpl() throws Exception {
boolean passed = runImplBasic();
-
+
// No exception was thrown if we get to this
// portion of rumImpl. The test result is
// given by passed.
@@ -152,7 +224,7 @@
report.setPassed(passed);
return report;
}
-
+
/**
* In the simplest test implementation, developers can
* simply implement the following method.
@@ -160,7 +232,7 @@
public boolean runImplBasic() throws Exception {
return true;
}
-
+
/**
* Convenience method.
*/
@@ -169,7 +241,7 @@
report.setPassed(true);
return report;
}
-
+
/**
* Convenience method to report a simple error code.
*/
@@ -178,6 +250,50 @@
report.setErrorCode(errorCode);
report.setPassed(false);
return report;
+ }
+
+ /**
+ * Convenience method to report an error condition.
+ */
+ public void error(String errorCode) throws TestErrorConditionException {
+ throw new TestErrorConditionException(errorCode);
+ }
+
+ /**
+ * Convenience method to check that a reference is null
+ */
+ public void assertNull(Object ref) throws AssertNullException {
+ if(ref != null){
+ throw new AssertNullException();
+ }
+ }
+
+ /**
+ * Convenience method to check that a given boolean is true.
+ */
+ public void assertTrue(boolean b) throws AssertTrueException {
+ if (!b){
+ throw new AssertTrueException();
+ }
+ }
+
+ /**
+ * Convenience method to check for a specific condition.
+ * Returns true if both objects are null or if ref is not
+ * null and ref.equals(cmp) is true.
+ */
+ public void assertEquals(Object ref, Object cmp) throws AssertEqualsException {
+ if(ref == null && cmp != null){
+ throw new AssertEqualsException(ref, cmp);
+ }
+
+ if(ref != null && !ref.equals(cmp)){
+ throw new AssertEqualsException(ref, cmp);
+ }
+ }
+
+ public void assertEquals(int ref, int cmp) throws AssertEqualsException {
+ assertEquals(new Integer(ref), new Integer(cmp));
}
/**
1.4 +16 -2 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestReport.java 2001/10/08 14:15:04 1.3
+++ TestReport.java 2001/10/19 09:22:17 1.4
@@ -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.3 2001/10/08 14:15:04 vhardy Exp $
+ * @version $Id: TestReport.java,v 1.4 2001/10/19 09:22:17 vhardy Exp $
*/
public interface TestReport {
/**
@@ -31,9 +31,15 @@
* that the test failed.
*/
public static final String ERROR_TEST_FAILED
- = "DefaultTestSuiteReport.error.test.failed";
+ = "TestReport.error.test.failed";
/**
+ * Generic error code to report test assertion failures.
+ */
+ public static final String ERROR_ASSERTION_FAILED
+ = "TestReport.error.assertion.failed";
+
+ /**
* Entry describing the class of the internal exception
* that caused the test's internal failure
*/
@@ -95,6 +101,14 @@
public static final String
ENTRY_KEY_REPORTED_TEST_FAILURE_EXCEPTION_STACK_TRACE
= "TestReport.entry.key.reported.test.failure.exception.stack.trace";
+
+ /**
+ * Entry with the stack trace for a specific test error
+ * condition.
+ */
+ public static final String
+ ENTRY_KEY_ERROR_CONDITION_STACK_TRACE
+ = "TestReport.entry.key.error.condition.stack.trace";
/**
* Inner class for describing an information element in a
1.14 +10 -1
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.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XMLTestReportProcessor.java 2001/10/11 09:42:42 1.13
+++ XMLTestReportProcessor.java 2001/10/19 09:22:17 1.14
@@ -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.13 2001/10/11 09:42:42 vhardy Exp $
+ * @version $Id: XMLTestReportProcessor.java,v 1.14 2001/10/19 09:22:17 vhardy Exp $
*/
public class XMLTestReportProcessor
implements TestReportProcessor,
@@ -115,6 +115,11 @@
protected XMLReportConsumer consumer;
/**
+ * String encoding the date the report was generated.
+ */
+ protected String reportDate;
+
+ /**
* Directory into which this processor puts all files and resources.
*/
protected File reportDirectory;
@@ -179,6 +184,9 @@
Element root = document.getDocumentElement();
+ root.setAttributeNS(null, XTR_DATE_ATTRIBUTE,
+ reportDate);
+
processReport(report, root, document);
File xmlReport = serializeReport(root);
@@ -250,6 +258,7 @@
+ makeTwoDigits(c.get(c.MINUTE)) + "m"
+ makeTwoDigits(c.get(c.SECOND)) + "s";
+ reportDate = dirName;
reportDirectory = new File(baseReportDir, dirName);
checkDirectory(reportDirectory, ERROR_REPORT_DIRECTORY_UNUSABLE);
1.4 +2 -1
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XTRConstants.java 2001/10/04 08:25:37 1.3
+++ XTRConstants.java 2001/10/19 09:22:17 1.4
@@ -12,7 +12,7 @@
* Contains constants for the XML Test Report (XTR) syntax.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a>
- * @version $Id: XTRConstants.java,v 1.3 2001/10/04 08:25:37 vhardy Exp $
+ * @version $Id: XTRConstants.java,v 1.4 2001/10/19 09:22:17 vhardy Exp $
*/
public interface XTRConstants extends XMLReflectConstants{
String XTR_NAMESPACE_URI
@@ -32,6 +32,7 @@
/////////////////////////////////////////////////////////////////////////
// XTR attributes
/////////////////////////////////////////////////////////////////////////
+ String XTR_DATE_ATTRIBUTE = "date";
String XTR_KEY_ATTRIBUTE = "key";
String XTR_ERROR_CODE_ATTRIBUTE = "errorCode";
String XTR_ID_ATTRIBUTE = "id";
1.42 +3 -3
xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml
Index: samplesRendering.xml
===================================================================
RCS file:
/home/cvs/xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- samplesRendering.xml 2001/10/19 08:45:18 1.41
+++ samplesRendering.xml 2001/10/19 09:22:17 1.42
@@ -8,7 +8,7 @@
<!-- ========================================================================= -->
<!-- @author [EMAIL PROTECTED] -->
-<!-- @version $Id: samplesRendering.xml,v 1.41 2001/10/19 08:45:18 tkormann Exp $
-->
+<!-- @version $Id: samplesRendering.xml,v 1.42 2001/10/19 09:22:17 vhardy Exp $ -->
<!-- ========================================================================= -->
<testSuite id="samplesRendering" name="samples and samples/test Rendering"
class="org.apache.batik.test.svg.SamplesRenderingTest">
@@ -103,8 +103,8 @@
<test id="samples/tests/spec/linking/linkingViewBox.svg" />
<testGroup id="reference"
class="org.apache.batik.test.svg.SVGReferenceRenderingAccuracyTest">
- <test id="samples/anne.svg#svgView(viewBox(0,0,100,200))-Viewbox1" />
- <test id="samples/anne.svg#svgView(viewBox(100,50,100,200))-Viewbox2" />
+ <test id="samples/anne.svg#svgView(viewBox(0,0,100,200))-ViewBox1" />
+ <test id="samples/anne.svg#svgView(viewBox(100,50,100,200))-ViewBox2" />
<test
id="samples/anne.svg#svgView(transform(translate(-100,-50)))-Transform1" />
<test
id="samples/anne.svg#svgView(transform(translate(225,250)rotate(45)translate(-225,-250)))-Transform2"
/>
<test
id="samples/anne.svg#svgView(transform(rotate(45,225,250)))-Transform2" />
1.12 +2 -2
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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- HTMLReport.xsl 2001/10/19 08:20:20 1.11
+++ HTMLReport.xsl 2001/10/19 09:22:17 1.12
@@ -9,7 +9,7 @@
<!-- ========================================================================= -->
<!-- @author [EMAIL PROTECTED] -->
-<!-- @version $Id: HTMLReport.xsl,v 1.11 2001/10/19 08:20:20 vhardy Exp $ -->
+<!-- @version $Id: HTMLReport.xsl,v 1.12 2001/10/19 09:22:17 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/" >
@@ -36,7 +36,7 @@
<!-- Report Date information -->
<table class="reportDate" width="600" border="0" cellpadding="0"
cellspacing="0" hspace="0" vspace="0" bgcolor="white">
- <tr><td class="reportDate"><xsl:value-of select="@date"
/></td></tr></table>
+ <tr><td class="reportDate"><xsl:value-of
select="/testSuiteReport[position()=1]/@date" /></td></tr></table>
<!-- Report Title containing the ratio of count(success) /
count(tests) -->
<h1>Regard Test Report --
1.3 +9 -7
xml-batik/test-resources/org/apache/batik/test/svg/resources/style/style.css
Index: style.css
===================================================================
RCS file:
/home/cvs/xml-batik/test-resources/org/apache/batik/test/svg/resources/style/style.css,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- style.css 2001/10/19 08:20:21 1.2
+++ style.css 2001/10/19 09:22:17 1.3
@@ -23,15 +23,17 @@
font-family: sans-serif;
}
-p,ol,ul,li { font-family: serif;}
+ol li { font-size: 10px; }
+
+p,ol,ul,li { font-family: sans-serif;}
h1, h2, h3, h4, h5, h6 { text-align: left }
h1, h2, h3 { color: #444; background: white; }
-h1 { font: 270% serif; }
-h2 { font: 240% serif }
-h3 { font: 220% serif }
-h4 { font: bold 100% serif }
-h5 { font: italic 100% serif }
-h6 { font: small-caps 100% serif }
+h1 { font: 27px serif; }
+h2 { font: 18px serif }
+h3 { font: 16px serif }
+h4 { font: bold 12px serif }
+h5 { font: italic 12px serif }
+h6 { font: small-caps 12px serif }
h7 { font-family: serif; }
.titlefailed { font-family: Arial; font-weight: bolder; font-size: 12;}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]